From d72c0e2f4b905a7e3bf55350614d0b8b4157b793 Mon Sep 17 00:00:00 2001 From: lukai Date: Tue, 27 May 2025 21:51:54 +0800 Subject: [PATCH] Adapt read barrier Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IBSHKF Change-Id: Ic6bb4f4f3684e2949650ef43d7559f9d3f64c83d Signed-off-by: lukai --- ecmascript/accessor_data.h | 4 +- ecmascript/async_generator_helper.cpp | 10 +- ecmascript/base/atomic_helper.cpp | 9 +- ecmascript/base/error_helper.cpp | 6 +- ecmascript/base/gc_helper.h | 38 +- ecmascript/base/json_parser.cpp | 10 +- ecmascript/base/json_parser.h | 3 +- ecmascript/base/json_stringifier.cpp | 132 +- .../base/json_stringifier_optimized.cpp | 124 +- ecmascript/base/number_helper.cpp | 12 +- ecmascript/base/number_helper.h | 2 +- ecmascript/base/sort_helper.cpp | 84 +- ecmascript/base/tests/ason_test.cpp | 56 +- ecmascript/base/tests/builtins_base_test.cpp | 10 +- ecmascript/base/tests/error_helper_test.cpp | 70 +- ecmascript/base/tests/json_parser_test.cpp | 50 +- .../base/tests/json_stringifier_test.cpp | 56 +- ecmascript/base/tests/number_helper_test.cpp | 16 +- .../base/tests/typed_array_helper_test.cpp | 12 +- ecmascript/base/typed_array_helper-inl.h | 4 +- ecmascript/base/typed_array_helper.cpp | 44 +- ecmascript/base/typed_array_helper.h | 2 +- ecmascript/base_env.h | 4 +- ecmascript/builtin_entries.h | 8 +- ecmascript/builtins/builtins.cpp | 8 +- ecmascript/builtins/builtins_ark_tools.cpp | 60 +- ecmascript/builtins/builtins_array.cpp | 14 +- ecmascript/builtins/builtins_arraybuffer.cpp | 54 +- ecmascript/builtins/builtins_arraybuffer.h | 4 +- .../builtins_async_from_sync_iterator.cpp | 26 +- .../builtins/builtins_async_iterator.cpp | 4 +- ecmascript/builtins/builtins_atomics.cpp | 25 +- ecmascript/builtins/builtins_atomics.h | 3 +- ecmascript/builtins/builtins_bigint.cpp | 2 +- ecmascript/builtins/builtins_boolean.cpp | 2 +- ecmascript/builtins/builtins_cjs_module.cpp | 2 +- ecmascript/builtins/builtins_collator.cpp | 8 +- ecmascript/builtins/builtins_dataview.cpp | 20 +- ecmascript/builtins/builtins_date.cpp | 12 +- .../builtins/builtins_date_time_format.cpp | 9 +- ecmascript/builtins/builtins_displaynames.cpp | 2 +- .../builtins_finalization_registry.cpp | 2 +- ecmascript/builtins/builtins_function.cpp | 20 +- ecmascript/builtins/builtins_gc.cpp | 16 +- ecmascript/builtins/builtins_global.cpp | 80 +- ecmascript/builtins/builtins_global.h | 2 +- ecmascript/builtins/builtins_global_uri.cpp | 32 +- .../builtins/builtins_lazy_callback.cpp | 10 +- ecmascript/builtins/builtins_locale.cpp | 16 +- ecmascript/builtins/builtins_map.cpp | 16 +- ecmascript/builtins/builtins_number.cpp | 14 +- ecmascript/builtins/builtins_number.h | 2 +- .../builtins/builtins_number_format.cpp | 9 +- ecmascript/builtins/builtins_object.cpp | 22 +- ecmascript/builtins/builtins_promise.cpp | 102 +- .../builtins/builtins_promise_handler.cpp | 117 +- ecmascript/builtins/builtins_promise_job.cpp | 20 +- ecmascript/builtins/builtins_regexp-inl.h | 4 +- ecmascript/builtins/builtins_regexp.cpp | 191 +- ecmascript/builtins/builtins_regexp.h | 34 +- .../builtins_relative_time_format.cpp | 2 +- ecmascript/builtins/builtins_segments.cpp | 4 +- .../builtins_sendable_arraybuffer.cpp | 30 +- .../builtins/builtins_sendable_arraybuffer.h | 4 +- ecmascript/builtins/builtins_set.cpp | 12 +- ecmascript/builtins/builtins_shared_array.cpp | 52 +- ecmascript/builtins/builtins_shared_map.cpp | 6 +- ecmascript/builtins/builtins_shared_set.cpp | 4 +- .../builtins/builtins_shared_typedarray.cpp | 62 +- .../builtins/builtins_sharedarraybuffer.cpp | 16 +- .../builtins/builtins_sharedarraybuffer.h | 2 +- ecmascript/builtins/builtins_string.cpp | 121 +- .../builtins/builtins_string_iterator.cpp | 8 +- ecmascript/builtins/builtins_symbol.cpp | 20 +- ecmascript/builtins/builtins_typedarray.cpp | 65 +- ecmascript/builtins/shared_builtins.cpp | 4 +- .../builtins/tests/builtins_array_test.cpp | 6 +- .../builtins/tests/builtins_bigint_test.cpp | 10 +- .../builtins/tests/builtins_boolean_test.cpp | 4 +- .../builtins/tests/builtins_collator_test.cpp | 19 +- .../builtins/tests/builtins_date_test.cpp | 34 +- .../builtins_date_time_format_first_test.cpp | 8 +- .../builtins_date_time_format_second_test.cpp | 24 +- .../tests/builtins_displaynames_test.cpp | 22 +- .../builtins/tests/builtins_function_test.cpp | 26 +- .../builtins/tests/builtins_global_test.cpp | 16 +- .../builtins/tests/builtins_intl_test.cpp | 12 +- .../builtins/tests/builtins_json_test.cpp | 6 +- .../tests/builtins_list_format_first_test.cpp | 10 +- .../builtins_list_format_second_test.cpp | 22 +- .../builtins/tests/builtins_locale_test.cpp | 26 +- .../builtins/tests/builtins_map_test.cpp | 16 +- .../tests/builtins_number_format_test.cpp | 18 +- .../builtins/tests/builtins_number_test.cpp | 108 +- .../builtins/tests/builtins_object_test.cpp | 10 +- .../tests/builtins_plural_rules_test.cpp | 12 +- .../builtins/tests/builtins_promise_test.cpp | 67 +- .../builtins/tests/builtins_proxy_test.cpp | 4 +- .../builtins/tests/builtins_reflect_test.cpp | 8 +- .../builtins/tests/builtins_regexp_test.cpp | 24 +- .../builtins_relative_time_format_test.cpp | 16 +- .../tests/builtins_segmenter_test.cpp | 20 +- .../builtins_sendable_arraybuffer_test.cpp | 6 +- .../builtins/tests/builtins_set_test.cpp | 16 +- .../tests/builtins_shared_array_test.cpp | 6 +- .../tests/builtins_shared_function_test.cpp | 26 +- .../tests/builtins_shared_map_test.cpp | 2 +- .../tests/builtins_shared_set_test.cpp | 2 +- .../tests/builtins_sharedarraybuffer_test.cpp | 4 +- .../tests/builtins_sharedobject_test.cpp | 10 +- .../builtins/tests/builtins_string_test.cpp | 35 +- .../builtins/tests/builtins_symbol_test.cpp | 15 +- .../builtins/tests/builtins_weak_map_test.cpp | 6 +- .../builtins/tests/builtins_weak_set_test.cpp | 6 +- ecmascript/common.h | 3 + .../compiler/aot_constantpool_patcher.cpp | 12 +- .../compiler/aot_file/aot_file_manager.cpp | 26 +- .../compiler/aot_file/aot_file_manager.h | 10 +- .../snapshot_constantpool_data.cpp | 51 +- .../aot_snapshot/snapshot_constantpool_data.h | 3 +- .../aot_snapshot/snapshot_global_data.cpp | 8 +- .../aot_snapshot/snapshot_global_data.h | 4 +- .../builtins/builtins_number_stub_builder.cpp | 4 +- .../builtins_typedarray_stub_builder.cpp | 4 +- ecmascript/compiler/call_signature.cpp | 49 +- ecmascript/compiler/circuit_builder.cpp | 2 +- ecmascript/compiler/common_stubs.cpp | 4 +- ecmascript/compiler/jit_compilation_env.cpp | 46 +- ecmascript/compiler/lazy_deopt_dependency.cpp | 6 +- ecmascript/compiler/lazy_deopt_dependency.h | 2 +- ecmascript/compiler/mcr_circuit_builder.cpp | 2 +- .../compiler/new_object_stub_builder.cpp | 2 +- .../compiler/ntype_bytecode_lowering.cpp | 7 +- ecmascript/compiler/ntype_hcr_lowering.cpp | 5 +- .../compiler/pgo_type/pgo_type_manager.cpp | 12 +- ecmascript/compiler/slowpath_lowering.cpp | 4 +- ecmascript/compiler/stub_builder-inl.h | 2 +- ecmascript/compiler/ts_hcr_opt_pass.cpp | 2 +- ecmascript/compiler/ts_inline_lowering.cpp | 11 +- ecmascript/compiler/type_info_accessors.cpp | 12 +- ecmascript/compiler/type_info_accessors.h | 6 +- .../compiler/typed_bytecode_lowering.cpp | 21 +- ecmascript/compiler/typed_bytecode_lowering.h | 2 +- .../compiler/typed_native_inline_lowering.cpp | 6 +- .../containers/containers_arraylist.cpp | 130 +- .../containers/containers_bitvector.cpp | 107 +- ecmascript/containers/containers_buffer.cpp | 41 +- ecmascript/containers/containers_buffer.h | 4 +- ecmascript/containers/containers_deque.cpp | 54 +- ecmascript/containers/containers_hashmap.cpp | 76 +- ecmascript/containers/containers_hashset.cpp | 46 +- .../containers/containers_lightweightmap.cpp | 114 +- .../containers/containers_lightweightset.cpp | 111 +- .../containers/containers_linked_list.cpp | 114 +- ecmascript/containers/containers_list.cpp | 124 +- .../containers/containers_plainarray.cpp | 106 +- ecmascript/containers/containers_private.cpp | 2 +- ecmascript/containers/containers_queue.cpp | 30 +- ecmascript/containers/containers_stack.cpp | 40 +- ecmascript/containers/containers_treemap.cpp | 100 +- ecmascript/containers/containers_treeset.cpp | 78 +- ecmascript/containers/containers_vector.cpp | 142 +- .../tests/containers_arraylist_test.cpp | 14 +- .../tests/containers_bitvector_test.cpp | 4 +- .../tests/containers_buffer_test.cpp | 4 +- .../tests/containers_deque_test.cpp | 7 +- .../tests/containers_hashmap_test.cpp | 8 +- .../tests/containers_hashset_test.cpp | 4 +- .../tests/containers_lightweightmap_test.cpp | 2 +- .../tests/containers_lightweightset_test.cpp | 4 +- .../tests/containers_linked_list_test.cpp | 48 +- .../containers/tests/containers_list_test.cpp | 38 +- .../tests/containers_plainarray_test.cpp | 8 +- .../tests/containers_queue_test.cpp | 2 +- .../tests/containers_stack_test.cpp | 7 +- .../tests/containers_treemap_test.cpp | 94 +- .../tests/containers_treeset_test.cpp | 104 +- .../tests/containers_vector_test.cpp | 19 +- ecmascript/debugger/debugger_api.cpp | 232 +- ecmascript/debugger/debugger_api.h | 3 +- ecmascript/debugger/dropframe_manager.cpp | 10 +- ecmascript/debugger/js_debugger.cpp | 23 +- ecmascript/deoptimizer/deoptimizer.cpp | 26 +- ecmascript/dependent_infos.cpp | 9 +- ecmascript/dfx/cpu_profiler/cpu_profiler.cpp | 8 +- ecmascript/dfx/hprof/heap_sampling.cpp | 2 +- ecmascript/dfx/hprof/heap_snapshot.cpp | 34 +- ecmascript/dfx/hprof/heap_snapshot.h | 2 +- ecmascript/dfx/hprof/tests/heap_dump_test.cpp | 2 +- .../dfx/stackinfo/async_stack_trace.cpp | 4 +- ecmascript/dfx/stackinfo/js_stackgetter.cpp | 49 +- ecmascript/dfx/stackinfo/js_stackgetter.h | 6 +- ecmascript/dfx/stackinfo/js_stackinfo.cpp | 22 +- ecmascript/dfx/stackinfo/js_stackinfo.h | 4 +- ecmascript/dfx/vmstat/function_call_timer.cpp | 16 +- ecmascript/dfx/vmstat/function_call_timer.h | 6 +- ecmascript/dfx/vmstat/opt_code_profiler.cpp | 10 +- ecmascript/dfx/vmstat/opt_code_profiler.h | 2 +- ecmascript/dump.cpp | 3767 +++++++++-------- ecmascript/ecma_macros.h | 42 +- ecmascript/ecma_string-inl.h | 78 +- ecmascript/ecma_string.cpp | 170 +- ecmascript/ecma_string.h | 222 +- ecmascript/ecma_string_table.cpp | 64 +- ecmascript/ecma_string_table.h | 40 +- .../ecma_string_table_optimization-inl.h | 5 +- ecmascript/ecma_string_table_optimization.cpp | 105 +- ecmascript/ecma_vm.cpp | 23 +- ecmascript/element_accessor-inl.h | 2 +- ecmascript/element_accessor.cpp | 34 +- ecmascript/element_accessor.h | 10 +- ecmascript/elements.cpp | 22 +- ecmascript/enum_cache.h | 19 +- ecmascript/frames.cpp | 13 +- ecmascript/free_object.cpp | 6 +- ecmascript/generator_helper.cpp | 6 +- ecmascript/global_dictionary-inl.h | 59 +- ecmascript/global_dictionary.h | 23 +- ecmascript/global_env.cpp | 2 +- ecmascript/global_env.h | 12 +- ecmascript/ic/ic_handler.cpp | 18 +- ecmascript/ic/ic_handler.h | 5 +- ecmascript/ic/ic_runtime.cpp | 10 +- ecmascript/ic/ic_runtime_stub-inl.h | 112 +- ecmascript/ic/ic_runtime_stub.h | 8 +- ecmascript/ic/mega_ic_cache.cpp | 5 +- ecmascript/ic/mega_ic_cache.h | 8 +- ecmascript/ic/profile_type_info.cpp | 44 +- ecmascript/ic/profile_type_info.h | 22 +- ecmascript/ic/properties_cache.h | 12 +- ecmascript/ic/property_box.cpp | 2 +- ecmascript/ic/property_box.h | 4 +- ecmascript/ic/proto_change_details.cpp | 10 +- ecmascript/ic/proto_change_details.h | 4 +- ecmascript/ic/tests/ic_handler_test.cpp | 16 +- ecmascript/ic/tests/ic_runtime_stub_test.cpp | 38 +- ecmascript/ic/tests/ic_runtime_test.cpp | 26 +- .../ic/tests/profile_type_info_test.cpp | 64 +- ecmascript/ic/tests/properties_cache_test.cpp | 20 +- ecmascript/ic/tests/property_box_test.cpp | 10 +- .../ic/tests/proto_change_details_test.cpp | 20 +- .../interpreter/fast_runtime_stub-inl.h | 23 +- ecmascript/interpreter/fast_runtime_stub.h | 2 +- ecmascript/interpreter/frame_handler.cpp | 14 +- ecmascript/interpreter/frame_handler.h | 9 +- ecmascript/interpreter/interpreter-inl.cpp | 523 +-- ecmascript/interpreter/interpreter-inl.h | 4 +- ecmascript/interpreter/interpreter.h | 8 +- .../interpreter/interpreter_assembly.cpp | 626 +-- ecmascript/interpreter/interpreter_assembly.h | 12 +- ecmascript/interpreter/slow_runtime_stub.cpp | 6 +- ecmascript/intl/global_intl_helper.cpp | 6 +- ecmascript/intl/global_intl_helper.h | 2 +- ecmascript/intl/locale_helper.cpp | 20 +- ecmascript/intl/locale_helper.h | 6 +- ecmascript/jit/compile_decision.cpp | 24 +- ecmascript/jit/jit.cpp | 9 +- ecmascript/jit/jit.h | 2 +- ecmascript/jit/jit_dfx.cpp | 12 +- ecmascript/jit/jit_dfx.h | 4 +- ecmascript/jit/jit_profiler.cpp | 104 +- ecmascript/jit/jit_task.cpp | 24 +- ecmascript/jobs/micro_job_queue.cpp | 22 +- ecmascript/jobs/pending_job.h | 8 +- .../jobs/tests/micro_job_queue_test.cpp | 62 +- ecmascript/jobs/tests/pending_job_test.cpp | 41 +- ecmascript/js_api/js_api_arraylist.cpp | 112 +- ecmascript/js_api/js_api_arraylist.h | 9 +- .../js_api/js_api_arraylist_iterator.cpp | 4 +- ecmascript/js_api/js_api_bitvector.cpp | 38 +- ecmascript/js_api/js_api_bitvector.h | 2 +- .../js_api/js_api_bitvector_iterator.cpp | 2 +- ecmascript/js_api/js_api_buffer.cpp | 200 +- ecmascript/js_api/js_api_buffer.h | 18 +- ecmascript/js_api/js_api_deque.cpp | 72 +- ecmascript/js_api/js_api_deque.h | 10 +- ecmascript/js_api/js_api_deque_iterator.cpp | 6 +- ecmascript/js_api/js_api_hasharray_iterator.h | 22 +- ecmascript/js_api/js_api_hashmap.cpp | 64 +- ecmascript/js_api/js_api_hashmap.h | 4 +- ecmascript/js_api/js_api_hashmap_iterator.cpp | 10 +- ecmascript/js_api/js_api_hashset.cpp | 16 +- ecmascript/js_api/js_api_hashset_iterator.cpp | 8 +- ecmascript/js_api/js_api_lightweightmap.cpp | 64 +- ecmascript/js_api/js_api_lightweightmap.h | 4 +- .../js_api/js_api_lightweightmap_iterator.cpp | 6 +- ecmascript/js_api/js_api_lightweightset.cpp | 113 +- ecmascript/js_api/js_api_lightweightset.h | 12 +- .../js_api/js_api_lightweightset_iterator.cpp | 6 +- ecmascript/js_api/js_api_linked_list.cpp | 74 +- ecmascript/js_api/js_api_linked_list.h | 16 +- .../js_api/js_api_linked_list_iterator.cpp | 8 +- ecmascript/js_api/js_api_list.cpp | 82 +- ecmascript/js_api/js_api_list.h | 18 +- ecmascript/js_api/js_api_list_iterator.cpp | 8 +- ecmascript/js_api/js_api_plain_array.cpp | 116 +- ecmascript/js_api/js_api_plain_array.h | 14 +- .../js_api/js_api_plain_array_iterator.cpp | 10 +- ecmascript/js_api/js_api_queue.cpp | 60 +- ecmascript/js_api/js_api_queue.h | 8 +- ecmascript/js_api/js_api_queue_iterator.cpp | 2 +- ecmascript/js_api/js_api_stack.cpp | 40 +- ecmascript/js_api/js_api_stack.h | 8 +- ecmascript/js_api/js_api_stack_iterator.cpp | 4 +- ecmascript/js_api/js_api_tree_map.cpp | 36 +- ecmascript/js_api/js_api_tree_map.h | 6 +- .../js_api/js_api_tree_map_iterator.cpp | 18 +- ecmascript/js_api/js_api_tree_set.cpp | 30 +- ecmascript/js_api/js_api_tree_set.h | 4 +- .../js_api/js_api_tree_set_iterator.cpp | 16 +- ecmascript/js_api/js_api_vector.cpp | 74 +- ecmascript/js_api/js_api_vector.h | 8 +- ecmascript/js_api/js_api_vector_iterator.cpp | 2 +- ecmascript/js_arguments.cpp | 2 +- ecmascript/js_array.cpp | 93 +- ecmascript/js_array.h | 6 +- ecmascript/js_array_iterator.cpp | 2 +- ecmascript/js_arraybuffer.cpp | 2 +- ecmascript/js_arraybuffer.h | 4 +- ecmascript/js_async_from_sync_iterator.cpp | 6 +- ecmascript/js_async_function.cpp | 24 +- ecmascript/js_async_generator_object.cpp | 56 +- ecmascript/js_bigint.h | 2 +- ecmascript/js_collator.cpp | 83 +- ecmascript/js_collator.h | 9 +- ecmascript/js_date.cpp | 22 +- ecmascript/js_date.h | 4 +- ecmascript/js_date_time_format.cpp | 58 +- ecmascript/js_date_time_format.h | 6 +- ecmascript/js_displaynames.cpp | 38 +- ecmascript/js_displaynames.h | 2 +- ecmascript/js_finalization_registry.cpp | 56 +- ecmascript/js_finalization_registry.h | 6 +- ecmascript/js_for_in_iterator.cpp | 33 +- ecmascript/js_for_in_iterator.h | 5 +- ecmascript/js_function.cpp | 177 +- ecmascript/js_function.h | 93 +- ecmascript/js_generator_object.cpp | 10 +- ecmascript/js_handle.h | 6 +- ecmascript/js_hclass-inl.h | 103 +- ecmascript/js_hclass.cpp | 242 +- ecmascript/js_hclass.h | 51 +- ecmascript/js_iterator.cpp | 10 +- ecmascript/js_list_format.cpp | 14 +- ecmascript/js_list_format.h | 2 +- ecmascript/js_locale.cpp | 48 +- ecmascript/js_locale.h | 14 +- ecmascript/js_map.cpp | 28 +- ecmascript/js_map.h | 6 +- ecmascript/js_map_iterator.cpp | 24 +- ecmascript/js_number_format.cpp | 48 +- ecmascript/js_number_format.h | 18 +- ecmascript/js_object-inl.h | 60 +- ecmascript/js_object.cpp | 413 +- ecmascript/js_object.h | 59 +- ecmascript/js_plural_rules.cpp | 36 +- ecmascript/js_plural_rules.h | 4 +- ecmascript/js_primitive_ref.cpp | 4 +- ecmascript/js_primitive_ref.h | 30 +- ecmascript/js_promise.cpp | 14 +- ecmascript/js_proxy.cpp | 106 +- ecmascript/js_regexp_iterator.cpp | 6 +- ecmascript/js_relative_time_format.cpp | 62 +- ecmascript/js_relative_time_format.h | 6 +- ecmascript/js_segment_iterator.cpp | 8 +- ecmascript/js_segment_iterator.h | 12 +- ecmascript/js_segmenter.cpp | 4 +- ecmascript/js_segmenter.h | 6 +- ecmascript/js_segments.cpp | 14 +- ecmascript/js_segments.h | 12 +- ecmascript/js_set.cpp | 20 +- ecmascript/js_set.h | 4 +- ecmascript/js_set_iterator.cpp | 16 +- ecmascript/js_stable_array.cpp | 251 +- ecmascript/js_stable_array.h | 33 +- ecmascript/js_symbol.h | 8 +- ecmascript/js_tagged_value-inl.h | 66 +- ecmascript/js_tagged_value.cpp | 76 +- ecmascript/js_tagged_value.h | 56 +- ecmascript/js_thread.cpp | 10 +- ecmascript/js_typed_array.cpp | 112 +- ecmascript/js_typed_array.h | 4 +- ecmascript/js_weak_container.cpp | 40 +- ecmascript/js_weak_container.h | 10 +- ecmascript/js_weak_ref.h | 6 +- .../jspandafile/class_info_extractor.cpp | 176 +- .../jspandafile/literal_data_extractor.cpp | 8 +- .../jspandafile/panda_file_translator.cpp | 8 +- ecmascript/jspandafile/program_object.cpp | 32 +- ecmascript/jspandafile/program_object.h | 100 +- .../jspandafile/scope_info_extractor.cpp | 10 +- .../tests/js_pandafile_manager_test.cpp | 4 +- .../tests/panda_file_translator_test.cpp | 8 +- ecmascript/layout_info-inl.h | 79 +- ecmascript/layout_info.cpp | 60 +- ecmascript/layout_info.h | 28 +- ecmascript/lexical_env.h | 16 +- ecmascript/linked_hash_table.cpp | 6 +- ecmascript/linked_hash_table.h | 64 +- ecmascript/mem/barriers-inl.h | 25 +- ecmascript/mem/barriers.h | 21 +- ecmascript/mem/c_string.cpp | 22 +- ecmascript/mem/c_string.h | 8 +- ecmascript/mem/dynamic_object_operator.h | 6 +- ecmascript/mem/full_gc-inl.h | 5 +- ecmascript/mem/machine_code.cpp | 11 +- ecmascript/mem/machine_code.h | 9 +- ecmascript/mem/old_gc_visitor-inl.h | 5 +- ecmascript/mem/parallel_evacuator-inl.h | 5 +- ecmascript/mem/parallel_evacuator.cpp | 10 +- .../mem/parallel_evacuator_visitor-inl.h | 9 +- ecmascript/mem/parallel_evacuator_visitor.h | 1 + .../mem/shared_heap/shared_full_gc-inl.h | 4 +- .../mem/shared_heap/shared_gc_evacuator.cpp | 4 +- .../mem/shared_heap/shared_gc_visitor-inl.h | 4 +- ecmascript/mem/verification.h | 7 +- ecmascript/mem/work_manager-inl.h | 5 + ecmascript/mem/work_manager.h | 2 + ecmascript/mem/young_gc_visitor-inl.h | 5 +- ecmascript/method.cpp | 40 +- ecmascript/method.h | 18 +- ecmascript/module/js_module_deregister.cpp | 8 +- ecmascript/module/js_module_deregister.h | 2 +- ecmascript/module/js_module_manager.cpp | 39 +- ecmascript/module/js_module_manager.h | 4 +- ecmascript/module/js_module_namespace.cpp | 41 +- ecmascript/module/js_module_source_text.cpp | 277 +- ecmascript/module/js_module_source_text.h | 11 +- ecmascript/module/js_shared_module.cpp | 14 +- ecmascript/module/module_logger.cpp | 8 +- ecmascript/module/module_message_helper.h | 6 +- ecmascript/module/module_path_helper.cpp | 4 +- ecmascript/module/module_path_helper.h | 2 +- ecmascript/module/module_resolver.cpp | 4 +- ecmascript/module/module_value_accessor.cpp | 76 +- ecmascript/module/tests/ecma_module_test.cpp | 24 +- ecmascript/napi/jsnapi.cpp | 35 +- ecmascript/napi/jsnapi_expo.cpp | 198 +- ecmascript/napi/test/ffi_workload.cpp | 2 +- ecmascript/napi/test/jsnapi_first_tests.cpp | 58 +- ecmascript/napi/test/jsnapi_second_tests.cpp | 16 +- ecmascript/napi/test/jsnapi_third_tests.cpp | 4 +- ecmascript/object_factory-inl.h | 2 +- ecmascript/object_factory.cpp | 191 +- ecmascript/object_factory.h | 4 +- ecmascript/object_fast_operator-inl.h | 156 +- ecmascript/object_fast_operator.h | 6 +- ecmascript/object_operator.cpp | 123 +- ecmascript/object_operator.h | 2 +- ecmascript/ohos/ohos_pkg_args.h | 10 +- ecmascript/patch/patch_loader.cpp | 50 +- ecmascript/patch/quick_fix_manager.cpp | 2 +- ecmascript/pgo_profiler/pgo_extra_profiler.h | 24 +- ecmascript/pgo_profiler/pgo_profiler.cpp | 318 +- ecmascript/pgo_profiler/pgo_profiler.h | 4 +- ecmascript/pgo_profiler/pgo_profiler_info.cpp | 33 +- ecmascript/pgo_profiler/pgo_profiler_info.h | 10 +- .../pgo_profiler/pgo_profiler_layout.cpp | 24 +- ecmascript/pgo_profiler/pgo_profiler_layout.h | 9 +- ecmascript/pgo_profiler/pgo_trace.h | 10 +- .../pgo_profiler/types/pgo_type_generator.h | 4 +- ecmascript/property_accessor.cpp | 30 +- ecmascript/regexp/regexp_parser_cache.cpp | 16 +- ecmascript/regexp/regexp_parser_cache.h | 8 +- ecmascript/require/js_cjs_module.cpp | 6 +- ecmascript/require/js_cjs_module_cache.cpp | 8 +- ecmascript/require/js_cjs_module_cache.h | 29 +- .../require/tests/js_cjs_manager_test.cpp | 2 +- .../tests/js_cjs_module_cache_test.cpp | 10 +- ecmascript/sendable_env.h | 12 +- ecmascript/serializer/base_deserializer.cpp | 41 +- ecmascript/serializer/base_serializer-inl.h | 4 +- ecmascript/serializer/base_serializer.cpp | 24 +- ecmascript/serializer/base_serializer.h | 4 + .../serializer/tests/serializer_test.cpp | 142 +- ecmascript/serializer/value_serializer.cpp | 19 +- ecmascript/shared_object_factory.cpp | 16 +- .../js_sendable_arraybuffer.cpp | 2 +- .../shared_objects/js_sendable_arraybuffer.h | 4 +- ecmascript/shared_objects/js_shared_array.cpp | 16 +- ecmascript/shared_objects/js_shared_array.h | 8 +- .../js_shared_array_iterator.cpp | 2 +- ecmascript/shared_objects/js_shared_map.cpp | 16 +- .../shared_objects/js_shared_map_iterator.cpp | 10 +- ecmascript/shared_objects/js_shared_set.cpp | 12 +- .../shared_objects/js_shared_set_iterator.cpp | 10 +- .../snapshot/mem/snapshot_processor.cpp | 15 +- ecmascript/snapshot/tests/snapshot_test.cpp | 60 +- .../stubs/runtime_optimized_stubs-inl.h | 16 +- ecmascript/stubs/runtime_stubs-inl.h | 269 +- ecmascript/stubs/runtime_stubs.cpp | 226 +- ecmascript/stubs/runtime_stubs.h | 26 +- ecmascript/stubs/test_runtime_stubs.cpp | 12 +- ecmascript/symbol_table.h | 26 +- ecmascript/tagged_array-inl.h | 12 +- ecmascript/tagged_array.cpp | 31 +- ecmascript/tagged_array.h | 11 +- ecmascript/tagged_dictionary.cpp | 98 +- ecmascript/tagged_dictionary.h | 44 +- ecmascript/tagged_hash_array.cpp | 89 +- ecmascript/tagged_hash_table.h | 88 +- ecmascript/tagged_list.cpp | 218 +- ecmascript/tagged_list.h | 66 +- ecmascript/tagged_node.cpp | 176 +- ecmascript/tagged_node.h | 12 +- ecmascript/tagged_queue.h | 64 +- ecmascript/tagged_tree.cpp | 34 +- ecmascript/tagged_tree.h | 78 +- ecmascript/template_map.h | 6 +- ecmascript/template_string.cpp | 4 +- ecmascript/tests/accessor_data_test.cpp | 12 +- ecmascript/tests/base_string_test.cpp | 180 +- ecmascript/tests/dump_test.cpp | 20 +- .../tests/ecma_string_accessor_test.cpp | 206 +- ecmascript/tests/ecma_string_hash_test.cpp | 5 +- ecmascript/tests/ecma_string_table_test.cpp | 65 +- ecmascript/tests/ecma_test_common.h | 105 +- ecmascript/tests/gc_region_promotion_test.cpp | 16 +- ecmascript/tests/global_dictionary_test.cpp | 58 +- ecmascript/tests/huge_object_test.cpp | 2 +- .../tests/js_api_arraylist_iterator_test.cpp | 2 +- ecmascript/tests/js_api_arraylist_test.cpp | 81 +- .../tests/js_api_bitvector_iterator_test.cpp | 2 +- ecmascript/tests/js_api_bitvector_test.cpp | 20 +- .../tests/js_api_deque_iterator_test.cpp | 6 +- ecmascript/tests/js_api_deque_test.cpp | 20 +- ecmascript/tests/js_api_hashmap_test.cpp | 10 +- .../tests/js_api_lightweightmap_test.cpp | 2 +- .../tests/js_api_lightweightset_test.cpp | 26 +- .../js_api_linked_list_iterator_test.cpp | 4 +- ecmascript/tests/js_api_linked_list_test.cpp | 52 +- .../tests/js_api_list_iterator_test.cpp | 4 +- ecmascript/tests/js_api_list_test.cpp | 30 +- ecmascript/tests/js_api_plain_array_test.cpp | 20 +- .../tests/js_api_queue_iterator_test.cpp | 8 +- ecmascript/tests/js_api_queue_test.cpp | 22 +- .../tests/js_api_stack_iterator_test.cpp | 8 +- ecmascript/tests/js_api_stack_test.cpp | 30 +- .../tests/js_api_tree_map_iterator_test.cpp | 10 +- ecmascript/tests/js_api_tree_map_test.cpp | 20 +- .../tests/js_api_tree_set_iterator_test.cpp | 8 +- ecmascript/tests/js_api_tree_set_test.cpp | 18 +- .../tests/js_api_vector_iterator_test.cpp | 7 +- ecmascript/tests/js_api_vector_test.cpp | 30 +- ecmascript/tests/js_arguments_test.cpp | 2 +- ecmascript/tests/js_array_buffer_test.cpp | 6 +- ecmascript/tests/js_array_iterator_test.cpp | 4 +- ecmascript/tests/js_array_test.cpp | 18 +- ecmascript/tests/js_async_function_test.cpp | 12 +- ecmascript/tests/js_bigint_test.cpp | 24 +- ecmascript/tests/js_collator_test.cpp | 14 +- ecmascript/tests/js_dataview_test.cpp | 10 +- ecmascript/tests/js_date_test.cpp | 8 +- .../tests/js_date_time_format_first_test.cpp | 46 +- .../tests/js_date_time_format_second_test.cpp | 24 +- ecmascript/tests/js_displaynames_test.cpp | 26 +- .../tests/js_finalization_registry_test.cpp | 10 +- ecmascript/tests/js_function_test.cpp | 8 +- ecmascript/tests/js_hclass_test.cpp | 52 +- ecmascript/tests/js_iterator_test.cpp | 2 +- ecmascript/tests/js_list_format_test.cpp | 22 +- ecmascript/tests/js_locale_test.cpp | 30 +- ecmascript/tests/js_map_iterator_test.cpp | 16 +- ecmascript/tests/js_map_test.cpp | 18 +- ecmascript/tests/js_number_format_test.cpp | 32 +- ecmascript/tests/js_object_test.cpp | 138 +- ecmascript/tests/js_plural_rules_test.cpp | 36 +- ecmascript/tests/js_promise_test.cpp | 34 +- ecmascript/tests/js_proxy_test.cpp | 18 +- .../tests/js_relative_time_format_test.cpp | 14 +- .../tests/js_sendable_arraybuffer_test.cpp | 28 +- ecmascript/tests/js_set_iterator_test.cpp | 10 +- ecmascript/tests/js_set_test.cpp | 4 +- ecmascript/tests/js_shared_array_test.cpp | 10 +- ecmascript/tests/js_stable_array_test.cpp | 43 +- ecmascript/tests/js_symbol_test.cpp | 18 +- ecmascript/tests/js_tagged_queue_test.cpp | 54 +- ecmascript/tests/js_typed_array_test.cpp | 27 +- ecmascript/tests/layout_info_test.cpp | 14 +- ecmascript/tests/linked_hash_table_test.cpp | 6 +- ecmascript/tests/locale_helper_test.cpp | 70 +- ecmascript/tests/machine_code_test.cpp | 18 +- ecmascript/tests/native_pointer_test.cpp | 4 +- ecmascript/tests/object_factory_test.cpp | 24 +- .../tests/object_operator_first_test.cpp | 10 +- .../tests/object_operator_second_test.cpp | 24 +- .../tests/object_operator_third_test.cpp | 98 +- ecmascript/tests/rb_tree_node_test.cpp | 20 +- .../tests/shared_object_factory_test.cpp | 28 +- ecmascript/tests/symbol_table_test.cpp | 49 +- ecmascript/tests/tagged_array_test.cpp | 32 +- ecmascript/tests/tagged_dictionary_test.cpp | 28 +- ecmascript/tests/tagged_hash_array_test.cpp | 128 +- ecmascript/tests/tagged_tree_test.cpp | 38 +- ecmascript/tests/tagged_value_test.cpp | 67 +- ecmascript/tests/template_map_test.cpp | 39 +- ecmascript/tests/template_string_test.cpp | 4 +- .../tests/transitions_dictionary_test.cpp | 20 +- ecmascript/tests/weak_ref_old_gc_test.cpp | 18 +- ecmascript/tests/weak_ref_semi_gc_test.cpp | 8 +- ecmascript/tests/weak_vector_test.cpp | 10 +- ecmascript/transitions_dictionary.h | 21 +- ecmascript/vtable.cpp | 16 +- ecmascript/vtable.h | 12 +- ecmascript/weak_vector.cpp | 6 +- ecmascript/weak_vector.h | 10 +- .../arraylist_fuzzer/arraylist_fuzzer.cpp | 5 +- .../containersvectorcommon_fuzzer.h | 5 +- .../functionrefinherit_fuzzer.cpp | 6 +- .../jsvaluerefismodulenamespace_fuzzer.cpp | 2 +- .../setiteratorrefget_fuzzer.cpp | 2 +- 611 files changed, 12291 insertions(+), 11858 deletions(-) diff --git a/ecmascript/accessor_data.h b/ecmascript/accessor_data.h index 486ffbf2cb..883459e319 100644 --- a/ecmascript/accessor_data.h +++ b/ecmascript/accessor_data.h @@ -58,9 +58,9 @@ public: return GetClass()->IsInternalAccessor(); } - inline bool HasSetter() const + inline bool HasSetter(const JSThread *thread) const { - auto setter = GetSetter(); + auto setter = GetSetter(thread); // When the raw data is 0, means the InternalAccessor's setter is nullptr. return !(setter.IsUndefined() || setter.GetRawData() == 0U); } diff --git a/ecmascript/async_generator_helper.cpp b/ecmascript/async_generator_helper.cpp index 4c4b5d4313..2ee54ae47b 100644 --- a/ecmascript/async_generator_helper.cpp +++ b/ecmascript/async_generator_helper.cpp @@ -23,7 +23,7 @@ using BuiltinsPromise = builtins::BuiltinsPromise; JSTaggedValue AsyncGeneratorHelper::Next(JSThread *thread, const JSHandle &genContext, JSTaggedValue value) { - JSHandle genObject(thread, genContext->GetGeneratorObject()); + JSHandle genObject(thread, genContext->GetGeneratorObject(thread)); genObject->SetResumeResult(thread, value); genObject->SetResumeMode(AsyncGeneratorResumeMode::NEXT); @@ -34,8 +34,8 @@ JSTaggedValue AsyncGeneratorHelper::Next(JSThread *thread, const JSHandle &genContext, const JSHandle completionRecord) { - JSHandle genObject(thread, genContext->GetGeneratorObject()); - genObject->SetResumeResult(thread, completionRecord->GetValue()); + JSHandle genObject(thread, genContext->GetGeneratorObject(thread)); + genObject->SetResumeResult(thread, completionRecord->GetValue(thread)); genObject->SetResumeMode(AsyncGeneratorResumeMode::THROW); EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext); @@ -45,8 +45,8 @@ JSTaggedValue AsyncGeneratorHelper::Throw(JSThread *thread, const JSHandle &genContext, const JSHandle completionRecord) { - JSHandle genObject(thread, genContext->GetGeneratorObject()); - genObject->SetResumeResult(thread, completionRecord->GetValue()); + JSHandle genObject(thread, genContext->GetGeneratorObject(thread)); + genObject->SetResumeResult(thread, completionRecord->GetValue(thread)); genObject->SetResumeMode(AsyncGeneratorResumeMode::RETURN); EcmaInterpreter::GeneratorReEnterInterpreter(thread, genContext); diff --git a/ecmascript/base/atomic_helper.cpp b/ecmascript/base/atomic_helper.cpp index 80d7ad14e7..5306283ba2 100644 --- a/ecmascript/base/atomic_helper.cpp +++ b/ecmascript/base/atomic_helper.cpp @@ -31,7 +31,8 @@ JSTaggedValue AtomicHelper::ValidateIntegerTypedArray(JSThread *thread, JSHandle // 3. Let typeName be typedArray.[[TypedArrayName]]. // 4. Let type be the Element Type value in Table 60 for typeName. - JSHandle typeName(thread, JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName()); + JSHandle typeName(thread, + JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName(thread)); DataViewType type = JSTypedArray::GetTypeFromName(thread, typeName); // 5. If waitable is true, then @@ -77,7 +78,7 @@ uint32_t AtomicHelper::ValidateAtomicAccess(JSThread *thread, const JSHandle arrayTypeName(thread, JSTypedArray::Cast(*typedArrayObj)->GetTypedArrayName()); + JSHandle arrayTypeName(thread, JSTypedArray::Cast(*typedArrayObj)->GetTypedArrayName(thread)); DataViewType elementType = JSTypedArray::GetTypeFromName(thread, arrayTypeName); uint32_t elementSize = TypedArrayHelper::GetSizeFromType(elementType); uint32_t offset = srcObj->GetByteOffset(); @@ -96,7 +97,7 @@ JSTaggedValue AtomicHelper::AtomicStore(JSThread *thread, const JSHandle arrayTypeName(thread, - JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName()); + JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName(thread)); DataViewType type = JSTypedArray::GetTypeFromName(thread, arrayTypeName); JSHandle bufferTag; if (type == DataViewType::BIGUINT64 || type == DataViewType::BIGINT64) { @@ -125,7 +126,7 @@ JSTaggedValue AtomicHelper::AtomicLoad(JSThread *thread, const JSHandle::Cast(typedArray)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle arrayTypeName(thread, - JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName()); + JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName(thread)); DataViewType elementType = JSTypedArray::GetTypeFromName(thread, arrayTypeName); return BuiltinsArrayBuffer::GetValueFromBuffer(thread, buffer.GetTaggedValue(), indexedPosition, elementType, true); diff --git a/ecmascript/base/error_helper.cpp b/ecmascript/base/error_helper.cpp index 32bd8e5397..8e1381f916 100644 --- a/ecmascript/base/error_helper.cpp +++ b/ecmascript/base/error_helper.cpp @@ -154,7 +154,7 @@ JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, if (!message->IsUndefined()) { JSHandle handleStr = JSTaggedValue::ToString(thread, message); if (errorType != ErrorType::OOM_ERROR) { - LOG_ECMA(DEBUG) << "Throw error: " << EcmaStringAccessor(handleStr).ToCString(); + LOG_ECMA(DEBUG) << "Throw error: " << EcmaStringAccessor(handleStr).ToCString(thread); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle msgKey = globalConst->GetHandledMessageString(); @@ -246,7 +246,7 @@ CString ErrorHelper::GetJSErrorInfo(JSThread *thread, const JSHandleClearException(); errStr = thread->GetEcmaVM()->GetFactory()->NewFromStdString(""); } - return ConvertToString(*errStr); + return ConvertToString(thread, *errStr); } JSHandle ErrorHelper::GetErrorJSFunction(JSThread *thread) @@ -259,7 +259,7 @@ JSHandle ErrorHelper::GetErrorJSFunction(JSThread *thread) auto function = frameHandler.GetFunction(); if (function.IsJSFunctionBase() || function.IsJSProxy()) { - Method *method = ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(thread); if (!method->IsNativeWithCallField()) { return JSHandle(thread, function); } diff --git a/ecmascript/base/gc_helper.h b/ecmascript/base/gc_helper.h index d2f007c9e3..0d5d7c9bb7 100644 --- a/ecmascript/base/gc_helper.h +++ b/ecmascript/base/gc_helper.h @@ -23,50 +23,50 @@ namespace panda::ecmascript::base { class GCHelper { public: - static inline void CopyCallTarget(void *callTargetToRef) + static inline void CopyCallTarget(const JSThread *thread, void *callTargetToRef) { if (!JSTaggedValue(static_cast(ToUintPtr(callTargetToRef))).IsHeapObject()) { return; } - Barriers::UpdateSlot(callTargetToRef, TaggedObject::HCLASS_OFFSET); + Barriers::UpdateSlot(thread, callTargetToRef, TaggedObject::HCLASS_OFFSET); if (JSTaggedValue(reinterpret_cast(callTargetToRef)).IsJSProxy()) { TaggedObject *methodToRef = reinterpret_cast( - Barriers::UpdateSlot(callTargetToRef, JSProxy::METHOD_OFFSET)); - Barriers::UpdateSlot(methodToRef, Method::CONSTANT_POOL_OFFSET); + Barriers::UpdateSlot(thread, callTargetToRef, JSProxy::METHOD_OFFSET)); + Barriers::UpdateSlot(thread, methodToRef, Method::CONSTANT_POOL_OFFSET); } else if (JSTaggedValue(reinterpret_cast(callTargetToRef)).IsJSFunctionBase()) { TaggedObject *methodToRef = reinterpret_cast( - Barriers::UpdateSlot(callTargetToRef, JSFunctionBase::METHOD_OFFSET)); - Barriers::UpdateSlot(methodToRef, Method::CONSTANT_POOL_OFFSET); + Barriers::UpdateSlot(thread, callTargetToRef, JSFunctionBase::METHOD_OFFSET)); + Barriers::UpdateSlot(thread, methodToRef, Method::CONSTANT_POOL_OFFSET); if (JSTaggedValue(reinterpret_cast(callTargetToRef)).IsJSFunction()) { TaggedObject *profileTypeInfoToRef = reinterpret_cast( - Barriers::UpdateSlot(callTargetToRef, JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET)); - Barriers::UpdateSlot(profileTypeInfoToRef, ProfileTypeInfoCell::VALUE_OFFSET); - Barriers::UpdateSlot(callTargetToRef, JSFunction::LEXICAL_ENV_OFFSET); + Barriers::UpdateSlot(thread, callTargetToRef, JSFunction::RAW_PROFILE_TYPE_INFO_OFFSET)); + Barriers::UpdateSlot(thread, profileTypeInfoToRef, ProfileTypeInfoCell::VALUE_OFFSET); + Barriers::UpdateSlot(thread, callTargetToRef, JSFunction::LEXICAL_ENV_OFFSET); } } else { ASSERT(!JSTaggedValue(reinterpret_cast(callTargetToRef)).IsCallable()); } } - static inline void CopyArgvArray(void *argvToRef, uint64_t argc) + static inline void CopyArgvArray(const JSThread *thread, void *argvToRef, uint64_t argc) { for (uint64_t i = 0; i < argc; i++) { size_t offset = i * sizeof(JSTaggedType) + TaggedArray::DATA_OFFSET; - Barriers::UpdateSlot(argvToRef, offset); + Barriers::UpdateSlot(thread, argvToRef, offset); } } - static inline void CopyGeneratorContext(void *contextToRef) + static inline void CopyGeneratorContext(const JSThread *thread, void *contextToRef) { - Barriers::UpdateSlot(contextToRef, GeneratorContext::GENERATOR_METHOD_OFFSET); - Barriers::UpdateSlot(contextToRef, GeneratorContext::GENERATOR_THIS_OFFSET); - Barriers::UpdateSlot(contextToRef, GeneratorContext::GENERATOR_LEXICALENV_OFFSET); - Barriers::UpdateSlot(contextToRef, GeneratorContext::GENERATOR_ACC_OFFSET); + Barriers::UpdateSlot(thread, contextToRef, GeneratorContext::GENERATOR_METHOD_OFFSET); + Barriers::UpdateSlot(thread, contextToRef, GeneratorContext::GENERATOR_THIS_OFFSET); + Barriers::UpdateSlot(thread, contextToRef, GeneratorContext::GENERATOR_LEXICALENV_OFFSET); + Barriers::UpdateSlot(thread, contextToRef, GeneratorContext::GENERATOR_ACC_OFFSET); TaggedObject *argvToRef = reinterpret_cast( - Barriers::UpdateSlot(contextToRef, GeneratorContext::GENERATOR_REGS_ARRAY_OFFSET)); + Barriers::UpdateSlot(thread, contextToRef, GeneratorContext::GENERATOR_REGS_ARRAY_OFFSET)); uint64_t argc = static_cast( - Barriers::GetValue(contextToRef, GeneratorContext::GENERATOR_NREGS_OFFSET)); - CopyArgvArray(argvToRef, argc); + Barriers::GetPrimitive(contextToRef, GeneratorContext::GENERATOR_NREGS_OFFSET)); + CopyArgvArray(thread, argvToRef, argc); } }; } diff --git a/ecmascript/base/json_parser.cpp b/ecmascript/base/json_parser.cpp index d49b396165..24e0556d1f 100644 --- a/ecmascript/base/json_parser.cpp +++ b/ecmascript/base/json_parser.cpp @@ -487,7 +487,7 @@ JSTaggedValue JsonParser::SetPropertyByValue(const JSHandle &r if (!stringAccessor.IsLineString() || (stringAccessor.IsUtf8() && IsNumberCharacter(*stringAccessor.GetDataUtf8()))) { uint32_t index = 0; - if (stringAccessor.ToElementIndex(&index)) { + if (stringAccessor.ToElementIndex(thread_, &index)) { return ObjectFastOperator::SetPropertyByIndex(thread_, receiver.GetTaggedValue(), index, value.GetTaggedValue()); } @@ -1109,7 +1109,7 @@ JSHandle Utf8JsonParser::Parse(const JSHandle &strHan } else if (stringAccessor.IsSlicedString()) { auto *sliced = static_cast(*strHandle); slicedOffset = sliced->GetStartIndex(); - sourceString_ = JSHandle(thread_, EcmaString::Cast(sliced->GetParent())); + sourceString_ = JSHandle(thread_, EcmaString::Cast(sliced->GetParent(thread_))); } else { auto *flatten = EcmaStringAccessor::Flatten(thread_->GetEcmaVM(), strHandle); sourceString_ = JSHandle(thread_, flatten); @@ -1159,7 +1159,7 @@ JSHandle Utf8JsonParser::ParseString(bool inObjOrArrOrMap) if (strLength == 1 && EcmaStringAccessor::IsASCIICharacter(utf8Data[0])) { int32_t ch = static_cast(utf8Data[0]); JSHandle singleCharTable(thread_, thread_->GetSingleCharTable()); - return JSHandle(thread_, singleCharTable->GetStringFromSingleCharTable(ch)); + return JSHandle(thread_, singleCharTable->GetStringFromSingleCharTable(thread_, ch)); } return JSHandle::Cast(factory_->NewCompressedUtf8SubString( sourceString_, offset, strLength)); @@ -1222,7 +1222,7 @@ JSHandle Utf16JsonParser::Parse(EcmaString *str) ASSERT(str != nullptr); uint32_t len = EcmaStringAccessor(str).GetLength(); CVector buf(len + 1, 0); - EcmaStringAccessor(str).WriteToFlatUtf16(buf.data(), len); + EcmaStringAccessor(str).WriteToFlatUtf16(thread_, buf.data(), len); Text begin = buf.data(); return Launch(begin, begin + len); } @@ -1359,7 +1359,7 @@ JSHandle Internalize::InternalizeJsonProperty(JSThread *thread, c uint32_t namesLength = ownerNames->GetLength(); JSMutableHandle keyName(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < namesLength; i++) { - keyName.Update(ownerNames->Get(i)); + keyName.Update(ownerNames->Get(thread, i)); RecurseAndApply(thread, obj, keyName, receiver, transformType); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); } diff --git a/ecmascript/base/json_parser.h b/ecmascript/base/json_parser.h index a6bcd75dea..b348042d30 100644 --- a/ecmascript/base/json_parser.h +++ b/ecmascript/base/json_parser.h @@ -111,7 +111,8 @@ protected: JSHandle GetSJsonPrototype() { JSHandle sObjFunction(thread_->GetEcmaVM()->GetGlobalEnv()->GetSObjectFunction()); - JSHandle jsonPrototype = JSHandle(thread_, sObjFunction->GetFunctionPrototype()); + JSHandle jsonPrototype = JSHandle(thread_, + sObjFunction->GetFunctionPrototype(thread_)); return jsonPrototype; } diff --git a/ecmascript/base/json_stringifier.cpp b/ecmascript/base/json_stringifier.cpp index 4ee0aa3be8..11cec2abc3 100644 --- a/ecmascript/base/json_stringifier.cpp +++ b/ecmascript/base/json_stringifier.cpp @@ -85,7 +85,7 @@ JSHandle JsonStringifier::Stringify(const JSHandle AddDeduplicateProp(propHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); } else if (prop.IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(prop.GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(prop.GetTaggedObject())->GetValue(thread_); if (primitive.IsNumber() || primitive.IsString()) { AddDeduplicateProp(propHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); @@ -97,7 +97,7 @@ JSHandle JsonStringifier::Stringify(const JSHandle // If Type(space) is Object, then if (gap->IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(gap->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(gap->GetTaggedObject())->GetValue(thread_); // a. If space has a [[NumberData]] internal slot, then if (primitive.IsNumber()) { // i. Let space be ToNumber(space). @@ -142,7 +142,7 @@ void JsonStringifier::AddDeduplicateProp(const JSHandle &property uint32_t propLen = propList_.size(); for (uint32_t i = 0; i < propLen; i++) { - if (JSTaggedValue::SameValue(propList_[i], addVal)) { + if (JSTaggedValue::SameValue(thread_, propList_[i], addVal)) { return; } } @@ -162,7 +162,7 @@ bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) bool JsonStringifier::CalculateStringGap(const JSHandle &primString) { - CString gapString = ConvertToString(*primString, StringConvertedUsage::LOGICOPERATION); + CString gapString = ConvertToString(thread_, *primString, StringConvertedUsage::LOGICOPERATION); uint32_t gapLen = gapString.length(); if (gapLen > 0) { uint32_t gapLength = gapLen; @@ -262,7 +262,7 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle strHandle = JSHandle(valHandle); auto string = JSHandle(thread_, EcmaStringAccessor::Flatten(thread_->GetEcmaVM(), strHandle)); - CString str = ConvertToString(*string, StringConvertedUsage::LOGICOPERATION); + CString str = ConvertToString(thread_, *string, StringConvertedUsage::LOGICOPERATION); JsonHelper::AppendValueToQuotedString(str, result_); return tagValue; } @@ -330,7 +330,7 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle thisBigint(thread_, valHandle.GetTaggedValue()); auto bigIntStr = BigInt::ToString(thread_, thisBigint); - result_ += ConvertToString(*bigIntStr); + result_ += ConvertToString(thread_, *bigIntStr); return tagValue; } } @@ -433,11 +433,11 @@ void JsonStringifier::SerializeObjectKey(const JSHandle &key, boo } CString str; if (key->IsString()) { - str = ConvertToString(EcmaString::Cast(key->GetTaggedObject()), StringConvertedUsage::LOGICOPERATION); + str = ConvertToString(thread_, EcmaString::Cast(key->GetTaggedObject()), StringConvertedUsage::LOGICOPERATION); } else if (key->IsInt()) { str = NumberHelper::IntToString(static_cast(key->GetInt())); } else { - str = ConvertToString(*JSTaggedValue::ToString(thread_, key), StringConvertedUsage::LOGICOPERATION); + str = ConvertToString(thread_, *JSTaggedValue::ToString(thread_, key), StringConvertedUsage::LOGICOPERATION); } result_ += stepBegin; JsonHelper::AppendValueToQuotedString(str, result_); @@ -450,7 +450,7 @@ bool JsonStringifier::PushValue(const JSHandle &value) uint32_t thisLen = stack_.size(); for (uint32_t i = 0; i < thisLen; i++) { - bool equal = JSTaggedValue::SameValue(stack_[i].GetTaggedValue(), value.GetTaggedValue()); + bool equal = JSTaggedValue::SameValue(thread_, stack_[i].GetTaggedValue(), value.GetTaggedValue()); if (equal) { return true; } @@ -481,7 +481,7 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); uint32_t arrLength = propertyArray->GetLength(); for (uint32_t i = 0; i < arrLength; i++) { - handleKey_.Update(propertyArray->Get(i)); + handleKey_.Update(propertyArray->Get(thread_, i)); JSHandle valueHandle = JSTaggedValue::GetProperty(thread_, value, handleKey_).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); JSTaggedValue serializeValue = GetSerializeValue(value, handleKey_, valueHandle, replacer); @@ -499,7 +499,7 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, } } } else { - uint32_t numOfKeys = obj->GetNumberOfKeys(); + uint32_t numOfKeys = obj->GetNumberOfKeys(thread_); uint32_t numOfElements = obj->GetNumberOfElements(thread_); if (numOfElements > 0) { hasContent = JsonStringifier::SerializeElements(obj, replacer, hasContent); @@ -548,7 +548,7 @@ bool JsonStringifier::SerializeJSONSharedMap(const JSHandle &valu { [[maybe_unused]] ConcurrentApiScope scope(thread_, value); JSHandle sharedMap(value); - JSHandle hashMap(thread_, sharedMap->GetLinkedMap()); + JSHandle hashMap(thread_, sharedMap->GetLinkedMap(thread_)); return SerializeLinkedHashMap(hashMap, replacer); } @@ -557,7 +557,7 @@ bool JsonStringifier::SerializeJSONSharedSet(const JSHandle &valu { [[maybe_unused]] ConcurrentApiScope scope(thread_, value); JSHandle sharedSet(value); - JSHandle hashSet(thread_, sharedSet->GetLinkedSet()); + JSHandle hashSet(thread_, sharedSet->GetLinkedSet(thread_)); return SerializeLinkedHashSet(hashSet, replacer); } @@ -565,7 +565,7 @@ bool JsonStringifier::SerializeJSONMap(const JSHandle &value, const JSHandle &replacer) { JSHandle jsMap(value); - JSHandle hashMap(thread_, jsMap->GetLinkedMap()); + JSHandle hashMap(thread_, jsMap->GetLinkedMap(thread_)); return SerializeLinkedHashMap(hashMap, replacer); } @@ -573,7 +573,7 @@ bool JsonStringifier::SerializeJSONSet(const JSHandle &value, const JSHandle &replacer) { JSHandle jsSet(value); - JSHandle hashSet(thread_, jsSet->GetLinkedSet()); + JSHandle hashSet(thread_, jsSet->GetLinkedSet(thread_)); return SerializeLinkedHashSet(hashSet, replacer); } @@ -583,7 +583,7 @@ bool JsonStringifier::SerializeJSONHashMap(const JSHandle &value, CString stepback = indent_; result_ += "{"; JSHandle hashMap(value); - JSHandle table(thread_, hashMap->GetTable()); + JSHandle table(thread_, hashMap->GetTable(thread_)); uint32_t len = table->GetLength(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSMutableHandle queue(thread_, factory->NewTaggedQueue(0)); @@ -597,8 +597,8 @@ bool JsonStringifier::SerializeJSONHashMap(const JSHandle &value, if (node.GetTaggedValue().IsHole()) { continue; } - keyHandle.Update(node->GetKey()); - valueHandle.Update(node->GetValue()); + keyHandle.Update(node->GetKey(thread_)); + valueHandle.Update(node->GetValue(thread_)); if (valueHandle->IsUndefined()) { continue; } @@ -629,7 +629,7 @@ bool JsonStringifier::SerializeJSONHashSet(const JSHandle &value, CString stepback = indent_; result_ += "["; JSHandle hashSet(value); - JSHandle table(thread_, hashSet->GetTable()); + JSHandle table(thread_, hashSet->GetTable(thread_)); uint32_t len = table->GetLength(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSMutableHandle queue(thread_, factory->NewTaggedQueue(0)); @@ -642,7 +642,7 @@ bool JsonStringifier::SerializeJSONHashSet(const JSHandle &value, if (node.GetTaggedValue().IsHole()) { continue; } - currentKey.Update(node->GetKey()); + currentKey.Update(node->GetKey(thread_)); JSTaggedValue res = SerializeJSONProperty(currentKey, replacer); if (res.IsUndefined()) { result_ += "null"; @@ -670,8 +670,8 @@ bool JsonStringifier::SerializeLinkedHashMap(const JSHandle &hash JSMutableHandle valHandle(thread_, JSTaggedValue::Undefined()); bool needRemove = false; while (index < totalElements) { - keyHandle.Update(hashMap->GetKey(index++)); - valHandle.Update(hashMap->GetValue(index - 1)); + keyHandle.Update(hashMap->GetKey(thread_, index++)); + valHandle.Update(hashMap->GetValue(thread_, index - 1)); if (keyHandle->IsHole() || valHandle->IsUndefined()) { continue; } @@ -709,7 +709,7 @@ bool JsonStringifier::SerializeLinkedHashSet(const JSHandle &hash int index = 0; int totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements(); while (index < totalElements) { - keyHandle.Update(hashSet->GetKey(index++)); + keyHandle.Update(hashSet->GetKey(thread_, index++)); if (keyHandle->IsHole()) { continue; } @@ -844,17 +844,17 @@ bool JsonStringifier::SerializeJSArray(const JSHandle &value, con void JsonStringifier::SerializePrimitiveRef(const JSHandle &primitiveRef) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(primitiveRef.GetTaggedValue().GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(primitiveRef.GetTaggedValue().GetTaggedObject())->GetValue(thread_); if (primitive.IsString()) { auto priStr = JSTaggedValue::ToString(thread_, primitiveRef); RETURN_IF_ABRUPT_COMPLETION(thread_); - CString str = ConvertToString(*priStr, StringConvertedUsage::LOGICOPERATION); + CString str = ConvertToString(thread_, *priStr, StringConvertedUsage::LOGICOPERATION); JsonHelper::AppendValueToQuotedString(str, result_); } else if (primitive.IsNumber()) { auto priNum = JSTaggedValue::ToNumber(thread_, primitiveRef); RETURN_IF_ABRUPT_COMPLETION(thread_); if (std::isfinite(priNum.GetNumber())) { - result_ += ConvertToString(*base::NumberHelper::NumberToString(thread_, priNum)); + result_ += ConvertToString(thread_, *base::NumberHelper::NumberToString(thread_, priNum)); } else { result_ += "null"; } @@ -866,7 +866,7 @@ void JsonStringifier::SerializePrimitiveRef(const JSHandle &primi } else { JSHandle thisBigint(thread_, primitive); auto bigIntStr = BigInt::ToString(thread_, thisBigint); - result_ += ConvertToString(*bigIntStr); + result_ += ConvertToString(thread_, *bigIntStr); } } } @@ -874,8 +874,8 @@ void JsonStringifier::SerializePrimitiveRef(const JSHandle &primi bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSHandle &replacer, bool hasContent) { - if (!ElementAccessor::IsDictionaryMode(obj)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + if (!ElementAccessor::IsDictionaryMode(thread_, obj)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread_, obj); for (uint32_t i = 0; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread_, obj, i).IsHole()) { handleKey_.Update(JSTaggedValue(i)); @@ -885,14 +885,14 @@ bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSH } } } else { - JSHandle elementsArr(thread_, obj->GetElements()); + JSHandle elementsArr(thread_, obj->GetElements(thread_)); JSHandle numberDic(elementsArr); CVector> sortArr; int size = numberDic->Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = numberDic->GetKey(hashIndex); + JSTaggedValue key = numberDic->GetKey(thread_, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = numberDic->GetAttributes(hashIndex); + PropertyAttributes attr = numberDic->GetAttributes(thread_, hashIndex); if (attr.IsEnumerable()) { JSTaggedValue numberKey = JSTaggedValue(static_cast(key.GetInt())); sortArr.emplace_back(JSHandle(thread_, numberKey)); @@ -903,11 +903,11 @@ bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSH for (const auto &entry : sortArr) { JSTaggedValue entryKey = entry.GetTaggedValue(); handleKey_.Update(entryKey); - int index = numberDic->FindEntry(entryKey); + int index = numberDic->FindEntry(thread_, entryKey); if (index < 0) { continue; } - JSTaggedValue value = numberDic->GetValue(index); + JSTaggedValue value = numberDic->GetValue(thread_, index); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -924,28 +924,28 @@ bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSH bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandle &replacer, bool hasContent) { - JSHandle propertiesArr(thread_, obj->GetProperties()); + JSHandle propertiesArr(thread_, obj->GetProperties(thread_)); if (!propertiesArr->IsDictionaryMode()) { bool hasChangedToDictionaryMode = false; JSHandle jsHClass(thread_, obj->GetJSHClass()); - if (jsHClass->GetEnumCache().IsEnumCacheOwnValid()) { + if (jsHClass->GetEnumCache(thread_).IsEnumCacheOwnValid(thread_)) { auto cache = JSHClass::GetEnumCacheOwnWithOutCheck(thread_, jsHClass); uint32_t length = cache->GetLength(); uint32_t dictStart = length; for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = cache->Get(i); + JSTaggedValue key = cache->Get(thread_, i); if (!key.IsString()) { continue; } handleKey_.Update(key); JSTaggedValue value; - LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout(thread_).GetTaggedObject()); int index = JSHClass::FindPropertyEntry(thread_, *jsHClass, key); - PropertyAttributes attr(layoutInfo->GetAttr(index)); + PropertyAttributes attr(layoutInfo->GetAttr(thread_, index)); ASSERT(static_cast(attr.GetOffset()) == index); value = attr.IsInlinedProps() - ? obj->GetPropertyInlinedPropsWithRep(static_cast(index), attr) - : propertiesArr->Get(static_cast(index) - jsHClass->GetInlinedProperties()); + ? obj->GetPropertyInlinedPropsWithRep(thread_, static_cast(index), attr) + : propertiesArr->Get(thread_, static_cast(index) - jsHClass->GetInlinedProperties()); if (attr.IsInlinedProps() && value.IsHole()) { continue; } @@ -953,7 +953,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - if (obj->GetProperties().IsDictionary()) { + if (obj->GetProperties(thread_).IsDictionary()) { dictStart = i; handleValue_.Update(value); hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); @@ -966,17 +966,17 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } if (dictStart < length) { - propertiesArr = JSHandle(thread_, obj->GetProperties()); + propertiesArr = JSHandle(thread_, obj->GetProperties(thread_)); JSHandle nameDic(propertiesArr); for (uint32_t i = dictStart + 1;i < length; i++) { - JSTaggedValue key = cache->Get(i); - int hashIndex = nameDic->FindEntry(key); - PropertyAttributes attr = nameDic->GetAttributes(hashIndex); + JSTaggedValue key = cache->Get(thread_, i); + int hashIndex = nameDic->FindEntry(thread_, key); + PropertyAttributes attr = nameDic->GetAttributes(thread_, hashIndex); if (!key.IsString() || hashIndex < 0 || !attr.IsEnumerable()) { continue; } handleKey_.Update(key); - JSTaggedValue value = nameDic->GetValue(hashIndex); + JSTaggedValue value = nameDic->GetValue(thread_, hashIndex); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -994,16 +994,16 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl return hasContent; } for (int i = 0; i < end; i++) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout().GetTaggedObject()); - JSTaggedValue key = layoutInfo->GetKey(i); + LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout(thread_).GetTaggedObject()); + JSTaggedValue key = layoutInfo->GetKey(thread_, i); if (!hasChangedToDictionaryMode) { - PropertyAttributes attr(layoutInfo->GetAttr(i)); + PropertyAttributes attr(layoutInfo->GetAttr(thread_, i)); ASSERT(static_cast(attr.GetOffset()) == i); if (key.IsString() && attr.IsEnumerable()) { handleKey_.Update(key); JSTaggedValue value = attr.IsInlinedProps() - ? obj->GetPropertyInlinedPropsWithRep(static_cast(i), attr) - : propertiesArr->Get(static_cast(i) - jsHClass->GetInlinedProperties()); + ? obj->GetPropertyInlinedPropsWithRep(thread_, static_cast(i), attr) + : propertiesArr->Get(thread_, static_cast(i) - jsHClass->GetInlinedProperties()); if (attr.IsInlinedProps() && value.IsHole()) { continue; } @@ -1014,24 +1014,24 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl } handleValue_.Update(value); hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); - if (obj->GetProperties().IsDictionary()) { + if (obj->GetProperties(thread_).IsDictionary()) { hasChangedToDictionaryMode = true; - propertiesArr = JSHandle(thread_, obj->GetProperties()); + propertiesArr = JSHandle(thread_, obj->GetProperties(thread_)); } jsHClass = JSHandle(thread_, obj->GetJSHClass()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } else { JSHandle nameDic(propertiesArr); - int index = nameDic->FindEntry(key); + int index = nameDic->FindEntry(thread_, key); if (!key.IsString()) { continue; } - PropertyAttributes attr = nameDic->GetAttributes(index); + PropertyAttributes attr = nameDic->GetAttributes(thread_, index); if (!attr.IsEnumerable() || index < 0) { continue; } - JSTaggedValue value = nameDic->GetValue(index); + JSTaggedValue value = nameDic->GetValue(thread_, index); handleKey_.Update(key); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), @@ -1051,11 +1051,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl int size = globalDic->Size(); CVector, PropertyAttributes>> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = globalDic->GetKey(hashIndex); + JSTaggedValue key = globalDic->GetKey(thread_, hashIndex); if (!key.IsString()) { continue; } - PropertyAttributes attr = globalDic->GetAttributes(hashIndex); + PropertyAttributes attr = globalDic->GetAttributes(thread_, hashIndex); if (!attr.IsEnumerable()) { continue; } @@ -1066,11 +1066,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl for (const auto &entry : sortArr) { JSTaggedValue entryKey = entry.first.GetTaggedValue(); handleKey_.Update(entryKey); - int index = globalDic->FindEntry(entryKey); + int index = globalDic->FindEntry(thread_, entryKey); if (index == -1) { continue; } - JSTaggedValue value = globalDic->GetValue(index); + JSTaggedValue value = globalDic->GetValue(thread_, index); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -1086,11 +1086,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl int size = nameDic->Size(); CVector, PropertyAttributes>> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = nameDic->GetKey(hashIndex); + JSTaggedValue key = nameDic->GetKey(thread_, hashIndex); if (!key.IsString()) { continue; } - PropertyAttributes attr = nameDic->GetAttributes(hashIndex); + PropertyAttributes attr = nameDic->GetAttributes(thread_, hashIndex); if (!attr.IsEnumerable()) { continue; } @@ -1101,11 +1101,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl for (const auto &entry : sortArr) { JSTaggedValue entryKey = entry.first.GetTaggedValue(); handleKey_.Update(entryKey); - int index = nameDic->FindEntry(entryKey); + int index = nameDic->FindEntry(thread_, entryKey); if (index < 0) { continue; } - JSTaggedValue value = nameDic->GetValue(index); + JSTaggedValue value = nameDic->GetValue(thread_, index); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); diff --git a/ecmascript/base/json_stringifier_optimized.cpp b/ecmascript/base/json_stringifier_optimized.cpp index d63a9ec246..8a2f42c335 100644 --- a/ecmascript/base/json_stringifier_optimized.cpp +++ b/ecmascript/base/json_stringifier_optimized.cpp @@ -85,7 +85,7 @@ JSHandle JsonStringifier::Stringify(const JSHandle AddDeduplicateProp(propHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); } else if (prop.IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(prop.GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(prop.GetTaggedObject())->GetValue(thread_); if (primitive.IsNumber() || primitive.IsString()) { AddDeduplicateProp(propHandle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); @@ -97,7 +97,7 @@ JSHandle JsonStringifier::Stringify(const JSHandle // If Type(space) is Object, then if (gap->IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(gap->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(gap->GetTaggedObject())->GetValue(thread_); // a. If space has a [[NumberData]] internal slot, then if (primitive.IsNumber()) { // i. Let space be ToNumber(space). @@ -147,7 +147,7 @@ void JsonStringifier::AddDeduplicateProp(const JSHandle &property uint32_t propLen = propList_.size(); for (uint32_t i = 0; i < propLen; i++) { - if (JSTaggedValue::SameValue(propList_[i], addVal)) { + if (JSTaggedValue::SameValue(thread_, propList_[i], addVal)) { return; } } @@ -167,10 +167,10 @@ bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) bool JsonStringifier::CalculateStringGap(const JSHandle &primString) { if (EcmaStringAccessor(primString).IsUtf8()) { - EcmaStringAccessor(primString).AppendToC16String(gap_); + EcmaStringAccessor(primString).AppendToC16String(thread_, gap_); } else { ChangeEncoding(); - EcmaStringAccessor(primString).AppendToC16String(gap_); + EcmaStringAccessor(primString).AppendToC16String(thread_, gap_); } if (gap_.size() > GAP_MAX_LEN) { gap_.resize(GAP_MAX_LEN); @@ -447,7 +447,7 @@ bool JsonStringifier::PushValue(const JSHandle &value) uint32_t thisLen = stack_.size(); for (uint32_t i = 0; i < thisLen; i++) { - bool equal = JSTaggedValue::SameValue(stack_[i].GetTaggedValue(), value.GetTaggedValue()); + bool equal = JSTaggedValue::SameValue(thread_, stack_[i].GetTaggedValue(), value.GetTaggedValue()); if (equal) { return true; } @@ -477,7 +477,7 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); uint32_t arrLength = propertyArray->GetLength(); for (uint32_t i = 0; i < arrLength; i++) { - handleKey_.Update(propertyArray->Get(i)); + handleKey_.Update(propertyArray->Get(thread_, i)); JSHandle valueHandle = JSTaggedValue::GetProperty(thread_, value, handleKey_).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); JSTaggedValue serializeValue = GetSerializeValue(value, handleKey_, valueHandle, replacer); @@ -495,7 +495,7 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, } } } else { - uint32_t numOfKeys = obj->GetNumberOfKeys(); + uint32_t numOfKeys = obj->GetNumberOfKeys(thread_); uint32_t numOfElements = obj->GetNumberOfElements(thread_); if (numOfElements > 0) { hasContent = JsonStringifier::SerializeElements(obj, replacer, hasContent); @@ -543,7 +543,7 @@ bool JsonStringifier::SerializeJSONSharedMap(const JSHandle &valu { [[maybe_unused]] ConcurrentApiScope scope(thread_, value); JSHandle sharedMap(value); - JSHandle hashMap(thread_, sharedMap->GetLinkedMap()); + JSHandle hashMap(thread_, sharedMap->GetLinkedMap(thread_)); return SerializeLinkedHashMap(hashMap, replacer); } @@ -552,7 +552,7 @@ bool JsonStringifier::SerializeJSONSharedSet(const JSHandle &valu { [[maybe_unused]] ConcurrentApiScope scope(thread_, value); JSHandle sharedSet(value); - JSHandle hashSet(thread_, sharedSet->GetLinkedSet()); + JSHandle hashSet(thread_, sharedSet->GetLinkedSet(thread_)); return SerializeLinkedHashSet(hashSet, replacer); } @@ -560,7 +560,7 @@ bool JsonStringifier::SerializeJSONMap(const JSHandle &value, const JSHandle &replacer) { JSHandle jsMap(value); - JSHandle hashMap(thread_, jsMap->GetLinkedMap()); + JSHandle hashMap(thread_, jsMap->GetLinkedMap(thread_)); return SerializeLinkedHashMap(hashMap, replacer); } @@ -568,7 +568,7 @@ bool JsonStringifier::SerializeJSONSet(const JSHandle &value, const JSHandle &replacer) { JSHandle jsSet(value); - JSHandle hashSet(thread_, jsSet->GetLinkedSet()); + JSHandle hashSet(thread_, jsSet->GetLinkedSet(thread_)); return SerializeLinkedHashSet(hashSet, replacer); } @@ -577,7 +577,7 @@ bool JsonStringifier::SerializeJSONHashMap(const JSHandle &value, { AppendChar('{'); JSHandle hashMap(value); - JSHandle table(thread_, hashMap->GetTable()); + JSHandle table(thread_, hashMap->GetTable(thread_)); uint32_t len = table->GetLength(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSMutableHandle queue(thread_, factory->NewTaggedQueue(0)); @@ -591,8 +591,8 @@ bool JsonStringifier::SerializeJSONHashMap(const JSHandle &value, if (node.GetTaggedValue().IsHole()) { continue; } - keyHandle.Update(node->GetKey()); - valueHandle.Update(node->GetValue()); + keyHandle.Update(node->GetKey(thread_)); + valueHandle.Update(node->GetValue(thread_)); if (valueHandle->IsUndefined()) { continue; } @@ -621,7 +621,7 @@ bool JsonStringifier::SerializeJSONHashSet(const JSHandle &value, { AppendChar('['); JSHandle hashSet(value); - JSHandle table(thread_, hashSet->GetTable()); + JSHandle table(thread_, hashSet->GetTable(thread_)); uint32_t len = table->GetLength(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSMutableHandle queue(thread_, factory->NewTaggedQueue(0)); @@ -634,7 +634,7 @@ bool JsonStringifier::SerializeJSONHashSet(const JSHandle &value, if (node.GetTaggedValue().IsHole()) { continue; } - currentKey.Update(node->GetKey()); + currentKey.Update(node->GetKey(thread_)); JSTaggedValue res = SerializeJSONProperty(currentKey, replacer); if (res.IsUndefined()) { AppendLiteral("null"); @@ -660,8 +660,8 @@ bool JsonStringifier::SerializeLinkedHashMap(const JSHandle &hash JSMutableHandle valHandle(thread_, JSTaggedValue::Undefined()); bool needRemove = false; while (index < totalElements) { - keyHandle.Update(hashMap->GetKey(index++)); - valHandle.Update(hashMap->GetValue(index - 1)); + keyHandle.Update(hashMap->GetKey(thread_, index++)); + valHandle.Update(hashMap->GetValue(thread_, index - 1)); if (keyHandle->IsHole() || valHandle->IsUndefined()) { continue; } @@ -697,7 +697,7 @@ bool JsonStringifier::SerializeLinkedHashSet(const JSHandle &hash int index = 0; int totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements(); while (index < totalElements) { - keyHandle.Update(hashSet->GetKey(index++)); + keyHandle.Update(hashSet->GetKey(thread_, index++)); if (keyHandle->IsHole()) { continue; } @@ -820,7 +820,7 @@ bool JsonStringifier::SerializeJSArray(const JSHandle &value, con void JsonStringifier::SerializePrimitiveRef(const JSHandle &primitiveRef) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(primitiveRef.GetTaggedValue().GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(primitiveRef.GetTaggedValue().GetTaggedObject())->GetValue(thread_); if (primitive.IsString()) { auto priStr = JSTaggedValue::ToString(thread_, primitiveRef); RETURN_IF_ABRUPT_COMPLETION(thread_); @@ -852,8 +852,8 @@ void JsonStringifier::SerializePrimitiveRef(const JSHandle &primi bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSHandle &replacer, bool hasContent) { - if (!ElementAccessor::IsDictionaryMode(obj)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + if (!ElementAccessor::IsDictionaryMode(thread_, obj)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread_, obj); for (uint32_t i = 0; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread_, obj, i).IsHole()) { handleKey_.Update(JSTaggedValue(i)); @@ -863,14 +863,14 @@ bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSH } } } else { - JSHandle elementsArr(thread_, obj->GetElements()); + JSHandle elementsArr(thread_, obj->GetElements(thread_)); JSHandle numberDic(elementsArr); CVector> sortArr; int size = numberDic->Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = numberDic->GetKey(hashIndex); + JSTaggedValue key = numberDic->GetKey(thread_, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = numberDic->GetAttributes(hashIndex); + PropertyAttributes attr = numberDic->GetAttributes(thread_, hashIndex); if (attr.IsEnumerable()) { JSTaggedValue numberKey = JSTaggedValue(static_cast(key.GetInt())); sortArr.emplace_back(JSHandle(thread_, numberKey)); @@ -881,11 +881,11 @@ bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSH for (const auto &entry : sortArr) { JSTaggedValue entryKey = entry.GetTaggedValue(); handleKey_.Update(entryKey); - int index = numberDic->FindEntry(entryKey); + int index = numberDic->FindEntry(thread_, entryKey); if (index < 0) { continue; } - JSTaggedValue value = numberDic->GetValue(index); + JSTaggedValue value = numberDic->GetValue(thread_, index); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -902,28 +902,28 @@ bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSH bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandle &replacer, bool hasContent) { - JSHandle propertiesArr(thread_, obj->GetProperties()); + JSHandle propertiesArr(thread_, obj->GetProperties(thread_)); if (!propertiesArr->IsDictionaryMode()) { bool hasChangedToDictionaryMode = false; JSHandle jsHClass(thread_, obj->GetJSHClass()); - if (jsHClass->GetEnumCache().IsEnumCacheOwnValid()) { + if (jsHClass->GetEnumCache(thread_).IsEnumCacheOwnValid(thread_)) { auto cache = JSHClass::GetEnumCacheOwnWithOutCheck(thread_, jsHClass); uint32_t length = cache->GetLength(); uint32_t dictStart = length; for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = cache->Get(i); + JSTaggedValue key = cache->Get(thread_, i); if (!key.IsString()) { continue; } handleKey_.Update(key); JSTaggedValue value; - LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout(thread_).GetTaggedObject()); int index = JSHClass::FindPropertyEntry(thread_, *jsHClass, key); - PropertyAttributes attr(layoutInfo->GetAttr(index)); + PropertyAttributes attr(layoutInfo->GetAttr(thread_, index)); ASSERT(static_cast(attr.GetOffset()) == index); value = attr.IsInlinedProps() - ? obj->GetPropertyInlinedPropsWithRep(static_cast(index), attr) - : propertiesArr->Get(static_cast(index) - jsHClass->GetInlinedProperties()); + ? obj->GetPropertyInlinedPropsWithRep(thread_, static_cast(index), attr) + : propertiesArr->Get(thread_, static_cast(index) - jsHClass->GetInlinedProperties()); if (attr.IsInlinedProps() && value.IsHole()) { continue; } @@ -931,7 +931,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - if (obj->GetProperties().IsDictionary()) { + if (obj->GetProperties(thread_).IsDictionary()) { dictStart = i; handleValue_.Update(value); hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); @@ -944,17 +944,17 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } if (dictStart < length) { - propertiesArr = JSHandle(thread_, obj->GetProperties()); + propertiesArr = JSHandle(thread_, obj->GetProperties(thread_)); JSHandle nameDic(propertiesArr); for (uint32_t i = dictStart + 1;i < length; i++) { - JSTaggedValue key = cache->Get(i); - int hashIndex = nameDic->FindEntry(key); - PropertyAttributes attr = nameDic->GetAttributes(hashIndex); + JSTaggedValue key = cache->Get(thread_, i); + int hashIndex = nameDic->FindEntry(thread_, key); + PropertyAttributes attr = nameDic->GetAttributes(thread_, hashIndex); if (!key.IsString() || hashIndex < 0 || !attr.IsEnumerable()) { continue; } handleKey_.Update(key); - JSTaggedValue value = nameDic->GetValue(hashIndex); + JSTaggedValue value = nameDic->GetValue(thread_, hashIndex); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -972,16 +972,16 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl return hasContent; } for (int i = 0; i < end; i++) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout().GetTaggedObject()); - JSTaggedValue key = layoutInfo->GetKey(i); + LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHClass->GetLayout(thread_).GetTaggedObject()); + JSTaggedValue key = layoutInfo->GetKey(thread_, i); if (!hasChangedToDictionaryMode) { - PropertyAttributes attr(layoutInfo->GetAttr(i)); + PropertyAttributes attr(layoutInfo->GetAttr(thread_, i)); ASSERT(static_cast(attr.GetOffset()) == i); if (key.IsString() && attr.IsEnumerable()) { handleKey_.Update(key); JSTaggedValue value = attr.IsInlinedProps() - ? obj->GetPropertyInlinedPropsWithRep(static_cast(i), attr) - : propertiesArr->Get(static_cast(i) - jsHClass->GetInlinedProperties()); + ? obj->GetPropertyInlinedPropsWithRep(thread_, static_cast(i), attr) + : propertiesArr->Get(thread_, static_cast(i) - jsHClass->GetInlinedProperties()); if (attr.IsInlinedProps() && value.IsHole()) { continue; } @@ -992,24 +992,24 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl } handleValue_.Update(value); hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); - if (obj->GetProperties().IsDictionary()) { + if (obj->GetProperties(thread_).IsDictionary()) { hasChangedToDictionaryMode = true; - propertiesArr = JSHandle(thread_, obj->GetProperties()); + propertiesArr = JSHandle(thread_, obj->GetProperties(thread_)); } jsHClass = JSHandle(thread_, obj->GetJSHClass()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } else { JSHandle nameDic(propertiesArr); - int index = nameDic->FindEntry(key); + int index = nameDic->FindEntry(thread_, key); if (!key.IsString()) { continue; } - PropertyAttributes attr = nameDic->GetAttributes(index); + PropertyAttributes attr = nameDic->GetAttributes(thread_, index); if (!attr.IsEnumerable() || index < 0) { continue; } - JSTaggedValue value = nameDic->GetValue(index); + JSTaggedValue value = nameDic->GetValue(thread_, index); handleKey_.Update(key); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), @@ -1029,11 +1029,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl int size = globalDic->Size(); CVector, PropertyAttributes>> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = globalDic->GetKey(hashIndex); + JSTaggedValue key = globalDic->GetKey(thread_, hashIndex); if (!key.IsString()) { continue; } - PropertyAttributes attr = globalDic->GetAttributes(hashIndex); + PropertyAttributes attr = globalDic->GetAttributes(thread_, hashIndex); if (!attr.IsEnumerable()) { continue; } @@ -1044,11 +1044,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl for (const auto &entry : sortArr) { JSTaggedValue entryKey = entry.first.GetTaggedValue(); handleKey_.Update(entryKey); - int index = globalDic->FindEntry(entryKey); + int index = globalDic->FindEntry(thread_, entryKey); if (index == -1) { continue; } - JSTaggedValue value = globalDic->GetValue(index); + JSTaggedValue value = globalDic->GetValue(thread_, index); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -1064,11 +1064,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl int size = nameDic->Size(); CVector, PropertyAttributes>> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = nameDic->GetKey(hashIndex); + JSTaggedValue key = nameDic->GetKey(thread_, hashIndex); if (!key.IsString()) { continue; } - PropertyAttributes attr = nameDic->GetAttributes(hashIndex); + PropertyAttributes attr = nameDic->GetAttributes(thread_, hashIndex); if (!attr.IsEnumerable()) { continue; } @@ -1079,11 +1079,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl for (const auto &entry : sortArr) { JSTaggedValue entryKey = entry.first.GetTaggedValue(); handleKey_.Update(entryKey); - int index = nameDic->FindEntry(entryKey); + int index = nameDic->FindEntry(thread_, entryKey); if (index < 0) { continue; } - JSTaggedValue value = nameDic->GetValue(index); + JSTaggedValue value = nameDic->GetValue(thread_, index); if (UNLIKELY(value.IsAccessor())) { value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()), JSHandle(obj)); @@ -1192,13 +1192,13 @@ inline void JsonStringifier::AppendEcmaStringToResult(JSHandle &stri { if (encoding_ == Encoding::ONE_BYTE_ENCODING) { if (EcmaStringAccessor(*string).IsUtf8()) { - ConvertQuotedAndAppendToCString(oneByteResult_, *string); + ConvertQuotedAndAppendToCString(thread_, oneByteResult_, *string); } else { ChangeEncoding(); - ConvertQuotedAndAppendToC16String(twoBytesResult_, *string); + ConvertQuotedAndAppendToC16String(thread_, twoBytesResult_, *string); } } else { - ConvertQuotedAndAppendToC16String(twoBytesResult_, *string); + ConvertQuotedAndAppendToC16String(thread_, twoBytesResult_, *string); } } diff --git a/ecmascript/base/number_helper.cpp b/ecmascript/base/number_helper.cpp index 0714b02629..0bf53cbff0 100644 --- a/ecmascript/base/number_helper.cpp +++ b/ecmascript/base/number_helper.cpp @@ -143,7 +143,7 @@ JSTaggedValue NumberHelper::Int32ToString(JSThread *thread, int32_t number, uint return thread->GlobalConstants()->GetHandledZeroString().GetTaggedValue(); } JSHandle singleCharTable(thread, thread->GetSingleCharTable()); - return singleCharTable->GetStringFromSingleCharTable(ToCharCode(n)); + return singleCharTable->GetStringFromSingleCharTable(thread, ToCharCode(n)); } } else { n = static_cast(-number); @@ -557,12 +557,12 @@ void NumberHelper::ToASCIIWithNegative(std::string& tmpbuf, int digitNumber, int tmpbuf += std::to_string(p); } -JSTaggedValue NumberHelper::StringToNumber(EcmaString *string, int32_t radix) +JSTaggedValue NumberHelper::StringToNumber(JSThread *thread, EcmaString *string, int32_t radix) { bool negative = false; if ((radix == base::DECIMAL || radix == 0)) { int32_t elementIndex = 0; - if (EcmaStringAccessor(string).ToInt(&elementIndex, &negative)) { + if (EcmaStringAccessor(string).ToInt(thread, &elementIndex, &negative)) { if (elementIndex == 0 && negative == true) { return JSTaggedValue(-0.0); } @@ -570,7 +570,7 @@ JSTaggedValue NumberHelper::StringToNumber(EcmaString *string, int32_t radix) } } CVector buf; - Span str = EcmaStringAccessor(string).ToUtf8Span(buf); + Span str = EcmaStringAccessor(string).ToUtf8Span(thread, buf); JSTaggedValue result = NumberHelper::StringToDoubleWithRadix(str.begin(), str.end(), radix, &negative); if (result.GetNumber() == 0 && negative == true) { @@ -776,7 +776,7 @@ JSHandle NumberHelper::NumberToString(const JSThread *thread, JSTagg ASSERT(number.IsNumber()); JSHandle cacheTable(thread->GetGlobalEnv()->GetNumberToStringResultCache()); int entry = cacheTable->GetNumberHash(number); - JSTaggedValue cacheResult = cacheTable->FindCachedResult(entry, number); + JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, entry, number); if (cacheResult != JSTaggedValue::Undefined()) { return JSHandle::Cast(JSHandle(thread, cacheResult)); } @@ -1166,7 +1166,7 @@ JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle buf; - Span str = EcmaStringAccessor(strObj).ToUtf8Span(buf); + Span str = EcmaStringAccessor(strObj).ToUtf8Span(thread, buf); auto p = const_cast(str.begin()); auto end = str.end(); diff --git a/ecmascript/base/number_helper.h b/ecmascript/base/number_helper.h index 1018d0cf67..56f04f2162 100644 --- a/ecmascript/base/number_helper.h +++ b/ecmascript/base/number_helper.h @@ -212,7 +212,7 @@ public: static int32_t DoubleToInt(double d, size_t bits); static int32_t PUBLIC_API DoubleInRangeInt32(double d); static int32_t PUBLIC_API SaturateTruncDoubleToInt32(double d); - static JSTaggedValue StringToNumber(EcmaString *string, int32_t radix); + static JSTaggedValue StringToNumber(JSThread *thread, EcmaString *string, int32_t radix); static JSTaggedValue StringToDoubleWithRadix(const uint8_t *start, const uint8_t *end, int radix, bool *negative); static CString IntToString(int number); template diff --git a/ecmascript/base/sort_helper.cpp b/ecmascript/base/sort_helper.cpp index 1abe9dac9e..c02ba26da5 100644 --- a/ecmascript/base/sort_helper.cpp +++ b/ecmascript/base/sort_helper.cpp @@ -62,13 +62,13 @@ int TimSort::CountRunAndMakeAscending(JSThread *thread, JSHandle &a return 1; } int runLength = 2; - JSMutableHandle runHiValue(thread, array->Get(runHi)); - JSMutableHandle previousValue(thread, array->Get(runHi - 1)); + JSMutableHandle runHiValue(thread, array->Get(thread, runHi)); + JSMutableHandle previousValue(thread, array->Get(thread, runHi - 1)); double order = ArrayHelper::SortCompare(thread, fn, runHiValue, previousValue); bool isDescending = order < 0 ? true : false; previousValue.Update(runHiValue.GetTaggedValue()); for (int i = runHi + 1; i < hi; i++) { - runHiValue.Update(array->Get(i)); + runHiValue.Update(array->Get(thread, i)); order = ArrayHelper::SortCompare(thread, fn, runHiValue, previousValue); if (isDescending) { if (order >= 0) break; @@ -91,8 +91,8 @@ void TimSort::ReverseRange(JSThread *thread, JSHandle &array, int f JSMutableHandle elementLow(thread, JSTaggedValue::Undefined()); JSMutableHandle elementHigh(thread, JSTaggedValue::Undefined()); while (low < high) { - elementLow.Update(array->Get(low)); - elementHigh.Update(array->Get(high)); + elementLow.Update(array->Get(thread, low)); + elementHigh.Update(array->Get(thread, high)); array->Set(thread, low++, elementHigh); array->Set(thread, high--, elementLow); } @@ -111,11 +111,11 @@ void TimSort::BinarySort(JSThread *thread, JSHandle &array, for (; start < hi; start++) { int left = lo; int right = start; - pivotVal.Update(array->Get(right)); + pivotVal.Update(array->Get(thread, right)); ASSERT(left <= right); while (left < right) { int mid = (left + right) >> 1; - midVal.Update(array->Get(mid)); + midVal.Update(array->Get(thread, mid)); if (ArrayHelper::SortCompare(thread, fn, pivotVal, midVal) < 0) { right = mid; } else { @@ -125,7 +125,7 @@ void TimSort::BinarySort(JSThread *thread, JSHandle &array, ASSERT(left == right); for (int p = start; p > left; --p) { - tmpVal.Update(array->Get(p - 1)); + tmpVal.Update(array->Get(thread, p - 1)); array->Set(thread, p, tmpVal); } array->Set(thread, left, pivotVal); @@ -182,7 +182,7 @@ void TimSort::MergeAt(int i) } pending_.pop_back(); - JSHandle key1(thread_, elements_->Get(base2)); + JSHandle key1(thread_, elements_->Get(thread_, base2)); int k = GallopRight(elements_, key1, base1, len1, 0); ASSERT(k >= 0); base1 += k; @@ -190,7 +190,7 @@ void TimSort::MergeAt(int i) if (len1 == 0) { return; } - JSHandle key2(thread_, elements_->Get(base1 + len1 - 1)); + JSHandle key2(thread_, elements_->Get(thread_, base1 + len1 - 1)); len2 = GallopLeft(elements_, key2, base2, len2, len2 - 1); ASSERT(len2 >= 0); if (len2 == 0) { @@ -210,14 +210,14 @@ int TimSort::GallopLeft(JSHandle &array, ASSERT(len > 0 && hint >= 0 && hint < len); int lastOfs = 0; int ofs = 1; - JSHandle baseHintElement(thread_, array->Get(base + hint)); + JSHandle baseHintElement(thread_, array->Get(thread_, base + hint)); JSMutableHandle offsetElement(thread_, JSTaggedValue::Undefined()); JSMutableHandle mElement(thread_, JSTaggedValue::Undefined()); double order = ArrayHelper::SortCompare(thread_, fn_, key, baseHintElement); if (order > 0) { int maxOfs = len - hint; while (ofs < maxOfs) { - offsetElement.Update(array->Get(base + hint + ofs)); + offsetElement.Update(array->Get(thread_, base + hint + ofs)); order = ArrayHelper::SortCompare(thread_, fn_, key, offsetElement); if (order <= 0) break; @@ -235,7 +235,7 @@ int TimSort::GallopLeft(JSHandle &array, } else { int maxOfs = hint + 1; while (ofs < maxOfs) { - offsetElement.Update(array->Get(base + hint - ofs)); + offsetElement.Update(array->Get(thread_, base + hint - ofs)); order = ArrayHelper::SortCompare(thread_, fn_, key, offsetElement); if (order > 0) break; @@ -256,7 +256,7 @@ int TimSort::GallopLeft(JSHandle &array, lastOfs++; while (lastOfs < ofs) { int m = lastOfs + ((ofs - lastOfs) >> 1); - mElement.Update(array->Get(base + m)); + mElement.Update(array->Get(thread_, base + m)); if (ArrayHelper::SortCompare(thread_, fn_, key, mElement) > 0) { lastOfs = m + 1; } else { @@ -273,14 +273,14 @@ int TimSort::GallopRight(JSHandle &array, ASSERT(len > 0 && hint >= 0 && hint < len); int lastOfs = 0; int ofs = 1; - JSHandle baseHintElement(thread_, array->Get(base + hint)); + JSHandle baseHintElement(thread_, array->Get(thread_, base + hint)); JSMutableHandle offsetElement(thread_, JSTaggedValue::Undefined()); JSMutableHandle mElement(thread_, JSTaggedValue::Undefined()); double order = ArrayHelper::SortCompare(thread_, fn_, key, baseHintElement); if (order < 0) { int maxOfs = hint + 1; while (ofs < maxOfs) { - offsetElement.Update(array->Get(base + hint - ofs)); + offsetElement.Update(array->Get(thread_, base + hint - ofs)); order = ArrayHelper::SortCompare(thread_, fn_, key, offsetElement); if (order >= 0) break; @@ -299,7 +299,7 @@ int TimSort::GallopRight(JSHandle &array, } else { int maxOfs = len - hint; while (ofs < maxOfs) { - offsetElement.Update(array->Get(base + hint + ofs)); + offsetElement.Update(array->Get(thread_, base + hint + ofs)); order = ArrayHelper::SortCompare(thread_, fn_, key, offsetElement); if (order < 0) break; @@ -319,7 +319,7 @@ int TimSort::GallopRight(JSHandle &array, lastOfs++; while (lastOfs < ofs) { int m = lastOfs + ((ofs - lastOfs) >> 1); - mElement.Update(array->Get(base + m)); + mElement.Update(array->Get(thread_, base + m)); if (ArrayHelper::SortCompare(thread_, fn_, key, mElement) < 0) { ofs = m; } else { @@ -345,7 +345,7 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) int dest = base1; this->CopyArray(workArray, base1, tmpArray, cursor1, len1); - tmpElement.Update(workArray->Get(cursor2++)); + tmpElement.Update(workArray->Get(thread_, cursor2++)); workArray->Set(thread_, dest++, tmpElement); if (--len2 == 0) { @@ -354,7 +354,7 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) } if (len1 == 1) { this->CopyArray(workArray, cursor2, workArray, dest, len2); - tmpElement.Update(tmpArray->Get(cursor1)); + tmpElement.Update(tmpArray->Get(thread_, cursor1)); workArray->Set(thread_, dest + len2, tmpElement); return; } @@ -364,11 +364,11 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) int count2 = 0; do { ASSERT(len1 > 1 && len2 > 0); - cmp1Element.Update(workArray->Get(cursor2)); - cmp2Element.Update(tmpArray->Get(cursor1)); + cmp1Element.Update(workArray->Get(thread_, cursor2)); + cmp2Element.Update(tmpArray->Get(thread_, cursor1)); if (ArrayHelper::SortCompare(thread_, fn_, cmp1Element, cmp2Element) < 0) { - tmpElement.Update(workArray->Get(cursor2++)); + tmpElement.Update(workArray->Get(thread_, cursor2++)); workArray->Set(thread_, dest++, tmpElement); count2++; count1 = 0; @@ -376,7 +376,7 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) goto epilogue; } } else { - tmpElement.Update(tmpArray->Get(cursor1++)); + tmpElement.Update(tmpArray->Get(thread_, cursor1++)); workArray->Set(thread_, dest++, tmpElement); count1++; count2 = 0; @@ -388,7 +388,7 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) do { ASSERT(len1 > 1 && len2 > 0); - JSHandle cursorVal(thread_, workArray->Get(cursor2)); + JSHandle cursorVal(thread_, workArray->Get(thread_, cursor2)); count1 = GallopRight(tmpArray, cursorVal, cursor1, len1, 0); if (count1 != 0) { this->CopyArray(tmpArray, cursor1, workArray, dest, count1); @@ -399,12 +399,12 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) goto epilogue; } } - tmpElement.Update(workArray->Get(cursor2++)); + tmpElement.Update(workArray->Get(thread_, cursor2++)); workArray->Set(thread_, dest++, tmpElement); if (--len2 == 0) { goto epilogue; } - JSHandle cursorVal2(thread_, tmpArray->Get(cursor1)); + JSHandle cursorVal2(thread_, tmpArray->Get(thread_, cursor1)); count2 = GallopLeft(workArray, cursorVal2, cursor2, len2, 0); if (count2 != 0) { this->CopyArray(workArray, cursor2, workArray, dest, count2); @@ -415,7 +415,7 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) goto epilogue; } } - tmpElement.Update(tmpArray->Get(cursor1++)); + tmpElement.Update(tmpArray->Get(thread_, cursor1++)); workArray->Set(thread_, dest++, tmpElement); if (--len1 == 1) { goto epilogue; @@ -435,7 +435,7 @@ void TimSort::MergeLo(int base1, int len1, int base2, int len2) if (len1 == 1) { ASSERT(len2 > 0); this->CopyArray(workArray, cursor2, workArray, dest, len2); - tmpElement.Update(tmpArray->Get(cursor1)); + tmpElement.Update(tmpArray->Get(thread_, cursor1)); workArray->Set(thread_, dest + len2, tmpElement); } else { ASSERT(len1 != 0); @@ -458,7 +458,7 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) int cursor2 = len2 - 1; int dest = base2 + len2 - 1; - tmpElement.Update(workArray->Get(cursor1--)); + tmpElement.Update(workArray->Get(thread_, cursor1--)); workArray->Set(thread_, dest--, tmpElement); if (--len1 == 0) { @@ -469,7 +469,7 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) dest -= len1; cursor1 -= len1; this->CopyArray(workArray, cursor1 + 1, workArray, dest + 1, len1); - tmpElement.Update(tmpArray->Get(cursor2)); + tmpElement.Update(tmpArray->Get(thread_, cursor2)); workArray->Set(thread_, dest, tmpElement); return; } @@ -479,11 +479,11 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) int count2 = 0; do { ASSERT(len1 > 0 && len2 > 1); - cmp1Element.Update(workArray->Get(cursor1)); - cmp2Element.Update(tmpArray->Get(cursor2)); + cmp1Element.Update(workArray->Get(thread_, cursor1)); + cmp2Element.Update(tmpArray->Get(thread_, cursor2)); if (ArrayHelper::SortCompare(thread_, fn_, cmp2Element, cmp1Element) < 0) { - tmpElement.Update(workArray->Get(cursor1--)); + tmpElement.Update(workArray->Get(thread_, cursor1--)); workArray->Set(thread_, dest--, tmpElement); count1++; count2 = 0; @@ -491,7 +491,7 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) goto epilogue; } } else { - tmpElement.Update(tmpArray->Get(cursor2--)); + tmpElement.Update(tmpArray->Get(thread_, cursor2--)); workArray->Set(thread_, dest--, tmpElement); count2++; count1 = 0; @@ -503,7 +503,7 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) do { ASSERT(len1 > 0 && len2 > 1); - JSHandle cursorVal(thread_, tmpArray->Get(cursor2)); + JSHandle cursorVal(thread_, tmpArray->Get(thread_, cursor2)); count1 = len1 - GallopRight(workArray, cursorVal, base1, len1, len1 - 1); if (count1 != 0) { dest -= count1; @@ -514,12 +514,12 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) goto epilogue; } } - tmpElement.Update(tmpArray->Get(cursor2--)); + tmpElement.Update(tmpArray->Get(thread_, cursor2--)); workArray->Set(thread_, dest--, tmpElement); if (--len2 == 1) { goto epilogue; } - JSHandle cursorVal2(thread_, workArray->Get(cursor1)); + JSHandle cursorVal2(thread_, workArray->Get(thread_, cursor1)); count2 = len2 - GallopLeft(tmpArray, cursorVal2, 0, len2, len2 - 1); if (count2 != 0) { dest -= count2; @@ -530,7 +530,7 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) goto epilogue; } } - tmpElement.Update(workArray->Get(cursor1--)); + tmpElement.Update(workArray->Get(thread_, cursor1--)); workArray->Set(thread_, dest--, tmpElement); if (--len1 == 0) { goto epilogue; @@ -552,7 +552,7 @@ void TimSort::MergeHi(int base1, int len1, int base2, int len2) dest -= len1; cursor1 -= len1; this->CopyArray(workArray, cursor1 + 1, workArray, dest + 1, len1); - tmpElement.Update(tmpArray->Get(cursor2)); + tmpElement.Update(tmpArray->Get(thread_, cursor2)); workArray->Set(thread_, dest, tmpElement); } else { ASSERT(len2 != 0); @@ -574,14 +574,14 @@ void TimSort::CopyArray(JSHandle &src, int srcPos, int srcIdx = srcPos + length - 1; int dstIdx = dstPos + length - 1; while (srcIdx >= srcPos) { - dst->Set(thread_, dstIdx--, src->Get(srcIdx--)); + dst->Set(thread_, dstIdx--, src->Get(thread_, srcIdx--)); } } else { int srcIdx = srcPos; int dstIdx = dstPos; int to = srcPos + length; while (srcIdx < to) { - dst->Set(thread_, dstIdx++, src->Get(srcIdx++)); + dst->Set(thread_, dstIdx++, src->Get(thread_, srcIdx++)); } } } diff --git a/ecmascript/base/tests/ason_test.cpp b/ecmascript/base/tests/ason_test.cpp index b10bf02f86..a04bbd5ff9 100644 --- a/ecmascript/base/tests/ason_test.cpp +++ b/ecmascript/base/tests/ason_test.cpp @@ -29,7 +29,7 @@ public: using ParseReturnType = base::JsonHelper::ParseReturnType; using TransformType = base::JsonHelper::TransformType; - bool CheckSendableConstraint(JSTaggedValue value) const + bool CheckSendableConstraint(JSThread *thread, JSTaggedValue value) const { if (!value.IsHeapObject()) { // tagged value always follow sendable constraint. @@ -42,48 +42,48 @@ public: } if (jsHClass->IsExtensible()) { LOG_ECMA(ERROR) << "sendable check failed. obj is extensible"; - value.D(); + value.D(thread); return false; } - if (!CheckSendableProps(value, obj)) { + if (!CheckSendableProps(thread, value, obj)) { return false; } // trace proto chain - auto proto = jsHClass->GetPrototype(); + auto proto = jsHClass->GetPrototype(thread); if (!proto.IsNull() && !proto.IsJSShared()) { LOG_ECMA(ERROR) << "sendable check failed. proto is not sendable."; - value.D(); + value.D(thread); return false; } return true; } - bool CheckSendableProps(JSTaggedValue value, TaggedObject *obj) const + bool CheckSendableProps(JSThread *thread, JSTaggedValue value, TaggedObject *obj) const { auto *jsHClass = obj->GetClass(); - auto layoutValue = jsHClass->GetLayout(); + auto layoutValue = jsHClass->GetLayout(thread); if (layoutValue.IsNull()) { return true; } auto *layoutInfo = LayoutInfo::Cast(layoutValue.GetTaggedObject()); auto *jsObj = JSObject::Cast(obj); - auto *propsValue = TaggedArray::Cast(jsObj->GetProperties()); + auto *propsValue = TaggedArray::Cast(jsObj->GetProperties(thread)); if (propsValue->IsDictionaryMode()) { for (int idx = 0; idx < static_cast(jsHClass->NumberOfProps()); idx++) { - auto attr = layoutInfo->GetAttr(idx); + auto attr = layoutInfo->GetAttr(thread, idx); if (attr.IsInlinedProps()) { // Do not check inline props continue; } if (attr.IsWritable()) { LOG_ECMA(ERROR) << "sendable check failed. supposed to be un-writable. idx: " << idx; - value.D(); + value.D(thread); return false; } auto val = propsValue->Get(thread, idx - jsHClass->GetInlinedProperties()); - if (!CheckSendableConstraint(val)) { + if (!CheckSendableConstraint(thread, val)) { LOG_ECMA(ERROR) << "sendable check failed. supposed to be sendable. idx: " << idx; - value.D(); + value.D(thread); return false; } } @@ -144,7 +144,7 @@ HWTEST_F_L0(AsonParserTest, Parser_002) JSHandle handleStr4(JSTaggedValue::ToString(thread, handleMsg4)); JSHandle result4 = parser.Parse(*handleStr4); JSHandle handleEcmaStr(result4); - EXPECT_STREQ("string", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("string", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(AsonParserTest, Parser_003) @@ -156,8 +156,8 @@ HWTEST_F_L0(AsonParserTest, Parser_003) "\n,\t\r \nnull\t\r, \ntrue\t\r,123.456\t\r \n]\t\r \n}\t\r \n")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); // JSON Object JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_004) @@ -167,8 +167,8 @@ HWTEST_F_L0(AsonParserTest, Parser_004) JSHandle handleMsg(factory->NewFromASCII("[100,2.5,\"abc\"]")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); // JSON Array JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_005) @@ -178,7 +178,7 @@ HWTEST_F_L0(AsonParserTest, Parser_005) JSHandle handleMsg(factory->NewFromASCII("{\"epf\":100,\"key1\":400}")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_006) @@ -207,9 +207,9 @@ HWTEST_F_L0(AsonParserTest, Parser_008) factory->NewFromASCII(R"({"innerEntry": {"x":1, "y":"abc", "str": "innerStr"}, "x": 1, "str": "outerStr"})")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); + result->D(thread); EXPECT_FALSE(result->IsException()); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_009) @@ -219,8 +219,8 @@ HWTEST_F_L0(AsonParserTest, Parser_009) JSHandle handleMsg(factory->NewFromASCII(R"({})")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_010) @@ -230,8 +230,8 @@ HWTEST_F_L0(AsonParserTest, Parser_010) JSHandle handleMsg(factory->NewFromASCII(R"([])")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_011) @@ -241,8 +241,8 @@ HWTEST_F_L0(AsonParserTest, Parser_011) JSHandle handleMsg(factory->NewFromASCII(R"([1, 2, 3])")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_012) @@ -253,8 +253,8 @@ HWTEST_F_L0(AsonParserTest, Parser_012) factory->NewFromASCII(R"({"innerEntry": {"array": [1, 2, 3]}, "x": 1, "str": "outerStr"})")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } HWTEST_F_L0(AsonParserTest, Parser_013) diff --git a/ecmascript/base/tests/builtins_base_test.cpp b/ecmascript/base/tests/builtins_base_test.cpp index 45686b7729..0ce83986ff 100644 --- a/ecmascript/base/tests/builtins_base_test.cpp +++ b/ecmascript/base/tests/builtins_base_test.cpp @@ -46,9 +46,9 @@ HWTEST_F_L0(BuiltinsBaseTest, GetArgsArray) TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(resultArray->GetLength(), 3U); - EXPECT_EQ(resultArray->Get(0).GetInt(), 1); - EXPECT_EQ(resultArray->Get(1).GetInt(), 2); - EXPECT_EQ(resultArray->Get(2).GetInt(), 3); + EXPECT_EQ(resultArray->Get(thread, 0).GetInt(), 1); + EXPECT_EQ(resultArray->Get(thread, 1).GetInt(), 2); + EXPECT_EQ(resultArray->Get(thread, 2).GetInt(), 3); } /** @@ -104,13 +104,13 @@ HWTEST_F_L0(BuiltinsBaseTest, GetTaggedString) JSTaggedValue resultStr1 = BuiltinsBase::GetTaggedString(thread, BuiltinsBaseStr1); EXPECT_TRUE(resultStr1.IsString()); JSHandle handleEcmaStr1(thread, resultStr1); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStr1).ToCString().c_str(), "BuiltinsBase"); + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str(), "BuiltinsBase"); char BuiltinsBaseStr2[] = ""; // Empty String JSTaggedValue resultStr2 = BuiltinsBase::GetTaggedString(thread, BuiltinsBaseStr2); EXPECT_TRUE(resultStr2.IsString()); JSHandle handleEcmaStr2(thread, resultStr2); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStr2).ToCString().c_str(), ""); + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStr2).ToCString(thread).c_str(), ""); } /** diff --git a/ecmascript/base/tests/error_helper_test.cpp b/ecmascript/base/tests/error_helper_test.cpp index a05f37da5e..d576ecb74a 100644 --- a/ecmascript/base/tests/error_helper_test.cpp +++ b/ecmascript/base/tests/error_helper_test.cpp @@ -66,10 +66,10 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonToString_001) EcmaStringAccessor evalErrorStrAcc(JSHandle::Cast(evalError)); EcmaStringAccessor typeErrorStrAcc(JSHandle::Cast(typeError)); EcmaStringAccessor rangeErrorStrAcc(JSHandle::Cast(rangeError)); - EXPECT_STREQ(errorStrAcc.ToCString().c_str(), "Error"); - EXPECT_STREQ(evalErrorStrAcc.ToCString().c_str(), "EvalError"); - EXPECT_STREQ(typeErrorStrAcc.ToCString().c_str(), "TypeError"); - EXPECT_STREQ(rangeErrorStrAcc.ToCString().c_str(), "RangeError"); + EXPECT_STREQ(errorStrAcc.ToCString(thread).c_str(), "Error"); + EXPECT_STREQ(evalErrorStrAcc.ToCString(thread).c_str(), "EvalError"); + EXPECT_STREQ(typeErrorStrAcc.ToCString(thread).c_str(), "TypeError"); + EXPECT_STREQ(rangeErrorStrAcc.ToCString(thread).c_str(), "RangeError"); } HWTEST_F_L0(ErrorHelperTest, ErrorCommonToString_002) @@ -133,11 +133,11 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonToString_002) EcmaStringAccessor syntaxErrorStrAcc(JSHandle::Cast(syntaxError)); EcmaStringAccessor referenceErrorStrAcc(JSHandle::Cast(referenceError)); EcmaStringAccessor aggregateErrorStrAcc(JSHandle::Cast(aggregateError)); - EXPECT_STREQ(uriErrorStrAcc.ToCString().c_str(), "URIError"); - EXPECT_STREQ(oomErrorStrAcc.ToCString().c_str(), "OutOfMemoryError"); - EXPECT_STREQ(syntaxErrorStrAcc.ToCString().c_str(), "SyntaxError"); - EXPECT_STREQ(referenceErrorStrAcc.ToCString().c_str(), "ReferenceError"); - EXPECT_STREQ(aggregateErrorStrAcc.ToCString().c_str(), "AggregateError"); + EXPECT_STREQ(uriErrorStrAcc.ToCString(thread).c_str(), "URIError"); + EXPECT_STREQ(oomErrorStrAcc.ToCString(thread).c_str(), "OutOfMemoryError"); + EXPECT_STREQ(syntaxErrorStrAcc.ToCString(thread).c_str(), "SyntaxError"); + EXPECT_STREQ(referenceErrorStrAcc.ToCString(thread).c_str(), "ReferenceError"); + EXPECT_STREQ(aggregateErrorStrAcc.ToCString(thread).c_str(), "AggregateError"); } HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_001) @@ -161,9 +161,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_001) TestHelper::TearDownFrame(thread, prev1); JSHandle errorMsgValue(JSObject::GetProperty(thread, errorResult, msgKey).GetValue()); JSHandle errorNameValue(JSObject::GetProperty(thread, errorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorMsgValue)).ToCString(thread).c_str(), "You have an Error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorNameValue)).ToCString().c_str(), "Error"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorNameValue)).ToCString(thread).c_str(), "Error"); JSHandle evalErrorMsg(factory->NewFromASCII("You have an eval error!")); EcmaRuntimeCallInfo *argv2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*evalError), 6); @@ -175,9 +175,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_001) TestHelper::TearDownFrame(thread, prev2); JSHandle evalMsgValue(JSObject::GetProperty(thread, evalErrorResult, msgKey).GetValue()); JSHandle evalNameValue(JSObject::GetProperty(thread, evalErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(evalMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(evalMsgValue)).ToCString(thread).c_str(), "You have an eval error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(evalNameValue)).ToCString().c_str(), "EvalError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(evalNameValue)).ToCString(thread).c_str(), "EvalError"); JSHandle typeErrorMsg(factory->NewFromASCII("You have a type error!")); EcmaRuntimeCallInfo *argv3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*typeError), 6); @@ -189,9 +189,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_001) TestHelper::TearDownFrame(thread, prev3); JSHandle typeMsgValue(JSObject::GetProperty(thread, typeErrorResult, msgKey).GetValue()); JSHandle typeNameValue(JSObject::GetProperty(thread, typeErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeMsgValue)).ToCString(thread).c_str(), "You have a type error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeNameValue)).ToCString().c_str(), "TypeError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeNameValue)).ToCString(thread).c_str(), "TypeError"); } HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_002) @@ -216,9 +216,10 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_002) TestHelper::TearDownFrame(thread, prev1); JSHandle rangeMsgValue(JSObject::GetProperty(thread, rangeErrorResult, msgKey).GetValue()); JSHandle rangeNameValue(JSObject::GetProperty(thread, rangeErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(rangeMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(rangeMsgValue)).ToCString(thread).c_str(), "You have an range error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(rangeNameValue)).ToCString().c_str(), "RangeError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(rangeNameValue)).ToCString(thread).c_str(), + "RangeError"); JSHandle uriErrorMsg(factory->NewFromASCII("You have an uri error!")); EcmaRuntimeCallInfo *argv2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*uriError), 6); @@ -230,9 +231,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_002) TestHelper::TearDownFrame(thread, prev2); JSHandle uriMsgValue(JSObject::GetProperty(thread, uriErrorResult, msgKey).GetValue()); JSHandle uriNameValue(JSObject::GetProperty(thread, uriErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(uriMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(uriMsgValue)).ToCString(thread).c_str(), "You have an uri error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(uriNameValue)).ToCString().c_str(), "URIError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(uriNameValue)).ToCString(thread).c_str(), "URIError"); JSHandle oomErrorMsg(factory->NewFromASCII("You have an out of memory error!")); EcmaRuntimeCallInfo *argv3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*oomError), 6); @@ -244,9 +245,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_002) TestHelper::TearDownFrame(thread, prev3); JSHandle oomMsgValue(JSObject::GetProperty(thread, oomErrorResult, msgKey).GetValue()); JSHandle oomNameValue(JSObject::GetProperty(thread, oomErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(oomMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(oomMsgValue)).ToCString(thread).c_str(), "You have an out of memory error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(oomNameValue)).ToCString().c_str(), "OutOfMemoryError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(oomNameValue)).ToCString(thread).c_str(), "OutOfMemoryError"); } HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_003) @@ -271,9 +272,10 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_003) TestHelper::TearDownFrame(thread, prev1); JSHandle syntaxMsgValue(JSObject::GetProperty(thread, syntaxErrorResult, msgKey).GetValue()); JSHandle syntaxNameValue(JSObject::GetProperty(thread, syntaxErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(syntaxMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(syntaxMsgValue)).ToCString(thread).c_str(), "You have an syntax error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(syntaxNameValue)).ToCString().c_str(), "SyntaxError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(syntaxNameValue)).ToCString(thread).c_str(), + "SyntaxError"); JSHandle referenceErrorMsg(factory->NewFromASCII("You have an reference error!")); EcmaRuntimeCallInfo *argv2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*referenceError), 6); @@ -287,9 +289,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_003) JSHandle referenceMsgValue(JSObject::GetProperty(thread, referenceErrorResult, msgKey).GetValue()); JSHandle referenceNameValue( JSObject::GetProperty(thread, referenceErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(referenceMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(referenceMsgValue)).ToCString(thread).c_str(), "You have an reference error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(referenceNameValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(referenceNameValue)).ToCString(thread).c_str(), "ReferenceError"); JSHandle aggregateErrorMsg(factory->NewFromASCII("You have an aggregate error!")); @@ -304,9 +306,9 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_003) JSHandle aggregateMsgValue(JSObject::GetProperty(thread, aggregateErrorResult, msgKey).GetValue()); JSHandle aggregateNameValue( JSObject::GetProperty(thread, aggregateErrorResult, nameKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(aggregateMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(aggregateMsgValue)).ToCString(thread).c_str(), "You have an aggregate error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(aggregateNameValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(aggregateNameValue)).ToCString(thread).c_str(), "AggregateError"); } @@ -338,10 +340,11 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_004) JSHandle errorMsgValue(JSObject::GetProperty(thread, errorResult, msgKey).GetValue()); JSHandle errorNameValue(JSObject::GetProperty(thread, errorResult, nameKey).GetValue()); JSHandle errorCauseValue(JSObject::GetProperty(thread, errorResult, causeKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorMsgValue)).ToCString(thread).c_str(), "You have an Error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorNameValue)).ToCString().c_str(), "Error"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorCauseValue)).ToCString().c_str(), "error cause"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorNameValue)).ToCString(thread).c_str(), "Error"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(errorCauseValue)).ToCString(thread).c_str(), + "error cause"); JSHandle typeErrorMsg(factory->NewFromASCII("You have a type error!")); EcmaRuntimeCallInfo *argv2 = @@ -356,9 +359,10 @@ HWTEST_F_L0(ErrorHelperTest, ErrorCommonConstructor_004) JSHandle typeMsgValue(JSObject::GetProperty(thread, typeErrorResult, msgKey).GetValue()); JSHandle typeNameValue(JSObject::GetProperty(thread, typeErrorResult, nameKey).GetValue()); JSHandle typeCauseValue(JSObject::GetProperty(thread, typeErrorResult, causeKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeMsgValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeMsgValue)).ToCString(thread).c_str(), "You have a type error!"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeNameValue)).ToCString().c_str(), "TypeError"); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeCauseValue)).ToCString().c_str(), "error cause"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeNameValue)).ToCString(thread).c_str(), "TypeError"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(typeCauseValue)).ToCString(thread).c_str(), + "error cause"); } } // namespace panda::test diff --git a/ecmascript/base/tests/json_parser_test.cpp b/ecmascript/base/tests/json_parser_test.cpp index 46f3d3bba6..7ee5e02ef0 100644 --- a/ecmascript/base/tests/json_parser_test.cpp +++ b/ecmascript/base/tests/json_parser_test.cpp @@ -26,18 +26,18 @@ class JsonParserTest : public BaseTestWithScope { public: using TransformType = base::JsonHelper::TransformType; - void CheckUnsupportedSendableJson(JSHandle &result) const + void CheckUnsupportedSendableJson(JSThread *thread, JSHandle &result) const { EXPECT_TRUE(result->IsException()); JSHandle exceptionObj(thread, thread->GetException()); auto messageValue = JSTaggedValue::GetProperty(thread, exceptionObj, thread->GlobalConstants()->GetHandledMessageString()) .GetValue(); - EXPECT_EQ(ConvertToString(EcmaString::Cast(messageValue->GetTaggedObject())), + EXPECT_EQ(ConvertToString(thread, EcmaString::Cast(messageValue->GetTaggedObject())), MessageString::GetMessageString(GET_MESSAGE_STRING_ID(SendableArrayForJson)).c_str()); } - bool CheckSendableConstraint(JSTaggedValue value) const + bool CheckSendableConstraint(const JSThread *thread, JSTaggedValue value) const { if (!value.IsHeapObject()) { // tagged value always follow sendable constraint. @@ -50,48 +50,48 @@ public: } if (jsHClass->IsExtensible()) { LOG_ECMA(ERROR) << "sendable check failed. obj is extensible"; - value.D(); + value.D(thread); return false; } - if (!CheckSendableProps(value, obj)) { + if (!CheckSendableProps(thread, value, obj)) { return false; } // trace proto chain - auto proto = jsHClass->GetPrototype(); + auto proto = jsHClass->GetPrototype(thread); if (!proto.IsNull() && !proto.IsJSShared()) { LOG_ECMA(ERROR) << "sendable check failed. proto is not sendable."; - value.D(); + value.D(thread); return false; } return true; } - bool CheckSendableProps(JSTaggedValue value, TaggedObject *obj) const + bool CheckSendableProps(const JSThread *thread, JSTaggedValue value, TaggedObject *obj) const { auto *jsHClass = obj->GetClass(); - auto layoutValue = jsHClass->GetLayout(); + auto layoutValue = jsHClass->GetLayout(thread); if (layoutValue.IsNull()) { return true; } auto *layoutInfo = LayoutInfo::Cast(layoutValue.GetTaggedObject()); auto *jsObj = JSObject::Cast(obj); - auto *propsValue = TaggedArray::Cast(jsObj->GetProperties()); + auto *propsValue = TaggedArray::Cast(jsObj->GetProperties(thread)); if (propsValue->IsDictionaryMode()) { for (int idx = 0; idx < static_cast(jsHClass->NumberOfProps()); idx++) { - auto attr = layoutInfo->GetAttr(idx); + auto attr = layoutInfo->GetAttr(thread, idx); if (attr.IsInlinedProps()) { // Do not check inline props continue; } if (attr.IsWritable()) { LOG_ECMA(ERROR) << "sendable check failed. supposed to be un-writable. idx: " << idx; - value.D(); + value.D(thread); return false; } auto val = propsValue->Get(thread, idx - jsHClass->GetInlinedProperties()); - if (!CheckSendableConstraint(val)) { + if (!CheckSendableConstraint(thread, val)) { LOG_ECMA(ERROR) << "sendable check failed. supposed to be sendable. idx: " << idx; - value.D(); + value.D(thread); return false; } } @@ -161,7 +161,7 @@ HWTEST_F_L0(JsonParserTest, Parser_002) JSHandle handleStr4(JSTaggedValue::ToString(thread, handleMsg4)); JSHandle result4 = parser.Parse(*handleStr4); JSHandle handleEcmaStr(result4); - EXPECT_STREQ("string", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("string", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } /** @@ -285,9 +285,9 @@ HWTEST_F_L0(JsonParserTest, Parser_008) factory->NewFromASCII(R"({"innerEntry": {"x":1, "y":"abc", "str": "innerStr"}, "x": 1, "str": "outerStr"})")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); + result->D(thread); EXPECT_FALSE(result->IsException()); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } /** @@ -303,8 +303,8 @@ HWTEST_F_L0(JsonParserTest, Parser_009) JSHandle handleMsg(factory->NewFromASCII(R"({})")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } /** @@ -320,8 +320,8 @@ HWTEST_F_L0(JsonParserTest, Parser_010) JSHandle handleMsg(factory->NewFromASCII(R"([])")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } /** @@ -337,8 +337,8 @@ HWTEST_F_L0(JsonParserTest, Parser_011) JSHandle handleMsg(factory->NewFromASCII(R"([1, 2, 3])")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } /** @@ -355,7 +355,7 @@ HWTEST_F_L0(JsonParserTest, Parser_012) factory->NewFromASCII(R"({"innerEntry": {"array": [1, 2, 3]}, "x": 1, "str": "outerStr"})")); JSHandle handleStr(JSTaggedValue::ToString(thread, handleMsg)); JSHandle result = parser.Parse(handleStr); - result->D(); - EXPECT_TRUE(CheckSendableConstraint(result.GetTaggedValue())); + result->D(thread); + EXPECT_TRUE(CheckSendableConstraint(thread, result.GetTaggedValue())); } } // namespace panda::test diff --git a/ecmascript/base/tests/json_stringifier_test.cpp b/ecmascript/base/tests/json_stringifier_test.cpp index 71371a19eb..28af66f5f0 100644 --- a/ecmascript/base/tests/json_stringifier_test.cpp +++ b/ecmascript/base/tests/json_stringifier_test.cpp @@ -174,13 +174,13 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_001) JSHandle resultString1 = stringifier1.Stringify(handleValue, handleReplacer1, handleGap); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("false", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("false", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); JsonStringifier stringifier2(thread); JSHandle resultString2 = stringifier2.Stringify(handleValue, handleReplacer2, handleGap); EXPECT_TRUE(resultString2->IsString()); JSHandle handleEcmaStr2(resultString2); - EXPECT_STREQ("10.12", EcmaStringAccessor(handleEcmaStr2).ToCString().c_str()); + EXPECT_STREQ("10.12", EcmaStringAccessor(handleEcmaStr2).ToCString(thread).c_str()); } /** @@ -204,7 +204,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_002) EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); EXPECT_STREQ("{\n \"z\": 1,\n \"x\": 3.6,\n \"y\": \"abc\"\n}", - EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } /** @@ -271,7 +271,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_004) JSHandle resultString = stringifier.Stringify(handleValue, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("{\ntttt\"z\": 1,\ntttt\"x\": 3.6\n}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("{\ntttt\"z\": 1,\ntttt\"x\": 3.6\n}", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } /** @@ -294,7 +294,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_005) JSHandle resultString = stringifier.Stringify(handleValue, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("{\"z\":1,\"x\":3.6,\"y\":\"abc\"}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("{\"z\":1,\"x\":3.6,\"y\":\"abc\"}", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } /** @@ -336,7 +336,8 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_006) JSHandle resultString = stringifier.Stringify(handleValue, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("[\ntttt\"json\",\ntttt100,\ntttt\"abc\"\n]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("[\ntttt\"json\",\ntttt100,\ntttt\"abc\"\n]", + EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } /** @@ -375,7 +376,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_007) JSHandle resultString = stringifier.Stringify(handleValue, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("[1,3.6,\"abc\"]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("[1,3.6,\"abc\"]", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } /** @@ -404,7 +405,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_008) JSHandle resultString = stringifier.Stringify(handleValue, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("\"\\\"\\\\\\b\\f\\n\\r\\t\"", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("\"\\\"\\\\\\b\\f\\n\\r\\t\"", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } static void* Detach(void *param1, void *param2, void *hint, void *detachData) @@ -462,7 +463,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_009) JSHandle resultString = stringifier.Stringify(handleValue, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("{\"key1\":{},\"key2\":\"abc\"}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("{\"key1\":{},\"key2\":\"abc\"}", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_010) @@ -476,7 +477,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_010) JSHandle resultString = stringifier.Stringify(handleMap, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); JsonStringifier stringifier1(thread, TransformType::SENDABLE); JSHandle sharedMap1 = CreateSharedMap(thread); @@ -495,7 +496,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_010) JSHandle resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("{\"key1\":\"abc\",\"key2\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("{\"key1\":\"abc\",\"key2\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_011) @@ -509,7 +510,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_011) JSHandle resultString = stringifier.Stringify(handleMap, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); JsonStringifier stringifier1(thread, TransformType::SENDABLE); JSHandle jsMap1 = CreateJSMap(thread); @@ -528,7 +529,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_011) JSHandle resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("{\"key1\":\"abc\",\"key2\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("{\"key1\":\"abc\",\"key2\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_012) @@ -542,7 +543,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_012) JSHandle resultString = stringifier.Stringify(handleSet, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); JsonStringifier stringifier1(thread, TransformType::SENDABLE); JSHandle sharedSet1 = CreateJSSharedSet(thread); @@ -559,7 +560,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_012) JSHandle resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("[\"abc\",\"val\"]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("[\"abc\",\"val\"]", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_013) @@ -573,7 +574,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_013) JSHandle resultString = stringifier.Stringify(handleSet, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); JsonStringifier stringifier1(thread, TransformType::SENDABLE); JSHandle jsSet1 = CreateJSSet(thread); @@ -590,7 +591,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_013) JSHandle resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("[\"abc\",\"val\"]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("[\"abc\",\"val\"]", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_014) @@ -604,7 +605,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_014) JSHandle resultString = stringifier.Stringify(handleMap, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); JsonStringifier stringifier1(thread, TransformType::SENDABLE); JSHandle hashMap1(thread, CreateHashMap(thread)); @@ -623,7 +624,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_014) JSHandle resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STRNE("{}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STRNE("{}", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_015) @@ -637,7 +638,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_015) JSHandle resultString = stringifier.Stringify(handleSet, handleReplacer, handleGap); EXPECT_TRUE(resultString->IsString()); JSHandle handleEcmaStr(resultString); - EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); JsonStringifier stringifier1(thread, TransformType::SENDABLE); JSHandle hashSet1(thread, CreateHashSet(thread)); @@ -654,7 +655,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_015) JSHandle resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STRNE("[]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STRNE("[]", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_016) @@ -680,7 +681,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_016) JSHandle resultString1 = stringifier.Stringify(handleMap1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("{\"key2\":\"val\",\"key1\":\"abc\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("{\"key2\":\"val\",\"key1\":\"abc\"}", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_017) @@ -703,7 +704,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_017) JSHandle resultString1 = stringifier.Stringify(handleSet1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("[\"val\",\"abc\"]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("[\"val\",\"abc\"]", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_018) @@ -729,7 +730,8 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_018) JSHandle resultString1 = stringifier.Stringify(handleMap1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("{\"key1\":\"abc\",\"undefined\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("{\"key1\":\"abc\",\"undefined\":\"val\"}", + EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_019) @@ -753,7 +755,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_019) JSHandle resultString1 = stringifier.Stringify(handleSet1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("[\"abc\",\"val\",null]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("[\"abc\",\"val\",null]", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_020) @@ -776,7 +778,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_020) JSHandle resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("{\"key1\":\"abc\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("{\"key1\":\"abc\"}", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } HWTEST_F_L0(JsonStringifierTest, Stringify_021) @@ -793,7 +795,7 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_021) JSHandle resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1); EXPECT_TRUE(resultString1->IsString()); JSHandle handleEcmaStr1(resultString1); - EXPECT_STREQ("[null]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str()); + EXPECT_STREQ("[null]", EcmaStringAccessor(handleEcmaStr1).ToCString(thread).c_str()); } #if ENABLE_NEXT_OPTIMIZATION diff --git a/ecmascript/base/tests/number_helper_test.cpp b/ecmascript/base/tests/number_helper_test.cpp index 64efcfc57c..d38471d41e 100644 --- a/ecmascript/base/tests/number_helper_test.cpp +++ b/ecmascript/base/tests/number_helper_test.cpp @@ -577,46 +577,46 @@ HWTEST_F_L0(NumberHelperTest, StringToDoubleWithRadix) radix = 3; resultStr = factory->NewFromASCII("-12"); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); bool negative = false; // 5 = 1 * 3 + 2 EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), -5); radix = 4; resultStr = factory->NewFromASCII("1234567"); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; // 27 = (1 * 4 + 2) * 4 + 3 EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 27); // string has space resultStr = factory->NewFromASCII(" 12345 "); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 27); radix = 16; resultStr = factory->NewFromASCII("0x00ff"); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 255); resultStr = factory->NewFromASCII("0x0010"); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 16); resultStr = factory->NewFromASCII("0x1234"); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 4660); // string has space resultStr = factory->NewFromASCII(" 0x12 "); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 18); resultStr = factory->NewFromASCII("0x1234XX"); - sp = EcmaStringAccessor(resultStr).ToUtf8Span(buf); + sp = EcmaStringAccessor(resultStr).ToUtf8Span(thread, buf); negative = false; EXPECT_EQ(NumberHelper::StringToDoubleWithRadix(sp.begin(), sp.end(), radix, &negative).GetDouble(), 4660); } diff --git a/ecmascript/base/tests/typed_array_helper_test.cpp b/ecmascript/base/tests/typed_array_helper_test.cpp index ab7ac72219..708dcfb28f 100755 --- a/ecmascript/base/tests/typed_array_helper_test.cpp +++ b/ecmascript/base/tests/typed_array_helper_test.cpp @@ -140,7 +140,7 @@ HWTEST_F_L0(TypedArrayHelperTest, AllocateTypedArray_001) TestHelper::TearDownFrame(thread, prev); JSTypedArray *jsTypedArray = JSTypedArray::Cast(*arrayObj); EXPECT_EQ(jsTypedArray->GetContentType(), ContentType::Number); - EXPECT_EQ(jsTypedArray->GetTypedArrayName().GetRawData(), constructorName.GetTaggedValue().GetRawData()); + EXPECT_EQ(jsTypedArray->GetTypedArrayName(thread).GetRawData(), constructorName.GetTaggedValue().GetRawData()); EXPECT_EQ(jsTypedArray->GetByteLength(), 0U); EXPECT_EQ(jsTypedArray->GetByteOffset(), 0U); EXPECT_EQ(jsTypedArray->GetArrayLength(), 0U); @@ -161,7 +161,7 @@ HWTEST_F_L0(TypedArrayHelperTest, AllocateTypedArray_002) TestHelper::TearDownFrame(thread, prev); JSTypedArray *jsTypedArray = JSTypedArray::Cast(*arrayObj); EXPECT_EQ(jsTypedArray->GetContentType(), ContentType::Number); - EXPECT_EQ(jsTypedArray->GetTypedArrayName().GetRawData(), constructorName.GetTaggedValue().GetRawData()); + EXPECT_EQ(jsTypedArray->GetTypedArrayName(thread).GetRawData(), constructorName.GetTaggedValue().GetRawData()); EXPECT_EQ(jsTypedArray->GetByteLength(), 256U); EXPECT_EQ(jsTypedArray->GetByteOffset(), 0U); EXPECT_EQ(jsTypedArray->GetArrayLength(), 256U); @@ -201,7 +201,7 @@ HWTEST_F_L0(TypedArrayHelperTest, TypedArrayCreate) JSTaggedType args[1] = {JSTaggedValue(lenVal).GetRawData()}; JSHandle newArrObj = TypedArrayHelper::TypedArrayCreate(thread, constructor, 1, args); // 1 : one arg uint32_t len = JSHandle::Cast(newArrObj)->GetArrayLength(); - JSHandle type(thread, JSHandle::Cast(newArrObj)->GetTypedArrayName()); + JSHandle type(thread, JSHandle::Cast(newArrObj)->GetTypedArrayName(thread)); EXPECT_EQ(len, 256U); EXPECT_EQ(type.GetTaggedValue().GetRawData(), constructorName.GetTaggedValue().GetRawData()); } @@ -211,7 +211,7 @@ HWTEST_F_L0(TypedArrayHelperTest, ValidateTypedArray) JSHandle uint32Array; CreateArrayList(thread, uint32Array); JSHandle buffer(thread, TypedArrayHelper::ValidateTypedArray(thread, uint32Array)); - JSTaggedValue result = JSHandle::Cast(uint32Array)->GetViewedArrayBufferOrByteArray(); + JSTaggedValue result = JSHandle::Cast(uint32Array)->GetViewedArrayBufferOrByteArray(thread); EXPECT_EQ(buffer.GetTaggedValue().GetRawData(), result.GetRawData()); } @@ -398,7 +398,7 @@ HWTEST_F_L0(TypedArrayHelperTest, SortCompare) JSHandle uint32Array; CreateArrayList(thread, uint32Array); JSHandle buffer(thread, TypedArrayHelper::ValidateTypedArray(thread, uint32Array)); - EXPECT_FALSE(builtins::BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())); + EXPECT_FALSE(builtins::BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer.GetTaggedValue())); JSHandle callbackfnHandle(thread, JSTaggedValue::Undefined()); JSHandle nan(thread, JSTaggedValue(base::NAN_VALUE)); @@ -451,7 +451,7 @@ HWTEST_F_L0(TypedArrayHelperTest, FastCreateTypedArray) { } else { EXPECT_EQ(jsTypedArray->GetContentType(), ContentType::Number); } - EXPECT_EQ(jsTypedArray->GetTypedArrayName().GetRawData(), constructorName.GetTaggedValue().GetRawData()); + EXPECT_EQ(jsTypedArray->GetTypedArrayName(thread).GetRawData(), constructorName.GetTaggedValue().GetRawData()); EXPECT_EQ(jsTypedArray->GetByteLength(), 0U); EXPECT_EQ(jsTypedArray->GetByteOffset(), 0U); EXPECT_EQ(jsTypedArray->GetArrayLength(), 0U); diff --git a/ecmascript/base/typed_array_helper-inl.h b/ecmascript/base/typed_array_helper-inl.h index 3adadba432..c1d7745e89 100644 --- a/ecmascript/base/typed_array_helper-inl.h +++ b/ecmascript/base/typed_array_helper-inl.h @@ -479,10 +479,10 @@ uint32_t TypedArrayHelper::GetSizeFromType(const DataViewType arrayType) return ElementSize::EIGHT; } -bool TypedArrayHelper::IsAccessorHasChanged(const JSHandle &obj) +bool TypedArrayHelper::IsAccessorHasChanged(JSThread *thread, const JSHandle &obj) { if (obj->IsHeapObject()) { - JSTaggedValue markerValue = obj->GetTaggedObject()->GetClass()->GetProtoChangeMarker(); + JSTaggedValue markerValue = obj->GetTaggedObject()->GetClass()->GetProtoChangeMarker(thread); if (markerValue.IsProtoChangeMarker()) { return ProtoChangeMarker::Cast(markerValue.GetTaggedObject())->GetAccessorHasChanged(); } diff --git a/ecmascript/base/typed_array_helper.cpp b/ecmascript/base/typed_array_helper.cpp index 5503ebb638..bfb47aa435 100644 --- a/ecmascript/base/typed_array_helper.cpp +++ b/ecmascript/base/typed_array_helper.cpp @@ -311,7 +311,7 @@ JSTaggedValue TypedArrayHelper::FastCopyElementFromArray( uint32_t len = JSHandle::Cast(argArray)->GetArrayLength(); JSHandle argObj(argArray); // load on demand check - if (ElementAccessor::GetElementsLength(argObj) < len) { + if (ElementAccessor::GetElementsLength(thread, argObj) < len) { TypedArrayHelper::CreateFromOrdinaryObject(argv, obj, arrayType); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return obj.GetTaggedValue(); @@ -441,7 +441,7 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, // 6. Let srcData be srcArray.[[ViewedArrayBuffer]]. JSHandle srcData(thread, JSTypedArray::GetOffHeapBuffer(thread, srcObj)); // 7. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcData.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcData.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 8. Let elementType be the Element Type value in Table 61 for constructorName. @@ -451,7 +451,7 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, // 11. Let srcType be the Element Type value in Table 61 for srcName. // 12. Let srcElementSize be the Element Size value specified in Table 61 for srcName. uint32_t elementLength = srcObj->GetArrayLength(); - JSHandle srcName(thread, srcObj->GetTypedArrayName()); + JSHandle srcName(thread, srcObj->GetTypedArrayName(thread)); DataViewType srcType = JSTypedArray::GetTypeFromName(thread, srcName); uint32_t srcElementSize = TypedArrayHelper::GetSizeFromType(srcType); // 13. Let srcByteOffset be srcArray.[[ByteOffset]]. @@ -484,7 +484,7 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, data.Update(tmp); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcData.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcData.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } ContentType objContentType = JSHandle::Cast(obj)->GetContentType(); @@ -540,11 +540,11 @@ JSTaggedValue GetTypedArrayBuffer(EcmaRuntimeCallInfo *argv, JSHandle srcArray) { // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (buffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer)) { + if (buffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } - if (!buffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (!buffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } @@ -634,7 +634,7 @@ JSTaggedValue TypedArrayHelper::CreateSharedFromTypedArray(EcmaRuntimeCallInfo * // 11. Let srcType be the Element Type value in Table 61 for srcName. // 12. Let srcElementSize be the Element Size value specified in Table 61 for srcName. uint32_t elementLength = srcObj->GetArrayLength(); - JSHandle srcName(thread, srcObj->GetTypedArrayName()); + JSHandle srcName(thread, srcObj->GetTypedArrayName(thread)); DataViewType srcType = JSTypedArray::GetTypeFromName(thread, srcName); uint32_t srcElementSize = TypedArrayHelper::GetSizeFromType(srcType); // 13. Let srcByteOffset be srcArray.[[ByteOffset]]. @@ -736,7 +736,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, } // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. JSHandle buffer = BuiltinsBase::GetCallArg(argv, 0); - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]. @@ -749,7 +749,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, if (length->IsUndefined()) { if (bufferByteLength % elementSize != 0) { std::string ctorName = EcmaStringAccessor( - JSTaggedValue::ToString(thread, GetConstructorNameFromType(thread, arrayType))).ToStdString(); + JSTaggedValue::ToString(thread, GetConstructorNameFromType(thread, arrayType))).ToStdString(thread); std::string message = "The byte length of " + ctorName + " should be a multiple of " + std::to_string(elementSize); THROW_RANGE_ERROR_AND_RETURN(thread, message.c_str(), JSTaggedValue::Exception()); @@ -803,7 +803,7 @@ JSTaggedValue TypedArrayHelper::CreateFromSendableArrayBuffer(EcmaRuntimeCallInf } // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. JSHandle buffer = BuiltinsBase::GetCallArg(argv, 0); - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]. @@ -816,7 +816,7 @@ JSTaggedValue TypedArrayHelper::CreateFromSendableArrayBuffer(EcmaRuntimeCallInf if (length->IsUndefined()) { if (bufferByteLength % elementSize != 0) { std::string ctorName = EcmaStringAccessor( - JSTaggedValue::ToString(thread, GetConstructorNameFromType(thread, arrayType))).ToStdString(); + JSTaggedValue::ToString(thread, GetConstructorNameFromType(thread, arrayType))).ToStdString(thread); std::string message = "The byte length of " + ctorName + " should be a multiple of " + std::to_string(elementSize); THROW_RANGE_ERROR_AND_RETURN(thread, message.c_str(), JSTaggedValue::Exception()); @@ -979,9 +979,9 @@ JSHandle TypedArrayHelper::TypedArraySpeciesCreate(JSThread *thread, c TypedArrayHelper::GetConstructor(thread, JSHandle(obj)); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle result; - JSHandle proto(thread, obj->GetJSHClass()->GetPrototype()); + JSHandle proto(thread, obj->GetJSHClass()->GetPrototype(thread)); bool isCtrUnchanged = !env->GetTypedArraySpeciesProtectDetector() && - !TypedArrayHelper::IsAccessorHasChanged(proto) && + !TypedArrayHelper::IsAccessorHasChanged(thread, proto) && !obj->GetJSHClass()->HasConstructor(); bool isCtrBylen = buffHandle->IsInt(); if (isCtrUnchanged && isCtrBylen) { @@ -1087,12 +1087,12 @@ JSTaggedValue TypedArrayHelper::ValidateTypedArray(JSThread *thread, const JSHan } // 3. Let buffer be O.[[ViewedArrayBuffer]]. // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - JSTaggedValue buffer = JSHandle::Cast(value)->GetViewedArrayBufferOrByteArray(); - if (buffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer)) { + JSTaggedValue buffer = JSHandle::Cast(value)->GetViewedArrayBufferOrByteArray(thread); + if (buffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } - if (!buffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (!buffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } @@ -1123,11 +1123,11 @@ int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandleIsSendableArrayBuffer() && - BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The buffer is detached sendable buffer.", 0); } if (!buffer->IsSendableArrayBuffer() && - BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The buffer is detached buffer.", 0); } JSHandle testResult(thread, callResult); @@ -1210,8 +1210,8 @@ bool TypedArrayHelper::IsNativeArrayIterator(JSThread *thread, } JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - if (!JSTaggedValue::SameValue(iterMethod, env->GetTypedArrayProtoValuesFunction()) && - !JSTaggedValue::SameValue(iterMethod, env->GetArrayProtoValuesFunction())) { + if (!JSTaggedValue::SameValue(thread, iterMethod, env->GetTypedArrayProtoValuesFunction()) && + !JSTaggedValue::SameValue(thread, iterMethod, env->GetArrayProtoValuesFunction())) { return false; } diff --git a/ecmascript/base/typed_array_helper.h b/ecmascript/base/typed_array_helper.h index c3958f7c62..49ad15a48e 100644 --- a/ecmascript/base/typed_array_helper.h +++ b/ecmascript/base/typed_array_helper.h @@ -95,7 +95,7 @@ public: inline static JSHandle GetSharedNotOnHeapHclassFromType( JSThread *thread, const JSHandle &obj, const DataViewType arrayType); inline static uint32_t GetSizeFromType(const DataViewType arrayType); - inline static bool IsAccessorHasChanged(const JSHandle &obj); + inline static bool IsAccessorHasChanged(JSThread *thread, const JSHandle &obj); static int32_t SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, const JSHandle &buffer, const JSHandle &firstValue, const JSHandle &secondValue); diff --git a/ecmascript/base_env.h b/ecmascript/base_env.h index 897ba08844..0d228948ed 100644 --- a/ecmascript/base_env.h +++ b/ecmascript/base_env.h @@ -31,9 +31,9 @@ public: return static_cast(obj); } - JSTaggedValue GetGlobalEnv() const + JSTaggedValue GetGlobalEnv(JSThread* thread) const { - return Get(GLOBAL_ENV_INDEX); + return Get(thread, GLOBAL_ENV_INDEX); } void SetGlobalEnv(JSThread* thread, JSTaggedValue value) diff --git a/ecmascript/builtin_entries.h b/ecmascript/builtin_entries.h index b8527a0e7f..cd5ec12c39 100644 --- a/ecmascript/builtin_entries.h +++ b/ecmascript/builtin_entries.h @@ -126,9 +126,9 @@ public: return instance; } - size_t GetBuiltinBoxOffset(JSTaggedValue key) const + size_t GetBuiltinBoxOffset(const JSThread *thread, JSTaggedValue key) const { - auto index = GetBuiltinIndex(key); + auto index = GetBuiltinIndex(thread, key); ASSERT(index != NOT_FOUND); return sizeof(JSTaggedValue) * (index * 2); // 2 is size of BuiltinEntries } @@ -138,10 +138,10 @@ public: return sizeof(JSTaggedValue) * (index * 2); // 2 is size of BuiltinEntries } - size_t GetBuiltinIndex(JSTaggedValue key) const + size_t GetBuiltinIndex(const JSThread *thread, JSTaggedValue key) const { auto ecmaString = EcmaString::Cast(key.GetTaggedObject()); - auto str = std::string(ConvertToString(ecmaString)); + auto str = std::string(ConvertToString(thread, ecmaString)); return GetBuiltinIndex(str); } diff --git a/ecmascript/builtins/builtins.cpp b/ecmascript/builtins/builtins.cpp index d640328cb0..fc4e0af52c 100644 --- a/ecmascript/builtins/builtins.cpp +++ b/ecmascript/builtins/builtins.cpp @@ -1358,7 +1358,7 @@ void Builtins::InitializeCtor(const JSHandle &env, const JSHandleGlobalConstants()->GetHandledAsyncFunctionString())) { + if (!JSTaggedValue::SameValue(thread_, nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { JSHandle globalObject(thread_, env->GetGlobalObject()); PropertyDescriptor descriptor2(thread_, JSHandle::Cast(ctor), true, false, true); JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor2); @@ -2381,7 +2381,7 @@ void Builtins::Initialize##Type(const JSHandle &env, const JSHandle(arrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); \ /* %TypedArray%.protoofprototype (where %TypedArray% is one of Int8Array, Uint8Array, etc.) */ \ - JSTaggedValue protoOfPrototypeValue = arrFuncPrototype->GetJSHClass()->GetPrototype(); \ + JSTaggedValue protoOfPrototypeValue = arrFuncPrototype->GetJSHClass()->GetPrototype(thread_); \ env->Set##Type##Function(thread_, arrayFunction); \ env->Set##Type##FunctionPrototype(thread_, arrFuncPrototypeValue); \ env->Set##Type##RootHclass(thread_, arrFuncInstanceHClass); \ @@ -3243,7 +3243,7 @@ void Builtins::InitializeIntlCtor(const JSHandle &env, const JSHandle // set "prototype" in constructor. JSFunction::SetFunctionPrototypeOrInstanceHClass(thread_, ctor, prototype.GetTaggedValue()); - if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { + if (!JSTaggedValue::SameValue(thread_, nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { JSHandle intlObject(thread_, env->GetIntlFunction().GetTaggedValue()); PropertyDescriptor descriptor2(thread_, JSHandle::Cast(ctor), true, false, true); JSObject::DefineOwnProperty(thread_, intlObject, nameString, descriptor2); @@ -3948,7 +3948,7 @@ void Builtins::InitializeDefaultExportOfScript(const JSHandle &env) c props->Set(thread_, 1, emptyObj); JSHandle hclass = factory_->CreateObjectClass(env, props, 1); JSHandle obj = factory_->NewJSObject(hclass); - obj->SetPropertyInlinedProps(thread_, 0, props->Get(1)); + obj->SetPropertyInlinedProps(thread_, 0, props->Get(thread_, 1)); env->SetExportOfScript(thread_, obj); return; } diff --git a/ecmascript/builtins/builtins_ark_tools.cpp b/ecmascript/builtins/builtins_ark_tools.cpp index 0cedf93f5c..6b9523fec0 100644 --- a/ecmascript/builtins/builtins_ark_tools.cpp +++ b/ecmascript/builtins/builtins_ark_tools.cpp @@ -55,13 +55,13 @@ JSTaggedValue BuiltinsArkTools::ObjectDump(EcmaRuntimeCallInfo *info) JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(info, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // The default log level of ace_engine and js_runtime is error - LOG_ECMA(ERROR) << ": " << EcmaStringAccessor(str).ToStdString(); + LOG_ECMA(ERROR) << ": " << EcmaStringAccessor(str).ToStdString(thread); uint32_t numArgs = info->GetArgsNumber(); for (uint32_t i = 1; i < numArgs; i++) { JSHandle obj = GetCallArg(info, i); std::ostringstream oss; - obj->Dump(oss); + obj->Dump(thread, oss); // The default log level of ace_engine and js_runtime is error LOG_ECMA(ERROR) << ": " << oss.str(); @@ -82,8 +82,8 @@ JSTaggedValue BuiltinsArkTools::CompareHClass(EcmaRuntimeCallInfo *info) JSHClass *obj1Hclass = obj1->GetTaggedObject()->GetClass(); JSHClass *obj2Hclass = obj2->GetTaggedObject()->GetClass(); std::ostringstream oss; - obj1Hclass->Dump(oss); - obj2Hclass->Dump(oss); + obj1Hclass->Dump(thread, oss); + obj2Hclass->Dump(thread, oss); bool res = (obj1Hclass == obj2Hclass); if (!res) { LOG_ECMA(ERROR) << "These two object don't share the same hclass:" << oss.str(); @@ -101,7 +101,7 @@ JSTaggedValue BuiltinsArkTools::DumpHClass(EcmaRuntimeCallInfo *info) JSHandle obj = GetCallArg(info, 0); JSHClass *objHclass = obj->GetTaggedObject()->GetClass(); std::ostringstream oss; - objHclass->Dump(oss); + objHclass->Dump(thread, oss); LOG_ECMA(ERROR) << "hclass:" << oss.str(); return JSTaggedValue::Undefined(); @@ -214,7 +214,7 @@ JSTaggedValue BuiltinsArkTools::IsNotHoleProperty(EcmaRuntimeCallInfo *info) if (entry == -1) { return GetTaggedBoolean(false); } - PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject())->GetAttr(entry); + PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject())->GetAttr(thread, entry); return GetTaggedBoolean(attr.IsNotHole()); } @@ -250,7 +250,7 @@ JSTaggedValue BuiltinsArkTools::GetLexicalEnv(EcmaRuntimeCallInfo *info) JSHandle object = GetCallArg(info, 0); if (object->IsHeapObject() && object->IsJSFunction()) { JSHandle function = JSHandle::Cast(object); - return function->GetLexicalEnv(); + return function->GetLexicalEnv(thread); } return JSTaggedValue::Null(); } @@ -266,7 +266,7 @@ JSTaggedValue BuiltinsArkTools::CurrentEnvIsGlobal(EcmaRuntimeCallInfo *info) JSHandle object = GetCallArg(info, 0); if (object->IsHeapObject() && object->IsJSFunction()) { JSHandle function = JSHandle::Cast(object); - if (function->GetLexicalEnv().IsJSGlobalEnv()) { + if (function->GetLexicalEnv(thread).IsJSGlobalEnv()) { return JSTaggedValue::True(); } } @@ -306,7 +306,7 @@ JSTaggedValue BuiltinsArkTools::ForceLazyDeopt(EcmaRuntimeCallInfo *info) return JSTaggedValue::Undefined(); } JSHClass *hclass = object->GetTaggedObject()->GetClass(); - JSTaggedValue infos = hclass->GetDependentInfos(); + JSTaggedValue infos = hclass->GetDependentInfos(thread); if (!infos.IsHeapObject()) { return JSTaggedValue::Undefined(); } @@ -351,7 +351,7 @@ JSTaggedValue BuiltinsArkTools::RemoveAOTFlag(EcmaRuntimeCallInfo *info) JSHandle object = GetCallArg(info, 0); if (object->IsHeapObject() && object->IsJSFunction()) { JSHandle func = JSHandle::Cast(object); - JSHandle method = JSHandle(thread, func->GetMethod()); + JSHandle method = JSHandle(thread, func->GetMethod(thread)); method->SetAotCodeBit(false); } @@ -372,7 +372,7 @@ JSTaggedValue BuiltinsArkTools::CheckCircularImport(EcmaRuntimeCallInfo *info) } CList referenceList; // str: bundleName/moduleName/xxx/xxx - CString string = ConvertToString(str.GetTaggedValue()); + CString string = ConvertToString(thread, str.GetTaggedValue()); LOG_ECMA(INFO) << "checkCircularImport begin with: "<< string; SourceTextModule::CheckCircularImportTool(thread, string, referenceList, printOtherCircular); return JSTaggedValue::Undefined(); @@ -416,7 +416,7 @@ JSTaggedValue BuiltinsArkTools::StartCpuProfiler(EcmaRuntimeCallInfo *info) if (fileNameValue->IsString()) { JSHandle str = JSTaggedValue::ToString(thread, fileNameValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - fileName = EcmaStringAccessor(str).ToStdString() + ".cpuprofile"; + fileName = EcmaStringAccessor(str).ToStdString(thread) + ".cpuprofile"; } else { fileName = GetProfileName(); } @@ -538,7 +538,7 @@ JSTaggedValue BuiltinsArkTools::IsSameProfileTypeInfo(EcmaRuntimeCallInfo *info) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle func0 = JSHandle::Cast(GetCallArg(info, 0)); JSHandle func1 = JSHandle::Cast(GetCallArg(info, 1)); - return JSTaggedValue(func0->GetProfileTypeInfo() == func1->GetProfileTypeInfo()); + return JSTaggedValue(func0->GetProfileTypeInfo(thread) == func1->GetProfileTypeInfo(thread)); } // It is used to check whether a function has valid profileTypeInfo @@ -549,7 +549,7 @@ JSTaggedValue BuiltinsArkTools::IsProfileTypeInfoValid(EcmaRuntimeCallInfo *info RETURN_IF_DISALLOW_ARKTOOLS(thread); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle func = JSHandle::Cast(GetCallArg(info, 0)); - return JSTaggedValue(func->GetProfileTypeInfo().IsTaggedArray()); + return JSTaggedValue(func->GetProfileTypeInfo(thread).IsTaggedArray()); } JSTaggedValue BuiltinsArkTools::IsOnHeap(EcmaRuntimeCallInfo *info) @@ -575,7 +575,7 @@ JSTaggedValue BuiltinsArkTools::IsAOTDeoptimized(EcmaRuntimeCallInfo *info) JSHandle func(thread, obj.GetTaggedValue()); bool isAotCompiled = func->IsCompiledCode(); if (isAotCompiled) { - Method *method = func->GetCallTarget(); + Method *method = func->GetCallTarget(thread); uint32_t deoptedCount = method->GetDeoptThreshold(); uint32_t deoptThreshold = thread->GetEcmaVM()->GetJSOptions().GetDeoptThreshold(); return JSTaggedValue(deoptedCount != deoptThreshold); @@ -593,7 +593,7 @@ JSTaggedValue BuiltinsArkTools::CheckDeoptStatus(EcmaRuntimeCallInfo *info) JSHandle obj = GetCallArg(info, 0); JSHandle func(thread, obj.GetTaggedValue()); - Method *method = func->GetCallTarget(); + Method *method = func->GetCallTarget(thread); bool isAotCompiled = func->IsCompiledCode(); uint16_t threshold = method->GetDeoptThreshold(); if (threshold > 0) { @@ -625,7 +625,7 @@ JSTaggedValue BuiltinsArkTools::PrintTypedOpProfiler(EcmaRuntimeCallInfo *info) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle opStrVal = GetCallArg(info, 0); - std::string opStr = EcmaStringAccessor(opStrVal.GetTaggedValue()).ToStdString(); + std::string opStr = EcmaStringAccessor(opStrVal.GetTaggedValue()).ToStdString(thread); TypedOpProfiler* profiler = thread->GetEcmaVM()->GetTypedOpProfiler(); if (profiler != nullptr) { profiler->Print(opStr); @@ -765,7 +765,7 @@ JSTaggedValue BuiltinsArkTools::StartCollectingOpcodes([[maybe_unused]] EcmaRunt vm->SetBytecodeStatsStack(bytecodeStatsMap); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(info, 0)); - auto msg = EcmaStringAccessor(str).ToCString(); + auto msg = EcmaStringAccessor(str).ToCString(thread); LOG_ECMA(ERROR) << msg.c_str(); return JSTaggedValue::Undefined(); } @@ -781,7 +781,7 @@ JSTaggedValue BuiltinsArkTools::StopCollectingOpcodes([[maybe_unused]] EcmaRunti bytecodeStatsStack_.pop(); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(info, 0)); - auto msg = EcmaStringAccessor(str).ToCString(); + auto msg = EcmaStringAccessor(str).ToCString(thread); LOG_ECMA(ERROR) << msg.c_str(); return JSTaggedValue::Undefined(); } @@ -971,7 +971,7 @@ JSTaggedValue BuiltinsArkTools::HasDictionaryElements([[maybe_unused]] EcmaRunti CHECK(arg->IsJSObject()); JSHandle obj(arg); bool isDict = obj->GetClass()->IsDictionaryElement(); - CHECK(isDict == ElementAccessor::IsDictionaryMode(obj)); + CHECK(isDict == ElementAccessor::IsDictionaryMode(thread, obj)); CHECK(isDict == (obj->GetClass()->GetElementsKind() == ElementsKind::DICTIONARY)); return JSTaggedValue(isDict); } @@ -1093,7 +1093,7 @@ JSTaggedValue BuiltinsArkTools::FunctionGetInferredName([[maybe_unused]] EcmaRun JSHandle obj = GetCallArg(info, 0); if (obj->IsJSFunction()) { JSHandle funcObj = JSHandle::Cast(obj); - std::string name = Method::ConstCast(funcObj->GetMethod().GetTaggedObject())->ParseFunctionName(); + std::string name = Method::ConstCast(funcObj->GetMethod(thread).GetTaggedObject())->ParseFunctionName(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); return factory->NewFromStdString(name).GetTaggedValue(); } @@ -1156,11 +1156,12 @@ JSTaggedValue BuiltinsArkTools::FinalizeOptimization([[maybe_unused]] EcmaRuntim JSTaggedValue BuiltinsArkTools::EnsureFeedbackVectorForFunction([[maybe_unused]] EcmaRuntimeCallInfo *info) { - RETURN_IF_DISALLOW_ARKTOOLS(info->GetThread()); + JSThread *thread = info->GetThread(); + RETURN_IF_DISALLOW_ARKTOOLS(thread); CHECK(info && info->GetArgsNumber() == 1); CHECK(info->GetCallArg(0)->IsJSFunction()); JSHandle func(info->GetCallArg(0)); - auto prof = func->GetProfileTypeInfo(); + auto prof = func->GetProfileTypeInfo(thread); CHECK(prof.IsUndefined() || prof.GetHeapObject()->GetClass()->IsTaggedArray()); return JSTaggedValue(!prof.IsUndefined()); } @@ -1202,7 +1203,8 @@ JSTaggedValue BuiltinsArkTools::AbortJS([[maybe_unused]] EcmaRuntimeCallInfo *in CHECK(info && info->GetArgsNumber() == 1); CHECK(info->GetCallArg(0)->IsString()); JSHandle msg(info->GetCallArg(0)); - std::cerr << "AbortJS: " << EcmaStringAccessor(msg).ToCString(StringConvertedUsage::PRINT) << std::endl; + std::cerr << "AbortJS: " << EcmaStringAccessor(msg).ToCString(info->GetThread(), StringConvertedUsage::PRINT) + << std::endl; panda::PrintStack(std::cerr); std::abort(); } @@ -1517,8 +1519,8 @@ JSTaggedValue BuiltinsArkTools::WaitJitCompileFinish(EcmaRuntimeCallInfo *info) if (!jit->IsEnableFastJit()) { return JSTaggedValue::False(); } - while (!jsFunction->GetMachineCode().IsMachineCodeObject()) { - if (jsFunction->GetJitHotnessCnt() == ProfileTypeInfo::JIT_DISABLE_FLAG) { + while (!jsFunction->GetMachineCode(thread).IsMachineCodeObject()) { + if (jsFunction->GetJitHotnessCnt(thread) == ProfileTypeInfo::JIT_DISABLE_FLAG) { // The current function is not compiled for some reason. break; } @@ -1636,13 +1638,13 @@ JSTaggedValue BuiltinsArkTools::TriggerSharedGC(EcmaRuntimeCallInfo *info) auto globalConst = thread->GlobalConstants(); SharedHeap *sHeap = SharedHeap::GetInstance(); sHeap->WaitGCFinished(thread); - if (JSTaggedValue::StrictEqual(globalConst->GetSharedGcCause(), type)) { + if (JSTaggedValue::StrictEqual(thread, globalConst->GetSharedGcCause(), type)) { sHeap->TriggerConcurrentMarking(thread); sHeap->WaitGCFinished(thread); - } else if (JSTaggedValue::StrictEqual(globalConst->GetSharedPartialGcCause(), type)) { + } else if (JSTaggedValue::StrictEqual(thread, globalConst->GetSharedPartialGcCause(), type)) { sHeap->TriggerConcurrentMarking(thread); sHeap->WaitGCFinished(thread); - } else if (JSTaggedValue::StrictEqual(globalConst->GetSharedFullGcCause(), type)) { + } else if (JSTaggedValue::StrictEqual(thread, globalConst->GetSharedFullGcCause(), type)) { sHeap->CollectGarbage(thread); } return JSTaggedValue::Undefined(); diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index 77793cd6ec..35f9933011 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -1344,7 +1344,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) } // 7. ReturnIfAbrupt(sep). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - std::u16string sepStr = EcmaStringAccessor(sepStringHandle).ToU16String(); + std::u16string sepStr = EcmaStringAccessor(sepStringHandle).ToU16String(thread); // 8. If len is zero or exist circular call, return the empty String. if (len == 0 || !ArrayJoinStack::Push(thread, thisObjVal)) { @@ -1374,7 +1374,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) if (!element->IsUndefined() && !element->IsNull()) { JSHandle nextStringHandle = JSTaggedValue::ToString(thread, element); RETURN_EXCEPTION_AND_POP_JOINSTACK(thread, thisHandle); - concatStr.append(EcmaStringAccessor(nextStringHandle).ToU16String()); + concatStr.append(EcmaStringAccessor(nextStringHandle).ToU16String(thread)); } if (concatStr.size() > BaseString::MAX_STRING_LENGTH) { ArrayJoinStack::Pop(thread, thisHandle); @@ -2201,7 +2201,7 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) int64_t count = final > k ? (final - k) : 0; if (thisHandle->IsStableJSArray(thread) && !thisObjHandle->GetJSHClass()->HasConstructor() - && JSObject::GetPrototype(thisObjHandle).IsJSArray()) { + && JSObject::GetPrototype(thread, thisObjHandle).IsJSArray()) { return JSStableArray::Slice(thread, thisObjHandle, k, count); } @@ -2653,7 +2653,7 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) JSHandle nextHandle(thread, next); JSHandle nextStringHandle = JSTaggedValue::ToString(thread, nextHandle); RETURN_EXCEPTION_AND_POP_JOINSTACK(thread, thisHandle); - CString nextString = ConvertToString(*nextStringHandle); + CString nextString = ConvertToString(thread, *nextStringHandle); if (k > 0) { concatStr += STRING_SEPERATOR; concatStr += nextString; @@ -2975,7 +2975,7 @@ JSTaggedValue BuiltinsArray::IncludesSlowPath( valueHandle.Update(JSArray::FastGetPropertyByValue(thread, thisObjVal, keyHandle).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If SameValueZero(searchElement, elementK) is true, return true. - if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), valueHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(thread, searchElement.GetTaggedValue(), valueHandle.GetTaggedValue())) { return GetTaggedBoolean(true); } // c. Set k to k + 1. @@ -3061,7 +3061,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) key.Update(fromStr.GetTaggedValue()); kValueHandle.Update(JSArray::FastGetPropertyByValue(thread, thisObjVal, key).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), kValueHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(thread, searchElement.GetTaggedValue(), kValueHandle.GetTaggedValue())) { return GetTaggedBoolean(true); } from++; @@ -3239,7 +3239,7 @@ JSTaggedValue BuiltinsArray::ToSorted(EcmaRuntimeCallInfo *argv) // b. Set j to j + 1. JSMutableHandle itemValue(thread, JSTaggedValue::Undefined()); while (j < len) { - itemValue.Update(sortedList->Get(j)); + itemValue.Update(sortedList->Get(thread, j)); JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, j, itemValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); ++j; diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index 44ca29e3d4..4fda7ec9a1 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -90,7 +90,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetByteLength(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "don't have internal slot", JSTaggedValue::Exception()); } // 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "IsDetachedBuffer", JSTaggedValue::Exception()); } JSHandle arrBuf(thisHandle); @@ -120,7 +120,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "don't have internal slot", JSTaggedValue::Exception()); } // 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } // 5. Let len be the value of O’s [[ArrayBufferByteLength]] internal slot. @@ -180,11 +180,11 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "don't have bufferdata internal slot", JSTaggedValue::Exception()); } // 18. If IsDetachedBuffer(new) is true, throw a TypeError exception. - if (IsDetachedBuffer(newArrBuf.GetTaggedValue())) { + if (IsDetachedBuffer(thread, newArrBuf.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "new arrayBuffer IsDetachedBuffer", JSTaggedValue::Exception()); } // 19. If SameValue(new, O) is true, throw a TypeError exception. - if (JSTaggedValue::SameValue(newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "value of new arraybuffer and this is same", JSTaggedValue::Exception()); } JSHandle newJsArrBuf(newArrBuf); @@ -195,14 +195,14 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) } // 21. NOTE: Side-effects of the above steps may have detached O. // 22. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } if (newLen > 0) { // 23. Let fromBuf be the value of O’s [[ArrayBufferData]] internal slot. - void *fromBuf = GetDataPointFromBuffer(arrBuf.GetTaggedValue()); + void *fromBuf = GetDataPointFromBuffer(thread, arrBuf.GetTaggedValue()); // 24. Let toBuf be the value of new’s [[ArrayBufferData]] internal slot. - void *toBuf = GetDataPointFromBuffer(newJsArrBuf.GetTaggedValue()); + void *toBuf = GetDataPointFromBuffer(thread, newJsArrBuf.GetTaggedValue()); // 25. Perform CopyDataBlockBytes(toBuf, fromBuf, first, newLen). JSArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, first, newLen); } @@ -246,13 +246,13 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J // 24.1.1.2 IsDetachedBuffer() void BuiltinsArrayBuffer::IsDetachedBuffer(JSThread *thread, const JSHandle &arrayBuffer) { - JSTaggedValue detachedBuffer = arrayBuffer->GetViewedArrayBufferOrByteArray(); - if (IsDetachedBuffer(detachedBuffer)) { + JSTaggedValue detachedBuffer = arrayBuffer->GetViewedArrayBufferOrByteArray(thread); + if (IsDetachedBuffer(thread, detachedBuffer)) { THROW_TYPE_ERROR(thread, "The ArrayBuffer of this value is detached buffer."); } } -bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) +bool BuiltinsArrayBuffer::IsDetachedBuffer(JSThread *thread, JSTaggedValue arrayBuffer) { if (arrayBuffer.IsByteArray()) { return false; @@ -263,7 +263,7 @@ bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) if (buffer == nullptr) { LOG_ECMA(FATAL) << "BuiltinsArrayBuffer::IsDetachedBuffer:buffer is nullptr"; } - JSTaggedValue dataSlot = buffer->GetArrayBufferData(); + JSTaggedValue dataSlot = buffer->GetArrayBufferData(thread); // 2. If arrayBuffer’s [[ArrayBufferData]] internal slot is null, return true. // 3. Return false. return dataSlot.IsNull(); @@ -286,7 +286,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa // b. ReturnIfAbrupt(cloneConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (IsDetachedBuffer(thread, srcBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } else { ASSERT(constructor->IsConstructor()); @@ -317,7 +317,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa // 9. ReturnIfAbrupt(targetBuffer). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (IsDetachedBuffer(thread, srcBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 11. Let targetBlock be the value of targetBuffer’s [[ArrayBufferData]] internal slot. @@ -325,8 +325,8 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa // Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength). // 7. Let srcBlock be the value of srcBuffer’s [[ArrayBufferData]] internal slot. if (cloneLen > 0) { - void *fromBuf = GetDataPointFromBuffer(srcBuffer.GetTaggedValue()); - void *toBuf = GetDataPointFromBuffer(taggedBuf); + void *fromBuf = GetDataPointFromBuffer(thread, srcBuffer.GetTaggedValue()); + void *toBuf = GetDataPointFromBuffer(thread, taggedBuf); JSArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, srcByteOffset, cloneLen); } return taggedBuf; @@ -337,7 +337,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSThread *thread, JSTaggedValue arrBuf, uint32_t byteIndex, DataViewType type, bool littleEndian) { - void *pointer = GetDataPointFromBuffer(arrBuf); + void *pointer = GetDataPointFromBuffer(thread, arrBuf); uint8_t *block = reinterpret_cast(pointer); return GetValueFromBuffer(thread, byteIndex, block, type, littleEndian); } @@ -402,7 +402,7 @@ JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSThread *thread, JSTaggedVa } return JSTaggedValue::Undefined(); } - void *pointer = GetDataPointFromBuffer(arrBuf); + void *pointer = GetDataPointFromBuffer(thread, arrBuf); uint8_t *block = reinterpret_cast(pointer); JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -681,7 +681,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForBigInt(JSThread *thread, if (!littleEndian) { value = LittleEndianToBigEndian64Bit(value); } - void *pointer = GetDataPointFromBuffer(arrBuf.GetTaggedValue()); + void *pointer = GetDataPointFromBuffer(thread, arrBuf.GetTaggedValue()); uint8_t *block = reinterpret_cast(pointer); SetTypeData(block, value, byteIndex); } @@ -712,13 +712,13 @@ JSTaggedValue BuiltinsArrayBuffer::FastSetValueInBuffer(JSThread *thread, JSTagg DataViewType type, double val, bool littleEndian) { // origin type maybe native JSType or shared JSType. - if (arrBuf.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(arrBuf)) { + if (arrBuf.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, arrBuf)) { return JSTaggedValue::Undefined(); } - if (!arrBuf.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(arrBuf)) { + if (!arrBuf.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, arrBuf)) { return JSTaggedValue::Undefined(); } - void *pointer = GetDataPointFromBuffer(arrBuf); + void *pointer = GetDataPointFromBuffer(thread, arrBuf); uint8_t *block = reinterpret_cast(pointer); return SetValueInBuffer(thread, byteIndex, block, type, val, littleEndian); } @@ -769,7 +769,7 @@ JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSThread* thread, uint32_t b return JSTaggedValue::Undefined(); } -void *BuiltinsArrayBuffer::GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t byteOffset) +void *BuiltinsArrayBuffer::GetDataPointFromBuffer(JSThread *thread, JSTaggedValue arrBuf, uint32_t byteOffset) { if (arrBuf.IsByteArray()) { return reinterpret_cast(ToUintPtr(ByteArray::Cast(arrBuf.GetTaggedObject())->GetData()) + byteOffset); @@ -785,7 +785,7 @@ void *BuiltinsArrayBuffer::GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t UNREACHABLE(); } - JSTaggedValue data = arrayBuffer->GetArrayBufferData(); + JSTaggedValue data = arrayBuffer->GetArrayBufferData(thread); return reinterpret_cast(ToUintPtr(JSNativePointer::Cast(data.GetTaggedObject()) ->GetExternalPointer()) + byteOffset); } @@ -793,11 +793,11 @@ void *BuiltinsArrayBuffer::GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t JSTaggedValue BuiltinsArrayBuffer::TypedArrayToList(JSThread *thread, JSHandle& items) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle bufferHandle(thread, items->GetViewedArrayBufferOrByteArray()); + JSHandle bufferHandle(thread, items->GetViewedArrayBufferOrByteArray(thread)); uint32_t arrayLen = items->GetArrayLength(); JSHandle newArrayHandle(thread, JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle oldElements(thread, newArrayHandle->GetElements()); + JSHandle oldElements(thread, newArrayHandle->GetElements(thread)); JSHandle elements = (oldElements->GetLength() < arrayLen) ? factory->ExtendArray(oldElements, arrayLen) : oldElements; newArrayHandle->SetElements(thread, elements); @@ -927,8 +927,8 @@ JSTaggedValue BuiltinsArrayBuffer::TryFastSetValueInBuffer([[maybe_unused]] JSTh uint32_t byteBeginOffset, uint32_t byteEndOffset, DataViewType type, double val, bool littleEndian) { - uint8_t *beginPointer = reinterpret_cast(GetDataPointFromBuffer(arrBuf, byteBeginOffset)); - uint8_t *endPointer = reinterpret_cast(GetDataPointFromBuffer(arrBuf, byteEndOffset)); + uint8_t *beginPointer = reinterpret_cast(GetDataPointFromBuffer(thread, arrBuf, byteBeginOffset)); + uint8_t *endPointer = reinterpret_cast(GetDataPointFromBuffer(thread, arrBuf, byteEndOffset)); switch (type) { case DataViewType::UINT8: FastSetValueInBufferForByte(beginPointer, endPointer, val); diff --git a/ecmascript/builtins/builtins_arraybuffer.h b/ecmascript/builtins/builtins_arraybuffer.h index 1a0f5ff025..487f86a997 100644 --- a/ecmascript/builtins/builtins_arraybuffer.h +++ b/ecmascript/builtins/builtins_arraybuffer.h @@ -64,7 +64,7 @@ public: static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); // 24.1.1.2 IsDetachedBuffer(arrayBuffer) static void IsDetachedBuffer(JSThread *thread, const JSHandle &arrayBuffer); - static bool IsDetachedBuffer(JSTaggedValue arrayBuffer); + static bool IsDetachedBuffer(JSThread *thread, JSTaggedValue arrayBuffer); // 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian ) static JSTaggedValue GetValueFromBuffer(JSThread *thread, JSTaggedValue arrBuf, uint32_t byteIndex, DataViewType type, bool littleEndian); @@ -111,7 +111,7 @@ public: DataViewType type, double val, bool littleEndian); static JSTaggedValue GetValueFromBuffer(JSThread *thread, uint32_t byteIndex, uint8_t *block, DataViewType type, bool littleEndian); - static void *GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t byteOffset = 0); + static void *GetDataPointFromBuffer(JSThread *thread, JSTaggedValue arrBuf, uint32_t byteOffset = 0); protected: static constexpr uint64_t MAX_NATIVE_SIZE_LIMIT = 4_GB; diff --git a/ecmascript/builtins/builtins_async_from_sync_iterator.cpp b/ecmascript/builtins/builtins_async_from_sync_iterator.cpp index 633fba4ae9..10f3ccd05c 100644 --- a/ecmascript/builtins/builtins_async_from_sync_iterator.cpp +++ b/ecmascript/builtins/builtins_async_from_sync_iterator.cpp @@ -41,7 +41,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Next(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.Let syncIteratorRecord be O.[[SyncIteratorRecord]]. JSHandle asyncIterator(thisValue); - JSHandle syncIteratorRecord(thread, asyncIterator->GetSyncIteratorRecord()); + JSHandle syncIteratorRecord(thread, asyncIterator->GetSyncIteratorRecord(thread)); // 5.If value is present, then // a.Let result be IteratorNext(syncIteratorRecord, value). // 6.Else, @@ -76,8 +76,8 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. - JSHandle syncIteratorRecord(thread, asyncIterator->GetSyncIteratorRecord()); - JSHandle syncIterator(thread, syncIteratorRecord->GetIterator()); + JSHandle syncIteratorRecord(thread, asyncIterator->GetSyncIteratorRecord(thread)); + JSHandle syncIterator(thread, syncIteratorRecord->GetIterator(thread)); // 5.Let return be GetMethod(syncIterator, "throw"). JSHandle throwString = globalConstant->GetHandledThrowString(); JSHandle throwResult = JSObject::GetMethod(thread, syncIterator, throwString); @@ -87,12 +87,12 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) // 7.If throw is undefined, then if (throwResult->IsUndefined()) { JSHandle iterResult = JSIterator::CreateIterResultObject(thread, value, true); - JSHandle reject(thread, pcap->GetReject()); + JSHandle reject(thread, pcap->GetReject(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(iterResult.GetTaggedValue()); - return pcap->GetPromise(); + return pcap->GetPromise(thread); } JSTaggedValue ret; // 8.If value is present, then @@ -116,7 +116,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) JSHandle resolutionError = factory->GetJSError(ErrorType::TYPE_ERROR, "AsyncFromSyncIteratorPrototype.throw: is not Object.", StackCheck::NO); - JSHandle reject(thread, pcap->GetReject()); + JSHandle reject(thread, pcap->GetReject(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -125,7 +125,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Throw(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b.Return promiseCapability.[[Promise]]. - JSHandle promise(thread, pcap->GetPromise()); + JSHandle promise(thread, pcap->GetPromise(thread)); return promise.GetTaggedValue(); } // 12.Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). @@ -153,8 +153,8 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.Let syncIterator be O.[[SyncIteratorRecord]].[[Iterator]]. JSHandle asyncIterator(thisValue); - JSHandle syncIteratorRecord(thread, asyncIterator->GetSyncIteratorRecord()); - JSHandle syncIterator(thread, syncIteratorRecord->GetIterator()); + JSHandle syncIteratorRecord(thread, asyncIterator->GetSyncIteratorRecord(thread)); + JSHandle syncIterator(thread, syncIteratorRecord->GetIterator(thread)); // 5.Let return be GetMethod(syncIterator, "return"). JSHandle returnString = globalConstant->GetHandledReturnString(); JSHandle returnResult = JSObject::GetMethod(thread, syncIterator, returnString); @@ -165,12 +165,12 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) if (returnResult->IsUndefined()) { JSHandle iterResult = JSIterator::CreateIterResultObject(thread, value, true); JSHandle its = JSHandle::Cast(iterResult); - JSHandle resolve(thread, pcap->GetResolve()); + JSHandle resolve(thread, pcap->GetResolve(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefinedValue, undefinedValue, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(its.GetTaggedValue()); - JSHandle promise(thread, pcap->GetPromise()); + JSHandle promise(thread, pcap->GetPromise(thread)); return promise.GetTaggedValue(); } JSTaggedValue ret; @@ -195,7 +195,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) JSHandle resolutionError = factory->GetJSError(ErrorType::TYPE_ERROR, "AsyncFromSyncIteratorPrototype.return: is not Object.", StackCheck::NO); JSHandle rstErr = JSHandle::Cast(resolutionError); - JSHandle reject(thread, pcap->GetReject()); + JSHandle reject(thread, pcap->GetReject(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefinedValue, undefinedValue, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -204,7 +204,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::Return(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b.Return promiseCapability.[[Promise]]. - JSHandle promise(thread, pcap->GetPromise()); + JSHandle promise(thread, pcap->GetPromise(thread)); return promise.GetTaggedValue(); } // 12.Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). diff --git a/ecmascript/builtins/builtins_async_iterator.cpp b/ecmascript/builtins/builtins_async_iterator.cpp index d8129fd00f..fe1ebb1c37 100644 --- a/ecmascript/builtins/builtins_async_iterator.cpp +++ b/ecmascript/builtins/builtins_async_iterator.cpp @@ -50,14 +50,14 @@ JSTaggedValue BuiltinsAsyncIterator::Return(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle iterResult = JSIterator::CreateIterResultObject(thread, value, true); JSHandle iterResultVal(iterResult); - JSHandle resolve(thread, pcap->GetResolve()); + JSHandle resolve(thread, pcap->GetResolve(thread)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo* info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(iterResultVal.GetTaggedValue()); JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return pcap->GetPromise(); + return pcap->GetPromise(thread); } JSTaggedValue BuiltinsAsyncIterator::GetAsyncIteratorObj(EcmaRuntimeCallInfo *argv) diff --git a/ecmascript/builtins/builtins_atomics.cpp b/ecmascript/builtins/builtins_atomics.cpp index 9e095057c5..e9e7631916 100644 --- a/ecmascript/builtins/builtins_atomics.cpp +++ b/ecmascript/builtins/builtins_atomics.cpp @@ -271,7 +271,7 @@ JSTaggedValue BuiltinsAtomics::Notify(EcmaRuntimeCallInfo *argv) if (!arrayBuffer->IsSharedArrayBuffer()) { return JSTaggedValue(0); } - return JSTaggedValue(Signal(arrayBuffer, indexedPosition, c)); + return JSTaggedValue(Signal(thread, arrayBuffer, indexedPosition, c)); } template @@ -292,7 +292,7 @@ JSTaggedValue BuiltinsAtomics::AtomicReadModifyWrite(JSThread *thread, const JSH RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let arrayTypeName be typedArray.[[TypedArrayName]]. JSHandle arrayTypeName(thread, - JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName()); + JSTypedArray::Cast(typedArray->GetTaggedObject())->GetTypedArrayName(thread)); BuiltinsArrayBuffer::IsDetachedBuffer(thread, JSHandle::Cast(typedArray)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. NOTE: The above check is not redundant with the check in ValidateIntegerTypedArray because the call to @@ -312,43 +312,43 @@ JSTaggedValue BuiltinsAtomics::AtomicReadModifyWriteCase(JSThread *thread, JSTag BUILTINS_API_TRACE(thread, Atomics, AtomicReadModifyWriteCase); JSHandle arrBufHadle(thread, arrBuf); JSHandle value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); - void *pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + void *pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); uint8_t *block = reinterpret_cast(pointer); uint32_t size = argv->GetArgsNumber(); switch (type) { case DataViewType::UINT8: { uint8_t tag = JSTaggedValue::ToInt8(thread, value); - pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); block = reinterpret_cast(pointer); return HandleWithUint8(thread, size, block, indexedPosition, argv, op, tag); } case DataViewType::INT8:{ int8_t tag = JSTaggedValue::ToInt8(thread, value); - pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); block = reinterpret_cast(pointer); return HandleWithInt8(thread, size, block, indexedPosition, argv, op, tag); } case DataViewType::UINT16: { uint16_t tag = JSTaggedValue::ToInt16(thread, value); - pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); block = reinterpret_cast(pointer); return HandleWithUint16(thread, size, block, indexedPosition, argv, op, tag); } case DataViewType::INT16: { int16_t tag = JSTaggedValue::ToInt16(thread, value); - pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); block = reinterpret_cast(pointer); return HandleWithInt16(thread, size, block, indexedPosition, argv, op, tag); } case DataViewType::UINT32: { uint32_t tag = JSTaggedValue::ToUint32(thread, value); - pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); block = reinterpret_cast(pointer); return HandleWithUint32(thread, size, block, indexedPosition, argv, op, tag); } case DataViewType::INT32: { int32_t tag = static_cast(JSTaggedValue::ToUint32(thread, value)); - pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrBufHadle.GetTaggedValue()); + pointer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrBufHadle.GetTaggedValue()); block = reinterpret_cast(pointer); return HandleWithInt32(thread, size, block, indexedPosition, argv, op, tag); } @@ -571,7 +571,7 @@ WaitResult BuiltinsAtomics::DoWait(JSThread *thread, JSHandle &ar { BUILTINS_API_TRACE(thread, Atomics, DoWait); MutexGuard lockGuard(g_mutex); - void *buffer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrayBuffer.GetTaggedValue()); + void *buffer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrayBuffer.GetTaggedValue()); ASSERT(buffer != nullptr); WaiterListNode *node = thread->GetEcmaVM()->GetWaiterListNode(); node->date_ = buffer; @@ -617,9 +617,10 @@ WaitResult BuiltinsAtomics::DoWait(JSThread *thread, JSHandle &ar return res; } -uint32_t BuiltinsAtomics::Signal(JSHandle &arrayBuffer, const size_t &index, double wakeCount) +uint32_t BuiltinsAtomics::Signal(JSThread *thread, JSHandle &arrayBuffer, + const size_t &index, double wakeCount) { - void *buffer = BuiltinsArrayBuffer::GetDataPointFromBuffer(arrayBuffer.GetTaggedValue()); + void *buffer = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrayBuffer.GetTaggedValue()); ASSERT(buffer != nullptr); MutexGuard lockGuard(g_mutex); auto &locationListMap = g_waitLists->locationListMap_; diff --git a/ecmascript/builtins/builtins_atomics.h b/ecmascript/builtins/builtins_atomics.h index 421a6a0d5b..19110bf222 100644 --- a/ecmascript/builtins/builtins_atomics.h +++ b/ecmascript/builtins/builtins_atomics.h @@ -96,7 +96,8 @@ private: }; #undef BUILTINS_ATOMICS_FUNCTION_ENTRY - static uint32_t Signal(JSHandle &arrayBuffer, const size_t &index, double wakeCount); + static uint32_t Signal(JSThread *thread, JSHandle &arrayBuffer, + const size_t &index, double wakeCount); template static WaitResult DoWait(JSThread *thread, JSHandle &arrayBuffer, size_t index, T execpt, double timeout); diff --git a/ecmascript/builtins/builtins_bigint.cpp b/ecmascript/builtins/builtins_bigint.cpp index f16a668e8a..e013bfc311 100644 --- a/ecmascript/builtins/builtins_bigint.cpp +++ b/ecmascript/builtins/builtins_bigint.cpp @@ -214,7 +214,7 @@ JSTaggedValue BuiltinsBigInt::ThisBigIntValue(EcmaRuntimeCallInfo *argv) } // 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then if (value->IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(thread); // a. Assert: Type(value.[[BigIntData]]) is BigInt. if (primitive.IsBigInt()) { // b. Return value.[[BigIntData]]. diff --git a/ecmascript/builtins/builtins_boolean.cpp b/ecmascript/builtins/builtins_boolean.cpp index 2e7fe9cabe..b5dc92f3fe 100644 --- a/ecmascript/builtins/builtins_boolean.cpp +++ b/ecmascript/builtins/builtins_boolean.cpp @@ -55,7 +55,7 @@ JSTaggedValue BuiltinsBoolean::ThisBooleanValue(JSThread *thread, JSTaggedValue } // 2. If Type(value) is Object and value has a [[BooleanData]] internal slot, then if (value.IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(value.GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value.GetTaggedObject())->GetValue(thread); // a. Assert: value's [[BooleanData]] internal slot is a Boolean value. if (primitive.IsBoolean()) { // b. Return the value of value's [[BooleanData]] internal slot. diff --git a/ecmascript/builtins/builtins_cjs_module.cpp b/ecmascript/builtins/builtins_cjs_module.cpp index 8cfb3134aa..472ddccbf9 100644 --- a/ecmascript/builtins/builtins_cjs_module.cpp +++ b/ecmascript/builtins/builtins_cjs_module.cpp @@ -66,7 +66,7 @@ JSTaggedValue BuiltinsCjsModule::ResolveFilename(EcmaRuntimeCallInfo *argv) UNREACHABLE(); } JSHandle requestName = JSHandle::Cast(GetCallArg(argv, 0)); - CString requestNameStr = ModulePathHelper::Utf8ConvertToString(requestName.GetTaggedValue()); + CString requestNameStr = ModulePathHelper::Utf8ConvertToString(thread, requestName.GetTaggedValue()); CString filename = ResolveFilenameFromNative(thread, dirname, requestNameStr); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle filenameHdl = JSHandle::Cast(factory->NewFromUtf8(filename)); diff --git a/ecmascript/builtins/builtins_collator.cpp b/ecmascript/builtins/builtins_collator.cpp index d8b1415d31..aa3eea9e3d 100644 --- a/ecmascript/builtins/builtins_collator.cpp +++ b/ecmascript/builtins/builtins_collator.cpp @@ -97,7 +97,7 @@ JSTaggedValue BuiltinsCollator::Compare(EcmaRuntimeCallInfo *argv) // c. Set collator.[[BoundCompare]] to F. // 4. Return collator.[[BoundCompare]]. JSHandle collator = JSHandle::Cast(thisValue); - JSHandle boundCompare(thread, collator->GetBoundCompare()); + JSHandle boundCompare(thread, collator->GetBoundCompare(thread)); if (boundCompare->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction( @@ -105,7 +105,7 @@ JSTaggedValue BuiltinsCollator::Compare(EcmaRuntimeCallInfo *argv) intlBoundFunc->SetCollator(thread, collator); collator->SetBoundCompare(thread, intlBoundFunc); } - return collator->GetBoundCompare(); + return collator->GetBoundCompare(thread); } // 11.3.3.1 Collator Compare Functions @@ -119,7 +119,7 @@ JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) JSHandle intlBoundFunc = JSHandle::Cast(GetConstructor(argv)); // 1. Let collator be F.[[Collator]]. - JSHandle collator(thread, intlBoundFunc->GetCollator()); + JSHandle collator(thread, intlBoundFunc->GetCollator(thread)); // 2. Assert: Type(collator) is Object and collator has an [[InitializedCollator]] internal slot. ASSERT_PRINT(collator->IsJSObject() && collator->IsJSCollator(), "collator is not object or JSCollator"); @@ -137,7 +137,7 @@ JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) JSHandle yValue = JSTaggedValue::ToString(thread, y); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); // 7. Return CompareStrings(collator, X, Y). - icu::Collator *icuCollator = (JSHandle::Cast(collator))->GetIcuCollator(); + icu::Collator *icuCollator = (JSHandle::Cast(collator))->GetIcuCollator(thread); return JSCollator::CompareStrings(thread, icuCollator, xValue, yValue); } diff --git a/ecmascript/builtins/builtins_dataview.cpp b/ecmascript/builtins/builtins_dataview.cpp index a2376e822e..81df8b2c0a 100644 --- a/ecmascript/builtins/builtins_dataview.cpp +++ b/ecmascript/builtins/builtins_dataview.cpp @@ -48,7 +48,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint64_t offset = base::NumberHelper::DoubleToUInt64(offsetNumber.GetNumber()); // 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(bufferHandle.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, bufferHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception()); } // 8. Let bufferByteLength be the value of buffer’s [[ArrayBufferByteLength]] internal slot. @@ -112,7 +112,7 @@ JSTaggedValue BuiltinsDataView::GetBuffer(EcmaRuntimeCallInfo *argv) } JSHandle dataView(thisHandle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(thread); // 5. Return buffer. return JSTaggedValue(buffer); } @@ -136,9 +136,9 @@ JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv) } JSHandle dataView(thisHandle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(thread); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. @@ -166,9 +166,9 @@ JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv) } JSHandle dataView(thisHandle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(thread); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. @@ -374,9 +374,9 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle dataView(view); - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(thread); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot. @@ -440,9 +440,9 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle dataView(view); - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = dataView->GetViewedArrayBuffer(thread); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot. diff --git a/ecmascript/builtins/builtins_date.cpp b/ecmascript/builtins/builtins_date.cpp index 3aea902e35..9b851c9c04 100644 --- a/ecmascript/builtins/builtins_date.cpp +++ b/ecmascript/builtins/builtins_date.cpp @@ -51,7 +51,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) JSHandle value = GetCallArg(argv, 0); if (value->IsDate()) { // The value is a date object. JSHandle jsDate(thread, JSDate::Cast(value->GetTaggedObject())); - timeValue = jsDate->GetTimeValue(); + timeValue = jsDate->GetTimeValue(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { JSHandle objValue(thread, JSTaggedValue::ToPrimitive(thread, value)); @@ -115,7 +115,7 @@ JSTaggedValue BuiltinsDate::GetTime(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } - return JSDate::Cast(msg->GetTaggedObject())->GetTime(); + return JSDate::Cast(msg->GetTaggedObject())->GetTime(thread); } JSTaggedValue BuiltinsDate::SetTime(EcmaRuntimeCallInfo *argv) @@ -180,7 +180,7 @@ JSTaggedValue BuiltinsDate::ValueOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } - return JSDate::Cast(msg->GetTaggedObject())->ValueOf(); + return JSDate::Cast(msg->GetTaggedObject())->ValueOf(thread); } // 20.4.4.45 @@ -234,7 +234,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } - JSTaggedValue value = JSDate::Cast(msg->GetTaggedObject())->GetTime(); + JSTaggedValue value = JSDate::Cast(msg->GetTaggedObject())->GetTime(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If x is NaN, return "Invalid Date". @@ -315,7 +315,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } - JSTaggedValue value = JSDate::Cast(msg->GetTaggedObject())->GetTime(); + JSTaggedValue value = JSDate::Cast(msg->GetTaggedObject())->GetTime(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If x is NaN, return "Invalid Date". @@ -396,7 +396,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } - JSTaggedValue value = JSDate::Cast(msg->GetTaggedObject())->GetTime(); + JSTaggedValue value = JSDate::Cast(msg->GetTaggedObject())->GetTime(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If x is NaN, return "Invalid Date". diff --git a/ecmascript/builtins/builtins_date_time_format.cpp b/ecmascript/builtins/builtins_date_time_format.cpp index 9410893cdb..b54a10b98a 100644 --- a/ecmascript/builtins/builtins_date_time_format.cpp +++ b/ecmascript/builtins/builtins_date_time_format.cpp @@ -68,7 +68,8 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (isInstanceOf) { PropertyDescriptor descriptor(thread, JSHandle::Cast(dtf), false, false, false); - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSHandle key(thread, + JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol(thread)); JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return thisValue.GetTaggedValue(); @@ -128,7 +129,7 @@ JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) // c. Set dtf.[[BoundFormat]] to F. // 5. Return dtf.[[BoundFormat]]. JSHandle dtf = JSHandle::Cast(dtfValue); - JSHandle boundFormat(thread, dtf->GetBoundFormat()); + JSHandle boundFormat(thread, dtf->GetBoundFormat(thread)); if (boundFormat->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction( @@ -136,7 +137,7 @@ JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) intlBoundFunc->SetDateTimeFormat(thread, dtf); dtf->SetBoundFormat(thread, intlBoundFunc); } - return dtf->GetBoundFormat(); + return dtf->GetBoundFormat(thread); } // 13.1.5 DateTime Format Functions @@ -150,7 +151,7 @@ JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInf JSHandle intlBoundFunc = JSHandle::Cast(GetConstructor(argv)); // 1. Let dtf be F.[[DateTimeFormat]]. - JSHandle dtf(thread, intlBoundFunc->GetDateTimeFormat()); + JSHandle dtf(thread, intlBoundFunc->GetDateTimeFormat(thread)); // 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]] internal slot. ASSERT_PRINT(dtf->IsJSObject() && dtf->IsJSDateTimeFormat(), "dtf is not object or JSDateTimeFormat"); diff --git a/ecmascript/builtins/builtins_displaynames.cpp b/ecmascript/builtins/builtins_displaynames.cpp index 6fb93f1de4..9e6fc9fc58 100644 --- a/ecmascript/builtins/builtins_displaynames.cpp +++ b/ecmascript/builtins/builtins_displaynames.cpp @@ -96,7 +96,7 @@ JSTaggedValue BuiltinsDisplayNames::Of(EcmaRuntimeCallInfo *argv) TypednsOption typeOpt = displayNames->GetType(); JSHandle code = JSDisplayNames::CanonicalCodeForDisplayNames(thread, displayNames, typeOpt, codeTemp); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - std::string codeString = intl::LocaleHelper::ConvertToStdString(code); + std::string codeString = intl::LocaleHelper::ConvertToStdString(thread, code); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (codeString.size()) { JSHandle codeStr = JSHandle::Cast(code); diff --git a/ecmascript/builtins/builtins_finalization_registry.cpp b/ecmascript/builtins/builtins_finalization_registry.cpp index 26e0d4dd06..362e849dc4 100644 --- a/ecmascript/builtins/builtins_finalization_registry.cpp +++ b/ecmascript/builtins/builtins_finalization_registry.cpp @@ -78,7 +78,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "target invalid", JSTaggedValue::Exception()); } // 4. If SameValue(target, heldValue) is true, throw a TypeError exception. - if (JSTaggedValue::SameValue(target, heldValue)) { + if (JSTaggedValue::SameValue(thread, target, heldValue)) { THROW_TYPE_ERROR_AND_RETURN(thread, "target and heldValue should not be equal", JSTaggedValue::Exception()); } // 5. If CanBeHeldWeakly(unregisterToken) is false, then diff --git a/ecmascript/builtins/builtins_function.cpp b/ecmascript/builtins/builtins_function.cpp index 64c1f400b3..4e49294d42 100644 --- a/ecmascript/builtins/builtins_function.cpp +++ b/ecmascript/builtins/builtins_function.cpp @@ -64,13 +64,13 @@ static std::pair BuildArgumentsListFast(JSThread *thread, { if (arrayObj->IsStableJSArguments(thread)) { JSHandle argList = JSHandle::Cast(arrayObj); - TaggedArray *elements = TaggedArray::Cast(argList->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(argList->GetElements(thread).GetTaggedObject()); auto env = thread->GetEcmaVM()->GetGlobalEnv(); if (argList->GetClass() != env->GetArgumentsClass().GetObject()) { return std::make_pair(nullptr, 0); } auto result = argList->GetPropertyInlinedPropsWithSize< - JSArguments::SIZE, JSArguments::LENGTH_INLINE_PROPERTY_INDEX>(); + JSArguments::SIZE, JSArguments::LENGTH_INLINE_PROPERTY_INDEX>(thread); if (!result.IsInt()) { return std::make_pair(nullptr, 0); } @@ -80,9 +80,9 @@ static std::pair BuildArgumentsListFast(JSThread *thread, } else if (arrayObj->IsStableJSArray(thread)) { JSHandle argList = JSHandle::Cast(arrayObj); TaggedArray *elements = nullptr; - if (argList->GetElements().IsMutantTaggedArray()) { + if (argList->GetElements(thread).IsMutantTaggedArray()) { JSHandle obj(arrayObj); - int elementsLength = static_cast(ElementAccessor::GetElementsLength(obj)); + int elementsLength = static_cast(ElementAccessor::GetElementsLength(thread, obj)); JSHandle newElements = thread->GetEcmaVM()->GetFactory()-> NewTaggedArray(elementsLength, JSTaggedValue::Undefined()); for (int i = 0; i < elementsLength; ++i) { @@ -91,7 +91,7 @@ static std::pair BuildArgumentsListFast(JSThread *thread, } elements = *newElements; } else { - elements = TaggedArray::Cast(argList->GetElements().GetTaggedObject()); + elements = TaggedArray::Cast(argList->GetElements(thread).GetTaggedObject()); } size_t length = argList->GetArrayLength(); if (elements->GetLength() == 0 && length != 0) { @@ -212,7 +212,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBindInternal(JSThread *thread, JSHandle obj(thread, target.GetTaggedValue()); uint32_t numberOfInlinedProps = obj->GetJSHClass()->GetInlinedProperties(); if (JSFunction::LENGTH_INLINE_PROPERTY_INDEX < numberOfInlinedProps) { - lengthProperty = obj->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX); + lengthProperty = obj->GetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX); } } if (lengthProperty.IsHole()) { @@ -266,7 +266,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBindInternal(JSThread *thread, JSHandle obj(thread, target.GetTaggedValue()); uint32_t numberOfInlinedProps = obj->GetJSHClass()->GetInlinedProperties(); if (JSFunction::NAME_INLINE_PROPERTY_INDEX < numberOfInlinedProps) { - nameProperty = obj->GetPropertyInlinedProps(JSFunction::NAME_INLINE_PROPERTY_INDEX); + nameProperty = obj->GetPropertyInlinedProps(thread, JSFunction::NAME_INLINE_PROPERTY_INDEX); } } if (nameProperty.IsHole()) { @@ -345,7 +345,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeToString(EcmaRuntimeCallInfo *a return GetTaggedString(thread, str.c_str()); } else { JSHandle func = JSHandle::Cast(thisValue); - JSHandle methodHandle(thread, func->GetMethod()); + JSHandle methodHandle(thread, func->GetMethod(thread)); method = JSHandle::Cast(methodHandle); } if (method->IsNativeWithCallField()) { @@ -353,14 +353,14 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeToString(EcmaRuntimeCallInfo *a JSHandle name = JSObject::GetProperty(thread, thisValue, nameKey).GetValue(); JSHandle methodName = JSTaggedValue::ToString(thread, name); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - std::string nameStr = EcmaStringAccessor(methodName).ToStdString(); + std::string nameStr = EcmaStringAccessor(methodName).ToStdString(thread); std::string startStr = "function "; std::string endStr = "() { [native code] }"; startStr.append(nameStr).append(endStr); return GetTaggedString(thread, startStr.c_str()); } DebugInfoExtractor *debugExtractor = - JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile()); + JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile(thread)); const std::string &sourceCode = debugExtractor->GetSourceCode(method->GetMethodId()); if (!sourceCode.empty()) { return GetTaggedString(thread, sourceCode.c_str()); diff --git a/ecmascript/builtins/builtins_gc.cpp b/ecmascript/builtins/builtins_gc.cpp index f162de5aab..2cae772c95 100644 --- a/ecmascript/builtins/builtins_gc.cpp +++ b/ecmascript/builtins/builtins_gc.cpp @@ -211,28 +211,28 @@ JSTaggedValue BuiltinsGc::AllocateArrayObject(EcmaRuntimeCallInfo *info) TriggerGCType BuiltinsGc::StringToGcType(JSThread *thread, JSTaggedValue cause) { static_assert(GC_TYPE_LAST == 8, "Update this method after TrigerGCType change"); - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetYoungGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetYoungGcCause(), cause)) { return YOUNG_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetOldGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetOldGcCause(), cause)) { return OLD_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetFullGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetFullGcCause(), cause)) { return FULL_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetAppSpawnFullGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetAppSpawnFullGcCause(), cause)) { return APPSPAWN_FULL_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetSharedGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetSharedGcCause(), cause)) { return SHARED_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetSharedPartialGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetSharedPartialGcCause(), cause)) { return SHARED_PARTIAL_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetSharedFullGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetSharedFullGcCause(), cause)) { return SHARED_FULL_GC; } - if (JSTaggedValue::StrictEqual(thread->GlobalConstants()->GetAppSpawnSharedFullGcCause(), cause)) { + if (JSTaggedValue::StrictEqual(thread, thread->GlobalConstants()->GetAppSpawnSharedFullGcCause(), cause)) { return APPSPAWN_SHARED_FULL_GC; } return GC_TYPE_LAST; diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index 579d51a7e6..72cd4af812 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -230,7 +230,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle= base::utf_helper::DECODE_TRAIL_LOW && cc <= base::utf_helper::DECODE_TRAIL_HIGH) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(string.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, string.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -256,12 +256,12 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle base::utf_helper::DECODE_TRAIL_HIGH) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(string.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, string.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } vv = base::utf_helper::UTF16Decode(cc, kc); @@ -305,7 +305,7 @@ uint8_t BuiltinsGlobal::GetValueFromTwoHex(uint16_t front, uint16_t behind) return res; } -uint16_t BuiltinsGlobal::GetValueFromHexString(const JSHandle &string) +uint16_t BuiltinsGlobal::GetValueFromHexString(JSThread *thread, const JSHandle &string) { uint32_t size = EcmaStringAccessor(string).GetLength(); ASSERT(size > 0 && size <= 4); // NOLINT 4: means 4 hex digits @@ -313,14 +313,14 @@ uint16_t BuiltinsGlobal::GetValueFromHexString(const JSHandle &strin uint16_t ret = 0; for (uint32_t i = 0; i < size; ++i) { - uint16_t ch = EcmaStringAccessor(string).Get(i); + uint16_t ch = EcmaStringAccessor(string).Get(thread, i); size_t idx = StringHelper::FindFromU16ToUpper(hexString, &ch); ret = ((ret << 4U) | idx) & BIT_MASK_4F; // NOLINT 4: means shift left by 4 } return ret; } #else // ENABLE_NEXT_OPTIMIZATION -uint16_t BuiltinsGlobal::GetValueFromHexString(const JSHandle &string) +uint16_t BuiltinsGlobal::GetValueFromHexString(JSThread *thread, const JSHandle &string) { auto stringAcc = EcmaStringAccessor(string); uint32_t size = stringAcc.GetLength(); @@ -328,7 +328,7 @@ uint16_t BuiltinsGlobal::GetValueFromHexString(const JSHandle &strin uint16_t ret = 0; for (uint32_t i = 0; i < size; ++i) { - uint16_t ch = stringAcc.Get(i); + uint16_t ch = stringAcc.Get(thread, i); size_t val = base::utf_helper::HexChar16Value(ch); ret = ((ret << 4U) | val) & BIT_MASK_4F; // NOLINT 4: means shift left by 4 } @@ -402,7 +402,7 @@ EcmaString *BuiltinsGlobal::StringToCodePoints(JSThread *thread, const JSHandle< // c. Set position to position + cp.[[CodeUnitCount]]. while (position < size) { // i.Let first be the code unit at index position within string. - uint16_t first = EcmaStringAccessor(string).Get(position); + uint16_t first = EcmaStringAccessor(string).Get(thread, position); uint16_t cp = first - CHAR16_LETTER_NULL; uint8_t codeUnitCount = 0; bool isUnpairedSurrogate = false; @@ -418,7 +418,7 @@ EcmaString *BuiltinsGlobal::StringToCodePoints(JSThread *thread, const JSHandle< isUnpairedSurrogate = true; } else { // iv. Let second be the code unit at index position + 1 within string. - uint16_t second = EcmaStringAccessor(string).Get(position + 1); + uint16_t second = EcmaStringAccessor(string).Get(thread, position + 1); // v. If second is not a trailing surrogate, then // a. Return the Record { [[CodePoint]]: cp, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: true }. if (!IsUTF16LowSurrogate(second)) { @@ -481,7 +481,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandleGetEcmaVM(), str, start, k - start + 1U); sStr = StringHelper::StringToU16string( - EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION)); + EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION)); } } @@ -522,13 +522,13 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa // iii. If the code units at index (k+1) and (k + 2) within string do not represent hexadecimal digits, // throw a URIError exception. if ((k + 2) >= strLen) { // 2: means plus 2 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } - uint16_t frontChar = EcmaStringAccessor(str).Get(k + 1); - uint16_t behindChar = EcmaStringAccessor(str).Get(k + 2); // 2: means plus 2 + uint16_t frontChar = EcmaStringAccessor(str).Get(thread, k + 1); + uint16_t behindChar = EcmaStringAccessor(str).Get(thread, k + 2); // 2: means plus 2 if (!(IsHexDigits(frontChar) && IsHexDigits(behindChar))) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint8_t bb = GetValueFromTwoHex(frontChar, behindChar); @@ -567,7 +567,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa } // 2. If n equals 1 or n is greater than 4, throw a URIError exception. if ((n == 1) || (n > 4)) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -575,7 +575,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa // 5. If k + (3 × (n – 1)) is greater than or equal to strLen, throw a URIError exception. if (k + (3 * (n - 1)) >= strLen) { // 3: means multiply by 3 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } DecodePercentEncoding(thread, n, k, str, bb, oct); @@ -594,25 +594,25 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, int32_t &n int32_t j = 1; while (j < n) { k++; - uint16_t codeUnit = EcmaStringAccessor(str).Get(k); + uint16_t codeUnit = EcmaStringAccessor(str).Get(thread, k); // b. If the code unit at index k within string is not "%", throw a URIError exception. // c. If the code units at index (k +1) and (k + 2) within string do not represent hexadecimal // digits, throw a URIError exception. if (!(codeUnit == '%')) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } - if (!(IsHexDigits(EcmaStringAccessor(str).Get(k + 1)) && - IsHexDigits(EcmaStringAccessor(str).Get(k + 2)))) { // 2: means plus 2 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + if (!(IsHexDigits(EcmaStringAccessor(str).Get(thread, k + 1)) && + IsHexDigits(EcmaStringAccessor(str).Get(thread, k + 2)))) { // 2: means plus 2 + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } - uint16_t frontChart = EcmaStringAccessor(str).Get(k + 1); - uint16_t behindChart = EcmaStringAccessor(str).Get(k + 2); // 2: means plus 2 + uint16_t frontChart = EcmaStringAccessor(str).Get(thread, k + 1); + uint16_t behindChart = EcmaStringAccessor(str).Get(thread, k + 2); // 2: means plus 2 bb = GetValueFromTwoHex(frontChart, behindChart); // e. If the two most significant bits in B are not 10, throw a URIError exception. if (!((bb & BIT_MASK_TWO) == BIT_MASK_ONE)) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } k += 2; // 2: means plus 2 @@ -627,7 +627,7 @@ JSTaggedValue BuiltinsGlobal::UTF16EncodeCodePoint(JSThread *thread, judgURIFunc uint32_t &start, int32_t &k, std::u16string &sStr) { if (!base::utf_helper::IsValidUTF8(oct)) { - CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint32_t vv = StringHelper::Utf8ToU32String(oct); @@ -638,7 +638,7 @@ JSTaggedValue BuiltinsGlobal::UTF16EncodeCodePoint(JSThread *thread, judgURIFunc auto substr = EcmaStringAccessor::FastSubString( thread->GetEcmaVM(), str, start, static_cast(k) - start + 1U); sStr = StringHelper::StringToU16string( - EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION)); + EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION)); } } else { uint16_t lv = (((vv - base::utf_helper::DECODE_SECOND_FACTOR) & BIT16_MASK) + @@ -658,7 +658,7 @@ void BuiltinsGlobal::PrintString([[maybe_unused]] JSThread *thread, EcmaString * return; } BUILTINS_API_TRACE(thread, Global, PrintString); - CString buffer = ConvertToString(string); + CString buffer = ConvertToString(thread, string); std::cout << buffer; } @@ -727,7 +727,7 @@ JSTaggedValue BuiltinsGlobal::LoadNativeModule(EcmaRuntimeCallInfo *msg) EcmaVM *vm = thread->GetEcmaVM(); auto [moduleName, fileName] = vm->GetCurrentModuleInfo(false); std::shared_ptr curJsPandaFile; - CString requestPath = ModulePathHelper::Utf8ConvertToString(input.GetTaggedValue()); + CString requestPath = ModulePathHelper::Utf8ConvertToString(thread, input.GetTaggedValue()); CString abcFilePath = fileName.c_str(); if (moduleName.size() != 0) { curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( @@ -768,7 +768,7 @@ JSTaggedValue BuiltinsGlobal::CallJsBoundFunction(EcmaRuntimeCallInfo *msg) // msg contains jsfunc, this, arg1,... JSHandle boundFunc(GetConstructor(msg)); - JSHandle thisObj(thread, boundFunc->GetBoundThis()); + JSHandle thisObj(thread, boundFunc->GetBoundThis(thread)); msg->SetThis(thisObj.GetTaggedValue()); return RuntimeStubs::CallBoundFunction(msg); } @@ -879,7 +879,7 @@ JSTaggedValue BuiltinsGlobal::Escape(EcmaRuntimeCallInfo *msg) // d. Set R to the string-concatenation of R and S. // e. Set k to k + 1. while (k < len) { - uint16_t c = EcmaStringAccessor(string).Get(k); + uint16_t c = EcmaStringAccessor(string).Get(thread, k); if (c < std::numeric_limits::max() && ESCAPE_BIT_MAP[c] == 1) { r.push_back(c); } else { @@ -941,14 +941,14 @@ JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) // c. Set R to the string-concatenation of R and C. // d. Set k to k + 1. while (k < len) { - uint16_t c = EcmaStringAccessor(string).Get(k); + uint16_t c = EcmaStringAccessor(string).Get(thread, k); if (c == '%') { - uint16_t c1 = EcmaStringAccessor(string).Get(k + 1); + uint16_t c1 = EcmaStringAccessor(string).Get(thread, k + 1); if (k + ESCAPE_CHAR_OFFSET5 < len && c1 == 'u') { - uint16_t c2 = EcmaStringAccessor(string).Get(k + ESCAPE_CHAR_OFFSET2); - uint16_t c3 = EcmaStringAccessor(string).Get(k + ESCAPE_CHAR_OFFSET3); - uint16_t c4 = EcmaStringAccessor(string).Get(k + ESCAPE_CHAR_OFFSET4); - uint16_t c5 = EcmaStringAccessor(string).Get(k + ESCAPE_CHAR_OFFSET5); + uint16_t c2 = EcmaStringAccessor(string).Get(thread, k + ESCAPE_CHAR_OFFSET2); + uint16_t c3 = EcmaStringAccessor(string).Get(thread, k + ESCAPE_CHAR_OFFSET3); + uint16_t c4 = EcmaStringAccessor(string).Get(thread, k + ESCAPE_CHAR_OFFSET4); + uint16_t c5 = EcmaStringAccessor(string).Get(thread, k + ESCAPE_CHAR_OFFSET5); #if !ENABLE_NEXT_OPTIMIZATION bool c2IsHexDigits = IsHexDigits(c2); bool c3IsHexDigits = IsHexDigits(c3); @@ -969,7 +969,7 @@ JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) k = k + ESCAPE_CHAR_OFFSET5; } } else if (k + ESCAPE_CHAR_OFFSET3 <= len) { - uint16_t c2 = EcmaStringAccessor(string).Get(k + ESCAPE_CHAR_OFFSET2); + uint16_t c2 = EcmaStringAccessor(string).Get(thread, k + ESCAPE_CHAR_OFFSET2); #if !ENABLE_NEXT_OPTIMIZATION bool c1IsHexDigits = IsHexDigits(c1); bool c2IsHexDigits = IsHexDigits(c2); diff --git a/ecmascript/builtins/builtins_global.h b/ecmascript/builtins/builtins_global.h index 2c153733b4..acdd3de8cb 100644 --- a/ecmascript/builtins/builtins_global.h +++ b/ecmascript/builtins/builtins_global.h @@ -232,7 +232,7 @@ private: static bool IsHexDigits(uint16_t ch); static uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind); #endif // ENABLE_NEXT_OPTIMIZATION - static uint16_t GetValueFromHexString(const JSHandle &string); + static uint16_t GetValueFromHexString(JSThread *thread, const JSHandle &string); // 22.1.3.17.2 StringPad ( S, maxLength, fillString, placement ) static EcmaString *StringPad(JSThread *thread, const JSHandle &string, diff --git a/ecmascript/builtins/builtins_global_uri.cpp b/ecmascript/builtins/builtins_global_uri.cpp index b0e495d045..62523d4955 100644 --- a/ecmascript/builtins/builtins_global_uri.cpp +++ b/ecmascript/builtins/builtins_global_uri.cpp @@ -95,7 +95,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle(cc)); } else { @@ -103,7 +103,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle= base::utf_helper::DECODE_TRAIL_LOW && cc <= base::utf_helper::DECODE_TRAIL_HIGH) { JSTaggedValue strVal = isTreeString ? string.GetTaggedValue() : str.GetTaggedValue(); - errorMsg = "DecodeURI: invalid character: " + ConvertToString(strVal); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, strVal); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -122,13 +122,13 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle base::utf_helper::DECODE_TRAIL_HIGH) { JSTaggedValue strVal = isTreeString ? string.GetTaggedValue() : str.GetTaggedValue(); - errorMsg = "DecodeURI: invalid character: " + ConvertToString(strVal); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, strVal); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } vv = base::utf_helper::UTF16Decode(cc, kc); @@ -162,7 +162,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandleGetParent(); + auto parent = SlicedEcmaString::Cast(string.GetTaggedValue())->GetParent(thread); auto parentStrAcc = EcmaStringAccessor(parent); auto startIndex = SlicedEcmaString::Cast(string.GetTaggedValue())->GetStartIndex(); if (parentStrAcc.IsLineString() && !parentStrAcc.IsUtf8()) { @@ -243,7 +243,7 @@ void BuiltinsGlobal::HandleSingleByteCharacter(JSThread *thread, uint8_t &bb, auto substr = EcmaStringAccessor::FastSubString( thread->GetEcmaVM(), str, start, k - start + 1U); resStr.append(StringHelper::StringToU16string( - EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION))); + EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION))); } } @@ -258,13 +258,13 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa // iii. If the code units at index (k+1) and (k + 2) within string do not represent hexadecimal digits, // throw a URIError exception. if ((k + 2) >= strLen) { // 2: means plus 2 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint16_t frontChar = GetCodeUnit(sp, k + 1, strLen); uint16_t behindChar = GetCodeUnit(sp, k + 2, strLen); // 2: means plus 2 if (!(base::utf_helper::IsHexDigits(frontChar) && base::utf_helper::IsHexDigits(behindChar))) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint8_t bb = base::utf_helper::GetValueFromTwoHex(frontChar, behindChar); @@ -303,7 +303,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa } // 2. If n equals 1 or n is greater than 4, throw a URIError exception. if ((n == 1) || (n > 4)) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -311,7 +311,7 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, const JSHa // 5. If k + (3 × (n – 1)) is greater than or equal to strLen, throw a URIError exception. if (k + (3 * (n - 1)) >= strLen) { // 3: means multiply by 3 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } DecodePercentEncoding(thread, n, k, str, bb, oct, sp, strLen); @@ -336,19 +336,19 @@ JSTaggedValue BuiltinsGlobal::DecodePercentEncoding(JSThread *thread, int32_t &n // c. If the code units at index (k +1) and (k + 2) within string do not represent hexadecimal // digits, throw a URIError exception. if (!(codeUnit == '%')) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint16_t frontChart = GetCodeUnit(sp, k + 1, strLen); uint16_t behindChart = GetCodeUnit(sp, k + 2, strLen); // 2: means plus 2 if (!(base::utf_helper::IsHexDigits(frontChart) && base::utf_helper::IsHexDigits(behindChart))) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } bb = base::utf_helper::GetValueFromTwoHex(frontChart, behindChart); // e. If the two most significant bits in B are not 10, throw a URIError exception. if (!((bb & BIT_MASK_TWO) == BIT_MASK_ONE)) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } k += 2; // 2: means plus 2 @@ -363,7 +363,7 @@ JSTaggedValue BuiltinsGlobal::UTF16EncodeCodePoint(JSThread *thread, judgURIFunc uint32_t &start, int32_t &k, std::u16string &resStr) { if (!base::utf_helper::IsValidUTF8(oct)) { - CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint32_t vv = StringHelper::Utf8ToU32String(oct); @@ -374,7 +374,7 @@ JSTaggedValue BuiltinsGlobal::UTF16EncodeCodePoint(JSThread *thread, judgURIFunc auto substr = EcmaStringAccessor::FastSubString( thread->GetEcmaVM(), str, start, static_cast(k) - start + 1U); resStr.append(StringHelper::StringToU16string( - EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION))); + EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION))); } } else { uint16_t lv = (((vv - base::utf_helper::DECODE_SECOND_FACTOR) & BIT16_MASK) + diff --git a/ecmascript/builtins/builtins_lazy_callback.cpp b/ecmascript/builtins/builtins_lazy_callback.cpp index 64f613b64f..7388b2ea98 100644 --- a/ecmascript/builtins/builtins_lazy_callback.cpp +++ b/ecmascript/builtins/builtins_lazy_callback.cpp @@ -224,21 +224,21 @@ void BuiltinsLazyCallback::ResetLazyInternalAttr(JSThread *thread, const JSHandl ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle key(factory->NewFromUtf8ReadOnly(name)); if (LIKELY(!hclass->IsDictionaryMode())) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); uint32_t propsNumber = hclass->NumberOfProps(); int entry = layoutInfo->FindElementWithCache(thread, hclass, key.GetTaggedValue(), propsNumber); if (entry != -1) { - PropertyAttributes attr(layoutInfo->GetAttr(entry)); + PropertyAttributes attr(layoutInfo->GetAttr(thread, entry)); attr.SetIsAccessor(false); layoutInfo->SetNormalAttr(thread, entry, attr); } } else { - TaggedArray *array = TaggedArray::Cast(object->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(object->GetProperties(thread).GetTaggedObject()); ASSERT(array->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key.GetTaggedValue()); + int entry = dict->FindEntry(thread, key.GetTaggedValue()); if (entry != -1) { - auto attr = dict->GetAttributes(entry); + auto attr = dict->GetAttributes(thread, entry); attr.SetIsAccessor(false); dict->SetAttributes(thread, entry, attr); } diff --git a/ecmascript/builtins/builtins_locale.cpp b/ecmascript/builtins/builtins_locale.cpp index cf8ee80e15..4f7c40c9a4 100644 --- a/ecmascript/builtins/builtins_locale.cpp +++ b/ecmascript/builtins/builtins_locale.cpp @@ -56,7 +56,7 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) localeString = JSTaggedValue::ToString(thread, tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - icu::Locale *icuLocale = (JSHandle::Cast(tag))->GetIcuLocale(); + icu::Locale *icuLocale = (JSHandle::Cast(tag))->GetIcuLocale(thread); localeString = intl::LocaleHelper::ToLanguageTag(thread, *icuLocale); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -93,7 +93,7 @@ JSTaggedValue BuiltinsLocale::Maximize(EcmaRuntimeCallInfo *argv) // 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is // signaled, set maximal to loc.[[Locale]]. JSHandle locale = JSHandle::Cast(loc); - icu::Locale source(*(locale->GetIcuLocale())); + icu::Locale source(*(locale->GetIcuLocale(thread))); UErrorCode status = U_ZERO_ERROR; source.addLikelySubtags(status); ASSERT(U_SUCCESS(status)); @@ -126,7 +126,7 @@ JSTaggedValue BuiltinsLocale::Minimize(EcmaRuntimeCallInfo *argv) // 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. // If an error is signaled, set minimal to loc.[[Locale]]. JSHandle locale = JSHandle::Cast(loc); - icu::Locale source(*(locale->GetIcuLocale())); + icu::Locale source(*(locale->GetIcuLocale(thread))); UErrorCode status = U_ZERO_ERROR; source.minimizeSubtags(status); ASSERT(U_SUCCESS(status)); @@ -175,7 +175,7 @@ JSTaggedValue BuiltinsLocale::GetBaseName(EcmaRuntimeCallInfo *argv) // 3. Let locale be loc.[[Locale]]. // 4. Return the substring of locale corresponding to the unicode_language_id production. JSHandle locale = JSHandle::Cast(loc); - icu::Locale icuLocale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName()); + icu::Locale icuLocale = icu::Locale::createFromName(locale->GetIcuLocale(thread)->getBaseName()); JSHandle baseName = intl::LocaleHelper::ToLanguageTag(thread, icuLocale); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return baseName.GetTaggedValue(); @@ -264,7 +264,7 @@ JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[Numeric]]. JSHandle locale = JSHandle::Cast(loc); - icu::Locale *icuLocale = locale->GetIcuLocale(); + icu::Locale *icuLocale = locale->GetIcuLocale(thread); UErrorCode status = U_ZERO_ERROR; auto numeric = icuLocale->getUnicodeKeywordValue("kn", status); JSTaggedValue result = (numeric == "true") ? JSTaggedValue::True() : JSTaggedValue::False(); @@ -306,7 +306,7 @@ JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv) // 5. Return the substring of locale corresponding to the unicode_language_subtag production of the // unicode_language_id. JSHandle result = JSHandle::Cast(thread->GlobalConstants()->GetHandledUndefinedString()); - CString language = locale->GetIcuLocale()->getLanguage(); + CString language = locale->GetIcuLocale(thread)->getLanguage(); if (language.empty()) { return result.GetTaggedValue(); } @@ -335,7 +335,7 @@ JSTaggedValue BuiltinsLocale::GetScript(EcmaRuntimeCallInfo *argv) // 6. Return the substring of locale corresponding to the unicode_script_subtag production of the // unicode_language_id. JSHandle result(thread, JSTaggedValue::Undefined()); - CString script = locale->GetIcuLocale()->getScript(); + CString script = locale->GetIcuLocale(thread)->getScript(); if (script.empty()) { return result.GetTaggedValue(); } @@ -364,7 +364,7 @@ JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv) // return undefined. // 6. Return the substring of locale corresponding to the unicode_region_subtag production of the // unicode_language_id. - CString region = locale->GetIcuLocale()->getCountry(); + CString region = locale->GetIcuLocale(thread)->getCountry(); if (region.empty()) { return globalConst->GetUndefined(); } diff --git a/ecmascript/builtins/builtins_map.cpp b/ecmascript/builtins/builtins_map.cpp index 176c5b8020..fb99e19b74 100644 --- a/ecmascript/builtins/builtins_map.cpp +++ b/ecmascript/builtins/builtins_map.cpp @@ -148,7 +148,7 @@ JSTaggedValue BuiltinsMap::Get(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } JSMap *jsMap = JSMap::Cast(self.GetTaggedValue().GetTaggedObject()); - if (jsMap->GetSize() == 0) { + if (jsMap->GetSize(thread) == 0) { return JSTaggedValue::Undefined(); } JSHandle key = GetCallArg(argv, 0); @@ -177,17 +177,17 @@ JSTaggedValue BuiltinsMap::ForEach(EcmaRuntimeCallInfo *argv) // 5.If thisArg was supplied, let T be thisArg; else let T be undefined. JSHandle thisArg = GetCallArg(argv, 1); - JSMutableHandle hashMap(thread, map->GetLinkedMap()); + JSMutableHandle hashMap(thread, map->GetLinkedMap(thread)); const uint32_t argsLength = 3; int index = 0; int totalElements = hashMap->NumberOfElements() + hashMap->NumberOfDeletedElements(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // 7.Repeat for each e that is an element of entries, in original insertion order while (index < totalElements) { - JSHandle key(thread, hashMap->GetKey(index++)); + JSHandle key(thread, hashMap->GetKey(thread, index++)); // a. If e is not empty, then if (!key->IsHole()) { - JSHandle value(thread, hashMap->GetValue(index - 1)); + JSHandle value(thread, hashMap->GetValue(thread, index - 1)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo( thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -197,11 +197,11 @@ JSTaggedValue BuiltinsMap::ForEach(EcmaRuntimeCallInfo *argv) // ii. ReturnIfAbrupt(funcResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // Maybe add or delete - JSTaggedValue nextTable = hashMap->GetNextTable(); + JSTaggedValue nextTable = hashMap->GetNextTable(thread); while (!nextTable.IsHole()) { - index -= hashMap->GetDeletedElementsAt(index); + index -= hashMap->GetDeletedElementsAt(thread, index); hashMap.Update(nextTable); - nextTable = hashMap->GetNextTable(); + nextTable = hashMap->GetNextTable(thread); } totalElements = hashMap->NumberOfElements() + hashMap->NumberOfDeletedElements(); } @@ -228,7 +228,7 @@ JSTaggedValue BuiltinsMap::GetSize(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } JSMap *jsMap = JSMap::Cast(self.GetTaggedValue().GetTaggedObject()); - uint32_t count = jsMap->GetSize(); + uint32_t count = jsMap->GetSize(thread); return JSTaggedValue(count); } diff --git a/ecmascript/builtins/builtins_number.cpp b/ecmascript/builtins/builtins_number.cpp index 767f0e66d6..99f9b6845d 100644 --- a/ecmascript/builtins/builtins_number.cpp +++ b/ecmascript/builtins/builtins_number.cpp @@ -165,7 +165,7 @@ JSTaggedValue BuiltinsNumber::ParseFloat(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(inputString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CVector buf; - Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); + Span str = EcmaStringAccessor(numberString).ToUtf8Span(thread, buf); // 4. If neither trimmedString nor any prefix of trimmedString satisfies the syntax of a StrDecimalLiteral // (see 7.1.3.1), return NaN. if (NumberHelper::IsEmptyString(str.begin(), str.end())) { @@ -196,7 +196,7 @@ JSTaggedValue BuiltinsNumber::ParseInt(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - return NumberHelper::StringToNumber(*numberString, radix); + return NumberHelper::StringToNumber(thread, *numberString, radix); } // prototype @@ -438,7 +438,7 @@ JSTaggedValue BuiltinsNumber::ToString(EcmaRuntimeCallInfo *argv) if (radix == base::DECIMAL) { JSHandle cacheTable(thread->GetGlobalEnv()->GetNumberToStringResultCache()); int entry = cacheTable->GetNumberHash(value); - JSTaggedValue cacheResult = cacheTable->FindCachedResult(entry, value); + JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, entry, value); if (cacheResult != JSTaggedValue::Undefined()) { return cacheResult; } @@ -491,7 +491,7 @@ JSTaggedNumber BuiltinsNumber::ThisNumberValue(JSThread *thread, EcmaRuntimeCall return JSTaggedNumber(value.GetTaggedValue()); } if (value->IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(thread); if (primitive.IsNumber()) { return JSTaggedNumber(primitive); } @@ -508,12 +508,12 @@ JSTaggedValue NumberToStringResultCache::CreateCacheTable(const JSThread *thread return JSTaggedValue(table); } -JSTaggedValue NumberToStringResultCache::FindCachedResult(int entry, JSTaggedValue &target) +JSTaggedValue NumberToStringResultCache::FindCachedResult(const JSThread *thread, int entry, JSTaggedValue &target) { uint32_t index = static_cast(entry * ENTRY_SIZE); - JSTaggedValue entryNumber = Get(index + NUMBER_INDEX); + JSTaggedValue entryNumber = Get(thread, index + NUMBER_INDEX); if (entryNumber == target) { - return Get(index + RESULT_INDEX); + return Get(thread, index + RESULT_INDEX); } return JSTaggedValue::Undefined(); } diff --git a/ecmascript/builtins/builtins_number.h b/ecmascript/builtins/builtins_number.h index 55f5599182..63d4cf3bd2 100644 --- a/ecmascript/builtins/builtins_number.h +++ b/ecmascript/builtins/builtins_number.h @@ -175,7 +175,7 @@ public: return reinterpret_cast(object); } static JSTaggedValue CreateCacheTable(const JSThread *thread); - JSTaggedValue FindCachedResult(int entry, JSTaggedValue &target); + JSTaggedValue FindCachedResult(const JSThread *thread, int entry, JSTaggedValue &target); void SetCachedResult(const JSThread *thread, int entry, JSTaggedValue &number, JSHandle &result); int GetNumberHash(JSTaggedValue &number) { diff --git a/ecmascript/builtins/builtins_number_format.cpp b/ecmascript/builtins/builtins_number_format.cpp index a4a003da28..348b6afa48 100644 --- a/ecmascript/builtins/builtins_number_format.cpp +++ b/ecmascript/builtins/builtins_number_format.cpp @@ -64,7 +64,8 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (isInstanceOf) { PropertyDescriptor descriptor(thread, JSHandle::Cast(numberFormat), false, false, false); - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSHandle key(thread, + JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol(thread)); JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return thisValue.GetTaggedValue(); @@ -117,7 +118,7 @@ JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) } JSHandle typpedNf = JSHandle::Cast(nf); - JSHandle boundFunc(thread, typpedNf->GetBoundFormat()); + JSHandle boundFunc(thread, typpedNf->GetBoundFormat(thread)); // 4. If nf.[[BoundFormat]] is undefined, then // a. Let F be a new built-in function object as defined in Number Format Functions (12.1.4). // b. Set F.[[NumberFormat]] to nf. @@ -129,7 +130,7 @@ JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) intlBoundFunc->SetNumberFormat(thread, typpedNf); typpedNf->SetBoundFormat(thread, intlBoundFunc); } - return typpedNf->GetBoundFormat(); + return typpedNf->GetBoundFormat(thread); } // 13.4.4 Intl.NumberFormat.prototype.formatToParts ( date ) @@ -195,7 +196,7 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatInternalFormatNumber(EcmaRuntime JSHandle intlBoundFunc = JSHandle::Cast(GetConstructor(argv)); // 1. Let nf be F.[[NumberFormat]]. - JSHandle nf(thread, intlBoundFunc->GetNumberFormat()); + JSHandle nf(thread, intlBoundFunc->GetNumberFormat(thread)); // 2. Assert: Type(nf) is Object and nf has an [[InitializedNumberFormat]] internal slot. ASSERT(nf->IsJSObject() && nf->IsJSNumberFormat()); // 3. If value is not provided, let value be undefined. diff --git a/ecmascript/builtins/builtins_object.cpp b/ecmascript/builtins/builtins_object.cpp index 296a5b0a18..3214375a47 100644 --- a/ecmascript/builtins/builtins_object.cpp +++ b/ecmascript/builtins/builtins_object.cpp @@ -64,7 +64,7 @@ JSTaggedValue BuiltinsObject::AssignTaggedValue(JSThread *thread, const JSHandle uint32_t keysLen = keys->GetLength(); for (uint32_t j = 0; j < keysLen; j++) { PropertyDescriptor desc(thread); - key.Update(keys->Get(j)); + key.Update(keys->Get(thread, j)); bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(from), key, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -129,7 +129,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) uint32_t keysLen = keys->GetLength(); for (uint32_t j = 0; j < keysLen; j++) { PropertyDescriptor desc(thread); - key.Update(keys->Get(j)); + key.Update(keys->Get(thread, j)); bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(from), key, desc); // ReturnIfAbrupt(desc) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -199,7 +199,7 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH std::vector desArr; for (uint32_t i = 0; i < length; i++) { PropertyDescriptor propDesc(thread); - JSHandle handleKey(thread, handleKeys->Get(i)); + JSHandle handleKey(thread, handleKeys->Get(thread, i)); bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(props), handleKey, propDesc); // ReturnIfAbrupt(propDesc) @@ -423,7 +423,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDescriptors(EcmaRuntimeCallInfo *arg uint32_t length = ownKeys->GetLength(); JSMutableHandle handleKey(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; ++i) { - handleKey.Update(ownKeys->Get(i)); + handleKey.Update(ownKeys->Get(thread, i)); PropertyDescriptor desc(thread); JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(handle), handleKey, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -466,7 +466,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl switch (type) { case KeyType::STRING_TYPE: { for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = handleKeys->Get(i); + JSTaggedValue key = handleKeys->Get(thread, i); if (key.IsString()) { nameList->Set(thread, copyLength, key); copyLength++; @@ -476,7 +476,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl } case KeyType::SYMBOL_TYPE: { for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = handleKeys->Get(i); + JSTaggedValue key = handleKeys->Get(thread, i); if (key.IsSymbol()) { nameList->Set(thread, copyLength, key); copyLength++; @@ -549,7 +549,7 @@ JSTaggedValue BuiltinsObject::Is(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Object, Is); // 1.Return SameValue(value1, value2). - bool result = JSTaggedValue::SameValue(GetCallArg(argv, 0), GetCallArg(argv, 1)); + bool result = JSTaggedValue::SameValue(argv->GetThread(), GetCallArg(argv, 0), GetCallArg(argv, 1)); return GetTaggedBoolean(result); } @@ -833,7 +833,7 @@ JSTaggedValue BuiltinsObject::IsPrototypeOf(EcmaRuntimeCallInfo *argv) msgValueHandle.Update(JSTaggedValue::GetPrototype(thread, msgValueHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::SameValue(object.GetTaggedValue(), msgValueHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, object.GetTaggedValue(), msgValueHandle.GetTaggedValue())) { return GetTaggedBoolean(true); } } @@ -910,12 +910,12 @@ JSTaggedValue BuiltinsObject::GetBuiltinObjectToString(JSThread *thread, const J } else if (object->IsJSPrimitiveRef()) { // 7. Else, if O is an exotic String object, return "[object String]". JSPrimitiveRef *primitiveRef = JSPrimitiveRef::Cast(*object); - if (primitiveRef->IsString()) { + if (primitiveRef->IsString(thread)) { return thread->GlobalConstants()->GetStringToString(); - } else if (primitiveRef->IsBoolean()) { + } else if (primitiveRef->IsBoolean(thread)) { // 11. Else, if O has a [[BooleanData]] internal slot, return "[object Boolean]". return thread->GlobalConstants()->GetBooleanToString(); - } else if (primitiveRef->IsNumber()) { + } else if (primitiveRef->IsNumber(thread)) { // 12. Else, if O has a [[NumberData]] internal slot, return "[object Number]". return thread->GlobalConstants()->GetNumberToString(); } diff --git a/ecmascript/builtins/builtins_promise.cpp b/ecmascript/builtins/builtins_promise.cpp index ad54f271b4..58021d9856 100644 --- a/ecmascript/builtins/builtins_promise.cpp +++ b/ecmascript/builtins/builtins_promise.cpp @@ -61,8 +61,8 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor(EcmaRuntimeCallInfo *argv) // 8. Let resolvingFunctions be CreateResolvingFunctions(promise). JSHandle resolvingFunction = JSPromise::CreateResolvingFunctions(thread, instancePromise); // 9. Let completion be Call(executor, undefined, «resolvingFunctions.[[Resolve]], resolvingFunctions.[[reject]]) - auto resolveFunc = resolvingFunction->GetResolveFunction(); - auto rejectFunc = resolvingFunction->GetRejectFunction(); + auto resolveFunc = resolvingFunction->GetResolveFunction(thread); + auto rejectFunc = resolvingFunction->GetRejectFunction(thread); JSHandle undefined = globalConst->GetHandledUndefined(); const uint32_t argsLength = 2; // 2: «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]» EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, executor, undefined, undefined, argsLength); @@ -77,7 +77,7 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor(EcmaRuntimeCallInfo *argv) if (thread->HasPendingException()) { completionValue = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - JSHandle reject(thread, resolvingFunction->GetRejectFunction()); + JSHandle reject(thread, resolvingFunction->GetRejectFunction(thread)); EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -147,14 +147,14 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) if (closeVal.GetTaggedValue().IsRecord()) { result = JSHandle::Cast(closeVal); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, capa); - return result->GetValue(); + return result->GetValue(thread); } } RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, capa); - return result->GetValue(); + return result->GetValue(thread); } // 13. Return Completion(result). - return result->GetValue(); + return result->GetValue(thread); } // 25.4.4.3 Promise.race ( iterable ) @@ -216,13 +216,13 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) if (value.GetTaggedValue().IsCompletionRecord()) { result = JSHandle(value); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); - return result->GetValue(); + return result->GetValue(thread); } } RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); - return result->GetValue(); + return result->GetValue(thread); } - return result->GetValue(); + return result->GetValue(thread); } // 25.4.4.5 Promise.resolve ( x ) @@ -267,7 +267,7 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) // 5. Let rejectResult be Call(promiseCapability.[[Reject]], undefined, «r»). // 6. ReturnIfAbrupt(rejectResult). JSHandle reason = GetCallArg(argv, 0); - JSHandle reject(thread, promiseCapability->GetReject()); + JSHandle reject(thread, promiseCapability->GetReject(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -276,7 +276,7 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Return promiseCapability.[[Promise]]. - JSHandle promise(thread, promiseCapability->GetPromise()); + JSHandle promise(thread, promiseCapability->GetPromise(thread)); return promise.GetTaggedValue(); } @@ -349,7 +349,7 @@ JSTaggedValue BuiltinsPromise::Then(EcmaRuntimeCallInfo *argv) description = "promise.finally"; } ecmaVm->GetAsyncStackTrace()->InsertAsyncTaskStacks( - JSHandle(thread, resultCapability->GetPromise()), description); + JSHandle(thread, resultCapability->GetPromise(thread)), description); } // 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability). @@ -385,25 +385,25 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand PromiseState state = promise->GetPromiseState(); if (state == PromiseState::PENDING) { - JSHandle fulfillReactions(thread, promise->GetPromiseFulfillReactions()); + JSHandle fulfillReactions(thread, promise->GetPromiseFulfillReactions(thread)); TaggedQueue *newQueue = TaggedQueue::Push(thread, fulfillReactions, JSHandle::Cast(fulfillReaction)); promise->SetPromiseFulfillReactions(thread, JSTaggedValue(newQueue)); - JSHandle rejectReactions(thread, promise->GetPromiseRejectReactions()); + JSHandle rejectReactions(thread, promise->GetPromiseRejectReactions(thread)); newQueue = TaggedQueue::Push(thread, rejectReactions, JSHandle::Cast(rejectReaction)); promise->SetPromiseRejectReactions(thread, JSTaggedValue(newQueue)); } else if (state == PromiseState::FULFILLED) { JSHandle argv = factory->NewTaggedArray(2); // 2: 2 means two args stored in array argv->Set(thread, 0, fulfillReaction.GetTaggedValue()); - argv->Set(thread, 1, promise->GetPromiseResult()); + argv->Set(thread, 1, promise->GetPromiseResult(thread)); JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); } else if (state == PromiseState::REJECTED) { JSHandle argv = factory->NewTaggedArray(2); // 2: 2 means two args stored in array argv->Set(thread, 0, rejectReaction.GetTaggedValue()); - argv->Set(thread, 1, promise->GetPromiseResult()); + argv->Set(thread, 1, promise->GetPromiseResult(thread)); // When a handler is added to a rejected promise for the first time, it is called with its operation // argument set to "handle". if (!promise->GetPromiseIsHandled()) { @@ -414,7 +414,7 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); } promise->SetPromiseIsHandled(true); - return capability->GetPromise(); + return capability->GetPromise(thread); } JSTaggedValue BuiltinsPromise::PerformPromiseAll(JSThread *thread, @@ -439,7 +439,7 @@ JSTaggedValue BuiltinsPromise::PerformPromiseAll(JSThread *thread, // 5. Let index be 0. uint32_t index = 0; // 6. Repeat - JSHandle itor(thread, itRecord->GetIterator()); + JSHandle itor(thread, itRecord->GetIterator(thread)); JSMutableHandle next(thread, globalConst->GetUndefined()); while (true) { [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -458,14 +458,14 @@ JSTaggedValue BuiltinsPromise::PerformPromiseAll(JSThread *thread, // i. Set iteratorRecord.[[done]] to true. itRecord->SetDone(true); // ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // iii. If remainingElementsCount.[[value]] is 0, - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).IsZero()) { // 1. Let valuesArray be CreateArrayFromList(values). JSHandle jsArrayValues = - JSArray::CreateArrayFromList(thread, JSHandle(thread, values->GetValue())); + JSArray::CreateArrayFromList(thread, JSHandle(thread, values->GetValue(thread))); // 2. Let resolveResult be Call(resultCapability.[[Resolve]], undefined, «valuesArray»). - JSHandle resCapaFunc(thread, capa->GetResolve()); + JSHandle resCapaFunc(thread, capa->GetResolve(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resCapaFunc, undefined, undefined, 1); RETURN_COMPLETION_VALUE_IF_ABRUPT(thread, next); @@ -477,7 +477,7 @@ JSTaggedValue BuiltinsPromise::PerformPromiseAll(JSThread *thread, } // iv. Return resultCapability.[[Promise]]. JSHandle resRecord = factory->NewCompletionRecord( - CompletionRecordType::NORMAL, JSHandle(thread, capa->GetPromise())); + CompletionRecordType::NORMAL, JSHandle(thread, capa->GetPromise(thread))); return resRecord.GetTaggedValue(); } // e. Let nextValue be IteratorValue(next). @@ -492,7 +492,7 @@ JSTaggedValue BuiltinsPromise::PerformPromiseAll(JSThread *thread, RETURN_COMPLETION_VALUE_IF_ABRUPT(thread, nextVal); // h. Append undefined to values. JSHandle valuesArray = - JSHandle::Cast(JSHandle(thread, values->GetValue())); + JSHandle::Cast(JSHandle(thread, values->GetValue(thread))); valuesArray = TaggedArray::SetCapacity(thread, valuesArray, index + 1); valuesArray->Set(thread, index, JSTaggedValue::Undefined()); values->SetValue(thread, valuesArray); @@ -521,14 +521,14 @@ JSTaggedValue BuiltinsPromise::PerformPromiseAll(JSThread *thread, // p. Set the [[RemainingElements]] internal slot of resolveElement to remainingElementsCount. resoleveElement->SetRemainingElements(thread, remainCnt); // q. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] + 1. - remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue(thread))); // r. Let result be Invoke(nextPromise, "then", «‍resolveElement, resultCapability.[[Reject]]»). JSHandle thenKey = globalConst->GetHandledPromiseThenString(); EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: «‍resolveElement, resultCapability.[[Reject]]» RETURN_COMPLETION_VALUE_IF_ABRUPT(thread, nextPromise); - runtimeInfo->SetCallArg(resoleveElement.GetTaggedValue(), capa->GetReject()); + runtimeInfo->SetCallArg(resoleveElement.GetTaggedValue(), capa->GetReject(thread)); JSTaggedValue taggedResult = JSFunction::Invoke(runtimeInfo, thenKey); JSHandle result(thread, taggedResult); // s. ReturnIfAbrupt(result). @@ -561,7 +561,7 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, auto ecmaVm = thread->GetEcmaVM(); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle iterator(thread, iteratorRecord->GetIterator()); + JSHandle iterator(thread, iteratorRecord->GetIterator(thread)); JSMutableHandle next(thread, globalConst->GetUndefined()); JSHandle undefined(globalConst->GetHandledUndefined()); while (true) { @@ -573,7 +573,7 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, RETURN_COMPLETION_IF_ABRUPT(thread, next); if (next->IsFalse()) { iteratorRecord->SetDone(true); - JSHandle promise(thread, capability->GetPromise()); + JSHandle promise(thread, capability->GetPromise(thread)); JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecordType::NORMAL, promise); return completionRecord; @@ -601,7 +601,7 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: two args RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); - runtimeInfo->SetCallArg(capability->GetResolve(), capability->GetReject()); + runtimeInfo->SetCallArg(capability->GetResolve(thread), capability->GetReject(thread)); result = JSFunction::Invoke(runtimeInfo, thenStr); JSHandle handleResult(thread, result); if (thread->HasPendingException()) { @@ -672,14 +672,14 @@ JSTaggedValue BuiltinsPromise::Any(EcmaRuntimeCallInfo *argv) if (closeVal.GetTaggedValue().IsCompletionRecord()) { result = JSHandle(closeVal); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); - return result->GetValue(); + return result->GetValue(thread); } } RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); - return result->GetValue(); + return result->GetValue(thread); } // 9. Return ? result. - return result->GetValue(); + return result->GetValue(thread); } JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, @@ -702,7 +702,7 @@ JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, // 3. Let index be 0. uint32_t index = 0; // 4. Repeat, - JSHandle iter(thread, iteratorRecord->GetIterator()); + JSHandle iter(thread, iteratorRecord->GetIterator(thread)); JSMutableHandle next(thread, globalConst->GetUndefined()); JSHandle undefined(globalConst->GetHandledUndefined()); while (true) { @@ -720,16 +720,16 @@ JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, // i. Set iteratorRecord.[[Done]] to true. iteratorRecord->SetDone(true); // ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // iii. If remainingElementsCount.[[Value]] is 0, then - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).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::Cast(JSHandle(thread, errors->GetValue(thread))); JSHandle errorsValue(JSArray::CreateArrayFromList(thread, errorsArray)); PropertyDescriptor msgDesc(thread, errorsValue, true, false, true); JSHandle errorTagged = JSHandle::Cast(error); @@ -742,7 +742,7 @@ JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, return errorResult; } // iv. Return resultCapability.[[Promise]]. - JSHandle resultCapabilityHandle(thread, resultCapability->GetPromise()); + JSHandle resultCapabilityHandle(thread, resultCapability->GetPromise(thread)); JSHandle resRecord = factory->NewCompletionRecord( CompletionRecordType::NORMAL, resultCapabilityHandle); return resRecord; @@ -757,7 +757,7 @@ JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, // g. ReturnIfAbrupt(nextValue). RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); // h. Append undefined to errors. - JSHandle errorsHandle(thread, errors->GetValue()); + JSHandle errorsHandle(thread, errors->GetValue(thread)); JSHandle errorsArray = JSHandle::Cast(errorsHandle); errorsArray = TaggedArray::SetCapacity(thread, errorsArray, index + 1); errorsArray->Set(thread, index, JSTaggedValue::Undefined()); @@ -792,10 +792,10 @@ JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, // q. Set onRejected.[[RemainingElements]] to remainingElementsCount. onRejected->SetRemainingElements(thread, remainCnt); // r. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1. - remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue(thread))); // s. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], onRejected »). JSHandle thenKey = globalConst->GetHandledPromiseThenString(); - JSHandle resCapaFunc(thread, resultCapability->GetResolve()); + JSHandle resCapaFunc(thread, resultCapability->GetResolve(thread)); EcmaRuntimeCallInfo *invokeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: two args RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); @@ -856,15 +856,15 @@ JSTaggedValue BuiltinsPromise::AllSettled(EcmaRuntimeCallInfo *argv) if (closeVal.GetTaggedValue().IsCompletionRecord()) { result = JSHandle(closeVal); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); - return result->GetValue(); + return result->GetValue(thread); } } // b. IfAbruptRejectPromise(result, promiseCapability). RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); - return result->GetValue(); + return result->GetValue(thread); } // 7.Return Completion(result). - return result->GetValue(); + return result->GetValue(thread); } JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *thread, @@ -887,7 +887,7 @@ JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *t // 3. Let index be 0. uint32_t index = 0; // 4. Repeat, - JSHandle iter(thread, iterRecord->GetIterator()); + JSHandle iter(thread, iterRecord->GetIterator(thread)); JSMutableHandle next(thread, globalConst->GetUndefined()); JSHandle undefined(globalConst->GetHandledUndefined()); while (true) { @@ -905,14 +905,14 @@ JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *t // i. Set iteratorRecord.[[Done]] to true. iterRecord->SetDone(true); // ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // iii. If remainingElementsCount.[[Value]] is 0, then - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).IsZero()) { // 1. Let valuesArray be ! CreateArrayFromList(values). - JSHandle taggedValues(thread, values->GetValue()); + JSHandle taggedValues(thread, values->GetValue(thread)); JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, taggedValues); // 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »). - JSHandle resCapaFunc(thread, resultCapa->GetResolve()); + JSHandle resCapaFunc(thread, resultCapa->GetResolve(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resCapaFunc, undefined, undefined, 1); RETURN_COMPLETION_IF_ABRUPT(thread, next); @@ -926,7 +926,7 @@ JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *t } } // iv. Return resultCapability.[[Promise]]. - JSHandle resultCapabilityHandle(thread, resultCapa->GetPromise()); + JSHandle resultCapabilityHandle(thread, resultCapa->GetPromise(thread)); JSHandle resRecord = factory->NewCompletionRecord( CompletionRecordType::NORMAL, resultCapabilityHandle); return resRecord; @@ -941,7 +941,7 @@ JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *t // g. ReturnIfAbrupt(nextValue). RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); // h. Append undefined to values. - JSHandle valuesHandle(thread, values->GetValue()); + JSHandle valuesHandle(thread, values->GetValue(thread)); JSHandle valuesArray = JSHandle::Cast(valuesHandle); valuesArray = TaggedArray::SetCapacity(thread, valuesArray, index + 1); valuesArray->Set(thread, index, JSTaggedValue::Undefined()); @@ -997,7 +997,7 @@ JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *t // z. Set onRejected.[[RemainingElements]] to remainingElementsCount. onRejected->SetRemainingElements(thread, remainCnt); // aa. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1. - remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue(thread))); // ab. Perform ? Invoke(nextPromise, "then", « onFulfilled, onRejected »). JSHandle thenKey = globalConst->GetHandledPromiseThenString(); EcmaRuntimeCallInfo *invokeInfo = diff --git a/ecmascript/builtins/builtins_promise_handler.cpp b/ecmascript/builtins/builtins_promise_handler.cpp index 8a49c39e67..4e8341e24f 100644 --- a/ecmascript/builtins/builtins_promise_handler.cpp +++ b/ecmascript/builtins/builtins_promise_handler.cpp @@ -32,18 +32,18 @@ JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. JSHandle resolve = JSHandle::Cast(GetConstructor(argv)); - ASSERT_PRINT(resolve->GetPromise().IsECMAObject(), "Resolve: promise must be js object"); + ASSERT_PRINT(resolve->GetPromise(thread).IsECMAObject(), "Resolve: promise must be js object"); // 2. Let promise be the value of F's [[Promise]] internal slot. // 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot. // 4. If alreadyResolved.[[value]] is true, return undefined. // 5. Set alreadyResolved.[[value]] to true. - JSHandle alreadyResolved(thread, resolve->GetAlreadyResolved()); - if (alreadyResolved->GetValue().IsTrue()) { + JSHandle alreadyResolved(thread, resolve->GetAlreadyResolved(thread)); + if (alreadyResolved->GetValue(thread).IsTrue()) { return JSTaggedValue::Undefined(); } alreadyResolved->SetValue(thread, JSTaggedValue::True()); - JSHandle resolvePromise(thread, resolve->GetPromise()); + JSHandle resolvePromise(thread, resolve->GetPromise(thread)); JSHandle resolution = BuiltinsBase::GetCallArg(argv, 0); return InnerResolve(thread, resolvePromise, resolution); } @@ -58,15 +58,15 @@ JSTaggedValue BuiltinsPromiseHandler::Reject(EcmaRuntimeCallInfo *argv) // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. JSHandle reject = JSHandle::Cast(GetConstructor(argv)); - ASSERT_PRINT(reject->GetPromise().IsECMAObject(), "Reject: promise must be js object"); + ASSERT_PRINT(reject->GetPromise(thread).IsECMAObject(), "Reject: promise must be js object"); // 2. Let promise be the value of F's [[Promise]] internal slot. // 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot. // 4. If alreadyResolved.[[value]] is true, return undefined. // 5. Set alreadyResolved.[[value]] to true. - JSHandle rejectPromise(thread, reject->GetPromise()); - JSHandle alreadyResolved(thread, reject->GetAlreadyResolved()); - if (alreadyResolved->GetValue().IsTrue()) { + JSHandle rejectPromise(thread, reject->GetPromise(thread)); + JSHandle alreadyResolved(thread, reject->GetAlreadyResolved(thread)); + if (alreadyResolved->GetValue(thread).IsTrue()) { return JSTaggedValue::Undefined(); } alreadyResolved->SetValue(thread, JSTaggedValue::True()); @@ -87,17 +87,17 @@ JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) // 1. Assert: F has a [[Capability]] internal slot whose value is a PromiseCapability Record. JSHandle executor = JSHandle::Cast(GetConstructor(argv)); - ASSERT_PRINT(executor->GetCapability().IsRecord(), + ASSERT_PRINT(executor->GetCapability(thread).IsRecord(), "Executor: F has a [[Capability]] internal slot whose value is a PromiseCapability Record."); // 2. Let promiseCapability be the value of F's [[Capability]] internal slot. // 3. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception. - JSHandle promiseCapability(thread, executor->GetCapability()); - if (!promiseCapability->GetResolve().IsUndefined()) { + JSHandle promiseCapability(thread, executor->GetCapability(thread)); + if (!promiseCapability->GetResolve(thread).IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Executor: resolve should be undefine!", JSTaggedValue::Undefined()); } // 4. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception. - if (!promiseCapability->GetReject().IsUndefined()) { + if (!promiseCapability->GetReject(thread).IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Executor: reject should be undefine!", JSTaggedValue::Undefined()); } // 5. Set promiseCapability.[[Resolve]] to resolve. @@ -122,35 +122,36 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo JSHandle::Cast(GetConstructor(argv)); // 1. Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot. JSHandle alreadyCalled = - JSHandle::Cast(JSHandle(thread, func->GetAlreadyCalled())); + JSHandle::Cast(JSHandle(thread, func->GetAlreadyCalled(thread))); // 2. If alreadyCalled.[[value]] is true, return undefined. - if (alreadyCalled->GetValue().IsTrue()) { + if (alreadyCalled->GetValue(thread).IsTrue()) { return JSTaggedValue::Undefined(); } // 3. Set alreadyCalled.[[value]] to true. alreadyCalled->SetValue(thread, JSTaggedValue::True()); // 4. Let index be the value of F's [[Index]] internal slot. - JSHandle index(thread, func->GetIndex()); + JSHandle index(thread, func->GetIndex(thread)); // 5. Let values be the value of F's [[Values]] internal slot. - JSHandle values = JSHandle::Cast(JSHandle(thread, func->GetValues())); + JSHandle values = + JSHandle::Cast(JSHandle(thread, func->GetValues(thread))); // 6. Let promiseCapability be the value of F's [[Capabilities]] internal slot. JSHandle capa = - JSHandle::Cast(JSHandle(thread, func->GetCapabilities())); + JSHandle::Cast(JSHandle(thread, func->GetCapabilities(thread))); // 7. Let remainingElementsCount be the value of F's [[RemainingElements]] internal slot. JSHandle remainCnt = - JSHandle::Cast(JSHandle(thread, func->GetRemainingElements())); + JSHandle::Cast(JSHandle(thread, func->GetRemainingElements(thread))); // 8. Set values[index] to x. JSHandle arrayValues = - JSHandle::Cast(JSHandle(thread, values->GetValue())); + JSHandle::Cast(JSHandle(thread, values->GetValue(thread))); arrayValues->Set(thread, JSTaggedValue::ToUint32(thread, index), GetCallArg(argv, 0).GetTaggedValue()); // 9. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // 10. If remainingElementsCount.[[value]] is 0, - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).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 capaResolve(thread, capa->GetResolve(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, capaResolve, undefined, undefined, 1); @@ -189,7 +190,7 @@ JSTaggedValue BuiltinsPromiseHandler::valueThunkFunction(EcmaRuntimeCallInfo *ar BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, valueThunkFunction); JSHandle valueThunk = JSHandle::Cast(GetConstructor(argv)); - return valueThunk->GetResult(); + return valueThunk->GetResult(argv->GetThread()); } JSTaggedValue BuiltinsPromiseHandler::throwerFunction(EcmaRuntimeCallInfo *argv) @@ -199,7 +200,7 @@ JSTaggedValue BuiltinsPromiseHandler::throwerFunction(EcmaRuntimeCallInfo *argv) JSHandle thrower = JSHandle::Cast(GetConstructor(argv)); JSTaggedValue undefined = thread->GlobalConstants()->GetUndefined(); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, thrower->GetResult(), undefined); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, thrower->GetResult(thread), undefined); } JSTaggedValue BuiltinsPromiseHandler::ThenFinally(EcmaRuntimeCallInfo *argv) @@ -214,7 +215,7 @@ JSTaggedValue BuiltinsPromiseHandler::ThenFinally(EcmaRuntimeCallInfo *argv) JSHandle value = BuiltinsBase::GetCallArg(argv, 0); // 2. Let onFinally be F.[[OnFinally]]. // 3. Assert: IsCallable(onFinally) is true. - JSHandle onFinally(thread, thenFinally->GetOnFinally()); + JSHandle onFinally(thread, thenFinally->GetOnFinally(thread)); ASSERT_PRINT(onFinally->IsCallable(), "onFinally is not callable"); // 4. Let result be ? Call(onFinally, undefined). JSHandle undefined = globalConst->GetHandledUndefined(); @@ -225,7 +226,7 @@ JSTaggedValue BuiltinsPromiseHandler::ThenFinally(EcmaRuntimeCallInfo *argv) JSHandle resultHandle(thread, result); // 5. Let C be F.[[Constructor]]. // 6. Assert: IsConstructor(C) is true. - JSHandle thenFinallyConstructor(thread, thenFinally->GetConstructor()); + JSHandle thenFinallyConstructor(thread, thenFinally->GetConstructor(thread)); ASSERT_PRINT(thenFinallyConstructor->IsConstructor(), "thenFinallyConstructor is not constructor"); // 7. Let promise be ? PromiseResolve(C, result). JSHandle promiseHandle = @@ -255,7 +256,7 @@ JSTaggedValue BuiltinsPromiseHandler::CatchFinally(EcmaRuntimeCallInfo *argv) JSHandle catchFinally(GetConstructor(argv)); // 2. Let onFinally be F.[[OnFinally]]. // 3. Assert: IsCallable(onFinally) is true. - JSHandle onFinally(thread, catchFinally->GetOnFinally()); + JSHandle onFinally(thread, catchFinally->GetOnFinally(thread)); ASSERT_PRINT(onFinally->IsCallable(), "thenOnFinally is not callable"); // 4. Let result be ? Call(onFinally, undefined). JSHandle undefined = globalConst->GetHandledUndefined(); @@ -266,7 +267,7 @@ JSTaggedValue BuiltinsPromiseHandler::CatchFinally(EcmaRuntimeCallInfo *argv) JSHandle resultHandle(thread, result); // 5. Let C be F.[[Constructor]]. // 6. Assert: IsConstructor(C) is true. - JSHandle catchFinallyConstructor(thread, catchFinally->GetConstructor()); + JSHandle catchFinallyConstructor(thread, catchFinally->GetConstructor(thread)); ASSERT_PRINT(catchFinallyConstructor->IsConstructor(), "catchFinallyConstructor is not constructor"); // 7. Let promise be ? PromiseResolve(C, result). JSHandle promiseHandle = @@ -302,7 +303,7 @@ JSHandle BuiltinsPromiseHandler::PromiseResolve(JSThread *thread, 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)) { + if (JSTaggedValue::SameValue(thread, ctorValue, constructor)) { return xValue; } } @@ -320,7 +321,7 @@ JSHandle BuiltinsPromiseHandler::PromiseResolve(JSThread *thread, 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 resolve(thread, promiseCapability->GetResolve(thread)); JSHandle undefined(globalConst->GetHandledUndefined()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); @@ -330,7 +331,7 @@ JSHandle BuiltinsPromiseHandler::PromiseResolve(JSThread *thread, JSHandle resolveResultHandle(thread, resolveResult); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, resolveResultHandle); // 8. Return promiseCapability.[[Promise]]. - JSHandle promise(thread, promiseCapability->GetPromise()); + JSHandle promise(thread, promiseCapability->GetPromise(thread)); return promise; } @@ -345,9 +346,9 @@ JSTaggedValue BuiltinsPromiseHandler::AllSettledResolveElementFunction(EcmaRunti JSHandle::Cast((GetConstructor(argv))); // 2. Let alreadyCalled be F.[[AlreadyCalled]]. JSHandle alreadyCalled = - JSHandle::Cast(JSHandle(thread, resolveElement->GetAlreadyCalled())); + JSHandle::Cast(JSHandle(thread, resolveElement->GetAlreadyCalled(thread))); // 3. If alreadyCalled.[[Value]] is true, return undefined. - if (alreadyCalled->GetValue().IsTrue()) { + if (alreadyCalled->GetValue(thread).IsTrue()) { return JSTaggedValue::Undefined(); } // 4. Set alreadyCalled.[[Value]] to true. @@ -356,13 +357,13 @@ JSTaggedValue BuiltinsPromiseHandler::AllSettledResolveElementFunction(EcmaRunti uint32_t index = resolveElement->GetIndex(); // 6. Let values be F.[[Values]]. JSHandle values = - JSHandle::Cast(JSHandle(thread, resolveElement->GetValues())); + JSHandle::Cast(JSHandle(thread, resolveElement->GetValues(thread))); // 7. Let promiseCapability be F.[[Capability]]. JSHandle capa = - JSHandle::Cast(JSHandle(thread, resolveElement->GetCapability())); + JSHandle::Cast(JSHandle(thread, resolveElement->GetCapability(thread))); // 8. Let remainingElementsCount be F.[[RemainingElements]]. JSHandle remainCnt = - JSHandle::Cast(JSHandle(thread, resolveElement->GetRemainingElements())); + JSHandle::Cast(JSHandle(thread, resolveElement->GetRemainingElements(thread))); // 9. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). JSHandle proto = env->GetObjectFunctionPrototype(); JSHandle obj = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(proto); @@ -378,16 +379,16 @@ JSTaggedValue BuiltinsPromiseHandler::AllSettledResolveElementFunction(EcmaRunti RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 12. Set values[index] to obj. JSHandle arrayValues = - JSHandle::Cast(JSHandle(thread, values->GetValue())); + JSHandle::Cast(JSHandle(thread, values->GetValue(thread))); arrayValues->Set(thread, index, obj.GetTaggedValue()); // 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // 14. If remainingElementsCount.[[Value]] is 0, then - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).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 capaResolve(thread, capa->GetResolve(thread)); JSHandle undefined(globalConst->GetHandledUndefined()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, capaResolve, undefined, undefined, 1); @@ -410,9 +411,9 @@ JSTaggedValue BuiltinsPromiseHandler::AllSettledRejectElementFunction(EcmaRuntim JSHandle::Cast((GetConstructor(argv))); // 2. Let alreadyCalled be F.[[AlreadyCalled]]. JSHandle alreadyCalled = - JSHandle::Cast(JSHandle(thread, rejectElement->GetAlreadyCalled())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetAlreadyCalled(thread))); // 3. If alreadyCalled.[[Value]] is true, return undefined. - if (alreadyCalled->GetValue().IsTrue()) { + if (alreadyCalled->GetValue(thread).IsTrue()) { return JSTaggedValue::Undefined(); } // 4. Set alreadyCalled.[[Value]] to true. @@ -421,13 +422,13 @@ JSTaggedValue BuiltinsPromiseHandler::AllSettledRejectElementFunction(EcmaRuntim uint32_t index = rejectElement->GetIndex(); // 6. Let values be F.[[Values]]. JSHandle values = - JSHandle::Cast(JSHandle(thread, rejectElement->GetValues())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetValues(thread))); // 7. Let promiseCapability be F.[[Capability]]. JSHandle capa = - JSHandle::Cast(JSHandle(thread, rejectElement->GetCapability())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetCapability(thread))); // 8. Let remainingElementsCount be F.[[RemainingElements]]. JSHandle remainCnt = - JSHandle::Cast(JSHandle(thread, rejectElement->GetRemainingElements())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetRemainingElements(thread))); // 9. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). JSHandle proto = env->GetObjectFunctionPrototype(); JSHandle obj = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(proto); @@ -443,16 +444,16 @@ JSTaggedValue BuiltinsPromiseHandler::AllSettledRejectElementFunction(EcmaRuntim RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 12. Set values[index] to obj. JSHandle arrayValues = - JSHandle::Cast(JSHandle(thread, values->GetValue())); + JSHandle::Cast(JSHandle(thread, values->GetValue(thread))); arrayValues->Set(thread, index, obj.GetTaggedValue()); // 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // 14. If remainingElementsCount.[[Value]] is 0, then - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).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 capaResolve(thread, capa->GetResolve(thread)); JSHandle undefined(globalConst->GetHandledUndefined()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, capaResolve, undefined, undefined, 1); @@ -474,7 +475,7 @@ JSTaggedValue BuiltinsPromiseHandler::AnyRejectElementFunction(EcmaRuntimeCallIn JSHandle rejectElement = JSHandle::Cast((GetConstructor(argv))); // 2. If F.[[AlreadyCalled]] is true, return undefined. - JSTaggedValue alreadyCalled = rejectElement->GetAlreadyCalled(); + JSTaggedValue alreadyCalled = rejectElement->GetAlreadyCalled(thread); if (alreadyCalled.IsTrue()) { return JSTaggedValue::Undefined(); } @@ -484,22 +485,22 @@ JSTaggedValue BuiltinsPromiseHandler::AnyRejectElementFunction(EcmaRuntimeCallIn uint32_t index = rejectElement->GetIndex(); // 5. Let errors be F.[[Errors]]. JSHandle errors = - JSHandle::Cast(JSHandle(thread, rejectElement->GetErrors())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetErrors(thread))); // 6. Let promiseCapability be F.[[Capability]]. JSHandle capa = - JSHandle::Cast(JSHandle(thread, rejectElement->GetCapability())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetCapability(thread))); // 7. Let remainingElementsCount be F.[[RemainingElements]]. JSHandle remainCnt = - JSHandle::Cast(JSHandle(thread, rejectElement->GetRemainingElements())); + JSHandle::Cast(JSHandle(thread, rejectElement->GetRemainingElements(thread))); // 8. Set errors[index] to x. JSHandle xValue = GetCallArg(argv, 0); JSHandle errorsArray = - JSHandle::Cast(JSHandle(thread, errors->GetValue())); + JSHandle::Cast(JSHandle(thread, errors->GetValue(thread))); errorsArray->Set(thread, index, xValue.GetTaggedValue()); // 9. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue(thread))); // 10. If remainingElementsCount.[[Value]] is 0, then - if (remainCnt->GetValue().IsZero()) { + if (remainCnt->GetValue(thread).IsZero()) { // a. Let error be a newly created AggregateError object. JSHandle error = factory->NewJSAggregateError(); // b. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, @@ -511,7 +512,7 @@ JSTaggedValue BuiltinsPromiseHandler::AnyRejectElementFunction(EcmaRuntimeCallIn JSTaggedValue::DefinePropertyOrThrow(thread, errorTagged, errorsKey, msgDesc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »). - JSHandle capaReject(thread, capa->GetReject()); + JSHandle capaReject(thread, capa->GetReject(thread)); JSHandle undefined(globalConst->GetHandledUndefined()); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, capaReject, undefined, undefined, 1); @@ -532,7 +533,7 @@ JSTaggedValue BuiltinsPromiseHandler::InnerResolve(JSThread *thread, const JSHan // 6. If SameValue(resolution, promise) is true, then // a. Let selfResolutionError be a newly created TypeError object. // b. Return RejectPromise(promise, selfResolutionError). - if (JSTaggedValue::SameValue(resolution.GetTaggedValue(), promise.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, resolution.GetTaggedValue(), promise.GetTaggedValue())) { JSHandle resolutionError = factory->GetJSError(ErrorType::TYPE_ERROR, "Resolve: The promise and resolution cannot be the same.", StackCheck::NO); JSPromise::RejectPromise(thread, promise, JSHandle::Cast(resolutionError)); diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index 058d3bd7f1..12cd0e0bf5 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -44,10 +44,10 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 2. Let promiseCapability be reaction.[[Capabilities]]. - JSHandle capability(thread, reaction->GetPromiseCapability()); + JSHandle capability(thread, reaction->GetPromiseCapability(thread)); // 3. Let handler be reaction.[[Handler]]. - JSHandle handler(thread, reaction->GetHandler()); - JSHandle call(thread, capability->GetResolve()); + JSHandle handler(thread, reaction->GetHandler(thread)); + JSHandle call(thread, capability->GetResolve(thread)); const uint32_t argsLength = 1; JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *runtimeInfo = @@ -60,7 +60,7 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) runtimeInfo->SetCallArg(argument.GetTaggedValue()); if (EcmaStringAccessor::StringsAreEqual(thread->GetEcmaVM(), JSHandle(handler), JSHandle(globalConst->GetHandledThrowerString()))) { - runtimeInfo->SetFunction(capability->GetReject()); + runtimeInfo->SetFunction(capability->GetReject(thread)); } } else { // 6. Else, let handlerResult be Call(handler, undefined, «argument»). @@ -76,7 +76,7 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) JSHandle throwValue = JSPromise::IfThrowGetThrowValue(thread); runtimeInfo->SetCallArg(throwValue.GetTaggedValue()); thread->ClearException(); - runtimeInfo->SetFunction(capability->GetReject()); + runtimeInfo->SetFunction(capability->GetReject(thread)); } else { runtimeInfo->SetCallArg(taggedValue); } @@ -104,7 +104,7 @@ JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, then, thenable, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(resolvingFunctions->GetResolveFunction(), resolvingFunctions->GetRejectFunction()); + info->SetCallArg(resolvingFunctions->GetResolveFunction(thread), resolvingFunctions->GetRejectFunction(thread)); JSTaggedValue result = JSFunction::Call(info); JSHandle thenResult(thread, result); // 3. If thenCallResult is an abrupt completion, @@ -113,7 +113,7 @@ JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo if (thread->HasPendingException()) { thenResult = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); + JSHandle reject(thread, resolvingFunctions->GetRejectFunction(thread)); EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -144,14 +144,14 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv) // Resolve request module's ohmurl CString entryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION; - CString fileName = ModulePathHelper::Utf8ConvertToString(dirPath.GetTaggedValue()); - CString requestPath = ModulePathHelper::Utf8ConvertToString(specifierString.GetTaggedValue()); + CString fileName = ModulePathHelper::Utf8ConvertToString(thread, dirPath.GetTaggedValue()); + CString requestPath = ModulePathHelper::Utf8ConvertToString(thread, specifierString.GetTaggedValue()); LOG_ECMA(DEBUG) << "Start importing dynamic module : " << requestPath; ModuleTraceScope moduleTraceScope(thread, "BuiltinsPromiseJob::DynamicImport:" + requestPath); std::shared_ptr curJsPandaFile; CString recordNameStr; if (!recordName->IsUndefined()) { - recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName.GetTaggedValue()); + recordNameStr = ModulePathHelper::Utf8ConvertToString(thread, recordName.GetTaggedValue()); curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile( thread, fileName, recordNameStr.c_str(), false, ExecuteTypes::STATIC); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject)); diff --git a/ecmascript/builtins/builtins_regexp-inl.h b/ecmascript/builtins/builtins_regexp-inl.h index bf0ede30b9..a0f045310f 100644 --- a/ecmascript/builtins/builtins_regexp-inl.h +++ b/ecmascript/builtins/builtins_regexp-inl.h @@ -26,7 +26,7 @@ JSTaggedValue RegExpGlobalResult::GetCapture(JSThread *thread) { JSHandle table = JSHandle(thread, RegExpExecResultCache::GetGlobalTable(thread)); JSHandle globalTable = JSHandle::Cast(table); - JSTaggedValue res = globalTable->Get(CAPTURE_START_INDEX + N - 1); + JSTaggedValue res = globalTable->Get(thread, CAPTURE_START_INDEX + N - 1); int captureNum = globalTable->GetTotalCaptureCounts().GetInt(); if (res.IsHole() && (N < captureNum)) { int startIndex = globalTable->GetStartOfCaptureIndex(N).GetInt(); @@ -36,7 +36,7 @@ JSTaggedValue RegExpGlobalResult::GetCapture(JSThread *thread) res = JSTaggedValue::Undefined(); } else { res = JSTaggedValue(EcmaStringAccessor::FastSubString(thread->GetEcmaVM(), - JSHandle(thread, EcmaString::Cast(globalTable->GetInputString())), + JSHandle(thread, EcmaString::Cast(globalTable->GetInputString(thread))), static_cast(startIndex), static_cast(len))); } globalTable->Set(thread, CAPTURE_START_INDEX + N - 1, res); diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index 9ad04cf5b2..4cd360b8ec 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -62,7 +62,7 @@ JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) // 4.b.ii ReturnIfAbrupt(patternConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.b.iii If SameValue(newTarget, patternConstructor) is true, return pattern. - if (JSTaggedValue::SameValue(newTarget.GetTaggedValue(), patternConstructor)) { + if (JSTaggedValue::SameValue(thread, newTarget.GetTaggedValue(), patternConstructor)) { return pattern.GetTaggedValue(); } } @@ -78,10 +78,10 @@ JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) if (isJsReg) { JSHandle patternReg(thread, JSRegExp::Cast(pattern->GetTaggedObject())); // 5.a Let P be the value of pattern’s [[OriginalSource]] internal slot. - patternTemp = JSHandle(thread, patternReg->GetOriginalSource()); + patternTemp = JSHandle(thread, patternReg->GetOriginalSource(thread)); if (flags->IsUndefined()) { // 5.b If flags is undefined, let F be the value of pattern’s [[OriginalFlags]] internal slot. - flagsTemp = JSHandle(thread, patternReg->GetOriginalFlags()); + flagsTemp = JSHandle(thread, patternReg->GetOriginalFlags(thread)); } else { // 5.c Else, let F be flags. flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); @@ -212,12 +212,12 @@ bool BuiltinsRegExp::IsFastRegExp(JSThread *thread, JSTaggedValue regexp, return false; } // lastIndex type is Int - JSTaggedValue lastIndex = JSObject::Cast(regexp)->GetPropertyInlinedProps(LAST_INDEX_OFFSET); + JSTaggedValue lastIndex = JSObject::Cast(regexp)->GetPropertyInlinedProps(thread, LAST_INDEX_OFFSET); if (!lastIndex.IsInt() || lastIndex.GetInt() < 0) { return false; } // RegExp.prototype hclass - JSTaggedValue proto = hclass->GetPrototype(); + JSTaggedValue proto = hclass->GetPrototype(thread); JSHClass *regexpHclass = proto.GetTaggedObject()->GetClass(); JSHandle originRegexpClassValue = env->GetRegExpPrototypeClass(); JSHClass *originRegexpHclass = JSHClass::Cast(originRegexpClassValue.GetTaggedValue().GetTaggedObject()); @@ -226,7 +226,7 @@ bool BuiltinsRegExp::IsFastRegExp(JSThread *thread, JSTaggedValue regexp, } JSObject* protoObj = JSObject::Cast(proto); // RegExp.prototype.exec - JSTaggedValue execVal = protoObj->GetPropertyInlinedProps(JSRegExp::EXEC_INLINE_PROPERTY_INDEX); + JSTaggedValue execVal = protoObj->GetPropertyInlinedProps(thread, JSRegExp::EXEC_INLINE_PROPERTY_INDEX); if (execVal != env->GetTaggedRegExpExecFunction()) { return false; } @@ -236,7 +236,7 @@ bool BuiltinsRegExp::IsFastRegExp(JSThread *thread, JSTaggedValue regexp, break; #define V(UpperCase, Camel) \ case RegExpSymbol::UpperCase: \ - symbolFunc = protoObj->GetPropertyInlinedProps( \ + symbolFunc = protoObj->GetPropertyInlinedProps(thread, \ JSRegExp::UpperCase##_INLINE_PROPERTY_INDEX); \ if (symbolFunc != env->GetTaggedRegExp##Camel##Function()) { \ return false; \ @@ -330,10 +330,10 @@ JSTaggedValue BuiltinsRegExp::ToString(EcmaRuntimeCallInfo *argv) if (IsFastRegExp(thread, thisObj.GetTaggedValue())) { JSHandle regexp(thread, JSRegExp::Cast(thisObj->GetTaggedObject())); // 3. Let pattern be ToString(Get(R, "source")). - getSource.Update(regexp->GetOriginalSource()); + getSource.Update(regexp->GetOriginalSource(thread)); sourceStrHandle = JSTaggedValue::ToString(thread, getSource); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint8_t flagsBits = static_cast(regexp->GetOriginalFlags().GetInt()); + uint8_t flagsBits = static_cast(regexp->GetOriginalFlags(thread).GetInt()); getFlags.Update(FlagsBitsToString(thread, flagsBits)); flagsStrHandle = JSTaggedValue::ToString(thread, getFlags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -374,7 +374,8 @@ JSTaggedValue BuiltinsRegExp::GetFlags(EcmaRuntimeCallInfo *argv) if (!IsFastRegExp(thread, thisObj.GetTaggedValue())) { return GetAllFlagsInternal(thread, thisObj); } - uint8_t flagsBits = static_cast(JSRegExp::Cast(thisObj->GetTaggedObject())->GetOriginalFlags().GetInt()); + uint8_t flagsBits = + static_cast(JSRegExp::Cast(thisObj->GetTaggedObject())->GetOriginalFlags(thread).GetInt()); return FlagsBitsToString(thread, flagsBits); } @@ -541,9 +542,9 @@ JSTaggedValue BuiltinsRegExp::GetSource(EcmaRuntimeCallInfo *argv) } // 5. Let src be the value of R’s [[OriginalSource]] internal slot. JSHandle regexpObj(thread, JSRegExp::Cast(thisObj->GetTaggedObject())); - JSHandle source(thread, regexpObj->GetOriginalSource()); + JSHandle source(thread, regexpObj->GetOriginalSource(thread)); // 6. Let flags be the value of R’s [[OriginalFlags]] internal slot. - uint8_t flagsBits = static_cast(regexpObj->GetOriginalFlags().GetInt()); + uint8_t flagsBits = static_cast(regexpObj->GetOriginalFlags(thread).GetInt()); JSHandle flags(thread, FlagsBitsToString(thread, flagsBits)); // 7. Return EscapeRegExpPattern(src, flags). return JSTaggedValue(EscapeRegExpPattern(thread, source, flags)); @@ -644,7 +645,7 @@ JSTaggedValue BuiltinsRegExp::RegExpMatch(JSThread *thread, const JSHandle array(JSArray::ArrayCreate(thread, JSTaggedNumber(0), ArrayMode::LITERAL)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - TaggedArray *srcElements = TaggedArray::Cast(array->GetElements().GetTaggedObject()); + TaggedArray *srcElements = TaggedArray::Cast(array->GetElements(thread).GetTaggedObject()); JSMutableHandle elements(thread, srcElements); // e. Let n be 0. uint32_t resultNum = 0; @@ -721,7 +722,7 @@ JSTaggedValue BuiltinsRegExp::RegExpMatch(JSThread *thread, const JSHandle jsRegExp = JSHandle::Cast(regexp); - JSHandle pattern(thread, jsRegExp->GetOriginalSource()); - JSHandle flags(thread, jsRegExp->GetOriginalFlags()); + JSHandle pattern(thread, jsRegExp->GetOriginalSource(thread)); + JSHandle flags(thread, jsRegExp->GetOriginalFlags(thread)); matcher.Update(BuiltinsRegExp::RegExpCreate(thread, pattern, flags)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); SetLastIndex(thread, matcher, - JSHandle::Cast(jsRegExp)->GetPropertyInlinedProps(LAST_INDEX_OFFSET), isFastPath); + JSHandle::Cast(jsRegExp)->GetPropertyInlinedProps(thread, LAST_INDEX_OFFSET), isFastPath); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); global = GetOriginalFlag(thread, matcher, RegExpParser::FLAG_GLOBAL); fullUnicode = GetOriginalFlag(thread, matcher, RegExpParser::FLAG_UTF16); @@ -833,7 +834,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle regexpHandle(regexp); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // get bytecode - JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(thread); void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); // get flags auto bytecodeBuffer = reinterpret_cast(dynBuf); @@ -846,8 +847,8 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandleGlobalConstants(); - JSHandle pattern(thread, regexpHandle->GetOriginalSource()); - JSHandle flagsBits(thread, regexpHandle->GetOriginalFlags()); + JSHandle pattern(thread, regexpHandle->GetOriginalSource(thread)); + JSHandle flagsBits(thread, regexpHandle->GetOriginalFlags(thread)); useCache = ShouldUseCache(thread, inputString); uint32_t lastIndexInput = lastIndex; JSHandle emptyString(thread, globalConst->GetEmptyString()); @@ -877,7 +878,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle regexp, uint32_t &lastIndex) { - JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(thread); void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); auto bytecodeBuffer = reinterpret_cast(dynBuf); uint32_t flags = *reinterpret_cast(bytecodeBuffer + RegExpParser::FLAGS_OFFSET); @@ -948,7 +949,7 @@ JSTaggedValue BuiltinsRegExp::MatchAndReplace(JSThread *thread, JSHandleGetEcmaVM(), inputString, nextPosition, startIndex - nextPosition); - resultString += EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION); + resultString += EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION); } nextPosition = endIndex; if (!(flags & RegExpParser::FLAG_GLOBAL)) { @@ -962,13 +963,13 @@ JSTaggedValue BuiltinsRegExp::MatchAndReplace(JSThread *thread, JSHandle(AdvanceStringIndex(tagInputString, endIndex, unicode)); + endIndex = static_cast(AdvanceStringIndex(thread, tagInputString, endIndex, unicode)); } lastIndex = endIndex; } auto substr = EcmaStringAccessor::FastSubString( thread->GetEcmaVM(), inputString, nextPosition, inputLength - nextPosition); - resultString += EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION); + resultString += EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION); return JSTaggedValue::Undefined(); } @@ -1107,7 +1108,7 @@ JSTaggedValue BuiltinsRegExp::ReplaceInternal(JSThread *thread, break; } // d. Else result is not null, i. Append result to the end of results. - TaggedArray *srcElements = TaggedArray::Cast(resultsList->GetElements().GetTaggedObject()); + TaggedArray *srcElements = TaggedArray::Cast(resultsList->GetElements(thread).GetTaggedObject()); JSMutableHandle elements(thread, srcElements); if (resultsIndex >= static_cast(elements->GetLength())) { elements.Update(JSObject::GrowElementsCapacity(thread, resultsList, elements->GetLength(), true)); @@ -1134,7 +1135,8 @@ JSTaggedValue BuiltinsRegExp::ReplaceInternal(JSThread *thread, uint32_t thisIndex = static_cast(GetLastIndex(thread, thisObj, isFastPath)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). - uint32_t nextIndex = static_cast(AdvanceStringIndex(inputStr, thisIndex, fullUnicode)); + uint32_t nextIndex = + static_cast(AdvanceStringIndex(thread, inputStr, thisIndex, fullUnicode)); nextIndexHandle.Update(JSTaggedValue(nextIndex)); // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). SetLastIndex(thread, thisObj, nextIndexHandle.GetTaggedValue(), isFastPath); @@ -1370,7 +1372,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSearch(JSThread *thread, RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If SameValue(previousLastIndex, 0) is false, then // Perform ? Set(rx, "lastIndex", 0, true). - if (!JSTaggedValue::SameValue(previousLastIndex.GetTaggedValue(), JSTaggedValue(0))) { + if (!JSTaggedValue::SameValue(thread, previousLastIndex.GetTaggedValue(), JSTaggedValue(0))) { JSHandle value(thread, JSTaggedValue(0)); JSObject::SetProperty(thread, regexp, lastIndexString, value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1383,7 +1385,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSearch(JSThread *thread, RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. If SameValue(currentLastIndex, previousLastIndex) is false, then // Perform ? Set(rx, "lastIndex", previousLastIndex, true). - if (!JSTaggedValue::SameValue(previousLastIndex.GetTaggedValue(), currentLastIndex.GetTaggedValue())) { + if (!JSTaggedValue::SameValue(thread, previousLastIndex.GetTaggedValue(), currentLastIndex.GetTaggedValue())) { JSObject::SetProperty(thread, regexp, lastIndexString, previousLastIndex, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -1548,7 +1550,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSplit(JSThread *thread, const JSHandleIsNull()) { - endIndex = static_cast(AdvanceStringIndex(jsString, endIndex, unicodeMatching)); + endIndex = static_cast(AdvanceStringIndex(thread, jsString, endIndex, unicodeMatching)); } else { // f. Else z is not null, // i. Let e be ToLength(Get(splitter, "lastIndex")). @@ -1561,14 +1563,15 @@ JSTaggedValue BuiltinsRegExp::RegExpSplit(JSThread *thread, const JSHandle(AdvanceStringIndex(jsString, endIndex, unicodeMatching)); + endIndex = static_cast(AdvanceStringIndex(thread, jsString, endIndex, unicodeMatching)); } else { // iv. Else e != p, // 1. Let T be a String value equal to the substring of S consisting of the elements at indices p // (inclusive) through q (exclusive). auto substr = EcmaStringAccessor::FastSubString(thread->GetEcmaVM(), JSHandle::Cast(jsString), startIndex, endIndex - startIndex); - std::string stdStrT = EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION); + std::string stdStrT = + EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION); // 2. Assert: The following call will never result in an abrupt completion. // 3. Perform CreateDataProperty(A, ToString(lengthA), T). JSHandle tValue(factory->NewFromStdString(stdStrT)); @@ -1620,7 +1623,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSplit(JSThread *thread, const JSHandleGetEcmaVM(), JSHandle::Cast(jsString), startIndex, size - startIndex); - std::string stdStrT = EcmaStringAccessor(substr).ToStdString(StringConvertedUsage::LOGICOPERATION); + std::string stdStrT = EcmaStringAccessor(substr).ToStdString(thread, StringConvertedUsage::LOGICOPERATION); // 26. Assert: The following call will never result in an abrupt completion. // 27. Perform CreateDataProperty(A, ToString(lengthA), t). JSHandle tValue(factory->NewFromStdString(stdStrT)); @@ -1703,7 +1706,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSplitFast(JSThread *thread, const JSHandle splitArray(JSArray::ArrayCreate(thread, JSTaggedNumber(1), ArrayMode::LITERAL)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - TaggedArray *srcElements = TaggedArray::Cast(splitArray->GetElements().GetTaggedObject()); + TaggedArray *srcElements = TaggedArray::Cast(splitArray->GetElements(thread).GetTaggedObject()); JSMutableHandle elements(thread, srcElements); JSMutableHandle matchValue(thread, JSTaggedValue::Undefined()); while (nextMatchFrom < size) { @@ -1713,7 +1716,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSplitFast(JSThread *thread, const JSHandle(AdvanceStringIndex(jsString, nextMatchFrom, isUnicode)); + nextMatchFrom = static_cast(AdvanceStringIndex(thread, jsString, nextMatchFrom, isUnicode)); continue; } // find match result @@ -1722,7 +1725,7 @@ JSTaggedValue BuiltinsRegExp::RegExpSplitFast(JSThread *thread, const JSHandle(matchResultInfo->GetEndOfCaptureIndex(0).GetInt()); if (matchEndIndex == lastMatchEnd && matchEndIndex == nextMatchFrom) { // advance index and continue if match result is empty. - nextMatchFrom = static_cast(AdvanceStringIndex(jsString, nextMatchFrom, isUnicode)); + nextMatchFrom = static_cast(AdvanceStringIndex(thread, jsString, nextMatchFrom, isUnicode)); } else { matchValue.Update(JSTaggedValue(EcmaStringAccessor::FastSubString(thread->GetEcmaVM(), string, lastMatchEnd, matchStartIndex - lastMatchEnd))); @@ -1807,7 +1810,7 @@ bool BuiltinsRegExp::RegExpExecInternal(JSThread *thread, const JSHandleGetTaggedObject())->GetOriginalSource(); + JSTaggedValue regexpSource = JSRegExp::Cast(regexp->GetTaggedObject())->GetOriginalSource(thread); uint32_t regexpLength = EcmaStringAccessor(regexpSource).GetLength(); if (UNLIKELY(regexpLength > MIN_REGEXP_PATTERN_LENGTH_EXECUTE_WITH_OFFHEAP_STRING && stringLength > 0)) { size_t utf8Len = LineEcmaString::DataSize(flatStrInfo.GetString()); @@ -1838,7 +1841,7 @@ bool BuiltinsRegExp::Matcher(JSThread *thread, const JSHandle reg { BUILTINS_API_TRACE(thread, RegExp, Matcher); // get bytecode - JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(thread); void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); auto bytecodeBuffer = reinterpret_cast(dynBuf); // execute @@ -1865,8 +1868,8 @@ bool BuiltinsRegExp::Matcher(JSThread *thread, const JSHandle reg return ret; } -int64_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &inputStr, int64_t index, - bool unicode) +int64_t BuiltinsRegExp::AdvanceStringIndex(const JSThread *thread, const JSHandle &inputStr, + int64_t index, bool unicode) { // 1. Assert: Type(S) is String. ASSERT(inputStr->IsString()); @@ -1884,13 +1887,13 @@ int64_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &inputS return index + 1; } // 7. Let first be the code unit value at index index in S. - uint16_t first = EcmaStringAccessor(inputStr->GetTaggedObject()).Get(index); + uint16_t first = EcmaStringAccessor(inputStr->GetTaggedObject()).Get(thread, index); // 8. If first < 0xD800 or first > 0xDFFF, return index+1. if (first < 0xD800 || first > 0xDFFF) { // NOLINT(readability-magic-numbers) return index + 1; } // 9. Let second be the code unit value at index index+1 in S. - uint16_t second = EcmaStringAccessor(inputStr->GetTaggedObject()).Get(index + 1); + uint16_t second = EcmaStringAccessor(inputStr->GetTaggedObject()).Get(thread, index + 1); // 10. If second < 0xDC00 or second > 0xDFFF, return index+1. if (second < 0xDC00 || second > 0xDFFF) { // NOLINT(readability-magic-numbers) return index + 1; @@ -1932,7 +1935,7 @@ JSTaggedValue BuiltinsRegExp::GetFlagsInternal(JSThread *thread, const JSHandle< JSHandle regexpObj(thread, JSRegExp::Cast(obj->GetTaggedObject())); // 5. If flags contains the code unit "[flag]", return true. // 6. Return false. - uint8_t flags = static_cast(regexpObj->GetOriginalFlags().GetInt()); + uint8_t flags = static_cast(regexpObj->GetOriginalFlags(thread).GetInt()); return GetTaggedBoolean(flags & mask); } @@ -2057,7 +2060,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle // Else, // a. Let groups be undefined. // b. Let hasGroups be false. - JSHandle groupName(thread, JSHandle::Cast(regexp)->GetGroupName()); + JSHandle groupName(thread, JSHandle::Cast(regexp)->GetGroupName(thread)); JSMutableHandle groups(thread, JSTaggedValue::Undefined()); bool hasGroups = false; if (!groupName->IsUndefined()) { @@ -2107,7 +2110,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle JSHandle groupObject = JSHandle::Cast(groups); TaggedArray *groupArray = TaggedArray::Cast(groupName->GetTaggedObject()); if (groupArray->GetLength() > captureIndex - 1) { - JSHandle skey(thread, groupArray->Get(captureIndex - 1)); + JSHandle skey(thread, groupArray->Get(thread, captureIndex - 1)); JSObject::CreateDataProperty(thread, groupObject, skey, iValue); groupNames.emplace_back(skey); } else { @@ -2374,7 +2377,7 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< * 7. If F contains any code unit other than "d", "g", "i", "m", "u", or "y" or if it contains the same code * unit more than once, throw a SyntaxError exception. **/ - CString checkStr = ConvertToString(*flagsStrHandle, StringConvertedUsage::LOGICOPERATION); + CString checkStr = ConvertToString(thread, *flagsStrHandle, StringConvertedUsage::LOGICOPERATION); flagsBits = static_cast(UpdateExpressionFlags(thread, checkStr)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -2383,11 +2386,12 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< RegExpParser parser = RegExpParser(thread, &chunk); RegExpParserCache *regExpParserCache = thread->GetEcmaVM()->GetRegExpParserCache(); CVector groupName; - auto getCache = regExpParserCache->GetCache(*patternStrHandle, flagsBits, groupName); + auto getCache = regExpParserCache->GetCache(thread, *patternStrHandle, flagsBits, groupName); if (getCache.first.IsHole()) { // String -> CString bool cesu8 = !(RegExpParser::FLAG_UTF16 & flagsBits); - CString patternStdStr = ConvertToString(*patternStrHandle, StringConvertedUsage::LOGICOPERATION, cesu8); + CString patternStdStr = ConvertToString(thread, *patternStrHandle, StringConvertedUsage::LOGICOPERATION, + cesu8); parser.Init(const_cast(reinterpret_cast(patternStdStr.c_str())), patternStdStr.size(), flagsBits); parser.Parse(); @@ -2420,7 +2424,8 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< auto bufferSize = parser.GetOriginBufferSize(); auto buffer = parser.GetOriginBuffer(); factory->NewJSRegExpByteCodeData(regexp, buffer, bufferSize); - regExpParserCache->SetCache(*patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(), bufferSize, groupName); + regExpParserCache->SetCache(thread, *patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(thread), + bufferSize, groupName); } else { regexp->SetByteCodeBuffer(thread, getCache.first); regexp->SetLength(static_cast(getCache.second)); @@ -2454,7 +2459,7 @@ EcmaString *BuiltinsRegExp::EscapeRegExpPattern(JSThread *thread, const JSHandle // String -> CString JSHandle srcStr(thread, static_cast(src->GetTaggedObject())); JSHandle flagsStr(thread, static_cast(flags->GetTaggedObject())); - CString srcStdStr = ConvertToString(*srcStr, StringConvertedUsage::LOGICOPERATION); + CString srcStdStr = ConvertToString(thread, *srcStr, StringConvertedUsage::LOGICOPERATION); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // "" -> (?:) if (srcStdStr.empty()) { @@ -2524,19 +2529,19 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, bool isIntermediateResult) { JSHandle regexpObj(regexp); - JSTaggedValue pattern = regexpObj->GetOriginalSource(); - JSTaggedValue flags = regexpObj->GetOriginalFlags(); + JSTaggedValue pattern = regexpObj->GetOriginalSource(thread); + JSTaggedValue flags = regexpObj->GetOriginalFlags(thread); JSTaggedValue inputValue = input.GetTaggedValue(); JSTaggedValue extendValue = extend.GetTaggedValue(); if (!pattern.IsString() || !flags.IsInt() || !input->IsString() || !lastIndexInput.IsInt()) { return JSTaggedValue::Undefined(); } - uint32_t hash = pattern.GetKeyHashCode() + static_cast(flags.GetInt()) + - input->GetKeyHashCode() + static_cast(lastIndexInput.GetInt()); + uint32_t hash = pattern.GetKeyHashCode(thread) + static_cast(flags.GetInt()) + + input->GetKeyHashCode(thread) + static_cast(lastIndexInput.GetInt()); uint32_t entry = hash & static_cast(GetCacheLength() - 1); - if (!Match(entry, pattern, flags, inputValue, lastIndexInput, extendValue, type)) { + if (!Match(thread, entry, pattern, flags, inputValue, lastIndexInput, extendValue, type)) { uint32_t entry2 = (entry + 1) & static_cast(GetCacheLength() - 1); - if (!Match(entry2, pattern, flags, inputValue, lastIndexInput, extendValue, type)) { + if (!Match(thread, entry2, pattern, flags, inputValue, lastIndexInput, extendValue, type)) { return JSTaggedValue::Undefined(); } entry = entry2; @@ -2545,32 +2550,32 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, static_cast(entry) * static_cast(ENTRY_SIZE)) <= static_cast(UINT32_MAX)); uint32_t index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; // update cached value if input value is changed - JSTaggedValue cachedStr = Get(index + INPUT_STRING_INDEX); + JSTaggedValue cachedStr = Get(thread, index + INPUT_STRING_INDEX); if (!cachedStr.IsUndefined() && cachedStr != inputValue) { Set(thread, index + INPUT_STRING_INDEX, inputValue); } JSTaggedValue result; switch (type) { case REPLACE_TYPE: - result = Get(index + RESULT_REPLACE_INDEX); + result = Get(thread, index + RESULT_REPLACE_INDEX); break; case SPLIT_TYPE: - result = Get(index + RESULT_SPLIT_INDEX); + result = Get(thread, index + RESULT_SPLIT_INDEX); break; case MATCH_TYPE: - result = Get(index + RESULT_MATCH_INDEX); + result = Get(thread, index + RESULT_MATCH_INDEX); break; case EXEC_TYPE: - result = Get(index + RESULT_EXEC_INDEX); + result = Get(thread, index + RESULT_EXEC_INDEX); break; case INTERMEDIATE_REPLACE_TYPE: - result = Get(index + RESULT_INTERMEDIATE_REPLACE_INDEX); + result = Get(thread, index + RESULT_INTERMEDIATE_REPLACE_INDEX); break; case TEST_TYPE: - result = Get(index + RESULT_TEST_INDEX); + result = Get(thread, index + RESULT_TEST_INDEX); break; case SEARCH_TYPE: - result = Get(index + RESULT_SEARCH_INDEX); + result = Get(thread, index + RESULT_SEARCH_INDEX); break; default: LOG_ECMA(FATAL) << "this branch is unreachable"; @@ -2582,7 +2587,7 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, SetNeedUpdateGlobal(thread, true); SetHitCount(thread, GetHitCount() + 1); if (type != SEARCH_TYPE && type != SPLIT_TYPE) { - BuiltinsRegExp::SetLastIndex(thread, regexp, Get(index + LAST_INDEX_INDEX), true); + BuiltinsRegExp::SetLastIndex(thread, regexp, Get(thread, index + LAST_INDEX_INDEX), true); } if (!isIntermediateResult && result.IsJSArray()) { JSHandle resultHandle(thread, JSArray::Cast(result)); @@ -2600,8 +2605,8 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle extend, bool isIntermediateResult) { JSHandle regexpObj(regexp); - JSHandle pattern(thread, regexpObj->GetOriginalSource()); - JSHandle flags(thread, regexpObj->GetOriginalFlags()); + JSHandle pattern(thread, regexpObj->GetOriginalSource(thread)); + JSHandle flags(thread, regexpObj->GetOriginalFlags(thread)); if (!pattern->IsString() || !flags->IsInt() || !input->IsString()) { return; } @@ -2627,20 +2632,21 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle(flagsValue.GetInt()) + - inputValue.GetKeyHashCode() + lastIndexInput; + uint32_t hash = patternValue.GetKeyHashCode(thread) + static_cast(flagsValue.GetInt()) + + inputValue.GetKeyHashCode(thread) + lastIndexInput; uint32_t entry = hash & static_cast(cache->GetCacheLength() - 1); ASSERT((static_cast(CACHE_TABLE_HEADER_SIZE) + static_cast(entry) * static_cast(ENTRY_SIZE)) <= static_cast(UINT32_MAX)); uint32_t index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; - if (cache->Get(index).IsUndefined()) { + if (cache->Get(thread, index).IsUndefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); cache->SetLastMatchGlobalTableIndex(thread, index); // update last match index cache->SetUseLastMatch(thread, true); // fast path cache->SetEntry(thread, entry, patternValue, flagsValue, inputValue, lastIndexInputValue, lastIndexValue, extendValue, resTableArrayValue); cache->UpdateResultArray(thread, entry, resultArrayCopy.GetTaggedValue(), type); - } else if (cache->Match(entry, patternValue, flagsValue, inputValue, lastIndexInputValue, extendValue, type)) { + } else if (cache->Match(thread, entry, patternValue, flagsValue, inputValue, + lastIndexInputValue, extendValue, type)) { cache->UpdateResultArray(thread, entry, resultArrayCopy.GetTaggedValue(), type); } else { uint32_t entry2 = (entry + 1) & static_cast(cache->GetCacheLength() - 1); @@ -2660,14 +2666,15 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandleGet(index2).IsUndefined()) { + if (cache->Get(thread, index2).IsUndefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); cache->SetLastMatchGlobalTableIndex(thread, index2); // update last match index cache->SetUseLastMatch(thread, true); // fast path cache->SetEntry(thread, entry2, patternValue, flagsValue, inputValue, lastIndexInputValue, lastIndexValue, extendValue, resTableArrayValue); cache->UpdateResultArray(thread, entry2, resultArrayCopy.GetTaggedValue(), type); - } else if (cache->Match(entry2, patternValue, flagsValue, inputValue, lastIndexInputValue, extendValue, type)) { + } else if (cache->Match(thread, entry2, patternValue, flagsValue, + inputValue, lastIndexInputValue, extendValue, type)) { cache->UpdateResultArray(thread, entry2, resultArrayCopy.GetTaggedValue(), type); } else { cache->SetConflictCount(thread, cache->GetConflictCount() > 1 ? (cache->GetConflictCount() - 1) : 0); @@ -2753,39 +2760,39 @@ void RegExpExecResultCache::ClearEntry(JSThread *thread, int entry) } } -bool RegExpExecResultCache::Match(int entry, JSTaggedValue &pattern, JSTaggedValue &flags, JSTaggedValue &input, - JSTaggedValue &lastIndexInputValue, JSTaggedValue &extend, CacheType type) +bool RegExpExecResultCache::Match(JSThread *thread, int entry, JSTaggedValue &pattern, JSTaggedValue &flags, + JSTaggedValue &input, JSTaggedValue &lastIndexInputValue, JSTaggedValue &extend, CacheType type) { ASSERT((static_cast(CACHE_TABLE_HEADER_SIZE) + static_cast(entry) * static_cast(ENTRY_SIZE)) <= static_cast(INT_MAX)); int index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; - JSTaggedValue typeKey = Get(index + RESULT_REPLACE_INDEX + type); + JSTaggedValue typeKey = Get(thread, index + RESULT_REPLACE_INDEX + type); if (typeKey.IsUndefined()) { return false; } - JSTaggedValue keyPattern = Get(index + PATTERN_INDEX); + JSTaggedValue keyPattern = Get(thread, index + PATTERN_INDEX); if (keyPattern.IsUndefined()) { return false; } uint8_t flagsBits = static_cast(flags.GetInt()); - JSTaggedValue keyFlags = Get(index + FLAG_INDEX); + JSTaggedValue keyFlags = Get(thread, index + FLAG_INDEX); uint8_t keyFlagsBits = static_cast(keyFlags.GetInt()); if (flagsBits != keyFlagsBits) { return false; } uint32_t lastIndexInputInt = static_cast(lastIndexInputValue.GetInt()); - JSTaggedValue keyLastIndexInput = Get(index + LAST_INDEX_INPUT_INDEX); + JSTaggedValue keyLastIndexInput = Get(thread, index + LAST_INDEX_INPUT_INDEX); uint32_t keyLastIndexInputInt = static_cast(keyLastIndexInput.GetInt()); if (lastIndexInputInt != keyLastIndexInputInt) { return false; } - JSTaggedValue keyInput = Get(index + INPUT_STRING_INDEX); - JSTaggedValue keyExtend = Get(index + EXTEND_INDEX); + JSTaggedValue keyInput = Get(thread, index + INPUT_STRING_INDEX); + JSTaggedValue keyExtend = Get(thread, index + EXTEND_INDEX); EcmaString *patternStr = EcmaString::Cast(pattern.GetTaggedObject()); EcmaString *inputStr = EcmaString::Cast(input.GetTaggedObject()); EcmaString *keyPatternStr = EcmaString::Cast(keyPattern.GetTaggedObject()); @@ -2794,15 +2801,15 @@ bool RegExpExecResultCache::Match(int entry, JSTaggedValue &pattern, JSTaggedVal if (extend.IsString() && keyExtend.IsString()) { EcmaString *extendStr = EcmaString::Cast(extend.GetTaggedObject()); EcmaString *keyExtendStr = EcmaString::Cast(keyExtend.GetTaggedObject()); - extendEqual = EcmaStringAccessor::StringsAreEqual(extendStr, keyExtendStr); + extendEqual = EcmaStringAccessor::StringsAreEqual(thread, extendStr, keyExtendStr); } else if (extend.IsUndefined() && keyExtend.IsUndefined()) { extendEqual = true; } else { return false; } return extendEqual && - EcmaStringAccessor::StringsAreEqual(patternStr, keyPatternStr) && - EcmaStringAccessor::StringsAreEqual(inputStr, keyInputStr); + EcmaStringAccessor::StringsAreEqual(thread, patternStr, keyPatternStr) && + EcmaStringAccessor::StringsAreEqual(thread, inputStr, keyInputStr); } JSTaggedValue RegExpExecResultCache::GetGlobalTable(JSThread *thread) @@ -2816,7 +2823,7 @@ JSTaggedValue RegExpExecResultCache::GetGlobalTable(JSThread *thread) return env->GetTaggedRegExpGlobalResult(); } - JSTaggedValue lastMatchTable = cacheTable->Get(lastMatchIndex + CAPTURE_SIZE); + JSTaggedValue lastMatchTable = cacheTable->Get(thread, lastMatchIndex + CAPTURE_SIZE); if (cacheTable->GetNeedUpdateGlobal()) { env->SetRegExpGlobalResult(thread, lastMatchTable); cacheTable->SetNeedUpdateGlobal(thread, false); @@ -2860,7 +2867,7 @@ JSHandle RegExpGlobalResult::GrowCapturesCapacity(JSThread * bool BuiltinsRegExp::GetFlag(JSThread *thread, const JSHandle regexp, uint32_t flag, bool isFastPath) { if (isFastPath) { - uint8_t flagsBits = static_cast(JSHandle::Cast(regexp)->GetOriginalFlags().GetInt()); + uint8_t flagsBits = static_cast(JSHandle::Cast(regexp)->GetOriginalFlags(thread).GetInt()); return (flagsBits & flag) != 0; } else { JSMutableHandle flagStr(thread, JSTaggedValue::Undefined()); @@ -2914,7 +2921,7 @@ void BuiltinsRegExp::SetLastIndex(JSThread *thread, const JSHandle regexp, bool isFastPath) { if (isFastPath) { - return JSHandle::Cast(regexp)->GetPropertyInlinedProps(LAST_INDEX_OFFSET).GetInt(); + return JSHandle::Cast(regexp)->GetPropertyInlinedProps(thread, LAST_INDEX_OFFSET).GetInt(); } JSHandle lastIndexHandle(thread, ObjectFastOperator::FastGetPropertyByValue( thread, regexp.GetTaggedValue(), thread->GlobalConstants()->GetHandledLastIndexString().GetTaggedValue())); @@ -2928,7 +2935,7 @@ JSTaggedValue BuiltinsRegExp::GetExecResultIndex(JSThread *thread, const JSHandl bool isFastPath) { if (isFastPath) { - return JSHandle::Cast(execResults)->GetPropertyInlinedProps(EXEC_RESULT_INDEX_OFFSET); + return JSHandle::Cast(execResults)->GetPropertyInlinedProps(thread, EXEC_RESULT_INDEX_OFFSET); } JSHandle resultIndex = thread->GlobalConstants()->GetHandledIndexString(); JSTaggedValue index = ObjectFastOperator::FastGetPropertyByValue( @@ -2941,7 +2948,7 @@ JSTaggedValue BuiltinsRegExp::GetExecResultGroups(JSThread *thread, const JSHand bool isFastPath) { if (isFastPath) { - return JSHandle::Cast(execResults)->GetPropertyInlinedProps(EXEC_RESULT_GROUPS_OFFSET); + return JSHandle::Cast(execResults)->GetPropertyInlinedProps(thread, EXEC_RESULT_GROUPS_OFFSET); } JSHandle groupKey = thread->GlobalConstants()->GetHandledGroupsString(); JSTaggedValue groups = ObjectFastOperator::FastGetPropertyByValue( @@ -2975,10 +2982,10 @@ JSHandle BuiltinsRegExp::CreateStringFromResultArray(JSThread *threa uint32_t subLength = ReplaceLengthField::Decode(bits); uint32_t subPosition = ReplacePositionField::Decode(bits); if (isUtf8) { - EcmaStringAccessor::WriteToFlatWithPos(*srcString, resultInfo.GetDataUtf8Writable(), + EcmaStringAccessor::WriteToFlatWithPos(thread, *srcString, resultInfo.GetDataUtf8Writable(), subLength, subPosition); } else { - EcmaStringAccessor::WriteToFlatWithPos(*srcString, resultInfo.GetDataUtf16Writable(), + EcmaStringAccessor::WriteToFlatWithPos(thread, *srcString, resultInfo.GetDataUtf16Writable(), subLength, subPosition); } nextPos += subLength; @@ -2986,9 +2993,9 @@ JSHandle BuiltinsRegExp::CreateStringFromResultArray(JSThread *threa EcmaString *replacementStr = EcmaString::Cast(substrValue.GetTaggedObject()); uint32_t replaceLength = static_cast(resultLengthArray[i]); if (isUtf8) { - EcmaStringAccessor::WriteToFlat(replacementStr, resultInfo.GetDataUtf8Writable(), replaceLength); + EcmaStringAccessor::WriteToFlat(thread, replacementStr, resultInfo.GetDataUtf8Writable(), replaceLength); } else { - EcmaStringAccessor::WriteToFlat(replacementStr, resultInfo.GetDataUtf16Writable(), replaceLength); + EcmaStringAccessor::WriteToFlat(thread, replacementStr, resultInfo.GetDataUtf16Writable(), replaceLength); } nextPos += replaceLength; } diff --git a/ecmascript/builtins/builtins_regexp.h b/ecmascript/builtins/builtins_regexp.h index 097a3bba2c..7e72bf4297 100644 --- a/ecmascript/builtins/builtins_regexp.h +++ b/ecmascript/builtins/builtins_regexp.h @@ -80,7 +80,7 @@ public: const JSHandle &inputString, bool useCache, bool isIntermediateResult = false); // 21.2.5.2.3 AdvanceStringIndex ( S, index, unicode ) - static int64_t AdvanceStringIndex(const JSHandle &inputStr, int64_t index, + static int64_t AdvanceStringIndex(const JSThread *thread, const JSHandle &inputStr, int64_t index, bool unicode); // 22.2.6.6 get RegExp.prototype.hasIndices static JSTaggedValue GetHasIndices(EcmaRuntimeCallInfo *argv); @@ -245,7 +245,7 @@ public: JSTaggedValue &lastIndexInputValue, JSTaggedValue &lastIndexValue, JSTaggedValue &extendValue, JSTaggedValue &resTableArray); void UpdateResultArray(JSThread *thread, int entry, JSTaggedValue resultArray, CacheType type); - bool Match(int entry, JSTaggedValue &pattenStr, JSTaggedValue &flagsStr, JSTaggedValue &inputStr, + bool Match(JSThread *thread, int entry, JSTaggedValue &pattenStr, JSTaggedValue &flagsStr, JSTaggedValue &inputStr, JSTaggedValue &lastIndexInputValue, JSTaggedValue &extend, CacheType type); static JSTaggedValue GetGlobalTable(JSThread *thread); inline void SetHitCount(JSThread *thread, int hitCount) @@ -255,7 +255,7 @@ public: inline int GetHitCount() { - return Get(CACHE_HIT_COUNT_INDEX).GetInt(); + return GetPrimitive(CACHE_HIT_COUNT_INDEX).GetInt(); } inline void SetCacheCount(JSThread *thread, int hitCount) @@ -265,7 +265,7 @@ public: inline int GetCacheCount() { - return Get(CACHE_COUNT_INDEX).GetInt(); + return GetPrimitive(CACHE_COUNT_INDEX).GetInt(); } void Print() @@ -291,17 +291,17 @@ public: inline uint32_t GetLargeStrCount() { - return Get(LARGE_STRING_COUNT_INDEX).GetInt(); + return GetPrimitive(LARGE_STRING_COUNT_INDEX).GetInt(); } inline uint32_t GetConflictCount() { - return Get(CONFLICT_COUNT_INDEX).GetInt(); + return GetPrimitive(CONFLICT_COUNT_INDEX).GetInt(); } inline uint32_t GetStrLenThreshold() { - return Get(STRING_LENGTH_THRESHOLD_INDEX).GetInt(); + return GetPrimitive(STRING_LENGTH_THRESHOLD_INDEX).GetInt(); } inline void SetCacheLength(JSThread *thread, int length) @@ -311,7 +311,7 @@ public: inline int GetCacheLength() { - return Get(CACHE_LENGTH_INDEX).GetInt(); + return GetPrimitive(CACHE_LENGTH_INDEX).GetInt(); } inline void SetLastMatchGlobalTableIndex(JSThread *thread, int index) @@ -321,7 +321,7 @@ public: inline int GetLastMatchGlobalTableIndex() { - return Get(LAST_MATCH_GLOBAL_TABLE_INDEX).GetInt(); + return GetPrimitive(LAST_MATCH_GLOBAL_TABLE_INDEX).GetInt(); } inline void SetUseLastMatch(JSThread *thread, bool useLastMatchIndex) @@ -331,7 +331,7 @@ public: inline bool GetUseLastMatch() { - return Get(USE_LAST_MATCH_INDEX).IsTrue(); + return GetPrimitive(USE_LAST_MATCH_INDEX).IsTrue(); } inline void SetNeedUpdateGlobal(JSThread *thread, bool needUpdateGlobal) @@ -341,7 +341,7 @@ public: inline bool GetNeedUpdateGlobal() { - return Get(NEED_UPDATE_GLOBAL_INDEX).IsTrue(); + return GetPrimitive(NEED_UPDATE_GLOBAL_INDEX).IsTrue(); } private: @@ -409,7 +409,7 @@ public: JSTaggedValue GetTotalCaptureCounts() { - return Get(TOTAL_CAPTURE_COUNTS_INDEX); + return GetPrimitive(TOTAL_CAPTURE_COUNTS_INDEX); } void SetEndIndex(JSThread *thread, JSTaggedValue endIndex) @@ -419,7 +419,7 @@ public: JSTaggedValue GetEndIndex() { - return Get(END_INDEX); + return GetPrimitive(END_INDEX); } void SetInputString(JSThread *thread, JSTaggedValue string) @@ -427,9 +427,9 @@ public: Set(thread, INPUT_STRING_INDEX, string); } - JSTaggedValue GetInputString() + JSTaggedValue GetInputString(JSThread *thread) { - return Get(INPUT_STRING_INDEX); + return Get(thread, INPUT_STRING_INDEX); } void SetStartOfCaptureIndex(JSThread *thread, uint32_t index, JSTaggedValue value) @@ -444,12 +444,12 @@ public: JSTaggedValue GetStartOfCaptureIndex(uint32_t index) { - return Get(FIRST_CAPTURE_INDEX + index * 2); // 2 : double + return GetPrimitive(FIRST_CAPTURE_INDEX + index * 2); // 2 : double } JSTaggedValue GetEndOfCaptureIndex(uint32_t index) { - return Get(FIRST_CAPTURE_INDEX + index * 2 + 1); // 2 : double + return GetPrimitive(FIRST_CAPTURE_INDEX + index * 2 + 1); // 2 : double } static JSHandle GrowCapturesCapacity(JSThread *thread, diff --git a/ecmascript/builtins/builtins_relative_time_format.cpp b/ecmascript/builtins/builtins_relative_time_format.cpp index d7ed9633a4..2ed99cdd82 100644 --- a/ecmascript/builtins/builtins_relative_time_format.cpp +++ b/ecmascript/builtins/builtins_relative_time_format.cpp @@ -52,7 +52,7 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { PropertyDescriptor descriptor(thread, JSHandle::Cast(relativeTimeFormat), false, false, true); - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol(thread)); JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return thisValue.GetTaggedValue(); diff --git a/ecmascript/builtins/builtins_segments.cpp b/ecmascript/builtins/builtins_segments.cpp index d6c9e4cc28..cdac67a4fa 100644 --- a/ecmascript/builtins/builtins_segments.cpp +++ b/ecmascript/builtins/builtins_segments.cpp @@ -58,9 +58,9 @@ JSTaggedValue BuiltinsSegments::GetSegmentIterator(EcmaRuntimeCallInfo *argv) JSHandle segments = JSHandle::Cast(thisValue); // 3. Let segmenter be segments.[[SegmentsSegmenter]]. // 4. Let string be segments.[[SegmentsString]]. - JSHandle string(thread, segments->GetSegmentsString()); + JSHandle string(thread, segments->GetSegmentsString(thread)); // 5. Return ! CreateSegmentIterator(segmenter, string). - return JSSegmentIterator::CreateSegmentIterator(thread, segments->GetIcuBreakIterator(), string, + return JSSegmentIterator::CreateSegmentIterator(thread, segments->GetIcuBreakIterator(thread), string, segments->GetGranularity()).GetTaggedValue(); } } // namespace panda::ecmascript::builtins \ No newline at end of file diff --git a/ecmascript/builtins/builtins_sendable_arraybuffer.cpp b/ecmascript/builtins/builtins_sendable_arraybuffer.cpp index ba199df9c9..f0de07a83e 100644 --- a/ecmascript/builtins/builtins_sendable_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_sendable_arraybuffer.cpp @@ -93,7 +93,7 @@ JSTaggedValue BuiltinsSendableArrayBuffer::GetByteLength(EcmaRuntimeCallInfo *ar THROW_TYPE_ERROR_AND_RETURN(thread, "don't have internal slot", JSTaggedValue::Exception()); } // 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "IsDetachedBuffer", JSTaggedValue::Exception()); } JSHandle arrBuf(thisHandle); @@ -124,7 +124,7 @@ JSTaggedValue BuiltinsSendableArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } // 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } JSHandle arrBuf(thisHandle); @@ -185,11 +185,11 @@ JSTaggedValue BuiltinsSendableArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "don't have bufferdata internal slot", JSTaggedValue::Exception()); } // 18. If IsDetachedBuffer(new) is true, throw a TypeError exception. - if (IsDetachedBuffer(newArrBuf.GetTaggedValue())) { + if (IsDetachedBuffer(thread, newArrBuf.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "new arrayBuffer IsDetachedBuffer", JSTaggedValue::Exception()); } // 19. If SameValue(new, O) is true, throw a TypeError exception. - if (JSTaggedValue::SameValue(newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "value of new arraybuffer and this is same", JSTaggedValue::Exception()); } JSHandle newJsArrBuf(newArrBuf); @@ -200,14 +200,14 @@ JSTaggedValue BuiltinsSendableArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) } // 21. NOTE: Side-effects of the above steps may have detached O. // 22. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } if (newLen > 0) { // 23. Let fromBuf be the value of O’s [[ArrayBufferData]] internal slot. - void *fromBuf = GetDataPointFromBuffer(arrBuf.GetTaggedValue()); + void *fromBuf = GetDataPointFromBuffer(thread, arrBuf.GetTaggedValue()); // 24. Let toBuf be the value of new’s [[ArrayBufferData]] internal slot. - void *toBuf = GetDataPointFromBuffer(newJsArrBuf.GetTaggedValue()); + void *toBuf = GetDataPointFromBuffer(thread, newJsArrBuf.GetTaggedValue()); // 25. Perform CopyDataBlockBytes(toBuf, fromBuf, first, newLen). JSSendableArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, first, newLen); } @@ -246,7 +246,7 @@ JSTaggedValue BuiltinsSendableArrayBuffer::AllocateSendableArrayBuffer( } // 24.1.1.2 IsDetachedBuffer() -bool BuiltinsSendableArrayBuffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) +bool BuiltinsSendableArrayBuffer::IsDetachedBuffer(JSThread *thread, JSTaggedValue arrayBuffer) { if (arrayBuffer.IsByteArray()) { return false; @@ -254,7 +254,7 @@ bool BuiltinsSendableArrayBuffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) // 1. Assert: Type(arrayBuffer) is Object and it has an [[ArrayBufferData]] internal slot. ASSERT(arrayBuffer.IsSendableArrayBuffer()); JSSendableArrayBuffer *buffer = JSSendableArrayBuffer::Cast(arrayBuffer.GetTaggedObject()); - JSTaggedValue dataSlot = buffer->GetArrayBufferData(); + JSTaggedValue dataSlot = buffer->GetArrayBufferData(thread); // 2. If arrayBuffer’s [[ArrayBufferData]] internal slot is null, return true. // 3. Return false. return dataSlot.IsNull(); @@ -279,7 +279,7 @@ JSTaggedValue BuiltinsSendableArrayBuffer::CloneArrayBuffer(JSThread *thread, // b. ReturnIfAbrupt(cloneConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (IsDetachedBuffer(thread, srcBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } else { ASSERT(constructor->IsConstructor()); @@ -311,22 +311,22 @@ JSTaggedValue BuiltinsSendableArrayBuffer::CloneArrayBuffer(JSThread *thread, // 9. ReturnIfAbrupt(targetBuffer). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (IsDetachedBuffer(thread, srcBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 11. Let targetBlock be the value of targetBuffer’s [[ArrayBufferData]] internal slot. JSHandle newArrBuf(thread, taggedBuf); // Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength). // 7. Let srcBlock be the value of srcBuffer’s [[ArrayBufferData]] internal slot. - void *fromBuf = GetDataPointFromBuffer(srcBuffer.GetTaggedValue()); - void *toBuf = GetDataPointFromBuffer(taggedBuf); + void *fromBuf = GetDataPointFromBuffer(thread, srcBuffer.GetTaggedValue()); + void *toBuf = GetDataPointFromBuffer(thread, taggedBuf); if (cloneLen > 0) { JSSendableArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, srcByteOffset, cloneLen); } return taggedBuf; } -void *BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t byteOffset) +void *BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(JSThread *thread, JSTaggedValue arrBuf, uint32_t byteOffset) { if (arrBuf.IsByteArray()) { return reinterpret_cast(ToUintPtr(ByteArray::Cast(arrBuf.GetTaggedObject())->GetData()) + byteOffset); @@ -337,7 +337,7 @@ void *BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(JSTaggedValue arrBuf, return nullptr; } - JSTaggedValue data = arrayBuffer->GetArrayBufferData(); + JSTaggedValue data = arrayBuffer->GetArrayBufferData(thread); return reinterpret_cast(ToUintPtr(JSNativePointer::Cast(data.GetTaggedObject()) ->GetExternalPointer()) + byteOffset); } diff --git a/ecmascript/builtins/builtins_sendable_arraybuffer.h b/ecmascript/builtins/builtins_sendable_arraybuffer.h index 0a5a34cd48..333656178f 100644 --- a/ecmascript/builtins/builtins_sendable_arraybuffer.h +++ b/ecmascript/builtins/builtins_sendable_arraybuffer.h @@ -48,7 +48,7 @@ public: static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); // 24.1.1.2 IsDetachedBuffer(arrayBuffer) - static bool IsDetachedBuffer(JSTaggedValue arrayBuffer); + static bool IsDetachedBuffer(JSThread *thread, JSTaggedValue arrayBuffer); // 24.1.1.4 CloneArrayBuffer( srcBuffer, srcByteOffset [, cloneConstructor] ) static JSTaggedValue CloneArrayBuffer(JSThread *thread, const JSHandle &srcBuffer, uint32_t srcByteOffset, JSHandle constructor); @@ -81,7 +81,7 @@ public: return Span>(ARRAYBUFFER_FUNCTION_PROPERTIES); } - static void *GetDataPointFromBuffer(JSTaggedValue arrBuf, uint32_t byteOffset = 0); + static void *GetDataPointFromBuffer(JSThread *thread, JSTaggedValue arrBuf, uint32_t byteOffset = 0); private: #define BUILTIN_ARRAY_BUFFER_ENTRY(name, func, length, id) \ BuiltinFunctionEntry::Create(name, BuiltinsSendableArrayBuffer::func, length, BUILTINS_STUB_ID(id)), diff --git a/ecmascript/builtins/builtins_set.cpp b/ecmascript/builtins/builtins_set.cpp index 3e786bed17..4a4bc618a0 100644 --- a/ecmascript/builtins/builtins_set.cpp +++ b/ecmascript/builtins/builtins_set.cpp @@ -195,14 +195,14 @@ JSTaggedValue BuiltinsSet::ForEach(EcmaRuntimeCallInfo *argv) JSHandle thisArg = GetCallArg(argv, 1); // 6.Let entries be the List that is the value of S’s [[SetData]] internal slot. - JSMutableHandle hashSet(thread, set->GetLinkedSet()); + JSMutableHandle hashSet(thread, set->GetLinkedSet(thread)); const uint32_t argsLength = 3; int index = 0; int totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // 7.Repeat for each e that is an element of entries, in original insertion order while (index < totalElements) { - JSHandle key(thread, hashSet->GetKey(index++)); + JSHandle key(thread, hashSet->GetKey(thread, index++)); // a. If e is not empty, then if (!key->IsHole()) { EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo( @@ -214,11 +214,11 @@ JSTaggedValue BuiltinsSet::ForEach(EcmaRuntimeCallInfo *argv) // ii. ReturnIfAbrupt(funcResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // Maybe add or delete - JSTaggedValue nextTable = hashSet->GetNextTable(); + JSTaggedValue nextTable = hashSet->GetNextTable(thread); while (!nextTable.IsHole()) { - index -= hashSet->GetDeletedElementsAt(index); + index -= hashSet->GetDeletedElementsAt(thread, index); hashSet.Update(nextTable); - nextTable = hashSet->GetNextTable(); + nextTable = hashSet->GetNextTable(thread); } totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements(); } @@ -244,7 +244,7 @@ JSTaggedValue BuiltinsSet::GetSize(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception()); } JSSet* jsSet = JSSet::Cast(self.GetTaggedValue().GetTaggedObject()); - uint32_t count = jsSet->GetSize(); + uint32_t count = jsSet->GetSize(thread); return JSTaggedValue(count); } diff --git a/ecmascript/builtins/builtins_shared_array.cpp b/ecmascript/builtins/builtins_shared_array.cpp index 373e2fdb33..947713c4ff 100644 --- a/ecmascript/builtins/builtins_shared_array.cpp +++ b/ecmascript/builtins/builtins_shared_array.cpp @@ -205,7 +205,7 @@ JSTaggedValue BuiltinsSharedArray::FromSharedArray(JSThread *thread, const JSHan JSHandle eleArray = factory->NewTaggedArray(len, JSTaggedValue::Undefined(), MemSpaceType::SHARED_OLD_SPACE); JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, items); - TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); eleArray->Copy(thread, 0, 0, element, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); newArrayHandle->SetElements(thread, eleArray); @@ -657,7 +657,7 @@ JSTaggedValue BuiltinsSharedArray::Concat(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle eleArray = factory->NewTaggedArray(newArrayLen, JSTaggedValue::Undefined(), MemSpaceType::SHARED_OLD_SPACE); - TaggedArray *oldElement = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *oldElement = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); eleArray->Copy(thread, 0, 0, oldElement, oldArrayLen); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -845,7 +845,7 @@ JSTaggedValue BuiltinsSharedArray::Fill(EcmaRuntimeCallInfo *argv) // d. Increase k by 1. int64_t k = start; JSMutableHandle key(thread, JSTaggedValue::Undefined()); - TaggedArray *elements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); while (k < end) { elements->Set(thread, k, value); k++; @@ -1025,7 +1025,7 @@ JSTaggedValue BuiltinsSharedArray::Find(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsSharedArray::GetElementByKey(JSThread *thread, JSHandle& thisObjHandle, uint32_t index) { - if (UNLIKELY(ElementAccessor::GetElementsLength(thisObjHandle) <= index)) { + if (UNLIKELY(ElementAccessor::GetElementsLength(thread, thisObjHandle) <= index)) { return JSTaggedValue::Undefined(); } @@ -1035,7 +1035,7 @@ JSTaggedValue BuiltinsSharedArray::GetElementByKey(JSThread *thread, JSHandle arrHandle, uint32_t key, const JSHandle &value) { - if (UNLIKELY(ElementAccessor::GetElementsLength(arrHandle) <= key)) { + if (UNLIKELY(ElementAccessor::GetElementsLength(thread, arrHandle) <= key)) { auto error = ContainerError::ParamError(thread, "Set element's index is exceeds the array length."); THROW_NEW_ERROR_AND_RETURN(thread, error); } @@ -1074,8 +1074,8 @@ JSTaggedValue BuiltinsSharedArray::FindIndex(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "the predicate is not callable.", JSTaggedValue::Exception()); } - if (UNLIKELY(ElementAccessor::GetElementsLength(thisObjHandle) < len)) { - len = ElementAccessor::GetElementsLength(thisObjHandle); + if (UNLIKELY(ElementAccessor::GetElementsLength(thread, thisObjHandle) < len)) { + len = ElementAccessor::GetElementsLength(thread, thisObjHandle); } const int32_t argsLength = 3; // 3: ?kValue, k, O? @@ -1445,9 +1445,9 @@ JSTaggedValue BuiltinsSharedArray::PopInner(EcmaRuntimeCallInfo *argv, JSHandle< JSHandle element(thread, ElementAccessor::Get(thread, thisObjHandle, newLen)); // BuiltinsSharedArray::GetElementByKey(thread, thisObjHandle, newLen)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t capacity = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t capacity = ElementAccessor::GetElementsLength(thread, thisObjHandle); if (TaggedArray::ShouldTrim(capacity, newLen)) { - TaggedArray *elements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); elements->Trim(thread, newLen); } @@ -1488,8 +1488,8 @@ JSTaggedValue BuiltinsSharedArray::Push(EcmaRuntimeCallInfo *argv) } uint32_t newLength = argc + static_cast(len); - TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); - if (newLength > ElementAccessor::GetElementsLength(thisObjHandle)) { + TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); + if (newLength > ElementAccessor::GetElementsLength(thread, thisObjHandle)) { element = *JSObject::GrowElementsCapacity(thread, thisObjHandle, newLength, true); } @@ -1656,14 +1656,14 @@ JSTaggedValue BuiltinsSharedArray::Shift(EcmaRuntimeCallInfo *argv) // i. Let deleteStatus be DeletePropertyOrThrow(O, to). // ii. ReturnIfAbrupt(deleteStatus). // g. Increase k by 1. - TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); int64_t newLen = len - 1; element->Copy(thread, 0, 1, element, newLen); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t capacity = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t capacity = ElementAccessor::GetElementsLength(thread, thisObjHandle); if (TaggedArray::ShouldTrim(capacity, newLen)) { - TaggedArray *elements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); elements->Trim(thread, newLen); } @@ -1781,7 +1781,7 @@ JSTaggedValue BuiltinsSharedArray::Sort(EcmaRuntimeCallInfo *argv) [[maybe_unused]] ConcurrentApiScope scope(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle elements(thread, thisObjHandle->GetElements()); + JSHandle elements(thread, thisObjHandle->GetElements(thread)); base::TimSort::Sort(thread, elements, callbackFnHandle); return thisObjHandle.GetTaggedValue(); } @@ -1851,7 +1851,7 @@ JSTaggedValue BuiltinsSharedArray::Splice(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle DelArrEle = factory->NewTaggedArray(actualDeleteCount, JSTaggedValue::Undefined(), MemSpaceType::SHARED_OLD_SPACE); - TaggedArray *oldElement = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *oldElement = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); // 14. Let k be 0. // 15. Repeat, while k < actualDeleteCount // a. Let from be ToString(actualStart+k). @@ -2027,7 +2027,7 @@ JSTaggedValue BuiltinsSharedArray::ToLocaleStringInternalHandle(EcmaRuntimeCallI nextHandle.Update(next); JSHandle nextStringHandle = JSTaggedValue::ToString(thread, nextHandle); RETURN_EXCEPTION_AND_POP_JOINSTACK(thread, thisHandle); - CString nextString = ConvertToString(*nextStringHandle); + CString nextString = ConvertToString(thread, *nextStringHandle); if (k > 0) { concatStr += STRING_SEPERATOR; concatStr += nextString; @@ -2073,8 +2073,8 @@ JSTaggedValue BuiltinsSharedArray::Unshift(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); - if (newLen > ElementAccessor::GetElementsLength(thisObjHandle)) { + TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); + if (newLen > ElementAccessor::GetElementsLength(thread, thisObjHandle)) { element = *JSObject::GrowElementsCapacity(thread, thisObjHandle, newLen, true); } element->Copy(thread, argc, 0, element, len); @@ -2247,7 +2247,7 @@ JSTaggedValue BuiltinsSharedArray::Includes(EcmaRuntimeCallInfo *argv) while (from < len) { kValueHandle.Update(BuiltinsSharedArray::GetElementByKey(thread, thisObjHandle, from)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), kValueHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(thread, searchElement.GetTaggedValue(), kValueHandle.GetTaggedValue())) { return GetTaggedBoolean(true); } from++; @@ -2517,7 +2517,7 @@ JSTaggedValue BuiltinsSharedArray::ExtendTo(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - if (newLength > ElementAccessor::GetElementsLength(thisObjHandle)) { + if (newLength > ElementAccessor::GetElementsLength(thread, thisObjHandle)) { JSObject::GrowElementsCapacity(thread, thisObjHandle, newLength, true); } @@ -2634,7 +2634,7 @@ JSTaggedValue BuiltinsSharedArray::Of(EcmaRuntimeCallInfo *argv) } JSHandle newArrayHandle(newArray); - if (UNLIKELY(argc > ElementAccessor::GetElementsLength(newArrayHandle))) { + if (UNLIKELY(argc > ElementAccessor::GetElementsLength(thread, newArrayHandle))) { JSObject::GrowElementsCapacity(thread, JSHandle::Cast(newArrayHandle), argc, true); } @@ -2734,7 +2734,7 @@ JSTaggedValue BuiltinsSharedArray::CopyWithin(EcmaRuntimeCallInfo *argv) // 16. Else, // a. Let direction = 1. if (count > 0) { - TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *element = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); element->Copy(thread, copyTo, copyFrom, element, count); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -2751,9 +2751,9 @@ JSTaggedValue BuiltinsSharedArray::FastReverse(JSThread *thread, JSHandleGetClass()->GetElementsKind(); - JSHandle elements(thread, thisObjHandle->GetElements()); + JSHandle elements(thread, thisObjHandle->GetElements(thread)); bool enableElementsKind = thread->GetEcmaVM()->IsEnableElementsKind(); if (enableElementsKind) { if (kind == ElementsKind::INT || kind == ElementsKind::HOLE_INT) { diff --git a/ecmascript/builtins/builtins_shared_map.cpp b/ecmascript/builtins/builtins_shared_map.cpp index 9c8a184a5f..6ca89453ff 100644 --- a/ecmascript/builtins/builtins_shared_map.cpp +++ b/ecmascript/builtins/builtins_shared_map.cpp @@ -171,16 +171,16 @@ JSTaggedValue BuiltinsSharedMap::ForEach(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not Callable", JSTaggedValue::Exception()); } JSHandle thisArg = GetCallArg(argv, 1); - JSMutableHandle hashMap(thread, map->GetLinkedMap()); + JSMutableHandle hashMap(thread, map->GetLinkedMap(thread)); const uint32_t argsLength = 3; int index = 0; int totalElements = hashMap->NumberOfElements() + hashMap->NumberOfDeletedElements(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // Repeat for each e that is an element of entries, in original insertion order while (index < totalElements) { - JSHandle key(thread, hashMap->GetKey(index++)); + JSHandle key(thread, hashMap->GetKey(thread, index++)); if (!key->IsHole()) { - JSHandle value(thread, hashMap->GetValue(index - 1)); + JSHandle value(thread, hashMap->GetValue(thread, index - 1)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo( thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/builtins/builtins_shared_set.cpp b/ecmascript/builtins/builtins_shared_set.cpp index 840a659c30..fd90aec6f6 100755 --- a/ecmascript/builtins/builtins_shared_set.cpp +++ b/ecmascript/builtins/builtins_shared_set.cpp @@ -194,14 +194,14 @@ JSTaggedValue BuiltinsSharedSet::ForEach(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "callback is not callable", JSTaggedValue::Exception()); } JSHandle thisArg = GetCallArg(argv, 1); - JSMutableHandle hashSet(thread, set->GetLinkedSet()); + JSMutableHandle hashSet(thread, set->GetLinkedSet(thread)); const uint32_t argsLength = 3; int index = 0; int totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // Repeat for each e that is an element of entries, in original insertion order while (index < totalElements) { - JSHandle key(thread, hashSet->GetKey(index++)); + JSHandle key(thread, hashSet->GetKey(thread, index++)); if (!key->IsHole()) { EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo( thread, func, thisArg, undefined, argsLength); diff --git a/ecmascript/builtins/builtins_shared_typedarray.cpp b/ecmascript/builtins/builtins_shared_typedarray.cpp index 984e5c5511..725930741c 100755 --- a/ecmascript/builtins/builtins_shared_typedarray.cpp +++ b/ecmascript/builtins/builtins_shared_typedarray.cpp @@ -384,9 +384,9 @@ JSTaggedValue BuiltinsSharedTypedArray::GetByteLength(EcmaRuntimeCallInfo *argv) } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSHandle typeArrayObj = JSHandle::Cast(thisHandle); - JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(thread); // 5. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue(0); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. @@ -413,9 +413,9 @@ JSTaggedValue BuiltinsSharedTypedArray::GetByteOffset(EcmaRuntimeCallInfo *argv) } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSHandle typeArrayObj = JSHandle::Cast(thisHandle); - JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(thread); // 5. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue(0); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. @@ -625,7 +625,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Filter(EcmaRuntimeCallInfo *argv) JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle ntKey(thread, JSTaggedValue::Undefined()); for (int32_t n = 0; n < captured; n++) { - valueHandle.Update(kept->Get(n)); + valueHandle.Update(kept->Get(thread, n)); ntKey.Update(JSTaggedValue(n)); ObjectFastOperator::FastSetPropertyByValue(thread, newArrObj.GetTaggedValue(), ntKey.GetTaggedValue(), valueHandle.GetTaggedValue()); @@ -784,7 +784,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Join(EcmaRuntimeCallInfo *argv) } if (EcmaStringAccessor(sepStringHandle).IsUtf8() && EcmaStringAccessor(sepStringHandle).GetLength() == 1) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sep = EcmaStringAccessor(sepStringHandle).Get(0); + sep = EcmaStringAccessor(sepStringHandle).Get(thread, 0); } else if (EcmaStringAccessor(sepStringHandle).GetLength() == 0) { sep = BuiltinsSharedTypedArray::SeparatorFlag::MINUS_TWO; sepLength = 0; @@ -839,14 +839,14 @@ JSTaggedValue BuiltinsSharedTypedArray::Join(EcmaRuntimeCallInfo *argv) if (sep >= 0) { EcmaStringAccessor(newString).Set(current, static_cast(sep)); } else if (sep != BuiltinsSharedTypedArray::SeparatorFlag::MINUS_TWO) { - EcmaStringAccessor::ReadData( + EcmaStringAccessor::ReadData(thread, newString, *sepStringHandle, current, allocateLength - static_cast(current), sepLength); } current += static_cast(sepLength); } JSHandle nextStr = vec[k]; int nextLength = static_cast(EcmaStringAccessor(nextStr).GetLength()); - EcmaStringAccessor::ReadData(newString, *nextStr, current, + EcmaStringAccessor::ReadData(thread, newString, *nextStr, current, allocateLength - static_cast(current), nextLength); current += nextLength; } @@ -896,9 +896,9 @@ JSTaggedValue BuiltinsSharedTypedArray::GetLength(EcmaRuntimeCallInfo *argv) } // 4. Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots. // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBufferOrByteArray(thread); // 6. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue(0); } // 7. Let length be the value of O’s [[ArrayLength]] internal slot. @@ -1116,9 +1116,9 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) } } // 9. Let targetBuffer be the value of target’s [[ViewedArrayBuffer]] internal slot. - JSHandle targetBuffer(thread, targetObj->GetViewedArrayBufferOrByteArray()); + JSHandle targetBuffer(thread, targetObj->GetViewedArrayBufferOrByteArray(thread)); // 10. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -1137,7 +1137,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) if (argArray->IsStableJSArray(thread)) { uint32_t length = JSHandle::Cast(argArray)->GetArrayLength(); JSHandle argObj(argArray); - uint32_t elemLength = ElementAccessor::GetElementsLength(argObj); + uint32_t elemLength = ElementAccessor::GetElementsLength(thread, argObj); // Load On Demand check if (elemLength >= length) { return JSStableArray::FastCopyFromArrayToTypedArray( @@ -1193,7 +1193,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) kValue.Update(ObjectFastOperator::FastGetPropertyByValue( thread, JSHandle::Cast(src).GetTaggedValue(), kKey.GetTaggedValue())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -1217,13 +1217,13 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) JSHandle typedArray(argArray); // 12. Let srcBuffer be the value of typedArray’s [[ViewedArrayBuffer]] internal slot. // 13. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSTaggedValue srcBuffer = typedArray->GetViewedArrayBufferOrByteArray(); + JSTaggedValue srcBuffer = typedArray->GetViewedArrayBufferOrByteArray(thread); JSHandle srcBufferHandle(thread, srcBuffer); - if (srcBuffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(srcBuffer)) { + if (srcBuffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, srcBuffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } - if (!srcBuffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(srcBuffer)) { + if (!srcBuffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcBuffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } @@ -1240,7 +1240,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) // 20. Let srcElementSize be the Number value of the Element Size value specified in Table 49 for srcName. // 21. Let srcLength be the value of typedArray’s [[ArrayLength]] internal slot. // 22. Let srcByteOffset be the value of typedArray’s [[ByteOffset]] internal slot. - JSHandle srcName(thread, typedArray->GetTypedArrayName()); + JSHandle srcName(thread, typedArray->GetTypedArrayName(thread)); DataViewType srcType = JSTypedArray::GetTypeFromName(thread, srcName); uint32_t srcElementSize = TypedArrayHelper::GetSizeFromType(srcType); uint32_t srcLength = typedArray->GetArrayLength(); @@ -1258,7 +1258,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) // d. Let srcByteIndex be 0. // 25. Else, let srcByteIndex be srcByteOffset. uint32_t srcByteIndex = 0; - if (JSTaggedValue::SameValue(srcBufferHandle.GetTaggedValue(), targetBuffer.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, srcBufferHandle.GetTaggedValue(), targetBuffer.GetTaggedValue())) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); srcBuffer = BuiltinsSendableArrayBuffer::CloneArrayBuffer(thread, targetBuffer, srcByteOffset, @@ -1309,13 +1309,13 @@ JSTaggedValue BuiltinsSharedTypedArray::Set(EcmaRuntimeCallInfo *argv) void *srcBuf = nullptr; if (argArray->IsSharedTypedArray()) { srcBuf = BuiltinsSendableArrayBuffer::GetDataPointFromBuffer( - srcBufferHandle.GetTaggedValue(), srcByteIndex); + thread, srcBufferHandle.GetTaggedValue(), srcByteIndex); } else { srcBuf = BuiltinsArrayBuffer::GetDataPointFromBuffer( - srcBufferHandle.GetTaggedValue(), srcByteIndex); + thread, srcBufferHandle.GetTaggedValue(), srcByteIndex); } void *targetBuf = BuiltinsSendableArrayBuffer::GetDataPointFromBuffer( - targetBuffer.GetTaggedValue(), targetByteIndex); + thread, targetBuffer.GetTaggedValue(), targetByteIndex); if (memcpy_s(targetBuf, srcLength * srcElementSize, srcBuf, srcLength * srcElementSize) != EOK) { LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); @@ -1382,11 +1382,11 @@ JSTaggedValue BuiltinsSharedTypedArray::Slice(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 17. Let srcName be the String value of O’s [[TypedArrayName]] internal slot. // 18. Let srcType be the String value of the Element Type value in Table 49 for srcName. - JSHandle srcName(thread, thisObj->GetTypedArrayName()); + JSHandle srcName(thread, thisObj->GetTypedArrayName(thread)); DataViewType srcType = JSTypedArray::GetTypeFromName(thread, srcName); // 19. Let targetName be the String value of A’s [[TypedArrayName]] internal slot. // 20. Let targetType be the String value of the Element Type value in Table 49 for targetName. - JSHandle targetName(thread, JSTypedArray::Cast(*newArrObj)->GetTypedArrayName()); + JSHandle targetName(thread, JSTypedArray::Cast(*newArrObj)->GetTypedArrayName(thread)); DataViewType targetType = JSTypedArray::GetTypeFromName(thread, targetName); // 21. If SameValue(srcType, targetType) is false, then // a. Let n be 0. @@ -1419,13 +1419,13 @@ JSTaggedValue BuiltinsSharedTypedArray::Slice(EcmaRuntimeCallInfo *argv) // 22. Else if count > 0, // a. Let srcBuffer be the value of O’s [[ViewedArrayBuffer]] internal slot. // b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSTaggedValue srcBuffer = thisObj->GetViewedArrayBufferOrByteArray(); - if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(srcBuffer)) { + JSTaggedValue srcBuffer = thisObj->GetViewedArrayBufferOrByteArray(thread); + if (BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, srcBuffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of this value is detached buffer.", JSTaggedValue::Exception()); } // c. Let targetBuffer be the value of A’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue targetBuffer = JSTypedArray::Cast(*newArrObj)->GetViewedArrayBufferOrByteArray(); + JSTaggedValue targetBuffer = JSTypedArray::Cast(*newArrObj)->GetViewedArrayBufferOrByteArray(thread); // d. Let elementSize be the Number value of the Element Size value specified in Table 49 for srcType. uint32_t elementSize = TypedArrayHelper::GetSizeFromType(srcType); // e. NOTE: If srcType and targetType are the same the transfer must be performed in a manner that @@ -1442,9 +1442,9 @@ JSTaggedValue BuiltinsSharedTypedArray::Slice(EcmaRuntimeCallInfo *argv) // iii. Increase srcByteIndex by 1. // iv. Increase targetByteIndex by 1. uint8_t *srcBuf = reinterpret_cast( - BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(srcBuffer, srcByteIndex)); + BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(thread, srcBuffer, srcByteIndex)); uint8_t *targetBuf = reinterpret_cast( - BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(targetBuffer, targetByteIndex)); + BuiltinsSendableArrayBuffer::GetDataPointFromBuffer(thread, targetBuffer, targetByteIndex)); if (srcBuffer != targetBuffer && memmove_s( targetBuf, elementSize * count, srcBuf, elementSize * count) != EOK) { LOG_FULL(FATAL) << "memcpy_s failed"; @@ -1616,7 +1616,7 @@ JSTaggedValue BuiltinsSharedTypedArray::Subarray(EcmaRuntimeCallInfo *argv) // 15. Let elementSize be the Number value of the Element Size value specified in Table 49 for constructorName. // 16. Let srcByteOffset be the value of O’s [[ByteOffset]] internal slot. // 17. Let beginByteOffset be srcByteOffset + beginIndex × elementSize. - JSHandle constructorName(thread, thisObj->GetTypedArrayName()); + JSHandle constructorName(thread, thisObj->GetTypedArrayName(thread)); DataViewType elementType = JSTypedArray::GetTypeFromName(thread, constructorName); uint32_t elementSize = TypedArrayHelper::GetSizeFromType(elementType); uint32_t srcByteOffset = thisObj->GetByteOffset(); @@ -1706,7 +1706,7 @@ JSTaggedValue BuiltinsSharedTypedArray::ToStringTag(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } // 4. Let name be the value of O’s [[TypedArrayName]] internal slot. - JSTaggedValue name = JSHandle::Cast(thisHandle)->GetTypedArrayName(); + JSTaggedValue name = JSHandle::Cast(thisHandle)->GetTypedArrayName(thread); // 5. Assert: name is a String value. ASSERT(name.IsString()); // 6. Return name. diff --git a/ecmascript/builtins/builtins_sharedarraybuffer.cpp b/ecmascript/builtins/builtins_sharedarraybuffer.cpp index 4e384b7340..1b73537418 100644 --- a/ecmascript/builtins/builtins_sharedarraybuffer.cpp +++ b/ecmascript/builtins/builtins_sharedarraybuffer.cpp @@ -58,7 +58,7 @@ JSTaggedValue BuiltinsSharedArrayBuffer::IsSharedArrayBuffer(EcmaRuntimeCallInfo } // 2. Let bufferData be obj.[[ArrayBufferData]]. JSHandle buffer(arg); - JSTaggedValue bufferdata = buffer->GetArrayBufferData(); + JSTaggedValue bufferdata = buffer->GetArrayBufferData(argv->GetThread()); // 3. If bufferData is null, return false. if (bufferdata.IsNull()) { return BuiltinsSharedArrayBuffer::GetTaggedBoolean(false); @@ -70,13 +70,13 @@ JSTaggedValue BuiltinsSharedArrayBuffer::IsSharedArrayBuffer(EcmaRuntimeCallInfo return BuiltinsSharedArrayBuffer::GetTaggedBoolean(true); } -bool BuiltinsSharedArrayBuffer::IsShared(JSTaggedValue arrayBuffer) +bool BuiltinsSharedArrayBuffer::IsShared(JSThread *thread, JSTaggedValue arrayBuffer) { if (!arrayBuffer.IsSharedArrayBuffer()) { return false; } JSArrayBuffer *buffer = JSArrayBuffer::Cast(arrayBuffer.GetTaggedObject()); - JSTaggedValue dataSlot = buffer->GetArrayBufferData(); + JSTaggedValue dataSlot = buffer->GetArrayBufferData(thread); // 2. If arrayBuffer’s [[ArrayBufferData]] internal slot is null, return false. if (dataSlot.IsNull()) { return false; @@ -167,7 +167,7 @@ JSTaggedValue BuiltinsSharedArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "don't have internal slot", JSTaggedValue::Exception()); } // 4. If IsSharedArrayBuffer(O) is false, throw a TypeError exception. - if (!IsShared(thisHandle.GetTaggedValue())) { + if (!IsShared(thread, thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value not IsSharedArrayBuffer", JSTaggedValue::Exception()); } // 5. Let len be the value of O’s [[ArrayBufferByteLength]] internal slot. @@ -222,11 +222,11 @@ JSTaggedValue BuiltinsSharedArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "don't have bufferdata internal slot", JSTaggedValue::Exception()); } // 18. If IsSharedArrayBuffer(new) is false, throw a TypeError exception. - if (!IsShared(newArrBuf.GetTaggedValue())) { + if (!IsShared(thread, newArrBuf.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "new arrayBuffer not IsSharedArrayBuffer", JSTaggedValue::Exception()); } // 19. If SameValue(new, O) is true, throw a TypeError exception. - if (JSTaggedValue::SameValue(newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "value of new arraybuffer and this is same", JSTaggedValue::Exception()); } JSHandle newJsShaArrBuf(newArrBuf); @@ -237,9 +237,9 @@ JSTaggedValue BuiltinsSharedArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) } if (newLen > 0) { // 23. Let fromBuf be the value of O’s [[ArrayBufferData]] internal slot. - JSTaggedValue from = shaArrBuf->GetArrayBufferData(); + JSTaggedValue from = shaArrBuf->GetArrayBufferData(thread); // 24. Let toBuf be the value of new’s [[ArrayBufferData]] internal slot. - JSTaggedValue to = newJsShaArrBuf->GetArrayBufferData(); + JSTaggedValue to = newJsShaArrBuf->GetArrayBufferData(thread); // 25. Perform CopyDataBlockBytes(toBuf, fromBuf, first, newLen). JSArrayBuffer::CopyDataBlockBytes(to, from, first, newLen); } diff --git a/ecmascript/builtins/builtins_sharedarraybuffer.h b/ecmascript/builtins/builtins_sharedarraybuffer.h index 48ce8d484c..52ec0c6c01 100644 --- a/ecmascript/builtins/builtins_sharedarraybuffer.h +++ b/ecmascript/builtins/builtins_sharedarraybuffer.h @@ -34,7 +34,7 @@ public: // 25.2.4.3 SharedArrayBuffer.prototype.slice ( start, end ) static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); - static bool IsShared(JSTaggedValue arrayBuffer); + static bool IsShared(JSThread *thread, JSTaggedValue arrayBuffer); private: // 25.2.1.1 AllocateSharedArrayBuffer ( constructor, byteLength ) static JSTaggedValue AllocateSharedArrayBuffer(JSThread *thread, const JSHandle &newTarget, diff --git a/ecmascript/builtins/builtins_string.cpp b/ecmascript/builtins/builtins_string.cpp index d163b527f6..7e56ddeebf 100644 --- a/ecmascript/builtins/builtins_string.cpp +++ b/ecmascript/builtins/builtins_string.cpp @@ -88,7 +88,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (EcmaStringAccessor::CanBeCompressed(&codePointValue, 1)) { JSHandle singleCharTable(thread, thread->GetSingleCharTable()); - return singleCharTable->GetStringFromSingleCharTable(codePointValue); + return singleCharTable->GetStringFromSingleCharTable(thread, codePointValue); } JSHandle strHandle = factory->NewFromUtf16Literal(&codePointValue, 1); return strHandle.GetTaggedValue(); @@ -192,7 +192,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); EcmaString *nextSeg = *JSTaggedValue::ToString(thread, elementString); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - u16str += EcmaStringAccessor(nextSeg).ToU16String(); + u16str += EcmaStringAccessor(nextSeg).ToU16String(thread); if (EcmaStringAccessor(nextSeg).IsUtf16()) { canBeCompress = false; } @@ -202,7 +202,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) if (argsI <= argc) { EcmaString *nextSub = *JSTaggedValue::ToString(thread, GetCallArg(argv, argsI)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - u16str += EcmaStringAccessor(nextSub).ToU16String(); + u16str += EcmaStringAccessor(nextSub).ToU16String(thread); if (EcmaStringAccessor(nextSub).IsUtf16()) { canBeCompress = false; } @@ -246,10 +246,10 @@ JSTaggedValue BuiltinsString::CharAt(EcmaRuntimeCallInfo *argv) if (pos < 0 || pos >= thisLen) { return factory->GetEmptyString().GetTaggedValue(); } - uint16_t res = EcmaStringAccessor(thisFlat).Get(pos); + uint16_t res = EcmaStringAccessor(thisFlat).Get(thread, pos); if (EcmaStringAccessor::CanBeCompressed(&res, 1)) { JSHandle singleCharTable(thread, thread->GetSingleCharTable()); - return singleCharTable->GetStringFromSingleCharTable(res); + return singleCharTable->GetStringFromSingleCharTable(thread, res); } return factory->NewFromUtf16Literal(&res, 1).GetTaggedValue(); } @@ -285,7 +285,7 @@ JSTaggedValue BuiltinsString::CharCodeAt(EcmaRuntimeCallInfo *argv) if (pos < 0 || pos >= thisLen) { return GetTaggedDouble(base::NAN_VALUE); } - uint16_t ret = EcmaStringAccessor(thisFlat).Get(pos); + uint16_t ret = EcmaStringAccessor(thisFlat).Get(thread, pos); return GetTaggedInt(ret); } @@ -310,11 +310,11 @@ JSTaggedValue BuiltinsString::CodePointAt(EcmaRuntimeCallInfo *argv) if (pos < 0 || pos >= thisLen) { return JSTaggedValue::Undefined(); } - uint16_t first = EcmaStringAccessor(thisFlat).Get(pos); + uint16_t first = EcmaStringAccessor(thisFlat).Get(thread, pos); if (first < base::utf_helper::DECODE_LEAD_LOW || first > base::utf_helper::DECODE_LEAD_HIGH || pos + 1 == thisLen) { return GetTaggedInt(first); } - uint16_t second = EcmaStringAccessor(thisFlat).Get(pos + 1); + uint16_t second = EcmaStringAccessor(thisFlat).Get(thread, pos + 1); if (second < base::utf_helper::DECODE_TRAIL_LOW || second > base::utf_helper::DECODE_TRAIL_HIGH) { return GetTaggedInt(first); } @@ -556,8 +556,8 @@ JSTaggedValue BuiltinsString::DoLocaleCompare(JSThread *thread, LOG_ECMA(ERROR) << "BuiltinsString::LocaleCompare:collator is nullptr"; } ASSERT(collator != nullptr); - auto result = collator->Compare(EcmaStringAccessor(thisHandle).ToStdString(), - EcmaStringAccessor(thatHandle).ToStdString()); + auto result = collator->Compare(EcmaStringAccessor(thisHandle).ToStdString(thread), + EcmaStringAccessor(thatHandle).ToStdString(thread)); return JSTaggedValue(result); #endif #endif @@ -584,7 +584,7 @@ JSTaggedValue BuiltinsString::LocaleCompareGC(JSThread *thread, icuCollator = JSCollator::GetCachedIcuCollator(thread, locales); ASSERT(icuCollator != nullptr); } else { - icuCollator = initCollator->GetIcuCollator(); + icuCollator = initCollator->GetIcuCollator(thread); } JSTaggedValue result = JSCollator::CompareStrings(thread, icuCollator, thisHandle, thatHandle, csOption); return result; @@ -737,7 +737,7 @@ JSTaggedValue BuiltinsString::IsWellFormed(EcmaRuntimeCallInfo *argv) uint32_t position = 0; while (position < size) { // i.Let first be the code unit at index position within string. - uint16_t first = EcmaStringAccessor(string).Get(position); + uint16_t first = EcmaStringAccessor(string).Get(thread, position); uint32_t cp = first - CHAR16_LETTER_NULL; uint8_t codeUnitCount = 0; bool isUnpairedSurrogate = false; @@ -753,7 +753,7 @@ JSTaggedValue BuiltinsString::IsWellFormed(EcmaRuntimeCallInfo *argv) isUnpairedSurrogate = true; } else { // iv. Let second be the code unit at index position + 1 within string. - uint16_t second = EcmaStringAccessor(string).Get(position + 1); + uint16_t second = EcmaStringAccessor(string).Get(thread, position + 1); // v. If second is not a trailing surrogate, then // a. Return the Record { [[CodePoint]]: cp, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: true }. if (!IsUTF16LowSurrogate(second)) { @@ -810,7 +810,7 @@ JSTaggedValue BuiltinsString::ToWellFormed(EcmaRuntimeCallInfo *argv) // d. Set k to k + cp.[[CodeUnitCount]]. while (position < size) { // i.Let first be the code unit at index position within string. - uint16_t first = EcmaStringAccessor(string).Get(position); + uint16_t first = EcmaStringAccessor(string).Get(thread, position); uint32_t cp = first - CHAR16_LETTER_NULL; uint8_t codeUnitCount = 0; bool isUnpairedSurrogate = false; @@ -826,7 +826,7 @@ JSTaggedValue BuiltinsString::ToWellFormed(EcmaRuntimeCallInfo *argv) isUnpairedSurrogate = true; } else { // iv. Let second be the code unit at index position + 1 within string. - uint16_t second = EcmaStringAccessor(string).Get(position + 1); + uint16_t second = EcmaStringAccessor(string).Get(thread, position + 1); // v. If second is not a trailing surrogate, then // a. Return the Record { [[CodePoint]]: cp, [[CodeUnitCount]]: 1, [[IsUnpairedSurrogate]]: true }. if (!IsUTF16LowSurrogate(second)) { @@ -928,7 +928,7 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv) THROW_RANGE_ERROR_AND_RETURN(thread, "compare not equal", JSTaggedValue::Exception()); } - std::u16string u16strThis = EcmaStringAccessor(thisHandle).ToU16String(); + std::u16string u16strThis = EcmaStringAccessor(thisHandle).ToU16String(thread); const char16_t *constChar16tData = u16strThis.data(); icu::UnicodeString src(constChar16tData, u16strThis.size()); icu::UnicodeString res; @@ -995,7 +995,7 @@ JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv) bool isUtf8 = EcmaStringAccessor(thisHandle).IsUtf8(); EcmaString *result = EcmaStringAccessor::CreateLineString(thread->GetEcmaVM(), thisLen * count, isUtf8); for (uint32_t index = 0; index < static_cast(count); ++index) { - EcmaStringAccessor::ReadData(result, *thisHandle, index * thisLen, (count - index) * thisLen, thisLen); + EcmaStringAccessor::ReadData(thread, result, *thisHandle, index * thisLen, (count - index) * thisLen, thisLen); } return JSTaggedValue(result); } @@ -1021,8 +1021,8 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) if (searchTag->IsJSRegExp() && replaceTag->IsString()) { JSHandle cacheTable(env->GetRegExpCache()); JSHandle re(searchTag); - JSHandle pattern(thread, re->GetOriginalSource()); - JSHandle flags(thread, re->GetOriginalFlags()); + JSHandle pattern(thread, re->GetOriginalSource(thread)); + JSHandle flags(thread, re->GetOriginalFlags(thread)); bool isFastPath = BuiltinsRegExp::IsFastRegExp(thread, searchTag.GetTaggedValue()); if (isFastPath) { uint32_t lastIndex = static_cast(BuiltinsRegExp::GetLastIndex(thread, searchTag, true)); @@ -1036,7 +1036,7 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) } if (searchTag->IsJSRegExp() && !env->GetRegExpReplaceDetector()) { - JSTaggedValue proto = JSObject::GetPrototype(JSHandle(searchTag)); + JSTaggedValue proto = JSObject::GetPrototype(thread, JSHandle(searchTag)); if (proto == env->GetTaggedRegExpPrototype()) { return BuiltinsRegExp::ReplaceInternal(thread, searchTag, thisTag, replaceTag); } @@ -1264,9 +1264,10 @@ JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) } // Handle $& - match case -void ProcessDollarAmpersand(std::u16string &stringBuilder, const JSHandle &matched, bool &canBeCompress) +void ProcessDollarAmpersand(EcmaVM *ecmaVm, std::u16string &stringBuilder, const JSHandle &matched, + bool &canBeCompress) { - stringBuilder += EcmaStringAccessor(matched).ToU16String(); + stringBuilder += EcmaStringAccessor(matched).ToU16String(ecmaVm->GetJSThread()); if (EcmaStringAccessor(matched).IsUtf16()) { canBeCompress = false; } @@ -1278,7 +1279,7 @@ void ProcessDollarBacktick(EcmaVM *ecmaVm, std::u16string &stringBuilder, const { if (position > 0) { EcmaString *prefix = EcmaStringAccessor::FastSubString(ecmaVm, srcString, 0, position); - stringBuilder += EcmaStringAccessor(prefix).ToU16String(); + stringBuilder += EcmaStringAccessor(prefix).ToU16String(ecmaVm->GetJSThread()); if (EcmaStringAccessor(prefix).IsUtf16()) { canBeCompress = false; } @@ -1292,25 +1293,25 @@ void ProcessDollarSingleQuote(EcmaVM *ecmaVm, std::u16string &stringBuilder, con int32_t srcLength = static_cast(EcmaStringAccessor(srcString).GetLength()); if (tailPos < srcLength) { EcmaString *suffix = EcmaStringAccessor::FastSubString(ecmaVm, srcString, tailPos, srcLength - tailPos); - stringBuilder += EcmaStringAccessor(suffix).ToU16String(); + stringBuilder += EcmaStringAccessor(suffix).ToU16String(ecmaVm->GetJSThread()); if (EcmaStringAccessor(suffix).IsUtf16()) { canBeCompress = false; } } } -std::pair ProcessDigitCapture(const JSHandle &replacementFlat, uint32_t peekIndex, - uint32_t replaceLength, const JSHandle &captureList, - std::u16string &stringBuilder) +std::pair ProcessDigitCapture(JSThread *thread, const JSHandle &replacementFlat, + uint32_t peekIndex, uint32_t replaceLength, const JSHandle &captureList, + std::u16string &stringBuilder) { uint32_t capturesLength = captureList->GetLength(); - uint16_t peek = EcmaStringAccessor(replacementFlat).Get(peekIndex); + uint16_t peek = EcmaStringAccessor(replacementFlat).Get(thread, peekIndex); uint32_t scaledIndex = peek - '0'; int32_t advance = 1; bool canBeCompress = true; if (peekIndex + 1 < replaceLength) { - uint16_t nextPeek = EcmaStringAccessor(replacementFlat).Get(peekIndex + 1); + uint16_t nextPeek = EcmaStringAccessor(replacementFlat).Get(thread, peekIndex + 1); if (nextPeek >= '0' && nextPeek <= '9') { constexpr uint32_t TEN_BASE = 10; uint32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0'); @@ -1326,10 +1327,10 @@ std::pair ProcessDigitCapture(const JSHandle &replace return {peekIndex, canBeCompress}; // No change in compressibility, just return the next index. } - JSTaggedValue capturesVal(captureList->Get(scaledIndex - 1)); + JSTaggedValue capturesVal(captureList->Get(thread, scaledIndex - 1)); if (!capturesVal.IsUndefined()) { EcmaString *captureString = EcmaString::Cast(capturesVal.GetTaggedObject()); - stringBuilder += EcmaStringAccessor(captureString).ToU16String(); + stringBuilder += EcmaStringAccessor(captureString).ToU16String(thread); if (EcmaStringAccessor(captureString).IsUtf16()) { canBeCompress = false; } @@ -1363,7 +1364,7 @@ std::pair ProcessNamedCaptures(JSThread *thread, const JSHandle captureName = JSTaggedValue::ToString(thread, capture); - stringBuilder += EcmaStringAccessor(captureName).ToU16String(); + stringBuilder += EcmaStringAccessor(captureName).ToU16String(thread); if (EcmaStringAccessor(captureName).IsUtf16()) { canBeCompress = false; } @@ -1391,7 +1392,7 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle 0) { - stringBuilder = EcmaStringAccessor(replacementFlat).ToU16String(nextDollarIndex); + stringBuilder = EcmaStringAccessor(replacementFlat).ToU16String(thread, nextDollarIndex); if (EcmaStringAccessor(replacementFlat).IsUtf16()) { canBeCompress = false; } @@ -1408,14 +1409,14 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleNewFromUtf16LiteralNotCompress(uint16tData, stringBuilder.length()).GetTaggedValue(); } int continueFromIndex = -1; - uint16_t peek = EcmaStringAccessor(replacementFlat).Get(peekIndex); + uint16_t peek = EcmaStringAccessor(replacementFlat).Get(thread, peekIndex); switch (peek) { case '$': // $$ stringBuilder += '$'; continueFromIndex = peekIndex + 1; break; case '&': // $& - match - ProcessDollarAmpersand(stringBuilder, matched, canBeCompress); + ProcessDollarAmpersand(ecmaVm, stringBuilder, matched, canBeCompress); continueFromIndex = peekIndex + 1; break; case '`': // $` - prefix @@ -1438,7 +1439,7 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle continueFromIndex) { EcmaString *nextAppend = EcmaStringAccessor::FastSubString( ecmaVm, replacementFlat, continueFromIndex, nextDollarIndex - continueFromIndex); - stringBuilder += EcmaStringAccessor(nextAppend).ToU16String(); + stringBuilder += EcmaStringAccessor(nextAppend).ToU16String(thread); if (EcmaStringAccessor(nextAppend).IsUtf16()) { canBeCompress = false; } @@ -1902,12 +1903,12 @@ JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) // Else, Let requestedLocale be DefaultLocale(). JSHandle requestedLocale = intl::LocaleHelper::DefaultLocale(thread); if (requestedLocales->GetLength() != 0) { - requestedLocale = JSHandle(thread, requestedLocales->Get(0)); + requestedLocale = JSHandle(thread, requestedLocales->Get(thread, 0)); } // Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences // removed. - intl::LocaleHelper::ParsedLocale noExtensionsLocale = intl::LocaleHelper::HandleLocale(requestedLocale); + intl::LocaleHelper::ParsedLocale noExtensionsLocale = intl::LocaleHelper::HandleLocale(thread, requestedLocale); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let availableLocales be a List with language tags that includes the languages for which the Unicode Character @@ -1963,12 +1964,12 @@ JSTaggedValue BuiltinsString::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) // Else, Let requestedLocale be DefaultLocale(). JSHandle requestedLocale = intl::LocaleHelper::DefaultLocale(thread); if (requestedLocales->GetLength() != 0) { - requestedLocale = JSHandle(thread, requestedLocales->Get(0)); + requestedLocale = JSHandle(thread, requestedLocales->Get(thread, 0)); } // Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences // removed. - intl::LocaleHelper::ParsedLocale noExtensionsLocale = intl::LocaleHelper::HandleLocale(requestedLocale); + intl::LocaleHelper::ParsedLocale noExtensionsLocale = intl::LocaleHelper::HandleLocale(thread, requestedLocale); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let availableLocales be a List with language tags that includes the languages for which the Unicode Character @@ -2241,7 +2242,7 @@ JSTaggedValue BuiltinsString::ThisStringValue(JSThread *thread, JSTaggedValue va if (value.IsECMAObject()) { auto jshclass = value.GetTaggedObject()->GetClass(); if (jshclass->GetObjectType() == JSType::JS_PRIMITIVE_REF) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(value.GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value.GetTaggedObject())->GetValue(thread); if (primitive.IsString()) { return primitive; } @@ -2275,12 +2276,12 @@ JSTaggedValue BuiltinsString::Pad(EcmaRuntimeCallInfo *argv, bool isStart) } else { JSHandle filler = JSTaggedValue::ToString(thread, fillString); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - stringBuilder = EcmaStringAccessor(filler).ToU16String(); + stringBuilder = EcmaStringAccessor(filler).ToU16String(thread); } if (stringBuilder.size() == 0) { return thisHandle.GetTaggedValue(); } - std::u16string u16strSearch = EcmaStringAccessor(thisHandle).ToU16String(); + std::u16string u16strSearch = EcmaStringAccessor(thisHandle).ToU16String(thread); int64_t fillLen = intMaxLength - stringLength; int64_t len = static_cast(stringBuilder.length()); if (static_cast(intMaxLength) >= BaseString::MAX_STRING_LENGTH) { @@ -2316,14 +2317,14 @@ JSTaggedValue BuiltinsString::StringToList(JSThread *thread, JSHandle newArrayHandle(thread, newArray); JSHandle iteratedString(str); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle oldElements(thread, newArrayHandle->GetElements()); + JSHandle oldElements(thread, newArrayHandle->GetElements(thread)); uint32_t totalElements = EcmaStringAccessor(iteratedString).GetLength(); JSHandle elements = (oldElements->GetLength() < totalElements) ? factory->ExtendArray(oldElements, totalElements) : oldElements; uint32_t index = 0; newArrayHandle->SetElements(thread, elements); while (index < totalElements) { - uint16_t c = EcmaStringAccessor(iteratedString).Get(index); + uint16_t c = EcmaStringAccessor(iteratedString).Get(thread, index); JSHandle newStr = factory->NewFromUtf16Literal(&c, 1); ElementAccessor::Set(thread, newArrayHandle, index, newStr, true); index++; @@ -2351,7 +2352,7 @@ JSTaggedValue BuiltinsString::StringToSList(JSThread *thread, JSHandle newSharedArrayHandle(thread, newSharedArray); JSHandle iteratedString(str); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle oldElements(thread, newSharedArrayHandle->GetElements()); + JSHandle oldElements(thread, newSharedArrayHandle->GetElements(thread)); uint32_t totalElements = EcmaStringAccessor(iteratedString).GetLength(); JSHandle elements = (oldElements->GetLength() < totalElements) @@ -2360,7 +2361,7 @@ JSTaggedValue BuiltinsString::StringToSList(JSThread *thread, JSHandleSetElements(thread, elements); while (index < totalElements) { - uint16_t c = EcmaStringAccessor(iteratedString).Get(index); + uint16_t c = EcmaStringAccessor(iteratedString).Get(thread, index); JSHandle newStr = factory->NewFromUtf16Literal(&c, 1); ElementAccessor::Set(thread, newSharedArrayHandle, index, newStr, true); index++; @@ -2385,11 +2386,11 @@ JSTaggedValue StringSplitResultCache::FindCachedResult(const JSThread *thread, const JSHandle &cache, const JSHandle &thisString, const JSHandle &pattern) { - uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(); + uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(thread); uint32_t entry = hash & (CACHE_SIZE - 1); uint32_t index = entry * ENTRY_SIZE; - JSTaggedValue cacheThis = cache->Get(index + STRING_INDEX); - JSTaggedValue cachePattern = cache->Get(index + PATTERN_INDEX); + JSTaggedValue cacheThis = cache->Get(thread, index + STRING_INDEX); + JSTaggedValue cachePattern = cache->Get(thread, index + PATTERN_INDEX); if (!cacheThis.IsString() || !cachePattern.IsString()) { return JSTaggedValue::Undefined(); } @@ -2398,7 +2399,7 @@ JSTaggedValue StringSplitResultCache::FindCachedResult(const JSThread *thread, if (EcmaStringAccessor::StringsAreEqual(thread->GetEcmaVM(), thisString, cacheStringHandle) && EcmaStringAccessor::StringsAreEqual(thread->GetEcmaVM(), pattern, cachePatternHandle)) { - return cache->Get(index + ARRAY_INDEX); + return cache->Get(thread, index + ARRAY_INDEX); } return JSTaggedValue::Undefined(); } @@ -2412,9 +2413,9 @@ void StringSplitResultCache::SetCachedResult(const JSThread *thread, const JSHan ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle newElements(factory->NewCOWTaggedArray(arrayLength)); for (uint32_t i = 0; i < arrayLength; i++) { - newElements->Set(thread, i, resultArray->Get(i)); + newElements->Set(thread, i, resultArray->Get(thread, i)); } - uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(); + uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(thread); uint32_t entry = hash & (CACHE_SIZE - 1); uint32_t index = entry * ENTRY_SIZE; @@ -2449,16 +2450,16 @@ JSTaggedValue StringToListResultCache::FindCachedResult(const JSThread *thread, if (EcmaStringAccessor(thisString).GetLength() > MAX_STRING_LENGTH) { return JSTaggedValue::Undefined(); } - uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(); + uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(thread); uint32_t entry = hash & (CACHE_SIZE - 1); uint32_t index = entry * ENTRY_SIZE; - JSHandle cacheThis(thread, cache->Get(index + STRING_INDEX)); + JSHandle cacheThis(thread, cache->Get(thread, index + STRING_INDEX)); if (!cacheThis->IsString()) { return JSTaggedValue::Undefined(); } JSHandle cacheStr(cacheThis); if (EcmaStringAccessor::StringsAreEqual(thread->GetEcmaVM(), thisString, cacheStr)) { - return cache->Get(index + ARRAY_INDEX); + return cache->Get(thread, index + ARRAY_INDEX); } return JSTaggedValue::Undefined(); } @@ -2483,9 +2484,9 @@ void StringToListResultCache::SetCachedResult(const JSThread *thread, const JSHa newElements = JSHandle(factory->NewCOWTaggedArray(arrayLength)); } for (uint32_t i = 0; i < arrayLength; i++) { - newElements->Set(thread, i, resultArray->Get(i)); + newElements->Set(thread, i, resultArray->Get(thread, i)); } - uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(); + uint32_t hash = EcmaStringAccessor(thisString).GetHashcode(thread); uint32_t entry = hash & (CACHE_SIZE - 1); uint32_t index = entry * ENTRY_SIZE; cache->Set(thread, index + STRING_INDEX, thisString); diff --git a/ecmascript/builtins/builtins_string_iterator.cpp b/ecmascript/builtins/builtins_string_iterator.cpp index ab1eee5676..46bdb81da8 100644 --- a/ecmascript/builtins/builtins_string_iterator.cpp +++ b/ecmascript/builtins/builtins_string_iterator.cpp @@ -41,7 +41,7 @@ JSTaggedValue BuiltinsStringIterator::NextInternal(JSThread *thread, JSHandle string(thread, thisValue.GetObject()->GetIteratedString()); + JSHandle string(thread, thisValue.GetObject()->GetIteratedString(thread)); // 5. If s is undefined, return CreateIterResultObject(undefined, true). if (string->IsUndefined()) { return JSIterator::CreateIterResultObject(thread, string, true).GetTaggedValue(); @@ -61,7 +61,7 @@ JSTaggedValue BuiltinsStringIterator::NextInternal(JSThread *thread, JSHandle()).Get(position); + uint16_t first = EcmaStringAccessor(string.GetObject()).Get(thread, position); JSMutableHandle result(thread, JSTaggedValue::Undefined()); uint32_t resultSize = 1; // 10. If first < 0xD800 or first > 0xDBFF or position+1 = len, let resultString be the string consisting of the @@ -71,7 +71,7 @@ JSTaggedValue BuiltinsStringIterator::NextInternal(JSThread *thread, JSHandle base::utf_helper::DECODE_LEAD_HIGH) { if (EcmaStringAccessor::CanBeCompressed(&first, 1)) { JSHandle singleCharTable(thread, thread->GetSingleCharTable()); - result.Update(singleCharTable->GetStringFromSingleCharTable(first)); + result.Update(singleCharTable->GetStringFromSingleCharTable(thread, first)); } else { std::vector resultString {first, 0x0}; result.Update(factory->NewFromUtf16(resultString.data(), 1).GetTaggedValue()); @@ -82,7 +82,7 @@ JSTaggedValue BuiltinsStringIterator::NextInternal(JSThread *thread, JSHandle 0xDFFF, let resultString be the string consisting of the single code unit // first. // c. Else, let resultString be the string consisting of the code unit first followed by the code unit second. - uint16_t second = EcmaStringAccessor(string.GetObject()).Get(position + 1); + uint16_t second = EcmaStringAccessor(string.GetObject()).Get(thread, position + 1); if (second < base::utf_helper::DECODE_TRAIL_LOW || second > base::utf_helper::DECODE_TRAIL_HIGH) { std::vector resultString {first, 0x0}; result.Update(factory->NewFromUtf16NotCompress(resultString.data(), 1).GetTaggedValue()); diff --git a/ecmascript/builtins/builtins_symbol.cpp b/ecmascript/builtins/builtins_symbol.cpp index b061665a69..261005bafb 100644 --- a/ecmascript/builtins/builtins_symbol.cpp +++ b/ecmascript/builtins/builtins_symbol.cpp @@ -70,7 +70,7 @@ JSTaggedValue BuiltinsSymbol::ToString(EcmaRuntimeCallInfo *argv) // 2.If value is an Object and value has a [[SymbolData]] internal slot, then if (valueHandle->IsJSPrimitiveRef()) { // Let sym be the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(thread); if (primitive.IsSymbol()) { return SymbolDescriptiveString(thread, primitive); } @@ -89,14 +89,14 @@ JSTaggedValue BuiltinsSymbol::SymbolDescriptiveString(JSThread *thread, JSTagged // Let desc be sym’s [[Description]] value. auto symbolObject = reinterpret_cast(sym.GetTaggedObject()); - JSHandle descHandle(thread, symbolObject->GetDescription()); + JSHandle descHandle(thread, symbolObject->GetDescription(thread)); // If desc is undefined, let desc be the empty string. JSHandle singleCharTable(thread, thread->GetSingleCharTable()); auto constants = thread->GlobalConstants(); if (descHandle->IsUndefined()) { JSHandle leftHandle = JSHandle::Cast(constants->GetHandledSymbolLeftParentheses()); - JSHandle rightHandle(thread, singleCharTable->GetStringFromSingleCharTable(')')); + JSHandle rightHandle(thread, singleCharTable->GetStringFromSingleCharTable(thread, ')')); JSHandle str = factory->ConcatFromString(leftHandle, rightHandle); return str.GetTaggedValue(); } @@ -104,7 +104,7 @@ JSTaggedValue BuiltinsSymbol::SymbolDescriptiveString(JSThread *thread, JSTagged ASSERT(descHandle->IsString()); // Return the result of concatenating the strings "Symbol(", desc, and ")". JSHandle leftHandle = JSHandle::Cast(constants->GetHandledSymbolLeftParentheses()); - JSHandle rightHandle(thread, singleCharTable->GetStringFromSingleCharTable(')')); + JSHandle rightHandle(thread, singleCharTable->GetStringFromSingleCharTable(thread, ')')); JSHandle stringLeft = factory->ConcatFromString(leftHandle, JSTaggedValue::ToString(thread, descHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -129,7 +129,7 @@ JSTaggedValue BuiltinsSymbol::ValueOf(EcmaRuntimeCallInfo *argv) // 2.If value is an Object and value has a [[SymbolData]] internal slot, then if (valueHandle->IsJSPrimitiveRef()) { // Let sym be the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(thread); if (primitive.IsSymbol()) { return primitive; } @@ -182,7 +182,7 @@ JSTaggedValue BuiltinsSymbol::KeyFor(EcmaRuntimeCallInfo *argv) // 4.Return undefined. JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); auto *table = env->GetRegisterSymbols().GetObject(); - JSTaggedValue key = table->FindSymbol(sym.GetTaggedValue()); + JSTaggedValue key = table->FindSymbol(thread, sym.GetTaggedValue()); if (key.IsUndefined()) { return JSTaggedValue::Undefined(); } @@ -206,7 +206,7 @@ JSTaggedValue BuiltinsSymbol::ToPrimitive(EcmaRuntimeCallInfo *argv) // 2.If value is an Object and value has a [[SymbolData]] internal slot, then if (sym->IsJSPrimitiveRef()) { // Let sym be the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitive = JSPrimitiveRef::Cast(sym->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(sym->GetTaggedObject())->GetValue(thread); if (primitive.IsSymbol()) { return primitive; } @@ -232,16 +232,16 @@ JSTaggedValue BuiltinsSymbol::ThisSymbolValue(JSThread *thread, const JSHandleIsSymbol()) { - JSTaggedValue desValue = JSSymbol::Cast(value->GetTaggedObject())->GetDescription(); + JSTaggedValue desValue = JSSymbol::Cast(value->GetTaggedObject())->GetDescription(thread); return desValue; } // If s does not have a [[SymbolData]] internal slot, throw a TypeError exception. if (value->IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(thread); if (primitive.IsSymbol()) { // Return the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitiveDesValue = JSSymbol::Cast(primitive.GetTaggedObject())->GetDescription(); + JSTaggedValue primitiveDesValue = JSSymbol::Cast(primitive.GetTaggedObject())->GetDescription(thread); return primitiveDesValue; } } diff --git a/ecmascript/builtins/builtins_typedarray.cpp b/ecmascript/builtins/builtins_typedarray.cpp index d090a7e444..83a181766c 100644 --- a/ecmascript/builtins/builtins_typedarray.cpp +++ b/ecmascript/builtins/builtins_typedarray.cpp @@ -413,9 +413,9 @@ JSTaggedValue BuiltinsTypedArray::GetByteLength(EcmaRuntimeCallInfo *argv) } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSHandle typeArrayObj = JSHandle::Cast(thisHandle); - JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(thread); // 5. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue(0); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. @@ -443,9 +443,9 @@ JSTaggedValue BuiltinsTypedArray::GetByteOffset(EcmaRuntimeCallInfo *argv) } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSHandle typeArrayObj = JSHandle::Cast(thisHandle); - JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typeArrayObj->GetViewedArrayBufferOrByteArray(thread); // 5. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue(0); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. @@ -724,7 +724,7 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle ntKey(thread, JSTaggedValue::Undefined()); for (int32_t n = 0; n < captured; n++) { - valueHandle.Update(kept->Get(n)); + valueHandle.Update(kept->Get(thread, n)); ntKey.Update(JSTaggedValue(n)); ObjectFastOperator::FastSetPropertyByValue(thread, newArrObj.GetTaggedValue(), ntKey.GetTaggedValue(), valueHandle.GetTaggedValue()); @@ -859,7 +859,7 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv) } if (EcmaStringAccessor(sepStringHandle).IsUtf8() && EcmaStringAccessor(sepStringHandle).GetLength() == 1) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sep = EcmaStringAccessor(sepStringHandle).Get(0); + sep = EcmaStringAccessor(sepStringHandle).Get(thread, 0); } else if (EcmaStringAccessor(sepStringHandle).GetLength() == 0) { sep = BuiltinsTypedArray::SeparatorFlag::MINUS_TWO; sepLength = 0; @@ -914,14 +914,14 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv) if (sep >= 0) { EcmaStringAccessor(newString).Set(current, static_cast(sep)); } else if (sep != BuiltinsTypedArray::SeparatorFlag::MINUS_TWO) { - EcmaStringAccessor::ReadData( + EcmaStringAccessor::ReadData(thread, newString, *sepStringHandle, current, allocateLength - static_cast(current), sepLength); } current += static_cast(sepLength); } JSHandle nextStr = vec[k]; int nextLength = static_cast(EcmaStringAccessor(nextStr).GetLength()); - EcmaStringAccessor::ReadData(newString, *nextStr, current, + EcmaStringAccessor::ReadData(thread, newString, *nextStr, current, allocateLength - static_cast(current), nextLength); current += nextLength; } @@ -981,9 +981,9 @@ JSTaggedValue BuiltinsTypedArray::GetLength(EcmaRuntimeCallInfo *argv) } // 4. Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots. // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBufferOrByteArray(thread); // 6. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue(0); } // 7. Let length be the value of O’s [[ArrayLength]] internal slot. @@ -1191,9 +1191,9 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) } } // 9. Let targetBuffer be the value of target’s [[ViewedArrayBuffer]] internal slot. - JSHandle targetBuffer(thread, targetObj->GetViewedArrayBufferOrByteArray()); + JSHandle targetBuffer(thread, targetObj->GetViewedArrayBufferOrByteArray(thread)); // 10. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -1214,7 +1214,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) if (argArray->IsStableJSArray(thread)) { uint32_t length = JSHandle::Cast(argArray)->GetArrayLength(); JSHandle argObj(argArray); - uint32_t elemLength = ElementAccessor::GetElementsLength(argObj); + uint32_t elemLength = ElementAccessor::GetElementsLength(thread, argObj); // Load On Demand check if (elemLength >= length) { return JSStableArray::FastCopyFromArrayToTypedArray(thread, targetObj, targetType, @@ -1270,7 +1270,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) kValue.Update(ObjectFastOperator::FastGetPropertyByValue( thread, JSHandle::Cast(src).GetTaggedValue(), kKey.GetTaggedValue())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (BuiltinsArrayBuffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -1294,9 +1294,9 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) JSHandle typedArray(argArray); // 12. Let srcBuffer be the value of typedArray’s [[ViewedArrayBuffer]] internal slot. // 13. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSTaggedValue srcBuffer = typedArray->GetViewedArrayBufferOrByteArray(); + JSTaggedValue srcBuffer = typedArray->GetViewedArrayBufferOrByteArray(thread); JSHandle srcBufferHandle(thread, srcBuffer); - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcBuffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcBuffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of typedArray is detached buffer.", JSTaggedValue::Exception()); } @@ -1313,7 +1313,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 20. Let srcElementSize be the Number value of the Element Size value specified in Table 49 for srcName. // 21. Let srcLength be the value of typedArray’s [[ArrayLength]] internal slot. // 22. Let srcByteOffset be the value of typedArray’s [[ByteOffset]] internal slot. - JSHandle srcName(thread, typedArray->GetTypedArrayName()); + JSHandle srcName(thread, typedArray->GetTypedArrayName(thread)); DataViewType srcType = JSTypedArray::GetTypeFromName(thread, srcName); uint32_t srcElementSize = TypedArrayHelper::GetSizeFromType(srcType); uint32_t srcLength = typedArray->GetArrayLength(); @@ -1331,7 +1331,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // d. Let srcByteIndex be 0. // 25. Else, let srcByteIndex be srcByteOffset. uint32_t srcByteIndex = 0; - if (JSTaggedValue::SameValue(srcBufferHandle.GetTaggedValue(), targetBuffer.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, srcBufferHandle.GetTaggedValue(), targetBuffer.GetTaggedValue())) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); srcBuffer = BuiltinsArrayBuffer::CloneArrayBuffer(thread, targetBuffer, srcByteOffset, env->GetArrayBufferFunction()); @@ -1378,8 +1378,10 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // ii. Perform SetValueInBuffer (targetBuffer, targetByteIndex, "Uint8", value). // iii. Set srcByteIndex to srcByteIndex + 1. // iv. Set targetByteIndex to targetByteIndex + 1. - void *srcBuf = BuiltinsArrayBuffer::GetDataPointFromBuffer(srcBufferHandle.GetTaggedValue(), srcByteIndex); - void *targetBuf = BuiltinsArrayBuffer::GetDataPointFromBuffer(targetBuffer.GetTaggedValue(), targetByteIndex); + void *srcBuf = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcBufferHandle.GetTaggedValue(), + srcByteIndex); + void *targetBuf = BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, targetBuffer.GetTaggedValue(), + targetByteIndex); if (memcpy_s(targetBuf, srcLength * srcElementSize, srcBuf, srcLength * srcElementSize) != EOK) { LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); @@ -1440,11 +1442,11 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 17. Let srcName be the String value of O’s [[TypedArrayName]] internal slot. // 18. Let srcType be the String value of the Element Type value in Table 49 for srcName. - JSHandle srcName(thread, thisObj->GetTypedArrayName()); + JSHandle srcName(thread, thisObj->GetTypedArrayName(thread)); DataViewType srcType = JSTypedArray::GetTypeFromName(thread, srcName); // 19. Let targetName be the String value of A’s [[TypedArrayName]] internal slot. // 20. Let targetType be the String value of the Element Type value in Table 49 for targetName. - JSHandle targetName(thread, JSTypedArray::Cast(*newArrObj)->GetTypedArrayName()); + JSHandle targetName(thread, JSTypedArray::Cast(*newArrObj)->GetTypedArrayName(thread)); DataViewType targetType = JSTypedArray::GetTypeFromName(thread, targetName); // 21. If SameValue(srcType, targetType) is false, then // a. Let n be 0. @@ -1477,17 +1479,17 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) // 22. Else if count > 0, // a. Let srcBuffer be the value of O’s [[ViewedArrayBuffer]] internal slot. // b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSTaggedValue srcBuffer = thisObj->GetViewedArrayBufferOrByteArray(); - if (!srcBuffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(srcBuffer)) { + JSTaggedValue srcBuffer = thisObj->GetViewedArrayBufferOrByteArray(thread); + if (!srcBuffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcBuffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of this value is detached buffer.", JSTaggedValue::Exception()); } - if (srcBuffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(srcBuffer)) { + if (srcBuffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, srcBuffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The SendableArrayBuffer of this value is detached sendable buffer.", JSTaggedValue::Exception()); } // c. Let targetBuffer be the value of A’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue targetBuffer = JSTypedArray::Cast(*newArrObj)->GetViewedArrayBufferOrByteArray(); + JSTaggedValue targetBuffer = JSTypedArray::Cast(*newArrObj)->GetViewedArrayBufferOrByteArray(thread); // d. Let elementSize be the Number value of the Element Size value specified in Table 49 for srcType. uint32_t elementSize = TypedArrayHelper::GetSizeFromType(srcType); // e. NOTE: If srcType and targetType are the same the transfer must be performed in a manner that @@ -1503,8 +1505,9 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) // ii. Perform SetValueInBuffer (targetBuffer, targetByteIndex, "Uint8", value). // iii. Increase srcByteIndex by 1. // iv. Increase targetByteIndex by 1. - uint8_t *srcBuf = (uint8_t *)BuiltinsArrayBuffer::GetDataPointFromBuffer(srcBuffer, srcByteIndex); - uint8_t *targetBuf = (uint8_t *)BuiltinsArrayBuffer::GetDataPointFromBuffer(targetBuffer, targetByteIndex); + uint8_t *srcBuf = (uint8_t *)BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcBuffer, srcByteIndex); + uint8_t *targetBuf = + (uint8_t *)BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, targetBuffer, targetByteIndex); if (srcBuffer != targetBuffer && memmove_s( targetBuf, elementSize * count, srcBuf, elementSize * count) != EOK) { LOG_FULL(FATAL) << "memcpy_s failed"; @@ -1716,7 +1719,7 @@ JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) // 15. Let elementSize be the Number value of the Element Size value specified in Table 49 for constructorName. // 16. Let srcByteOffset be the value of O’s [[ByteOffset]] internal slot. // 17. Let beginByteOffset be srcByteOffset + beginIndex × elementSize. - JSHandle constructorName(thread, thisObj->GetTypedArrayName()); + JSHandle constructorName(thread, thisObj->GetTypedArrayName(thread)); DataViewType elementType = JSTypedArray::GetTypeFromName(thread, constructorName); uint32_t elementSize = TypedArrayHelper::GetSizeFromType(elementType); uint32_t srcByteOffset = thisObj->GetByteOffset(); @@ -1798,7 +1801,7 @@ JSTaggedValue BuiltinsTypedArray::ToStringTag(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } // 4. Let name be the value of O’s [[TypedArrayName]] internal slot. - JSTaggedValue name = JSHandle::Cast(thisHandle)->GetTypedArrayName(); + JSTaggedValue name = JSHandle::Cast(thisHandle)->GetTypedArrayName(thread); // 5. Assert: name is a String value. ASSERT(name.IsString()); // 6. Return name. @@ -1972,7 +1975,7 @@ JSTaggedValue BuiltinsTypedArray::With(EcmaRuntimeCallInfo* argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If IsValidIntegerIndex(O, 𝔽(actualIndex)) is false, throw a RangeError exception. - if (!JSTypedArray::IsValidIntegerIndex(thisHandle, JSTaggedValue(actualIndex))) { + if (!JSTypedArray::IsValidIntegerIndex(thread, thisHandle, JSTaggedValue(actualIndex))) { THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid typed array index", JSTaggedValue::Exception()); } diff --git a/ecmascript/builtins/shared_builtins.cpp b/ecmascript/builtins/shared_builtins.cpp index 13750f61d9..142965587d 100644 --- a/ecmascript/builtins/shared_builtins.cpp +++ b/ecmascript/builtins/shared_builtins.cpp @@ -845,7 +845,7 @@ void Builtins::InitializeSCtor(const JSHandle &protoHClass, const JSHa { SetSFunctionLength(ctor, length); SetSFunctionName(ctor, name); - SetSFunctionPrototype(ctor, protoHClass->GetProto()); + SetSFunctionPrototype(ctor, protoHClass->GetProto(thread_)); ctor->SetProtoOrHClass(thread_, protoHClass); } @@ -946,7 +946,7 @@ DETECTOR_SYMBOL_LIST(INIT_SYMBOL_STRING) JSHandle key##Symbol = factory_->NewSEmptySymbol(); \ JSHandle key##String = factory_->NewFromUtf8ReadOnly(description); \ key##Symbol->SetDescription(thread_, key##String.GetTaggedValue()); \ - key##Symbol->SetHashField(SymbolTable::Hash(key##String.GetTaggedValue())); + key##Symbol->SetHashField(SymbolTable::Hash(thread_, key##String.GetTaggedValue())); DETECTOR_SYMBOL_LIST(INIT_PUBLIC_SYMBOL) #undef INIT_PUBLIC_SYMBOL diff --git a/ecmascript/builtins/tests/builtins_array_test.cpp b/ecmascript/builtins/tests/builtins_array_test.cpp index 9d9b57a0d6..2b1d93a226 100644 --- a/ecmascript/builtins/tests/builtins_array_test.cpp +++ b/ecmascript/builtins/tests/builtins_array_test.cpp @@ -811,7 +811,7 @@ HWTEST_F_L0(BuiltinsArrayTest, ForEach) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); \ JSTaggedValue result = Array::method(ecmaRuntimeCallInfo); \ TestHelper::TearDownFrame(thread, prev); \ - ASSERT_TRUE(JSTaggedValue::StrictEqual(result, JSTaggedValue(expected))); \ + ASSERT_TRUE(JSTaggedValue::StrictEqual(thread, result, JSTaggedValue(expected))); \ } while (false) #define ARRAY_BUILTIN_METHOD_TEST_CASE_ARG1(method, target, expected, arg0) \ @@ -824,7 +824,7 @@ HWTEST_F_L0(BuiltinsArrayTest, ForEach) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); \ JSTaggedValue result = Array::method(ecmaRuntimeCallInfo); \ TestHelper::TearDownFrame(thread, prev); \ - ASSERT_TRUE(JSTaggedValue::StrictEqual(result, JSTaggedValue(expected))); \ + ASSERT_TRUE(JSTaggedValue::StrictEqual(thread, result, JSTaggedValue(expected))); \ } while (false) #define ARRAY_BUILTIN_METHOD_TEST_CASE_ARG2(method, target, expected, arg0, arg1) \ @@ -838,7 +838,7 @@ HWTEST_F_L0(BuiltinsArrayTest, ForEach) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); \ JSTaggedValue result = Array::method(ecmaRuntimeCallInfo); \ TestHelper::TearDownFrame(thread, prev); \ - ASSERT_TRUE(JSTaggedValue::StrictEqual(result, JSTaggedValue(expected))); \ + ASSERT_TRUE(JSTaggedValue::StrictEqual(thread, result, JSTaggedValue(expected))); \ } while (false) // 22.1.3.11 Array.IndexOf(searchElement [ , fromIndex ]) diff --git a/ecmascript/builtins/tests/builtins_bigint_test.cpp b/ecmascript/builtins/tests/builtins_bigint_test.cpp index 4216808873..0ef0d77771 100644 --- a/ecmascript/builtins/tests/builtins_bigint_test.cpp +++ b/ecmascript/builtins/tests/builtins_bigint_test.cpp @@ -208,7 +208,7 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToLocaleString_002) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle(thread, result2); - EXPECT_STREQ("123.456.789.123.456.789,00 €", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("123.456.789.123.456.789,00 €", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } // 17.ToStirng() @@ -226,7 +226,7 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_001) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle(thread, result2); - EXPECT_STREQ("17", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("17", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } // -0.ToStirng() @@ -244,7 +244,7 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_002) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle(thread, result2); - EXPECT_STREQ("0", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("0", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } // -10.ToStirng(2) @@ -263,7 +263,7 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_003) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle(thread, result2); - EXPECT_STREQ("-1010", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("-1010", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } // 254.ToStirng(16) @@ -282,7 +282,7 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_004) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle(thread, result2); - EXPECT_STREQ("fe", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("fe", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } // BigInt.ValueOf diff --git a/ecmascript/builtins/tests/builtins_boolean_test.cpp b/ecmascript/builtins/tests/builtins_boolean_test.cpp index 9c592c808f..30582995c5 100644 --- a/ecmascript/builtins/tests/builtins_boolean_test.cpp +++ b/ecmascript/builtins/tests/builtins_boolean_test.cpp @@ -50,7 +50,7 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanConstructor) JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); - ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsTrue(), 1); + ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue(thread).IsTrue(), 1); } // new Boolean(undefined) @@ -70,7 +70,7 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanConstructor1) JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); - ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsFalse(), 1); + ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue(thread).IsFalse(), 1); } // Boolean("helloworld") diff --git a/ecmascript/builtins/tests/builtins_collator_test.cpp b/ecmascript/builtins/tests/builtins_collator_test.cpp index 40e633dfc9..4294dddd20 100644 --- a/ecmascript/builtins/tests/builtins_collator_test.cpp +++ b/ecmascript/builtins/tests/builtins_collator_test.cpp @@ -196,9 +196,9 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_001) JSHandle resultArr = JSHandle(thread, JSTaggedValue(static_cast(result2.GetRawData()))); - EXPECT_EQ(JSTaggedValue::SameValue(JSArray::GetProperty(thread, resultArr, key0).GetValue(), value1), true); - EXPECT_EQ(JSTaggedValue::SameValue(JSArray::GetProperty(thread, resultArr, key1).GetValue(), value2), true); - EXPECT_EQ(JSTaggedValue::SameValue(JSArray::GetProperty(thread, resultArr, key2).GetValue(), value0), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSArray::GetProperty(thread, resultArr, key0).GetValue(), value1), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSArray::GetProperty(thread, resultArr, key1).GetValue(), value2), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSArray::GetProperty(thread, resultArr, key2).GetValue(), value0), true); } // // compare with sort(sv) @@ -285,15 +285,16 @@ HWTEST_F_L0(BuiltinsCollatorTest, ResolvedOptions) JSHandle(thread, JSTaggedValue(static_cast(result.GetRawData()))); // judge whether the properties of the object are the same as those of jscollator tag JSHandle localeKey = globalConst->GetHandledLocaleString(); - EXPECT_EQ(JSTaggedValue::SameValue(JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), locale), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), locale), + true); JSHandle usageKey = globalConst->GetHandledUsageString(); JSHandle defaultUsageValue(factory->NewFromASCII("sort")); EXPECT_EQ( - JSTaggedValue::SameValue(JSObject::GetProperty(thread, resultObj, usageKey).GetValue(), defaultUsageValue), + JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, usageKey).GetValue(), defaultUsageValue), true); JSHandle handledCaseFirstKey = globalConst->GetHandledCaseFirstString(); JSHandle handledCaseFirstValue(factory->NewFromASCII("upper")); - EXPECT_EQ(JSTaggedValue::SameValue(JSObject::GetProperty(thread, resultObj, handledCaseFirstKey).GetValue(), + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, handledCaseFirstKey).GetValue(), handledCaseFirstValue), true); } @@ -314,9 +315,9 @@ HWTEST_F_L0(BuiltinsCollatorTest, SupportedLocalesOf) auto resultArr = CollatorAlgorithm(thread, vals, 8, AlgorithmType::COLLATOR_SUPPORTED_LOCALES_OF); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_date_test.cpp b/ecmascript/builtins/tests/builtins_date_test.cpp index a63897aeb4..51dd1ca377 100644 --- a/ecmascript/builtins/tests/builtins_date_test.cpp +++ b/ecmascript/builtins/tests/builtins_date_test.cpp @@ -652,7 +652,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToDateString) TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result.GetRawData()), *expect_value)); } @@ -665,7 +665,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToISOString) std::vector args{}; auto result1 = DateAlgorithm(thread, jsDate.GetTaggedValue(), args, 4, AlgorithmType::ALGORITHM_TO_ISO_STRING); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -679,7 +679,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToISOStringMinus) std::vector args{}; auto result1 = DateAlgorithm(thread, jsDate.GetTaggedValue(), args, 4, AlgorithmType::ALGORITHM_TO_ISO_STRING); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -699,7 +699,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToJSON) JSTaggedValue result1 = BuiltinsDate::ToJSON(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result1.GetRawData()), *expect_value)); // number double infinite @@ -727,15 +727,15 @@ HWTEST_F_L0(BuiltinsDateTest, ToJSONMinus) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result1 = BuiltinsDate::ToJSON(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result1.GetRawData()), *expect_value)); } -CString GetLocalTime(JSHandle& jsDate) +CString GetLocalTime(JSThread *thread, JSHandle& jsDate) { CString localTime; int localMin = 0; - localMin = GetLocalOffsetFromOS(static_cast((*jsDate)->GetTimeValue().GetDouble()), true); + localMin = GetLocalOffsetFromOS(static_cast((*jsDate)->GetTimeValue(thread).GetDouble()), true); if (localMin >= 0) { localTime += PLUS; } else if (localMin < 0) { @@ -756,9 +756,9 @@ void ToStringCommon(JSThread* thread, CString& str1, CString& str2, CString& str ASSERT_TRUE(result1.IsString()); JSHandle result1_val(thread, reinterpret_cast(result1.GetRawData())); - CString str = str1 + GetLocalTime(jsDate); + CString str = str1 + GetLocalTime(thread, jsDate); JSHandle str_handle = thread->GetEcmaVM()->GetFactory()->NewFromASCII(str); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*result1_val, *str_handle)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *result1_val, *str_handle)); JSHandle js_date1 = JSDateCreateTest(thread); SetAll1(thread, js_date1); @@ -766,18 +766,18 @@ void ToStringCommon(JSThread* thread, CString& str1, CString& str2, CString& str JSTaggedValue result2 = DateAlgorithm(thread, js_date1.GetTaggedValue(), argTags, 4, type); ASSERT_TRUE(result2.IsString()); JSHandle result2_val(thread, reinterpret_cast(result2.GetRawData())); - str = str2 + GetLocalTime(js_date1); + str = str2 + GetLocalTime(thread, js_date1); str_handle = thread->GetEcmaVM()->GetFactory()->NewFromASCII(str); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*result2_val, *str_handle)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *result2_val, *str_handle)); JSHandle js_date2 = JSDateCreateTest(thread); SetAll2(thread, js_date2); JSTaggedValue result3 = DateAlgorithm(thread, js_date2.GetTaggedValue(), argTags, 4, type); ASSERT_TRUE(result3.IsString()); JSHandle result3_val(thread, reinterpret_cast(result3.GetRawData())); - str = str3 + GetLocalTime(js_date2); + str = str3 + GetLocalTime(thread, js_date2); str_handle = thread->GetEcmaVM()->GetFactory()->NewFromASCII(str); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*result3_val, *str_handle)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *result3_val, *str_handle)); } HWTEST_F_L0(BuiltinsDateTest, ToString) @@ -809,7 +809,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToUTCString) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -826,7 +826,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToUTCStringMinus) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -996,7 +996,7 @@ HWTEST_F_L0(BuiltinsDateTest, DateConstructor) ASSERT_TRUE(result9.IsObject()); JSHandle result10(thread, result9); JSHandle dateResult1 = JSHandle::Cast(result10); - ASSERT_EQ(dateResult1->GetTimeValue(), JSTaggedValue(static_cast(base::NAN_VALUE))); + ASSERT_EQ(dateResult1->GetTimeValue(thread), JSTaggedValue(static_cast(base::NAN_VALUE))); // case7: length > 1, infinite number auto ecmaRuntimeCallInfo12 = TestHelper::CreateEcmaRuntimeCallInfo(thread, jsDate.GetTaggedValue(), 8); @@ -1011,7 +1011,7 @@ HWTEST_F_L0(BuiltinsDateTest, DateConstructor) ASSERT_TRUE(result11.IsObject()); JSHandle result12(thread, result11); JSHandle dateResult2 = JSHandle::Cast(result12); - ASSERT_EQ(dateResult2->GetTimeValue(), JSTaggedValue(static_cast(base::NAN_VALUE))); + ASSERT_EQ(dateResult2->GetTimeValue(thread), JSTaggedValue(static_cast(base::NAN_VALUE))); // case8: length > 1 auto ecmaRuntimeCallInfo13 = TestHelper::CreateEcmaRuntimeCallInfo(thread, jsDate.GetTaggedValue(), 8); diff --git a/ecmascript/builtins/tests/builtins_date_time_format_first_test.cpp b/ecmascript/builtins/tests/builtins_date_time_format_first_test.cpp index 7e6ad85655..a883a887c2 100644 --- a/ecmascript/builtins/tests/builtins_date_time_format_first_test.cpp +++ b/ecmascript/builtins/tests/builtins_date_time_format_first_test.cpp @@ -128,7 +128,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, Format_001) { double days = BuiltinsDateCreate(2020, 10, 1); auto resultStr = FormatCommon(thread, "en-US", days); - EXPECT_STREQ("Sun, 11/1/2020, 24:00:00", EcmaStringAccessor(resultStr).ToCString().c_str()); + EXPECT_STREQ("Sun, 11/1/2020, 24:00:00", EcmaStringAccessor(resultStr).ToCString(thread).c_str()); } // Format.Tostring(pt-BR) @@ -136,7 +136,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, Format_002) { double days = BuiltinsDateCreate(2020, 5, 11); auto resultStr = FormatCommon(thread, "pt-BR", days); - CString resStr = EcmaStringAccessor(resultStr).ToCString(); + CString resStr = EcmaStringAccessor(resultStr).ToCString(thread); // the index of string "qui" is zero. EXPECT_TRUE(resStr.find("qui") == 0); // the index of string "11/06/2020 24:00:00" is not zero. @@ -154,7 +154,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, FormatToParts) auto result = AtomicsAlgorithm(thread, jsDateTimeFormat, vals, 6, AlgorithmType::ALGORITHM_FORMAT_TO_PARTS); // 6: args length JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 16U); // sixteen formatters } @@ -215,7 +215,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, FormatRangeToParts) AlgorithmType::ALGORITHM_FORMAT_RANGE_TO_PARTS); // 8: args length JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 39U); // The number of characters of "Fri1/1/202124:00:00–Mon3/1/202124:00:00" } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_date_time_format_second_test.cpp b/ecmascript/builtins/tests/builtins_date_time_format_second_test.cpp index 01d610d640..af25fa8fda 100644 --- a/ecmascript/builtins/tests/builtins_date_time_format_second_test.cpp +++ b/ecmascript/builtins/tests/builtins_date_time_format_second_test.cpp @@ -53,11 +53,11 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, ResolvedOptions) // judge whether the properties of the object are the same as those of jsdatetimeformat tag JSHandle localeKey = globalConst->GetHandledLocaleString(); JSHandle localeValue(factory->NewFromASCII("de")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), localeValue), true); JSHandle timeZone = globalConst->GetHandledTimeZoneString(); JSHandle timeZoneValue(factory->NewFromASCII("UTC")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, timeZone).GetValue(), timeZoneValue), true); } @@ -79,11 +79,11 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, SupportedLocalesOf_001) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle resultStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(resultStr).ToCString().c_str()); + JSHandle resultStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(resultStr).ToCString(thread).c_str()); } // SupportedLocalesOf("look up") @@ -111,11 +111,11 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, SupportedLocalesOf_002) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle resultStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de", EcmaStringAccessor(resultStr).ToCString().c_str()); + JSHandle resultStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de", EcmaStringAccessor(resultStr).ToCString(thread).c_str()); } static JSTaggedValue JSDateTime(JSThread *thread, JSTaggedValue &formatResult) @@ -220,7 +220,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, DateTimeFormat_001) constexpr int americaNewYork = -300; constexpr int sysDefaultTimezone = -180; // america_argentina_Buenos_Aires constexpr int utc = 0; - auto cstr = EcmaStringAccessor(resultStr).ToCString(); + auto cstr = EcmaStringAccessor(resultStr).ToCString(thread); if (TimeOffset() == utc) { if (cstr.find("GMT") != std::string::npos) { EXPECT_STREQ("10/08/22, 12:00:00 AM GMT", cstr.c_str()); @@ -307,7 +307,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, DateTimeFormat_002) auto formatResult = JSDateTimeFormatForObject(thread, constructorResult); auto dtResult = JSDateTime(thread, formatResult); JSHandle resultStr(thread, dtResult); - EXPECT_STREQ("2022年10月8日 UTC 上午12:00:00", EcmaStringAccessor(resultStr).ToCString().c_str()); + EXPECT_STREQ("2022年10月8日 UTC 上午12:00:00", EcmaStringAccessor(resultStr).ToCString(thread).c_str()); } // DateTimeFormat_003 @@ -329,7 +329,7 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, DateTimeFormat_003) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 16U); } @@ -356,6 +356,6 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, DateTimeFormat_004) auto constructorResult = JSDateTimeFormatConstructor(thread, optionsObj, localesString); JSHandle resultStr = JSDateTimeFormat::FormatDateTime(thread, JSHandle(thread, constructorResult), 0.0); - EXPECT_STREQ("1970年1月1日星期四 协调世界时 00:00:00", EcmaStringAccessor(resultStr).ToCString().c_str()); + EXPECT_STREQ("1970年1月1日星期四 协调世界时 00:00:00", EcmaStringAccessor(resultStr).ToCString(thread).c_str()); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/builtins/tests/builtins_displaynames_test.cpp b/ecmascript/builtins/tests/builtins_displaynames_test.cpp index 624bb1dadd..9fb4a6dfe4 100644 --- a/ecmascript/builtins/tests/builtins_displaynames_test.cpp +++ b/ecmascript/builtins/tests/builtins_displaynames_test.cpp @@ -101,7 +101,7 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, Of_001) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("French", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("French", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Of(419, type(region)) @@ -125,7 +125,7 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, Of_002) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("Latin America", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("Latin America", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Of(EUR, type(currency)) @@ -149,7 +149,7 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, Of_003) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("Euro", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("Euro", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Of(Code Cover) @@ -187,10 +187,10 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, SupportedLocalesOf_001) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // SupportedLocalesOf("look up") @@ -217,10 +217,10 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, SupportedLocalesOf_002) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("de-DE-u-co-phonebk", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("de-DE-u-co-phonebk", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsDisplayNamesTest, ResolvedOptions) @@ -244,10 +244,10 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, ResolvedOptions) // judge whether the properties of the object are the same as those of jsdatetimeformat tag JSHandle localeKey = globalConst->GetHandledLocaleString(); JSHandle localeValue(factory->NewFromASCII("de-DE")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), localeValue), true); JSHandle typeKey = globalConst->GetHandledTypeString(); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, typeKey).GetValue(), typeValue), true); } } diff --git a/ecmascript/builtins/tests/builtins_function_test.cpp b/ecmascript/builtins/tests/builtins_function_test.cpp index ac9b7afa89..0d8f30cf85 100644 --- a/ecmascript/builtins/tests/builtins_function_test.cpp +++ b/ecmascript/builtins/tests/builtins_function_test.cpp @@ -182,11 +182,11 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeBind) JSHandle resultFunc(thread, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(thread), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(thread), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread, resultFunc->GetBoundArguments()); + JSHandle array(thread, resultFunc->GetBoundArguments(thread)); ASSERT_EQ(array->GetLength(), 0U); // test name property auto globalConst = thread->GlobalConstants(); @@ -225,14 +225,14 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeBind1) JSHandle resultFunc(thread, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(thread), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(thread), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread, resultFunc->GetBoundArguments()); + JSHandle array(thread, resultFunc->GetBoundArguments(thread)); ASSERT_EQ(array->GetLength(), 2U); - JSTaggedValue elem = array->Get(0); - JSTaggedValue elem1 = array->Get(1); + JSTaggedValue elem = array->Get(thread, 0); + JSTaggedValue elem1 = array->Get(thread, 1); ASSERT_EQ(elem.GetRawData(), JSTaggedValue(123).GetRawData()); ASSERT_EQ(elem1.GetRawData(), str.GetTaggedType()); @@ -274,15 +274,15 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeBind2) JSHandle resultFunc(thread, reinterpret_cast(result.GetRawData())); // test BoundThis - ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(thread), thisArg.GetTaggedValue()); // test BoundTarget - ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(thread), target.GetTaggedValue()); // test BoundArguments - JSHandle array(thread, resultFunc->GetBoundArguments()); + JSHandle array(thread, resultFunc->GetBoundArguments(thread)); ASSERT_EQ(array->GetLength(), 2U); - JSTaggedValue elem = array->Get(0); - JSTaggedValue elem1 = array->Get(1); + JSTaggedValue elem = array->Get(thread, 0); + JSTaggedValue elem1 = array->Get(thread, 1); ASSERT_EQ(elem.GetRawData(), JSTaggedValue(123).GetRawData()); ASSERT_TRUE(elem1.IsString()); diff --git a/ecmascript/builtins/tests/builtins_global_test.cpp b/ecmascript/builtins/tests/builtins_global_test.cpp index 85cda34f40..3ced1e0688 100644 --- a/ecmascript/builtins/tests/builtins_global_test.cpp +++ b/ecmascript/builtins/tests/builtins_global_test.cpp @@ -54,7 +54,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, DecodeURIComponent) TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); JSHandle ecmaStrHandle(thread, result); - EXPECT_STREQ("123", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("123", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsGlobalTest, EncodeURIComponent) @@ -69,7 +69,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, EncodeURIComponent) TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); JSHandle ecmaStrHandle(thread, result); - EXPECT_STREQ("123", EcmaStringAccessor(ecmaStrHandle).ToCString().c_str()); + EXPECT_STREQ("123", EcmaStringAccessor(ecmaStrHandle).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsGlobalTest, PrintEntrypointAndPrintString) @@ -114,7 +114,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, Escape) TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(result1.IsString()); JSHandle ecmaStrHandle1(thread, result1); - EXPECT_STREQ("%3F%21%3D%28%29%23%25%26", EcmaStringAccessor(ecmaStrHandle1).ToCString().c_str()); // NOLINT + EXPECT_STREQ("%3F%21%3D%28%29%23%25%26", EcmaStringAccessor(ecmaStrHandle1).ToCString(thread).c_str()); // NOLINT JSHandle str2 = factory->NewFromASCII("%u%u0%u9%ua%uF%u00%u09%u0f%u0F%u000%u00a%u00F"); auto ecmaRuntimeCallInfo2 = @@ -129,7 +129,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, Escape) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle2(thread, result2); EXPECT_STREQ("%25u%25u0%25u9%25ua%25uF%25u00%25u09%25u0f%25u0F%25u000%25u00a%25u00F", // NOLINT special value - EcmaStringAccessor(ecmaStrHandle2).ToCString().c_str()); + EcmaStringAccessor(ecmaStrHandle2).ToCString(thread).c_str()); JSHandle str3 = factory->NewFromASCII("Hello World!"); std::vector args{str3.GetTaggedValue()}; @@ -140,7 +140,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, Escape) TestHelper::TearDownFrame(thread, prev3); EXPECT_TRUE(result3.IsString()); JSHandle ecmaStrHandle3(thread, result3); - EXPECT_STREQ("Hello%20World%21", EcmaStringAccessor(ecmaStrHandle3).ToCString().c_str()); + EXPECT_STREQ("Hello%20World%21", EcmaStringAccessor(ecmaStrHandle3).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsGlobalTest, Unescape) @@ -158,7 +158,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, Unescape) TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(result1.IsString()); JSHandle ecmaStrHandle1(thread, result1); - EXPECT_STREQ("", EcmaStringAccessor(ecmaStrHandle1).ToCString().c_str()); + EXPECT_STREQ("", EcmaStringAccessor(ecmaStrHandle1).ToCString(thread).c_str()); JSHandle str2 = factory->NewFromASCII("%u%u0%u9%ua%uF%u00%u09%u0f%u0F%u000%u00a%u00F"); auto ecmaRuntimeCallInfo2 = @@ -173,7 +173,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, Unescape) EXPECT_TRUE(result2.IsString()); JSHandle ecmaStrHandle2(thread, result2); EXPECT_STREQ("%u%u0%u9%ua%uF%u00%u09%u0f%u0F%u000%u00a%u00F", - EcmaStringAccessor(ecmaStrHandle2).ToCString().c_str()); + EcmaStringAccessor(ecmaStrHandle2).ToCString(thread).c_str()); JSHandle str3 = factory->NewFromASCII("Hello%20World%21"); std::vector args{str3.GetTaggedValue()}; @@ -184,7 +184,7 @@ HWTEST_F_L0(BuiltinsGlobalTest, Unescape) TestHelper::TearDownFrame(thread, prev3); EXPECT_TRUE(result3.IsString()); JSHandle ecmaStrHandle3(thread, result3); - EXPECT_STREQ("Hello%2520World%2521", EcmaStringAccessor(ecmaStrHandle3).ToCString().c_str()); + EXPECT_STREQ("Hello%2520World%2521", EcmaStringAccessor(ecmaStrHandle3).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsGlobalTest, isSendable_0) diff --git a/ecmascript/builtins/tests/builtins_intl_test.cpp b/ecmascript/builtins/tests/builtins_intl_test.cpp index e29e72a6ac..6669bf7cf1 100644 --- a/ecmascript/builtins/tests/builtins_intl_test.cpp +++ b/ecmascript/builtins/tests/builtins_intl_test.cpp @@ -53,10 +53,10 @@ HWTEST_F_L0(BuiltinsIntlTest, GetCanonicalLocales_002) JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, resultObj); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("ko-Kore-KR", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("ko-Kore-KR", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsIntlTest, GetCanonicalLocales_003) @@ -80,9 +80,9 @@ HWTEST_F_L0(BuiltinsIntlTest, GetCanonicalLocales_003) JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, resultObj); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("zh-Hans-CN", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("zh-Hans-CN", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_json_test.cpp b/ecmascript/builtins/tests/builtins_json_test.cpp index ae63a2233d..fcd8a6163c 100644 --- a/ecmascript/builtins/tests/builtins_json_test.cpp +++ b/ecmascript/builtins/tests/builtins_json_test.cpp @@ -418,7 +418,7 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify3) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*test, EcmaString::Cast(result.GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *test, EcmaString::Cast(result.GetTaggedObject()))); } JSHandle CreateJSObject(JSThread *thread) @@ -467,7 +467,7 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify4) // Test for proxy object [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*test, EcmaString::Cast(result.GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *test, EcmaString::Cast(result.GetTaggedObject()))); TestHelper::TearDownFrame(thread, prev); } @@ -504,7 +504,7 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify5) // Test for typedarray object JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*test, EcmaString::Cast(result.GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *test, EcmaString::Cast(result.GetTaggedObject()))); } HWTEST_F_L0(BuiltinsJsonTest, Stringify6) // Test for bigint object diff --git a/ecmascript/builtins/tests/builtins_list_format_first_test.cpp b/ecmascript/builtins/tests/builtins_list_format_first_test.cpp index 02710fe208..bc4adaf3e5 100644 --- a/ecmascript/builtins/tests/builtins_list_format_first_test.cpp +++ b/ecmascript/builtins/tests/builtins_list_format_first_test.cpp @@ -75,7 +75,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_001) auto result = FormatCommon(thread, jSListFormat, listValue.GetTaggedValue()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("M, o, t, o, r, c, y, c, l and e", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("M, o, t, o, r, c, y, c, l and e", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } void DefineOwnPropertyCommonTest(JSThread* thread, JSHandle& obj, std::vector>& vals) @@ -117,7 +117,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_002) JSHandle typeValue(factory->NewFromASCII("conjunction")); // the default value std::vector listVal{"Motorcycle", "Bus", "Car"}; JSHandle handleEcmaStr = CommonTest(thread, locale, typeValue, listVal); - EXPECT_STREQ("Motorcycle, Bus and Car", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("Motorcycle, Bus and Car", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Format(["Motorcycle", "Bus", "Car" ], type(disjunction)) @@ -128,7 +128,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_003) JSHandle typeValue(factory->NewFromASCII("disjunction")); // the default value std::vector listVal{"Motorcycle", "Bus", "Car"}; JSHandle handleEcmaStr = CommonTest(thread, locale, typeValue, listVal); - EXPECT_STREQ("Motorcycle, Bus or Car", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("Motorcycle, Bus or Car", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Format(["中文英文" ], type(disjunction)) @@ -140,7 +140,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_004) std::vector listVal{"中文英文"}; JSHandle handleEcmaStr = CommonTest(thread, locale, typeValue, listVal); - EXPECT_STREQ("中文英文", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("中文英文", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Format(["中文", "英文", "韩文" ], type(conjunction)) @@ -152,6 +152,6 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_005) std::vector listVal{"中文", "英文", "韩文" }; JSHandle handleEcmaStr = CommonTest(thread, locale, typeValue, listVal); - EXPECT_STREQ("中文、英文和韩文", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("中文、英文和韩文", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_list_format_second_test.cpp b/ecmascript/builtins/tests/builtins_list_format_second_test.cpp index afb828baee..11fd915d31 100644 --- a/ecmascript/builtins/tests/builtins_list_format_second_test.cpp +++ b/ecmascript/builtins/tests/builtins_list_format_second_test.cpp @@ -73,7 +73,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_001) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 0U); // zero formatters } @@ -88,7 +88,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_002) JSTaggedValue result = CommonTest(thread, locale, typeValue, vals); JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 6U); } @@ -120,7 +120,7 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_004) JSTaggedValue result = CommonTest(thread, locale, typeValue, vals); JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 3U); } @@ -159,10 +159,10 @@ HWTEST_F_L0(BuiltinsListFormatTest, SupportedLocalesOf_001) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // SupportedLocalesOf("look up") @@ -190,11 +190,11 @@ HWTEST_F_L0(BuiltinsListFormatTest, SupportedLocalesOf_002) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle resultStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de", EcmaStringAccessor(resultStr).ToCString().c_str()); + JSHandle resultStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de", EcmaStringAccessor(resultStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsListFormatTest, ResolvedOptions) @@ -219,10 +219,10 @@ HWTEST_F_L0(BuiltinsListFormatTest, ResolvedOptions) // judge whether the properties of the object are the same as those of jslistformat tag JSHandle localeKey = globalConst->GetHandledLocaleString(); JSHandle localeValue(factory->NewFromASCII("de-DE")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), localeValue), true); JSHandle typeKey = globalConst->GetHandledTypeString(); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, typeKey).GetValue(), typeValue), true); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/builtins/tests/builtins_locale_test.cpp b/ecmascript/builtins/tests/builtins_locale_test.cpp index 45a860fc46..d947337358 100644 --- a/ecmascript/builtins/tests/builtins_locale_test.cpp +++ b/ecmascript/builtins/tests/builtins_locale_test.cpp @@ -219,7 +219,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetBaseName) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("en-Latn-US", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("en-Latn-US", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetHourCycle) @@ -232,7 +232,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetHourCycle) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("h24", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("h24", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetCalendar) @@ -244,7 +244,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetCalendar) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("chinese", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("chinese", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetCaseFirst) @@ -268,7 +268,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetCollation) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("compat", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("compat", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetNumeric) @@ -292,7 +292,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetNumberingSystem) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("mong", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("mong", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetLanguage) @@ -305,7 +305,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetLanguage) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("en", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("en", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetScript) @@ -317,7 +317,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetScript) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("Latn", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("Latn", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, GetRegion) @@ -329,7 +329,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetRegion) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("US", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("US", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } static JSTaggedValue JSLocaleCreateWithOptionsTagsTest(JSThread *thread, JSHandle &value) @@ -376,7 +376,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, Maximize_001) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("zh-Hans-CN", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("zh-Hans-CN", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, Maximize_002) @@ -393,7 +393,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, Maximize_002) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("en-Latn-US", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("en-Latn-US", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, Minimize_001) @@ -411,7 +411,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, Minimize_001) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("en", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("en", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsLocaleTest, Minimize_002) @@ -431,7 +431,7 @@ HWTEST_F_L0(BuiltinsLocaleTest, Minimize_002) EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("zh", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("zh", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // test NormalizeKeywordValue(kf is not setted "yes") @@ -461,6 +461,6 @@ HWTEST_F_L0(BuiltinsLocaleTest, NormalizeKeywordValue) JSHandle jsInitLocale(thread, result); JSTaggedValue keyWords = JSLocale::NormalizeKeywordValue(thread, jsInitLocale, "kf"); - EXPECT_STREQ("false", EcmaStringAccessor(keyWords).ToCString().c_str()); + EXPECT_STREQ("false", EcmaStringAccessor(keyWords).ToCString(thread).c_str()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_map_test.cpp b/ecmascript/builtins/tests/builtins_map_test.cpp index bbad057881..56cdb5c21e 100644 --- a/ecmascript/builtins/tests/builtins_map_test.cpp +++ b/ecmascript/builtins/tests/builtins_map_test.cpp @@ -146,7 +146,7 @@ HWTEST_F_L0(BuiltinsMapTest, CreateAndGetSize) JSTaggedValue result1 = BuiltinsMap::MapConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(JSMap::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); + EXPECT_EQ(JSMap::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(thread), 5); } } @@ -175,7 +175,7 @@ HWTEST_F_L0(BuiltinsMapTest, SetAndHas) EXPECT_TRUE(result2.IsECMAObject()); jsMap = JSMap::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(jsMap->GetSize(), 1); + EXPECT_EQ(jsMap->GetSize(thread), 1); } // test Has() @@ -199,7 +199,7 @@ HWTEST_F_L0(BuiltinsMapTest, ForEach) EXPECT_TRUE(result1.IsECMAObject()); JSMap *jsMap = JSMap::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(jsMap->GetSize(), static_cast(i) + 1); + EXPECT_EQ(jsMap->GetSize(thread), static_cast(i) + 1); } JSHandle jsArray(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestFunc)); @@ -227,7 +227,7 @@ HWTEST_F_L0(BuiltinsMapTest, DeleteAndRemove) EXPECT_TRUE(result1.IsECMAObject()); JSMap *jsMap = JSMap::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(jsMap->GetSize(), static_cast(i) + 1); + EXPECT_EQ(jsMap->GetSize(thread), static_cast(i) + 1); } // whether jsMap has delete key keyArray[3] = '1' + 8; @@ -265,7 +265,7 @@ HWTEST_F_L0(BuiltinsMapTest, DeleteAndRemove) JSTaggedValue result6 = BuiltinsMap::Clear(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev4); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - EXPECT_EQ(map->GetSize(), 0); + EXPECT_EQ(map->GetSize(thread), 0); } HWTEST_F_L0(BuiltinsMapTest, Species) @@ -290,10 +290,10 @@ HWTEST_F_L0(BuiltinsMapTest, Species) JSHandle stringTag(JSObject::GetProperty(thread, map, toStringTagSymbol).GetValue()); JSHandle str = factory->NewFromASCII("Map"); EXPECT_TRUE(!stringTag.GetTaggedValue().IsUndefined()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*str, *stringTag)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *str, *stringTag)); JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread, valueHandle)); - EXPECT_EQ(JSTaggedValue::GetPrototype(thread, map), constructor->GetFunctionPrototype()); + EXPECT_EQ(JSTaggedValue::GetPrototype(thread, map), constructor->GetFunctionPrototype(thread)); JSHandle key1(factory->NewFromASCII("set")); JSTaggedValue value1 = JSObject::GetProperty(thread, map, key1).GetValue().GetTaggedValue(); @@ -337,7 +337,7 @@ HWTEST_F_L0(BuiltinsMapTest, GetIterator) JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSMapIterator()); EXPECT_EQ(IterationKind::VALUE, iter->GetIterationKind()); - EXPECT_EQ(JSMap::Cast(map.GetTaggedValue().GetTaggedObject())->GetLinkedMap(), iter->GetIteratedMap()); + EXPECT_EQ(JSMap::Cast(map.GetTaggedValue().GetTaggedObject())->GetLinkedMap(thread), iter->GetIteratedMap(thread)); // test Keys() JSTaggedValue result1 = BuiltinsMap::Keys(ecmaRuntimeCallInfo); diff --git a/ecmascript/builtins/tests/builtins_number_format_test.cpp b/ecmascript/builtins/tests/builtins_number_format_test.cpp index 9aa8cdfc14..1da4d38d04 100644 --- a/ecmascript/builtins/tests/builtins_number_format_test.cpp +++ b/ecmascript/builtins/tests/builtins_number_format_test.cpp @@ -103,7 +103,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, Format_001) JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); JSHandle resultEcmaStr(thread, formatResult); - EXPECT_STREQ("3,500", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("3,500", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); } // format currency @@ -134,7 +134,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, Format_002) JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); JSHandle resultEcmaStr(thread, formatResult); - EXPECT_STREQ("($3,500.00)", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("($3,500.00)", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); } // format percent @@ -159,7 +159,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, Format_003) JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); JSHandle resultEcmaStr(thread, formatResult); - EXPECT_STREQ("+55%", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("+55%", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); } // format unit @@ -184,7 +184,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, Format_004) JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); JSHandle resultEcmaStr(thread, formatResult); - EXPECT_STREQ("3,500 L", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("3,500 L", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); } // format notation @@ -205,7 +205,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, Format_005) JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); JSHandle resultEcmaStr(thread, formatResult); - EXPECT_STREQ("9.9亿", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("9.9亿", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); } static JSTaggedValue NumberFormatCreateTest(JSThread *thread, JSHandle &options, @@ -249,7 +249,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, FormatToParts) // format currency JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); JSHandle resultEcmaStr(thread, formatResult); - EXPECT_STREQ("3.500,00 €", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("3.500,00 €", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); @@ -261,7 +261,7 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, FormatToParts) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 10U); // "3","." ,"5" ,"0" ,"0" ,"," ,"0" ,0" ," " ,"€" } @@ -296,9 +296,9 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, ResolvedOptions) 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( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, styleKey).GetValue(), styleValue), true); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, currencyKey).GetValue(), currencyValue), true); } } diff --git a/ecmascript/builtins/tests/builtins_number_test.cpp b/ecmascript/builtins/tests/builtins_number_test.cpp index bf24174e0e..25ce0ce010 100644 --- a/ecmascript/builtins/tests/builtins_number_test.cpp +++ b/ecmascript/builtins/tests/builtins_number_test.cpp @@ -59,7 +59,7 @@ HWTEST_F_L0(BuiltinsNumberTest, NumberConstructor) JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSPrimitiveRef *ref = JSPrimitiveRef::Cast(value.GetTaggedObject()); - ASSERT_EQ(ref->GetValue().GetDouble(), 5.0); + ASSERT_EQ(ref->GetValue(thread).GetDouble(), 5.0); } // Number.isFinite(-10) @@ -211,7 +211,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString1) ASSERT_TRUE(result1.IsString()); JSHandle res1(thread, reinterpret_cast(result1.GetRawData())); JSHandle correctResult1 = factory->NewFromASCII("234.312256641535441"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res1, *correctResult1)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res1, *correctResult1)); TestHelper::TearDownFrame(thread, prev); // (15).toString(4) @@ -225,7 +225,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString1) ASSERT_TRUE(result2.IsString()); JSHandle res2(thread, reinterpret_cast(result2.GetRawData())); JSHandle correctResult2 = factory->NewFromASCII("33"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res2, *correctResult2)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res2, *correctResult2)); TestHelper::TearDownFrame(thread, prev); // (5).toString(8) @@ -239,7 +239,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString1) ASSERT_TRUE(result3.IsString()); JSHandle res3(thread, reinterpret_cast(result3.GetRawData())); JSHandle correctResult3 = factory->NewFromASCII("5"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res3, *correctResult3)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res3, *correctResult3)); TestHelper::TearDownFrame(thread, prev); // (0).toString(8) @@ -253,7 +253,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString1) ASSERT_TRUE(result4.IsString()); JSHandle res4(thread, reinterpret_cast(result4.GetRawData())); JSHandle correctResult4 = factory->NewFromASCII("0"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res4, *correctResult4)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res4, *correctResult4)); TestHelper::TearDownFrame(thread, prev); } HWTEST_F_L0(BuiltinsNumberTest, ToString2) @@ -270,7 +270,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString2) ASSERT_TRUE(result1.IsString()); JSHandle res1(thread, reinterpret_cast(result1.GetRawData())); JSHandle correctResult1 = factory->NewFromASCII("-1f"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res1, *correctResult1)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res1, *correctResult1)); TestHelper::TearDownFrame(thread, prev); // (2).toString(2.5) @@ -284,7 +284,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString2) ASSERT_TRUE(result2.IsString()); JSHandle res2(thread, reinterpret_cast(result2.GetRawData())); JSHandle correctResult2 = factory->NewFromASCII("10"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res2, *correctResult2)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res2, *correctResult2)); TestHelper::TearDownFrame(thread, prev); } @@ -308,7 +308,7 @@ HWTEST_F_L0(BuiltinsNumberTest, IsExponential) ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("1.23456e+2"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res, *correctResult)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res, *correctResult)); TestHelper::TearDownFrame(thread, prev); } @@ -332,7 +332,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed) ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("123.4560000000"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res, *correctResult)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res, *correctResult)); TestHelper::TearDownFrame(thread, prev); } @@ -356,7 +356,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed1) ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("123.456000000000003069544618483633"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res, *correctResult)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res, *correctResult)); TestHelper::TearDownFrame(thread, prev); } @@ -381,7 +381,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed2) { ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("1e+21"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res, *correctResult)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res, *correctResult)); TestHelper::TearDownFrame(thread, prev); } @@ -405,7 +405,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToPrecision) ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("123.45600"); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*res, *correctResult)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *res, *correctResult)); TestHelper::TearDownFrame(thread, prev); } @@ -467,74 +467,74 @@ HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleFlags) // flags of IGNORE_TRAILING str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0a"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 0); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0b"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 0); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0o"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 0); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 00x"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 0); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 000.4_"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 0.4); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0010.s "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 10); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0010e2"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 1000); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0010e+3_0"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::IGNORE_TRAILING), 10000); // flags of ALLOW_HEX str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0x"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_HEX))); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0x10 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_HEX), 16); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0x1g"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_HEX + base::IGNORE_TRAILING), 1); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0xh"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan( base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_HEX + base::IGNORE_TRAILING))); // flags of ALLOW_OCTAL str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0O"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_OCTAL))); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0o10 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_OCTAL), 8); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0o1d"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_OCTAL | base::IGNORE_TRAILING), 1); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0o8"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan( base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_OCTAL | base::IGNORE_TRAILING))); // flags of ALLOW_BINARY str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0b"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_BINARY))); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0b10 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_BINARY), 2); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0b1d"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_BINARY | base::IGNORE_TRAILING), 1); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII("0b2"); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan( base::NumberHelper::StringToDouble(sp.begin(), sp.end(), 0, base::ALLOW_BINARY | base::IGNORE_TRAILING))); } @@ -549,80 +549,80 @@ HWTEST_F_L0(BuiltinsNumberTest, StringToDoubleRadix) radix = 0; // default 10 str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 100); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100.3e2 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 10030); radix = 1; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0000 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 0); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0001 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_TRUE(std::isnan(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS))); radix = 2; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 4); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 11 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 3); radix = 3; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 9); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 21 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 7); radix = 4; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 16); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 31 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 13); radix = 8; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 64); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 71 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 57); radix = 10; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 100); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 0020 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 20); radix = 16; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 256); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 1e "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 30); radix = 18; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 324); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 1g "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 34); radix = 25; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 625); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 1g "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 41); radix = 36; str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 100 "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 1296); str = thread->GetEcmaVM()->GetFactory()->NewFromASCII(" 1z "); - sp = EcmaStringAccessor(str).ToUtf8Span(buf); + sp = EcmaStringAccessor(str).ToUtf8Span(thread, buf); ASSERT_EQ(base::NumberHelper::StringToDouble(sp.begin(), sp.end(), radix, base::NO_FLAGS), 71); } diff --git a/ecmascript/builtins/tests/builtins_object_test.cpp b/ecmascript/builtins/tests/builtins_object_test.cpp index 6b60c15b18..c070c013f8 100644 --- a/ecmascript/builtins/tests/builtins_object_test.cpp +++ b/ecmascript/builtins/tests/builtins_object_test.cpp @@ -84,7 +84,7 @@ HWTEST_F_L0(BuiltinsObjectTest, ObjectConstructor) ASSERT_TRUE(result.IsECMAObject()); JSHandle jtHandle(thread, JSTaggedValue(reinterpret_cast(result.GetRawData()))); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(jtHandle)); - JSTaggedValue funcProto = objectFunc->GetFunctionPrototype(); + JSTaggedValue funcProto = objectFunc->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); ASSERT_TRUE(jtHandle->IsExtensible()); @@ -103,7 +103,7 @@ HWTEST_F_L0(BuiltinsObjectTest, ObjectConstructor) ASSERT_TRUE(resultTg.IsObject()); JSHandle jtHandleTg(thread, JSTaggedValue(reinterpret_cast(resultTg.GetRawData()))); JSTaggedValue resultProtoTg = JSTaggedValue::GetPrototype(thread, JSHandle(jtHandleTg)); - JSTaggedValue funcProtoTg = objectFunc->GetFunctionPrototype(); + JSTaggedValue funcProtoTg = objectFunc->GetFunctionPrototype(thread); ASSERT_EQ(resultProtoTg, funcProtoTg); ASSERT_TRUE(jtHandleTg->IsExtensible()); @@ -124,7 +124,7 @@ HWTEST_F_L0(BuiltinsObjectTest, ObjectConstructor) ASSERT_TRUE(resultVn.IsObject()); JSHandle jtHandleVn(thread, JSTaggedValue(reinterpret_cast(resultVn.GetRawData()))); JSTaggedValue resultProtoVn = JSTaggedValue::GetPrototype(thread, JSHandle(jtHandleVn)); - JSTaggedValue funcProtoVn = objectFunc->GetFunctionPrototype(); + JSTaggedValue funcProtoVn = objectFunc->GetFunctionPrototype(thread); ASSERT_EQ(resultProtoVn, funcProtoVn); ASSERT_TRUE(jtHandleVn->IsExtensible()); } @@ -169,7 +169,7 @@ HWTEST_F_L0(BuiltinsObjectTest, Create) { JSHandle function(thread, BuiltinsObjectTestCreate(thread)); JSHandle objectFunc(thread, BuiltinsObjectTestCreate(thread)); - JSHandle funcProto(thread, objectFunc->GetFunctionPrototype()); + JSHandle funcProto(thread, objectFunc->GetFunctionPrototype(thread)); // no prop auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -358,7 +358,7 @@ HWTEST_F_L0(BuiltinsObjectTest, GetOwnPropertyDescriptor) JSTaggedValue jt(reinterpret_cast(result.GetRawData())); PropertyDescriptor desc(thread); JSObject::GetOwnProperty(thread, JSHandle(thread, jt), writableStr, desc); - ASSERT_TRUE(JSTaggedValue::SameValue(desc.GetValue().GetTaggedValue(), JSTaggedValue(true))); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, desc.GetValue().GetTaggedValue(), JSTaggedValue(true))); } // 19.1.2.7 Object.getOwnPropertyNames ( O ) diff --git a/ecmascript/builtins/tests/builtins_plural_rules_test.cpp b/ecmascript/builtins/tests/builtins_plural_rules_test.cpp index 390b8616ae..f6a7378bc1 100644 --- a/ecmascript/builtins/tests/builtins_plural_rules_test.cpp +++ b/ecmascript/builtins/tests/builtins_plural_rules_test.cpp @@ -93,7 +93,7 @@ static void SelectTest(JSThread *thread, std::string_view data, std::string_view EXPECT_TRUE(result.IsString()); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ(expectStr.data(), EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ(expectStr.data(), EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // select(0, type(cardinal)) @@ -155,10 +155,10 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, SupportedLocalesOf) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsPluralRulesTest, ResolvedOptions) @@ -183,10 +183,10 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, ResolvedOptions) // judge whether the properties of the object are the same as those of jspluralrulesformat tag JSHandle localeKey = globalConst->GetHandledLocaleString(); JSHandle localeValue(factory->NewFromASCII("en")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), localeValue), true); JSHandle typeKey = globalConst->GetHandledTypeString(); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, typeKey).GetValue(), typeValue), true); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_promise_test.cpp b/ecmascript/builtins/tests/builtins_promise_test.cpp index 027b2edefd..4460434e65 100644 --- a/ecmascript/builtins/tests/builtins_promise_test.cpp +++ b/ecmascript/builtins/tests/builtins_promise_test.cpp @@ -41,15 +41,17 @@ class BuiltinsPromiseTest : public BaseTestWithScope { // native function for race2 then_on_rejected() JSTaggedValue TestPromiseRaceThenOnRejectd(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle result = BuiltinsBase::GetCallArg(argv, 0); // 12345 : test case - EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), JSTaggedValue(12345)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, result.GetTaggedValue(), JSTaggedValue(12345)), true); return JSTaggedValue::Undefined(); } // native function for all then_on_resolved() JSTaggedValue TestPromiseAllThenOnResolved(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle array = BuiltinsBase::GetCallArg(argv, 0); JSHandle objectArray = JSHandle::Cast(array); [[maybe_unused]] PropertyDescriptor desc(argv->GetThread()); @@ -58,42 +60,45 @@ JSTaggedValue TestPromiseAllThenOnResolved(EcmaRuntimeCallInfo *argv) EXPECT_TRUE(result1); JSHandle value1 = desc.GetValue(); // 111 : test case - EXPECT_EQ(JSTaggedValue::SameValue(value1.GetTaggedValue(), JSTaggedValue(111)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, value1.GetTaggedValue(), JSTaggedValue(111)), true); [[maybe_unused]] bool result2 = JSObject::GetOwnProperty( argv->GetThread(), objectArray, JSHandle(argv->GetThread(), JSTaggedValue(1)), desc); EXPECT_TRUE(result2); JSHandle value2 = desc.GetValue(); // 222 : test case - EXPECT_EQ(JSTaggedValue::SameValue(value2.GetTaggedValue(), JSTaggedValue(222)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, value2.GetTaggedValue(), JSTaggedValue(222)), true); return JSTaggedValue::Undefined(); } // native function for catch catch_on_rejected() JSTaggedValue TestPromiseCatch(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle result = BuiltinsBase::GetCallArg(argv, 0); // 3 : test case - EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), JSTaggedValue(3)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, result.GetTaggedValue(), JSTaggedValue(3)), true); return JSTaggedValue::Undefined(); } // native function for then then_on_resolved() JSTaggedValue TestPromiseThenOnResolved(EcmaRuntimeCallInfo *argv) { - auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); + JSThread *thread = argv->GetThread(); + auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle result = BuiltinsBase::GetCallArg(argv, 0); auto expect = factory->NewFromASCII("resolve"); - EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), expect.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, result.GetTaggedValue(), expect.GetTaggedValue()), true); return JSTaggedValue::Undefined(); } // native function for then then_on_rejected() JSTaggedValue TestPromiseThenOnRejected(EcmaRuntimeCallInfo *argv) { - auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); + JSThread *thread = argv->GetThread(); + auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle result = BuiltinsBase::GetCallArg(argv, 0); auto expect = factory->NewFromASCII("reject"); - EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), expect.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, result.GetTaggedValue(), expect.GetTaggedValue()), true); return JSTaggedValue::Undefined(); } @@ -167,7 +172,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject1) auto result = PromiseAlgorithm(thread, promise, paramMsg.GetTaggedValue(), AlgorithmType::REJECT); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), JSTaggedValue(3)), true); } /* @@ -191,7 +196,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject2) auto result = PromiseAlgorithm(thread, promise, paramMsg1.GetTaggedValue(), AlgorithmType::REJECT); JSHandle promise1(thread, result); EXPECT_EQ(promise1->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, promise1->GetPromiseResult(thread), paramMsg1.GetTaggedValue()), true); /** * @tc.steps: step2. var p2 = Promise.reject(p1) @@ -201,7 +206,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject2) EXPECT_NE(*promise1, *promise2); EXPECT_EQ(promise2->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ( - JSTaggedValue::SameValue(promise2->GetPromiseResult(), JSTaggedValue(promise1.GetTaggedValue().GetRawData())), + JSTaggedValue::SameValue(thread, promise2->GetPromiseResult(thread), JSTaggedValue(promise1.GetTaggedValue().GetRawData())), true); } @@ -223,7 +228,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve1) auto result = PromiseAlgorithm(thread, promise, paramMsg.GetTaggedValue(), AlgorithmType::RESOLVE); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(5)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), JSTaggedValue(5)), true); } /* @@ -247,7 +252,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve2) auto result = PromiseAlgorithm(thread, promise, paramMsg1.GetTaggedValue(), AlgorithmType::REJECT); JSHandle promise1(thread, result); EXPECT_EQ(promise1->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, promise1->GetPromiseResult(thread), paramMsg1.GetTaggedValue()), true); // promise1 Enter Reject() as a parameter. /** @@ -257,7 +262,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve2) JSHandle promise2(thread, result1); EXPECT_EQ(*promise1, *promise2); EXPECT_EQ(promise2->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, promise2->GetPromiseResult(thread), paramMsg1.GetTaggedValue()), true); } /* @@ -278,7 +283,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) auto result1 = PromiseAlgorithm(thread, promise, paramMsg1.GetTaggedValue(), AlgorithmType::REJECT); JSHandle rejectPromise(thread, result1); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), JSTaggedValue(12345)), true); /** * @tc.steps: step2. var p2 = Promise.resolve(6789) @@ -287,7 +292,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) auto result2 = PromiseAlgorithm(thread, promise, paramMsg2.GetTaggedValue(), AlgorithmType::RESOLVE); JSHandle resolvePromise(thread, result2); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resolvePromise->GetPromiseResult(thread), JSTaggedValue(6789)), true); /** * @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] */ @@ -304,7 +309,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) auto result4 = PromiseAlgorithm(thread, promise, array.GetTaggedValue(), AlgorithmType::RACE); JSHandle racePromise(thread, result4); EXPECT_EQ(racePromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(racePromise->GetPromiseResult(thread).IsUndefined(), true); } /* @@ -328,7 +333,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) auto result1 = PromiseAlgorithm(thread, promise, paramMsg1.GetTaggedValue(), AlgorithmType::REJECT); JSHandle rejectPromise(thread, result1); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), JSTaggedValue(12345)), true); /** * @tc.steps: step2. var p2 = Promise.resolve(6789) @@ -336,7 +341,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) auto result2 = PromiseAlgorithm(thread, promise, paramMsg2.GetTaggedValue(), AlgorithmType::RESOLVE); JSHandle resolvePromise(thread, result2); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resolvePromise->GetPromiseResult(thread), JSTaggedValue(6789)), true); /** * @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] @@ -354,7 +359,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) auto result3 = PromiseAlgorithm(thread, promise, array.GetTaggedValue(), AlgorithmType::RACE); JSHandle racePromise(thread, result3); EXPECT_EQ(racePromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(racePromise->GetPromiseResult(thread).IsUndefined(), true); /** * @tc.steps: step5. p3.then((resolve)=>{print(resolve)}, (reject)=>{print(reject)}) @@ -366,7 +371,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); + EXPECT_TRUE(thenPromise->GetPromiseResult(thread).IsUndefined()); /** * @tc.steps: step6. execute promise queue @@ -398,7 +403,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) auto result1 = PromiseAlgorithm(thread, promise, paramMsg1.GetTaggedValue(), AlgorithmType::RESOLVE); JSHandle resolvePromise1(thread, result1); EXPECT_EQ(resolvePromise1->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise1->GetPromiseResult(), JSTaggedValue(111)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resolvePromise1->GetPromiseResult(thread), JSTaggedValue(111)), true); /** * @tc.steps: step2. var p2 = Promise.resolve(222) @@ -406,7 +411,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) auto result2 = PromiseAlgorithm(thread, promise, paramMsg2.GetTaggedValue(), AlgorithmType::RESOLVE); JSHandle resolvePromise2(thread, result2); EXPECT_EQ(resolvePromise2->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise2->GetPromiseResult(), JSTaggedValue(222)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resolvePromise2->GetPromiseResult(thread), JSTaggedValue(222)), true); /** * @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] @@ -424,7 +429,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) auto result4 = PromiseAlgorithm(thread, promise, array.GetTaggedValue(), AlgorithmType::ALL); JSHandle allPromise(thread, result4); EXPECT_EQ(allPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(allPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(allPromise->GetPromiseResult(thread).IsUndefined(), true); /** * @tc.steps: step5. p3.then((resolve)=>{print(resolve)}, (reject)=>{print(reject)}); @@ -436,7 +441,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); + EXPECT_TRUE(thenPromise->GetPromiseResult(thread).IsUndefined()); /** * @tc.steps: step6. execute promise queue @@ -466,7 +471,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Catch) auto result = PromiseAlgorithm(thread, promise, paramMsg1.GetTaggedValue(), AlgorithmType::REJECT); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), JSTaggedValue(3)), true); /** * @tc.steps: step2. p1 invokes catch() @@ -482,7 +487,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, Catch) JSHandle catchPromise(thread, catchResult); EXPECT_EQ(catchPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(catchPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(catchPromise->GetPromiseResult(thread).IsUndefined(), true); TestHelper::TearDownFrame(thread, prevCatch); /** @@ -513,7 +518,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenResolve) auto result = PromiseAlgorithm(thread, promise, paramMsg.GetTaggedValue(), AlgorithmType::RESOLVE); JSHandle resolvePromise(thread, result); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resolvePromise->GetPromiseResult(thread), paramMsg.GetTaggedValue()), true); /** * @tc.steps: step2. p1 invokes then() @@ -525,7 +530,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenResolve) JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(thenPromise->GetPromiseResult(thread).IsUndefined(), true); /** * @tc.steps: step3. execute promise queue @@ -555,7 +560,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenReject) auto result = PromiseAlgorithm(thread, promise, paramMsg.GetTaggedValue(), AlgorithmType::REJECT); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), paramMsg.GetTaggedValue()), true); /** * @tc.steps: step1. p1 invokes then() @@ -566,7 +571,7 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenReject) testPromiseThenOnRejected.GetTaggedValue()); JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(thenPromise->GetPromiseResult(thread).IsUndefined(), true); /** * @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 d28fa4d67c..2bda44ef3f 100644 --- a/ecmascript/builtins/tests/builtins_proxy_test.cpp +++ b/ecmascript/builtins/tests/builtins_proxy_test.cpp @@ -97,10 +97,10 @@ HWTEST_F_L0(BuiltinsProxyTest, Revocable) bool pflag = false; bool rflag = false; for (uint32_t i = 0; i < keys->GetLength(); i++) { - if (JSTaggedValue::SameValue(keys->Get(i), proxyKey.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, keys->Get(thread, i), proxyKey.GetTaggedValue())) { pflag = true; } - if (JSTaggedValue::SameValue(keys->Get(i), revokeKey.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, keys->Get(thread, i), revokeKey.GetTaggedValue())) { rflag = true; } } diff --git a/ecmascript/builtins/tests/builtins_reflect_test.cpp b/ecmascript/builtins/tests/builtins_reflect_test.cpp index 9fde42f979..9f106db45d 100644 --- a/ecmascript/builtins/tests/builtins_reflect_test.cpp +++ b/ecmascript/builtins/tests/builtins_reflect_test.cpp @@ -137,7 +137,7 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectConstruct) JSHandle refResult = JSHandle::Cast(taggedResult); JSHandle ruler = factory->NewFromASCII("ReflectConstruct"); ASSERT_EQ(EcmaStringAccessor::Compare(instance, - JSHandle(thread, EcmaString::Cast(refResult->GetValue())), ruler), 0); + JSHandle(thread, EcmaString::Cast(refResult->GetValue(thread))), ruler), 0); TestHelper::TearDownFrame(thread, prev); } @@ -315,7 +315,7 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectGetPrototypeOf) 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); + ASSERT_EQ(JSTaggedValue::SameValue(thread, resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); TestHelper::TearDownFrame(thread, prev); } @@ -490,8 +490,8 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectSetPrototypeOf) 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); + JSHandle resultObj(thread, target->GetJSHClass()->GetPrototype(thread)); + ASSERT_EQ(JSTaggedValue::SameValue(thread, 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 9879564a88..55c9ebff7a 100644 --- a/ecmascript/builtins/tests/builtins_regexp_test.cpp +++ b/ecmascript/builtins/tests/builtins_regexp_test.cpp @@ -48,8 +48,8 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpConstructor1) ASSERT_TRUE(JSObject::IsRegExp(thread, regexpObject)); JSHandle jsRegexp(thread, JSRegExp::Cast(regexpObject->GetTaggedObject())); - JSHandle originalSource(thread, jsRegexp->GetOriginalSource()); - uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags().GetInt()); + JSHandle originalSource(thread, jsRegexp->GetOriginalSource(thread)); + uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags(thread).GetInt()); JSHandle originalFlags(thread, BuiltinsRegExp::FlagsBitsToString(thread, flagsBits)); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(originalSource), pattern), 0); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(originalFlags), flags), 0); @@ -83,8 +83,8 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpConstructor2) ASSERT_TRUE(JSObject::IsRegExp(thread, regexpObject)); JSHandle jsRegexp(thread, JSRegExp::Cast(regexpObject->GetTaggedObject())); - JSHandle originalSource(thread, jsRegexp->GetOriginalSource()); - uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags().GetInt()); + JSHandle originalSource(thread, jsRegexp->GetOriginalSource(thread)); + uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags(thread).GetInt()); JSHandle originalFlags(thread, BuiltinsRegExp::FlagsBitsToString(thread, flagsBits)); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(originalSource), pattern), 0); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(originalFlags), flags), 0); @@ -118,8 +118,8 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpConstructor3) ASSERT_TRUE(JSObject::IsRegExp(thread, regexpObject)); JSHandle jsRegexp(thread, JSRegExp::Cast(regexpObject->GetTaggedObject())); - JSHandle originalSource(thread, jsRegexp->GetOriginalSource()); - uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags().GetInt()); + JSHandle originalSource(thread, jsRegexp->GetOriginalSource(thread)); + uint8_t flagsBits = static_cast(jsRegexp->GetOriginalFlags(thread).GetInt()); JSHandle originalFlags(thread, BuiltinsRegExp::FlagsBitsToString(thread, flagsBits)); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(originalSource), pattern1), 0); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(originalFlags), flags2), 0); @@ -586,13 +586,13 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpParseCache) JSHandle string1 = factory->NewFromASCII("abc"); JSHandle string2 = factory->NewFromASCII("abcd"); CVector vec; - regExpParserCache->SetCache(*string1, 0, JSTaggedValue::True(), 2, vec); - ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0, vec).first.IsTrue()); - ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0, vec).second == 2U); - ASSERT_TRUE(regExpParserCache->GetCache(*string1, + regExpParserCache->SetCache(thread, *string1, 0, JSTaggedValue::True(), 2, vec); + ASSERT_TRUE(regExpParserCache->GetCache(thread, *string1, 0, vec).first.IsTrue()); + ASSERT_TRUE(regExpParserCache->GetCache(thread, *string1, 0, vec).second == 2U); + ASSERT_TRUE(regExpParserCache->GetCache(thread, *string1, RegExpParserCache::CACHE_SIZE, vec).first.IsHole()); - ASSERT_TRUE(regExpParserCache->GetCache(*string2, 0, vec).first.IsHole()); - ASSERT_TRUE(regExpParserCache->GetCache(*string2, UINT32_MAX, vec).first.IsHole()); + ASSERT_TRUE(regExpParserCache->GetCache(thread, *string2, 0, vec).first.IsHole()); + ASSERT_TRUE(regExpParserCache->GetCache(thread, *string2, UINT32_MAX, vec).first.IsHole()); } HWTEST_F_L0(BuiltinsRegExpTest, FlagD) diff --git a/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp b/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp index 5e94edef34..1470c3d808 100644 --- a/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp +++ b/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp @@ -104,7 +104,7 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_001) auto result = FormatCommon(thread, jsPluralRules, numberValue, unitValue); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("tomorrow", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("tomorrow", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // format(0, auto) @@ -121,7 +121,7 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_002) auto result = FormatCommon(thread, jsPluralRules, numberValue, unitValue); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("today", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("today", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // format(-1, auto) @@ -139,7 +139,7 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_003) auto result = FormatCommon(thread, jsPluralRules, numberValue, unitValue); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("yesterday", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("yesterday", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // format(-1, always) @@ -157,7 +157,7 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_004) auto result = FormatCommon(thread, jsPluralRules, numberValue, unitValue); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("1 day ago", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("1 day ago", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // format(1, always) @@ -174,7 +174,7 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_005) auto result = FormatCommon(thread, jsPluralRules, numberValue, unitValue); JSHandle handleEcmaStr(thread, result); - EXPECT_STREQ("in 1 day", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + EXPECT_STREQ("in 1 day", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, FormatToParts) @@ -225,15 +225,15 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, ResolvedOptions) JSHandle(thread, JSTaggedValue(static_cast(result.GetRawData()))); // judge whether the properties of the object are the same as those of jsrelativetimeformat tag JSHandle localeKey = globalConst->GetHandledLocaleString(); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), locale), true); JSHandle styleKey = globalConst->GetHandledStyleString(); JSHandle styleValue(factory->NewFromASCII("long")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, styleKey).GetValue(), styleValue), true); JSHandle numberingSystemKey = globalConst->GetHandledNumberingSystemString(); JSHandle numberingSystemValue(factory->NewFromASCII("latn")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, numberingSystemKey).GetValue(), numberingSystemValue), true); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_segmenter_test.cpp b/ecmascript/builtins/tests/builtins_segmenter_test.cpp index 39e4a6cac7..5be502c638 100644 --- a/ecmascript/builtins/tests/builtins_segmenter_test.cpp +++ b/ecmascript/builtins/tests/builtins_segmenter_test.cpp @@ -156,10 +156,10 @@ HWTEST_F_L0(BuiltinsSegmenterTest, SupportedLocalesOf) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); - JSHandle elements(thread, resultHandle->GetElements()); + JSHandle elements(thread, resultHandle->GetElements(thread)); EXPECT_EQ(elements->GetLength(), 1U); - JSHandle handleEcmaStr(thread, elements->Get(0)); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, elements->Get(thread, 0)); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); } // Intl.Segmenter.prototype.resolvedOptions @@ -182,11 +182,11 @@ HWTEST_F_L0(BuiltinsSegmenterTest, ResolvedOptions) JSHandle(thread, JSTaggedValue(static_cast(result.GetRawData()))); // judge whether the properties of the object are the same as those of jsdatetimeformat tag JSHandle localeKey = globalConst->GetHandledLocaleString(); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, localeKey).GetValue(), locale), true); JSHandle granularityKey = globalConst->GetHandledGranularityString(); JSHandle defaultGranularityValue(factory->NewFromASCII("grapheme")); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, granularityKey).GetValue(), defaultGranularityValue), true); } @@ -228,10 +228,10 @@ HWTEST_F_L0(BuiltinsSegmenterTest, SegmentsPrototypeContaining_001) std::vector> outValues; SegmentsPrototypeCommon(thread, result, outValues); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[0])).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[0])).ToCString(thread).c_str(), "这句话是中文。"); EXPECT_EQ(outValues[1]->GetRawData(), JSTaggedValue(0).GetRawData()); // 1:index value - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[2])).ToCString().c_str(), // 2: input value + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[2])).ToCString(thread).c_str(), // 2: input value "这句话是中文。这句还是中文!"); EXPECT_TRUE(outValues[3]->IsUndefined()); // 2: word link value } @@ -255,10 +255,10 @@ HWTEST_F_L0(BuiltinsSegmenterTest, SegmentsPrototypeContaining_002) std::vector> outValues; SegmentsPrototypeCommon(thread, result, outValues); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[0])).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[0])).ToCString(thread).c_str(), "joie"); EXPECT_EQ(outValues[1]->GetRawData(), JSTaggedValue(7).GetRawData()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[2])).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(outValues[2])).ToCString(thread).c_str(), "Que ma joie demeure"); EXPECT_EQ(outValues[3]->GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -337,7 +337,7 @@ HWTEST_F_L0(BuiltinsSegmenterTest, SegmentIteratorNext) EXPECT_TRUE(value1->IsJSObject()); JSHandle segmentKey = globalConst->GetHandledSegmentString(); JSHandle segmentValue(JSObject::GetProperty(thread, value1, segmentKey).GetValue()); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(segmentValue)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(segmentValue)).ToCString(thread).c_str(), "Que ma joie demeure."); EXPECT_FALSE(done1->ToBoolean()); diff --git a/ecmascript/builtins/tests/builtins_sendable_arraybuffer_test.cpp b/ecmascript/builtins/tests/builtins_sendable_arraybuffer_test.cpp index b73dc9fb18..3f5fe16f06 100644 --- a/ecmascript/builtins/tests/builtins_sendable_arraybuffer_test.cpp +++ b/ecmascript/builtins/tests/builtins_sendable_arraybuffer_test.cpp @@ -256,7 +256,7 @@ HWTEST_F_L0(BuiltinsSendableArrayBufferTest, IsDetachBuffer1) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle byteArray = factory->NewByteArray(5, 8); - bool result = BuiltinsSendableArrayBuffer::IsDetachedBuffer(byteArray.GetTaggedValue()); + bool result = BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, byteArray.GetTaggedValue()); ASSERT_EQ(JSTaggedValue(result).GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -267,7 +267,7 @@ HWTEST_F_L0(BuiltinsSendableArrayBufferTest, IsDetachBuffer2) JSHandle arrBuf( thread, JSSendableArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); arrBuf->SetArrayBufferData(thread, JSTaggedValue::Null()); - bool result = BuiltinsSendableArrayBuffer::IsDetachedBuffer(tagged); + bool result = BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, tagged); ASSERT_EQ(JSTaggedValue(result).GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -278,7 +278,7 @@ HWTEST_F_L0(BuiltinsSendableArrayBufferTest, IsDetachBuffer3) JSHandle arrBuf( thread, JSSendableArrayBuffer::Cast(reinterpret_cast(tagged.GetRawData()))); arrBuf->SetArrayBufferData(thread, JSTaggedValue(1)); - bool result = BuiltinsSendableArrayBuffer::IsDetachedBuffer(tagged); + bool result = BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, tagged); ASSERT_EQ(JSTaggedValue(result).GetRawData(), JSTaggedValue(false).GetRawData()); } diff --git a/ecmascript/builtins/tests/builtins_set_test.cpp b/ecmascript/builtins/tests/builtins_set_test.cpp index 43469cb71c..0fb1719cb2 100644 --- a/ecmascript/builtins/tests/builtins_set_test.cpp +++ b/ecmascript/builtins/tests/builtins_set_test.cpp @@ -138,7 +138,7 @@ HWTEST_F_L0(BuiltinsSetTest, CreateAndGetSize) JSTaggedValue result1 = BuiltinsSet::SetConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(JSSet::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); + EXPECT_EQ(JSSet::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(thread), 5); } } @@ -164,7 +164,7 @@ HWTEST_F_L0(BuiltinsSetTest, AddAndHas) JSTaggedValue result2 = BuiltinsSet::Add(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); JSSet *jsSet = JSSet::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(jsSet->GetSize(), 1); + EXPECT_EQ(jsSet->GetSize(thread), 1); // test Has() JSTaggedValue jsSetTag(jsSet); @@ -201,7 +201,7 @@ HWTEST_F_L0(BuiltinsSetTest, ForEach) EXPECT_TRUE(result1.IsECMAObject()); JSSet *jsSet = JSSet::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(jsSet->GetSize(), static_cast(i) + 1); + EXPECT_EQ(jsSet->GetSize(thread), static_cast(i) + 1); } // test foreach JSHandle jsArray(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); @@ -238,7 +238,7 @@ HWTEST_F_L0(BuiltinsSetTest, DeleteAndRemove) EXPECT_TRUE(result1.IsECMAObject()); JSSet *jsSet = JSSet::Cast(reinterpret_cast(result1.GetRawData())); - EXPECT_EQ(jsSet->GetSize(), static_cast(i) + 1); + EXPECT_EQ(jsSet->GetSize(thread), static_cast(i) + 1); } // whether jsSet has delete key keyArray[3] = '1' + 8; @@ -271,7 +271,7 @@ HWTEST_F_L0(BuiltinsSetTest, DeleteAndRemove) // clear JSTaggedValue result6 = BuiltinsSet::Clear(ecmaRuntimeCallInfo1); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); - EXPECT_EQ(set->GetSize(), 0); + EXPECT_EQ(set->GetSize(thread), 0); } HWTEST_F_L0(BuiltinsSetTest, Species) @@ -294,10 +294,10 @@ HWTEST_F_L0(BuiltinsSetTest, Species) JSHandle stringTag(JSObject::GetProperty(thread, set, toStringTagSymbol).GetValue()); JSHandle str = factory->NewFromASCII("Set"); EXPECT_TRUE(!stringTag.GetTaggedValue().IsUndefined()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*str, *stringTag)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *str, *stringTag)); JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread, valueHandle)); - EXPECT_EQ(JSTaggedValue::GetPrototype(thread, set), constructor->GetFunctionPrototype()); + EXPECT_EQ(JSTaggedValue::GetPrototype(thread, set), constructor->GetFunctionPrototype(thread)); JSHandle key1(factory->NewFromASCII("add")); JSTaggedValue value1 = JSObject::GetProperty(thread, set, key1).GetValue().GetTaggedValue(); @@ -338,7 +338,7 @@ HWTEST_F_L0(BuiltinsSetTest, GetIterator) 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()); + EXPECT_EQ(JSSet::Cast(set.GetTaggedValue().GetTaggedObject())->GetLinkedSet(thread), iter->GetIteratedSet(thread)); // test entries() JSTaggedValue result2 = BuiltinsSet::Entries(ecmaRuntimeCallInfo); diff --git a/ecmascript/builtins/tests/builtins_shared_array_test.cpp b/ecmascript/builtins/tests/builtins_shared_array_test.cpp index 9dd29fa188..0cafba0c9a 100644 --- a/ecmascript/builtins/tests/builtins_shared_array_test.cpp +++ b/ecmascript/builtins/tests/builtins_shared_array_test.cpp @@ -778,7 +778,7 @@ HWTEST_F_L0(BuiltinsSharedArrayTest, ForEach) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); \ JSTaggedValue result = Array::method(ecmaRuntimeCallInfo); \ TestHelper::TearDownFrame(thread, prev); \ - ASSERT_TRUE(JSTaggedValue::StrictEqual(result, JSTaggedValue(expected))); \ + ASSERT_TRUE(JSTaggedValue::StrictEqual(thread, result, JSTaggedValue(expected))); \ } while (false) #define ARRAY_BUILTIN_METHOD_TEST_CASE_ARG1(method, target, expected, arg0) \ @@ -791,7 +791,7 @@ HWTEST_F_L0(BuiltinsSharedArrayTest, ForEach) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); \ JSTaggedValue result = Array::method(ecmaRuntimeCallInfo); \ TestHelper::TearDownFrame(thread, prev); \ - ASSERT_TRUE(JSTaggedValue::StrictEqual(result, JSTaggedValue(expected))); \ + ASSERT_TRUE(JSTaggedValue::StrictEqual(thread, result, JSTaggedValue(expected))); \ } while (false) #define ARRAY_BUILTIN_METHOD_TEST_CASE_ARG2(method, target, expected, arg0, arg1) \ @@ -805,7 +805,7 @@ HWTEST_F_L0(BuiltinsSharedArrayTest, ForEach) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); \ JSTaggedValue result = Array::method(ecmaRuntimeCallInfo); \ TestHelper::TearDownFrame(thread, prev); \ - ASSERT_TRUE(JSTaggedValue::StrictEqual(result, JSTaggedValue(expected))); \ + ASSERT_TRUE(JSTaggedValue::StrictEqual(thread, result, JSTaggedValue(expected))); \ } while (false) // Array.IndexOf(searchElement [ , fromIndex ]) diff --git a/ecmascript/builtins/tests/builtins_shared_function_test.cpp b/ecmascript/builtins/tests/builtins_shared_function_test.cpp index d26b8439f5..a3ab5d637f 100644 --- a/ecmascript/builtins/tests/builtins_shared_function_test.cpp +++ b/ecmascript/builtins/tests/builtins_shared_function_test.cpp @@ -190,11 +190,11 @@ HWTEST_F_L0(BuiltinsSharedFunctionTest, FunctionPrototypeBind) JSHandle resultFunc(thread, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(thread), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(thread), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread, resultFunc->GetBoundArguments()); + JSHandle array(thread, resultFunc->GetBoundArguments(thread)); ASSERT_EQ(array->GetLength(), 0U); } @@ -215,14 +215,14 @@ HWTEST_F_L0(BuiltinsSharedFunctionTest, FunctionPrototypeBind1) JSHandle resultFunc(thread, reinterpret_cast(result.GetRawData())); // test BoundTarget - ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(thread), target.GetTaggedValue()); // test BoundThis - ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(thread), thisArg.GetTaggedValue()); // test BoundArguments - JSHandle array(thread, resultFunc->GetBoundArguments()); + JSHandle array(thread, resultFunc->GetBoundArguments(thread)); ASSERT_EQ(array->GetLength(), 2U); - JSTaggedValue elem = array->Get(0); - JSTaggedValue elem1 = array->Get(1); + JSTaggedValue elem = array->Get(thread, 0); + JSTaggedValue elem1 = array->Get(thread, 1); ASSERT_EQ(elem.GetRawData(), JSTaggedValue(123).GetRawData()); ASSERT_EQ(elem1.GetRawData(), str.GetTaggedType()); @@ -250,14 +250,14 @@ HWTEST_F_L0(BuiltinsSharedFunctionTest, FunctionPrototypeBind2) JSHandle resultFunc(thread, reinterpret_cast(result.GetRawData())); // test BoundThis - ASSERT_EQ(resultFunc->GetBoundThis(), thisArg.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundThis(thread), thisArg.GetTaggedValue()); // test BoundTarget - ASSERT_EQ(resultFunc->GetBoundTarget(), target.GetTaggedValue()); + ASSERT_EQ(resultFunc->GetBoundTarget(thread), target.GetTaggedValue()); // test BoundArguments - JSHandle array(thread, resultFunc->GetBoundArguments()); + JSHandle array(thread, resultFunc->GetBoundArguments(thread)); ASSERT_EQ(array->GetLength(), 2U); - JSTaggedValue elem = array->Get(0); - JSTaggedValue elem1 = array->Get(1); + JSTaggedValue elem = array->Get(thread, 0); + JSTaggedValue elem1 = array->Get(thread, 1); ASSERT_EQ(elem.GetRawData(), JSTaggedValue(123).GetRawData()); ASSERT_TRUE(elem1.IsString()); diff --git a/ecmascript/builtins/tests/builtins_shared_map_test.cpp b/ecmascript/builtins/tests/builtins_shared_map_test.cpp index 11867beb85..b51eb2c9fc 100644 --- a/ecmascript/builtins/tests/builtins_shared_map_test.cpp +++ b/ecmascript/builtins/tests/builtins_shared_map_test.cpp @@ -361,7 +361,7 @@ HWTEST_F_L0(BuiltinsSharedMapTest, Species) EXPECT_EQ(value, newTarget.GetTaggedValue()); JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread, valueHandle)); - EXPECT_EQ(JSTaggedValue::GetPrototype(thread, map), constructor->GetFunctionPrototype()); + EXPECT_EQ(JSTaggedValue::GetPrototype(thread, map), constructor->GetFunctionPrototype(thread)); JSHandle key1(factory->NewFromASCII("set")); JSTaggedValue value1 = JSObject::GetProperty(thread, map, key1).GetValue().GetTaggedValue(); diff --git a/ecmascript/builtins/tests/builtins_shared_set_test.cpp b/ecmascript/builtins/tests/builtins_shared_set_test.cpp index d6c44693a6..164441d205 100644 --- a/ecmascript/builtins/tests/builtins_shared_set_test.cpp +++ b/ecmascript/builtins/tests/builtins_shared_set_test.cpp @@ -335,7 +335,7 @@ HWTEST_F_L0(BuiltinsSharedSetTest, Species) EXPECT_TRUE(!stringTag.GetTaggedValue().IsUndefined()); JSHandle constructor = JSHandle::Cast(JSTaggedValue::ToObject(thread, valueHandle)); - EXPECT_EQ(JSTaggedValue::GetPrototype(thread, set), constructor->GetFunctionPrototype()); + EXPECT_EQ(JSTaggedValue::GetPrototype(thread, set), constructor->GetFunctionPrototype(thread)); JSHandle key1(factory->NewFromASCII("add")); JSTaggedValue value1 = JSObject::GetProperty(thread, set, key1).GetValue().GetTaggedValue(); diff --git a/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp b/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp index 6acc5254d7..b405561207 100644 --- a/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp +++ b/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp @@ -187,14 +187,14 @@ HWTEST_F_L0(BuiltinsSharedArrayBufferTest, IsShared) { // is not SharedBuffer JSHandle jsArrayBuffer(thread, CreateJSArrayBuffer(thread)); - bool result = BuiltinsSharedArrayBuffer::IsShared(jsArrayBuffer.GetTaggedValue()); + bool result = BuiltinsSharedArrayBuffer::IsShared(thread, jsArrayBuffer.GetTaggedValue()); ASSERT_EQ(result, false); // no BufferData JSTaggedValue tagged1 = BuiltTestUtil::CreateBuiltinsSharedArrayBuffer(thread, 0); JSHandle arrBuf1(thread, JSArrayBuffer::Cast(reinterpret_cast(tagged1.GetRawData()))); arrBuf1->SetArrayBufferData(thread, JSTaggedValue::Null()); - bool result1 = BuiltinsSharedArrayBuffer::IsShared(arrBuf1.GetTaggedValue()); + bool result1 = BuiltinsSharedArrayBuffer::IsShared(thread, arrBuf1.GetTaggedValue()); ASSERT_EQ(result1, false); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_sharedobject_test.cpp b/ecmascript/builtins/tests/builtins_sharedobject_test.cpp index 5c44deee0a..3d3ecf3f40 100644 --- a/ecmascript/builtins/tests/builtins_sharedobject_test.cpp +++ b/ecmascript/builtins/tests/builtins_sharedobject_test.cpp @@ -46,7 +46,7 @@ HWTEST_F_L0(BuiltinsSharedObjectTest, SharedObject) ASSERT_FALSE(hclass->IsConstructor()); ASSERT_FALSE(hclass->IsCallable()); ASSERT_TRUE(hclass->IsJSSharedObject()); - ASSERT_TRUE(hclass->GetProto().IsNull()); + ASSERT_TRUE(hclass->GetProto(thread).IsNull()); // SharedObject PropertyDescriptor desc(thread); @@ -61,7 +61,7 @@ HWTEST_F_L0(BuiltinsSharedObjectTest, SharedObject) ASSERT_TRUE(ctorHClass->IsJSSharedFunction()); // SharedFunction.prototype - auto proto = ctorHClass->GetProto(); + auto proto = ctorHClass->GetProto(thread); ASSERT_EQ(proto, env->GetSFunctionPrototype().GetTaggedValue()); ASSERT_TRUE(proto.IsJSSharedFunction()); JSHClass *protoHClass = proto.GetTaggedObject()->GetClass(); @@ -70,7 +70,7 @@ HWTEST_F_L0(BuiltinsSharedObjectTest, SharedObject) ASSERT_TRUE(protoHClass->IsCallable()); // SharedObject.prototype - auto sObjProto = protoHClass->GetProto(); + auto sObjProto = protoHClass->GetProto(thread); ASSERT_EQ(sObjProto, sharedObjectPrototype.GetTaggedValue()); ASSERT_TRUE(sObjProto.IsJSSharedObject()); JSHClass *sObjProtoHClass = sObjProto.GetTaggedObject()->GetClass(); @@ -132,7 +132,7 @@ HWTEST_F_L0(BuiltinsSharedObjectTest, SendableMethod) JSHandle method = factory->NewSMethod(methodLiteral); method->SetFunctionKind(FunctionKind::BASE_CONSTRUCTOR); JSHandle func = factory->NewJSSendableFunction(method); - ASSERT_TRUE(Method::Cast(func->GetMethod())->IsSendableMethod()); + ASSERT_TRUE(Method::Cast(func->GetMethod(thread))->IsSendableMethod()); uint32_t methodOffset1 = 101; MethodLiteral *methodLiteral1 = new MethodLiteral(EntityId(methodOffset1)); @@ -140,6 +140,6 @@ HWTEST_F_L0(BuiltinsSharedObjectTest, SendableMethod) method1->SetIsSendable(true); JSHandle func1 = factory->NewSFunctionByHClass( method1, JSHandle::Cast(env->GetSFunctionClassWithoutProto())); - ASSERT_TRUE(Method::Cast(func1->GetMethod())->IsSendableMethod()); + ASSERT_TRUE(Method::Cast(func1->GetMethod(thread))->IsSendableMethod()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_string_test.cpp b/ecmascript/builtins/tests/builtins_string_test.cpp index 33ea0402a2..445972ed9d 100644 --- a/ecmascript/builtins/tests/builtins_string_test.cpp +++ b/ecmascript/builtins/tests/builtins_string_test.cpp @@ -162,7 +162,7 @@ HWTEST_F_L0(BuiltinsStringTest, StringConstructor1) JSHandle ref(thread, JSPrimitiveRef::Cast(value.GetTaggedObject())); JSHandle test = factory->NewFromASCII("ABC"); ASSERT_EQ(EcmaStringAccessor::Compare(instance, - JSHandle(thread, EcmaString::Cast(ref->GetValue())), test), 0); + JSHandle(thread, EcmaString::Cast(ref->GetValue(thread))), test), 0); } // String.fromCharCode(65, 66, 67) @@ -528,7 +528,7 @@ HWTEST_F_L0(BuiltinsStringTest, toLowerCase1) ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSHandle test = factory->NewFromASCII("abc"); - ASSERT_TRUE(JSTaggedValue::SameValue(resultHandle.GetTaggedValue(), test.GetTaggedValue())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, resultHandle.GetTaggedValue(), test.GetTaggedValue())); } // "abc".toUpperCase() @@ -926,7 +926,8 @@ HWTEST_F_L0(BuiltinsStringTest, Raw) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsString::Raw(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(reinterpret_cast(result.GetRawData()), *test)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result.GetRawData()), + *test)); } HWTEST_F_L0(BuiltinsStringTest, Replace) @@ -941,7 +942,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) auto result = StringAlgorithm(thread, thisStr.GetTaggedValue(), args, 8, AlgorithmType::REPLACE); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result.GetRawData()), + *expected)); JSHandle replaceStr1 = factory->NewFromASCII("abc$$"); JSHandle expected1 = factory->NewFromASCII("Twas the night before abc$..."); @@ -951,7 +953,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) JSHandle resultString1(thread, result1); ASSERT_TRUE(result1.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString1, *expected1)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString1, *expected1)); JSHandle replaceStr2 = factory->NewFromASCII("abc$$dd"); JSHandle expected2 = factory->NewFromASCII("Twas the night before abc$dd..."); @@ -961,7 +963,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) JSHandle resultString2(thread, result2); ASSERT_TRUE(result2.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString2, *expected2)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString2, *expected2)); JSHandle replaceStr3 = factory->NewFromASCII("abc$&dd"); JSHandle expected3 = factory->NewFromASCII("Twas the night before abcXmasdd..."); @@ -971,7 +973,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) JSHandle resultString3(thread, result3); ASSERT_TRUE(result3.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString3, *expected3)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString3, *expected3)); JSHandle replaceStr4 = factory->NewFromASCII("abc$`dd"); JSHandle expected4 = @@ -982,7 +984,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) JSHandle resultString4(thread, result4); ASSERT_TRUE(result4.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString4, *expected4)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString4, *expected4)); } HWTEST_F_L0(BuiltinsStringTest, Replace2) @@ -997,7 +999,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) auto result = StringAlgorithm(thread, thisStr.GetTaggedValue(), args, 8, AlgorithmType::REPLACE); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result.GetRawData()), + *expected)); JSHandle replaceStr2 = factory->NewFromASCII("abc$`dd$\'$ff"); JSHandle expected2 = @@ -1009,7 +1012,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) JSHandle resultString2(thread, result2); ASSERT_TRUE(result2.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString2, *expected2)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString2, *expected2)); JSHandle replaceStr3 = factory->NewFromASCII("abc$`dd$\'$"); JSHandle expected3 = @@ -1020,7 +1023,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) JSHandle resultString3(thread, result3); ASSERT_TRUE(result3.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString3, *expected3)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString3, *expected3)); JSHandle replaceStr4 = factory->NewFromASCII("abc$`dd$$"); JSHandle expected4 = @@ -1031,7 +1034,7 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) ASSERT_TRUE(result4.IsString()); JSHandle resultString4(thread, result4); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*resultString4, *expected4)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resultString4, *expected4)); } HWTEST_F_L0(BuiltinsStringTest, Replace3) @@ -1047,7 +1050,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace3) auto result = StringAlgorithm(thread, thisStr.GetTaggedValue(), args, 8, AlgorithmType::REPLACE); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result.GetRawData()), + *expected)); } HWTEST_F_L0(BuiltinsStringTest, Replace4) @@ -1071,7 +1075,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace4) auto result = StringAlgorithm(thread, thisStr.GetTaggedValue(), args, 8, AlgorithmType::REPLACE); ASSERT_TRUE(result.IsString()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread,reinterpret_cast(result.GetRawData()), + *expected)); } void SplitCommon(JSThread *thread, std::vector> expecteds, JSHandle &resultArray) @@ -1082,7 +1087,7 @@ void SplitCommon(JSThread *thread, std::vector> expecteds, JSObject::GetProperty(thread, resultObj, JSHandle(thread, JSTaggedValue(static_cast(i)))) .GetValue()); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*str, *expecteds[i])); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *str, *expecteds[i])); } } diff --git a/ecmascript/builtins/tests/builtins_symbol_test.cpp b/ecmascript/builtins/tests/builtins_symbol_test.cpp index 9c77a1c0d5..69b1fb73d7 100644 --- a/ecmascript/builtins/tests/builtins_symbol_test.cpp +++ b/ecmascript/builtins/tests/builtins_symbol_test.cpp @@ -207,13 +207,13 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolWithParameterFor) JSHandle string = ecmaVM->GetFactory()->NewFromASCII("ccc"); ASSERT_EQ(EcmaStringAccessor(string).GetLength(), 3U); JSHandle string_handle(string); - ASSERT_EQ(tableHandle->ContainsKey(string_handle.GetTaggedValue()), false); + ASSERT_EQ(tableHandle->ContainsKey(thread, string_handle.GetTaggedValue()), false); JSHandle symbol = ecmaVM->GetFactory()->NewSymbolWithTableWithChar("ccc"); std::vector args{string.GetTaggedValue()}; auto result = SymbolAlgorithm(thread, JSTaggedValue::Undefined(), args, 6, AlgorithmType::BUILTIN_FOR); - ASSERT_EQ(tableHandle->ContainsKey(string_handle.GetTaggedValue()), true); + ASSERT_EQ(tableHandle->ContainsKey(thread, string_handle.GetTaggedValue()), true); JSTaggedValue target(*symbol); ASSERT_EQ(result.GetRawData() == target.GetRawData(), true); @@ -243,7 +243,7 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolKeyFor) ASSERT_TRUE(otherResult.IsString()); JSHandle tableHandle(env->GetRegisterSymbols()); JSTaggedValue stringValue(*string); - ASSERT_EQ(tableHandle->ContainsKey(stringValue), true); + ASSERT_EQ(tableHandle->ContainsKey(thread, stringValue), true); // not symbol args[0] = JSTaggedValue::Undefined(); @@ -292,7 +292,7 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolConstructor) TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); JSSymbol *sym = reinterpret_cast(result.GetRawData()); - ASSERT_EQ(sym->GetDescription().IsUndefined(), true); + ASSERT_EQ(sym->GetDescription(thread).IsUndefined(), true); JSHandle string = ecmaVM->GetFactory()->NewFromASCII("ddd"); @@ -305,7 +305,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolConstructor) JSTaggedValue result1 = BuiltinsSymbol::SymbolConstructor(otherEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultString = JSTaggedValue::ToString( - thread, JSHandle(thread, reinterpret_cast(result1.GetRawData())->GetDescription())); + thread, + JSHandle(thread, reinterpret_cast(result1.GetRawData())->GetDescription(thread))); ASSERT_EQ(EcmaStringAccessor::Compare(ecmaVM, resultString, string), 0); } @@ -327,7 +328,7 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolGetter) ASSERT_TRUE(result.IsString()); EcmaString *resString = reinterpret_cast(result.GetRawData()); ASSERT_EQ(EcmaStringAccessor(resString).GetLength(), 0U); - ASSERT_EQ(EcmaStringAccessor::StringsAreEqual(resString, *string), true); + ASSERT_EQ(EcmaStringAccessor::StringsAreEqual(thread, resString, *string), true); // value is not symbol JSHandle symbolObject(env->GetSymbolFunction()); @@ -343,7 +344,7 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolGetter) ASSERT_TRUE(result.IsString()); resString = reinterpret_cast(result.GetRawData()); ASSERT_EQ(EcmaStringAccessor(resString).GetLength(), 0U); - ASSERT_EQ(EcmaStringAccessor::StringsAreEqual(resString, *string), true); + ASSERT_EQ(EcmaStringAccessor::StringsAreEqual(thread, resString, *string), true); // Undefined ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); diff --git a/ecmascript/builtins/tests/builtins_weak_map_test.cpp b/ecmascript/builtins/tests/builtins_weak_map_test.cpp index 304243f564..2682654616 100644 --- a/ecmascript/builtins/tests/builtins_weak_map_test.cpp +++ b/ecmascript/builtins/tests/builtins_weak_map_test.cpp @@ -97,7 +97,7 @@ HWTEST_F_L0(BuiltinsWeakMapTest, CreateAndGetSize) JSTaggedValue result1 = BuiltinsWeakMap::WeakMapConstructor(ecmaRuntimeCallInfo); JSHandle weakMap(thread, JSWeakMap::Cast(reinterpret_cast(result1.GetRawData()))); - EXPECT_EQ(weakMap->GetSize(), 1); + EXPECT_EQ(weakMap->GetSize(thread), 1); } HWTEST_F_L0(BuiltinsWeakMapTest, SetAndHas) @@ -124,7 +124,7 @@ HWTEST_F_L0(BuiltinsWeakMapTest, SetAndHas) JSTaggedValue result2 = BuiltinsWeakMap::Set(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); JSWeakMap *jsWeakMap = JSWeakMap::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(jsWeakMap->GetSize(), 1); + EXPECT_EQ(jsWeakMap->GetSize(thread), 1); // test Has() auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -155,7 +155,7 @@ void KeySetCommon(JSThread* thread, JSHandle& weakMap, JSHandle(result1.GetRawData())); - EXPECT_EQ(jsWeakMap->GetSize(), static_cast(val) + 1); + EXPECT_EQ(jsWeakMap->GetSize(thread), static_cast(val) + 1); } HWTEST_F_L0(BuiltinsWeakMapTest, DeleteAndRemove) diff --git a/ecmascript/builtins/tests/builtins_weak_set_test.cpp b/ecmascript/builtins/tests/builtins_weak_set_test.cpp index f0310a88f1..f4fdeff213 100644 --- a/ecmascript/builtins/tests/builtins_weak_set_test.cpp +++ b/ecmascript/builtins/tests/builtins_weak_set_test.cpp @@ -94,7 +94,7 @@ HWTEST_F_L0(BuiltinsWeakSetTest, CreateAndGetSize) TestHelper::TearDownFrame(thread, prev); JSHandle weakSetResult(thread, JSWeakSet::Cast(reinterpret_cast(result1.GetRawData()))); - EXPECT_EQ(weakSetResult->GetSize(), 5); + EXPECT_EQ(weakSetResult->GetSize(thread), 5); } HWTEST_F_L0(BuiltinsWeakSetTest, AddAndHas) @@ -119,7 +119,7 @@ HWTEST_F_L0(BuiltinsWeakSetTest, AddAndHas) JSTaggedValue result2 = BuiltinsWeakSet::Add(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result2.GetRawData())); - EXPECT_EQ(jsWeakSet->GetSize(), 1); + EXPECT_EQ(jsWeakSet->GetSize(thread), 1); } // test Has() @@ -151,7 +151,7 @@ void AddCommon(JSThread* thread, JSHandle& weakSet, JSHandle(result1.GetRawData())); - EXPECT_EQ(jsWeakSet->GetSize(), i + 1); + EXPECT_EQ(jsWeakSet->GetSize(thread), i + 1); } void HasAndDeleteCommon(JSThread* thread, JSHandle& weakSet, JSTaggedValue& lastKey) diff --git a/ecmascript/common.h b/ecmascript/common.h index 3bfdf8cb77..14f0b86fb8 100644 --- a/ecmascript/common.h +++ b/ecmascript/common.h @@ -25,6 +25,9 @@ namespace panda { namespace ecmascript { +// placeholder used when unsure how to get the thread arg +#define THREAD_ARG_PLACEHOLDER static_cast(nullptr) + #define SCOPE_LIST(V) \ V(TotalGC) \ V(Initialize) \ diff --git a/ecmascript/compiler/aot_constantpool_patcher.cpp b/ecmascript/compiler/aot_constantpool_patcher.cpp index 8115b0b6f3..1b6bcd85af 100644 --- a/ecmascript/compiler/aot_constantpool_patcher.cpp +++ b/ecmascript/compiler/aot_constantpool_patcher.cpp @@ -25,7 +25,7 @@ void AotConstantpoolPatcher::SetPrototypeForTransitions(JSThread *thread, JSHCla backHClass.pop(); hclass->SetProto(thread, proto); - auto transitions = current->GetTransitions(); + auto transitions = current->GetTransitions(thread); if (transitions.IsUndefined()) { continue; } @@ -36,7 +36,7 @@ void AotConstantpoolPatcher::SetPrototypeForTransitions(JSThread *thread, JSHCla } ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - dict->IterateEntryValue([&backHClass] (JSHClass *cache) { + dict->IterateEntryValue(thread, [&backHClass] (JSHClass *cache) { backHClass.push(JSHClass::Cast(cache)); }); } @@ -44,7 +44,7 @@ void AotConstantpoolPatcher::SetPrototypeForTransitions(JSThread *thread, JSHCla void AotConstantpoolPatcher::SetObjectFunctionFromConstPool(JSThread *thread, JSHandle newConstPool) { - auto aotHCInfo = newConstPool->GetAotHClassInfo(); + auto aotHCInfo = newConstPool->GetAotHClassInfo(thread); if (!aotHCInfo.IsTaggedArray()) { return; } @@ -52,7 +52,7 @@ void AotConstantpoolPatcher::SetObjectFunctionFromConstPool(JSThread *thread, JS if (aotHCInfoArray->GetLength() <= 0) { return; } - JSTaggedValue ihc = aotHCInfoArray->Get(0); + JSTaggedValue ihc = aotHCInfoArray->Get(thread, 0); if (!ihc.IsJSHClass()) { return; } @@ -66,9 +66,9 @@ void AotConstantpoolPatcher::SetObjectFunctionFromConstPool(JSThread *thread, JS auto env = thread->GetGlobalEnv(); if (env->GetObjectFunctionTsNapiClass() == env->GetObjectFunctionNapiClass()) { JSHandle objectFunctionNapiClass(env->GetObjectFunctionNapiClass()); - objectFunctionIHC->SetPrototype(thread, objectFunctionNapiClass->GetProto()); + objectFunctionIHC->SetPrototype(thread, objectFunctionNapiClass->GetProto(thread)); JSHClass::EnableProtoChangeMarker(thread, objectFunctionIHC); - SetPrototypeForTransitions(thread, *objectFunctionIHC, objectFunctionNapiClass->GetProto()); + SetPrototypeForTransitions(thread, *objectFunctionIHC, objectFunctionNapiClass->GetProto(thread)); env->SetObjectFunctionTsNapiClass(thread, objectFunctionIHC.GetTaggedValue()); } } diff --git a/ecmascript/compiler/aot_file/aot_file_manager.cpp b/ecmascript/compiler/aot_file/aot_file_manager.cpp index 038205a163..4f95b518c5 100644 --- a/ecmascript/compiler/aot_file/aot_file_manager.cpp +++ b/ecmascript/compiler/aot_file/aot_file_manager.cpp @@ -398,7 +398,8 @@ void AOTFileManager::SetAOTMainFuncEntry(JSHandle mainFunc, const JS } mainMethod->SetAotCodeBit(true); mainMethod->SetNativeBit(false); - Method *method = mainFunc->GetCallTarget(); + JSThread *thread = vm_->GetJSThread(); + Method *method = mainFunc->GetCallTarget(thread); method->SetDeoptThreshold(vm_->GetJSOptions().GetDeoptThreshold()); method->SetCodeEntryAndMarkAOTWhenBinding(static_cast(mainEntry)); method->SetFpDelta(fpDelta); @@ -408,7 +409,7 @@ void AOTFileManager::SetAOTMainFuncEntry(JSHandle mainFunc, const JS PrintAOTEntry(jsPandaFile, method, mainEntry); #endif - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); ASSERT(methodLiteral != nullptr); methodLiteral->SetAotCodeBit(true); methodLiteral->SetIsFastCall(isFastCall); @@ -441,7 +442,7 @@ void AOTFileManager::SetAOTFuncEntry(const JSPandaFile *jsPandaFile, JSFunction *canFastCall = entry.isFastCall_; } - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + MethodLiteral *methodLiteral = method->GetMethodLiteral(vm_->GetJSThread()); ASSERT(methodLiteral != nullptr); methodLiteral->SetAotCodeBit(true); methodLiteral->SetIsFastCall(entry.isFastCall_); @@ -583,27 +584,28 @@ void AOTFileManager::ParseDeserializedData(const CString &snapshotFileName, JSTa JSMutableHandle cpList(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < aiDataLen; i += AOTSnapshotConstants::SNAPSHOT_DATA_ITEM_SIZE) { // handle file info - fileInfo.Update(aiData->Get(i + SnapshotGlobalData::Cast(SnapshotGlobalData::CP_TOP_ITEM::PANDA_INFO_ID))); + fileInfo.Update(aiData->Get(thread, i + SnapshotGlobalData::Cast(SnapshotGlobalData::CP_TOP_ITEM::PANDA_INFO_ID))); auto nameOffset = SnapshotGlobalData::Cast(SnapshotGlobalData::CP_PANDA_INFO_ITEM::NAME_ID); auto indexOffset = SnapshotGlobalData::Cast(SnapshotGlobalData::CP_PANDA_INFO_ITEM::INDEX_ID); - CString fileNameCStr = EcmaStringAccessor(fileInfo->Get(nameOffset)).ToCString(); - std::string fileNameStr = EcmaStringAccessor(fileInfo->Get(nameOffset)).ToStdString(); - uint32_t fileIndex = static_cast(fileInfo->Get(indexOffset).GetInt()); + CString fileNameCStr = EcmaStringAccessor(fileInfo->Get(thread, nameOffset)).ToCString(thread); + std::string fileNameStr = EcmaStringAccessor(fileInfo->Get(thread, nameOffset)).ToStdString(thread); + uint32_t fileIndex = static_cast(fileInfo->Get(thread, indexOffset).GetInt()); // handle constant pool - cpList.Update(aiData->Get(i + SnapshotGlobalData::Cast(SnapshotGlobalData::CP_TOP_ITEM::CP_ARRAY_ID))); + cpList.Update(aiData->Get(thread, i + SnapshotGlobalData::Cast(SnapshotGlobalData::CP_TOP_ITEM::CP_ARRAY_ID))); uint32_t cpLen = cpList->GetLength(); ASSERT(cpLen % AOTSnapshotConstants::SNAPSHOT_CP_ARRAY_ITEM_SIZE == 0); auto &PandaCpInfoInserted = fileNameToMulCpMap.try_emplace(fileNameCStr).first->second; PandaCpInfoInserted.fileIndex_ = fileIndex; MultiConstantPoolMap& cpMap = PandaCpInfoInserted.multiCpsMap_; if (cpLen > 0) { - JSTaggedValue cp = cpList->Get(AOTSnapshotConstants::SNAPSHOT_CP_ARRAY_ITEM_SIZE - 1); // first constpool + JSTaggedValue cp = cpList->Get(thread, + AOTSnapshotConstants::SNAPSHOT_CP_ARRAY_ITEM_SIZE - 1); // first constpool vm_->LoadProtoTransitionTable(cp); } JSMutableHandle cpHandle(thread, JSTaggedValue::Undefined()); for (uint32_t pos = 0; pos < cpLen; pos += AOTSnapshotConstants::SNAPSHOT_CP_ARRAY_ITEM_SIZE) { - int32_t constantPoolID = cpList->Get(pos).GetInt(); - cpHandle.Update(cpList->Get(pos + 1)); + int32_t constantPoolID = cpList->Get(thread, pos).GetInt(); + cpHandle.Update(cpList->Get(thread, pos + 1)); vm_->ResetProtoTransitionTableOnConstpool(cpHandle.GetTaggedValue()); cpMap.insert({constantPoolID, cpHandle.GetTaggedValue()}); // the arkui framework abc file constpool was patched here @@ -660,7 +662,7 @@ AOTFileManager::AOTFileManager(EcmaVM *vm) : vm_(vm), factory_(vm->GetFactory()) JSTaggedValue AOTFileManager::GetAbsolutePath(JSThread *thread, JSTaggedValue relativePathVal) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - CString relativePath = ConvertToString(relativePathVal); + CString relativePath = ConvertToString(thread, relativePathVal); CString absPath; if (!GetAbsolutePath(relativePath, absPath)) { LOG_FULL(FATAL) << "Get Absolute Path failed"; diff --git a/ecmascript/compiler/aot_file/aot_file_manager.h b/ecmascript/compiler/aot_file/aot_file_manager.h index 268c748df7..cae4e91379 100644 --- a/ecmascript/compiler/aot_file/aot_file_manager.h +++ b/ecmascript/compiler/aot_file/aot_file_manager.h @@ -94,7 +94,7 @@ public: inline JSTaggedValue GetIhc() const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetIhcOffset())); + return JSTaggedValue(Barriers::GetPrimitive(GetData(), GetIhcOffset())); } inline void SetChc(JSTaggedValue value) @@ -104,7 +104,7 @@ public: inline JSTaggedValue GetChc() const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetChcOffset())); + return JSTaggedValue(Barriers::GetPrimitive(GetData(), GetChcOffset())); } inline void SetLiteralType(JSTaggedValue value) @@ -114,14 +114,14 @@ public: inline int GetLiteralType() const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetLiteralTypeOffset())).GetInt(); + return JSTaggedValue(Barriers::GetPrimitive(GetData(), GetLiteralTypeOffset())).GetInt(); } void SetObjectToCache(JSThread *thread, uint32_t index, JSTaggedValue value); - inline JSTaggedValue GetObjectFromCache(uint32_t index) const + inline JSTaggedValue GetObjectFromCache(JSThread *thread, uint32_t index) const { - return Get(index); + return Get(thread, index); } private: diff --git a/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.cpp b/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.cpp index bcc635d415..b254256e75 100644 --- a/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.cpp +++ b/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.cpp @@ -65,12 +65,12 @@ JSHandle BaseSnapshotInfo::TryGetHClassFromCached(const JSHandle< const SnapshotGlobalData &globalData) const { DISALLOW_GARBAGE_COLLECTION; - JSHandle maybeCache(thread_, globalData.GetObjectLiteralHClassCache()); + JSHandle maybeCache(thread_, globalData.GetObjectLiteralHClassCache(thread_)); if (maybeCache->IsTaggedArray()) { size_t length = properties->GetLength(); uint32_t propsLen = 0; for (size_t i = 0; i < length; i += 2) { // 2: skip a pair of key and value - if (properties->Get(i).IsHole()) { + if (properties->Get(thread_, i).IsHole()) { break; } propsLen++; @@ -81,7 +81,7 @@ JSHandle BaseSnapshotInfo::TryGetHClassFromCached(const JSHandle< } JSHandle hclassCacheArr = JSHandle::Cast(maybeCache); - JSTaggedValue maybeHClass = hclassCacheArr->Get(propsLen); + JSTaggedValue maybeHClass = hclassCacheArr->Get(thread_, propsLen); if (!maybeHClass.IsJSHClass()) { return thread_->GlobalConstants()->GetHandledUndefined(); } @@ -89,10 +89,10 @@ JSHandle BaseSnapshotInfo::TryGetHClassFromCached(const JSHandle< JSMutableHandle key(thread_, JSTaggedValue::Undefined()); for (size_t fieldOffset = 0; fieldOffset < propsLen; fieldOffset++) { - key.Update(properties->Get(fieldOffset * 2)); // 2 : pair of key and value + key.Update(properties->Get(thread_, fieldOffset * 2)); // 2 : pair of key and value ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes = PropertyAttributes::Default(); - auto value = properties->Get(fieldOffset * 2 + 1); + auto value = properties->Get(thread_, fieldOffset * 2 + 1); if (value.IsAccessor()) { // 2: Meaning to double attributes.SetIsAccessor(true); } @@ -102,14 +102,14 @@ JSHandle BaseSnapshotInfo::TryGetHClassFromCached(const JSHandle< auto metadata = JSTaggedValue(attributes.GetPropertyMetaData()); auto rep = PropertyAttributes::TranslateToRep(value); - newClass = newClass->FindTransitions(key.GetTaggedValue(), metadata, rep); + newClass = newClass->FindTransitions(thread_, key.GetTaggedValue(), metadata, rep); if (newClass == nullptr) { return thread_->GlobalConstants()->GetHandledUndefined(); } } auto result = JSHandle(thread_, newClass); - if (JSObject::CheckPropertiesForRep(properties, propsLen, result)) { + if (JSObject::CheckPropertiesForRep(thread_, properties, propsLen, result)) { return JSHandle(result); } } @@ -132,12 +132,12 @@ void BaseSnapshotInfo::CollectLiteralInfo(JSHandle array, uint32_t uint32_t len = array->GetLength(); std::vector methodOffsetVec; for (uint32_t i = 0; i < len; i++) { - valueHandle.Update(array->Get(i)); + valueHandle.Update(array->Get(thread_, i)); uint32_t methodOffset = 0; if (valueHandle->IsJSFunction()) { - methodOffset = JSHandle(valueHandle)->GetCallTarget()->GetMethodId().GetOffset(); + methodOffset = JSHandle(valueHandle)->GetCallTarget(thread_)->GetMethodId().GetOffset(); } else if (valueHandle->IsFunctionTemplate()) { - auto method = Method::Cast(JSHandle(valueHandle)->GetMethod()); + auto method = Method::Cast(JSHandle(valueHandle)->GetMethod(thread_)); methodOffset = method->GetMethodId().GetOffset(); } if (methodOffset != 0) { @@ -167,13 +167,14 @@ void BaseSnapshotInfo::CollectLiteralInfo(JSHandle array, uint32_t snapshotConstantPool->SetObjectToCache(thread_, constantPoolIndex, aotLiteralInfo.GetTaggedValue()); } -bool BaseSnapshotInfo::CheckAOTPropertiesForRep(const JSHandle &properties, +bool BaseSnapshotInfo::CheckAOTPropertiesForRep(const JSThread *thread, + const JSHandle &properties, const JSHandle &hclass) { - auto layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + auto layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); for (size_t i = 0; i < properties->GetLength(); i++) { - auto attr = layout->GetAttr(i); - auto value = JSObject::ConvertValueWithRep(attr, properties->Get(i)); + auto attr = layout->GetAttr(thread, i); + auto value = JSObject::ConvertValueWithRep(attr, properties->Get(thread, i)); // If value.first is false, indicating that value cannot be converted to the expected value of // representation. For example, the representation is INT, but the value type is string. if (!value.first) { @@ -192,15 +193,15 @@ bool BaseSnapshotInfo::CheckAOTIhcPropertiesForRep(JSThread *thread, const JSHan JSHandle prototype; if (ihc->IsJSHClass()) { JSHandle ihclass(ihc); - prototype = JSHandle(thread, ihclass->GetProto()); + prototype = JSHandle(thread, ihclass->GetProto(thread)); } else { prototype = JSHandle(ihc); } ASSERT(!prototype->GetJSHClass()->IsDictionaryMode()); - JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties()); + JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties(thread)); JSHandle protohclass(thread, prototype->GetJSHClass()); - return CheckAOTPropertiesForRep(nonStaticProperties, protohclass); + return CheckAOTPropertiesForRep(thread, nonStaticProperties, protohclass); } bool BaseSnapshotInfo::CheckAOTChcPropertiesForRep(JSThread *thread, const JSHandle &chc, @@ -211,8 +212,8 @@ bool BaseSnapshotInfo::CheckAOTChcPropertiesForRep(JSThread *thread, const JSHan } JSHandle chclass(thread, JSHClass::Cast(chc->GetTaggedObject())); ASSERT(!chclass->IsDictionaryMode()); - JSHandle staticProperties(thread, extractor->GetStaticProperties()); - return CheckAOTPropertiesForRep(staticProperties, chclass); + JSHandle staticProperties(thread, extractor->GetStaticProperties(thread)); + return CheckAOTPropertiesForRep(thread, staticProperties, chclass); } void StringSnapshotInfo::StoreDataToGlobalData(SnapshotGlobalData &globalData, const std::set&) @@ -221,7 +222,7 @@ void StringSnapshotInfo::StoreDataToGlobalData(SnapshotGlobalData &globalData, c const ItemData &data = item.second; uint32_t snapshotCpArrIdx = globalData.GetCpArrIdxByConstanPoolId(data.constantPoolId_); JSHandle snapshotCpArr(thread_, globalData.GetCurSnapshotCpArray()); - JSHandle snapshotCp(thread_, snapshotCpArr->Get(snapshotCpArrIdx)); + JSHandle snapshotCp(thread_, snapshotCpArr->Get(thread_, snapshotCpArrIdx)); // Lazy ConstantPool String Loading snapshotCp->SetObjectToCache(thread_, data.constantPoolIdx_, JSTaggedValue::Hole()); } @@ -245,7 +246,7 @@ void MethodSnapshotInfo::StoreDataToGlobalData(SnapshotGlobalData &globalData, uint32_t snapshotCpArrIdx = globalData.GetCpArrIdxByConstanPoolId(data.constantPoolId_); JSHandle snapshotCpArr(thread_, globalData.GetCurSnapshotCpArray()); - JSHandle snapshotCp(thread_, snapshotCpArr->Get(snapshotCpArrIdx)); + JSHandle snapshotCp(thread_, snapshotCpArr->Get(thread_, snapshotCpArrIdx)); JSHandle ihc = thread_->GlobalConstants()->GetHandledUndefined(); if (hasAbcId) { @@ -289,11 +290,11 @@ void ClassLiteralSnapshotInfo::StoreDataToGlobalData(SnapshotGlobalData &globalD JSHandle cp = GetUnsharedConstpool(data); auto literalObj = ConstantPool::GetClassLiteralFromCache(thread_, cp, data.constantPoolIdx_, data.recordName_); JSHandle classLiteral(thread_, literalObj); - JSHandle arrayHandle(thread_, classLiteral->GetArray()); + JSHandle arrayHandle(thread_, classLiteral->GetArray(thread_)); uint32_t snapshotCpArrIdx = globalData.GetCpArrIdxByConstanPoolId(data.constantPoolId_); JSHandle snapshotCpArr(thread_, globalData.GetCurSnapshotCpArray()); - JSHandle snapshotCp(thread_, snapshotCpArr->Get(snapshotCpArrIdx)); + JSHandle snapshotCp(thread_, snapshotCpArr->Get(thread_, snapshotCpArrIdx)); uint32_t methodId = cp->GetEntityId(data.ctorMethodOffset_).GetOffset(); JSHandle undefinedHandle = thread_->GlobalConstants()->GetHandledUndefined(); @@ -343,7 +344,7 @@ void ObjectLiteralSnapshotInfo::StoreDataToGlobalData(SnapshotGlobalData &global uint32_t snapshotCpArrIdx = globalData.GetCpArrIdxByConstanPoolId(data.constantPoolId_); JSHandle snapshotCpArr(thread_, globalData.GetCurSnapshotCpArray()); - JSHandle snapshotCp(thread_, snapshotCpArr->Get(snapshotCpArrIdx)); + JSHandle snapshotCp(thread_, snapshotCpArr->Get(thread_, snapshotCpArrIdx)); JSHandle ihc = thread_->GlobalConstants()->GetHandledUndefined(); JSHandle chc = thread_->GlobalConstants()->GetHandledUndefined(); @@ -374,7 +375,7 @@ void ArrayLiteralSnapshotInfo::StoreDataToGlobalData(SnapshotGlobalData &globalD thread_, jsPandaFile_, id, cp, data.recordName_); uint32_t snapshotCpArrIdx = globalData.GetCpArrIdxByConstanPoolId(data.constantPoolId_); JSHandle snapshotCpArr(thread_, globalData.GetCurSnapshotCpArray()); - JSHandle snapshotCp(thread_, snapshotCpArr->Get(snapshotCpArrIdx)); + JSHandle snapshotCp(thread_, snapshotCpArr->Get(thread_, snapshotCpArrIdx)); JSHandle ihc = thread_->GlobalConstants()->GetHandledUndefined(); JSHandle chc = thread_->GlobalConstants()->GetHandledUndefined(); CollectLiteralInfo(literal, data.constantPoolIdx_, snapshotCp, skippedMethods, ihc, chc); diff --git a/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.h b/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.h index dc32cbea83..43e00713ab 100644 --- a/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.h +++ b/ecmascript/compiler/aot_snapshot/snapshot_constantpool_data.h @@ -83,7 +83,8 @@ protected: JSHandle ihc, JSHandle chc); JSHandle GetUnsharedConstpool(const ItemData &data); - static bool CheckAOTPropertiesForRep(const JSHandle &properties, const JSHandle &hclass); + static bool CheckAOTPropertiesForRep(const JSThread *thread, const JSHandle &properties, + const JSHandle &hclass); static bool CheckAOTIhcPropertiesForRep(JSThread *thread, const JSHandle &ihc, const JSHandle &extractor); diff --git a/ecmascript/compiler/aot_snapshot/snapshot_global_data.cpp b/ecmascript/compiler/aot_snapshot/snapshot_global_data.cpp index 31224c00eb..099353cc62 100644 --- a/ecmascript/compiler/aot_snapshot/snapshot_global_data.cpp +++ b/ecmascript/compiler/aot_snapshot/snapshot_global_data.cpp @@ -25,8 +25,8 @@ JSHandle ReviseData::GetConstantPoolFromSnapshotData(JSThread *thr { JSHandle data(thread, globalData->GetData()); auto cpArrayOffset = SnapshotGlobalData::Cast(SnapshotGlobalData::CP_TOP_ITEM::CP_ARRAY_ID); - JSHandle cpArr(thread, data->Get(dataIdx + cpArrayOffset)); - return JSHandle(thread, cpArr->Get(cpArrayIdx)); + JSHandle cpArr(thread, data->Get(thread, dataIdx + cpArrayOffset)); + return JSHandle(thread, cpArr->Get(thread, cpArrayIdx)); } void ReviseData::Resolve(JSThread *thread, const SnapshotGlobalData *globalData, @@ -36,7 +36,7 @@ void ReviseData::Resolve(JSThread *thread, const SnapshotGlobalData *globalData, JSHandle newCP = GetConstantPoolFromSnapshotData(thread, globalData, item.dataIdx_, item.cpArrayIdx_); - JSTaggedValue val = newCP->GetObjectFromCache(item.constpoolIdx_); + JSTaggedValue val = newCP->GetObjectFromCache(thread, item.constpoolIdx_); if (val.IsHole()) { continue; } @@ -60,7 +60,7 @@ void ReviseData::Resolve(JSThread *thread, const SnapshotGlobalData *globalData, AOTLiteralInfo *aotLiteralInfo = AOTLiteralInfo::Cast(val.GetTaggedObject()); uint32_t aotLiteralInfoLen = aotLiteralInfo->GetCacheLength(); for (uint32_t i = 0; i < aotLiteralInfoLen; ++i) { - JSTaggedValue methodOffsetVal = aotLiteralInfo->GetObjectFromCache(i); + JSTaggedValue methodOffsetVal = aotLiteralInfo->GetObjectFromCache(thread, i); if (methodOffsetVal.GetInt() == static_cast(AOTLiteralInfo::NO_FUNC_ENTRY_VALUE)) { continue; } diff --git a/ecmascript/compiler/aot_snapshot/snapshot_global_data.h b/ecmascript/compiler/aot_snapshot/snapshot_global_data.h index be6fbef9ee..228b212e1e 100644 --- a/ecmascript/compiler/aot_snapshot/snapshot_global_data.h +++ b/ecmascript/compiler/aot_snapshot/snapshot_global_data.h @@ -180,12 +180,12 @@ public: return constantIndexInfo_; } - JSTaggedValue GetObjectLiteralHClassCache() const + JSTaggedValue GetObjectLiteralHClassCache(JSThread *thread) const { if (hclassInfo_.IsTaggedArray()) { auto hclassInfoArr = TaggedArray::Cast(hclassInfo_); ASSERT(hclassInfoArr->GetLength() > 0); - return hclassInfoArr->Get(hclassInfoArr->GetLength() - 1); + return hclassInfoArr->Get(thread, hclassInfoArr->GetLength() - 1); } return JSTaggedValue::Undefined(); } diff --git a/ecmascript/compiler/builtins/builtins_number_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_number_stub_builder.cpp index ffe28db0a1..9b9628285c 100644 --- a/ecmascript/compiler/builtins/builtins_number_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_number_stub_builder.cpp @@ -40,7 +40,7 @@ void BuiltinsNumberStubBuilder::ParseFloat(Variable *result, Label *exit, Label BRANCH(IsString(glue_, msg), &stringObj, slowPath); Bind(&stringObj); { - *result = CallNGCRuntime(glue_, RTSTUB_ID(NumberHelperStringToDouble), { msg }); + *result = CallNGCRuntime(glue_, RTSTUB_ID(NumberHelperStringToDouble), { glue_, msg }); Jump(exit); } } @@ -74,7 +74,7 @@ void BuiltinsNumberStubBuilder::ParseInt(Variable *result, Label *exit, Label *s } Bind(&radixIsSpecialInt); { - *result = CallNGCRuntime(glue_, RTSTUB_ID(StringToNumber), { msg, *radix }); + *result = CallNGCRuntime(glue_, RTSTUB_ID(StringToNumber), { glue_, msg, *radix }); Jump(exit); } } diff --git a/ecmascript/compiler/builtins/builtins_typedarray_stub_builder.cpp b/ecmascript/compiler/builtins/builtins_typedarray_stub_builder.cpp index cd951fd08c..00c06e18eb 100644 --- a/ecmascript/compiler/builtins/builtins_typedarray_stub_builder.cpp +++ b/ecmascript/compiler/builtins/builtins_typedarray_stub_builder.cpp @@ -474,7 +474,7 @@ void BuiltinsTypedArrayStubBuilder::Reverse(GateRef glue, GateRef thisValue, [[m GateRef arrLen = GetArrayLength(thisValue); BRANCH(Int32Equal(arrLen, Int32(0)), &writeResult, ¬Empty); Bind(¬Empty); - CallNGCRuntime(glue, RTSTUB_ID(ReverseTypedArray), {thisValue}); + CallNGCRuntime(glue, RTSTUB_ID(ReverseTypedArray), {glue, thisValue}); Jump(&writeResult); Bind(&writeResult); result->WriteVariable(thisValue); @@ -2119,7 +2119,7 @@ void BuiltinsTypedArrayStubBuilder::Sort( GateRef buffer = GetViewedArrayBuffer(glue, thisValue); BRANCH(IsDetachedBuffer(glue, buffer), slowPath, ¬Detached); Bind(¬Detached); - CallNGCRuntime(glue, RTSTUB_ID(SortTypedArray), {thisValue}); + CallNGCRuntime(glue, RTSTUB_ID(SortTypedArray), {glue, thisValue}); result->WriteVariable(thisValue); Jump(exit); } diff --git a/ecmascript/compiler/call_signature.cpp b/ecmascript/compiler/call_signature.cpp index 9bcb1b7333..7be9561ae3 100644 --- a/ecmascript/compiler/call_signature.cpp +++ b/ecmascript/compiler/call_signature.cpp @@ -1734,11 +1734,12 @@ DEF_CALL_SIGNATURE(ResumeRspAndRollback) DEF_CALL_SIGNATURE(JSHClassFindProtoTransitions) { - // 3 : 3 input parameters - CallSignature bigIntSameValueZero("JSHClassFindProtoTransitions", 0, 3, + // 4 : 4 input parameters + CallSignature bigIntSameValueZero("JSHClassFindProtoTransitions", 0, 4, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = bigIntSameValueZero; - std::array params = { // 3 : 3 input parameters + std::array params = { // 4 : 4 input parameters + VariableType::NATIVE_POINTER(), VariableType::JS_POINTER(), VariableType::JS_POINTER(), VariableType::JS_POINTER(), @@ -1750,11 +1751,12 @@ DEF_CALL_SIGNATURE(JSHClassFindProtoTransitions) DEF_CALL_SIGNATURE(FinishObjSizeTracking) { - // 1 : 1 input parameters - CallSignature finishObjSizeTracking("FinishObjSizeTracking", 0, 1, + // 2 : 2 input parameters + CallSignature finishObjSizeTracking("FinishObjSizeTracking", 0, 2, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = finishObjSizeTracking; - std::array params = { // 1 : 1 input parameters + std::array params = { // 2 : 2 input parameters + VariableType::NATIVE_POINTER(), VariableType::JS_POINTER(), }; callSign->SetParameters(params.data()); @@ -1764,11 +1766,12 @@ DEF_CALL_SIGNATURE(FinishObjSizeTracking) DEF_CALL_SIGNATURE(NumberHelperStringToDouble) { - // 1 : 1 input parameters - CallSignature bigIntSameValueZero("NumberHelperStringToDouble", 0, 1, + // 2 : 2 input parameters + CallSignature bigIntSameValueZero("NumberHelperStringToDouble", 0, 2, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = bigIntSameValueZero; - std::array params = { // 1 : 1 input parameters + std::array params = { // 2 : 2 input parameters + VariableType::NATIVE_POINTER(), VariableType::JS_POINTER(), }; callSign->SetParameters(params.data()); @@ -1883,11 +1886,12 @@ DEF_CALL_SIGNATURE(FastArraySortString) DEF_CALL_SIGNATURE(StringToNumber) { - // 4 : 4 input parameters - CallSignature stringToNumber("StringToDoubleWithRadix", 0, 2, + // 3 : 3 input parameters + CallSignature stringToNumber("StringToDoubleWithRadix", 0, 3, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = stringToNumber; - std::array params = { // 2 : 2 input parameters + std::array params = { // 3 : 3 input parameters + VariableType::NATIVE_POINTER(), VariableType::JS_POINTER(), VariableType::INT32(), }; @@ -1975,11 +1979,13 @@ DEF_CALL_SIGNATURE(StringGetEnd) DEF_CALL_SIGNATURE(ReverseTypedArray) { - CallSignature reverseTypedArray("ReverseTypedArray", 0, 1, + // 2 : 2 input parameters + CallSignature reverseTypedArray("ReverseTypedArray", 0, 2, ArgumentsOrder::DEFAULT_ORDER, VariableType::VOID()); *callSign = reverseTypedArray; - std::array params = { + std::array params = { VariableType::NATIVE_POINTER(), + VariableType::JS_POINTER(), }; callSign->SetParameters(params.data()); callSign->SetGCLeafFunction(true); @@ -2006,11 +2012,13 @@ DEF_CALL_SIGNATURE(ReverseArray) DEF_CALL_SIGNATURE(SortTypedArray) { - CallSignature sortTypedArray("SortTypedArray", 0, 1, + // 2 : 2 input parameters + CallSignature sortTypedArray("SortTypedArray", 0, 2, ArgumentsOrder::DEFAULT_ORDER, VariableType::VOID()); *callSign = sortTypedArray; - std::array params = { + std::array params = { VariableType::NATIVE_POINTER(), + VariableType::JS_POINTER(), }; callSign->SetParameters(params.data()); callSign->SetGCLeafFunction(true); @@ -2658,11 +2666,12 @@ DEF_CALL_SIGNATURE(CallDateNow) DEF_CALL_SIGNATURE(UpdateFieldType) { - // 2 : 2 input parameters - CallSignature index("UpdateFieldType", 0, 2, ArgumentsOrder::DEFAULT_ORDER, VariableType::INT32()); + // 3 : 3 input parameters + CallSignature index("UpdateFieldType", 0, 3, ArgumentsOrder::DEFAULT_ORDER, VariableType::INT32()); *callSign = index; - // 2 : 2 input parameters - std::array params = { + // 3 : 3 input parameters + std::array params = { + VariableType::NATIVE_POINTER(), VariableType::JS_ANY(), VariableType::INT64(), }; diff --git a/ecmascript/compiler/circuit_builder.cpp b/ecmascript/compiler/circuit_builder.cpp index 1baf37f302..ca2fd3a61d 100644 --- a/ecmascript/compiler/circuit_builder.cpp +++ b/ecmascript/compiler/circuit_builder.cpp @@ -1403,7 +1403,7 @@ GateRef CircuitBuilder::TransProtoWithoutLayout(GateRef glue, GateRef hClass, Ga GateRef key = GetGlobalConstantValue(VariableType::JS_POINTER(), glue, ConstantIndex::PROTOTYPE_STRING_INDEX); GateRef newClass = CallNGCRuntime(glue, RTSTUB_ID(JSHClassFindProtoTransitions), Gate::InvalidGateRef, - { hClass, key, proto }, glue); + { glue, hClass, key, proto }, glue); Label undef(env_); Label find(env_); BRANCH(IntPtrEqual(TaggedCastToIntPtr(newClass), IntPtr(0)), &undef, &find); diff --git a/ecmascript/compiler/common_stubs.cpp b/ecmascript/compiler/common_stubs.cpp index 16532c867f..4f38111866 100644 --- a/ecmascript/compiler/common_stubs.cpp +++ b/ecmascript/compiler/common_stubs.cpp @@ -265,7 +265,7 @@ void ConvertCharToInt32StubBuilder::GenerateCircuit() // char to string GateRef result = builder.CreateStringBySingleCharCode(glue, charCode); // string to number - result = CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), {result, Int32(0)}, charCode); + result = CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), {glue, result, Int32(0)}, charCode); // get int from number result = NumberGetInt(glue, result); Return(result); @@ -279,7 +279,7 @@ void ConvertCharToDoubleStubBuilder::GenerateCircuit() // char to string GateRef result = builder.CreateStringBySingleCharCode(glue, charCode); // string to number - result = CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), {result, Int32(0)}, charCode); + result = CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), {glue, result, Int32(0)}, charCode); // get double from number result = GetDoubleOfTNumber(result); Return(result); diff --git a/ecmascript/compiler/jit_compilation_env.cpp b/ecmascript/compiler/jit_compilation_env.cpp index dc3d4a9650..8977da963b 100644 --- a/ecmascript/compiler/jit_compilation_env.cpp +++ b/ecmascript/compiler/jit_compilation_env.cpp @@ -28,11 +28,11 @@ JitCompilationEnv::JitCompilationEnv(EcmaVM *jitVm, EcmaVM *jsVm, if (hostThread_ != nullptr && jsVm->GetPTManager() != nullptr) { ptManager_ = jsVm->GetPTManager(); } - Method *method = Method::Cast(jsFunction->GetMethod().GetTaggedObject()); - jsPandaFile_ = const_cast(method->GetJSPandaFile()); - methodLiteral_ = method->GetMethodLiteral(); + Method *method = Method::Cast(jsFunction->GetMethod(thread_).GetTaggedObject()); + jsPandaFile_ = const_cast(method->GetJSPandaFile(thread_)); + methodLiteral_ = method->GetMethodLiteral(thread_); pcStart_ = method->GetBytecodeArray(); - abcId_ = PGOProfiler::GetMethodAbcId(*jsFunction); + abcId_ = PGOProfiler::GetMethodAbcId(thread_, *jsFunction); if (method->GetFunctionKind() == FunctionKind::CLASS_CONSTRUCTOR) { methodLiteral_->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR); } @@ -73,8 +73,8 @@ JSTaggedValue JitCompilationEnv::FindConstpool([[maybe_unused]] const JSPandaFil [[maybe_unused]] panda_file::File::EntityId id) const { ASSERT(thread_->IsInRunningState()); - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); - JSTaggedValue constpool = method->GetConstantPool(); + Method *method = Method::Cast(jsFunction_->GetMethod(thread_).GetTaggedObject()); + JSTaggedValue constpool = method->GetConstantPool(thread_); [[maybe_unused]] const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); ASSERT(taggedPool->GetJSPandaFile() == jsPandaFile); ASSERT(method->GetMethodId() == id); @@ -85,8 +85,8 @@ JSTaggedValue JitCompilationEnv::FindConstpool([[maybe_unused]] const JSPandaFil [[maybe_unused]] int32_t index) const { ASSERT(thread_->IsInRunningState()); - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); - JSTaggedValue constpool = method->GetConstantPool(); + Method *method = Method::Cast(jsFunction_->GetMethod(thread_).GetTaggedObject()); + JSTaggedValue constpool = method->GetConstantPool(thread_); [[maybe_unused]] const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); ASSERT(taggedPool->GetJSPandaFile() == jsPandaFile); ASSERT(taggedPool->GetSharedConstpoolId().GetInt() == index); @@ -106,8 +106,8 @@ JSTaggedValue JitCompilationEnv::FindOrCreateUnsharedConstpool([[maybe_unused]] JSTaggedValue JitCompilationEnv::FindOrCreateUnsharedConstpool([[maybe_unused]] JSTaggedValue sharedConstpool) const { - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); - [[maybe_unused]] JSTaggedValue constpool = method->GetConstantPool(); + Method *method = Method::Cast(jsFunction_->GetMethod(thread_).GetTaggedObject()); + [[maybe_unused]] JSTaggedValue constpool = method->GetConstantPool(thread_); ASSERT(constpool == sharedConstpool); uint32_t methodOffset = method->GetMethodId().GetOffset(); return FindOrCreateUnsharedConstpool(methodOffset); @@ -124,15 +124,15 @@ JSTaggedValue JitCompilationEnv::GetConstantPoolByMethodOffset([[maybe_unused]] { ASSERT(thread_->IsInRunningState()); JSTaggedValue constpool; - Method *currMethod = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); + Method *currMethod = Method::Cast(jsFunction_->GetMethod(thread_).GetTaggedObject()); if (methodOffset != currMethod->GetMethodId().GetOffset()) { auto calleeFunc = GetJsFunctionByMethodOffset(methodOffset); if (!calleeFunc) { return JSTaggedValue::Undefined(); } - constpool = Method::Cast(calleeFunc->GetMethod())->GetConstantPool(); + constpool = Method::Cast(calleeFunc->GetMethod(thread_))->GetConstantPool(thread_); } else { - constpool = currMethod->GetConstantPool(); + constpool = currMethod->GetConstantPool(thread_); } return constpool; } @@ -140,18 +140,18 @@ JSTaggedValue JitCompilationEnv::GetConstantPoolByMethodOffset([[maybe_unused]] JSTaggedValue JitCompilationEnv::GetArrayLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const { ASSERT(thread_->IsInRunningState()); - return ConstantPool::GetLiteralFromCache(constpool, index, entry); + return ConstantPool::GetLiteralFromCacheNoScope(thread_, constpool, index, entry); } JSTaggedValue JitCompilationEnv::GetObjectLiteralFromCache(JSTaggedValue constpool, uint32_t index, CString entry) const { ASSERT(thread_->IsInRunningState()); - return ConstantPool::GetLiteralFromCache(constpool, index, entry); + return ConstantPool::GetLiteralFromCacheNoScope(thread_, constpool, index, entry); } JSTaggedValue JitCompilationEnv::GetMethodFromCache(JSTaggedValue constpool, uint32_t index) const { - return ConstantPool::GetMethodFromCache(constpool, index); + return ConstantPool::GetMethodFromCache(constpool, index, thread_); } panda_file::File::EntityId JitCompilationEnv::GetIdFromCache(JSTaggedValue constpool, uint32_t index) const @@ -187,7 +187,7 @@ JSTaggedValue JitCompilationEnv::GetStringFromConstantPool([[maybe_unused]] cons JSFunction *JitCompilationEnv::GetJsFunctionByMethodOffset(uint32_t methodOffset) const { ASSERT(thread_->IsInRunningState()); - Method *currMethod = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); + Method *currMethod = Method::Cast(jsFunction_->GetMethod(thread_).GetTaggedObject()); auto currMethodOffset = currMethod->GetMethodId().GetOffset(); if (methodOffset == currMethodOffset) { return *jsFunction_; @@ -206,15 +206,15 @@ JSFunction *JitCompilationEnv::GetJsFunctionByMethodOffset(uint32_t methodOffset for (int i = static_cast(funcSlotChain.size()) - 1; i >= 0; --i) { uint32_t slotId = funcSlotChain[i].first; uint32_t callerOffset = funcSlotChain[i].second; - if (Method::Cast(currFunc->GetMethod())->GetMethodId().GetOffset() != callerOffset) { + if (Method::Cast(currFunc->GetMethod(thread_))->GetMethodId().GetOffset() != callerOffset) { return nullptr; } - auto slotValue = currFuncPTI->Get(slotId); + auto slotValue = currFuncPTI->Get(thread_, slotId); if (slotValue.IsJSFunction()) { - currFunc = JSFunction::Cast(currFuncPTI->Get(slotId).GetTaggedObject()); + currFunc = JSFunction::Cast(currFuncPTI->Get(thread_, slotId).GetTaggedObject()); } else if (slotValue.IsPrototypeHandler()) { auto prototypeHandler = PrototypeHandler::Cast(slotValue.GetTaggedObject()); - auto accessorFunction = prototypeHandler->GetAccessorJSFunction(); + auto accessorFunction = prototypeHandler->GetAccessorJSFunction(thread_); if (!accessorFunction.IsJSFunction()) { return nullptr; } @@ -222,13 +222,13 @@ JSFunction *JitCompilationEnv::GetJsFunctionByMethodOffset(uint32_t methodOffset } else { return nullptr; } - auto profileTypeInfoVal = currFunc->GetProfileTypeInfo(); + auto profileTypeInfoVal = currFunc->GetProfileTypeInfo(thread_); if (profileTypeInfoVal.IsUndefined()) { return nullptr; } currFuncPTI = ProfileTypeInfo::Cast(profileTypeInfoVal.GetTaggedObject()); } - if (Method::Cast(currFunc->GetMethod())->GetMethodId().GetOffset() != methodOffset) { + if (Method::Cast(currFunc->GetMethod(thread_))->GetMethodId().GetOffset() != methodOffset) { return nullptr; } return currFunc; diff --git a/ecmascript/compiler/lazy_deopt_dependency.cpp b/ecmascript/compiler/lazy_deopt_dependency.cpp index 604bba1197..5e740fb43f 100644 --- a/ecmascript/compiler/lazy_deopt_dependency.cpp +++ b/ecmascript/compiler/lazy_deopt_dependency.cpp @@ -61,7 +61,7 @@ bool LazyDeoptAllDependencies::DependOnStableHClass(JSHClass *hclass) return false; } -bool LazyDeoptAllDependencies::DependOnStableProtoChain(JSHClass *receiverHClass, +bool LazyDeoptAllDependencies::DependOnStableProtoChain(JSThread *thread, JSHClass *receiverHClass, JSHClass *holderHClass) { // For "stobjbyname", the holder may not the actual holder. @@ -70,7 +70,7 @@ bool LazyDeoptAllDependencies::DependOnStableProtoChain(JSHClass *receiverHClass if (receiverHClass == holderHClass) { holderHClass = nullptr; } - JSTaggedValue current = receiverHClass->GetPrototype(); + JSTaggedValue current = receiverHClass->GetPrototype(thread); bool success = true; while (current.IsHeapObject()) { auto currentHC = current.GetTaggedObject()->GetClass(); @@ -80,7 +80,7 @@ bool LazyDeoptAllDependencies::DependOnStableProtoChain(JSHClass *receiverHClass if (currentHC == holderHClass) { break; } - current = currentHC->GetPrototype(); + current = currentHC->GetPrototype(thread); } return success; } diff --git a/ecmascript/compiler/lazy_deopt_dependency.h b/ecmascript/compiler/lazy_deopt_dependency.h index bc504ca695..9fef886107 100644 --- a/ecmascript/compiler/lazy_deopt_dependency.h +++ b/ecmascript/compiler/lazy_deopt_dependency.h @@ -81,7 +81,7 @@ public: } bool DependOnStableHClass(JSHClass *hclass); - bool DependOnStableProtoChain(JSHClass *receiverHClass, + bool DependOnStableProtoChain(JSThread *thread, JSHClass *receiverHClass, JSHClass *holderHClass); bool PreInstall(JSThread *thread); PUBLIC_API static bool Commit(LazyDeoptAllDependencies *dependencies, diff --git a/ecmascript/compiler/mcr_circuit_builder.cpp b/ecmascript/compiler/mcr_circuit_builder.cpp index 6a8dca57fb..59a271e58e 100644 --- a/ecmascript/compiler/mcr_circuit_builder.cpp +++ b/ecmascript/compiler/mcr_circuit_builder.cpp @@ -1735,7 +1735,7 @@ GateRef CircuitBuilder::ToNumber(GateRef gate, GateRef value, GateRef glue) GateRef CircuitBuilder::StringToNumber(GateRef gate, GateRef value, GateRef radix, GateRef glue) { - return CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), Gate::InvalidGateRef, { value, radix }, gate); + return CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), Gate::InvalidGateRef, { glue, value, radix }, gate); } GateRef CircuitBuilder::BuildControlDependOp(const GateMetaData* op, std::vector args, diff --git a/ecmascript/compiler/new_object_stub_builder.cpp b/ecmascript/compiler/new_object_stub_builder.cpp index e63429bb38..73e9b78fd3 100644 --- a/ecmascript/compiler/new_object_stub_builder.cpp +++ b/ecmascript/compiler/new_object_stub_builder.cpp @@ -478,7 +478,7 @@ void NewObjectStubBuilder::NewJSObject(Variable *result, Label *exit, GateRef hc Branch(Int32Equal(nextCount, Int32(0)), &calcuFinalCount, exit); Bind(&calcuFinalCount); { - CallNGCRuntime(glue_, RTSTUB_ID(FinishObjSizeTracking), { hclass }); + CallNGCRuntime(glue_, RTSTUB_ID(FinishObjSizeTracking), { glue_, hclass }); Jump(exit); } } diff --git a/ecmascript/compiler/ntype_bytecode_lowering.cpp b/ecmascript/compiler/ntype_bytecode_lowering.cpp index 0990394dff..0ccf9cec0d 100644 --- a/ecmascript/compiler/ntype_bytecode_lowering.cpp +++ b/ecmascript/compiler/ntype_bytecode_lowering.cpp @@ -363,14 +363,15 @@ void NTypeBytecodeLowering::LowerNTypedStOwnByName(GateRef gate) if (key.IsUndefined()) { return; } + JSThread *thread = compilationEnv_->GetJSThread(); JSHClass *hclass = JSHClass::Cast(taggedHClass.GetTaggedObject()); - int entry = JSHClass::FindPropertyEntry(compilationEnv_->GetJSThread(), hclass, key); + int entry = JSHClass::FindPropertyEntry(thread, hclass, key); if (entry == -1) { return; } - LayoutInfo *LayoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(LayoutInfo->GetAttr(entry)); + LayoutInfo *LayoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(LayoutInfo->GetAttr(thread, entry)); if (attr.IsAccessor()) { return; } diff --git a/ecmascript/compiler/ntype_hcr_lowering.cpp b/ecmascript/compiler/ntype_hcr_lowering.cpp index ca51979388..fc8d2fa1a2 100644 --- a/ecmascript/compiler/ntype_hcr_lowering.cpp +++ b/ecmascript/compiler/ntype_hcr_lowering.cpp @@ -110,7 +110,7 @@ void NTypeHCRLowering::LowerCreateArrayWithBuffer(GateRef gate, GateRef glue) GateRef literialElements = builder_.GetElementsArray(glue, cachedArray); DISALLOW_GARBAGE_COLLECTION; JSArray *arrayHandle = JSArray::Cast(arr.GetTaggedObject()); - TaggedArray *arrayLiteral = TaggedArray::Cast(arrayHandle->GetElements()); + TaggedArray *arrayLiteral = TaggedArray::Cast(arrayHandle->GetElements(compilationEnv_->GetJSThread())); uint32_t literialLength = arrayLiteral->GetLength(); uint32_t arrayLength = acc_.GetArraySize(gate); GateRef elements = Circuit::NullGate(); @@ -222,8 +222,9 @@ GateRef NTypeHCRLowering::NewJSArrayLiteral(GateRef glue, GateRef gate, GateRef GateRef globalEnv = builder_.GetGlobalEnv(glue); hclass = builder_.GetGlobalEnvValue(VariableType::JS_POINTER(), glue, globalEnv, static_cast(hclassIndex)); + JSThread *thread = JSThread::GlueToJSThread(glue); JSHandle arrayFunc(compilationEnv_->GetGlobalEnv()->GetArrayFunction()); - JSTaggedValue protoOrHClass = arrayFunc->GetProtoOrHClass(); + JSTaggedValue protoOrHClass = arrayFunc->GetProtoOrHClass(thread); JSHClass *arrayHC = JSHClass::Cast(protoOrHClass.GetTaggedObject()); size_t arraySize = arrayHC->GetObjectSize(); size_t lengthAccessorOffset = arrayHC->GetInlinedPropertiesOffset(JSArray::LENGTH_INLINE_PROPERTY_INDEX); diff --git a/ecmascript/compiler/pgo_type/pgo_type_manager.cpp b/ecmascript/compiler/pgo_type/pgo_type_manager.cpp index 64461fa227..e9e4945959 100644 --- a/ecmascript/compiler/pgo_type/pgo_type_manager.cpp +++ b/ecmascript/compiler/pgo_type/pgo_type_manager.cpp @@ -70,11 +70,11 @@ uint32_t PGOTypeManager::GetSymbolCountFromHClassData() continue; } JSHClass* hclass = JSHClass::Cast(JSTaggedValue(child.second).GetTaggedObject()); - if (!hclass->HasTransitions()) { - LayoutInfo* layoutInfo = LayoutInfo::GetLayoutInfoFromHClass(hclass); + if (!hclass->HasTransitions(thread_)) { + LayoutInfo* layoutInfo = LayoutInfo::GetLayoutInfoFromHClass(thread_, hclass); uint32_t len = hclass->NumberOfProps(); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); + JSTaggedValue key = layoutInfo->GetKey(thread_, i); if (key.IsSymbol() && JSSymbol::Cast(key)->HasId()) { count++; } @@ -100,11 +100,11 @@ void PGOTypeManager::GenSymbolInfo() } ProfileType childType = child.first; JSHClass* hclass = JSHClass::Cast(JSTaggedValue(child.second).GetTaggedObject()); - if (!hclass->HasTransitions()) { - LayoutInfo* layoutInfo = LayoutInfo::GetLayoutInfoFromHClass(hclass); + if (!hclass->HasTransitions(thread_)) { + LayoutInfo* layoutInfo = LayoutInfo::GetLayoutInfoFromHClass(thread_, hclass); uint32_t len = hclass->NumberOfProps(); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue symbol = layoutInfo->GetKey(i); + JSTaggedValue symbol = layoutInfo->GetKey(thread_, i); if (symbol.IsSymbol() && JSSymbol::Cast(symbol)->HasId()) { JSSymbol* symbolPtr = JSSymbol::Cast(symbol.GetTaggedObject()); uint64_t symbolId = symbolPtr->GetPrivateId(); diff --git a/ecmascript/compiler/slowpath_lowering.cpp b/ecmascript/compiler/slowpath_lowering.cpp index 8de6466e63..a287d071a4 100644 --- a/ecmascript/compiler/slowpath_lowering.cpp +++ b/ecmascript/compiler/slowpath_lowering.cpp @@ -2880,7 +2880,7 @@ bool SlowPathLowering::OptimizeDefineFuncForJit(GateRef gate, GateRef jsFunc, Ga return false; } - auto method = ConstantPool::GetMethodFromCache(constPool, methodIdValue); + auto method = ConstantPool::GetMethodFromCache(compilationEnv_->GetJSThread(), constPool, methodIdValue); if (!method.IsMethod()) { return false; } @@ -2892,7 +2892,7 @@ bool SlowPathLowering::OptimizeDefineFuncForJit(GateRef gate, GateRef jsFunc, Ga auto jitCompilationEnv = static_cast(compilationEnv_); auto func = jitCompilationEnv->GetJsFunctionByMethodOffset(acc_.TryGetMethodOffset(gate)); - auto profileTypeInfo = func->GetProfileTypeInfo(); + auto profileTypeInfo = func->GetProfileTypeInfo(compilationEnv_->GetJSThread()); if (profileTypeInfo.IsUndefined()) { return false; } diff --git a/ecmascript/compiler/stub_builder-inl.h b/ecmascript/compiler/stub_builder-inl.h index d004427380..2e9b53c7b8 100644 --- a/ecmascript/compiler/stub_builder-inl.h +++ b/ecmascript/compiler/stub_builder-inl.h @@ -2736,7 +2736,7 @@ inline GateRef StubBuilder::GetIhcFromAOTLiteralInfo(GateRef glue, GateRef info) inline void StubBuilder::UpdateFieldType(GateRef glue, GateRef hclass, GateRef attr) { - CallNGCRuntime(glue, RTSTUB_ID(UpdateFieldType), { hclass, attr }); + CallNGCRuntime(glue, RTSTUB_ID(UpdateFieldType), { glue, hclass, attr }); } inline GateRef StubBuilder::GetPropertyMetaDataFromAttr(GateRef attr) diff --git a/ecmascript/compiler/ts_hcr_opt_pass.cpp b/ecmascript/compiler/ts_hcr_opt_pass.cpp index 502c91b2d9..b86cb25ac6 100644 --- a/ecmascript/compiler/ts_hcr_opt_pass.cpp +++ b/ecmascript/compiler/ts_hcr_opt_pass.cpp @@ -147,7 +147,7 @@ GateRef TSHCROptPass::ConvertConstSingleCharToInt32(GateRef gate) return Circuit::NullGate(); } ASSERT(EcmaStringAccessor(str).GetLength() == 1); - uint16_t strToInt = EcmaStringAccessor(str).Get(0); + uint16_t strToInt = EcmaStringAccessor(str).Get(compilationEnv_->GetJSThread(), 0); return builder_.Int32(strToInt); } diff --git a/ecmascript/compiler/ts_inline_lowering.cpp b/ecmascript/compiler/ts_inline_lowering.cpp index 8c909d6e25..7d2226b098 100644 --- a/ecmascript/compiler/ts_inline_lowering.cpp +++ b/ecmascript/compiler/ts_inline_lowering.cpp @@ -781,22 +781,23 @@ bool TSInlineLowering::CalleePFIProcess(uint32_t methodOffset) return true; } auto jitCompilationEnv = static_cast(compilationEnv_); + JSThread *thread = jitCompilationEnv->GetJSThread(); JSFunction *calleeFunc = jitCompilationEnv->GetJsFunctionByMethodOffset(methodOffset); if (!calleeFunc) { return false; } auto calleeMethodHandle = jitCompilationEnv->NewJSHandle(JSTaggedValue(calleeFunc)); - auto calleeMethod = Method::Cast(calleeFunc->GetMethod()); + auto calleeMethod = Method::Cast(calleeFunc->GetMethod(thread)); ASSERT(calleeMethod->GetMethodId().GetOffset() == methodOffset); - auto profileTIVal = calleeFunc->GetProfileTypeInfo(); + auto profileTIVal = calleeFunc->GetProfileTypeInfo(thread); if (profileTIVal.IsUndefined()) { return false; } auto profileTypeInfo = ProfileTypeInfo::Cast(profileTIVal.GetTaggedObject()); - auto calleeLiteral = calleeMethod->GetMethodLiteral(); - auto calleeFile = calleeMethod->GetJSPandaFile(); - auto calleeAbcId = PGOProfiler::GetMethodAbcId(calleeFunc); + auto calleeLiteral = calleeMethod->GetMethodLiteral(thread); + auto calleeFile = calleeMethod->GetJSPandaFile(thread); + auto calleeAbcId = PGOProfiler::GetMethodAbcId(thread, calleeFunc); auto calleeCodeSize = calleeLiteral->GetCodeSize(calleeFile, calleeMethod->GetMethodId()); compilationEnv_->GetPGOProfiler()->GetJITProfile()->ProfileBytecode( compilationEnv_->GetJSThread(), JSHandle(), profileTypeInfo, calleeMethod->GetMethodId(), diff --git a/ecmascript/compiler/type_info_accessors.cpp b/ecmascript/compiler/type_info_accessors.cpp index 1c1de7e0a4..3349bfd511 100644 --- a/ecmascript/compiler/type_info_accessors.cpp +++ b/ecmascript/compiler/type_info_accessors.cpp @@ -500,7 +500,7 @@ bool InlineTypeInfoAccessor::InitPropAndCheck(JSTaggedValue& prop) const } // PGO currently does not support call, so GT is still used to support inline operations. // However, the original GT solution cannot support accessing the property of prototype, so it is filtered here - if (EcmaStringAccessor(prop).ToStdString() == "prototype") { + if (EcmaStringAccessor(prop).ToStdString(compilationEnv_->GetJSThread()) == "prototype") { return false; } return true; @@ -666,7 +666,7 @@ JSTaggedValue StorePrivatePropertyTypeInfoAccessor::GetKeyTaggedValue() const AOTSnapshot& snapshot = ptManager_->GetAOTSnapshot(); auto symbolInfo = snapshot.GetSymbolInfo(); - auto symbol = ConstantPool::GetSymbolFromSymbolInfo(symbolInfo, *privateId); + auto symbol = ConstantPool::GetSymbolFromSymbolInfo(compilationEnv_->GetJSThread(), symbolInfo, *privateId); return symbol; } @@ -772,7 +772,7 @@ JSTaggedValue LoadPrivatePropertyTypeInfoAccessor::GetKeyTaggedValue() const AOTSnapshot& snapshot = ptManager_->GetAOTSnapshot(); auto symbolInfo = snapshot.GetSymbolInfo(); - auto symbol = ConstantPool::GetSymbolFromSymbolInfo(symbolInfo, *privateId); + auto symbol = ConstantPool::GetSymbolFromSymbolInfo(compilationEnv_->GetJSThread(), symbolInfo, *privateId); return symbol; } @@ -1447,8 +1447,9 @@ JSTaggedValue CreateObjWithBufferTypeInfoAccessor::AotAccessorStrategy::GetHClas JSObject *jsObj = JSObject::Cast(obj); JSHClass *oldClass = jsObj->GetClass(); + JSThread *thread = parent_.compilationEnv_->GetJSThread(); if (hclassIndex == -1) { - if (jsObj->ElementsAndPropertiesIsEmpty()) { + if (jsObj->ElementsAndPropertiesIsEmpty(thread)) { return JSTaggedValue(oldClass); } return JSTaggedValue::Undefined(); @@ -1476,8 +1477,9 @@ JSTaggedValue CreateObjWithBufferTypeInfoAccessor::JitAccessorStrategy::GetHClas JSObject *jsObj = JSObject::Cast(obj); JSHClass *oldClass = jsObj->GetClass(); JSHClass *newClass = sampleType->GetReceiver(); + JSThread *thread = parent_.compilationEnv_->GetJSThread(); if (newClass == nullptr) { - if (jsObj->ElementsAndPropertiesIsEmpty()) { + if (jsObj->ElementsAndPropertiesIsEmpty(thread)) { return JSTaggedValue(oldClass); } return JSTaggedValue::Undefined(); diff --git a/ecmascript/compiler/type_info_accessors.h b/ecmascript/compiler/type_info_accessors.h index 3296d2f74b..f68203e889 100644 --- a/ecmascript/compiler/type_info_accessors.h +++ b/ecmascript/compiler/type_info_accessors.h @@ -2190,15 +2190,15 @@ public: return index_; } - bool CanOptimize() const + bool CanOptimize(JSThread *thread) const { JSTaggedValue obj = GetObject(); if (obj.IsUndefined()) { return false; } JSObject *jsObj = JSObject::Cast(obj); - TaggedArray *properties = TaggedArray::Cast(jsObj->GetProperties()); - TaggedArray *elements = TaggedArray::Cast(jsObj->GetElements()); + TaggedArray *properties = TaggedArray::Cast(jsObj->GetProperties(thread)); + TaggedArray *elements = TaggedArray::Cast(jsObj->GetElements(thread)); return properties->GetLength() == 0 && elements->GetLength() == 0; } diff --git a/ecmascript/compiler/typed_bytecode_lowering.cpp b/ecmascript/compiler/typed_bytecode_lowering.cpp index 7176f0ef88..a239b2a880 100644 --- a/ecmascript/compiler/typed_bytecode_lowering.cpp +++ b/ecmascript/compiler/typed_bytecode_lowering.cpp @@ -2166,9 +2166,9 @@ void TypedBytecodeLowering::ConvertCallTargetCheckToHeapConstantCheckAndLowerCal auto *jitCompilationEnv = static_cast(compilationEnv_); JSHandle heapObject = jitCompilationEnv->GetHeapConstantHandle(heapConstantIndex); JSHandle jsFunc = JSHandle::Cast(heapObject); - Method *calleeMethod = Method::Cast(jsFunc->GetMethod()); - ASSERT(calleeMethod->GetMethodLiteral() != nullptr); - if (calleeMethod->GetMethodLiteral()->IsFastCall()) { + Method *calleeMethod = Method::Cast(jsFunc->GetMethod(compilationEnv_->GetJSThread())); + ASSERT(calleeMethod->GetMethodLiteral(compilationEnv_->GetJSThread()) != nullptr); + if (calleeMethod->GetMethodLiteral(compilationEnv_->GetJSThread())->IsFastCall()) { LowerFastCall(gate, func, argsFastCall, isNoGC); } else { LowerCall(gate, func, args, isNoGC); @@ -2684,7 +2684,7 @@ void TypedBytecodeLowering::LowerTypedTryLdGlobalByName(GateRef gate) } BuiltinIndex& builtin = BuiltinIndex::GetInstance(); - auto index = builtin.GetBuiltinIndex(key); + auto index = builtin.GetBuiltinIndex(compilationEnv_->GetJSThread(), key); if (index != builtin.NOT_FOUND) { AddProfiling(gate); GateRef result = builder_.LoadBuiltinObject(index); @@ -2746,7 +2746,7 @@ void TypedBytecodeLowering::LowerCreateEmptyObject(GateRef gate) GateRef hclass = builder_.GetGlobalEnvObjHClass(globalEnv, GlobalEnv::OBJECT_FUNCTION_INDEX); JSHandle objectFunc(compilationEnv_->GetGlobalEnv()->GetObjectFunction()); - JSTaggedValue protoOrHClass = objectFunc->GetProtoOrHClass(); + JSTaggedValue protoOrHClass = objectFunc->GetProtoOrHClass(compilationEnv_->GetJSThread()); JSHClass *objectHC = JSHClass::Cast(protoOrHClass.GetTaggedObject()); size_t objectSize = objectHC->GetObjectSize(); @@ -2782,7 +2782,8 @@ void TypedBytecodeLowering::LowerTypedStOwnByValue(GateRef gate) void TypedBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate) { CreateObjWithBufferTypeInfoAccessor tacc(compilationEnv_, circuit_, gate, recordName_, chunk_); - if (!tacc.CanOptimize()) { + JSThread *thread = compilationEnv_->GetJSThread(); + if (!tacc.CanOptimize(thread)) { return; } JSTaggedValue hclassVal = tacc.GetHClass(); @@ -2797,12 +2798,12 @@ void TypedBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate) } JSObject *objhandle = JSObject::Cast(obj); std::vector inlinedProps; - auto layout = LayoutInfo::Cast(newClass->GetLayout().GetTaggedObject()); + auto layout = LayoutInfo::Cast(newClass->GetLayout(thread).GetTaggedObject()); uint32_t numOfProps = newClass->NumberOfProps(); uint32_t numInlinedProps = newClass->GetInlinedProperties(); for (uint32_t i = 0; i < numOfProps; i++) { - auto attr = layout->GetAttr(i); - JSTaggedValue value = objhandle->GetPropertyInlinedProps(i); + auto attr = layout->GetAttr(thread, i); + JSTaggedValue value = objhandle->GetPropertyInlinedProps(thread, i); if ((!attr.IsTaggedRep()) || value.IsUndefinedOrNull() || value.IsNumber() || value.IsBoolean() || value.IsException()) { auto converted = JSObject::ConvertValueWithRep(attr, value); @@ -2824,7 +2825,7 @@ void TypedBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate) valueIn.emplace_back(builder_.Int64(JSTaggedValue(newClass).GetRawData())); valueIn.emplace_back(acc_.GetValueIn(gate, 1)); for (uint32_t i = 0; i < numOfProps; i++) { - auto attr = layout->GetAttr(i); + auto attr = layout->GetAttr(thread, i); GateRef prop; if (attr.IsIntRep()) { prop = builder_.Int32(inlinedProps.at(i)); diff --git a/ecmascript/compiler/typed_bytecode_lowering.h b/ecmascript/compiler/typed_bytecode_lowering.h index 130493dd7b..954ac74ead 100644 --- a/ecmascript/compiler/typed_bytecode_lowering.h +++ b/ecmascript/compiler/typed_bytecode_lowering.h @@ -267,7 +267,7 @@ private: auto holderHC = tacc.GetHolderHClass(index); auto receiverHC = tacc.GetReceiverHClass(index); bool success = compilationEnv_->GetDependencies()-> - DependOnStableProtoChain(receiverHC, + DependOnStableProtoChain(compilationEnv_->GetJSThread(), receiverHC, holderHC); #if ECMASCRIPT_ENABLE_LAZY_DEOPT_TRACE if (success) { diff --git a/ecmascript/compiler/typed_native_inline_lowering.cpp b/ecmascript/compiler/typed_native_inline_lowering.cpp index 82f8d57712..8b018e566f 100644 --- a/ecmascript/compiler/typed_native_inline_lowering.cpp +++ b/ecmascript/compiler/typed_native_inline_lowering.cpp @@ -1117,7 +1117,7 @@ GateRef AllocateNewNumber(GateRef glue, const CompilationEnv *compilationEnv, Ci { Jit::JitLockHolder lock(compilationEnv, "AllocateNewNumber"); JSHandle numberFunctionCT(compilationEnv->GetGlobalEnv()->GetNumberFunction()); - JSTaggedValue protoOrHClassCT = numberFunctionCT->GetProtoOrHClass(); + JSTaggedValue protoOrHClassCT = numberFunctionCT->GetProtoOrHClass(compilationEnv->GetJSThread()); JSHClass *numberHClassCT = JSHClass::Cast(protoOrHClassCT.GetTaggedObject()); size_t objectSize = numberHClassCT->GetObjectSize(); @@ -1978,7 +1978,7 @@ void TypedNativeInlineLowering::LowerNumberParseInt(GateRef gate) builder_.Bind(&radixIsSpecialInt); { result = builder_.CallNGCRuntime(glue, RTSTUB_ID(StringToNumber), Gate::InvalidGateRef, - { msg, *radix }, gate); + { glue, msg, *radix }, gate); builder_.Jump(&exit); } } @@ -2039,7 +2039,7 @@ void TypedNativeInlineLowering::LowerNumberParseFloat(GateRef gate) builder_.Bind(¬IntegerStr); { auto taggedDouble = builder_.CallNGCRuntime(glue, RTSTUB_ID(NumberHelperStringToDouble), - Gate::InvalidGateRef, { msg }, gate); + Gate::InvalidGateRef, { glue, msg }, gate); result = builder_.GetDoubleOfTDouble(taggedDouble); builder_.Jump(&exitIntegerStr); } diff --git a/ecmascript/containers/containers_arraylist.cpp b/ecmascript/containers/containers_arraylist.cpp index bcea6172b0..a16a673cda 100644 --- a/ecmascript/containers/containers_arraylist.cpp +++ b/ecmascript/containers/containers_arraylist.cpp @@ -53,8 +53,8 @@ JSTaggedValue ContainersArrayList::Add(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The add method cannot be bound"); @@ -75,8 +75,8 @@ JSTaggedValue ContainersArrayList::Insert(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The insert method cannot be bound"); @@ -95,7 +95,7 @@ JSTaggedValue ContainersArrayList::Insert(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -114,8 +114,8 @@ JSTaggedValue ContainersArrayList::Clear(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -137,8 +137,8 @@ JSTaggedValue ContainersArrayList::Clone(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The clone method cannot be bound"); @@ -160,8 +160,8 @@ JSTaggedValue ContainersArrayList::Has(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The has method cannot be bound"); @@ -170,7 +170,7 @@ JSTaggedValue ContainersArrayList::Has(EcmaRuntimeCallInfo *argv) } JSHandle value = GetCallArg(argv, 0); - bool isHas = JSHandle::Cast(self)->Has(value.GetTaggedValue()); + bool isHas = JSHandle::Cast(self)->Has(thread, value.GetTaggedValue()); return GetTaggedBoolean(isHas); } @@ -184,8 +184,8 @@ JSTaggedValue ContainersArrayList::GetCapacity(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getCapacity method cannot be bound"); @@ -207,8 +207,8 @@ JSTaggedValue ContainersArrayList::IncreaseCapacityTo(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The increaseCapacityTo method cannot be bound"); @@ -221,7 +221,7 @@ JSTaggedValue ContainersArrayList::IncreaseCapacityTo(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, newCapacity); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"newCapacity\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"newCapacity\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -241,8 +241,8 @@ JSTaggedValue ContainersArrayList::TrimToCurrentLength(EcmaRuntimeCallInfo *argv JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The trimToCurrentLength method cannot be bound"); @@ -264,8 +264,8 @@ JSTaggedValue ContainersArrayList::Get(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -289,8 +289,8 @@ JSTaggedValue ContainersArrayList::GetIndexOf(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOf method cannot be bound"); @@ -312,8 +312,8 @@ JSTaggedValue ContainersArrayList::IsEmpty(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -333,8 +333,8 @@ JSTaggedValue ContainersArrayList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLastIndexOf method cannot be bound"); @@ -356,8 +356,8 @@ JSTaggedValue ContainersArrayList::RemoveByIndex(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeByIndex method cannot be bound"); @@ -373,7 +373,7 @@ JSTaggedValue ContainersArrayList::RemoveByIndex(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -395,8 +395,8 @@ JSTaggedValue ContainersArrayList::Remove(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -421,8 +421,8 @@ JSTaggedValue ContainersArrayList::RemoveByRange(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The removeByRange method cannot be bound"); @@ -437,7 +437,7 @@ JSTaggedValue ContainersArrayList::RemoveByRange(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"fromIndex\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"fromIndex\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -446,7 +446,7 @@ JSTaggedValue ContainersArrayList::RemoveByRange(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"toIndex\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"toIndex\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -466,8 +466,8 @@ JSTaggedValue ContainersArrayList::ReplaceAllElements(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The replaceAllElements method cannot be bound"); @@ -480,7 +480,7 @@ JSTaggedValue ContainersArrayList::ReplaceAllElements(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -498,8 +498,8 @@ JSTaggedValue ContainersArrayList::Set(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The set method cannot be bound"); @@ -524,8 +524,8 @@ JSTaggedValue ContainersArrayList::SubArrayList(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The subArrayList method cannot be bound"); @@ -539,7 +539,7 @@ JSTaggedValue ContainersArrayList::SubArrayList(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"fromIndex\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"fromIndex\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -548,7 +548,7 @@ JSTaggedValue ContainersArrayList::SubArrayList(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value2); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"toIndex\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"toIndex\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -567,8 +567,8 @@ JSTaggedValue ContainersArrayList::Sort(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The sort method cannot be bound"); @@ -580,24 +580,24 @@ JSTaggedValue ContainersArrayList::Sort(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"comparator\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"comparator\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } auto obj = JSHandle::Cast(self); - uint32_t length = JSHandle::Cast(self)->GetLength().GetArrayLength(); + uint32_t length = JSHandle::Cast(self)->GetLength(); JSHandle elements = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); - elements->Copy(thread, 0, 0, TaggedArray::Cast(obj->GetElements()), length); + elements->Copy(thread, 0, 0, TaggedArray::Cast(obj->GetElements(thread)), length); JSMutableHandle presentValue(thread, JSTaggedValue::Undefined()); JSMutableHandle middleValue(thread, JSTaggedValue::Undefined()); JSMutableHandle previousValue(thread, JSTaggedValue::Undefined()); for (uint32_t i = 1; i < length; i++) { uint32_t beginIndex = 0; uint32_t endIndex = i; - presentValue.Update(elements->Get(i)); + presentValue.Update(elements->Get(thread, i)); while (beginIndex < endIndex) { uint32_t middleIndex = (beginIndex + endIndex) / 2; // 2 : half - middleValue.Update(elements->Get(middleIndex)); + middleValue.Update(elements->Get(thread, middleIndex)); double compareResult = base::ArrayHelper::SortCompare(thread, callbackFnHandle, middleValue, presentValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -609,14 +609,14 @@ JSTaggedValue ContainersArrayList::Sort(EcmaRuntimeCallInfo *argv) } if (endIndex >= 0 && endIndex < i) { for (uint32_t j = i; j > endIndex; j--) { - previousValue.Update(elements->Get(j - 1)); + previousValue.Update(elements->Get(thread, j - 1)); elements->Set(thread, j, previousValue.GetTaggedValue()); } elements->Set(thread, endIndex, presentValue.GetTaggedValue()); } } obj->SetElements(thread, elements); - obj->SetLength(thread, JSTaggedValue(elements->GetLength())); + obj->SetLength(elements->GetLength()); return JSTaggedValue::Undefined(); } @@ -629,8 +629,8 @@ JSTaggedValue ContainersArrayList::GetSize(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -650,8 +650,8 @@ JSTaggedValue ContainersArrayList::ConvertToArray(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The convertToArray method cannot be bound"); @@ -663,10 +663,10 @@ JSTaggedValue ContainersArrayList::ConvertToArray(EcmaRuntimeCallInfo *argv) auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle array = factory->NewJSArray(); - uint32_t length = arrayList->GetLength().GetArrayLength(); + uint32_t length = arrayList->GetLength(); array->SetArrayLength(thread, length); - JSHandle srcElements(thread, arrayList->GetElements()); + JSHandle srcElements(thread, arrayList->GetElements(thread)); JSHandle dstElements = factory->NewAndCopyTaggedArray(srcElements, length, length); array->SetElements(thread, dstElements); return array.GetTaggedValue(); @@ -681,8 +681,8 @@ JSTaggedValue ContainersArrayList::ForEach(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -695,7 +695,7 @@ JSTaggedValue ContainersArrayList::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -715,8 +715,8 @@ JSTaggedValue ContainersArrayList::GetIteratorObj(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIArrayList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIArrayList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIArrayList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/containers/containers_bitvector.cpp b/ecmascript/containers/containers_bitvector.cpp index 1d59a9694d..185b40f62f 100644 --- a/ecmascript/containers/containers_bitvector.cpp +++ b/ecmascript/containers/containers_bitvector.cpp @@ -43,7 +43,8 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg if (!length->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"length\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"length\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -71,8 +72,8 @@ JSTaggedValue ContainersBitVector::Push(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The push method cannot be bound"); @@ -92,8 +93,8 @@ JSTaggedValue ContainersBitVector::Pop(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The pop method cannot be bound"); @@ -113,8 +114,8 @@ JSTaggedValue ContainersBitVector::Has(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The has method cannot be bound"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); @@ -127,14 +128,16 @@ JSTaggedValue ContainersBitVector::Has(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -153,8 +156,8 @@ JSTaggedValue ContainersBitVector::SetBitsByRange(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The setBitsByRange method cannot be bound"); @@ -168,14 +171,16 @@ JSTaggedValue ContainersBitVector::SetBitsByRange(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -193,8 +198,8 @@ JSTaggedValue ContainersBitVector::GetBitsByRange(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The getBitsByRange method cannot be bound"); @@ -207,14 +212,16 @@ JSTaggedValue ContainersBitVector::GetBitsByRange(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -231,8 +238,8 @@ JSTaggedValue ContainersBitVector::Resize(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The resize method cannot be bound"); @@ -243,7 +250,8 @@ JSTaggedValue ContainersBitVector::Resize(EcmaRuntimeCallInfo* argv) if (!size->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, size); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"size\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"size\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -260,8 +268,8 @@ JSTaggedValue ContainersBitVector::SetAllBits(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The setAllBits method cannot be bound"); @@ -283,8 +291,8 @@ JSTaggedValue ContainersBitVector::GetBitCountByRange(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The getBitCountByRange method cannot be bound"); @@ -298,14 +306,16 @@ JSTaggedValue ContainersBitVector::GetBitCountByRange(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -322,8 +332,8 @@ JSTaggedValue ContainersBitVector::GetIndexOf(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The getIndexOf method cannot be bound"); @@ -337,14 +347,16 @@ JSTaggedValue ContainersBitVector::GetIndexOf(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -362,8 +374,8 @@ JSTaggedValue ContainersBitVector::GetLastIndexOf(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The getLastIndexOf method cannot be bound"); @@ -377,14 +389,16 @@ JSTaggedValue ContainersBitVector::GetLastIndexOf(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -401,8 +415,8 @@ JSTaggedValue ContainersBitVector::FlipBitByIndex(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The flipBitByIndex method cannot be bound"); @@ -413,7 +427,8 @@ JSTaggedValue ContainersBitVector::FlipBitByIndex(EcmaRuntimeCallInfo* argv) if (!value->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"index\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"index\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -432,8 +447,8 @@ JSTaggedValue ContainersBitVector::FlipBitsByRange(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The flipBitsByRange method cannot be bound"); @@ -445,14 +460,16 @@ JSTaggedValue ContainersBitVector::FlipBitsByRange(EcmaRuntimeCallInfo* argv) if (!startIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, startIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"fromIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } if (!endIndex->IsInteger()) { JSHandle result = JSTaggedValue::ToString(thread, endIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(*result); + CString errorMsg = + "The type of \"toIndex\" must be integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -470,8 +487,8 @@ JSTaggedValue ContainersBitVector::GetSize(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getSize method cannot be bound"); @@ -492,8 +509,8 @@ JSTaggedValue ContainersBitVector::GetIteratorObj(EcmaRuntimeCallInfo* argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIBitVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBitVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBitVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/containers/containers_buffer.cpp b/ecmascript/containers/containers_buffer.cpp index 82a88e1951..415ca9447d 100644 --- a/ecmascript/containers/containers_buffer.cpp +++ b/ecmascript/containers/containers_buffer.cpp @@ -70,13 +70,13 @@ bool IsNegetiveNumber(JSHandle &v) return v->GetNumber() < 0; } -bool IsValidEncoding(JSHandle &str) +bool IsValidEncoding(JSThread *thread, JSHandle &str) { if (!str->IsString()) { return false; } auto strAccessor = EcmaStringAccessor(JSHandle(str)); - auto res = strAccessor.ToStdString(); + auto res = strAccessor.ToStdString(thread); return JSAPIFastBuffer::GetEncodingType(res) != JSAPIFastBuffer::EncodingType::INVALID; } @@ -106,7 +106,7 @@ JSTaggedValue ContainersBuffer::BufferConstructor(EcmaRuntimeCallInfo *argv) RANGE_ERROR_CHECK(value, value, 0, UINT32_MAX); JSAPIFastBuffer::AllocateFastBuffer(thread, bufferObj, GetValueUInt32(value)); } else if (value->IsString()) { - if (byteOffsetOrEncoding->IsString() && !IsValidEncoding(byteOffsetOrEncoding)) { + if (byteOffsetOrEncoding->IsString() && !IsValidEncoding(thread, byteOffsetOrEncoding)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); @@ -166,7 +166,8 @@ JSTaggedValue ContainersBuffer::GetByteOffset(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); CONTAINER_BUFFER_CHECK(GetByteOffset); - auto array = JSTypedArray::Cast(JSHandle::Cast(self)->GetFastBufferData().GetTaggedObject()); + auto array = + JSTypedArray::Cast(JSHandle::Cast(self)->GetFastBufferData(thread).GetTaggedObject()); return JSTaggedValue(array->GetByteOffset()); } @@ -285,13 +286,13 @@ JSTaggedValue ContainersBuffer::IndexOf(EcmaRuntimeCallInfo *argv) JSHandle encoding = GetCallArg(argv, 2); // 2 means the third arg JSAPIFastBuffer::EncodingType encodingType = JSAPIFastBuffer::UTF8; if (encoding->IsString()) { - if (!IsValidEncoding(encoding)) { + if (!IsValidEncoding(thread, encoding)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(encoding)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, encoding)); } return JSAPIFastBuffer::IndexOf(thread, buffer, value, offsetIndex, encodingType); } @@ -324,13 +325,13 @@ JSTaggedValue ContainersBuffer::Includes(EcmaRuntimeCallInfo *argv) JSHandle encoding = GetCallArg(argv, 2); // 2 means the third arg JSAPIFastBuffer::EncodingType encodingType = JSAPIFastBuffer::UTF8; if (encoding->IsString()) { - if (!IsValidEncoding(encoding)) { + if (!IsValidEncoding(thread, encoding)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(encoding)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, encoding)); } return JSAPIFastBuffer::Includes(thread, buffer, value, offsetIndex, encodingType); } @@ -364,13 +365,13 @@ JSTaggedValue ContainersBuffer::LastIndexOf(EcmaRuntimeCallInfo *argv) JSHandle encoding = GetCallArg(argv, 2); // 2 means the third arg JSAPIFastBuffer::EncodingType encodingType = JSAPIFastBuffer::UTF8; if (encoding->IsString()) { - if (!IsValidEncoding(encoding)) { + if (!IsValidEncoding(thread, encoding)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(encoding)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, encoding)); } return JSAPIFastBuffer::IndexOf(thread, buffer, value, offsetIndex, encodingType, true); } @@ -426,13 +427,13 @@ JSTaggedValue ContainersBuffer::Fill(EcmaRuntimeCallInfo *argv) JSHandle start = GetCallArg(argv, 1); // 1 means the second arg if (start->IsString()) { JSAPIFastBuffer::EncodingType encodingType = JSAPIFastBuffer::UTF8; - if (!IsValidEncoding(start)) { + if (!IsValidEncoding(thread, start)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(start)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, start)); return JSAPIFastBuffer::Fill(thread, buffer, value, encodingType, 0, buffer->GetLength()); } JSHandle end = GetCallArg(argv, 2); // 2 means the third arg @@ -452,13 +453,13 @@ JSTaggedValue ContainersBuffer::Fill(EcmaRuntimeCallInfo *argv) } JSAPIFastBuffer::EncodingType encodingType = JSAPIFastBuffer::UTF8; if (encoding->IsString()) { - if (!IsValidEncoding(encoding)) { + if (!IsValidEncoding(thread, encoding)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(encoding)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, encoding)); } return JSAPIFastBuffer::Fill(thread, buffer, value, encodingType, startIndex, endIndex); } @@ -481,13 +482,13 @@ JSTaggedValue ContainersBuffer::Write(EcmaRuntimeCallInfo *argv) JSAPIFastBuffer::UTF8); } if (secondArg->IsString()) { - if (!IsValidEncoding(secondArg)) { + if (!IsValidEncoding(thread, secondArg)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(secondArg)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, secondArg)); return JSAPIFastBuffer::WriteString(thread, buffer, firstArg, 0, buffer->GetLength(), encodingType); } uint32_t offset = 0; @@ -503,13 +504,13 @@ JSTaggedValue ContainersBuffer::Write(EcmaRuntimeCallInfo *argv) } JSHandle encoding = GetCallArg(argv, 3); // 3 means the fourth arg if (encoding->IsString()) { - if (!IsValidEncoding(encoding)) { + if (!IsValidEncoding(thread, encoding)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(encoding)); + encodingType = JSAPIFastBuffer::GetEncodingType(JSAPIFastBuffer::GetString(thread, encoding)); } return JSAPIFastBuffer::WriteString(thread, buffer, firstArg, offset, maxLength, encodingType); } @@ -529,13 +530,13 @@ JSTaggedValue ContainersBuffer::ToString(EcmaRuntimeCallInfo *argv) JSHandle end = GetCallArg(argv, 2); // 2 means the third arg JSAPIFastBuffer::EncodingType encodingType = JSAPIFastBuffer::UTF8; if (firstArg->IsString()) { - if (!IsValidEncoding(firstArg)) { + if (!IsValidEncoding(thread, firstArg)) { JSTaggedValue error = ContainerError::BusinessError( thread, ErrorFlag::TYPE_ERROR, "Parameter error. The type of \"encoding\" must be BufferEncoding. the encoding code is unknown"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - encodingType = JSAPIFastBuffer::GetEncodingType(firstArg); + encodingType = JSAPIFastBuffer::GetEncodingType(thread, firstArg); } uint32_t startIndex = 0; if (start->IsNumber()) { diff --git a/ecmascript/containers/containers_buffer.h b/ecmascript/containers/containers_buffer.h index b14b2df2ba..6a49b7c0d3 100644 --- a/ecmascript/containers/containers_buffer.h +++ b/ecmascript/containers/containers_buffer.h @@ -26,8 +26,8 @@ namespace panda::ecmascript::containers { #define CONTAINER_BUFFER_CHECK(name) \ JSHandle self = GetThis(argv); \ if (!self->IsJSAPIBuffer()) { \ - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIBuffer()) { \ - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); \ + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIBuffer()) { \ + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); \ } else { \ JSTaggedValue error = \ ContainerError::BusinessError(thread, BIND_ERROR, "The " #name " method cannot be bound"); \ diff --git a/ecmascript/containers/containers_deque.cpp b/ecmascript/containers/containers_deque.cpp index a536cd48f9..5c0cf9d449 100644 --- a/ecmascript/containers/containers_deque.cpp +++ b/ecmascript/containers/containers_deque.cpp @@ -52,8 +52,8 @@ JSTaggedValue ContainersDeque::InsertFront(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The insertFront method cannot be bound"); @@ -77,8 +77,8 @@ JSTaggedValue ContainersDeque::InsertEnd(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The insertEnd method cannot be bound"); @@ -101,8 +101,8 @@ JSTaggedValue ContainersDeque::GetFirst(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getFirst method cannot be bound"); @@ -111,7 +111,7 @@ JSTaggedValue ContainersDeque::GetFirst(EcmaRuntimeCallInfo *argv) } JSHandle deque = JSHandle::Cast(self); - JSTaggedValue firstElement = deque->GetFront(); + JSTaggedValue firstElement = deque->GetFront(thread); return firstElement; } @@ -124,8 +124,8 @@ JSTaggedValue ContainersDeque::GetLast(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLast method cannot be bound"); @@ -134,7 +134,7 @@ JSTaggedValue ContainersDeque::GetLast(EcmaRuntimeCallInfo *argv) } JSHandle deque = JSHandle::Cast(self); - JSTaggedValue lastElement = deque->GetTail(); + JSTaggedValue lastElement = deque->GetTail(thread); return lastElement; } @@ -147,8 +147,8 @@ JSTaggedValue ContainersDeque::Has(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -159,7 +159,7 @@ JSTaggedValue ContainersDeque::Has(EcmaRuntimeCallInfo *argv) JSHandle value(GetCallArg(argv, 0)); JSHandle deque = JSHandle::Cast(self); - bool isHas = deque->Has(value.GetTaggedValue()); + bool isHas = deque->Has(thread, value.GetTaggedValue()); return GetTaggedBoolean(isHas); } @@ -172,8 +172,8 @@ JSTaggedValue ContainersDeque::PopFirst(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The popFirst method cannot be bound"); @@ -195,8 +195,8 @@ JSTaggedValue ContainersDeque::PopLast(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The popLast method cannot be bound"); @@ -218,8 +218,8 @@ JSTaggedValue ContainersDeque::ForEach(EcmaRuntimeCallInfo *argv) JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIDeque()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIDeque()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIDeque()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -232,7 +232,7 @@ JSTaggedValue ContainersDeque::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -243,12 +243,12 @@ JSTaggedValue ContainersDeque::ForEach(EcmaRuntimeCallInfo *argv) uint32_t first = deque->GetFirst(); uint32_t last = deque->GetLast(); - JSHandle elements(thread, deque->GetElements()); + JSHandle elements(thread, deque->GetElements(thread)); uint32_t capacity = elements->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); uint32_t index = 0; while (first != last) { - JSTaggedValue kValue = deque->Get(index); + JSTaggedValue kValue = deque->Get(thread, index); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3:three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -273,8 +273,8 @@ JSTaggedValue ContainersDeque::GetIteratorObj(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -295,8 +295,8 @@ JSTaggedValue ContainersDeque::GetSize(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIDeque()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIDeque()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIDeque()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -305,7 +305,7 @@ JSTaggedValue ContainersDeque::GetSize(EcmaRuntimeCallInfo *argv) } JSHandle deque = JSHandle::Cast(self); - uint32_t length = deque->GetSize(); + uint32_t length = deque->GetSize(thread); return JSTaggedValue(length); } diff --git a/ecmascript/containers/containers_hashmap.cpp b/ecmascript/containers/containers_hashmap.cpp index 56c83bd78a..feefe0b687 100644 --- a/ecmascript/containers/containers_hashmap.cpp +++ b/ecmascript/containers/containers_hashmap.cpp @@ -57,8 +57,8 @@ JSTaggedValue ContainersHashMap::Keys(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The keys method cannot be bound"); @@ -78,8 +78,8 @@ JSTaggedValue ContainersHashMap::Values(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The values method cannot be bound"); @@ -91,7 +91,7 @@ JSTaggedValue ContainersHashMap::Values(EcmaRuntimeCallInfo *argv) return iter.GetTaggedValue(); } -JSTaggedValue ContainersHashMap::GetIteratorObj(EcmaRuntimeCallInfo *argv) +JSTaggedValue ContainersHashMap::GetIteratorObj(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); @@ -99,8 +99,8 @@ JSTaggedValue ContainersHashMap::GetIteratorObj(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -120,8 +120,8 @@ JSTaggedValue ContainersHashMap::Entries(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The entries method cannot be bound"); @@ -141,8 +141,8 @@ JSTaggedValue ContainersHashMap::ForEach(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIHashMap()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIHashMap()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIHashMap()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -154,13 +154,13 @@ JSTaggedValue ContainersHashMap::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle thisArgHandle = GetCallArg(argv, 1); JSHandle hashMap = JSHandle::Cast(thisHandle); - JSHandle table(thread, hashMap->GetTable()); + JSHandle table(thread, hashMap->GetTable(thread)); uint32_t len = table->GetLength(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSMutableHandle queue(thread, factory->NewTaggedQueue(0)); @@ -172,8 +172,8 @@ JSTaggedValue ContainersHashMap::ForEach(EcmaRuntimeCallInfo *argv) while (index < len) { node.Update(TaggedHashArray::GetCurrentNode(thread, queue, table, index)); if (!node.GetTaggedValue().IsHole()) { - key.Update(node->GetKey()); - value.Update(node->GetValue()); + key.Update(node->GetKey(thread)); + value.Update(node->GetValue(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3: three args @@ -194,8 +194,8 @@ JSTaggedValue ContainersHashMap::Set(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The set method cannot be bound"); @@ -218,8 +218,8 @@ JSTaggedValue ContainersHashMap::SetAll(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The setAll method cannot be bound"); @@ -229,13 +229,13 @@ JSTaggedValue ContainersHashMap::SetAll(EcmaRuntimeCallInfo *argv) JSHandle obj = GetCallArg(argv, 0); if (!obj->IsJSAPIHashMap()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPIHashMap()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPIHashMap()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSHandle result = JSTaggedValue::ToString(thread, obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"map\" must be HashMap. Received value is: " + ConvertToString(*result); + "The type of \"map\" must be HashMap. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -255,8 +255,8 @@ JSTaggedValue ContainersHashMap::Get(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -277,8 +277,8 @@ JSTaggedValue ContainersHashMap::Remove(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -299,8 +299,8 @@ JSTaggedValue ContainersHashMap::HasKey(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasKey method cannot be bound"); @@ -321,8 +321,8 @@ JSTaggedValue ContainersHashMap::HasValue(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasValue method cannot be bound"); @@ -342,8 +342,8 @@ JSTaggedValue ContainersHashMap::Replace(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The replace method cannot be bound"); @@ -364,8 +364,8 @@ JSTaggedValue ContainersHashMap::Clear(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -385,8 +385,8 @@ JSTaggedValue ContainersHashMap::GetLength(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -405,8 +405,8 @@ JSTaggedValue ContainersHashMap::IsEmpty(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); diff --git a/ecmascript/containers/containers_hashset.cpp b/ecmascript/containers/containers_hashset.cpp index 954bcaf280..038cbe6d8f 100644 --- a/ecmascript/containers/containers_hashset.cpp +++ b/ecmascript/containers/containers_hashset.cpp @@ -57,8 +57,8 @@ JSTaggedValue ContainersHashSet::GetIteratorObj(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -77,8 +77,8 @@ JSTaggedValue ContainersHashSet::Values(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The values method cannot be bound"); @@ -97,8 +97,8 @@ JSTaggedValue ContainersHashSet::Entries(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The entries method cannot be bound"); @@ -119,8 +119,8 @@ JSTaggedValue ContainersHashSet::Add(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The add method cannot be bound"); @@ -144,8 +144,8 @@ JSTaggedValue ContainersHashSet::Remove(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -167,8 +167,8 @@ JSTaggedValue ContainersHashSet::Has(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -189,8 +189,8 @@ JSTaggedValue ContainersHashSet::Clear(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -211,8 +211,8 @@ JSTaggedValue ContainersHashSet::GetLength(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -233,8 +233,8 @@ JSTaggedValue ContainersHashSet::IsEmpty(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIHashSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIHashSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIHashSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -253,8 +253,8 @@ JSTaggedValue ContainersHashSet::ForEach(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIHashSet()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIHashSet()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIHashSet()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -266,13 +266,13 @@ JSTaggedValue ContainersHashSet::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle thisArgHandle = GetCallArg(argv, 1); JSHandle hashSet = JSHandle::Cast(thisHandle); - JSHandle table(thread, hashSet->GetTable()); + JSHandle table(thread, hashSet->GetTable(thread)); uint32_t len = table->GetLength(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSMutableHandle queue(thread, factory->NewTaggedQueue(0)); @@ -283,7 +283,7 @@ JSTaggedValue ContainersHashSet::ForEach(EcmaRuntimeCallInfo *argv) while (index < len) { node.Update(TaggedHashArray::GetCurrentNode(thread, queue, table, index)); if (!node.GetTaggedValue().IsHole()) { - currentKey.Update(node->GetKey()); + currentKey.Update(node->GetKey(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3: three args diff --git a/ecmascript/containers/containers_lightweightmap.cpp b/ecmascript/containers/containers_lightweightmap.cpp index 963f24ca00..31f0be1648 100644 --- a/ecmascript/containers/containers_lightweightmap.cpp +++ b/ecmascript/containers/containers_lightweightmap.cpp @@ -59,8 +59,8 @@ JSTaggedValue ContainersLightWeightMap::Length(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -80,8 +80,8 @@ JSTaggedValue ContainersLightWeightMap::HasAll(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasAll method cannot be bound"); @@ -92,13 +92,14 @@ JSTaggedValue ContainersLightWeightMap::HasAll(EcmaRuntimeCallInfo *argv) JSHandle lightWeightMap(GetCallArg(argv, 0)); if (!lightWeightMap->IsJSAPILightWeightMap()) { if (lightWeightMap->IsJSProxy() && - JSHandle::Cast(lightWeightMap)->GetTarget().IsJSAPILightWeightMap()) { - lightWeightMap = JSHandle(thread, JSHandle::Cast(lightWeightMap)->GetTarget()); + JSHandle::Cast(lightWeightMap)->GetTarget(thread).IsJSAPILightWeightMap()) { + lightWeightMap = + JSHandle(thread, JSHandle::Cast(lightWeightMap)->GetTarget(thread)); } else { JSHandle result = JSTaggedValue::ToString(thread, lightWeightMap.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"map\" must be LightWeightMap. Received value is: " + ConvertToString(*result); + "The type of \"map\" must be LightWeightMap. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -117,8 +118,8 @@ JSTaggedValue ContainersLightWeightMap::HasKey(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasKey method cannot be bound"); @@ -139,8 +140,8 @@ JSTaggedValue ContainersLightWeightMap::HasValue(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasValue method cannot be bound"); @@ -161,8 +162,8 @@ JSTaggedValue ContainersLightWeightMap::IncreaseCapacityTo(EcmaRuntimeCallInfo * JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The increaseCapacityTo method cannot be bound"); @@ -180,8 +181,8 @@ JSTaggedValue ContainersLightWeightMap::IncreaseCapacityTo(EcmaRuntimeCallInfo * if (!index->IsInt()) { JSHandle result = JSTaggedValue::ToString(thread, index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = - "The type of \"minimumCapacity\" must be small integer. Received value is: " + ConvertToString(*result); + CString errorMsg = "The type of \"minimumCapacity\" must be small integer. Received value is: " + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -213,8 +214,8 @@ JSTaggedValue ContainersLightWeightMap::Get(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -236,8 +237,8 @@ JSTaggedValue ContainersLightWeightMap::GetIndexOfKey(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOfKey method cannot be bound"); @@ -260,8 +261,8 @@ JSTaggedValue ContainersLightWeightMap::GetIndexOfValue(EcmaRuntimeCallInfo *arg JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOfValue method cannot be bound"); @@ -284,8 +285,8 @@ JSTaggedValue ContainersLightWeightMap::IsEmpty(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -304,8 +305,8 @@ JSTaggedValue ContainersLightWeightMap::GetKeyAt(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getKeyAt method cannot be bound"); @@ -322,7 +323,7 @@ JSTaggedValue ContainersLightWeightMap::GetKeyAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -352,8 +353,8 @@ JSTaggedValue ContainersLightWeightMap::SetAll(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The setAll method cannot be bound"); @@ -365,13 +366,14 @@ JSTaggedValue ContainersLightWeightMap::SetAll(EcmaRuntimeCallInfo *argv) if (!lightWeightMap->IsJSAPILightWeightMap()) { if (lightWeightMap->IsJSProxy() && - JSHandle::Cast(lightWeightMap)->GetTarget().IsJSAPILightWeightMap()) { - lightWeightMap = JSHandle(thread, JSHandle::Cast(lightWeightMap)->GetTarget()); + JSHandle::Cast(lightWeightMap)->GetTarget(thread).IsJSAPILightWeightMap()) { + lightWeightMap = + JSHandle(thread, JSHandle::Cast(lightWeightMap)->GetTarget(thread)); } else { JSHandle result = JSTaggedValue::ToString(thread, lightWeightMap.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"map\" must be LightWeightMap. Received value is: " + ConvertToString(*result); + "The type of \"map\" must be LightWeightMap. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -391,8 +393,8 @@ JSTaggedValue ContainersLightWeightMap::Set(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The set method cannot be bound"); @@ -417,8 +419,8 @@ JSTaggedValue ContainersLightWeightMap::Remove(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -439,8 +441,8 @@ JSTaggedValue ContainersLightWeightMap::RemoveAt(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeAt method cannot be bound"); @@ -457,7 +459,7 @@ JSTaggedValue ContainersLightWeightMap::RemoveAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -475,8 +477,8 @@ JSTaggedValue ContainersLightWeightMap::Clear(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -497,8 +499,8 @@ JSTaggedValue ContainersLightWeightMap::SetValueAt(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The setValueAt method cannot be bound"); @@ -515,7 +517,7 @@ JSTaggedValue ContainersLightWeightMap::SetValueAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -533,8 +535,8 @@ JSTaggedValue ContainersLightWeightMap::ForEach(EcmaRuntimeCallInfo *argv) // get and check lightweightmap object JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -547,15 +549,15 @@ JSTaggedValue ContainersLightWeightMap::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, func.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, 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()); + JSMutableHandle keys(thread, tmap->GetKeys(thread)); + JSMutableHandle values(thread, tmap->GetValues(thread)); uint32_t index = 0; uint32_t length = tmap->GetSize(); @@ -566,14 +568,14 @@ JSTaggedValue ContainersLightWeightMap::ForEach(EcmaRuntimeCallInfo *argv) // 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()); + info->SetCallArg(values->Get(thread, index), keys->Get(thread, 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->GetSize() != length) { - keys.Update(tmap->GetKeys()); - values.Update(tmap->GetValues()); + keys.Update(tmap->GetKeys(thread)); + values.Update(tmap->GetValues(thread)); length = tmap->GetSize(); } index++; @@ -590,8 +592,8 @@ JSTaggedValue ContainersLightWeightMap::ToString(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The toString method cannot be bound"); @@ -611,8 +613,8 @@ JSTaggedValue ContainersLightWeightMap::GetValueAt(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getValueAt method cannot be bound"); @@ -627,7 +629,7 @@ JSTaggedValue ContainersLightWeightMap::GetValueAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } diff --git a/ecmascript/containers/containers_lightweightset.cpp b/ecmascript/containers/containers_lightweightset.cpp index c78b481aec..304e91d5d1 100644 --- a/ecmascript/containers/containers_lightweightset.cpp +++ b/ecmascript/containers/containers_lightweightset.cpp @@ -57,8 +57,8 @@ JSTaggedValue ContainersLightWeightSet::Add(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, BIND_ERROR, "The add method cannot be bound"); @@ -78,8 +78,8 @@ JSTaggedValue ContainersLightWeightSet::AddAll(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The addAll method cannot be bound"); @@ -89,13 +89,13 @@ JSTaggedValue ContainersLightWeightSet::AddAll(EcmaRuntimeCallInfo *argv) JSHandle value(GetCallArg(argv, 0)); if (!value->IsJSAPILightWeightSet()) { - if (value->IsJSProxy() && JSHandle::Cast(value)->GetTarget().IsJSAPILightWeightSet()) { - value = JSHandle(thread, JSHandle::Cast(value)->GetTarget()); + if (value->IsJSProxy() && JSHandle::Cast(value)->GetTarget(thread).IsJSAPILightWeightSet()) { + value = JSHandle(thread, JSHandle::Cast(value)->GetTarget(thread)); } else { JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"set\" must be LightWeightSet. Received value is: " + ConvertToString(*result); + "The type of \"set\" must be LightWeightSet. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -112,8 +112,8 @@ JSTaggedValue ContainersLightWeightSet::IsEmpty(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -132,8 +132,8 @@ JSTaggedValue ContainersLightWeightSet::GetValueAt(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getValueAt method cannot be bound"); @@ -148,12 +148,12 @@ JSTaggedValue ContainersLightWeightSet::GetValueAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); - return set->GetValueAt(value->GetInt()); + return set->GetValueAt(thread, value->GetInt()); } JSTaggedValue ContainersLightWeightSet::HasAll(EcmaRuntimeCallInfo *argv) @@ -164,8 +164,8 @@ JSTaggedValue ContainersLightWeightSet::HasAll(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasAll method cannot be bound"); @@ -174,19 +174,19 @@ JSTaggedValue ContainersLightWeightSet::HasAll(EcmaRuntimeCallInfo *argv) } JSHandle value(GetCallArg(argv, 0)); if (!value->IsJSAPILightWeightSet()) { - if (value->IsJSProxy() && JSHandle::Cast(value)->GetTarget().IsJSAPILightWeightSet()) { - value = JSHandle(thread, JSHandle::Cast(value)->GetTarget()); + if (value->IsJSProxy() && JSHandle::Cast(value)->GetTarget(thread).IsJSAPILightWeightSet()) { + value = JSHandle(thread, JSHandle::Cast(value)->GetTarget(thread)); } else { JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"set\" must be LightWeightSet. Received value is: " + ConvertToString(*result); + "The type of \"set\" must be LightWeightSet. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } } JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); - return JSTaggedValue(set->HasAll(value)); + return JSTaggedValue(set->HasAll(thread, value)); } JSTaggedValue ContainersLightWeightSet::Has(EcmaRuntimeCallInfo *argv) @@ -197,8 +197,8 @@ JSTaggedValue ContainersLightWeightSet::Has(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -218,8 +218,8 @@ JSTaggedValue ContainersLightWeightSet::HasHash(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasHash method cannot be bound"); @@ -228,7 +228,7 @@ JSTaggedValue ContainersLightWeightSet::HasHash(EcmaRuntimeCallInfo *argv) } JSHandle value(GetCallArg(argv, 0)); JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); - return JSTaggedValue(set->HasHash(value)); + return JSTaggedValue(set->HasHash(thread, value)); } JSTaggedValue ContainersLightWeightSet::Equal(EcmaRuntimeCallInfo *argv) @@ -239,8 +239,8 @@ JSTaggedValue ContainersLightWeightSet::Equal(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The equal method cannot be bound"); @@ -259,8 +259,8 @@ JSTaggedValue ContainersLightWeightSet::IncreaseCapacityTo(EcmaRuntimeCallInfo * [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The increaseCapacityTo method cannot be bound"); @@ -277,8 +277,8 @@ JSTaggedValue ContainersLightWeightSet::IncreaseCapacityTo(EcmaRuntimeCallInfo * if (!value->IsInt()) { JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - CString errorMsg = - "The type of \"minimumCapacity\" must be small integer. Received value is: " + ConvertToString(*result); + CString errorMsg = "The type of \"minimumCapacity\" must be small integer. Received value is: " + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -296,8 +296,8 @@ JSTaggedValue ContainersLightWeightSet::GetIteratorObj(EcmaRuntimeCallInfo *argv [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -317,8 +317,8 @@ JSTaggedValue ContainersLightWeightSet::Values(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The values method cannot be bound"); @@ -338,8 +338,8 @@ JSTaggedValue ContainersLightWeightSet::Entries(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The entries method cannot be bound"); @@ -362,8 +362,9 @@ JSTaggedValue ContainersLightWeightSet::ForEach(EcmaRuntimeCallInfo *argv) JSHandle callbackFnHandle = GetCallArg(argv, 0); if (!thisHandle->IsJSAPILightWeightSet()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPILightWeightSet()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && + JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPILightWeightSet()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -375,7 +376,7 @@ JSTaggedValue ContainersLightWeightSet::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -391,8 +392,8 @@ JSTaggedValue ContainersLightWeightSet::GetIndexOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOf method cannot be bound"); @@ -413,8 +414,8 @@ JSTaggedValue ContainersLightWeightSet::Remove(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -436,8 +437,8 @@ JSTaggedValue ContainersLightWeightSet::RemoveAt(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeAt method cannot be bound"); @@ -452,7 +453,7 @@ JSTaggedValue ContainersLightWeightSet::RemoveAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -470,8 +471,8 @@ JSTaggedValue ContainersLightWeightSet::Clear(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -491,8 +492,8 @@ JSTaggedValue ContainersLightWeightSet::ToString(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The toString method cannot be bound"); @@ -512,8 +513,8 @@ JSTaggedValue ContainersLightWeightSet::ToArray(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The toArray method cannot be bound"); @@ -527,7 +528,7 @@ JSTaggedValue ContainersLightWeightSet::ToArray(EcmaRuntimeCallInfo *argv) uint32_t length = lightweightset->GetLength(); array->SetArrayLength(thread, length); - JSHandle srcArray(thread, lightweightset->GetValues()); + JSHandle srcArray(thread, lightweightset->GetValues(thread)); if (srcArray.GetTaggedValue().IsCOWArray()) { array->SetElements(thread, srcArray.GetTaggedValue()); @@ -549,8 +550,8 @@ JSTaggedValue ContainersLightWeightSet::GetSize(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILightWeightSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILightWeightSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILightWeightSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); diff --git a/ecmascript/containers/containers_linked_list.cpp b/ecmascript/containers/containers_linked_list.cpp index f15bc01d2c..f649f74293 100644 --- a/ecmascript/containers/containers_linked_list.cpp +++ b/ecmascript/containers/containers_linked_list.cpp @@ -53,8 +53,8 @@ JSTaggedValue ContainersLinkedList::Add(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The add method cannot be bound"); @@ -76,8 +76,8 @@ JSTaggedValue ContainersLinkedList::AddFirst(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The addFirst method cannot be bound"); @@ -99,8 +99,8 @@ JSTaggedValue ContainersLinkedList::GetFirst(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getFirst method cannot be bound"); @@ -108,7 +108,7 @@ JSTaggedValue ContainersLinkedList::GetFirst(EcmaRuntimeCallInfo *argv) } } JSHandle jsAPILinkedList = JSHandle::Cast(self); - return jsAPILinkedList->GetFirst(); + return jsAPILinkedList->GetFirst(thread); } JSTaggedValue ContainersLinkedList::GetLast(EcmaRuntimeCallInfo *argv) @@ -119,8 +119,8 @@ JSTaggedValue ContainersLinkedList::GetLast(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLast method cannot be bound"); @@ -128,7 +128,7 @@ JSTaggedValue ContainersLinkedList::GetLast(EcmaRuntimeCallInfo *argv) } } JSHandle jsAPILinkedList = JSHandle::Cast(self); - return jsAPILinkedList->GetLast(); + return jsAPILinkedList->GetLast(thread); } JSTaggedValue ContainersLinkedList::Length(EcmaRuntimeCallInfo *argv) @@ -139,8 +139,8 @@ JSTaggedValue ContainersLinkedList::Length(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -148,7 +148,7 @@ JSTaggedValue ContainersLinkedList::Length(EcmaRuntimeCallInfo *argv) } } JSHandle jsAPILinkedList = JSHandle::Cast(self); - return JSTaggedValue(jsAPILinkedList->Length()); + return JSTaggedValue(jsAPILinkedList->Length(thread)); } JSTaggedValue ContainersLinkedList::Insert(EcmaRuntimeCallInfo *argv) @@ -160,8 +160,8 @@ JSTaggedValue ContainersLinkedList::Insert(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The insert method cannot be bound"); @@ -179,7 +179,7 @@ JSTaggedValue ContainersLinkedList::Insert(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -198,8 +198,8 @@ JSTaggedValue ContainersLinkedList::Clear(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -220,8 +220,8 @@ JSTaggedValue ContainersLinkedList::Clone(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clone method cannot be bound"); @@ -241,8 +241,8 @@ JSTaggedValue ContainersLinkedList::Has(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -251,7 +251,7 @@ JSTaggedValue ContainersLinkedList::Has(EcmaRuntimeCallInfo *argv) } JSHandle jsAPILinkedList = JSHandle::Cast(self); JSHandle element = GetCallArg(argv, 0); - return GetTaggedBoolean(jsAPILinkedList->Has(element.GetTaggedValue())); + return GetTaggedBoolean(jsAPILinkedList->Has(thread, element.GetTaggedValue())); } JSTaggedValue ContainersLinkedList::Get(EcmaRuntimeCallInfo *argv) @@ -262,8 +262,8 @@ JSTaggedValue ContainersLinkedList::Get(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -279,11 +279,11 @@ JSTaggedValue ContainersLinkedList::Get(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - return jsAPILinkedList->Get(index->GetInt()); + return jsAPILinkedList->Get(thread, index->GetInt()); } JSTaggedValue ContainersLinkedList::GetIndexOf(EcmaRuntimeCallInfo *argv) @@ -294,8 +294,8 @@ JSTaggedValue ContainersLinkedList::GetIndexOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOf method cannot be bound"); @@ -304,7 +304,7 @@ JSTaggedValue ContainersLinkedList::GetIndexOf(EcmaRuntimeCallInfo *argv) } JSHandle jsAPILinkedList = JSHandle::Cast(self); JSHandle element = GetCallArg(argv, 0); - return jsAPILinkedList->GetIndexOf(element.GetTaggedValue()); + return jsAPILinkedList->GetIndexOf(thread, element.GetTaggedValue()); } JSTaggedValue ContainersLinkedList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) @@ -315,8 +315,8 @@ JSTaggedValue ContainersLinkedList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLastIndexOf method cannot be bound"); @@ -325,7 +325,7 @@ JSTaggedValue ContainersLinkedList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) } JSHandle jsAPILinkedList = JSHandle::Cast(self); JSHandle element(GetCallArg(argv, 0)); - return jsAPILinkedList->GetLastIndexOf(element.GetTaggedValue()); + return jsAPILinkedList->GetLastIndexOf(thread, element.GetTaggedValue()); } JSTaggedValue ContainersLinkedList::RemoveByIndex(EcmaRuntimeCallInfo *argv) @@ -336,8 +336,8 @@ JSTaggedValue ContainersLinkedList::RemoveByIndex(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeByIndex method cannot be bound"); @@ -352,7 +352,7 @@ JSTaggedValue ContainersLinkedList::RemoveByIndex(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -371,8 +371,8 @@ JSTaggedValue ContainersLinkedList::Remove(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -392,8 +392,8 @@ JSTaggedValue ContainersLinkedList::RemoveFirst(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeFirst method cannot be bound"); @@ -414,8 +414,8 @@ JSTaggedValue ContainersLinkedList::RemoveFirstFound(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeFirstFound method cannot be bound"); @@ -438,8 +438,8 @@ JSTaggedValue ContainersLinkedList::RemoveLast(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeLast method cannot be bound"); @@ -460,8 +460,8 @@ JSTaggedValue ContainersLinkedList::RemoveLastFound(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeLastFound method cannot be bound"); @@ -483,8 +483,8 @@ JSTaggedValue ContainersLinkedList::Set(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The set method cannot be bound"); @@ -500,7 +500,7 @@ JSTaggedValue ContainersLinkedList::Set(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -519,8 +519,8 @@ JSTaggedValue ContainersLinkedList::ConvertToArray(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPILinkedList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPILinkedList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPILinkedList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The convertToArray method cannot be bound"); @@ -539,8 +539,8 @@ JSTaggedValue ContainersLinkedList::ForEach(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPILinkedList()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPILinkedList()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPILinkedList()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -553,15 +553,15 @@ JSTaggedValue ContainersLinkedList::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle thisArgHandle = GetCallArg(argv, 1); JSHandle linkedList = JSHandle::Cast(thisHandle); - JSHandle doubleList(thread, linkedList->GetDoubleList()); - uint32_t length = linkedList->Length(); + JSHandle doubleList(thread, linkedList->GetDoubleList(thread)); + uint32_t length = linkedList->Length(thread); uint32_t index = 0; const uint32_t argsLength = 3; // 3: «kValue, k, O» @@ -569,7 +569,7 @@ JSTaggedValue ContainersLinkedList::ForEach(EcmaRuntimeCallInfo *argv) int valueNode = TaggedDoubleList::ELEMENTS_START_INDEX; while (index < length) { valueNode = doubleList->GetNextDataIndex(valueNode); - JSTaggedValue value = doubleList->GetElement(valueNode); + JSTaggedValue value = doubleList->GetElement(thread, valueNode); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/containers/containers_list.cpp b/ecmascript/containers/containers_list.cpp index 067994a93e..079b8535ef 100644 --- a/ecmascript/containers/containers_list.cpp +++ b/ecmascript/containers/containers_list.cpp @@ -56,8 +56,8 @@ JSTaggedValue ContainersList::Add(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The add method cannot be bound"); @@ -79,8 +79,8 @@ JSTaggedValue ContainersList::Insert(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The insert method cannot be bound"); @@ -96,7 +96,7 @@ JSTaggedValue ContainersList::Insert(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -114,8 +114,8 @@ JSTaggedValue ContainersList::GetFirst(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getFirst method cannot be bound"); @@ -123,7 +123,7 @@ JSTaggedValue ContainersList::GetFirst(EcmaRuntimeCallInfo *argv) } } JSHandle jSAPIList = JSHandle::Cast(self); - return jSAPIList->GetFirst(); + return jSAPIList->GetFirst(thread); } JSTaggedValue ContainersList::GetLast(EcmaRuntimeCallInfo *argv) @@ -134,8 +134,8 @@ JSTaggedValue ContainersList::GetLast(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLast method cannot be bound"); @@ -143,7 +143,7 @@ JSTaggedValue ContainersList::GetLast(EcmaRuntimeCallInfo *argv) } } JSHandle jSAPIList = JSHandle::Cast(self); - return jSAPIList->GetLast(); + return jSAPIList->GetLast(thread); } JSTaggedValue ContainersList::Has(EcmaRuntimeCallInfo *argv) @@ -154,8 +154,8 @@ JSTaggedValue ContainersList::Has(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -164,7 +164,7 @@ JSTaggedValue ContainersList::Has(EcmaRuntimeCallInfo *argv) } JSHandle jSAPIList = JSHandle::Cast(self); JSHandle element = GetCallArg(argv, 0); - return GetTaggedBoolean(jSAPIList->Has(element.GetTaggedValue())); + return GetTaggedBoolean(jSAPIList->Has(thread, element.GetTaggedValue())); } JSTaggedValue ContainersList::IsEmpty(EcmaRuntimeCallInfo *argv) @@ -175,8 +175,8 @@ JSTaggedValue ContainersList::IsEmpty(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -184,7 +184,7 @@ JSTaggedValue ContainersList::IsEmpty(EcmaRuntimeCallInfo *argv) } } JSHandle jSAPIList = JSHandle::Cast(self); - return GetTaggedBoolean(jSAPIList->IsEmpty()); + return GetTaggedBoolean(jSAPIList->IsEmpty(thread)); } JSTaggedValue ContainersList::Get(EcmaRuntimeCallInfo *argv) @@ -195,8 +195,8 @@ JSTaggedValue ContainersList::Get(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -212,11 +212,11 @@ JSTaggedValue ContainersList::Get(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - return jsAPIList->Get(index->GetInt()); + return jsAPIList->Get(thread, index->GetInt()); } JSTaggedValue ContainersList::GetIndexOf(EcmaRuntimeCallInfo *argv) @@ -227,8 +227,8 @@ JSTaggedValue ContainersList::GetIndexOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOf method cannot be bound"); @@ -237,7 +237,7 @@ JSTaggedValue ContainersList::GetIndexOf(EcmaRuntimeCallInfo *argv) } JSHandle jsAPIList = JSHandle::Cast(self); JSHandle element = GetCallArg(argv, 0); - return jsAPIList->GetIndexOf(element.GetTaggedValue()); + return jsAPIList->GetIndexOf(thread, element.GetTaggedValue()); } JSTaggedValue ContainersList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) @@ -248,8 +248,8 @@ JSTaggedValue ContainersList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLastIndexOf method cannot be bound"); @@ -258,7 +258,7 @@ JSTaggedValue ContainersList::GetLastIndexOf(EcmaRuntimeCallInfo *argv) } JSHandle jsAPIList = JSHandle::Cast(self); JSHandle element = GetCallArg(argv, 0); - return jsAPIList->GetLastIndexOf(element.GetTaggedValue()); + return jsAPIList->GetLastIndexOf(thread, element.GetTaggedValue()); } JSTaggedValue ContainersList::Set(EcmaRuntimeCallInfo *argv) @@ -269,8 +269,8 @@ JSTaggedValue ContainersList::Set(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The set method cannot be bound"); @@ -286,7 +286,7 @@ JSTaggedValue ContainersList::Set(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -305,8 +305,8 @@ JSTaggedValue ContainersList::ForEach(EcmaRuntimeCallInfo *argv) // get and check List object JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIList()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIList()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIList()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -320,7 +320,7 @@ JSTaggedValue ContainersList::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -328,8 +328,8 @@ JSTaggedValue ContainersList::ForEach(EcmaRuntimeCallInfo *argv) // If thisArgHandle was supplied, let T be thisArgHandle; else let T be undefined. JSHandle thisArgHandle = GetCallArg(argv, 1); JSHandle list = JSHandle::Cast(thisHandle); - JSHandle singleList(thread, list->GetSingleList()); - uint32_t length = list->Length(); + JSHandle singleList(thread, list->GetSingleList(thread)); + uint32_t length = list->Length(thread); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); uint32_t index = 0; @@ -337,7 +337,7 @@ JSTaggedValue ContainersList::ForEach(EcmaRuntimeCallInfo *argv) int valueNode = TaggedSingleList::ELEMENTS_START_INDEX; while (index < length) { valueNode = singleList->GetNextDataIndex(valueNode); - JSTaggedValue value = singleList->GetElement(valueNode); + JSTaggedValue value = singleList->GetElement(thread, valueNode); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -357,8 +357,8 @@ JSTaggedValue ContainersList::Clear(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -378,8 +378,8 @@ JSTaggedValue ContainersList::RemoveByIndex(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeByIndex method cannot be bound"); @@ -394,7 +394,7 @@ JSTaggedValue ContainersList::RemoveByIndex(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -412,8 +412,8 @@ JSTaggedValue ContainersList::Remove(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -432,8 +432,8 @@ JSTaggedValue ContainersList::ReplaceAllElements(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, List, ReplaceAllElements); JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIList()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIList()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIList()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The replaceAllElements method cannot be bound"); @@ -445,7 +445,7 @@ JSTaggedValue ContainersList::ReplaceAllElements(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -461,8 +461,8 @@ JSTaggedValue ContainersList::Equal(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The equal method cannot be bound"); @@ -472,8 +472,8 @@ JSTaggedValue ContainersList::Equal(EcmaRuntimeCallInfo *argv) JSHandle jsAPIList = JSHandle::Cast(self); JSHandle obj = GetCallArg(argv, 0); if (!obj->IsJSAPIList()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPIList()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPIList()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { return JSTaggedValue::False(); } @@ -490,8 +490,8 @@ JSTaggedValue ContainersList::Sort(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The sort method cannot be bound"); @@ -503,7 +503,7 @@ JSTaggedValue ContainersList::Sort(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"comparator\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"comparator\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -529,8 +529,8 @@ JSTaggedValue ContainersList::ConvertToArray(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The convertToArray method cannot be bound"); @@ -549,8 +549,8 @@ JSTaggedValue ContainersList::GetSubList(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getSubList method cannot be bound"); @@ -567,7 +567,7 @@ JSTaggedValue ContainersList::GetSubList(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, fromIndex.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"fromIndex\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"fromIndex\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -583,7 +583,7 @@ JSTaggedValue ContainersList::GetSubList(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, toIndex.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"toIndex\" must be number. Received value is: " + ConvertToString(*result); + "The type of \"toIndex\" must be number. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -602,8 +602,8 @@ JSTaggedValue ContainersList::Length(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIList()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIList()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIList()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -611,6 +611,6 @@ JSTaggedValue ContainersList::Length(EcmaRuntimeCallInfo *argv) } } JSHandle jsAPIList = JSHandle::Cast(self); - return JSTaggedValue(jsAPIList->Length()); + return JSTaggedValue(jsAPIList->Length(thread)); } } // namespace panda::ecmascript::containers diff --git a/ecmascript/containers/containers_plainarray.cpp b/ecmascript/containers/containers_plainarray.cpp index 4771643cd4..9ed544a30f 100644 --- a/ecmascript/containers/containers_plainarray.cpp +++ b/ecmascript/containers/containers_plainarray.cpp @@ -55,8 +55,8 @@ JSTaggedValue ContainersPlainArray::Add(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The add method cannot be bound"); @@ -72,7 +72,7 @@ JSTaggedValue ContainersPlainArray::Add(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -88,8 +88,8 @@ JSTaggedValue ContainersPlainArray::Clear(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -109,8 +109,8 @@ JSTaggedValue ContainersPlainArray::Clone(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clone method cannot be bound"); @@ -130,8 +130,8 @@ JSTaggedValue ContainersPlainArray::Has(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -146,13 +146,13 @@ JSTaggedValue ContainersPlainArray::Has(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSAPIPlainArray *array = JSAPIPlainArray::Cast(self->GetTaggedObject()); int32_t key = value->GetNumber(); - bool result = array->Has(key); + bool result = array->Has(thread, key); return JSTaggedValue(result); } @@ -164,8 +164,8 @@ JSTaggedValue ContainersPlainArray::Get(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -180,12 +180,12 @@ JSTaggedValue ContainersPlainArray::Get(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSAPIPlainArray *array = JSAPIPlainArray::Cast(self->GetTaggedObject()); - JSTaggedValue value = array->Get(key.GetTaggedValue()); + JSTaggedValue value = array->Get(thread, key.GetTaggedValue()); return value; } @@ -198,8 +198,8 @@ JSTaggedValue ContainersPlainArray::GetIteratorObj(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -218,8 +218,8 @@ JSTaggedValue ContainersPlainArray::ForEach(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, ForEach); JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIPlainArray()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIPlainArray()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIPlainArray()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -231,7 +231,7 @@ JSTaggedValue ContainersPlainArray::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -246,8 +246,8 @@ JSTaggedValue ContainersPlainArray::ToString(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, ToString); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The toString method cannot be bound"); @@ -265,8 +265,8 @@ JSTaggedValue ContainersPlainArray::GetIndexOfKey(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, GetIndexOfKey); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOfKey method cannot be bound"); @@ -281,13 +281,13 @@ JSTaggedValue ContainersPlainArray::GetIndexOfKey(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSAPIPlainArray *array = JSAPIPlainArray::Cast(self->GetTaggedObject()); int32_t key = value->GetNumber(); - JSTaggedValue result = array->GetIndexOfKey(key); + JSTaggedValue result = array->GetIndexOfKey(thread, key); return result; } @@ -298,8 +298,8 @@ JSTaggedValue ContainersPlainArray::GetIndexOfValue(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, GetIndexOfValue); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getIndexOfValue method cannot be bound"); @@ -308,7 +308,7 @@ JSTaggedValue ContainersPlainArray::GetIndexOfValue(EcmaRuntimeCallInfo *argv) } JSAPIPlainArray *array = JSAPIPlainArray::Cast(self->GetTaggedObject()); JSHandle value(GetCallArg(argv, 0)); - JSTaggedValue jsValue = array->GetIndexOfValue(value.GetTaggedValue()); + JSTaggedValue jsValue = array->GetIndexOfValue(thread, value.GetTaggedValue()); return jsValue; } @@ -319,8 +319,8 @@ JSTaggedValue ContainersPlainArray::IsEmpty(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, IsEmpty); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -339,8 +339,8 @@ JSTaggedValue ContainersPlainArray::GetKeyAt(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, GetKeyAt); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getKeyAt method cannot be bound"); @@ -355,13 +355,13 @@ JSTaggedValue ContainersPlainArray::GetKeyAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSAPIPlainArray *array = JSAPIPlainArray::Cast(self->GetTaggedObject()); int32_t index = value->GetNumber(); - JSTaggedValue result = array->GetKeyAt(index); + JSTaggedValue result = array->GetKeyAt(thread, index); return result; } @@ -372,8 +372,8 @@ JSTaggedValue ContainersPlainArray::Remove(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, Remove); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -388,7 +388,7 @@ JSTaggedValue ContainersPlainArray::Remove(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -404,8 +404,8 @@ JSTaggedValue ContainersPlainArray::RemoveAt(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, RemoveAt); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeAt method cannot be bound"); @@ -420,7 +420,7 @@ JSTaggedValue ContainersPlainArray::RemoveAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -436,8 +436,8 @@ JSTaggedValue ContainersPlainArray::RemoveRangeFrom(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, RemoveRangeFrom); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The removeRangeFrom method cannot be bound"); @@ -456,7 +456,7 @@ JSTaggedValue ContainersPlainArray::RemoveRangeFrom(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, valueIndex.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -464,7 +464,7 @@ JSTaggedValue ContainersPlainArray::RemoveRangeFrom(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, valueSize.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"size\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"size\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -483,8 +483,8 @@ JSTaggedValue ContainersPlainArray::SetValueAt(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The setValueAt method cannot be bound"); @@ -500,7 +500,7 @@ JSTaggedValue ContainersPlainArray::SetValueAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, index.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -517,8 +517,8 @@ JSTaggedValue ContainersPlainArray::GetValueAt(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getValueAt method cannot be bound"); @@ -533,7 +533,7 @@ JSTaggedValue ContainersPlainArray::GetValueAt(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, idx.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"index\" must be small integer. Received value is: " + ConvertToString(*result); + "The type of \"index\" must be small integer. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -550,8 +550,8 @@ JSTaggedValue ContainersPlainArray::GetSize(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PlainArray, GetSize); JSHandle self = GetThis(argv); if (!self->IsJSAPIPlainArray()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIPlainArray()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIPlainArray()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); diff --git a/ecmascript/containers/containers_private.cpp b/ecmascript/containers/containers_private.cpp index ac788f45c1..d5f7362558 100644 --- a/ecmascript/containers/containers_private.cpp +++ b/ecmascript/containers/containers_private.cpp @@ -65,7 +65,7 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) JSHandle thisValue(GetThis(msg)); uint32_t tag = 0; - if (!JSTaggedValue::ToElementIndex(argv.GetTaggedValue(), &tag) || tag >= ContainerTag::END) { + if (!JSTaggedValue::ToElementIndex(thread, argv.GetTaggedValue(), &tag) || tag >= ContainerTag::END) { THROW_TYPE_ERROR_AND_RETURN(thread, "Incorrect input parameters", JSTaggedValue::Exception()); } diff --git a/ecmascript/containers/containers_queue.cpp b/ecmascript/containers/containers_queue.cpp index 3f2a46f4a6..35970e34f6 100644 --- a/ecmascript/containers/containers_queue.cpp +++ b/ecmascript/containers/containers_queue.cpp @@ -53,8 +53,8 @@ JSTaggedValue ContainersQueue::Add(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIQueue()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIQueue()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIQueue()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The add method cannot be bound"); @@ -76,8 +76,8 @@ JSTaggedValue ContainersQueue::GetFirst(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIQueue()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIQueue()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIQueue()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getFirst method cannot be bound"); @@ -99,8 +99,8 @@ JSTaggedValue ContainersQueue::Pop(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIQueue()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIQueue()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIQueue()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The pop method cannot be bound"); @@ -123,8 +123,8 @@ JSTaggedValue ContainersQueue::ForEach(EcmaRuntimeCallInfo *argv) // Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); // JSAPIQueue if (!thisHandle->IsJSAPIQueue()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIQueue()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIQueue()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -143,7 +143,7 @@ JSTaggedValue ContainersQueue::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -157,7 +157,7 @@ JSTaggedValue ContainersQueue::ForEach(EcmaRuntimeCallInfo *argv) while (k < len) { JSHandle kValue = JSHandle(thread, queue->Get(thread, index)); - index = queue->GetNextPosition(index); + index = queue->GetNextPosition(thread, index); key.Update(JSTaggedValue(k)); const uint32_t argsLength = 3; EcmaRuntimeCallInfo *info = @@ -180,8 +180,8 @@ JSTaggedValue ContainersQueue::GetIteratorObj(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle self = GetThis(argv); if (!self->IsJSAPIQueue()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIQueue()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIQueue()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -201,8 +201,8 @@ JSTaggedValue ContainersQueue::GetSize(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIQueue()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIQueue()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIQueue()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -210,7 +210,7 @@ JSTaggedValue ContainersQueue::GetSize(EcmaRuntimeCallInfo *argv) } } - uint32_t length = JSHandle::Cast(self)->GetSize(); + uint32_t length = JSHandle::Cast(self)->GetSize(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(length); diff --git a/ecmascript/containers/containers_stack.cpp b/ecmascript/containers/containers_stack.cpp index 7a65d55a6b..8e6520bcf3 100644 --- a/ecmascript/containers/containers_stack.cpp +++ b/ecmascript/containers/containers_stack.cpp @@ -54,8 +54,8 @@ JSTaggedValue ContainersStack::IsEmpty(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -77,8 +77,8 @@ JSTaggedValue ContainersStack::Push(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The push method cannot be bound"); @@ -100,8 +100,8 @@ JSTaggedValue ContainersStack::Peek(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The peek method cannot be bound"); @@ -110,7 +110,7 @@ JSTaggedValue ContainersStack::Peek(EcmaRuntimeCallInfo *argv) } JSHandle stack = JSHandle::Cast(self); - JSTaggedValue jsValue = stack->Peek(); + JSTaggedValue jsValue = stack->Peek(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return jsValue; } @@ -124,8 +124,8 @@ JSTaggedValue ContainersStack::Locate(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The locate method cannot be bound"); @@ -135,7 +135,7 @@ JSTaggedValue ContainersStack::Locate(EcmaRuntimeCallInfo *argv) JSHandle value = GetCallArg(argv, 0); JSHandle stack = JSHandle::Cast(self); - int num = stack->Search(value); + int num = stack->Search(thread, value); return JSTaggedValue(num); } @@ -148,8 +148,8 @@ JSTaggedValue ContainersStack::Pop(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The pop method cannot be bound"); @@ -171,8 +171,8 @@ JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv) JSHandle thisHandle = GetThis(argv); if (!thisHandle->IsJSAPIStack()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIStack()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIStack()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -189,7 +189,7 @@ JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, callbackFnHandle.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -199,7 +199,7 @@ JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv) uint32_t k = 0; uint32_t actLen = static_cast(len + 1); while (k < actLen) { - JSTaggedValue kValue = stack->Get(k); + JSTaggedValue kValue = stack->Get(thread, k); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3:three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -220,8 +220,8 @@ JSTaggedValue ContainersStack::Iterator(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); @@ -241,8 +241,8 @@ JSTaggedValue ContainersStack::GetLength(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIStack()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIStack()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIStack()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); diff --git a/ecmascript/containers/containers_treemap.cpp b/ecmascript/containers/containers_treemap.cpp index 8dfaa779ec..b0b671e49d 100644 --- a/ecmascript/containers/containers_treemap.cpp +++ b/ecmascript/containers/containers_treemap.cpp @@ -58,7 +58,7 @@ JSTaggedValue ContainersTreeMap::TreeMapConstructor(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, compareFn.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"comparefn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"comparefn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -76,8 +76,8 @@ JSTaggedValue ContainersTreeMap::Set(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); // get and check this map if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The set method cannot be bound"); @@ -103,8 +103,8 @@ JSTaggedValue ContainersTreeMap::Get(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The get method cannot be bound"); @@ -125,8 +125,8 @@ JSTaggedValue ContainersTreeMap::Remove(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); // get and check this map if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -147,8 +147,8 @@ JSTaggedValue ContainersTreeMap::HasKey(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasKey method cannot be bound"); @@ -172,8 +172,8 @@ JSTaggedValue ContainersTreeMap::HasValue(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The hasValue method cannot be bound"); @@ -194,8 +194,8 @@ JSTaggedValue ContainersTreeMap::GetFirstKey(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getFirstKey method cannot be bound"); @@ -204,7 +204,7 @@ JSTaggedValue ContainersTreeMap::GetFirstKey(EcmaRuntimeCallInfo *argv) } JSHandle map = JSHandle::Cast(self); - return TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())->GetFirstKey(); + return TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())->GetFirstKey(thread); } JSTaggedValue ContainersTreeMap::GetLastKey(EcmaRuntimeCallInfo *argv) @@ -215,8 +215,8 @@ JSTaggedValue ContainersTreeMap::GetLastKey(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLastKey method cannot be bound"); @@ -225,7 +225,7 @@ JSTaggedValue ContainersTreeMap::GetLastKey(EcmaRuntimeCallInfo *argv) } JSHandle map = JSHandle::Cast(self); - return TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())->GetLastKey(); + return TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())->GetLastKey(thread); } JSTaggedValue ContainersTreeMap::SetAll(EcmaRuntimeCallInfo *argv) @@ -236,8 +236,8 @@ JSTaggedValue ContainersTreeMap::SetAll(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The setAll method cannot be bound"); @@ -247,23 +247,23 @@ JSTaggedValue ContainersTreeMap::SetAll(EcmaRuntimeCallInfo *argv) JSHandle obj = GetCallArg(argv, 0); if (!obj->IsJSAPITreeMap()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPITreeMap()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPITreeMap()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSHandle result = JSTaggedValue::ToString(thread, obj.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"map\" must be TreeMap. Received value is: " + ConvertToString(*result); + "The type of \"map\" must be TreeMap. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } } JSHandle dst = JSHandle::Cast(self); - JSHandle dmap(thread, dst->GetTreeMap()); - JSHandle smap(thread, JSHandle::Cast(obj)->GetTreeMap()); + JSHandle dmap(thread, dst->GetTreeMap(thread)); + JSHandle smap(thread, JSHandle::Cast(obj)->GetTreeMap(thread)); - if (JSHandle::Cast(obj)->GetSize() > 0) { + if (JSHandle::Cast(obj)->GetSize(thread) > 0) { JSTaggedValue tmap = TaggedTreeMap::SetAll(thread, dmap, smap); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); dst->SetTreeMap(thread, tmap); @@ -279,8 +279,8 @@ JSTaggedValue ContainersTreeMap::Clear(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -300,8 +300,8 @@ JSTaggedValue ContainersTreeMap::GetLowerKey(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLowerKey method cannot be bound"); @@ -312,7 +312,7 @@ JSTaggedValue ContainersTreeMap::GetLowerKey(EcmaRuntimeCallInfo *argv) JSHandle map = JSHandle::Cast(self); JSHandle key = GetCallArg(argv, 0); - JSHandle tmap(thread, map->GetTreeMap()); + JSHandle tmap(thread, map->GetTreeMap(thread)); return TaggedTreeMap::GetLowerKey(thread, tmap, key); } @@ -324,8 +324,8 @@ JSTaggedValue ContainersTreeMap::GetHigherKey(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getHigherKey method cannot be bound"); @@ -336,7 +336,7 @@ JSTaggedValue ContainersTreeMap::GetHigherKey(EcmaRuntimeCallInfo *argv) JSHandle map = JSHandle::Cast(self); JSHandle key = GetCallArg(argv, 0); - JSHandle tmap(thread, map->GetTreeMap()); + JSHandle tmap(thread, map->GetTreeMap(thread)); return TaggedTreeMap::GetHigherKey(thread, tmap, key); } @@ -348,8 +348,8 @@ JSTaggedValue ContainersTreeMap::Replace(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The replace method cannot be bound"); @@ -405,8 +405,8 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) // get and check TreeMap object JSHandle self = GetThis(argv); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -419,14 +419,14 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, func.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, 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 iteratedMap(thread, tmap->GetTreeMap()); + JSMutableHandle iteratedMap(thread, tmap->GetTreeMap(thread)); uint32_t elements = iteratedMap->NumberOfElements(); JSHandle entries = TaggedTreeMap::GetArrayFromMap(thread, iteratedMap); uint32_t index = 0; @@ -436,9 +436,9 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); while (index < elements) { - int entriesIndex = entries->Get(index).GetInt(); - key.Update(iteratedMap->GetKey(entriesIndex)); - value.Update(iteratedMap->GetValue(entriesIndex)); + int entriesIndex = entries->GetPrimitive(index).GetInt(); + key.Update(iteratedMap->GetKey(thread, entriesIndex)); + value.Update(iteratedMap->GetValue(thread, entriesIndex)); // Let funcResult be Call(callbackfn, T, «e, e, S»). EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -446,8 +446,8 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) 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->GetSize() != static_cast(length)) { - iteratedMap.Update(tmap->GetTreeMap()); + if (tmap->GetSize(thread) != static_cast(length)) { + iteratedMap.Update(tmap->GetTreeMap(thread)); entries = TaggedTreeMap::GetArrayFromMap(thread, iteratedMap); elements = iteratedMap->NumberOfElements(); length = entries->GetLength(); @@ -466,15 +466,15 @@ JSTaggedValue ContainersTreeMap::GetLength(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } } - int count = JSHandle::Cast(self)->GetSize(); + int count = JSHandle::Cast(self)->GetSize(thread); return JSTaggedValue(count); } @@ -486,8 +486,8 @@ JSTaggedValue ContainersTreeMap::IsEmpty(EcmaRuntimeCallInfo *argv) // get and check this map JSHandle self = GetThis(argv); if (!self->IsJSAPITreeMap()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeMap()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeMap()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -495,6 +495,6 @@ JSTaggedValue ContainersTreeMap::IsEmpty(EcmaRuntimeCallInfo *argv) } } JSHandle map = JSHandle::Cast(self); - return GetTaggedBoolean(map->GetSize() == 0); + return GetTaggedBoolean(map->GetSize(thread) == 0); } } // namespace panda::ecmascript::containers diff --git a/ecmascript/containers/containers_treeset.cpp b/ecmascript/containers/containers_treeset.cpp index 017e7619f9..c2004b0b2c 100644 --- a/ecmascript/containers/containers_treeset.cpp +++ b/ecmascript/containers/containers_treeset.cpp @@ -57,7 +57,7 @@ JSTaggedValue ContainersTreeSet::TreeSetConstructor(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, compareFn.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"comparefn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"comparefn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } @@ -75,8 +75,8 @@ JSTaggedValue ContainersTreeSet::Add(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self = GetThis(argv); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The add method cannot be bound"); @@ -99,8 +99,8 @@ JSTaggedValue ContainersTreeSet::Remove(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self = GetThis(argv); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The remove method cannot be bound"); @@ -121,8 +121,8 @@ JSTaggedValue ContainersTreeSet::Has(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The has method cannot be bound"); @@ -146,8 +146,8 @@ JSTaggedValue ContainersTreeSet::GetFirstValue(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getFirstValue method cannot be bound"); @@ -156,7 +156,7 @@ JSTaggedValue ContainersTreeSet::GetFirstValue(EcmaRuntimeCallInfo *argv) } JSHandle set = JSHandle::Cast(self); - return TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())->GetFirstKey(); + return TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())->GetFirstKey(thread); } JSTaggedValue ContainersTreeSet::GetLastValue(EcmaRuntimeCallInfo *argv) @@ -167,8 +167,8 @@ JSTaggedValue ContainersTreeSet::GetLastValue(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLastValue method cannot be bound"); @@ -177,7 +177,7 @@ JSTaggedValue ContainersTreeSet::GetLastValue(EcmaRuntimeCallInfo *argv) } JSHandle set = JSHandle::Cast(self); - return TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())->GetLastKey(); + return TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())->GetLastKey(thread); } JSTaggedValue ContainersTreeSet::Clear(EcmaRuntimeCallInfo *argv) @@ -188,8 +188,8 @@ JSTaggedValue ContainersTreeSet::Clear(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The clear method cannot be bound"); @@ -209,8 +209,8 @@ JSTaggedValue ContainersTreeSet::GetLowerValue(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLowerValue method cannot be bound"); @@ -220,7 +220,7 @@ JSTaggedValue ContainersTreeSet::GetLowerValue(EcmaRuntimeCallInfo *argv) JSHandle set = JSHandle::Cast(self); JSHandle key = GetCallArg(argv, 0); - JSHandle tset(thread, set->GetTreeSet()); + JSHandle tset(thread, set->GetTreeSet(thread)); return TaggedTreeSet::GetLowerKey(thread, tset, key); } @@ -232,8 +232,8 @@ JSTaggedValue ContainersTreeSet::GetHigherValue(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getHigherValue method cannot be bound"); @@ -243,7 +243,7 @@ JSTaggedValue ContainersTreeSet::GetHigherValue(EcmaRuntimeCallInfo *argv) JSHandle set = JSHandle::Cast(self); JSHandle key = GetCallArg(argv, 0); - JSHandle tset(thread, set->GetTreeSet()); + JSHandle tset(thread, set->GetTreeSet(thread)); return TaggedTreeSet::GetHigherKey(thread, tset, key); } @@ -255,8 +255,8 @@ JSTaggedValue ContainersTreeSet::PopFirst(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The popFirst method cannot be bound"); @@ -276,8 +276,8 @@ JSTaggedValue ContainersTreeSet::PopLast(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The popLast method cannot be bound"); @@ -297,8 +297,8 @@ JSTaggedValue ContainersTreeSet::IsEmpty(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self = GetThis(argv); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The isEmpty method cannot be bound"); @@ -306,7 +306,7 @@ JSTaggedValue ContainersTreeSet::IsEmpty(EcmaRuntimeCallInfo *argv) } } JSHandle set = JSHandle::Cast(self); - return GetTaggedBoolean(set->GetSize() == 0); + return GetTaggedBoolean(set->GetSize(thread) == 0); } JSTaggedValue ContainersTreeSet::Values(EcmaRuntimeCallInfo *argv) @@ -338,8 +338,8 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) // get and check TreeSet object JSHandle self = GetThis(argv); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The forEach method cannot be bound"); @@ -352,14 +352,14 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) JSHandle result = JSTaggedValue::ToString(thread, func.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(*result); + "The type of \"callbackfn\" must be callable. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } // If thisArg was supplied, let T be thisArg; else let T be undefined. JSHandle thisArg = GetCallArg(argv, 1); JSHandle tset = JSHandle::Cast(self); - JSMutableHandle iteratedSet(thread, tset->GetTreeSet()); + JSMutableHandle iteratedSet(thread, tset->GetTreeSet(thread)); uint32_t elements = iteratedSet->NumberOfElements(); JSHandle entries = TaggedTreeSet::GetArrayFromSet(thread, iteratedSet); uint32_t index = 0; @@ -368,8 +368,8 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (index < elements) { - int entriesIndex = entries->Get(index).GetInt(); - key.Update(iteratedSet->GetKey(entriesIndex)); + int entriesIndex = entries->GetPrimitive(index).GetInt(); + key.Update(iteratedSet->GetKey(thread, entriesIndex)); // Let funcResult be Call(callbackfn, T, «e, e, S»). EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -377,8 +377,8 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) 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. - if (tset->GetSize() != static_cast(length)) { - iteratedSet.Update(tset->GetTreeSet()); + if (tset->GetSize(thread) != static_cast(length)) { + iteratedSet.Update(tset->GetTreeSet(thread)); entries = TaggedTreeSet::GetArrayFromSet(thread, iteratedSet); elements = iteratedSet->NumberOfElements(); length = entries->GetLength(); @@ -397,8 +397,8 @@ JSTaggedValue ContainersTreeSet::GetLength(EcmaRuntimeCallInfo *argv) // get and check this set JSHandle self(GetThis(argv)); if (!self->IsJSAPITreeSet()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPITreeSet()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPITreeSet()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The getLength method cannot be bound"); @@ -406,7 +406,7 @@ JSTaggedValue ContainersTreeSet::GetLength(EcmaRuntimeCallInfo *argv) } } - int count = JSHandle::Cast(self)->GetSize(); + int count = JSHandle::Cast(self)->GetSize(thread); return JSTaggedValue(count); } } // namespace panda::ecmascript::containers diff --git a/ecmascript/containers/containers_vector.cpp b/ecmascript/containers/containers_vector.cpp index 3575678309..fe1ec8a847 100644 --- a/ecmascript/containers/containers_vector.cpp +++ b/ecmascript/containers/containers_vector.cpp @@ -52,8 +52,8 @@ JSTaggedValue ContainersVector::Add(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -74,8 +74,8 @@ JSTaggedValue ContainersVector::Insert(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -101,8 +101,8 @@ JSTaggedValue ContainersVector::SetLength(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -128,13 +128,13 @@ JSTaggedValue ContainersVector::GetCapacity(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } } - uint32_t capacity = JSHandle::Cast(self)->GetCapacity(); + uint32_t capacity = JSHandle::Cast(self)->GetCapacity(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue(capacity); @@ -149,8 +149,8 @@ JSTaggedValue ContainersVector::IncreaseCapacityTo(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -176,8 +176,8 @@ JSTaggedValue ContainersVector::Get(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -202,8 +202,8 @@ JSTaggedValue ContainersVector::GetIndexOf(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -224,8 +224,8 @@ JSTaggedValue ContainersVector::GetIndexFrom(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -252,8 +252,8 @@ JSTaggedValue ContainersVector::IsEmpty(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -272,13 +272,13 @@ JSTaggedValue ContainersVector::GetLastElement(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } } - JSTaggedValue value = JSHandle::Cast(self)->GetLastElement(); + JSTaggedValue value = JSHandle::Cast(self)->GetLastElement(thread); return value; } @@ -292,8 +292,8 @@ JSTaggedValue ContainersVector::GetLastIndexOf(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -314,8 +314,8 @@ JSTaggedValue ContainersVector::GetLastIndexFrom(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -342,8 +342,8 @@ JSTaggedValue ContainersVector::Remove(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -364,8 +364,8 @@ JSTaggedValue ContainersVector::RemoveByIndex(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -389,8 +389,8 @@ JSTaggedValue ContainersVector::RemoveByRange(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -417,8 +417,8 @@ JSTaggedValue ContainersVector::Set(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -449,8 +449,8 @@ JSTaggedValue ContainersVector::SubVector(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -476,8 +476,8 @@ JSTaggedValue ContainersVector::ToString(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -497,8 +497,8 @@ JSTaggedValue ContainersVector::GetSize(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -518,8 +518,8 @@ JSTaggedValue ContainersVector::ForEach(EcmaRuntimeCallInfo *argv) JSHandle thisHandle = GetThis(argv); // JSAPIVector if (!thisHandle->IsJSAPIVector()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIVector()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIVector()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -544,8 +544,8 @@ JSTaggedValue ContainersVector::ReplaceAllElements(EcmaRuntimeCallInfo *argv) // Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); // JSAPIVector if (!thisHandle->IsJSAPIVector()) { - if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget().IsJSAPIVector()) { - thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget()); + if (thisHandle->IsJSProxy() && JSHandle::Cast(thisHandle)->GetTarget(thread).IsJSAPIVector()) { + thisHandle = JSHandle(thread, JSHandle::Cast(thisHandle)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -570,8 +570,8 @@ JSTaggedValue ContainersVector::TrimToCurrentLength(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -590,8 +590,8 @@ JSTaggedValue ContainersVector::Clear(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -611,8 +611,8 @@ JSTaggedValue ContainersVector::Clone(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -630,15 +630,15 @@ JSTaggedValue ContainersVector::Has(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } } JSHandle value(GetCallArg(argv, 0)); - bool isHas = JSHandle::Cast(self)->Has(value.GetTaggedValue()); + bool isHas = JSHandle::Cast(self)->Has(thread, value.GetTaggedValue()); return GetTaggedBoolean(isHas); } @@ -651,8 +651,8 @@ JSTaggedValue ContainersVector::CopyToArray(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -663,11 +663,11 @@ JSTaggedValue ContainersVector::CopyToArray(EcmaRuntimeCallInfo *argv) } JSHandle vector = JSHandle::Cast(self); - JSHandle vectorElements(thread, vector->GetElements()); + JSHandle vectorElements(thread, vector->GetElements(thread)); uint32_t vectorLength = static_cast(vector->GetSize()); JSHandle array = JSHandle::Cast(arg0); - JSHandle arrayElements(thread, array->GetElements()); + JSHandle arrayElements(thread, array->GetElements(thread)); uint32_t arrayLength = array->GetArrayLength(); if (vectorLength <= arrayLength) { TaggedArray::CopyTaggedArrayElement(thread, vectorElements, arrayElements, vectorLength); @@ -694,8 +694,8 @@ JSTaggedValue ContainersVector::ConvertToArray(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -708,7 +708,7 @@ JSTaggedValue ContainersVector::ConvertToArray(EcmaRuntimeCallInfo *argv) uint32_t length = vector->GetSize(); array->SetArrayLength(thread, length); - JSHandle srcElements(thread, vector->GetElements()); + JSHandle srcElements(thread, vector->GetElements(thread)); JSHandle dstElements = factory->NewAndCopyTaggedArray(srcElements, length, length); array->SetElements(thread, dstElements); @@ -724,14 +724,14 @@ JSTaggedValue ContainersVector::GetFirstElement(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } } - JSTaggedValue firstElement = JSAPIVector::GetFirstElement(JSHandle::Cast(self)); + JSTaggedValue firstElement = JSAPIVector::GetFirstElement(thread, JSHandle::Cast(self)); return firstElement; } @@ -744,8 +744,8 @@ JSTaggedValue ContainersVector::Sort(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } @@ -755,17 +755,17 @@ JSTaggedValue ContainersVector::Sort(EcmaRuntimeCallInfo *argv) auto obj = JSHandle::Cast(self); uint32_t length = static_cast(obj->GetSize()); JSHandle elements = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); - elements->Copy(thread, 0, 0, TaggedArray::Cast(obj->GetElements()), length); + elements->Copy(thread, 0, 0, TaggedArray::Cast(obj->GetElements(thread)), length); JSMutableHandle presentValue(thread, JSTaggedValue::Undefined()); JSMutableHandle middleValue(thread, JSTaggedValue::Undefined()); JSMutableHandle previousValue(thread, JSTaggedValue::Undefined()); for (uint32_t i = 1; i < length; i++) { uint32_t beginIndex = 0; uint32_t endIndex = i; - presentValue.Update(elements->Get(i)); + presentValue.Update(elements->Get(thread, i)); while (beginIndex < endIndex) { uint32_t middleIndex = (beginIndex + endIndex) / 2; // 2 : half - middleValue.Update(elements->Get(middleIndex)); + middleValue.Update(elements->Get(thread, middleIndex)); double compareResult = base::ArrayHelper::SortCompare(thread, callbackFnHandle, middleValue, presentValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (compareResult > 0) { @@ -777,7 +777,7 @@ JSTaggedValue ContainersVector::Sort(EcmaRuntimeCallInfo *argv) if (endIndex < i) { for (uint32_t j = i; j > endIndex; j--) { - previousValue.Update(elements->Get(j - 1)); + previousValue.Update(elements->Get(thread, j - 1)); elements->Set(thread, j, previousValue.GetTaggedValue()); } elements->Set(thread, endIndex, presentValue.GetTaggedValue()); @@ -798,8 +798,8 @@ JSTaggedValue ContainersVector::GetIteratorObj(EcmaRuntimeCallInfo *argv) JSHandle self = GetThis(argv); if (!self->IsJSAPIVector()) { - if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget().IsJSAPIVector()) { - self = JSHandle(thread, JSHandle::Cast(self)->GetTarget()); + if (self->IsJSProxy() && JSHandle::Cast(self)->GetTarget(thread).IsJSAPIVector()) { + self = JSHandle(thread, JSHandle::Cast(self)->GetTarget(thread)); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPIVector", JSTaggedValue::Exception()); } diff --git a/ecmascript/containers/tests/containers_arraylist_test.cpp b/ecmascript/containers/tests/containers_arraylist_test.cpp index 3f8abff6a9..643301af80 100644 --- a/ecmascript/containers/tests/containers_arraylist_test.cpp +++ b/ecmascript/containers/tests/containers_arraylist_test.cpp @@ -61,13 +61,14 @@ public: public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle value = GetCallArg(argv, 0); JSHandle arrayList = GetCallArg(argv, 1); if (!arrayList->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIArrayList::Cast(arrayList.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - JSTaggedValue result = elements->Get(value->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + JSTaggedValue result = elements->Get(thread, value->GetInt()); EXPECT_EQ(result, value.GetTaggedValue()); } } @@ -175,10 +176,10 @@ HWTEST_F_L0(ContainersArrayListTest, ArrayListConstructor) ASSERT_TRUE(result.IsJSAPIArrayList()); JSHandle arrayList(thread, result); - JSTaggedValue resultProto = JSObject::GetPrototype(JSHandle::Cast(arrayList)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue resultProto = JSObject::GetPrototype(thread, JSHandle::Cast(arrayList)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); - int length = arrayList->GetLength().GetInt(); + int length = arrayList->GetLength(); ASSERT_EQ(length, 0); // 0 means the value // test ArrayListConstructor exception @@ -256,7 +257,8 @@ HWTEST_F_L0(ContainersArrayListTest, SubArrayList) // success { JSTaggedValue newArrayList = ArrayListSubArrayList(arrayList, JSTaggedValue(1), JSTaggedValue(3)); - JSHandle elements(thread, JSAPIArrayList::Cast(newArrayList.GetTaggedObject())->GetElements()); + JSHandle elements(thread, + JSAPIArrayList::Cast(newArrayList.GetTaggedObject())->GetElements(thread)); EXPECT_EQ(elements->GetLength(), static_cast(2)); // length = 3 - 1 EXPECT_EQ(elements->Get(thread, 0), JSTaggedValue(1)); EXPECT_EQ(elements->Get(thread, 1), JSTaggedValue(2)); diff --git a/ecmascript/containers/tests/containers_bitvector_test.cpp b/ecmascript/containers/tests/containers_bitvector_test.cpp index 48d5f5c000..d786a31674 100644 --- a/ecmascript/containers/tests/containers_bitvector_test.cpp +++ b/ecmascript/containers/tests/containers_bitvector_test.cpp @@ -144,8 +144,8 @@ HWTEST_F_L0(ContainersBitVectorTest, BitVectorConstructor) TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIBitVector()); JSHandle bitVector(thread, result); - JSTaggedValue resultProto = JSObject::GetPrototype(JSHandle::Cast(bitVector)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue resultProto = JSObject::GetPrototype(thread, JSHandle::Cast(bitVector)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int length = bitVector->GetLength(); ASSERT_EQ(length, 10); diff --git a/ecmascript/containers/tests/containers_buffer_test.cpp b/ecmascript/containers/tests/containers_buffer_test.cpp index 13185b5ae8..144c03ccc1 100644 --- a/ecmascript/containers/tests/containers_buffer_test.cpp +++ b/ecmascript/containers/tests/containers_buffer_test.cpp @@ -110,8 +110,8 @@ HWTEST_F_L0(ContainersBufferTest, BufferConstructor) TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIBuffer()); JSHandle buffer(thread, result); - JSTaggedValue resultProto = JSObject::GetPrototype(JSHandle::Cast(buffer)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue resultProto = JSObject::GetPrototype(thread, JSHandle::Cast(buffer)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int length = buffer->GetLength(); ASSERT_EQ(length, JSAPIFastBuffer::DEFAULT_CAPACITY_LENGTH); diff --git a/ecmascript/containers/tests/containers_deque_test.cpp b/ecmascript/containers/tests/containers_deque_test.cpp index 439c40be5c..33950776d4 100644 --- a/ecmascript/containers/tests/containers_deque_test.cpp +++ b/ecmascript/containers/tests/containers_deque_test.cpp @@ -60,14 +60,15 @@ public: public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle value = GetCallArg(argv, 0); JSHandle key = GetCallArg(argv, 1); JSHandle deque = GetCallArg(argv, 2); // 2 means the secode arg if (!deque->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIDeque::Cast(deque.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - JSTaggedValue result = elements->Get(key->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + JSTaggedValue result = elements->Get(thread, key->GetInt()); EXPECT_EQ(result, value.GetTaggedValue()); } } @@ -131,7 +132,7 @@ HWTEST_F_L0(ContainersDequeTest, DequeConstructor) ASSERT_TRUE(result.IsJSAPIDeque()); JSHandle deque(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(deque)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); // test DequeConstructor exception diff --git a/ecmascript/containers/tests/containers_hashmap_test.cpp b/ecmascript/containers/tests/containers_hashmap_test.cpp index 1228ea2c45..4cc233ecfb 100644 --- a/ecmascript/containers/tests/containers_hashmap_test.cpp +++ b/ecmascript/containers/tests/containers_hashmap_test.cpp @@ -131,7 +131,7 @@ HWTEST_F_L0(ContainersHashMapTest, HashMapConstructor) ASSERT_TRUE(result.IsJSAPIHashMap()); JSHandle mapHandle(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(mapHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int size = mapHandle->GetSize(); ASSERT_EQ(size, 0); @@ -507,7 +507,7 @@ HWTEST_F_L0(ContainersHashMapTest, Remove) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue rValue = ContainersHashMap::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(rValue, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, rValue, value.GetTaggedValue())); EXPECT_EQ(tMap->GetSize(), NODE_NUMBERS * 2 - 2); } } @@ -602,7 +602,7 @@ HWTEST_F_L0(ContainersHashMapTest, SetAll) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersHashMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, value.GetTaggedValue())); } EXPECT_EQ(dMap->GetSize(), 2 * NODE_NUMBERS); } @@ -806,7 +806,7 @@ HWTEST_F_L0(ContainersHashMapTest, Replace) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersHashMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, value.GetTaggedValue())); } } diff --git a/ecmascript/containers/tests/containers_hashset_test.cpp b/ecmascript/containers/tests/containers_hashset_test.cpp index 7a2b7f27cd..b9408c3e92 100644 --- a/ecmascript/containers/tests/containers_hashset_test.cpp +++ b/ecmascript/containers/tests/containers_hashset_test.cpp @@ -110,7 +110,7 @@ HWTEST_F_L0(ContainersHashSetTest, HashSetConstructor) ASSERT_TRUE(result.IsJSAPIHashSet()); JSHandle setHandle(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(setHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int size = setHandle->GetSize(); ASSERT_EQ(size, 0); @@ -221,7 +221,7 @@ HWTEST_F_L0(ContainersHashSetTest, Remove) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue rValue = ContainersHashSet::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(rValue, JSTaggedValue::True())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, rValue, JSTaggedValue::True())); EXPECT_EQ(tSet->GetSize(), NODE_NUMBERS * 2 - 2); } } diff --git a/ecmascript/containers/tests/containers_lightweightmap_test.cpp b/ecmascript/containers/tests/containers_lightweightmap_test.cpp index 44cbcee182..b69ca8e594 100644 --- a/ecmascript/containers/tests/containers_lightweightmap_test.cpp +++ b/ecmascript/containers/tests/containers_lightweightmap_test.cpp @@ -126,7 +126,7 @@ HWTEST_F_L0(ContainersLightWeightMapTest, LightWeightMapConstructor) ASSERT_TRUE(result.IsJSAPILightWeightMap()); JSHandle mapHandle(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(mapHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); // test PlainArrayConstructor exception diff --git a/ecmascript/containers/tests/containers_lightweightset_test.cpp b/ecmascript/containers/tests/containers_lightweightset_test.cpp index 26e7028cf4..5b04d11e11 100644 --- a/ecmascript/containers/tests/containers_lightweightset_test.cpp +++ b/ecmascript/containers/tests/containers_lightweightset_test.cpp @@ -124,8 +124,8 @@ HWTEST_F_L0(ContainersLightWeightSetTest, LightWeightSetConstructor) ASSERT_TRUE(result.IsJSAPILightWeightSet()); JSHandle mapHandle(thread, result); - JSTaggedValue resultProto = JSObject::GetPrototype(JSHandle::Cast(mapHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue resultProto = JSObject::GetPrototype(thread, JSHandle::Cast(mapHandle)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int length = mapHandle->GetLength(); ASSERT_EQ(length, 0); // 0 means the value diff --git a/ecmascript/containers/tests/containers_linked_list_test.cpp b/ecmascript/containers/tests/containers_linked_list_test.cpp index 9c2f636681..c268804b03 100644 --- a/ecmascript/containers/tests/containers_linked_list_test.cpp +++ b/ecmascript/containers/tests/containers_linked_list_test.cpp @@ -170,9 +170,9 @@ HWTEST_F_L0(ContainersLinkedListTest, LinkedListConstructor) ASSERT_TRUE(result.IsJSAPILinkedList()); JSHandle list(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(list)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); - int size = list->Length(); + int size = list->Length(thread); ASSERT_EQ(size, 0); // test PlainArrayConstructor exception @@ -188,24 +188,24 @@ HWTEST_F_L0(ContainersLinkedListTest, InsertAndGet) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = LinkedListInsert(linkedlist, JSTaggedValue(i), JSTaggedValue(5)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } // Insert in position 0(first) with value 10 result = LinkedListInsert(linkedlist, JSTaggedValue(0), JSTaggedValue(10)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS + 1)); // Insert in position NODE_NUMBERS / 2(middle) with value 10 result = LinkedListInsert(linkedlist, JSTaggedValue(NODE_NUMBERS / 2), JSTaggedValue(10)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS + 2)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS + 2)); // Insert in position NODE_NUMBERS + 2(last) with value 10 result = LinkedListInsert(linkedlist, JSTaggedValue(NODE_NUMBERS + 2), JSTaggedValue(10)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS + 3)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS + 3)); - uint32_t length = static_cast(linkedlist->Length()); + uint32_t length = static_cast(linkedlist->Length(thread)); for (uint32_t i = 0; i < length; i++) { if (i == 0) { result = LinkedListGet(linkedlist, JSTaggedValue(i)); @@ -231,7 +231,7 @@ HWTEST_F_L0(ContainersLinkedListTest, Remove) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = LinkedListInsert(linkedlist, JSTaggedValue(i), JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } { @@ -244,7 +244,7 @@ HWTEST_F_L0(ContainersLinkedListTest, Remove) JSTaggedValue rvalue = ContainersLinkedList::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 1)); } } @@ -256,18 +256,18 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveByIndex) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = LinkedListInsert(linkedlist, JSTaggedValue(i), JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } // Remove index > (NODE_NUMBERS / 2) result = LinkedListRemoveByIndex(linkedlist, JSTaggedValue(16)); EXPECT_EQ(result, JSTaggedValue(16)); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 1)); // Remove index < (NODE_NUMBERS / 2) result = LinkedListRemoveByIndex(linkedlist, JSTaggedValue(6)); EXPECT_EQ(result, JSTaggedValue(6)); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 2)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 2)); } HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) @@ -278,7 +278,7 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = LinkedListInsert(linkedlist, JSTaggedValue(i), JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } { @@ -290,7 +290,7 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) JSTaggedValue rvalue = ContainersLinkedList::RemoveFirst(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(0)); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 1)); } { @@ -303,7 +303,7 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) JSTaggedValue rvalue = ContainersLinkedList::RemoveFirstFound(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 2)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 2)); } } @@ -315,7 +315,7 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveLast) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = LinkedListInsert(linkedlist, JSTaggedValue(i), JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } { @@ -327,7 +327,7 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveLast) JSTaggedValue rvalue = ContainersLinkedList::RemoveLast(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(19)); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 1)); } { @@ -340,7 +340,7 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveLast) JSTaggedValue rvalue = ContainersLinkedList::RemoveLastFound(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 2)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(NODE_NUMBERS - 2)); } } @@ -358,7 +358,7 @@ HWTEST_F_L0(ContainersLinkedListTest, Clear) JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } { @@ -369,7 +369,7 @@ HWTEST_F_L0(ContainersLinkedListTest, Clear) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersLinkedList::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(linkedlist->Length(), 0); + EXPECT_EQ(linkedlist->Length(thread), 0); } } @@ -388,10 +388,10 @@ HWTEST_F_L0(ContainersLinkedListTest, Clone) JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedList->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedList->Length(thread), static_cast(i + 1)); } - linkedList->Dump(); + linkedList->Dump(thread); auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -425,7 +425,7 @@ HWTEST_F_L0(ContainersLinkedListTest, Values) JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } // test values @@ -465,7 +465,7 @@ HWTEST_F_L0(ContainersLinkedListTest, ForEach) JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); + EXPECT_EQ(linkedlist->Length(thread), static_cast(i + 1)); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle newLinkedlist = CreateJSAPILinkedList(); diff --git a/ecmascript/containers/tests/containers_list_test.cpp b/ecmascript/containers/tests/containers_list_test.cpp index 35773a2ac9..5db8802e21 100644 --- a/ecmascript/containers/tests/containers_list_test.cpp +++ b/ecmascript/containers/tests/containers_list_test.cpp @@ -156,9 +156,9 @@ HWTEST_F_L0(ContainersListTest, ListConstructor) ASSERT_TRUE(result.IsJSAPIList()); JSHandle list(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(list)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); - int size = list->Length(); + int size = list->Length(thread); ASSERT_EQ(size, 0); // test ListConstructor exception @@ -181,7 +181,7 @@ HWTEST_F_L0(ContainersListTest, InsertAndGet) JSTaggedValue result = ContainersList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } { @@ -225,7 +225,7 @@ HWTEST_F_L0(ContainersListTest, Remove) JSTaggedValue result = ContainersList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } { @@ -238,7 +238,7 @@ HWTEST_F_L0(ContainersListTest, Remove) JSTaggedValue rvalue = ContainersList::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(NODE_NUMBERS - 1)); + EXPECT_EQ(list->Length(thread), static_cast(NODE_NUMBERS - 1)); } { @@ -251,7 +251,7 @@ HWTEST_F_L0(ContainersListTest, Remove) JSTaggedValue rvalue = ContainersList::RemoveByIndex(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(6)); - EXPECT_EQ(list->Length(), static_cast(NODE_NUMBERS - 2)); + EXPECT_EQ(list->Length(thread), static_cast(NODE_NUMBERS - 2)); } } @@ -263,14 +263,14 @@ HWTEST_F_L0(ContainersListTest, Equal) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = ListAdd(list, JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } // Equal JSHandle list1 = CreateJSAPIList(); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { result = ListAdd(list1, JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list1->Length(), static_cast(i + 1)); + EXPECT_EQ(list1->Length(thread), static_cast(i + 1)); } result = ListEqual(list, list1); EXPECT_EQ(result, JSTaggedValue::True()); @@ -281,7 +281,7 @@ HWTEST_F_L0(ContainersListTest, Equal) result = ListAdd(list2, JSTaggedValue(i)); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list2->Length(), static_cast(i + 1)); + EXPECT_EQ(list2->Length(thread), static_cast(i + 1)); } result = ListEqual(list, list2); EXPECT_EQ(result, JSTaggedValue::False()); @@ -295,7 +295,7 @@ HWTEST_F_L0(ContainersListTest, Equal) result = ListAdd(list3, JSTaggedValue(i)); } EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list3->Length(), static_cast(i + 1)); + EXPECT_EQ(list3->Length(thread), static_cast(i + 1)); } result = ListEqual(list, list2); EXPECT_EQ(result, JSTaggedValue::False()); @@ -315,7 +315,7 @@ HWTEST_F_L0(ContainersListTest, GetSubList) JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } { @@ -327,7 +327,7 @@ HWTEST_F_L0(ContainersListTest, GetSubList) [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); JSTaggedValue newList = ContainersList::GetSubList(callInfo1); TestHelper::TearDownFrame(thread, prev1); - EXPECT_EQ(list->Length(), 10); + EXPECT_EQ(list->Length(thread), 10); for (uint32_t i = 0; i < 3; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); callInfo->SetFunction(JSTaggedValue::Undefined()); @@ -359,7 +359,7 @@ HWTEST_F_L0(ContainersListTest, ConvertToArray) oldArray->Set(thread, i, JSTaggedValue(i)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); @@ -370,11 +370,11 @@ HWTEST_F_L0(ContainersListTest, ConvertToArray) JSTaggedValue newArray = ContainersList::ConvertToArray(callInfo); TestHelper::TearDownFrame(thread, prev); JSTaggedValue newArrayValue = - JSTaggedValue::ToObject(thread, JSHandle(thread, newArray))->GetElements(); + JSTaggedValue::ToObject(thread, JSHandle(thread, newArray))->GetElements(thread); JSHandle newArrayHandle(thread, newArrayValue); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { - EXPECT_EQ(newArrayHandle->Get(i), oldArray->Get(i)); + EXPECT_EQ(newArrayHandle->Get(thread, i), oldArray->Get(thread, i)); } } @@ -392,7 +392,7 @@ HWTEST_F_L0(ContainersListTest, Clear) JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } { @@ -403,7 +403,7 @@ HWTEST_F_L0(ContainersListTest, Clear) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersList::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(list->Length(), 0); + EXPECT_EQ(list->Length(thread), 0); } } @@ -422,7 +422,7 @@ HWTEST_F_L0(ContainersListTest, Values) JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); @@ -461,7 +461,7 @@ HWTEST_F_L0(ContainersListTest, ForEach) JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(list->Length(), static_cast(i + 1)); + EXPECT_EQ(list->Length(thread), static_cast(i + 1)); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle dlist = CreateJSAPIList(); diff --git a/ecmascript/containers/tests/containers_plainarray_test.cpp b/ecmascript/containers/tests/containers_plainarray_test.cpp index 74187b6a6f..5ce39cb954 100644 --- a/ecmascript/containers/tests/containers_plainarray_test.cpp +++ b/ecmascript/containers/tests/containers_plainarray_test.cpp @@ -159,8 +159,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, PlainArrayConstructor) ASSERT_TRUE(result.IsJSAPIPlainArray()); JSHandle arrayHandle(thread, result); - JSTaggedValue resultProto = JSObject::GetPrototype(JSHandle::Cast(arrayHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue resultProto = JSObject::GetPrototype(thread, JSHandle::Cast(arrayHandle)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int size = arrayHandle->GetSize(); ASSERT_EQ(size, 0); @@ -427,9 +427,9 @@ HWTEST_F_L0(ContainersPlainArrayTest, RemoveRangeFrom) EXPECT_EQ(pArray->GetSize(), static_cast(NODE_NUMBERS - 2)); for (uint32_t i = 0; i < NODE_NUMBERS - 2; i++) { if (i < 2) { - EXPECT_EQ(pArray->Get(JSTaggedValue(i)), JSTaggedValue(i + 1)); + EXPECT_EQ(pArray->Get(thread, JSTaggedValue(i)), JSTaggedValue(i + 1)); } else { - EXPECT_EQ(pArray->Get(JSTaggedValue(i + 2)), JSTaggedValue(i + 3)); + EXPECT_EQ(pArray->Get(thread, JSTaggedValue(i + 2)), JSTaggedValue(i + 3)); } } } diff --git a/ecmascript/containers/tests/containers_queue_test.cpp b/ecmascript/containers/tests/containers_queue_test.cpp index f0e0b48a2d..788d2dddc6 100644 --- a/ecmascript/containers/tests/containers_queue_test.cpp +++ b/ecmascript/containers/tests/containers_queue_test.cpp @@ -112,7 +112,7 @@ HWTEST_F_L0(ContainersQueueTest, QueueConstructor) ASSERT_TRUE(result.IsJSAPIQueue()); JSHandle queue(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(queue)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); // test QueueConstructor exception diff --git a/ecmascript/containers/tests/containers_stack_test.cpp b/ecmascript/containers/tests/containers_stack_test.cpp index b160bb4c51..08d97fe059 100644 --- a/ecmascript/containers/tests/containers_stack_test.cpp +++ b/ecmascript/containers/tests/containers_stack_test.cpp @@ -60,14 +60,15 @@ public: public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle value = GetCallArg(argv, 0); JSHandle key = GetCallArg(argv, 1); JSHandle stack = GetCallArg(argv, 2); // 2 means the secode arg if (!stack->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIStack::Cast(stack.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - JSTaggedValue result = elements->Get(key->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + JSTaggedValue result = elements->Get(thread, key->GetInt()); EXPECT_EQ(result, value.GetTaggedValue()); } } @@ -131,7 +132,7 @@ HWTEST_F_L0(ContainersStackTest, StackConstructor) ASSERT_TRUE(result.IsJSAPIStack()); JSHandle stack(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(stack)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); // test StackConstructor exception diff --git a/ecmascript/containers/tests/containers_treemap_test.cpp b/ecmascript/containers/tests/containers_treemap_test.cpp index c3fe152659..d821352263 100644 --- a/ecmascript/containers/tests/containers_treemap_test.cpp +++ b/ecmascript/containers/tests/containers_treemap_test.cpp @@ -172,9 +172,9 @@ HWTEST_F_L0(ContainersTreeMapTest, TreeMapConstructor) ASSERT_TRUE(result.IsJSAPITreeMap()); JSHandle mapHandle(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(mapHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); - int size = mapHandle->GetSize(); + int size = mapHandle->GetSize(thread); ASSERT_EQ(size, 0); // test TreeMapConstructor exception @@ -200,7 +200,7 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAndGet) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test add string @@ -224,7 +224,7 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAndGet) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } for (int i = 0; i < NODE_NUMBERS; i++) { @@ -273,7 +273,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } for (int i = 0; i < REMOVE_SIZE; i++) { @@ -287,7 +287,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(i)); } - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS - REMOVE_SIZE); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS - REMOVE_SIZE); for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -326,7 +326,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) 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); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS - REMOVE_SIZE + i + 1); } for (int i = 0; i < REMOVE_SIZE; i++) { @@ -342,9 +342,9 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue rvalue = ContainersTreeMap::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(rvalue, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, rvalue, value.GetTaggedValue())); } - EXPECT_EQ(tmap->GetSize(), (NODE_NUMBERS - REMOVE_SIZE) * 2); + EXPECT_EQ(tmap->GetSize(thread), (NODE_NUMBERS - REMOVE_SIZE) * 2); } // treemap.hasKey(key), treemap.hasValue(value) @@ -363,7 +363,7 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } for (int i = 0; i < NODE_NUMBERS; i++) { @@ -414,7 +414,7 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } for (int i = 0; i < NODE_NUMBERS; i++) { @@ -465,7 +465,7 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test getFirstKey { @@ -511,7 +511,7 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } // test getFirstKey @@ -556,7 +556,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test clear @@ -568,7 +568,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersTreeMap::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(tmap->GetSize(), 0); + EXPECT_EQ(tmap->GetSize(thread), 0); } for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -603,7 +603,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test clear @@ -615,7 +615,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersTreeMap::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(tmap->GetSize(), 0); + EXPECT_EQ(tmap->GetSize(thread), 0); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); @@ -648,7 +648,7 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } JSHandle dmap = CreateJSAPITreeMap(); @@ -661,7 +661,7 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersTreeMap::SetAll(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(dmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(dmap->GetSize(thread), NODE_NUMBERS); } for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -696,7 +696,7 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -707,7 +707,7 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersTreeMap::SetAll(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(dmap->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(dmap->GetSize(thread), NODE_NUMBERS * 2); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); @@ -722,9 +722,9 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, value.GetTaggedValue())); } - EXPECT_EQ(dmap->GetSize(), 2 * NODE_NUMBERS); + EXPECT_EQ(dmap->GetSize(thread), 2 * NODE_NUMBERS); } // treemap.getLowerKey(key), treemap.getHigherKey(key) @@ -743,7 +743,7 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test getLowerKey @@ -800,7 +800,7 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } // test getLowerKey @@ -821,7 +821,7 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) if (i == 0) { EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS - 1)); } else { - EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, value.GetTaggedValue())); } } // test getHigherKey @@ -842,7 +842,7 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) if (i >= NODE_NUMBERS - 1) { EXPECT_EQ(result, JSTaggedValue::Undefined()); } else { - EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, value.GetTaggedValue())); } } } @@ -863,7 +863,7 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test keys @@ -928,7 +928,7 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) JSTaggedValue result1 = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result1.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result1.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } // test keys after add for (int i = 0; i < NODE_NUMBERS; i++) { @@ -943,7 +943,7 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); - EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, itRes)); } // test values after add for (int i = 0; i < NODE_NUMBERS; i++) { @@ -957,7 +957,7 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) [[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))); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, value, JSIterator::IteratorValue(thread, result))); } // test entries @@ -1001,8 +1001,10 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) 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())); - EXPECT_TRUE(JSTaggedValue::SameValue(value, JSObject::GetProperty(thread, entries, second).GetValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, + JSObject::GetProperty(thread, entries, first).GetValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, value, + JSObject::GetProperty(thread, entries, second).GetValue())); } } } @@ -1023,7 +1025,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } { @@ -1037,7 +1039,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) JSTaggedValue result = ContainersTreeMap::Replace(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS); } for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -1076,7 +1078,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } { @@ -1094,7 +1096,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) JSTaggedValue result = ContainersTreeMap::Replace(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS * 2); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); @@ -1114,7 +1116,7 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, value.GetTaggedValue())); } } @@ -1134,7 +1136,7 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test foreach function with TestForEachFunc; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -1153,7 +1155,7 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) TestHelper::TearDownFrame(thread, prev); } - EXPECT_EQ(dmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(dmap->GetSize(thread), NODE_NUMBERS); for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); callInfo->SetFunction(JSTaggedValue::Undefined()); @@ -1198,7 +1200,7 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } // test foreach function with TestForEachFunc; @@ -1216,7 +1218,7 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) TestHelper::TearDownFrame(thread, prev); } - EXPECT_EQ(dmap->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(dmap->GetSize(thread), NODE_NUMBERS * 2); for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); callInfo->SetFunction(JSTaggedValue::Undefined()); @@ -1276,7 +1278,7 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); } // test add string @@ -1298,7 +1300,7 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), NODE_NUMBERS + i + 1); } // test sort @@ -1322,7 +1324,7 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); - EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, itRes)); } for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); @@ -1352,7 +1354,7 @@ HWTEST_F_L0(ContainersTreeMapTest, IsEmpty) JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); - EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); + EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(thread), i + 1); JSTaggedValue isEmpty = ContainersTreeMap::IsEmpty(callInfo); EXPECT_EQ(isEmpty, JSTaggedValue::False()); } diff --git a/ecmascript/containers/tests/containers_treeset_test.cpp b/ecmascript/containers/tests/containers_treeset_test.cpp index e322c09797..08ad67a456 100644 --- a/ecmascript/containers/tests/containers_treeset_test.cpp +++ b/ecmascript/containers/tests/containers_treeset_test.cpp @@ -168,9 +168,9 @@ HWTEST_F_L0(ContainersTreeSetTest, TreeSetConstructor) ASSERT_TRUE(result.IsJSAPITreeSet()); JSHandle setHandle(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(setHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); - int size = setHandle->GetSize(); + int size = setHandle->GetSize(thread); ASSERT_EQ(size, 0); // test TreeSetConstructor exception @@ -195,9 +195,9 @@ HWTEST_F_L0(ContainersTreeSetTest, AddAndHas) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS); // test add string ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -216,9 +216,9 @@ HWTEST_F_L0(ContainersTreeSetTest, AddAndHas) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2); for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -263,7 +263,7 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } for (int i = 0; i < REMOVE_SIZE; i++) { @@ -277,7 +277,7 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(rvalue.IsTrue()); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - REMOVE_SIZE); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - REMOVE_SIZE); for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -312,9 +312,9 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - REMOVE_SIZE + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - REMOVE_SIZE + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2 - REMOVE_SIZE); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2 - REMOVE_SIZE); for (int i = 0; i < REMOVE_SIZE; i++) { std::string ikey = myKey + std::to_string(i); @@ -330,7 +330,7 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(rvalue.IsTrue()); } - EXPECT_EQ(tset->GetSize(), (NODE_NUMBERS - REMOVE_SIZE) * 2); + EXPECT_EQ(tset->GetSize(thread), (NODE_NUMBERS - REMOVE_SIZE) * 2); for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); @@ -366,7 +366,7 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test getFirstValue { @@ -408,9 +408,9 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2); // test getFirstValue { @@ -454,7 +454,7 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test clear { @@ -465,7 +465,7 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersTreeSet::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(tset->GetSize(), 0); + EXPECT_EQ(tset->GetSize(thread), 0); } for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -496,9 +496,9 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS); // test clear { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); @@ -508,7 +508,7 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); ContainersTreeSet::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(tset->GetSize(), 0); + EXPECT_EQ(tset->GetSize(thread), 0); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); @@ -541,7 +541,7 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test getLowerValue @@ -597,9 +597,9 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2); // test getLowerValue // using to compare the result of GetLowerValue @@ -642,7 +642,7 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) if (i == NODE_NUMBERS - 1) { EXPECT_EQ(result, JSTaggedValue::Undefined()); } else { - EXPECT_TRUE(JSTaggedValue::SameValue(result, resultKey.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, resultKey.GetTaggedValue())); } } } @@ -662,7 +662,7 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test popFirst @@ -675,7 +675,7 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) JSTaggedValue result = ContainersTreeSet::PopFirst(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - 1); } // test popLast { @@ -687,7 +687,7 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) 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 + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - 2); // 2 means two elements } // test add string @@ -707,9 +707,9 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i - 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS + i - 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2 - 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2 - 2); // test popFirst { @@ -721,7 +721,7 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) 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 + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2 - 3); // 3 means three elements } // test popLast { @@ -736,7 +736,7 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) 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 + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2 - 4); // 4 means four elements } } @@ -755,7 +755,7 @@ HWTEST_F_L0(ContainersTreeSetTest, IsEmpty) JSTaggedValue result = ContainersTreeSet::IsEmpty(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), 0); + EXPECT_EQ(tset->GetSize(thread), 0); } // add elements @@ -769,7 +769,7 @@ HWTEST_F_L0(ContainersTreeSetTest, IsEmpty) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test isEmpty { @@ -781,7 +781,7 @@ HWTEST_F_L0(ContainersTreeSetTest, IsEmpty) JSTaggedValue result = ContainersTreeSet::IsEmpty(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsFalse()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS); } } @@ -800,7 +800,7 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test values @@ -841,9 +841,9 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2); { JSMutableHandle result(thread, JSTaggedValue::Undefined()); for (int i = 0; i < NODE_NUMBERS; i++) { @@ -858,7 +858,7 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); - EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, itRes)); } } // test entries @@ -899,8 +899,10 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) 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())); - EXPECT_TRUE(JSTaggedValue::SameValue(key, JSObject::GetProperty(thread, entries, second).GetValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, + JSObject::GetProperty(thread, entries, first).GetValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, + JSObject::GetProperty(thread, entries, second).GetValue())); } } } @@ -920,7 +922,7 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } // test foreach function with TestForEachFunc; @@ -940,8 +942,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) TestHelper::TearDownFrame(thread, prev); } - EXPECT_EQ(dset->GetSize(), NODE_NUMBERS / 2); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS / 2); + EXPECT_EQ(dset->GetSize(thread), NODE_NUMBERS / 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS / 2); for (int i = 0; i < NODE_NUMBERS; i += 2) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); callInfo->SetFunction(JSTaggedValue::Undefined()); @@ -970,9 +972,9 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS / 2 + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS / 2 + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS / 2 + NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS / 2 + NODE_NUMBERS); { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForEachFunc)); @@ -986,8 +988,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) ContainersTreeSet::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } - EXPECT_EQ(dset->GetSize(), NODE_NUMBERS + 2); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - 2); + EXPECT_EQ(dset->GetSize(thread), NODE_NUMBERS + 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - 2); for (int i = 0; i < NODE_NUMBERS; i += 2) { std::string ikey = myKey + std::to_string(i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); @@ -1021,9 +1023,9 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), i + 1); + EXPECT_EQ(tset->GetSize(thread), i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS); // test add string JSMutableHandle key(thread, JSTaggedValue::Undefined()); @@ -1041,9 +1043,9 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS + i + 1); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS * 2); // test sort auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); @@ -1066,7 +1068,7 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); - EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, key, itRes)); } for (int i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); diff --git a/ecmascript/containers/tests/containers_vector_test.cpp b/ecmascript/containers/tests/containers_vector_test.cpp index 6f81baf91c..681b997818 100644 --- a/ecmascript/containers/tests/containers_vector_test.cpp +++ b/ecmascript/containers/tests/containers_vector_test.cpp @@ -62,14 +62,15 @@ public: public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle value = GetCallArg(argv, 0); JSHandle key = GetCallArg(argv, 1); JSHandle vector = GetCallArg(argv, 2); // 2 means the secode arg if (!vector->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIVector::Cast(vector.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - JSTaggedValue result = elements->Get(key->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + JSTaggedValue result = elements->Get(thread, key->GetInt()); EXPECT_EQ(result, value.GetTaggedValue()); } } @@ -151,7 +152,7 @@ HWTEST_F_L0(ContainersVectorTest, VectorConstructor) JSHandle setHandle(thread, result); JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(setHandle)); - JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(thread); ASSERT_EQ(resultProto, funcProto); int size = setHandle->GetSize(); ASSERT_EQ(size, 0); @@ -591,7 +592,7 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) JSHandle handleArr(thread, arr); JSHandle taggedArr = JSArray::ToTaggedArray(thread, handleArr); for (int32_t i = 0; i < ELEMENT_NUMS; i++) { - JSTaggedValue result = taggedArr->Get(i); + JSTaggedValue result = taggedArr->Get(thread, i); EXPECT_EQ(result, JSTaggedValue(i)); } } @@ -798,7 +799,7 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersVector::GetLastIndexFrom(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(1))); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, JSTaggedValue(1))); } // getIndexFrom { @@ -811,7 +812,7 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersVector::GetIndexFrom(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(-1))); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, JSTaggedValue(-1))); } // getIndexFrom { @@ -824,7 +825,7 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSTaggedValue result = ContainersVector::GetIndexFrom(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(-1))); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, JSTaggedValue(-1))); } } @@ -864,7 +865,7 @@ HWTEST_F_L0(ContainersVectorTest, ProxyOfGetSizeSetLength) JSTaggedValue result = ContainersVector::GetSize(callInfo); TestHelper::TearDownFrame(thread, prev1); - EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(NODE_NUMBERS * 2))); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, JSTaggedValue(NODE_NUMBERS * 2))); } // SetLength @@ -879,7 +880,7 @@ HWTEST_F_L0(ContainersVectorTest, ProxyOfGetSizeSetLength) JSTaggedValue result = ContainersVector::GetSize(callInfo); TestHelper::TearDownFrame(thread, prev1); - EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(NODE_NUMBERS / 2))); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, result, JSTaggedValue(NODE_NUMBERS / 2))); } } diff --git a/ecmascript/debugger/debugger_api.cpp b/ecmascript/debugger/debugger_api.cpp index 09da4d5b96..dd551897d3 100644 --- a/ecmascript/debugger/debugger_api.cpp +++ b/ecmascript/debugger/debugger_api.cpp @@ -121,10 +121,11 @@ uint32_t DebuggerApi::GetBytecodeOffset(const EcmaVM *ecmaVm) std::unique_ptr DebuggerApi::GetMethod(const EcmaVM *ecmaVm) { - FrameHandler frameHandler(ecmaVm->GetJSThread()); + JSThread *thread = ecmaVm->GetJSThread(); + FrameHandler frameHandler(thread); Method* method = frameHandler.GetMethod(); std::unique_ptr ptMethod = std::make_unique( - method->GetJSPandaFile(), method->GetMethodId(), method->IsNativeWithCallField()); + method->GetJSPandaFile(thread), method->GetMethodId(), method->IsNativeWithCallField()); return ptMethod; } @@ -160,8 +161,9 @@ bool DebuggerApi::IsNativeMethod(const FrameHandler *frameHandler) JSPandaFile *DebuggerApi::GetJSPandaFile(const EcmaVM *ecmaVm) { - Method *method = FrameHandler(ecmaVm->GetJSThread()).GetMethod(); - return const_cast(method->GetJSPandaFile()); + JSThread *thread = ecmaVm->GetJSThread(); + Method *method = FrameHandler(thread).GetMethod(); + return const_cast(method->GetJSPandaFile(thread)); } JSTaggedValue DebuggerApi::GetEnv(const FrameHandler *frameHandler) @@ -181,7 +183,8 @@ int32_t DebuggerApi::GetVregIndex(const FrameHandler *frameHandler, std::string_ LOG_DEBUGGER(ERROR) << "GetVregIndex: native frame not support"; return -1; } - DebugInfoExtractor *extractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile()); + DebugInfoExtractor *extractor = + JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile(frameHandler->GetJSThread())); if (extractor == nullptr) { LOG_DEBUGGER(ERROR) << "GetVregIndex: extractor is null"; return -1; @@ -292,15 +295,16 @@ int32_t DebuggerApi::GetObjectHash(const EcmaVM *ecmaVM, const JSHandleIsECMAObject()) { return 0; } - bool hasHash = ECMAObject::Cast(tagged->GetTaggedObject())->HasHash(); + JSThread *thread = ecmaVM->GetJSThread(); + bool hasHash = ECMAObject::Cast(tagged->GetTaggedObject())->HasHash(thread); if (!hasHash) { int32_t hash = base::RandomGenerator::GenerateIdentityHash(); auto ecmaObj = ECMAObject::Cast(tagged->GetTaggedObject()); - JSHandle ecmaObjHandle(ecmaVM->GetJSThread(), ecmaObj); - ECMAObject::SetHash(ecmaVM->GetJSThread(), hash, ecmaObjHandle); + JSHandle ecmaObjHandle(thread, ecmaObj); + ECMAObject::SetHash(thread, hash, ecmaObjHandle); return hash; } else { - return ECMAObject::Cast(tagged->GetTaggedObject())->GetHash(); + return ECMAObject::Cast(tagged->GetTaggedObject())->GetHash(thread); } } @@ -309,11 +313,12 @@ int32_t DebuggerApi::GetObjectHashCode(const EcmaVM *ecmaVM, const JSHandleIsECMAObject()) { return 0; } - int32_t hash = ECMAObject::Cast(tagged->GetTaggedObject())->GetHash(); + JSThread *thread = ecmaVM->GetJSThread(); + int32_t hash = ECMAObject::Cast(tagged->GetTaggedObject())->GetHash(thread); if (hash == 0) { hash = base::RandomGenerator::GenerateIdentityHash(); auto ecmaObjHandle = JSHandle::Cast(tagged); - ECMAObject::SetHash(ecmaVM->GetJSThread(), hash, ecmaObjHandle); + ECMAObject::SetHash(thread, hash, ecmaObjHandle); } return hash; } @@ -362,13 +367,14 @@ Local DebuggerApi::GetProperties(const EcmaVM *ecmaVm, const FrameHa int32_t level, uint32_t slot) { JSTaggedValue env = frameHandler->GetEnv(); + JSThread *thread = ecmaVm->GetJSThread(); for (int i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(taggedParentEnv.IsLexicalEnv()); env = taggedParentEnv; } - JSTaggedValue value = LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot); - JSHandle handledValue(ecmaVm->GetJSThread(), value); + JSTaggedValue value = LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ; + JSHandle handledValue(thread, value); return JSNApiHelper::ToLocal(handledValue); } @@ -376,26 +382,29 @@ void DebuggerApi::SetProperties(const EcmaVM *ecmaVm, const FrameHandler *frameH int32_t level, uint32_t slot, Local value) { JSTaggedValue env = frameHandler->GetEnv(); + JSThread *thread = ecmaVm->GetJSThread(); for (int i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(taggedParentEnv.IsLexicalEnv()); env = taggedParentEnv; } JSTaggedValue target = JSNApiHelper::ToJSHandle(value).GetTaggedValue(); - LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(ecmaVm->GetJSThread(), slot, target); + LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot, target); } -std::pair DebuggerApi::GetLevelSlot(const FrameHandler *frameHandler, std::string_view name) +std::pair DebuggerApi::GetLevelSlot(const JSThread *thread, const FrameHandler *frameHandler, + std::string_view name) { int32_t level = 0; uint32_t slot = 0; JSTaggedValue curEnv = frameHandler->GetEnv(); - for (; curEnv.IsLexicalEnv(); curEnv = LexicalEnv::Cast(curEnv.GetTaggedObject())->GetParentEnv(), level++) { + for (; curEnv.IsLexicalEnv(); curEnv = LexicalEnv::Cast(curEnv.GetTaggedObject())->GetParentEnv(thread), level++) { LexicalEnv *lexicalEnv = LexicalEnv::Cast(curEnv.GetTaggedObject()); - if (lexicalEnv->GetScopeInfo().IsHole()) { + if (lexicalEnv->GetScopeInfo(thread).IsHole()) { continue; } - auto result = JSNativePointer::Cast(lexicalEnv->GetScopeInfo().GetTaggedObject())->GetExternalPointer(); + auto result = + JSNativePointer::Cast(lexicalEnv->GetScopeInfo(thread).GetTaggedObject())->GetExternalPointer(); ScopeDebugInfo *scopeDebugInfo = reinterpret_cast(result); auto iter = scopeDebugInfo->scopeInfo.find(name.data()); if (iter == scopeDebugInfo->scopeInfo.end()) { @@ -417,7 +426,7 @@ Local DebuggerApi::GetGlobalValue(const EcmaVM *ecmaVm, LocalGetValue(); + result = PropertyBox::Cast(globalRec.GetTaggedObject())->GetValue(thread); return JSNApiHelper::ToLocal(JSHandle(thread, result)); } @@ -469,7 +478,7 @@ JSTaggedValue DebuggerApi::GetCurrentModule(const EcmaVM *ecmaVm) continue; } JSTaggedValue func = frameHandler.GetFunction(); - JSTaggedValue module = JSFunction::Cast(func.GetTaggedObject())->GetModule(); + JSTaggedValue module = JSFunction::Cast(func.GetTaggedObject())->GetModule(thread); if (module.IsUndefined()) { continue; } @@ -487,7 +496,7 @@ JSHandle DebuggerApi::GetImportModule(const EcmaVM *ecmaVm, return importModule; } - JSTaggedValue importEntries = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetImportEntries(); + JSTaggedValue importEntries = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetImportEntries(thread); if (importEntries.IsUndefined()) { return importModule; } @@ -498,22 +507,22 @@ JSHandle DebuggerApi::GetImportModule(const EcmaVM *ecmaVm, JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); JSMutableHandle environment(thread, thread->GlobalConstants()->GetUndefined()); for (size_t idx = 0; idx < importEntriesLen; idx++) { - ee.Update(importArray->Get(idx)); - JSTaggedValue localName = ee->GetLocalName(); - JSTaggedValue importName = ee->GetImportName(); + ee.Update(importArray->Get(thread, idx)); + JSTaggedValue localName = ee->GetLocalName(thread); + JSTaggedValue importName = ee->GetImportName(thread); // Skip 'import * as name from xxx' - if (localName.IsString() && !JSTaggedValue::SameValue(importName, starString.GetTaggedValue())) { - std::string varName = EcmaStringAccessor(localName).ToStdString(); + if (localName.IsString() && !JSTaggedValue::SameValue(thread, importName, starString.GetTaggedValue())) { + std::string varName = EcmaStringAccessor(localName).ToStdString(thread); if (varName != name) { continue; } JSTaggedValue moduleEnvironment = SourceTextModule::Cast( - currentModule->GetTaggedObject())->GetEnvironment(); + currentModule->GetTaggedObject())->GetEnvironment(thread); environment.Update(moduleEnvironment); - JSTaggedValue resolvedBinding = environment->Get(idx); + JSTaggedValue resolvedBinding = environment->Get(thread, idx); ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject()); - importModule.Update(binding->GetModule()); - name = EcmaStringAccessor(importName).ToStdString(); + importModule.Update(binding->GetModule(thread)); + name = EcmaStringAccessor(importName).ToStdString(thread); return importModule; } } @@ -526,26 +535,26 @@ int32_t DebuggerApi::GetModuleVariableIndex(const EcmaVM *ecmaVm, const JSHandle if (!currentModule->IsSourceTextModule()) { return -1; } - JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(); + JSThread *thread = ecmaVm->GetJSThread(); + JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(thread); if (dictionary.IsUndefined()) { return -1; } - JSThread *thread = ecmaVm->GetJSThread(); if (dictionary.IsTaggedArray()) { JSTaggedValue localExportEntries = SourceTextModule::Cast( - currentModule->GetTaggedObject())->GetLocalExportEntries(); + currentModule->GetTaggedObject())->GetLocalExportEntries(thread); ASSERT(localExportEntries.IsTaggedArray()); JSHandle localExportArray(thread, TaggedArray::Cast(localExportEntries.GetTaggedObject())); uint32_t exportEntriesLen = localExportArray->GetLength(); JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); for (uint32_t idx = 0; idx < exportEntriesLen; idx++) { - ee.Update(localExportArray->Get(idx)); - JSTaggedValue localKey = ee->GetLocalName(); - JSTaggedValue exportKey = ee->GetExportName(); + ee.Update(localExportArray->Get(thread, idx)); + JSTaggedValue localKey = ee->GetLocalName(thread); + JSTaggedValue exportKey = ee->GetExportName(thread); if (localKey.IsString() && exportKey.IsString()) { - std::string localName = EcmaStringAccessor(localKey).ToStdString(); - std::string exportName = EcmaStringAccessor(exportKey).ToStdString(); + std::string localName = EcmaStringAccessor(localKey).ToStdString(thread); + std::string exportName = EcmaStringAccessor(exportKey).ToStdString(thread); if (localName == name || exportName == name) { return idx; } @@ -567,15 +576,15 @@ Local DebuggerApi::GetExportVariableValue(const EcmaVM *ecmaVm, return result; } - JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(); + JSThread *thread = ecmaVm->GetJSThread(); + JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(thread); if (dictionary.IsUndefined()) { return result; } - JSThread *thread = ecmaVm->GetJSThread(); if (dictionary.IsTaggedArray()) { TaggedArray *array = TaggedArray::Cast(dictionary.GetTaggedObject()); - JSTaggedValue moduleValue = array->Get(index); + JSTaggedValue moduleValue = array->Get(thread, index); result = JSNApiHelper::ToLocal(JSHandle(thread, moduleValue)); return result; } @@ -593,12 +602,12 @@ bool DebuggerApi::SetExportVariableValue(const EcmaVM *ecmaVm, const JSHandleGetTaggedObject())->GetNameDictionary(); + JSThread *thread = ecmaVm->GetJSThread(); + JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(thread); if (dictionary.IsUndefined()) { return false; } - JSThread *thread = ecmaVm->GetJSThread(); JSTaggedValue curValue = JSNApiHelper::ToJSTaggedValue(*value); if (dictionary.IsTaggedArray()) { TaggedArray *array = TaggedArray::Cast(dictionary.GetTaggedObject()); @@ -653,13 +662,13 @@ void DebuggerApi::InitializeExportVariables(const EcmaVM *ecmaVm, LocalIsSourceTextModule()) { return; } + JSThread *thread = ecmaVm->GetJSThread(); JSTaggedValue localExportEntries = SourceTextModule::Cast( - currentModule->GetTaggedObject())->GetLocalExportEntries(); + currentModule->GetTaggedObject())->GetLocalExportEntries(thread); if (localExportEntries.IsUndefined()) { return; } - JSThread *thread = ecmaVm->GetJSThread(); JSHandle localExportArray(thread, TaggedArray::Cast(localExportEntries.GetTaggedObject())); uint32_t exportEntriesLen = localExportArray->GetLength(); JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); @@ -667,8 +676,8 @@ void DebuggerApi::InitializeExportVariables(const EcmaVM *ecmaVm, Local value(thread, thread->GlobalConstants()->GetUndefined()); JSTaggedValue moduleValue = JSTaggedValue::Undefined(); for (uint32_t idx = 0; idx < exportEntriesLen; idx++) { - ee.Update(localExportArray->Get(idx)); - JSTaggedValue key = ee->GetLocalName(); + ee.Update(localExportArray->Get(thread, idx)); + JSTaggedValue key = ee->GetLocalName(thread); name.Update(key); value.Update(moduleValue); if (key.IsString()) { @@ -686,18 +695,18 @@ void DebuggerApi::GetLocalExportVariables(const EcmaVM *ecmaVm, Local if (!currentModule->IsSourceTextModule()) { return; } - JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(); + JSThread *thread = ecmaVm->GetJSThread(); + JSTaggedValue dictionary = SourceTextModule::Cast(currentModule->GetTaggedObject())->GetNameDictionary(thread); if (dictionary.IsUndefined()) { InitializeExportVariables(ecmaVm, moduleObj, currentModule); return; } - JSThread *thread = ecmaVm->GetJSThread(); JSMutableHandle name(thread, thread->GlobalConstants()->GetUndefined()); JSMutableHandle value(thread, thread->GlobalConstants()->GetUndefined()); if (dictionary.IsTaggedArray()) { JSTaggedValue localExportEntries = SourceTextModule::Cast( - currentModule->GetTaggedObject())->GetLocalExportEntries(); + currentModule->GetTaggedObject())->GetLocalExportEntries(thread); ASSERT(localExportEntries.IsTaggedArray()); JSHandle localExportArray(thread, TaggedArray::Cast(localExportEntries.GetTaggedObject())); uint32_t exportEntriesLen = localExportArray->GetLength(); @@ -709,15 +718,15 @@ void DebuggerApi::GetLocalExportVariables(const EcmaVM *ecmaVm, Local JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); for (uint32_t idx = 0; idx < exportEntriesLen; idx++) { - ee.Update(localExportArray->Get(idx)); + ee.Update(localExportArray->Get(thread, idx)); JSTaggedValue key; if (isImportStar) { - key = ee->GetExportName(); + key = ee->GetExportName(thread); } else { - key = ee->GetLocalName(); + key = ee->GetLocalName(thread); } name.Update(key); - JSTaggedValue moduleValue = dict->Get(idx); + JSTaggedValue moduleValue = dict->Get(thread, idx); if (moduleValue.IsHole()) { moduleValue = JSTaggedValue::Undefined(); } @@ -739,26 +748,26 @@ void DebuggerApi::GetIndirectExportVariables(const EcmaVM *ecmaVm, Local module = JSHandle::Cast(currentModule); - JSTaggedValue indirectExportEntries = module->GetIndirectExportEntries(); + JSThread *thread = ecmaVm->GetJSThread(); + JSTaggedValue indirectExportEntries = module->GetIndirectExportEntries(thread); if (indirectExportEntries.IsUndefined()) { return; } ASSERT(indirectExportEntries.IsTaggedArray()); - JSThread *thread = ecmaVm->GetJSThread(); JSHandle indirectExportArray(thread, TaggedArray::Cast(indirectExportEntries.GetTaggedObject())); - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); uint32_t indirectExportEntriesLen = indirectExportArray->GetLength(); JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); JSMutableHandle name(thread, thread->GlobalConstants()->GetUndefined()); for (uint32_t idx = 0; idx < indirectExportEntriesLen; idx++) { - ee.Update(indirectExportArray->Get(idx)); - JSTaggedValue key = ee->GetImportName(); + ee.Update(indirectExportArray->Get(thread, idx)); + JSTaggedValue key = ee->GetImportName(thread); name.Update(key); if (key.IsString()) { JSHandle importModule = JSHandle::Cast( SourceTextModule::GetRequestedModuleFromCache(thread, requestedModules, ee->GetModuleRequestIndex())); ASSERT(importModule->IsSourceTextModule()); - std::string importName = EcmaStringAccessor(ee->GetImportName()).ToStdString(); + std::string importName = EcmaStringAccessor(ee->GetImportName(thread)).ToStdString(thread); Local value = GetModuleValue(ecmaVm, importModule, importName); PropertyAttribute descriptor(value, true, true, true); Local variableName = JSNApiHelper::ToLocal(name); @@ -774,24 +783,24 @@ void DebuggerApi::GetImportVariables(const EcmaVM *ecmaVm, Local &mod return; } JSHandle module = JSHandle::Cast(currentModule); - JSTaggedValue importEntries = module->GetImportEntries(); + JSThread *thread = ecmaVm->GetJSThread(); + JSTaggedValue importEntries = module->GetImportEntries(thread); if (importEntries.IsUndefined()) { return; } - JSThread *thread = ecmaVm->GetJSThread(); JSHandle importArray(thread, TaggedArray::Cast(importEntries.GetTaggedObject())); - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); uint32_t importEntriesLen = importArray->GetLength(); JSHandle starString = thread->GlobalConstants()->GetHandledStarString(); JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); JSMutableHandle name(thread, thread->GlobalConstants()->GetUndefined()); for (uint32_t idx = 0; idx < importEntriesLen; idx++) { - ee.Update(importArray->Get(idx)); - JSTaggedValue key = ee->GetImportName(); - JSTaggedValue localName = ee->GetLocalName(); + ee.Update(importArray->Get(thread, idx)); + JSTaggedValue key = ee->GetImportName(thread); + JSTaggedValue localName = ee->GetLocalName(thread); name.Update(localName); - if (JSTaggedValue::SameValue(key, starString.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, key, starString.GetTaggedValue())) { JSHandle importModule = JSHandle::Cast( SourceTextModule::GetRequestedModuleFromCache(thread, requestedModules, ee->GetModuleRequestIndex())); ASSERT(importModule->IsSourceTextModule()); @@ -824,10 +833,10 @@ void DebuggerApi::HandleUncaughtException(const EcmaVM *ecmaVm, std::string &mes JSHandle name(JSObject::GetProperty(thread, exHandle, nameKey).GetValue()); JSHandle msgKey = globalConst->GetHandledMessageString(); JSHandle msg(JSObject::GetProperty(thread, exHandle, msgKey).GetValue()); - message = ConvertToString(*name) + ": " + ConvertToString(*msg); + message = ConvertToString(thread, *name) + ": " + ConvertToString(thread, *msg); } else { JSHandle ecmaStr = JSTaggedValue::ToString(thread, exHandle); - message = ConvertToString(*ecmaStr); + message = ConvertToString(thread, *ecmaStr); } } @@ -842,7 +851,7 @@ Local DebuggerApi::GenerateFuncFromBuffer(const EcmaVM *ecmaVm, con } JSHandle program = mgr->GenerateProgram(const_cast(ecmaVm), jsPandaFile.get(), entryPoint); - JSTaggedValue func = program->GetMainFunction(); + JSTaggedValue func = program->GetMainFunction(ecmaVm->GetJSThread()); return JSNApiHelper::ToLocal(JSHandle(ecmaVm->GetJSThread(), func)); } @@ -886,13 +895,14 @@ Local DebuggerApi::CallFunctionOnCall(EcmaVM *ecmaVm, LocalGetJSThread()); + JSThread *thread = ecmaVm->GetJSThread(); + FrameHandler frameHandler(thread); for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) { if (frameHandler.IsEntryFrame()) { return false; } auto method = frameHandler.GetMethod(); - if (method->FindCatchBlock(frameHandler.GetBytecodeOffset()) != INVALID_INDEX) { + if (method->FindCatchBlock(thread, frameHandler.GetBytecodeOffset()) != INVALID_INDEX) { return true; } } @@ -930,7 +940,7 @@ std::vector DebuggerApi::GetNativePointer(const EcmaVM *ecmaVm) if (method->IsNativeWithCallField()) { JSTaggedValue function = it.GetFunction(); JSHandle extraInfoValue( - thread, JSFunctionBase::Cast(function.GetTaggedObject())->GetFunctionExtraInfo()); + thread, JSFunctionBase::Cast(function.GetTaggedObject())->GetFunctionExtraInfo(thread)); auto cb = ecmaVm->GetNativePtrGetter(); if (extraInfoValue->IsJSNativePointer() && cb != nullptr) { JSHandle extraInfo(extraInfoValue); @@ -980,13 +990,13 @@ Local DebuggerApi::GetDequeValue(const EcmaVM *ecmaVm, Local internalObjects) { JSHandle deque(JSNApiHelper::ToJSHandle(value)); - uint32_t size = static_cast(deque->GetSize()); - Local jsValueRef = ArrayRef::New(ecmaVm, size); JSThread *thread = ecmaVm->GetJSThread(); + uint32_t size = static_cast(deque->GetSize(thread)); + Local jsValueRef = ArrayRef::New(ecmaVm, size); JSMutableHandle currentValue(thread, JSTaggedValue::Undefined()); uint32_t index = 0; while (index < size) { - currentValue.Update(deque->Get(index)); + currentValue.Update(deque->Get(thread, index)); ArrayRef::SetValueAt(ecmaVm, jsValueRef, index++, JSNApiHelper::ToLocal(currentValue)); } AddInternalProperties(ecmaVm, jsValueRef, ArkInternalValueType::Entry, internalObjects); @@ -998,7 +1008,7 @@ Local DebuggerApi::GetHashMapValue(const EcmaVM *ecmaVm, Local hashMap(JSNApiHelper::ToJSHandle(value)); JSThread *thread = ecmaVm->GetJSThread(); - JSHandle table(thread, hashMap->GetTable()); + JSHandle table(thread, hashMap->GetTable(thread)); uint32_t length = table->GetLength(); uint32_t size = static_cast(hashMap->GetSize()); Local jsValueRef = ArrayRef::New(ecmaVm, size); @@ -1014,8 +1024,8 @@ Local DebuggerApi::GetHashMapValue(const EcmaVM *ecmaVm, LocalGetKey()); - currentValue.Update(node->GetValue()); + currentKey.Update(node->GetKey(thread)); + currentValue.Update(node->GetValue(thread)); Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsKey, JSNApiHelper::ToLocal(currentKey)); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentValue)); @@ -1032,7 +1042,7 @@ Local DebuggerApi::GetHashSetValue(const EcmaVM *ecmaVm, Local hashSet(JSNApiHelper::ToJSHandle(value)); JSThread *thread = ecmaVm->GetJSThread(); - JSHandle table(thread, hashSet->GetTable()); + JSHandle table(thread, hashSet->GetTable(thread)); uint32_t length = table->GetLength(); uint32_t size = static_cast(hashSet->GetSize()); Local jsValueRef = ArrayRef::New(ecmaVm, size); @@ -1046,7 +1056,7 @@ Local DebuggerApi::GetHashSetValue(const EcmaVM *ecmaVm, LocalGetKey()); + currentKey.Update(node->GetKey(thread)); if (currentKey->IsECMAObject()) { Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentKey)); @@ -1068,16 +1078,16 @@ Local DebuggerApi::GetLightWeightMapValue(const EcmaVM *ecmaVm, Loca uint32_t size = static_cast(lightweightMap->GetSize()); Local jsValueRef = ArrayRef::New(ecmaVm, size); JSThread *thread = ecmaVm->GetJSThread(); - JSMutableHandle keys(thread, lightweightMap->GetKeys()); - JSMutableHandle values(thread, lightweightMap->GetValues()); + JSMutableHandle keys(thread, lightweightMap->GetKeys(thread)); + JSMutableHandle values(thread, lightweightMap->GetValues(thread)); JSMutableHandle currentKey(thread, JSTaggedValue::Undefined()); JSMutableHandle currentValue(thread, JSTaggedValue::Undefined()); Local jsKey = StringRef::NewFromUtf8(ecmaVm, "key"); Local jsValue = StringRef::NewFromUtf8(ecmaVm, "value"); uint32_t index = 0; while (index < size) { - currentKey.Update(keys->Get(index)); - currentValue.Update(values->Get(index)); + currentKey.Update(keys->Get(thread, index)); + currentValue.Update(values->Get(thread, index)); Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsKey, JSNApiHelper::ToLocal(currentKey)); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentValue)); @@ -1099,7 +1109,7 @@ Local DebuggerApi::GetLightWeightSetValue(const EcmaVM *ecmaVm, Loca Local jsValue = StringRef::NewFromUtf8(ecmaVm, "value"); uint32_t index = 0; while (index < size) { - currentValue.Update(lightWeightSet->GetValueAt(index)); + currentValue.Update(lightWeightSet->GetValueAt(thread, index)); if (currentValue->IsECMAObject()) { Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentValue)); @@ -1118,15 +1128,15 @@ Local DebuggerApi::GetLinkedListValue(const EcmaVM *ecmaVm, Local linkedList(JSNApiHelper::ToJSHandle(value)); JSThread *thread = ecmaVm->GetJSThread(); - JSHandle doubleList(thread, linkedList->GetDoubleList()); - uint32_t size = static_cast(linkedList->Length()); + JSHandle doubleList(thread, linkedList->GetDoubleList(thread)); + uint32_t size = static_cast(linkedList->Length(thread)); Local jsValueRef = ArrayRef::New(ecmaVm, size); JSMutableHandle currentValue(thread, JSTaggedValue::Undefined()); int valueNode = TaggedDoubleList::ELEMENTS_START_INDEX; uint32_t index = 0; while (index < size) { valueNode = doubleList->GetNextDataIndex(valueNode); - currentValue.Update(doubleList->GetElement(valueNode)); + currentValue.Update(doubleList->GetElement(thread, valueNode)); ArrayRef::SetValueAt(ecmaVm, jsValueRef, index++, JSNApiHelper::ToLocal(currentValue)); } AddInternalProperties(ecmaVm, jsValueRef, ArkInternalValueType::Entry, internalObjects); @@ -1138,15 +1148,15 @@ Local DebuggerApi::GetListValue(const EcmaVM *ecmaVm, Local list(JSNApiHelper::ToJSHandle(value)); JSThread *thread = ecmaVm->GetJSThread(); - JSHandle singleList(thread, list->GetSingleList()); - uint32_t size = static_cast(list->Length()); + JSHandle singleList(thread, list->GetSingleList(thread)); + uint32_t size = static_cast(list->Length(thread)); Local jsValueRef = ArrayRef::New(ecmaVm, size); JSMutableHandle currentValue(thread, JSTaggedValue::Undefined()); int valueNode = TaggedDoubleList::ELEMENTS_START_INDEX; uint32_t index = 0; while (index < size) { valueNode = singleList->GetNextDataIndex(valueNode); - currentValue.Update(singleList->GetElement(valueNode)); + currentValue.Update(singleList->GetElement(thread, valueNode)); ArrayRef::SetValueAt(ecmaVm, jsValueRef, index++, JSNApiHelper::ToLocal(currentValue)); } AddInternalProperties(ecmaVm, jsValueRef, ArkInternalValueType::Entry, internalObjects); @@ -1160,16 +1170,16 @@ Local DebuggerApi::GetPlainArrayValue(const EcmaVM *ecmaVm, Local(plainarray->GetSize()); Local jsValueRef = ArrayRef::New(ecmaVm, size); JSThread *thread = ecmaVm->GetJSThread(); - JSHandle keyArray(thread, plainarray->GetKeys()); - JSHandle valueArray(thread, plainarray->GetValues()); + JSHandle keyArray(thread, plainarray->GetKeys(thread)); + JSHandle valueArray(thread, plainarray->GetValues(thread)); JSMutableHandle currentKey(thread, JSTaggedValue::Undefined()); JSMutableHandle currentValue(thread, JSTaggedValue::Undefined()); Local jsKey = StringRef::NewFromUtf8(ecmaVm, "key"); Local jsValue = StringRef::NewFromUtf8(ecmaVm, "value"); uint32_t index = 0; while (index < size) { - currentKey.Update(keyArray->Get(index)); - currentValue.Update(valueArray->Get(index)); + currentKey.Update(keyArray->Get(thread, index)); + currentValue.Update(valueArray->Get(thread, index)); Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsKey, JSNApiHelper::ToLocal(currentKey)); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentValue)); @@ -1184,15 +1194,15 @@ Local DebuggerApi::GetQueueValue(const EcmaVM *ecmaVm, Local internalObjects) { JSHandle queue(JSNApiHelper::ToJSHandle(value)); - uint32_t size = static_cast(queue->GetSize()); - Local jsValueRef = ArrayRef::New(ecmaVm, size); JSThread *thread = ecmaVm->GetJSThread(); + uint32_t size = static_cast(queue->GetSize(thread)); + Local jsValueRef = ArrayRef::New(ecmaVm, size); JSMutableHandle currentValue(thread, JSTaggedValue::Undefined()); uint32_t pos = 0; uint32_t index = 0; while (index < size) { currentValue.Update(queue->Get(thread, pos)); - pos = queue->GetNextPosition(pos); + pos = queue->GetNextPosition(thread, pos); ArrayRef::SetValueAt(ecmaVm, jsValueRef, index++, JSNApiHelper::ToLocal(currentValue)); } AddInternalProperties(ecmaVm, jsValueRef, ArkInternalValueType::Entry, internalObjects); @@ -1209,7 +1219,7 @@ Local DebuggerApi::GetStackValue(const EcmaVM *ecmaVm, Local currentValue(thread, JSTaggedValue::Undefined()); uint32_t index = 0; while (index < size) { - currentValue.Update(stack->Get(index)); + currentValue.Update(stack->Get(thread, index)); ArrayRef::SetValueAt(ecmaVm, jsValueRef, index++, JSNApiHelper::ToLocal(currentValue)); } AddInternalProperties(ecmaVm, jsValueRef, ArkInternalValueType::Entry, internalObjects); @@ -1220,10 +1230,10 @@ Local DebuggerApi::GetTreeMapValue(const EcmaVM *ecmaVm, Local internalObjects) { JSHandle treeMap(JSNApiHelper::ToJSHandle(value)); - uint32_t size = static_cast(treeMap->GetSize()); - Local jsValueRef = ArrayRef::New(ecmaVm, size); JSThread *thread = ecmaVm->GetJSThread(); - JSMutableHandle iteratedMap(thread, treeMap->GetTreeMap()); + uint32_t size = static_cast(treeMap->GetSize(thread)); + Local jsValueRef = ArrayRef::New(ecmaVm, size); + JSMutableHandle iteratedMap(thread, treeMap->GetTreeMap(thread)); uint32_t elements = static_cast(iteratedMap->NumberOfElements()); JSHandle entries = TaggedTreeMap::GetArrayFromMap(thread, iteratedMap); JSMutableHandle currentKey(thread, JSTaggedValue::Undefined()); @@ -1232,9 +1242,9 @@ Local DebuggerApi::GetTreeMapValue(const EcmaVM *ecmaVm, Local jsValue = StringRef::NewFromUtf8(ecmaVm, "value"); uint32_t index = 0; while (index < elements) { - int entriesIndex = entries->Get(index).GetInt(); - currentKey.Update(iteratedMap->GetKey(entriesIndex)); - currentValue.Update(iteratedMap->GetValue(entriesIndex)); + int entriesIndex = entries->Get(thread, index).GetInt(); + currentKey.Update(iteratedMap->GetKey(thread, entriesIndex)); + currentValue.Update(iteratedMap->GetValue(thread, entriesIndex)); Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsKey, JSNApiHelper::ToLocal(currentKey)); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentValue)); @@ -1250,7 +1260,7 @@ Local DebuggerApi::GetTreeSetValue(const EcmaVM *ecmaVm, Local treeSet(JSNApiHelper::ToJSHandle(value)); JSThread *thread = ecmaVm->GetJSThread(); - JSMutableHandle iteratedSet(thread, treeSet->GetTreeSet()); + JSMutableHandle iteratedSet(thread, treeSet->GetTreeSet(thread)); uint32_t elements = static_cast(iteratedSet->NumberOfElements()); Local jsValueRef = ArrayRef::New(ecmaVm, elements); JSHandle entries = TaggedTreeSet::GetArrayFromSet(thread, iteratedSet); @@ -1258,8 +1268,8 @@ Local DebuggerApi::GetTreeSetValue(const EcmaVM *ecmaVm, Local jsValue = StringRef::NewFromUtf8(ecmaVm, "value"); uint32_t index = 0; while (index < elements) { - int entriesIndex = entries->Get(index).GetInt(); - currentValue.Update(iteratedSet->GetKey(entriesIndex)); + int entriesIndex = entries->Get(thread, index).GetInt(); + currentValue.Update(iteratedSet->GetKey(thread, entriesIndex)); if (currentValue->IsECMAObject()) { Local objRef = ObjectRef::New(ecmaVm); objRef->Set(ecmaVm, jsValue, JSNApiHelper::ToLocal(currentValue)); diff --git a/ecmascript/debugger/debugger_api.h b/ecmascript/debugger/debugger_api.h index 06fca02863..ab3232ff48 100644 --- a/ecmascript/debugger/debugger_api.h +++ b/ecmascript/debugger/debugger_api.h @@ -104,7 +104,8 @@ public: int32_t level, uint32_t slot); static void SetProperties(const EcmaVM *ecmaVm, const FrameHandler *frameHandler, int32_t level, uint32_t slot, Local value); - static std::pair GetLevelSlot(const FrameHandler *frameHandler, std::string_view name); + static std::pair GetLevelSlot(const JSThread *ecmaVm, const FrameHandler *frameHandler, + std::string_view name); static Local GetGlobalValue(const EcmaVM *ecmaVm, Local name); static bool SetGlobalValue(const EcmaVM *ecmaVm, Local name, Local value); diff --git a/ecmascript/debugger/dropframe_manager.cpp b/ecmascript/debugger/dropframe_manager.cpp index ff9cf2c497..88333412a1 100644 --- a/ecmascript/debugger/dropframe_manager.cpp +++ b/ecmascript/debugger/dropframe_manager.cpp @@ -72,7 +72,7 @@ std::pair DropframeManager::ReadStlexvarParams(const uint8_t void DropframeManager::MethodEntry(JSThread *thread, JSHandle method, JSHandle envHandle) { std::set> modifiedLexVarPos; - const JSPandaFile* methodJsPandaFile = method->GetJSPandaFile(); + const JSPandaFile* methodJsPandaFile = method->GetJSPandaFile(thread); panda_file::File::EntityId methodId = method->GetMethodId(); PushMethodInfo(std::make_tuple(const_cast(methodJsPandaFile), methodId)); if (method->IsSendableMethod()) { @@ -86,7 +86,7 @@ void DropframeManager::MethodEntry(JSThread *thread, JSHandle method, JS return; } PushMethodType(MethodType::NORMAL_METHOD); - uint32_t codeSize = method->GetCodeSize(); + uint32_t codeSize = method->GetCodeSize(thread); uint16_t newEnvCount = 0; auto bcIns = BytecodeInstruction(method->GetBytecodeArray()); auto bcInsLast = bcIns.JumpTo(codeSize); @@ -114,14 +114,14 @@ void DropframeManager::AddLexPropertiesToRecord(JSThread *thread, BytecodeInstru if ((level < newEnvCount || i >= level - newEnvCount) && slot < LexicalEnv::Cast(env.GetTaggedObject())->GetLength() - LexicalEnv::RESERVED_ENV_LENGTH && !modifiedLexVarPos.count({i, slot})) { - JSTaggedValue value = LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot); + JSTaggedValue value = LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ; EmplaceLexModifyRecord(thread, env, slot, value); modifiedLexVarPos.insert({i, slot}); } if (i >= level) { break; } - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); if (!taggedParentEnv.IsLexicalEnv()) { break; } @@ -132,7 +132,7 @@ void DropframeManager::AddLexPropertiesToRecord(JSThread *thread, BytecodeInstru void DropframeManager::MethodExit(JSThread *thread, [[maybe_unused]] JSHandle method) { - const JSPandaFile* methodJsPandaFile = method->GetJSPandaFile(); + const JSPandaFile* methodJsPandaFile = method->GetJSPandaFile(thread); panda_file::File::EntityId methodId = method->GetMethodId(); if (!CheckExitMethodInfo(std::make_tuple(const_cast(methodJsPandaFile), methodId))) { return; diff --git a/ecmascript/debugger/js_debugger.cpp b/ecmascript/debugger/js_debugger.cpp index ee8f7e871a..c61116464e 100644 --- a/ecmascript/debugger/js_debugger.cpp +++ b/ecmascript/debugger/js_debugger.cpp @@ -107,7 +107,7 @@ bool JSDebugger::RemoveBreakpointsByUrl(const std::string &url) void JSDebugger::BytecodePcChanged(JSThread *thread, JSHandle method, uint32_t bcOffset) { - ASSERT(bcOffset < method->GetCodeSize() && "code size of current Method less then bcOffset"); + ASSERT(bcOffset < method->GetCodeSize(thread) && "code size of current Method less then bcOffset"); HandleExceptionThrowEvent(thread, method, bcOffset); // clear singlestep flag singleStepOnDebuggerStmt_ = false; @@ -138,9 +138,10 @@ bool JSDebugger::HandleBreakpoint(JSHandle method, uint32_t bcOffset) return false; } + JSThread *thread = ecmaVm_->GetJSThread(); auto smartBreakpoint = FindSmartBreakpoint(method, bcOffset); if (smartBreakpoint.has_value()) { - JSPtLocation smartLocation {method->GetJSPandaFile(), method->GetMethodId(), bcOffset, + JSPtLocation smartLocation {method->GetJSPandaFile(thread), method->GetMethodId(), bcOffset, smartBreakpoint.value().GetSourceFile()}; std::unique_ptr ptMethod = FindMethod(smartLocation); RemoveSmartBreakpoint(ptMethod, bcOffset); @@ -152,7 +153,7 @@ bool JSDebugger::HandleBreakpoint(JSHandle method, uint32_t bcOffset) if (!breakpoint.has_value() || !IsBreakpointCondSatisfied(breakpoint)) { return false; } - JSPtLocation location {method->GetJSPandaFile(), method->GetMethodId(), bcOffset, + JSPtLocation location {method->GetJSPandaFile(thread), method->GetMethodId(), bcOffset, breakpoint.value().GetSourceFile()}; hooks_->Breakpoint(location); @@ -175,7 +176,8 @@ bool JSDebugger::HandleDebuggerStmt(JSHandle method, uint32_t bcOffset) if (breakpointAtDebugger.has_value()) { return false; } - JSPtLocation location {method->GetJSPandaFile(), method->GetMethodId(), bcOffset}; + JSThread *thread = ecmaVm_->GetJSThread(); + JSPtLocation location {method->GetJSPandaFile(thread), method->GetMethodId(), bcOffset}; hooks_->DebuggerStmt(location); return true; @@ -187,7 +189,7 @@ void JSDebugger::HandleExceptionThrowEvent(const JSThread *thread, JSHandleGetJSPandaFile(), method->GetMethodId(), bcOffset}; + JSPtLocation throwLocation {method->GetJSPandaFile(thread), method->GetMethodId(), bcOffset}; hooks_->Exception(throwLocation); } @@ -198,16 +200,18 @@ bool JSDebugger::HandleStep(JSHandle method, uint32_t bcOffset) return false; } - JSPtLocation location {method->GetJSPandaFile(), method->GetMethodId(), bcOffset}; + JSThread *thread = ecmaVm_->GetJSThread(); + JSPtLocation location {method->GetJSPandaFile(thread), method->GetMethodId(), bcOffset}; return hooks_->SingleStep(location); } std::optional JSDebugger::FindBreakpoint(JSHandle method, uint32_t bcOffset) const { + JSThread *thread = ecmaVm_->GetJSThread(); for (const auto &bp : breakpoints_) { if ((bp.GetBytecodeOffset() == bcOffset) && - (bp.GetPtMethod()->GetJSPandaFile() == method->GetJSPandaFile()) && + (bp.GetPtMethod()->GetJSPandaFile() == method->GetJSPandaFile(thread)) && (bp.GetPtMethod()->GetMethodId() == method->GetMethodId())) { return bp; } @@ -217,9 +221,10 @@ std::optional JSDebugger::FindBreakpoint(JSHandle method, std::optional JSDebugger::FindSmartBreakpoint(JSHandle method, uint32_t bcOffset) const { + JSThread *thread = ecmaVm_->GetJSThread(); for (const auto &bp : smartBreakpoints_) { if ((bp.GetBytecodeOffset() == bcOffset) && - (bp.GetPtMethod()->GetJSPandaFile() == method->GetJSPandaFile()) && + (bp.GetPtMethod()->GetJSPandaFile() == method->GetJSPandaFile(thread)) && (bp.GetPtMethod()->GetMethodId() == method->GetMethodId())) { return bp; } @@ -334,7 +339,7 @@ void JSDebugger::MethodEntry(JSHandle method, JSHandle en if (symbolicBreakpoints_.empty()) { return; } - auto symbolicBreakpoint = symbolicBreakpoints_.find(method->ParseFunctionName()); + auto symbolicBreakpoint = symbolicBreakpoints_.find(method->ParseFunctionName(ecmaVm_->GetAssociatedJSThread())); if (symbolicBreakpoint != symbolicBreakpoints_.end()) { hooks_->HitSymbolicBreakpoint(); } diff --git a/ecmascript/deoptimizer/deoptimizer.cpp b/ecmascript/deoptimizer/deoptimizer.cpp index 3eb0bf391f..878d8d4fae 100644 --- a/ecmascript/deoptimizer/deoptimizer.cpp +++ b/ecmascript/deoptimizer/deoptimizer.cpp @@ -345,7 +345,7 @@ Method* Deoptimizier::GetMethod(JSTaggedValue &target) { ECMAObject *callTarget = reinterpret_cast(target.GetTaggedObject()); ASSERT(callTarget != nullptr); - Method *method = callTarget->GetCallTarget(); + Method *method = callTarget->GetCallTarget(thread_); return method; } @@ -382,7 +382,7 @@ bool Deoptimizier::CollectVirtualRegisters(JSTaggedValue callTarget, Method *met // [maybe argc] [actual args] [reserved args] [call field virtual regs] // [maybe argc] - bool isFastCall = JSFunctionBase::IsFastCallFromCallTarget(callTarget); + bool isFastCall = JSFunctionBase::IsFastCallFromCallTarget(thread_, callTarget); if (!isFastCall && declaredNumArgs != actualNumArgs) { auto value = JSTaggedValue(actualNumArgs); frameWriter->PushValue(value.GetRawData()); @@ -458,7 +458,7 @@ void Deoptimizier::Dump(JSTaggedValue callTarget, kungfu::DeoptType type, size_t { if (thread_->IsPGOProfilerEnable()) { JSFunction *function = JSFunction::Cast(callTarget); - auto profileTypeInfo = function->GetProfileTypeInfo(); + auto profileTypeInfo = function->GetProfileTypeInfo(thread_); if (profileTypeInfo.IsUndefined()) { SlowRuntimeStub::NotifyInlineCache(thread_, function); } @@ -544,7 +544,7 @@ JSTaggedType Deoptimizier::ConstructAsmInterpretFrame(JSHandle ma JSTaggedValue env = GetDeoptValue(curDepth, static_cast(SpecVregIndex::ENV_INDEX)); if (env.IsUndefined()) { - statePtr->env = JSFunction::Cast(callTarget.GetTaggedObject())->GetLexicalEnv(); + statePtr->env = JSFunction::Cast(callTarget.GetTaggedObject())->GetLexicalEnv(thread_); } else { statePtr->env = env; } @@ -581,8 +581,8 @@ JSTaggedType Deoptimizier::ConstructAsmInterpretFrame(JSHandle ma // static void Deoptimizier::ResetJitHotness(JSThread *thread, JSFunction *jsFunc) { - if (jsFunc->GetMachineCode().IsMachineCodeObject()) { - JSTaggedValue profileTypeInfoVal = jsFunc->GetProfileTypeInfo(); + if (jsFunc->GetMachineCode(thread).IsMachineCodeObject()) { + JSTaggedValue profileTypeInfoVal = jsFunc->GetProfileTypeInfo(thread); if (!profileTypeInfoVal.IsUndefined()) { ProfileTypeInfo *profileTypeInfo = ProfileTypeInfo::Cast(profileTypeInfoVal.GetTaggedObject()); profileTypeInfo->SetJitHotnessCnt(0); @@ -591,9 +591,11 @@ void Deoptimizier::ResetJitHotness(JSThread *thread, JSFunction *jsFunc) uint16_t threshold = profileTypeInfo->GetJitHotnessThreshold(); threshold = threshold >= thresholdLimit ? ProfileTypeInfo::JIT_DISABLE_FLAG : threshold * thresholdStep; profileTypeInfo->SetJitHotnessThreshold(threshold); - ProfileTypeInfoCell::Cast(jsFunc->GetRawProfileTypeInfo())->SetMachineCode(thread, JSTaggedValue::Hole()); - Method *method = Method::Cast(jsFunc->GetMethod().GetTaggedObject()); - LOG_JIT(DEBUG) << "reset jit hotness for func: " << method->GetMethodName() << ", threshold:" << threshold; + ProfileTypeInfoCell::Cast(jsFunc->GetRawProfileTypeInfo(thread))->SetMachineCode(thread, + JSTaggedValue::Hole()); + Method *method = Method::Cast(jsFunc->GetMethod(thread).GetTaggedObject()); + LOG_JIT(DEBUG) << "reset jit hotness for func: " << method->GetMethodName(thread) + << ", threshold:" << threshold; } } } @@ -603,7 +605,7 @@ void Deoptimizier::ClearCompiledCodeStatusWhenDeopt(JSThread *thread, JSFunction Method *method, kungfu::DeoptType type) { method->SetDeoptType(type); - if (func->GetMachineCode().IsMachineCodeObject()) { + if (func->GetMachineCode(thread).IsMachineCodeObject()) { Jit::GetInstance()->GetJitDfx()->SetJitDeoptCount(); } if (func->IsCompiledCode()) { @@ -625,8 +627,8 @@ void Deoptimizier::UpdateAndDumpDeoptInfo(kungfu::DeoptType type) for (size_t i = 0; i <= inlineDepth_; i++) { JSTaggedValue callTarget = GetDeoptValue(i, static_cast(SpecVregIndex::FUNC_INDEX)); auto func = JSFunction::Cast(callTarget.GetTaggedObject()); - if (func->GetMachineCode().IsMachineCodeObject()) { - MachineCode *machineCode = MachineCode::Cast(func->GetMachineCode().GetTaggedObject()); + if (func->GetMachineCode(thread_).IsMachineCodeObject()) { + MachineCode *machineCode = MachineCode::Cast(func->GetMachineCode(thread_).GetTaggedObject()); if (type != kungfu::DeoptType::OSRLOOPEXIT && machineCode->GetOSROffset() != MachineCode::INVALID_OSR_OFFSET) { machineCode->SetOsrDeoptFlag(true); diff --git a/ecmascript/dependent_infos.cpp b/ecmascript/dependent_infos.cpp index 02d2ff5351..0d0be4b13b 100644 --- a/ecmascript/dependent_infos.cpp +++ b/ecmascript/dependent_infos.cpp @@ -44,7 +44,7 @@ void DependentInfos::TraceLazyDeoptReason(JSThread *thread, JSHandle } JSTaggedValue funcName = JSFunction::NameGetter(thread, JSHandle::Cast(func)); std::string funNameS = "Lazy Deoptimization occurred on"; - funNameS += " function: \"" + EcmaStringAccessor(funcName).ToStdString() + "\""; + funNameS += " function: \"" + EcmaStringAccessor(funcName).ToStdString(thread) + "\""; LOG_TRACE(INFO) << funNameS; // Get the lowbit of groups. uint32_t value = (static_cast(groups) & (-static_cast(groups))); @@ -71,18 +71,19 @@ void DependentInfos::DeoptimizeGroups(JSHandle dependentInfos, { bool hasDeoptMethod = false; for (uint32_t i = 0; i < dependentInfos->GetEnd(); i += SLOT_PER_ENTRY) { - DependentGroups depGroups = static_cast(dependentInfos->Get(i + GROUP_SLOT_OFFSET).GetInt()); + DependentGroups depGroups = + static_cast(dependentInfos->GetPrimitive(i + GROUP_SLOT_OFFSET).GetInt()); if (!CheckGroupsEffect(depGroups, groups)) { continue; } - JSTaggedValue rawValue = dependentInfos->Get(i + FUNCTION_SLOT_OFFSET).GetWeakRawValue(); + JSTaggedValue rawValue = dependentInfos->Get(thread, i + FUNCTION_SLOT_OFFSET).GetWeakRawValue(); if (!rawValue.IsHeapObject()) { continue; } JSHandle func(thread, rawValue); if (func->IsCompiledCode()) { hasDeoptMethod = true; - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); // When lazy deopt happened, the deopt method cannot call as jit any more. Deoptimizier::ClearCompiledCodeStatusWhenDeopt(thread, func.GetObject(), diff --git a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp index 9f28d1c279..d690ebac80 100644 --- a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp +++ b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp @@ -269,9 +269,9 @@ void CpuProfiler::GetStack(FrameIterator &it) methodKey.state = JsStackGetter::GetRunningState(it, vm_, isNative, false, enableVMTag_); } if (isNative) { - JsStackGetter::GetCallLineNumber(it, methodKey.lineNumber); + JsStackGetter::GetCallLineNumber(it, vm_, methodKey.lineNumber); } - void *methodIdentifier = JsStackGetter::GetMethodIdentifier(method, it); + void *methodIdentifier = JsStackGetter::GetMethodIdentifier(method, it, vm_); if (methodIdentifier == nullptr) { continue; } @@ -342,9 +342,9 @@ bool CpuProfiler::GetStackCallNapi(JSThread *thread, bool beforeCallNapi) methodKey.state = JsStackGetter::GetRunningState(it, vm_, isNative, false, enableVMTag_); } if (isNative) { - JsStackGetter::GetCallLineNumber(it, methodKey.lineNumber); + JsStackGetter::GetCallLineNumber(it, vm_, methodKey.lineNumber); } - void *methodIdentifier = JsStackGetter::GetMethodIdentifier(method, it); + void *methodIdentifier = JsStackGetter::GetMethodIdentifier(method, it, vm_); if (methodIdentifier == nullptr) { continue; } diff --git a/ecmascript/dfx/hprof/heap_sampling.cpp b/ecmascript/dfx/hprof/heap_sampling.cpp index 7ec0cc6002..5034356320 100644 --- a/ecmascript/dfx/hprof/heap_sampling.cpp +++ b/ecmascript/dfx/hprof/heap_sampling.cpp @@ -102,7 +102,7 @@ void HeapSampling::GetStack() } else { methodKey.state = JsStackGetter::GetRunningState(it, vm_, isNative, false); } - void *methodIdentifier = JsStackGetter::GetMethodIdentifier(method, it); + void *methodIdentifier = JsStackGetter::GetMethodIdentifier(method, it, vm_); if (methodIdentifier == nullptr) { continue; } diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index dcb81724bf..4ccec0f8ec 100755 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -920,12 +920,12 @@ int HeapSnapshot::AddTraceNode(int sequenceId, int size) if (method == nullptr || method->IsNativeWithCallField()) { continue; } - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); if (methodLiteral == nullptr) { continue; } if (stackInfo_.count(methodLiteral) == 0) { - if (!AddMethodInfo(methodLiteral, method->GetJSPandaFile(), sequenceId)) { + if (!AddMethodInfo(methodLiteral, method->GetJSPandaFile(thread), sequenceId)) { continue; } } @@ -996,9 +996,10 @@ Node *HeapSnapshot::GenerateStringNode(JSTaggedValue entry, size_t size, bool is static const CString EMPTY_STRING; JSTaggedType addr = entry.GetRawData(); Node *existNode = entryMap_.FindEntry(addr); // Fast Index + JSThread *thread = vm_->GetJSThread(); if (existNode != nullptr) { if (isInFinish || isBinMod) { - existNode->SetName(GetString(EntryVisitor::ConvertKey(entry))); + existNode->SetName(GetString(EntryVisitor::ConvertKey(thread, entry))); } existNode->SetLive(true); return existNode; @@ -1008,7 +1009,7 @@ Node *HeapSnapshot::GenerateStringNode(JSTaggedValue entry, size_t size, bool is size_t selfsize = (size != 0) ? size : entry.GetTaggedObject()->GetSize(); const CString *nodeName = &EMPTY_STRING; if (isInFinish || isBinMod) { - nodeName = GetString(EntryVisitor::ConvertKey(entry)); + nodeName = GetString(EntryVisitor::ConvertKey(thread, entry)); } auto [idExist, sequenceId] = entryIdMap_->FindId(addr); Node *node = Node::NewNode(chunk_, sequenceId, nodeCount_, nodeName, NodeType::STRING, selfsize, @@ -1029,7 +1030,7 @@ Node *HeapSnapshot::GeneratePrivateStringNode(size_t size) JSTaggedValue stringValue = vm_->GetJSThread()->GlobalConstants()->GetStringString(); size_t selfsize = (size != 0) ? size : stringValue.GetTaggedObject()->GetSize(); CString strContent; - strContent.append(EntryVisitor::ConvertKey(stringValue)); + strContent.append(EntryVisitor::ConvertKey(vm_->GetJSThread(), stringValue)); JSTaggedType addr = stringValue.GetRawData(); auto [idExist, sequenceId] = entryIdMap_->FindId(addr); Node *node = Node::NewNode(chunk_, sequenceId, nodeCount_, GetString(strContent), NodeType::STRING, selfsize, @@ -1129,7 +1130,7 @@ void HeapSnapshot::FillEdges(bool isSimplify) continue; } std::vector referenceResources; - value.DumpForSnapshot(referenceResources, isVmMode_); + value.DumpForSnapshot(vm_->GetJSThread(), referenceResources, isVmMode_); for (auto const &it : referenceResources) { JSTaggedValue toValue = it.value_; if (toValue.IsNumber() && !captureNumericValue_) { @@ -1276,24 +1277,25 @@ CString HeapSnapshot::ParseFunctionName(TaggedObject *obj, bool isRawHeap) { CString result; JSFunctionBase *func = JSFunctionBase::Cast(obj); - Method *method = Method::Cast(func->GetMethod().GetTaggedObject()); - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + JSThread *thread = vm_->GetJSThread(); + Method *method = Method::Cast(func->GetMethod(thread).GetTaggedObject()); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); if (methodLiteral == nullptr) { if (!isRawHeap) { return "JSFunction"; } - JSHandle funcBase = JSHandle(vm_->GetJSThread(), obj); - auto funcName = JSFunction::GetFunctionName(vm_->GetJSThread(), funcBase); + JSHandle funcBase = JSHandle(thread, obj); + auto funcName = JSFunction::GetFunctionName(thread, funcBase); if (funcName->IsString()) { - auto name = EcmaStringAccessor(JSHandle::Cast(funcName)).ToCString(); + auto name = EcmaStringAccessor(JSHandle::Cast(funcName)).ToCString(thread); return name.empty() ? "JSFunction" : name; } return "JSFunction"; } - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); panda_file::File::EntityId methodId = methodLiteral->GetMethodId(); const CString &nameStr = MethodLiteral::ParseFunctionNameToCString(jsPandaFile, methodId); - const CString &moduleStr = method->GetRecordNameStr(); + const CString &moduleStr = method->GetRecordNameStr(thread); CString defaultName = "anonymous"; DebugInfoExtractor *debugExtractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(jsPandaFile); @@ -1505,17 +1507,17 @@ Edge *HeapSnapshot::InsertEdgeAt(size_t pos, Edge *edge) return edge; } -CString EntryVisitor::ConvertKey(JSTaggedValue key) +CString EntryVisitor::ConvertKey(JSThread *thread, JSTaggedValue key) { ASSERT(key.GetTaggedObject() != nullptr); EcmaString *keyString = EcmaString::Cast(key.GetTaggedObject()); if (key.IsSymbol()) { JSSymbol *symbol = JSSymbol::Cast(key.GetTaggedObject()); - keyString = EcmaString::Cast(symbol->GetDescription().GetTaggedObject()); + keyString = EcmaString::Cast(symbol->GetDescription(thread).GetTaggedObject()); } // convert, expensive but safe - return EcmaStringAccessor(keyString).ToCString(StringConvertedUsage::PRINT); + return EcmaStringAccessor(keyString).ToCString(thread, StringConvertedUsage::PRINT); } Node *HeapEntryMap::FindOrInsertNode(Node *node) diff --git a/ecmascript/dfx/hprof/heap_snapshot.h b/ecmascript/dfx/hprof/heap_snapshot.h index 61d090c050..294fe1a3de 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.h +++ b/ecmascript/dfx/hprof/heap_snapshot.h @@ -402,7 +402,7 @@ public: NO_COPY_SEMANTIC(EntryVisitor); EntryVisitor() = default; ~EntryVisitor() = default; - static CString ConvertKey(JSTaggedValue key); + static CString ConvertKey(JSThread *thread, JSTaggedValue key); }; class HeapSnapshot { diff --git a/ecmascript/dfx/hprof/tests/heap_dump_test.cpp b/ecmascript/dfx/hprof/tests/heap_dump_test.cpp index cb47208ede..2217427616 100644 --- a/ecmascript/dfx/hprof/tests/heap_dump_test.cpp +++ b/ecmascript/dfx/hprof/tests/heap_dump_test.cpp @@ -432,7 +432,7 @@ public: JSHandle proto = instance->GetGlobalEnv()->GetFunctionPrototype(); JSHandle jsAPIArrayListObject = NewObject(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto); JSHandle jsAPIArrayList = JSHandle::Cast(jsAPIArrayListObject); - jsAPIArrayList->SetLength(instance->GetJSThread(), JSTaggedValue(0)); + jsAPIArrayList->SetLength(0); return jsAPIArrayList; } diff --git a/ecmascript/dfx/stackinfo/async_stack_trace.cpp b/ecmascript/dfx/stackinfo/async_stack_trace.cpp index a791c8eb2f..971ca1055d 100644 --- a/ecmascript/dfx/stackinfo/async_stack_trace.cpp +++ b/ecmascript/dfx/stackinfo/async_stack_trace.cpp @@ -83,8 +83,8 @@ bool AsyncStackTrace::InsertAsyncTaskStacks(const JSHandle &promise, bool AsyncStackTrace::InsertCurrentAsyncTaskStack(const JSTaggedValue &PromiseReaction) { if (PromiseReaction.IsPromiseReaction()) { - JSTaggedValue promiseCapability = PromiseReaction::Cast(PromiseReaction)->GetPromiseCapability(); - JSTaggedValue promise = PromiseCapability::Cast(promiseCapability)->GetPromise(); + JSTaggedValue promiseCapability = PromiseReaction::Cast(PromiseReaction)->GetPromiseCapability(jsThread_); + JSTaggedValue promise = PromiseCapability::Cast(promiseCapability)->GetPromise(jsThread_); uint32_t asyncTaskId = JSPromise::Cast(promise)->GetAsyncTaskId(); auto stackIt = asyncTaskStacks_.find(asyncTaskId); if (stackIt != asyncTaskStacks_.end()) { diff --git a/ecmascript/dfx/stackinfo/js_stackgetter.cpp b/ecmascript/dfx/stackinfo/js_stackgetter.cpp index 08f0c54382..f33742bf56 100644 --- a/ecmascript/dfx/stackinfo/js_stackgetter.cpp +++ b/ecmascript/dfx/stackinfo/js_stackgetter.cpp @@ -62,10 +62,10 @@ bool JsStackGetter::ParseMethodInfo(struct MethodKey &methodKey, if (method->IsNativeWithCallField()) { FrameIterator itNext(it.GetSp(), it.GetThread()); itNext.Advance(); - GetNativeMethodCallPos(itNext, codeEntry); + GetNativeMethodCallPos(itNext, vm, codeEntry); GetNativeStack(vm, it, codeEntry.functionName, sizeof(codeEntry.functionName), isCpuProfiler); } else { - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(vm->GetJSThread()); if (jsPandaFile == nullptr) { return false; } @@ -136,9 +136,9 @@ void JsStackGetter::GetNativeStack(const EcmaVM *vm, const FrameIterator &it, ch { std::stringstream stream; JSFunction* function = JSFunction::Cast(it.GetFunction().GetTaggedObject()); - JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(); // it not allow thread check here, if enable thread check, it maybe deadlock in IsInThreadPool JSThread *thread = vm->GetJSThreadNoCheck(); + JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle nameKey = globalConst->GetHandledNameString(); JSHandle func(thread, function); @@ -146,7 +146,7 @@ void JsStackGetter::GetNativeStack(const EcmaVM *vm, const FrameIterator &it, ch std::string methodNameStr; if (funcNameValue->IsString()) { JSHandle methodName(funcNameValue); - methodNameStr = EcmaStringAccessor(methodName).ToStdString(); + methodNameStr = EcmaStringAccessor(methodName).ToStdString(thread); } // napi method if (isCpuProfiler && function->IsCallNapi() && extraInfoValue.CheckIsJSNativePointer()) { @@ -200,8 +200,8 @@ RunningState JsStackGetter::GetRunningState(const FrameIterator &it, const EcmaV return RunningState::NAPI; } if (isNative) { - return function->GetNativeFunctionExtraInfo().CheckIsJSNativePointer() ? RunningState::ARKUI_ENGINE : - RunningState::BUILTIN; + return function->GetNativeFunctionExtraInfo(thread).CheckIsJSNativePointer() ? RunningState::ARKUI_ENGINE : + RunningState::BUILTIN; } if (it.IsFastJitFunctionFrame()) { return RunningState::JIT; @@ -211,8 +211,8 @@ RunningState JsStackGetter::GetRunningState(const FrameIterator &it, const EcmaV } if (thread->IsAsmInterpreter()) { // For Methods that is compiled in AOT but deoptimized at runtime, we mark it as AINT-D - Method *method = Method::Cast(function->GetMethod()); - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + Method *method = Method::Cast(function->GetMethod(thread)); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); if (methodLiteral != nullptr && MethodLiteral::IsAotWithCallField(methodLiteral->GetCallField())) { return RunningState::AINT_D; } @@ -234,28 +234,29 @@ RunningState JsStackGetter::GetRunningState(const FrameIterator &it, const EcmaV return RunningState::NAPI; } if (isNative) { - return function->GetNativeFunctionExtraInfo().CheckIsJSNativePointer() ? RunningState::ARKUI_ENGINE : - RunningState::BUILTIN; + return function->GetNativeFunctionExtraInfo(thread).CheckIsJSNativePointer() ? RunningState::ARKUI_ENGINE : + RunningState::BUILTIN; } return RunningState::OTHER; } -void JsStackGetter::GetNativeMethodCallPos(FrameIterator &it, FrameInfoTemp &codeEntry) +void JsStackGetter::GetNativeMethodCallPos(FrameIterator &it, const EcmaVM *vm, FrameInfoTemp &codeEntry) { + JSThread *thread = vm->GetJSThread(); auto nextMethod = it.CheckAndGetMethod(); if (nextMethod == nullptr) { return ; } JSFunction* function = JSFunction::Cast(it.GetFunction().GetTaggedObject()); - JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(); - if (!extraInfoValue.CheckIsJSNativePointer() && nextMethod->GetJSPandaFile() != nullptr) { + JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(thread); + if (!extraInfoValue.CheckIsJSNativePointer() && nextMethod->GetJSPandaFile(thread) != nullptr) { DebugInfoExtractor *debugExtractor = - JSPandaFileManager::GetInstance()->GetJSPtExtractor(nextMethod->GetJSPandaFile()); + JSPandaFileManager::GetInstance()->GetJSPtExtractor(nextMethod->GetJSPandaFile(thread)); if (debugExtractor == nullptr) { return; } - MethodLiteral *methodLiteral = nextMethod->GetMethodLiteral(); + MethodLiteral *methodLiteral = nextMethod->GetMethodLiteral(thread); if (methodLiteral == nullptr) { return; } @@ -292,10 +293,11 @@ void JsStackGetter::GetNativeMethodCallPos(FrameIterator &it, FrameInfoTemp &cod } } -void *JsStackGetter::GetMethodIdentifier(Method *method, const FrameIterator &it) +void *JsStackGetter::GetMethodIdentifier(Method *method, const FrameIterator &it, const EcmaVM *vm) { + JSThread *thread = vm->GetJSThread(); JSFunction* function = JSFunction::Cast(it.GetFunction().GetTaggedObject()); - JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(); + JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(thread); if (method->IsNativeWithCallField()) { if (extraInfoValue.CheckIsJSNativePointer()) { JSNativePointer *extraInfo = JSNativePointer::Cast(extraInfoValue.GetTaggedObject()); @@ -304,11 +306,12 @@ void *JsStackGetter::GetMethodIdentifier(Method *method, const FrameIterator &it return function->GetNativePointer(); } - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); return reinterpret_cast(methodLiteral); } -void JsStackGetter::GetCallLineNumber(const FrameIterator &it, int &LineNumber) +void JsStackGetter::GetCallLineNumber(const FrameIterator &it, const EcmaVM *vm, int &LineNumber) { + JSThread *thread = vm->GetJSThread(); FrameIterator itNext(it.GetSp(), it.GetThread()); itNext.Advance(); auto nextMethod = itNext.CheckAndGetMethod(); @@ -316,14 +319,14 @@ void JsStackGetter::GetCallLineNumber(const FrameIterator &it, int &LineNumber) return ; } JSFunction* function = JSFunction::Cast(itNext.GetFunction().GetTaggedObject()); - JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(); - if (!extraInfoValue.CheckIsJSNativePointer() && nextMethod->GetJSPandaFile() != nullptr) { + JSTaggedValue extraInfoValue = function->GetNativeFunctionExtraInfo(thread); + if (!extraInfoValue.CheckIsJSNativePointer() && nextMethod->GetJSPandaFile(thread) != nullptr) { DebugInfoExtractor *debugExtractor = - JSPandaFileManager::GetInstance()->GetJSPtExtractor(nextMethod->GetJSPandaFile()); + JSPandaFileManager::GetInstance()->GetJSPtExtractor(nextMethod->GetJSPandaFile(thread)); if (debugExtractor == nullptr) { return; } - MethodLiteral *methodLiteral = nextMethod->GetMethodLiteral(); + MethodLiteral *methodLiteral = nextMethod->GetMethodLiteral(thread); if (methodLiteral == nullptr) { return; } diff --git a/ecmascript/dfx/stackinfo/js_stackgetter.h b/ecmascript/dfx/stackinfo/js_stackgetter.h index 756e89a6a6..8957123eba 100644 --- a/ecmascript/dfx/stackinfo/js_stackgetter.h +++ b/ecmascript/dfx/stackinfo/js_stackgetter.h @@ -87,9 +87,9 @@ public: size_t size, bool isCpuProfiler); static RunningState GetRunningState(const FrameIterator &it, const EcmaVM *vm, bool isNative, bool topFrame, bool enableVMTag = false); - static void GetNativeMethodCallPos(FrameIterator &it, FrameInfoTemp &codeEntry); - static void *GetMethodIdentifier(Method *method, const FrameIterator &it); - static void GetCallLineNumber(const FrameIterator &it, int &LineNumber); + static void GetNativeMethodCallPos(FrameIterator &it, const EcmaVM *vm, FrameInfoTemp &codeEntry); + static void *GetMethodIdentifier(Method *method, const FrameIterator &it, const EcmaVM *vm); + static void GetCallLineNumber(const FrameIterator &it, const EcmaVM *vm, int &LineNumber); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_DFX_STACKINFO_JS_STACKGETTER_H diff --git a/ecmascript/dfx/stackinfo/js_stackinfo.cpp b/ecmascript/dfx/stackinfo/js_stackinfo.cpp index 8dd690c9c3..03cf574377 100644 --- a/ecmascript/dfx/stackinfo/js_stackinfo.cpp +++ b/ecmascript/dfx/stackinfo/js_stackinfo.cpp @@ -45,13 +45,13 @@ bool IsFastJitFunctionFrame(uintptr_t frameType) static_cast(frameType) == FrameType::FASTJIT_FAST_CALL_FUNCTION_FRAME; } -std::string JsStackInfo::BuildMethodTrace(Method *method, uint32_t pcOffset, LastBuilderCache &lastCache, - bool enableStackSourceFile) +std::string JsStackInfo::BuildMethodTrace(const JSThread *thread, Method *method, uint32_t pcOffset, + LastBuilderCache &lastCache, bool enableStackSourceFile) { std::string data; data.reserve(InitialLength); data.append(" at "); - std::string name = method->ParseFunctionName(); + std::string name = method->ParseFunctionName(thread); if (name.empty()) { data.append("anonymous ("); } else { @@ -59,7 +59,7 @@ std::string JsStackInfo::BuildMethodTrace(Method *method, uint32_t pcOffset, Las } // source file DebugInfoExtractor *debugExtractor = nullptr; - const JSPandaFile *pandaFile = method->GetJSPandaFile(); + const JSPandaFile *pandaFile = method->GetJSPandaFile(thread); if (pandaFile == lastCache.pf) { debugExtractor = lastCache.extractor; } else { @@ -148,9 +148,9 @@ void AssembleJitCodeMap(JSThread *thread, const JSHandle &jsErrorObj, uintptr_t offset) { ASSERT(!jsErrorObj.GetTaggedValue().IsUndefined()); - JSTaggedValue machineCodeTagVal = func->GetMachineCode(); + JSTaggedValue machineCodeTagVal = func->GetMachineCode(thread); MachineCode *machineCode = MachineCode::Cast(machineCodeTagVal.GetTaggedObject()); - std::string methodName = method->ParseFunctionName(); + std::string methodName = method->ParseFunctionName(thread); if (methodName.empty()) { methodName = "anonymous"; } @@ -187,7 +187,7 @@ std::string JsStackInfo::BuildJsStackTrace(JSThread *thread, bool needNative, co if (needBaselineSpecialHandling) { // the pcOffste in baseline frame slot is always uint64::max(), so pcOffset should be computed JSHandle function(thread, it.GetFunction()); - pcOffset = RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(function, baselineNativePc); + pcOffset = RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(thread, function, baselineNativePc); baselineNativePc = 0; } data += BuildJsStackTraceInfo(thread, method, it, jsErrorObj, lastCache, @@ -227,9 +227,9 @@ std::string JsStackInfo::BuildJsStackTraceInfo(JSThread *thread, Method *method, it.GetStackTraceInfos(stackTraceInfos, needBaselineSpecialHandling, pcOffset); std::string data; for (auto &info : stackTraceInfos) { - Method *methodInline = ECMAObject::Cast(reinterpret_cast(info.first))->GetCallTarget(); + Method *methodInline = ECMAObject::Cast(reinterpret_cast(info.first))->GetCallTarget(thread); uint32_t pcOffsetInline = info.second; - data += BuildMethodTrace(methodInline, pcOffsetInline, lastCache, + data += BuildMethodTrace(thread, methodInline, pcOffsetInline, lastCache, thread->GetEnableStackSourceFile()); } return data; @@ -273,7 +273,7 @@ std::vector JsStackInfo::BuildJsStackInfo(JSThread *thread, } struct JsFrameInfo frameInfo; if (!method->IsNativeWithCallField()) { - std::string name = method->ParseFunctionName(); + std::string name = method->ParseFunctionName(thread); if (name.empty()) { frameInfo.functionName = "anonymous"; } else { @@ -281,7 +281,7 @@ std::vector JsStackInfo::BuildJsStackInfo(JSThread *thread, } // source file DebugInfoExtractor *debugExtractor = - JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile()); + JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile(thread)); const std::string &sourceFile = debugExtractor->GetSourceFile(method->GetMethodId()); if (sourceFile.empty()) { frameInfo.fileName = "?"; diff --git a/ecmascript/dfx/stackinfo/js_stackinfo.h b/ecmascript/dfx/stackinfo/js_stackinfo.h index bf26a0db65..3abdd05a9e 100644 --- a/ecmascript/dfx/stackinfo/js_stackinfo.h +++ b/ecmascript/dfx/stackinfo/js_stackinfo.h @@ -194,8 +194,8 @@ public: static std::string BuildJsStackTrace(JSThread *thread, bool needNative, const JSHandle &jsErrorObj, bool needNativeStack, uint32_t depth = UINT32_MAX); static std::vector BuildJsStackInfo(JSThread *thread, bool currentStack = false); - static std::string BuildMethodTrace(Method *method, uint32_t pcOffset, LastBuilderCache &lastCache, - bool enableStackSourceFile = true); + static std::string BuildMethodTrace(const JSThread *thread, Method *method, uint32_t pcOffset, + LastBuilderCache &lastCache, bool enableStackSourceFile = true); static AOTFileManager *loader; static JSRuntimeOptions *options; static void BuildCrashInfo(bool isJsCrash, uintptr_t pc = 0, JSThread *thread = nullptr); diff --git a/ecmascript/dfx/vmstat/function_call_timer.cpp b/ecmascript/dfx/vmstat/function_call_timer.cpp index 1953410590..a7d467c3c7 100644 --- a/ecmascript/dfx/vmstat/function_call_timer.cpp +++ b/ecmascript/dfx/vmstat/function_call_timer.cpp @@ -35,13 +35,13 @@ void FunctionCallTimer::StartCount(size_t id, bool isAot) calleeTimer->Start(calleeStat, callerTimer); } -void FunctionCallTimer::StopCount(Method *method) +void FunctionCallTimer::StopCount(const JSThread *thread, Method *method) { size_t id = method->GetMethodId().GetOffset(); auto callee = &callTimer_[id]; if (callee != currentTimer_) { LOG_ECMA(INFO) << "EndCallTimer and StartCallTimer have different functions. Current function: " - << GetFullName(method) << "has been skipped"; + << GetFullName(thread, method) << "has been skipped"; return; } @@ -49,27 +49,27 @@ void FunctionCallTimer::StopCount(Method *method) currentTimer_ = callerTimer; } -CString FunctionCallTimer::GetFullName(Method *method) +CString FunctionCallTimer::GetFullName(const JSThread *thread, Method *method) { - CString funcName(method->GetMethodName()); - CString recordName = method->GetRecordNameStr(); + CString funcName(method->GetMethodName(thread)); + CString recordName = method->GetRecordNameStr(thread); CString fullName = funcName + "@" + recordName; return fullName; } -void FunctionCallTimer::InitialStatAndTimer(Method *method, size_t methodId, bool isAot) +void FunctionCallTimer::InitialStatAndTimer(const JSThread *thread, Method *method, size_t methodId, bool isAot) { if (isAot) { auto iter = aotCallStat_.find(methodId); if (iter == aotCallStat_.end()) { - CString funcName = GetFullName(method); + CString funcName = GetFullName(thread, method); FunctionCallStat stat(funcName, isAot); aotCallStat_[methodId] = stat; } } else { auto iter = intCallStat_.find(methodId); if (iter == intCallStat_.end()) { - CString funcName = GetFullName(method); + CString funcName = GetFullName(thread, method); FunctionCallStat stat(funcName, isAot); intCallStat_[methodId] = stat; } diff --git a/ecmascript/dfx/vmstat/function_call_timer.h b/ecmascript/dfx/vmstat/function_call_timer.h index ec983974a4..bc97606e0b 100644 --- a/ecmascript/dfx/vmstat/function_call_timer.h +++ b/ecmascript/dfx/vmstat/function_call_timer.h @@ -69,10 +69,10 @@ public: FunctionCallTimer() = default; ~FunctionCallTimer() = default; void StartCount(size_t id, bool isAot); - void StopCount(Method *method); + void StopCount(const JSThread *thread, Method *method); void PrintAllStats(); - CString GetFullName(Method *method); - void InitialStatAndTimer(Method *method, size_t methodId, bool isAot); + CString GetFullName(const JSThread *thread, Method *method); + void InitialStatAndTimer(const JSThread *thread, Method *method, size_t methodId, bool isAot); void ResetStat(); private: diff --git a/ecmascript/dfx/vmstat/opt_code_profiler.cpp b/ecmascript/dfx/vmstat/opt_code_profiler.cpp index 70477fec2e..18e3907191 100644 --- a/ecmascript/dfx/vmstat/opt_code_profiler.cpp +++ b/ecmascript/dfx/vmstat/opt_code_profiler.cpp @@ -171,7 +171,8 @@ void OptCodeProfiler::PrintMethodRecord(Key key, std::string methodName) } } -void OptCodeProfiler::Update(JSHandle &func, int bcIndex, EcmaOpcode opcode, Mode mode) +void OptCodeProfiler::Update(JSThread *thread, JSHandle &func, int bcIndex, + EcmaOpcode opcode, Mode mode) { auto it = profMap_.find(opcode); if (it != profMap_.end()) { @@ -184,15 +185,16 @@ void OptCodeProfiler::Update(JSHandle &func, int bcIndex, EcmaOpc // methodId & methodName auto funcPoint = JSFunction::Cast(func->GetTaggedObject()); - auto method = funcPoint->GetMethod(); + auto method = funcPoint->GetMethod(thread); if (!method.IsMethod()) { return; } auto methodPoint = Method::Cast(method); auto methodId = methodPoint->GetMethodId().GetOffset(); - auto methodName = ConvertToStdString(methodPoint->GetRecordNameStr()) + "." + methodPoint->GetMethodName(); + auto methodName = + ConvertToStdString(methodPoint->GetRecordNameStr(thread)) + "." + methodPoint->GetMethodName(thread); - const auto *pf = methodPoint->GetJSPandaFile(); + const auto *pf = methodPoint->GetJSPandaFile(thread); ASSERT(pf != nullptr); auto pfName = pf->GetJSPandaFileDesc(); auto itr = std::find(abcNames_.begin(), abcNames_.end(), pfName); diff --git a/ecmascript/dfx/vmstat/opt_code_profiler.h b/ecmascript/dfx/vmstat/opt_code_profiler.h index 3a68792d3f..fbdf2fc19d 100644 --- a/ecmascript/dfx/vmstat/opt_code_profiler.h +++ b/ecmascript/dfx/vmstat/opt_code_profiler.h @@ -185,7 +185,7 @@ public: ~OptCodeProfiler(); - void Update(JSHandle &func, int bcIndex, EcmaOpcode opcode, Mode mode); + void Update(JSThread *thread, JSHandle &func, int bcIndex, EcmaOpcode opcode, Mode mode); void PrintAndReset(); diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 0be91de1d5..f6a5443f56 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -444,78 +444,78 @@ CString JSHClass::DumpJSType(JSType type) } } -static void DumpArrayClass(const TaggedArray *arr, std::ostream &os) +static void DumpArrayClass(const JSThread *thread, const TaggedArray *arr, std::ostream &os) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); os << " \n"; for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); if (!val.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << i << ": "; - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); os << "\n"; } } } -static void DumpMutantTaggedArray(const MutantTaggedArray *arr, std::ostream &os) +static void DumpMutantTaggedArray(const JSThread *thread, const MutantTaggedArray *arr, std::ostream &os) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); os << " \n"; for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << i << ": "; os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[JSTaggedType] : " << val.GetRawData(); os << "\n"; } } -static void DumpCOWMutantTaggedArray(const COWMutantTaggedArray *arr, std::ostream &os) +static void DumpCOWMutantTaggedArray(const JSThread *thread, const COWMutantTaggedArray *arr, std::ostream &os) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); os << " \n"; for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << i << ": "; os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[JSTaggedType] : " << val.GetRawData(); os << "\n"; } } -static void DumpConstantPoolClass(const ConstantPool *pool, std::ostream &os) +static void DumpConstantPoolClass(const JSThread *thread, const ConstantPool *pool, std::ostream &os) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = pool->GetCacheLength(); os << " \n"; for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(pool->GetObjectFromCache(i)); + JSTaggedValue val(pool->GetObjectFromCache(thread, i)); if (!val.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << i << ": "; - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); os << "\n"; } } } -static void DumpStringClass(const EcmaString *str, std::ostream &os) +static void DumpStringClass(const JSThread *thread, const EcmaString *str, std::ostream &os) { DISALLOW_GARBAGE_COLLECTION; - CString string = ConvertToString(str); + CString string = ConvertToString(thread, str); os << string; } -static void DumpPropertyKey(JSTaggedValue key, std::ostream &os) +static void DumpPropertyKey(const JSThread *thread, JSTaggedValue key, std::ostream &os) { if (key.IsString()) { - DumpStringClass(EcmaString::Cast(key.GetTaggedObject()), os); + DumpStringClass(thread, EcmaString::Cast(key.GetTaggedObject()), os); } else if (key.IsSymbol()) { JSSymbol *sym = JSSymbol::Cast(key.GetTaggedObject()); - if (sym->GetDescription().IsString()) { + if (sym->GetDescription(thread).IsString()) { os << "Symbol(\""; - DumpStringClass(EcmaString::Cast(sym->GetDescription().GetTaggedObject()), os); + DumpStringClass(thread, EcmaString::Cast(sym->GetDescription(thread).GetTaggedObject()), os); os << "\")"; } else { os << "Symbol(" << sym << ")"; @@ -561,28 +561,28 @@ static void DumpAttr(const PropertyAttributes &attr, bool fastMode, std::ostream } } -static void DumpHClass(const JSHClass *jshclass, std::ostream &os, bool withDetail) +static void DumpHClass(const JSThread *thread, const JSHClass *jshclass, std::ostream &os, bool withDetail) { DISALLOW_GARBAGE_COLLECTION; os << "JSHClass :" << std::setw(DUMP_TYPE_OFFSET); os << "Type :" << JSHClass::DumpJSType(jshclass->GetObjectType()) << "\n"; os << " - Prototype :" << std::setw(DUMP_TYPE_OFFSET); - jshclass->GetPrototype().DumpTaggedValue(os); + jshclass->GetPrototype(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - PropertyDescriptors :" << std::setw(DUMP_TYPE_OFFSET); - JSTaggedValue attrs = jshclass->GetLayout(); - attrs.DumpTaggedValue(os); + JSTaggedValue attrs = jshclass->GetLayout(thread); + attrs.DumpTaggedValue(thread, os); os << "\n"; if (withDetail && !attrs.IsNull()) { - LayoutInfo *layout = LayoutInfo::Cast(jshclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::Cast(jshclass->GetLayout(thread).GetTaggedObject()); int element = static_cast(jshclass->NumberOfProps()); for (int i = 0; i < element; i++) { - JSTaggedValue key = layout->GetKey(i); - PropertyAttributes attr = layout->GetAttr(i); + JSTaggedValue key = layout->GetKey(thread, i); + PropertyAttributes attr = layout->GetAttr(thread, i); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); os << "[" << i << "]: "; - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << " : "; DumpAttr(attr, true, os); os << "\n"; @@ -590,27 +590,27 @@ static void DumpHClass(const JSHClass *jshclass, std::ostream &os, bool withDeta } os << " - Transitions :" << std::setw(DUMP_TYPE_OFFSET); - JSTaggedValue transtions = jshclass->GetTransitions(); - transtions.DumpTaggedValue(os); + JSTaggedValue transtions = jshclass->GetTransitions(thread); + transtions.DumpTaggedValue(thread, os); os << "\n"; if (withDetail && !transtions.IsWeakForHeapObject() && transtions.IsDictionary()) { - transtions.Dump(os); + transtions.Dump(thread, os); } os << " - ProtoChangeMarker :" << std::setw(DUMP_TYPE_OFFSET); - JSTaggedValue marker = jshclass->GetProtoChangeMarker(); - marker.DumpTaggedValue(os); + JSTaggedValue marker = jshclass->GetProtoChangeMarker(thread); + marker.DumpTaggedValue(thread, os); if (marker.IsHeapObject()) { - ProtoChangeMarker::Cast(marker.GetTaggedObject())->Dump(os); + ProtoChangeMarker::Cast(marker.GetTaggedObject())->Dump(thread, os); } else { os << "\n"; } os << " - ProtoChangeDetails :" << std::setw(DUMP_TYPE_OFFSET); - JSTaggedValue details = jshclass->GetProtoChangeDetails(); - details.DumpTaggedValue(os); + JSTaggedValue details = jshclass->GetProtoChangeDetails(thread); + details.DumpTaggedValue(thread, os); if (details.IsHeapObject()) { - ProtoChangeDetails::Cast(details.GetTaggedObject())->Dump(os); + ProtoChangeDetails::Cast(details.GetTaggedObject())->Dump(thread, os); } else { os << "\n"; } @@ -630,13 +630,13 @@ static void DumpHClass(const JSHClass *jshclass, std::ostream &os, bool withDeta os << "\n"; } -static void DumpClass(TaggedObject *obj, std::ostream &os) +static void DumpClass(const JSThread *thread, TaggedObject *obj, std::ostream &os) { ASSERT(obj->GetClass()->GetObjectType() == JSType::HCLASS); - DumpHClass(JSHClass::Cast(obj), os, true); + DumpHClass(thread, JSHClass::Cast(obj), os, true); } -static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) +static void DumpObject(const JSThread *thread, TaggedObject *obj, std::ostream &os, bool isPrivacy) { DISALLOW_GARBAGE_COLLECTION; auto jsHclass = obj->GetClass(); @@ -645,7 +645,7 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) bool needDumpHClass = false; switch (type) { case JSType::HCLASS: - return DumpClass(obj, os); + return DumpClass(thread, obj, os); case JSType::TAGGED_ARRAY: case JSType::TAGGED_DICTIONARY: case JSType::TEMPLATE_MAP: @@ -654,38 +654,38 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) case JSType::SENDABLE_ENV: case JSType::COW_TAGGED_ARRAY: case JSType::AOT_LITERAL_INFO: - DumpArrayClass(TaggedArray::Cast(obj), os); + DumpArrayClass(thread, TaggedArray::Cast(obj), os); break; case JSType::MUTANT_TAGGED_ARRAY: - DumpMutantTaggedArray(MutantTaggedArray::Cast(obj), os); + DumpMutantTaggedArray(thread, MutantTaggedArray::Cast(obj), os); break; case JSType::COW_MUTANT_TAGGED_ARRAY: - DumpCOWMutantTaggedArray(COWMutantTaggedArray::Cast(obj), os); + DumpCOWMutantTaggedArray(thread, COWMutantTaggedArray::Cast(obj), os); break; case JSType::CONSTANT_POOL: - DumpConstantPoolClass(ConstantPool::Cast(obj), os); + DumpConstantPoolClass(thread, ConstantPool::Cast(obj), os); break; case JSType::PROFILE_TYPE_INFO: - ProfileTypeInfo::Cast(obj)->Dump(os); + ProfileTypeInfo::Cast(obj)->Dump(thread, os); break; case JSType::PROFILE_TYPE_INFO_CELL_0: case JSType::PROFILE_TYPE_INFO_CELL_1: case JSType::PROFILE_TYPE_INFO_CELL_N: - ProfileTypeInfoCell::Cast(obj)->Dump(os); + ProfileTypeInfoCell::Cast(obj)->Dump(thread, os); break; case JSType::FUNCTION_TEMPLATE: - FunctionTemplate::Cast(obj)->Dump(os); + FunctionTemplate::Cast(obj)->Dump(thread, os); break; case JSType::VTABLE: - VTable::Cast(obj)->Dump(os); + VTable::Cast(obj)->Dump(thread, os); break; case JSType::EXTRA_PROFILE_TYPE_INFO: - ExtraProfileTypeInfo::Cast(obj)->Dump(os); + ExtraProfileTypeInfo::Cast(obj)->Dump(thread, os); break; case JSType::LINE_STRING: case JSType::TREE_STRING: case JSType::SLICED_STRING: - DumpStringClass(EcmaString::Cast(obj), os); + DumpStringClass(thread, EcmaString::Cast(obj), os); os << "\n"; break; case JSType::JS_NATIVE_POINTER: @@ -705,75 +705,75 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) case JSType::JS_TERMINATION_ERROR: case JSType::JS_ARGUMENTS: needDumpHClass = true; - JSObject::Cast(obj)->Dump(os, isPrivacy); + JSObject::Cast(obj)->Dump(thread, os, isPrivacy); break; case JSType::JS_FUNCTION_BASE: needDumpHClass = true; - JSFunctionBase::Cast(obj)->Dump(os); + JSFunctionBase::Cast(obj)->Dump(thread, os); break; case JSType::GLOBAL_ENV: - GlobalEnv::Cast(obj)->Dump(os); + GlobalEnv::Cast(obj)->Dump(thread, os); break; case JSType::ACCESSOR_DATA: break; case JSType::JS_SHARED_FUNCTION: case JSType::JS_FUNCTION: needDumpHClass = true; - JSFunction::Cast(obj)->Dump(os); + JSFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_BOUND_FUNCTION: needDumpHClass = true; - JSBoundFunction::Cast(obj)->Dump(os); + JSBoundFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_SET: needDumpHClass = true; - JSSet::Cast(obj)->Dump(os); + JSSet::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_SET: needDumpHClass = true; - JSSharedSet::Cast(obj)->Dump(os); + JSSharedSet::Cast(obj)->Dump(thread, os); break; case JSType::JS_MAP: needDumpHClass = true; - JSMap::Cast(obj)->Dump(os); + JSMap::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_MAP: needDumpHClass = true; - JSSharedMap::Cast(obj)->Dump(os); + JSSharedMap::Cast(obj)->Dump(thread, os); break; case JSType::JS_WEAK_SET: needDumpHClass = true; - JSWeakSet::Cast(obj)->Dump(os); + JSWeakSet::Cast(obj)->Dump(thread, os); break; case JSType::JS_WEAK_MAP: needDumpHClass = true; - JSWeakMap::Cast(obj)->Dump(os); + JSWeakMap::Cast(obj)->Dump(thread, os); break; case JSType::JS_WEAK_REF: needDumpHClass = true; - JSWeakRef::Cast(obj)->Dump(os); + JSWeakRef::Cast(obj)->Dump(thread, os); break; case JSType::JS_FINALIZATION_REGISTRY: - JSFinalizationRegistry::Cast(obj)->Dump(os); + JSFinalizationRegistry::Cast(obj)->Dump(thread, os); break; case JSType::CELL_RECORD: - CellRecord::Cast(obj)->Dump(os); + CellRecord::Cast(obj)->Dump(thread, os); break; case JSType::JS_REG_EXP: needDumpHClass = true; - JSRegExp::Cast(obj)->Dump(os); + JSRegExp::Cast(obj)->Dump(thread, os); break; case JSType::JS_DATE: needDumpHClass = true; - JSDate::Cast(obj)->Dump(os); + JSDate::Cast(obj)->Dump(thread, os); break; case JSType::JS_ARRAY: needDumpHClass = true; - JSArray::Cast(obj)->Dump(os); + JSArray::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_ARRAY: needDumpHClass = true; - JSSharedArray::Cast(obj)->Dump(os); + JSSharedArray::Cast(obj)->Dump(thread, os); break; case JSType::JS_TYPED_ARRAY: case JSType::JS_INT8_ARRAY: @@ -788,7 +788,7 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) case JSType::JS_BIGINT64_ARRAY: case JSType::JS_BIGUINT64_ARRAY: needDumpHClass = true; - JSTypedArray::Cast(obj)->Dump(os); + JSTypedArray::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_TYPED_ARRAY: case JSType::JS_SHARED_INT8_ARRAY: @@ -803,216 +803,216 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) case JSType::JS_SHARED_BIGINT64_ARRAY: case JSType::JS_SHARED_BIGUINT64_ARRAY: needDumpHClass = true; - JSSharedTypedArray::Cast(obj)->Dump(os); + JSSharedTypedArray::Cast(obj)->Dump(thread, os); break; case JSType::BIGINT: - BigInt::Cast(obj)->Dump(os); + BigInt::Cast(obj)->Dump(thread, os); break; case JSType::BYTE_ARRAY: - ByteArray::Cast(obj)->Dump(os); + ByteArray::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROXY: needDumpHClass = true; - JSProxy::Cast(obj)->Dump(os); + JSProxy::Cast(obj)->Dump(thread, os); break; case JSType::JS_PRIMITIVE_REF: - JSPrimitiveRef::Cast(obj)->Dump(os); + JSPrimitiveRef::Cast(obj)->Dump(thread, os); break; case JSType::SYMBOL: - JSSymbol::Cast(obj)->Dump(os); + JSSymbol::Cast(obj)->Dump(thread, os); break; case JSType::JS_DATA_VIEW: - JSDataView::Cast(obj)->Dump(os); + JSDataView::Cast(obj)->Dump(thread, os); break; case JSType::JS_ARRAY_BUFFER: - JSArrayBuffer::Cast(obj)->Dump(os); + JSArrayBuffer::Cast(obj)->Dump(thread, os); break; case JSType::JS_SENDABLE_ARRAY_BUFFER: - JSSendableArrayBuffer::Cast(obj)->Dump(os); + JSSendableArrayBuffer::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_ARRAY_BUFFER: - JSArrayBuffer::Cast(obj)->Dump(os); + JSArrayBuffer::Cast(obj)->Dump(thread, os); break; case JSType::PROMISE_REACTIONS: - PromiseReaction::Cast(obj)->Dump(os); + PromiseReaction::Cast(obj)->Dump(thread, os); break; case JSType::PROMISE_CAPABILITY: - PromiseCapability::Cast(obj)->Dump(os); + PromiseCapability::Cast(obj)->Dump(thread, os); break; case JSType::PROMISE_ITERATOR_RECORD: - PromiseIteratorRecord::Cast(obj)->Dump(os); + PromiseIteratorRecord::Cast(obj)->Dump(thread, os); break; case JSType::PROMISE_RECORD: - PromiseRecord::Cast(obj)->Dump(os); + PromiseRecord::Cast(obj)->Dump(thread, os); break; case JSType::RESOLVING_FUNCTIONS_RECORD: - ResolvingFunctionsRecord::Cast(obj)->Dump(os); + ResolvingFunctionsRecord::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE: needDumpHClass = true; - JSPromise::Cast(obj)->Dump(os); + JSPromise::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_REACTIONS_FUNCTION: - JSPromiseReactionsFunction::Cast(obj)->Dump(os); + JSPromiseReactionsFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_EXECUTOR_FUNCTION: - JSPromiseExecutorFunction::Cast(obj)->Dump(os); + JSPromiseExecutorFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_MODULE_FULFILLED_FUNCTION: - JSAsyncModuleFulfilledFunction::Cast(obj)->Dump(os); + JSAsyncModuleFulfilledFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_MODULE_REJECTED_FUNCTION: - JSAsyncModuleRejectedFunction::Cast(obj)->Dump(os); + JSAsyncModuleRejectedFunction::Cast(obj)->Dump(thread, os); break; case JSType::ASYNC_GENERATOR_REQUEST: - AsyncGeneratorRequest::Cast(obj)->Dump(os); + AsyncGeneratorRequest::Cast(obj)->Dump(thread, os); break; case JSType::ASYNC_ITERATOR_RECORD: - AsyncIteratorRecord::Cast(obj)->Dump(os); + AsyncIteratorRecord::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_FROM_SYNC_ITERATOR: - JSAsyncFromSyncIterator::Cast(obj)->Dump(os); + JSAsyncFromSyncIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_FROM_SYNC_ITER_UNWARP_FUNCTION: - JSAsyncFromSyncIterUnwarpFunction::Cast(obj)->Dump(os); + JSAsyncFromSyncIterUnwarpFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: - JSPromiseAllResolveElementFunction::Cast(obj)->Dump(os); + JSPromiseAllResolveElementFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: - JSPromiseAnyRejectElementFunction::Cast(obj)->Dump(os); + JSPromiseAnyRejectElementFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: - JSPromiseAllSettledElementFunction::Cast(obj)->Dump(os); + JSPromiseAllSettledElementFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_FINALLY_FUNCTION: - JSPromiseFinallyFunction::Cast(obj)->Dump(os); + JSPromiseFinallyFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: - JSPromiseValueThunkOrThrowerFunction::Cast(obj)->Dump(os); + JSPromiseValueThunkOrThrowerFunction::Cast(obj)->Dump(thread, os); break; case JSType::MICRO_JOB_QUEUE: - MicroJobQueue::Cast(obj)->Dump(os); + MicroJobQueue::Cast(obj)->Dump(thread, os); break; case JSType::PENDING_JOB: - PendingJob::Cast(obj)->Dump(os); + PendingJob::Cast(obj)->Dump(thread, os); break; case JSType::COMPLETION_RECORD: - CompletionRecord::Cast(obj)->Dump(os); + CompletionRecord::Cast(obj)->Dump(thread, os); break; case JSType::JS_PROXY_REVOC_FUNCTION: - JSProxyRevocFunction::Cast(obj)->Dump(os); + JSProxyRevocFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_FUNCTION: case JSType::JS_SHARED_ASYNC_FUNCTION: needDumpHClass = true; - JSAsyncFunction::Cast(obj)->Dump(os); + JSAsyncFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION: - JSAsyncAwaitStatusFunction::Cast(obj)->Dump(os); + JSAsyncAwaitStatusFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_GENERATOR_FUNCTION: - JSGeneratorFunction::Cast(obj)->Dump(os); + JSGeneratorFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_GENERATOR_FUNCTION: needDumpHClass = true; - JSAsyncGeneratorFunction::Cast(obj)->Dump(os); + JSAsyncGeneratorFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_GENERATOR_RESUME_NEXT_RETURN_PROCESSOR_RST_FTN: - JSAsyncGeneratorResNextRetProRstFtn::Cast(obj)->Dump(os); + JSAsyncGeneratorResNextRetProRstFtn::Cast(obj)->Dump(thread, os); break; case JSType::JS_INTL_BOUND_FUNCTION: - JSIntlBoundFunction::Cast(obj)->Dump(os); + JSIntlBoundFunction::Cast(obj)->Dump(thread, os); break; case JSType::JS_ITERATOR: break; case JSType::JS_ASYNCITERATOR: break; case JSType::JS_FORIN_ITERATOR: - JSForInIterator::Cast(obj)->Dump(os); + JSForInIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_MAP_ITERATOR: - JSMapIterator::Cast(obj)->Dump(os); + JSMapIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_MAP_ITERATOR: - JSSharedMapIterator::Cast(obj)->Dump(os); + JSSharedMapIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_SET_ITERATOR: - JSSetIterator::Cast(obj)->Dump(os); + JSSetIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_SET_ITERATOR: - JSSharedSetIterator::Cast(obj)->Dump(os); + JSSharedSetIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_REG_EXP_ITERATOR: - JSRegExpIterator::Cast(obj)->Dump(os); + JSRegExpIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_ARRAY_ITERATOR: - JSArrayIterator::Cast(obj)->Dump(os); + JSArrayIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_SHARED_ARRAY_ITERATOR: - JSSharedArrayIterator::Cast(obj)->Dump(os); + JSSharedArrayIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_STRING_ITERATOR: - JSStringIterator::Cast(obj)->Dump(os); + JSStringIterator::Cast(obj)->Dump(thread, os); break; case JSType::PROTOTYPE_HANDLER: - PrototypeHandler::Cast(obj)->Dump(os); + PrototypeHandler::Cast(obj)->Dump(thread, os); break; case JSType::TRANSITION_HANDLER: - TransitionHandler::Cast(obj)->Dump(os); + TransitionHandler::Cast(obj)->Dump(thread, os); break; case JSType::TRANS_WITH_PROTO_HANDLER: - TransWithProtoHandler::Cast(obj)->Dump(os); + TransWithProtoHandler::Cast(obj)->Dump(thread, os); break; case JSType::STORE_TS_HANDLER: - StoreAOTHandler::Cast(obj)->Dump(os); + StoreAOTHandler::Cast(obj)->Dump(thread, os); break; case JSType::PROPERTY_BOX: - PropertyBox::Cast(obj)->Dump(os); + PropertyBox::Cast(obj)->Dump(thread, os); break; case JSType::JS_REALM: needDumpHClass = true; - JSRealm::Cast(obj)->Dump(os); + JSRealm::Cast(obj)->Dump(thread, os); break; #ifdef ARK_SUPPORT_INTL case JSType::JS_INTL: needDumpHClass = true; - JSIntl::Cast(obj)->Dump(os); + JSIntl::Cast(obj)->Dump(thread, os); break; case JSType::JS_LOCALE: needDumpHClass = true; - JSLocale::Cast(obj)->Dump(os); + JSLocale::Cast(obj)->Dump(thread, os); break; case JSType::JS_DATE_TIME_FORMAT: - JSDateTimeFormat::Cast(obj)->Dump(os); + JSDateTimeFormat::Cast(obj)->Dump(thread, os); break; case JSType::JS_RELATIVE_TIME_FORMAT: - JSRelativeTimeFormat::Cast(obj)->Dump(os); + JSRelativeTimeFormat::Cast(obj)->Dump(thread, os); break; case JSType::JS_NUMBER_FORMAT: - JSNumberFormat::Cast(obj)->Dump(os); + JSNumberFormat::Cast(obj)->Dump(thread, os); break; case JSType::JS_COLLATOR: needDumpHClass = true; - JSCollator::Cast(obj)->Dump(os); + JSCollator::Cast(obj)->Dump(thread, os); break; case JSType::JS_PLURAL_RULES: - JSPluralRules::Cast(obj)->Dump(os); + JSPluralRules::Cast(obj)->Dump(thread, os); break; case JSType::JS_DISPLAYNAMES: - JSDisplayNames::Cast(obj)->Dump(os); + JSDisplayNames::Cast(obj)->Dump(thread, os); break; case JSType::JS_SEGMENTER: - JSSegmenter::Cast(obj)->Dump(os); + JSSegmenter::Cast(obj)->Dump(thread, os); break; case JSType::JS_SEGMENTS: - JSSegments::Cast(obj)->Dump(os); + JSSegments::Cast(obj)->Dump(thread, os); break; case JSType::JS_SEGMENT_ITERATOR: - JSSegmentIterator::Cast(obj)->Dump(os); + JSSegmentIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_LIST_FORMAT: - JSListFormat::Cast(obj)->Dump(os); + JSListFormat::Cast(obj)->Dump(thread, os); break; #else case JSType::JS_INTL: @@ -1031,188 +1031,188 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) #endif case JSType::JS_GENERATOR_OBJECT: needDumpHClass = true; - JSGeneratorObject::Cast(obj)->Dump(os); + JSGeneratorObject::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_GENERATOR_OBJECT: needDumpHClass = true; - JSAsyncGeneratorObject::Cast(obj)->Dump(os); + JSAsyncGeneratorObject::Cast(obj)->Dump(thread, os); break; case JSType::JS_ASYNC_FUNC_OBJECT: needDumpHClass = true; - JSAsyncFuncObject::Cast(obj)->Dump(os); + JSAsyncFuncObject::Cast(obj)->Dump(thread, os); break; case JSType::JS_GENERATOR_CONTEXT: - GeneratorContext::Cast(obj)->Dump(os); + GeneratorContext::Cast(obj)->Dump(thread, os); break; case JSType::PROTOTYPE_INFO: - ProtoChangeDetails::Cast(obj)->Dump(os); + ProtoChangeDetails::Cast(obj)->Dump(thread, os); break; case JSType::TRACK_INFO: - TrackInfo::Cast(obj)->Dump(os); + TrackInfo::Cast(obj)->Dump(thread, os); break; case JSType::ENUM_CACHE: - EnumCache::Cast(obj)->Dump(os); + EnumCache::Cast(obj)->Dump(thread, os); break; case JSType::PROTO_CHANGE_MARKER: - ProtoChangeMarker::Cast(obj)->Dump(os); + ProtoChangeMarker::Cast(obj)->Dump(thread, os); break; case JSType::MARKER_CELL: - MarkerCell::Cast(obj)->Dump(os); + MarkerCell::Cast(obj)->Dump(thread, os); break; case JSType::PROGRAM: - Program::Cast(obj)->Dump(os); + Program::Cast(obj)->Dump(thread, os); break; case JSType::MACHINE_CODE_OBJECT: - MachineCode::Cast(obj)->Dump(os); + MachineCode::Cast(obj)->Dump(thread, os); break; case JSType::CLASS_INFO_EXTRACTOR: - ClassInfoExtractor::Cast(obj)->Dump(os); + ClassInfoExtractor::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_ARRAY_LIST: - JSAPIArrayList::Cast(obj)->Dump(os); + JSAPIArrayList::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_ARRAYLIST_ITERATOR: - JSAPIArrayListIterator::Cast(obj)->Dump(os); + JSAPIArrayListIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_BITVECTOR: - JSAPIBitVector::Cast(obj)->Dump(os); + JSAPIBitVector::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_BITVECTOR_ITERATOR: - JSAPIBitVectorIterator::Cast(obj)->Dump(os); + JSAPIBitVectorIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_FAST_BUFFER: - JSAPIFastBuffer::Cast(obj)->Dump(os); + JSAPIFastBuffer::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LIGHT_WEIGHT_MAP: - JSAPILightWeightMap::Cast(obj)->Dump(os); + JSAPILightWeightMap::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: - JSAPILightWeightMapIterator::Cast(obj)->Dump(os); + JSAPILightWeightMapIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LIGHT_WEIGHT_SET: - JSAPILightWeightSet::Cast(obj)->Dump(os); + JSAPILightWeightSet::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: - JSAPILightWeightSetIterator::Cast(obj)->Dump(os); + JSAPILightWeightSetIterator::Cast(obj)->Dump(thread, os); break; case JSType::LINKED_NODE: - LinkedNode::Cast(obj)->Dump(os); + LinkedNode::Cast(obj)->Dump(thread, os); break; case JSType::RB_TREENODE: break; case JSType::JS_API_HASH_MAP: - JSAPIHashMap::Cast(obj)->Dump(os); + JSAPIHashMap::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_HASH_SET: - JSAPIHashSet::Cast(obj)->Dump(os); + JSAPIHashSet::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_HASHMAP_ITERATOR: - JSAPIHashMapIterator::Cast(obj)->Dump(os); + JSAPIHashMapIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_HASHSET_ITERATOR: - JSAPIHashSetIterator::Cast(obj)->Dump(os); + JSAPIHashSetIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_TREE_MAP: - JSAPITreeMap::Cast(obj)->Dump(os); + JSAPITreeMap::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_TREE_SET: - JSAPITreeSet::Cast(obj)->Dump(os); + JSAPITreeSet::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_TREEMAP_ITERATOR: - JSAPITreeMapIterator::Cast(obj)->Dump(os); + JSAPITreeMapIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_TREESET_ITERATOR: - JSAPITreeSetIterator::Cast(obj)->Dump(os); + JSAPITreeSetIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_VECTOR: - JSAPIVector::Cast(obj)->Dump(os); + JSAPIVector::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_VECTOR_ITERATOR: - JSAPIVectorIterator::Cast(obj)->Dump(os); + JSAPIVectorIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_QUEUE: - JSAPIQueue::Cast(obj)->Dump(os); + JSAPIQueue::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_QUEUE_ITERATOR: - JSAPIQueueIterator::Cast(obj)->Dump(os); + JSAPIQueueIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_DEQUE: - JSAPIDeque::Cast(obj)->Dump(os); + JSAPIDeque::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_DEQUE_ITERATOR: - JSAPIDequeIterator::Cast(obj)->Dump(os); + JSAPIDequeIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_STACK: - JSAPIStack::Cast(obj)->Dump(os); + JSAPIStack::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_STACK_ITERATOR: - JSAPIStackIterator::Cast(obj)->Dump(os); + JSAPIStackIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LIST: - JSAPIList::Cast(obj)->Dump(os); + JSAPIList::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LIST_ITERATOR: - JSAPIListIterator::Cast(obj)->Dump(os); + JSAPIListIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LINKED_LIST: - JSAPILinkedList::Cast(obj)->Dump(os); + JSAPILinkedList::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_LINKED_LIST_ITERATOR: - JSAPILinkedListIterator::Cast(obj)->Dump(os); + JSAPILinkedListIterator::Cast(obj)->Dump(thread, os); break; case JSType::SOURCE_TEXT_MODULE_RECORD: - SourceTextModule::Cast(obj)->Dump(os); + SourceTextModule::Cast(obj)->Dump(thread, os); break; case JSType::IMPORTENTRY_RECORD: - ImportEntry::Cast(obj)->Dump(os); + ImportEntry::Cast(obj)->Dump(thread, os); break; case JSType::LOCAL_EXPORTENTRY_RECORD: - LocalExportEntry::Cast(obj)->Dump(os); + LocalExportEntry::Cast(obj)->Dump(thread, os); break; case JSType::INDIRECT_EXPORTENTRY_RECORD: - IndirectExportEntry::Cast(obj)->Dump(os); + IndirectExportEntry::Cast(obj)->Dump(thread, os); break; case JSType::STAR_EXPORTENTRY_RECORD: - StarExportEntry::Cast(obj)->Dump(os); + StarExportEntry::Cast(obj)->Dump(thread, os); break; case JSType::RESOLVEDBINDING_RECORD: - ResolvedBinding::Cast(obj)->Dump(os); + ResolvedBinding::Cast(obj)->Dump(thread, os); break; case JSType::RESOLVEDINDEXBINDING_RECORD: - ResolvedIndexBinding::Cast(obj)->Dump(os); + ResolvedIndexBinding::Cast(obj)->Dump(thread, os); break; case JSType::RESOLVEDRECORDINDEXBINDING_RECORD: - ResolvedRecordIndexBinding::Cast(obj)->Dump(os); + ResolvedRecordIndexBinding::Cast(obj)->Dump(thread, os); break; case JSType::RESOLVEDRECORDBINDING_RECORD: - ResolvedRecordBinding::Cast(obj)->Dump(os); + ResolvedRecordBinding::Cast(obj)->Dump(thread, os); break; case JSType::NATIVE_MODULE_FAILURE_INFO: - NativeModuleFailureInfo::Cast(obj)->Dump(os); + NativeModuleFailureInfo::Cast(obj)->Dump(thread, os); break; case JSType::JS_MODULE_NAMESPACE: - ModuleNamespace::Cast(obj)->Dump(os); + ModuleNamespace::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_PLAIN_ARRAY: - JSAPIPlainArray::Cast(obj)->Dump(os); + JSAPIPlainArray::Cast(obj)->Dump(thread, os); break; case JSType::JS_API_PLAIN_ARRAY_ITERATOR: - JSAPIPlainArrayIterator::Cast(obj)->Dump(os); + JSAPIPlainArrayIterator::Cast(obj)->Dump(thread, os); break; case JSType::JS_CJS_MODULE: - CjsModule::Cast(obj)->Dump(os); + CjsModule::Cast(obj)->Dump(thread, os); break; case JSType::JS_CJS_REQUIRE: - CjsRequire::Cast(obj)->Dump(os); + CjsRequire::Cast(obj)->Dump(thread, os); break; case JSType::JS_CJS_EXPORTS: - CjsExports::Cast(obj)->Dump(os); + CjsExports::Cast(obj)->Dump(thread, os); break; case JSType::METHOD: - Method::Cast(obj)->Dump(os); + Method::Cast(obj)->Dump(thread, os); break; case JSType::CLASS_LITERAL: - ClassLiteral::Cast(obj)->Dump(os); + ClassLiteral::Cast(obj)->Dump(thread, os); break; default: LOG_ECMA(FATAL) << "this branch is unreachable"; @@ -1221,7 +1221,7 @@ static void DumpObject(TaggedObject *obj, std::ostream &os, bool isPrivacy) } if (needDumpHClass) { - DumpHClass(jsHclass, os, false); + DumpHClass(thread, jsHclass, os, false); } } @@ -1255,7 +1255,7 @@ void JSTaggedValue::DumpSpecialValue(std::ostream &os) const } } -void JSTaggedValue::DumpHeapObjectType(std::ostream &os) const +void JSTaggedValue::DumpHeapObjectType(const JSThread *thread, std::ostream &os) const { ASSERT(IsWeak() || IsHeapObject()); bool isWeak = IsWeak(); @@ -1266,7 +1266,7 @@ void JSTaggedValue::DumpHeapObjectType(std::ostream &os) const JSType type = obj->GetClass()->GetObjectType(); if (type >= JSType::STRING_FIRST && type <= JSType::STRING_LAST) { - CString string = ConvertToString(EcmaString::Cast(obj)); + CString string = ConvertToString(thread, EcmaString::Cast(obj)); os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[" + string + "]"; } else if (type == JSType::METHOD) { std::ostringstream address; @@ -1275,7 +1275,7 @@ void JSTaggedValue::DumpHeapObjectType(std::ostream &os) const Method *method = Method::Cast(obj); os << std::left << std::setw(DUMP_TYPE_OFFSET) - << "[" + JSHClass::DumpJSType(type) + "(" + addrStr + "-" + method->GetMethodName() + ")]"; + << "[" + JSHClass::DumpJSType(type) + "(" + addrStr + "-" + method->GetMethodName(thread) + ")]"; } else { std::ostringstream address; address << obj; @@ -1285,7 +1285,7 @@ void JSTaggedValue::DumpHeapObjectType(std::ostream &os) const } } -void JSTaggedValue::DumpTaggedValue(std::ostream &os) const +void JSTaggedValue::DumpTaggedValue(const JSThread *thread, std::ostream &os) const { if (IsInt()) { os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[Int] : " << std::hex << "0x" << GetInt() << std::dec << " (" @@ -1295,7 +1295,7 @@ void JSTaggedValue::DumpTaggedValue(std::ostream &os) const } else if (IsSpecial()) { DumpSpecialValue(os); } else { - DumpHeapObjectType(os); + DumpHeapObjectType(thread, os); } } @@ -1314,18 +1314,21 @@ void JSTaggedValue::DumpTaggedValueType(std::ostream &os) const } } -void JSTaggedValue::Dump(std::ostream &os, bool isPrivacy) const +void JSTaggedValue::Dump(const JSThread *thread, std::ostream &os, bool isPrivacy) const { - DumpTaggedValue(os); + DumpTaggedValue(thread, os); os << "\n"; if (IsHeapObject()) { + if (UNLIKELY(thread == nullptr)) { + thread = JSThread::GetCurrent(); + } TaggedObject *obj = IsWeak() ? GetTaggedWeakRef() : GetTaggedObject(); - DumpObject(obj, os, isPrivacy); + DumpObject(thread, obj, os, isPrivacy); } } -void JSTaggedValue::DumpHeapObjAddress(std::ostream &os) const +void JSTaggedValue::DumpHeapObjAddress([[maybe_unused]]const JSThread *thread, std::ostream &os) const { if (IsHeapObject()) { TaggedObject *obj = IsWeak() ? GetTaggedWeakRef() : GetTaggedObject(); @@ -1335,14 +1338,14 @@ void JSTaggedValue::DumpHeapObjAddress(std::ostream &os) const } } -void JSTaggedValue::D() const +void JSTaggedValue::D(const JSThread *thread) const { - Dump(std::cout); + Dump(thread, std::cout); } -void JSTaggedValue::DV(JSTaggedType val) +void JSTaggedValue::DV(const JSThread *thread, JSTaggedType val) { - JSTaggedValue(val).D(); + JSTaggedValue(val).D(thread); } void JSThread::DumpStack() @@ -1351,134 +1354,134 @@ void JSThread::DumpStack() handler.DumpStack(std::cout); } -void NumberDictionary::Dump(std::ostream &os, bool isPrivacy) const +void NumberDictionary::Dump(const JSThread *thread, std::ostream &os, bool isPrivacy) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << static_cast(JSTaggedNumber(key).GetNumber()) << ": "; if (!isPrivacy) { - JSTaggedValue val(GetValue(hashIndex)); - val.DumpTaggedValue(os); + JSTaggedValue val(GetValue(thread, hashIndex)); + val.DumpTaggedValue(thread, os); } os << " "; - DumpAttr(GetAttributes(hashIndex), false, os); + DumpAttr(GetAttributes(thread, hashIndex), false, os); os << "\n"; } } } -void NameDictionary::Dump(std::ostream &os, bool isPrivacy) const +void NameDictionary::Dump(const JSThread *thread, std::ostream &os, bool isPrivacy) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << ": "; if (!isPrivacy) { - JSTaggedValue val(GetValue(hashIndex)); - val.DumpTaggedValue(os); + JSTaggedValue val(GetValue(thread, hashIndex)); + val.DumpTaggedValue(thread, os); } os << " "; - DumpAttr(GetAttributes(hashIndex), false, os); + DumpAttr(GetAttributes(thread, hashIndex), false, os); os << "\n"; } } } -void GlobalDictionary::Dump(std::ostream &os, bool isPrivacy) const +void GlobalDictionary::Dump(const JSThread *thread, std::ostream &os, bool isPrivacy) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << " : "; if (!isPrivacy) { - JSTaggedValue val(GetValue(hashIndex)); - val.DumpTaggedValue(os); + JSTaggedValue val(GetValue(thread, hashIndex)); + val.DumpTaggedValue(thread, os); } os << " "; - DumpAttr(GetAttributes(hashIndex), false, os); + DumpAttr(GetAttributes(thread, hashIndex), false, os); os << "\n"; } } } -void LayoutInfo::Dump(std::ostream &os) const +void LayoutInfo::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; int num = NumberOfElements(); for (int i = 0; i < num; i++) { - JSTaggedValue key = GetKey(i); - PropertyAttributes attr = GetAttr(i); + JSTaggedValue key = GetKey(thread, i); + PropertyAttributes attr = GetAttr(thread, i); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); os << "[" << i << "]: "; - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << " : "; DumpAttr(attr, true, os); os << "\n"; } } -void TransitionsDictionary::Dump(std::ostream &os) const +void TransitionsDictionary::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << " : "; - GetValue(hashIndex).DumpTaggedValue(os); + GetValue(thread, hashIndex).DumpTaggedValue(thread, os); os << " : "; - GetAttributes(hashIndex).DumpTaggedValue(os); + GetAttributes(thread, hashIndex).DumpTaggedValue(thread, os); os << "\n"; } } } -void LinkedHashSet::Dump(std::ostream &os) const +void LinkedHashSet::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfElements() + NumberOfDeletedElements(); for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); - key.DumpTaggedValue(os); + key.DumpTaggedValue(thread, os); os << "\n"; } } } -void LinkedHashMap::Dump(std::ostream &os) const +void LinkedHashMap::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfElements() + NumberOfDeletedElements(); for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(thread, hashIndex)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); - key.DumpTaggedValue(os); + key.DumpTaggedValue(thread, os); os << ": "; - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); os << "\n"; } } } -void TaggedDoubleList::Dump(std::ostream &os) const +void TaggedDoubleList::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfNodes(); @@ -1486,87 +1489,87 @@ void TaggedDoubleList::Dump(std::ostream &os) const os << " - delete node num: " << std::dec << NumberOfDeletedNodes() << "\n"; os << "head-next: "; // 5 : 5 first element next ptr - GetElement(5).Dump(os); + GetElement(thread, 5).Dump(thread, os); os << "head-pre: "; // 6 : 6 first element per ptr - GetElement(6).Dump(os); + GetElement(thread, 6).Dump(thread, os); os << "\n"; int i = 0; - int next = GetElement(5).GetInt(); + int next = GetElement(thread, 5).GetInt(); while (capacity > i) { os << " value: "; - GetElement(next).DumpTaggedValue(os); + GetElement(thread, next).DumpTaggedValue(thread, os); os << " next: "; // 1 : 1 current element next ptr offset - GetElement(next + 1).Dump(os); + GetElement(thread, next + 1).Dump(thread, os); os << " pre: "; // 2 : 2 current element pre ptr offset - GetElement(next + 2).Dump(os); + GetElement(thread, next + 2).Dump(thread, os); os << "\n"; - next = GetElement(next + 1).GetInt(); + next = GetElement(thread, next + 1).GetInt(); i++; } } -void TaggedSingleList::Dump(std::ostream &os) const +void TaggedSingleList::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfNodes(); os << "head-next: "; // 5 : 5 first element next ptr - GetElement(5).Dump(os); + GetElement(thread, 5).Dump(thread, os); os << "\n"; int i = 0; - int next = GetElement(5).GetInt(); + int next = GetElement(thread, 5).GetInt(); while (capacity > i) { os << " value: "; - GetElement(next).DumpTaggedValue(os); + GetElement(thread, next).DumpTaggedValue(thread, os); os << " next: "; // 1 : 1 current element next ptr offset - GetElement(next + 1).Dump(os); + GetElement(thread, next + 1).Dump(thread, os); os << "\n"; - next = GetElement(next + 1).GetInt(); + next = GetElement(thread, next + 1).GetInt(); i++; } } -void JSObject::Dump(std::ostream &os, bool isPrivacy) const +void JSObject::Dump(const JSThread *thread, std::ostream &os, bool isPrivacy) const { DISALLOW_GARBAGE_COLLECTION; JSHClass *jshclass = GetJSHClass(); os << " - hclass: " << std::hex << jshclass << "\n"; os << " - prototype: "; - jshclass->GetPrototype().DumpTaggedValue(os); + jshclass->GetPrototype(thread).DumpTaggedValue(thread, os); os << "\n"; - JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, this, HASH_OFFSET); JSTaggedValue value(hashField); os << " - hash: " << std::hex << hashField; - value.Dump(os); + value.Dump(thread, os); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); os << " - elements: " << std::hex << elements; if (elements->GetLength() == 0) { os << " NONE\n"; } else if (!elements->IsDictionaryMode()) { - DumpArrayClass(elements, os); + DumpArrayClass(thread, elements, os); } else { NumberDictionary *dict = NumberDictionary::Cast(elements); os << " EntriesCount() << "]>\n"; - dict->Dump(os, isPrivacy); + dict->Dump(thread, os, isPrivacy); } - TaggedArray *properties = TaggedArray::Cast(GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); os << " - properties: " << std::hex << properties; if (IsJSGlobalObject()) { GlobalDictionary *dict = GlobalDictionary::Cast(properties); os << " EntriesCount() << "]>\n"; - dict->Dump(os, isPrivacy); + dict->Dump(thread, os, isPrivacy); return; } if (!properties->IsDictionaryMode()) { - JSTaggedValue attrs = jshclass->GetLayout(); + JSTaggedValue attrs = jshclass->GetLayout(thread); if (attrs.IsNull()) { return; } @@ -1575,20 +1578,20 @@ void JSObject::Dump(std::ostream &os, bool isPrivacy) const int propNumber = static_cast(jshclass->NumberOfProps()); os << " \n"; for (int i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); - PropertyAttributes attr = layoutInfo->GetAttr(i); + JSTaggedValue key = layoutInfo->GetKey(thread, i); + PropertyAttributes attr = layoutInfo->GetAttr(thread, i); ASSERT(i == static_cast(attr.GetOffset())); os << " " << std::right << std::setw(DUMP_PROPERTY_OFFSET); - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << ": ("; JSTaggedValue val; if (attr.IsInlinedProps()) { - val = GetPropertyInlinedPropsWithRep(i, attr); + val = GetPropertyInlinedPropsWithRep(thread, i, attr); } else { - val = properties->Get(i - static_cast(jshclass->GetInlinedProperties())); + val = properties->Get(thread, i - static_cast(jshclass->GetInlinedProperties())); } if (!isPrivacy) { - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); } os << ") "; DumpAttr(attr, true, os); @@ -1597,16 +1600,16 @@ void JSObject::Dump(std::ostream &os, bool isPrivacy) const } else { NameDictionary *dict = NameDictionary::Cast(properties); os << " EntriesCount() << "]>\n"; - dict->Dump(os, isPrivacy); + dict->Dump(thread, os, isPrivacy); } } -void TaggedArray::Dump(std::ostream &os) const +void TaggedArray::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void AccessorData::Dump(std::ostream &os) const +void AccessorData::Dump(const JSThread *thread, std::ostream &os) const { auto *hclass = GetClass(); if (hclass->GetObjectType() == JSType::INTERNAL_ACCESSOR) { @@ -1616,81 +1619,81 @@ void AccessorData::Dump(std::ostream &os) const } os << " - Getter: "; - GetGetter().DumpTaggedValue(os); + GetGetter(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - Setter: "; - GetSetter().DumpTaggedValue(os); + GetSetter(thread).DumpTaggedValue(thread, os); os << "\n"; } -void Program::Dump(std::ostream &os) const +void Program::Dump(const JSThread *thread, std::ostream &os) const { os << " - MainFunction: "; - GetMainFunction().Dump(os); + GetMainFunction(thread).Dump(thread, os); os << "\n"; } -void LinkedNode::Dump(std::ostream &os) const +void LinkedNode::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - Next: "; os << "\n"; } -void ConstantPool::Dump(std::ostream &os) const +void ConstantPool::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void ProfileTypeInfo::Dump(std::ostream &os) const +void ProfileTypeInfo::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; uint32_t len = GetIcSlotLength(); os << " \n"; for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(Get(i)); + JSTaggedValue val(Get(thread, i)); if (!val.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << i << ": "; - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); os << "\n"; } } } -void ExtraProfileTypeInfo::Dump(std::ostream &os) const +void ExtraProfileTypeInfo::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; os << " - Receiver: "; - GetReceiverObject().Dump(os); + GetReceiverObject(thread).Dump(thread, os); os << " - Holder: "; - GetHolderObject().Dump(os); + GetHolderObject(thread).Dump(thread, os); os << "\n"; } -void ProfileTypeInfoCell::Dump(std::ostream &os) const +void ProfileTypeInfoCell::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; os << " - Value: "; - GetValue().Dump(os); + GetValue(thread).Dump(thread, os); os << " - Handle: "; - GetHandle().Dump(os); + GetHandle(thread).Dump(thread, os); os << "\n"; } -void FunctionTemplate::Dump(std::ostream &os) const +void FunctionTemplate::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; os << " - Method: "; - GetMethod().Dump(os); + GetMethod(thread).Dump(thread, os); os << " - Module: "; - GetModule().Dump(os); + GetModule(thread).Dump(thread, os); os << " - RawProfileTypeInfo: "; - GetRawProfileTypeInfo().Dump(os); + GetRawProfileTypeInfo(thread).Dump(thread, os); os << " - length : " << GetLength() << "\n"; } -void VTable::Dump(std::ostream &os) const +void VTable::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; uint32_t num = GetNumberOfTuples(); @@ -1698,176 +1701,178 @@ void VTable::Dump(std::ostream &os) const for (uint32_t i = 0; i < num; i++) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); os << "[" << i << "]: [ name :"; - JSTaggedValue name = GetTupleItem(i, VTable::TupleItem::NAME); - DumpPropertyKey(name, os); - os << ", type :" << (IsAccessor(i) ? "Accessor" : "Function"); - JSTaggedValue owner = GetTupleItem(i, VTable::TupleItem::OWNER); + JSTaggedValue name = GetTupleItem(thread, i, VTable::TupleItem::NAME); + DumpPropertyKey(thread, name, os); + os << ", type :" << (IsAccessor(thread, i) ? "Accessor" : "Function"); + JSTaggedValue owner = GetTupleItem(thread, i, VTable::TupleItem::OWNER); os << ", owner :"; - owner.DumpTaggedValue(os); - JSTaggedValue offset = GetTupleItem(i, VTable::TupleItem::OFFSET); + owner.DumpTaggedValue(thread, os); + JSTaggedValue offset = GetTupleItem(thread, i, VTable::TupleItem::OFFSET); os << ", offset :" << offset.GetInt(); os << " ] "; os << "\n"; } } -void JSFunction::Dump(std::ostream &os) const +void JSFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - ProtoOrHClass: "; - GetProtoOrHClass().Dump(os); + GetProtoOrHClass(thread).Dump(thread, os); os << "\n"; os << " - LexicalEnv: "; - if (GetLexicalEnv().IsLexicalEnv()) { - GetLexicalEnv().Dump(os); + if (GetLexicalEnv(thread).IsLexicalEnv()) { + GetLexicalEnv(thread).Dump(thread, os); } else { - GetLexicalEnv().DumpTaggedValue(os); // reduce circular calls + GetLexicalEnv(thread).DumpTaggedValue(thread, os); // reduce circular calls } os << "\n"; os << " - RawProfileTypeInfo: "; - GetRawProfileTypeInfo().Dump(os); + GetRawProfileTypeInfo(thread).Dump(thread, os); os << "\n"; os << " - HomeObject: "; - GetHomeObject().Dump(os); + GetHomeObject(thread).Dump(thread, os); os << "\n"; os << " - FunctionExtraInfo: "; - GetFunctionExtraInfo().Dump(os); + GetFunctionExtraInfo(thread).Dump(thread, os); os << "\n"; os << " - Method: "; - GetMethod().Dump(os); + GetMethod(thread).Dump(thread, os); os << "\n"; os << " - Module: "; - GetModule().Dump(os); + GetModule(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSHClass::Dump(std::ostream &os) const +void JSHClass::Dump(const JSThread *thread, std::ostream &os) const { - DumpHClass(this, os, true); + DumpHClass(thread, this, os, true); } -void JSBoundFunction::Dump(std::ostream &os) const +void JSBoundFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - BoundTarget: "; - GetBoundTarget().DumpTaggedValue(os); + GetBoundTarget(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - BoundThis: "; - GetBoundThis().DumpTaggedValue(os); + GetBoundThis(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - BoundArguments: "; - GetBoundArguments().DumpTaggedValue(os); + GetBoundArguments(thread).DumpTaggedValue(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSPrimitiveRef::Dump(std::ostream &os) const +void JSPrimitiveRef::Dump(const JSThread *thread, std::ostream &os) const { os << " - SubValue : "; - GetValue().DumpTaggedValue(os); + GetValue(thread).DumpTaggedValue(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void BigInt::Dump(std::ostream &os) const +void BigInt::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - length : " << GetLength() << "\n"; os << " - Sign : " << GetSign() << "\n"; os << " - value : " << ToStdString(DECIMAL) << "\n"; } -void JSDate::Dump(std::ostream &os) const +void JSDate::Dump(const JSThread *thread, std::ostream &os) const { - os << " - time: " << GetTime().GetDouble() << "\n"; - os << " - localOffset: " << GetLocalOffset().GetDouble() << "\n"; - JSObject::Dump(os); + os << " - time: " << GetTime(const_cast(thread)).GetDouble() << "\n"; + os << " - localOffset: " << GetLocalOffset(thread).GetDouble() << "\n"; + JSObject::Dump(thread, os); } -void JSMap::Dump(std::ostream &os) const +void JSMap::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject()); os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSSharedMap::Dump(std::ostream &os) const +void JSSharedMap::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject()); os << " - modRecord: " << std::dec << GetModRecord() << "\n"; os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSAPITreeMap::Dump(std::ostream &os) const +void JSAPITreeMap::Dump(const JSThread *thread, std::ostream &os) const { - TaggedTreeMap *map = TaggedTreeMap::Cast(GetTreeMap().GetTaggedObject()); + TaggedTreeMap *map = TaggedTreeMap::Cast(GetTreeMap(thread).GetTaggedObject()); os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSAPITreeMap::DumpForSnapshot(std::vector &vec) const +void JSAPITreeMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetTreeMap().IsInvalidValue())) { - TaggedTreeMap *map = TaggedTreeMap::Cast(GetTreeMap().GetTaggedObject()); - vec.emplace_back("treemap", GetTreeMap()); - map->DumpForSnapshot(vec); + if (!(GetTreeMap(thread).IsInvalidValue())) { + TaggedTreeMap *map = TaggedTreeMap::Cast(GetTreeMap(thread).GetTaggedObject()); + vec.emplace_back("treemap", GetTreeMap(thread)); + map->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPITreeMapIterator::Dump(std::ostream &os) const +void JSAPITreeMapIterator::Dump(const JSThread *thread, std::ostream &os) const { TaggedTreeMap *map = - TaggedTreeMap::Cast(JSAPITreeMap::Cast(GetIteratedMap().GetTaggedObject())->GetTreeMap().GetTaggedObject()); + TaggedTreeMap::Cast(JSAPITreeMap::Cast(GetIteratedMap(thread).GetTaggedObject())-> + GetTreeMap(thread).GetTaggedObject()); os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSAPITreeMapIterator::DumpForSnapshot(std::vector &vec) const +void JSAPITreeMapIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedMap().IsInvalidValue())) { + if (!(GetIteratedMap(thread).IsInvalidValue())) { TaggedTreeMap *map = - TaggedTreeMap::Cast(JSAPITreeMap::Cast(GetIteratedMap().GetTaggedObject())->GetTreeMap().GetTaggedObject()); - vec.emplace_back("iteratedmap", GetIteratedMap()); - map->DumpForSnapshot(vec); + TaggedTreeMap::Cast(JSAPITreeMap::Cast(GetIteratedMap(thread).GetTaggedObject())-> + GetTreeMap(thread).GetTaggedObject()); + vec.emplace_back("iteratedmap", GetIteratedMap(thread)); + map->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } template -void DumpTaggedTreeEntry(T tree, std::ostream &os, int index, bool isMap = false) +void DumpTaggedTreeEntry(const JSThread *thread, T tree, std::ostream &os, int index, bool isMap = false) { DISALLOW_GARBAGE_COLLECTION; JSTaggedValue parent(tree->GetParent(index)); - JSTaggedValue val(tree->GetValue(index)); + JSTaggedValue val(tree->GetValue(thread, index)); JSTaggedValue color(static_cast(tree->GetColor(index))); JSTaggedValue left = tree->GetLeftChild(index); JSTaggedValue right = tree->GetRightChild(index); @@ -1875,1259 +1880,1261 @@ void DumpTaggedTreeEntry(T tree, std::ostream &os, int index, bool isMap = false os << "\n"; if (isMap) { os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << " [key]: {"; - JSTaggedValue key(tree->GetKey(index)); - key.DumpTaggedValue(os); + JSTaggedValue key(tree->GetKey(thread, index)); + key.DumpTaggedValue(thread, os); os << std::right << "};"; os << "\n"; } os << std::left << std::setw(DUMP_TYPE_OFFSET) << " [value]: {"; - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); os << std::right << "};"; os << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << " [parent]: {"; - parent.DumpTaggedValue(os); + parent.DumpTaggedValue(thread, os); os << std::right << "};"; os << "\n"; os << std::left << std::setw(DUMP_TYPE_OFFSET) << " [color]: {"; - color.DumpTaggedValue(os); + color.DumpTaggedValue(thread, os); os << std::right << "};"; os << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << " [left]: {"; - left.DumpTaggedValue(os); + left.DumpTaggedValue(thread, os); os << std::right << "}; "; os << std::left << std::setw(DUMP_TYPE_OFFSET) << " [right]: {"; - right.DumpTaggedValue(os); + right.DumpTaggedValue(thread, os); os << std::right << "};"; os << "\n"; } -void TaggedTreeMap::Dump(std::ostream &os) const +void TaggedTreeMap::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[Elements]: {"; - JSTaggedValue node = TaggedArray::Get(0); - node.DumpTaggedValue(os); + JSTaggedValue node = TaggedArray::Get(thread, 0); + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[Delete]: {"; - node = TaggedArray::Get(1); - node.DumpTaggedValue(os); + node = TaggedArray::Get(thread, 1); + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[Capacity]: {"; - node = TaggedArray::Get(2); // 2 means the three element - node.DumpTaggedValue(os); + node = TaggedArray::Get(thread, 2); // 2 means the three element + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[RootNode]: {"; - node = TaggedArray::Get(3); // 3 means the three element - node.DumpTaggedValue(os); + node = TaggedArray::Get(thread, 3); // 3 means the three element + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; uint32_t capacity = NumberOfElements() + NumberOfDeletedElements(); for (uint32_t index = 0; index < capacity; index++) { - if (GetKey(index).IsHole()) { + if (GetKey(thread, index).IsHole()) { os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[entry] " << index << ": "; - GetKey(index).DumpTaggedValue(os); + GetKey(thread, index).DumpTaggedValue(thread, os); os << "\n"; } else { - DumpTaggedTreeEntry(const_cast(this), os, index, true); + DumpTaggedTreeEntry(thread, const_cast(this), os, index, true); } } } -void JSAPITreeSet::Dump(std::ostream &os) const +void JSAPITreeSet::Dump(const JSThread *thread, std::ostream &os) const { - TaggedTreeSet *set = TaggedTreeSet::Cast(GetTreeSet().GetTaggedObject()); + TaggedTreeSet *set = TaggedTreeSet::Cast(GetTreeSet(thread).GetTaggedObject()); os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSAPITreeSet::DumpForSnapshot(std::vector &vec) const +void JSAPITreeSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetTreeSet().IsInvalidValue())) { - TaggedTreeSet *set = TaggedTreeSet::Cast(GetTreeSet().GetTaggedObject()); - vec.emplace_back("treeset", GetTreeSet()); - set->DumpForSnapshot(vec); + if (!(GetTreeSet(thread).IsInvalidValue())) { + TaggedTreeSet *set = TaggedTreeSet::Cast(GetTreeSet(thread).GetTaggedObject()); + vec.emplace_back("treeset", GetTreeSet(thread)); + set->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPITreeSetIterator::Dump(std::ostream &os) const +void JSAPITreeSetIterator::Dump(const JSThread *thread, std::ostream &os) const { TaggedTreeSet *set = - TaggedTreeSet::Cast(JSAPITreeSet::Cast(GetIteratedSet().GetTaggedObject())->GetTreeSet().GetTaggedObject()); + TaggedTreeSet::Cast(JSAPITreeSet::Cast(GetIteratedSet(thread).GetTaggedObject())-> + GetTreeSet(thread).GetTaggedObject()); os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSAPITreeSetIterator::DumpForSnapshot(std::vector &vec) const +void JSAPITreeSetIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedSet().IsInvalidValue())) { + if (!(GetIteratedSet(thread).IsInvalidValue())) { TaggedTreeSet *set = - TaggedTreeSet::Cast(JSAPITreeSet::Cast(GetIteratedSet().GetTaggedObject())->GetTreeSet().GetTaggedObject()); - vec.emplace_back("iteratedset", GetIteratedSet()); - set->DumpForSnapshot(vec); + TaggedTreeSet::Cast(JSAPITreeSet::Cast(GetIteratedSet(thread).GetTaggedObject())-> + GetTreeSet(thread).GetTaggedObject()); + vec.emplace_back("iteratedset", GetIteratedSet(thread)); + set->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void TaggedTreeSet::Dump(std::ostream &os) const +void TaggedTreeSet::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[Elements]: {"; - JSTaggedValue node = TaggedArray::Get(0); - node.DumpTaggedValue(os); + JSTaggedValue node = TaggedArray::Get(thread, 0); + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[Delete]: {"; - node = TaggedArray::Get(1); - node.DumpTaggedValue(os); + node = TaggedArray::Get(thread, 1); + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[Capacity]: {"; - node = TaggedArray::Get(2); // 2 means the three element - node.DumpTaggedValue(os); + node = TaggedArray::Get(thread, 2); // 2 means the three element + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[RootNode]: {"; - node = TaggedArray::Get(3); // 3 means the three element - node.DumpTaggedValue(os); + node = TaggedArray::Get(thread, 3); // 3 means the three element + node.DumpTaggedValue(thread, os); os << std::right << "}" << "\n"; uint32_t capacity = NumberOfElements() + NumberOfDeletedElements(); for (uint32_t index = 0; index < capacity; index++) { - if (GetKey(index).IsHole()) { + if (GetKey(thread, index).IsHole()) { os << std::left << std::setw(DUMP_ELEMENT_OFFSET) << "[entry] " << index << ": "; - GetKey(index).DumpTaggedValue(os); + GetKey(thread, index).DumpTaggedValue(thread, os); os << "\n"; } else { - DumpTaggedTreeEntry(const_cast(this), os, index); + DumpTaggedTreeEntry(thread, const_cast(this), os, index); } } } -void JSAPIPlainArray::Dump(std::ostream &os) const +void JSAPIPlainArray::Dump(const JSThread *thread, std::ostream &os) const { - TaggedArray *keys = TaggedArray::Cast(GetKeys().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *keys = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); uint32_t len = static_cast(GetLength()); for (uint32_t i = 0; i < len; i++) { os << " - keys: "; - keys->Get(i).DumpTaggedValue(os); + keys->Get(thread, i).DumpTaggedValue(thread, os); os << "\n"; os << " - values: "; - values->Get(i).DumpTaggedValue(os); + values->Get(thread, i).DumpTaggedValue(thread, os); os << "\n"; } os << " - length: " << std::dec << len << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIPlainArrayIterator::Dump(std::ostream &os) const +void JSAPIPlainArrayIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIPlainArray *array = JSAPIPlainArray::Cast(GetIteratedPlainArray().GetTaggedObject()); + JSAPIPlainArray *array = JSAPIPlainArray::Cast(GetIteratedPlainArray(thread).GetTaggedObject()); os << " - length: " << std::dec << array->GetSize() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIPlainArrayIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIPlainArrayIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedPlainArray().IsInvalidValue())) { - JSAPIPlainArray *array = JSAPIPlainArray::Cast(GetIteratedPlainArray().GetTaggedObject()); - vec.emplace_back("iteratedplainarray", GetIteratedPlainArray()); - array->DumpForSnapshot(vec); + if (!(GetIteratedPlainArray(thread).IsInvalidValue())) { + JSAPIPlainArray *array = JSAPIPlainArray::Cast(GetIteratedPlainArray(thread).GetTaggedObject()); + vec.emplace_back("iteratedplainarray", GetIteratedPlainArray(thread)); + array->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSForInIterator::Dump(std::ostream &os) const +void JSForInIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - Object : "; - GetObject().DumpTaggedValue(os); + GetObject(thread).DumpTaggedValue(thread, os); os << " - CachedHclass : "; - GetCachedHClass().DumpTaggedValue(os); + GetCachedHClass(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - Keys : "; - GetKeys().DumpTaggedValue(os); + GetKeys(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - Index : " << GetIndex(); os << "\n"; os << " - Length : " << GetLength(); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSMapIterator::Dump(std::ostream &os) const +void JSMapIterator::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashMap *map = LinkedHashMap::Cast(GetIteratedMap().GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(GetIteratedMap(thread).GetTaggedObject()); os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSSharedMapIterator::Dump(std::ostream &os) const +void JSSharedMapIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSSharedMap *iteratedMap = JSSharedMap::Cast(GetIteratedMap().GetTaggedObject()); - LinkedHashMap *map = LinkedHashMap::Cast(iteratedMap->GetLinkedMap().GetTaggedObject()); + JSSharedMap *iteratedMap = JSSharedMap::Cast(GetIteratedMap(thread).GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(iteratedMap->GetLinkedMap(thread).GetTaggedObject()); os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSSet::Dump(std::ostream &os) const +void JSSet::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject()); + LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject()); os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSSharedSet::Dump(std::ostream &os) const +void JSSharedSet::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject()); + LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject()); os << " - modRecord: " << std::dec << GetModRecord() << "\n"; os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSWeakMap::Dump(std::ostream &os) const +void JSWeakMap::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject()); - os << " - length: " << std::dec << GetSize() << "\n"; + LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject()); + os << " - length: " << std::dec << GetSize(thread) << "\n"; os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - map->Dump(os); + map->Dump(thread, os); } -void JSWeakSet::Dump(std::ostream &os) const +void JSWeakSet::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject()); - os << " - size: " << std::dec << GetSize() << "\n"; + LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject()); + os << " - size: " << std::dec << GetSize(thread) << "\n"; os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSWeakRef::Dump(std::ostream &os) const +void JSWeakRef::Dump(const JSThread *thread, std::ostream &os) const { os << " - WeakObject : "; - GetWeakObject().DumpTaggedValue(os); + GetWeakObject(thread).DumpTaggedValue(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSFinalizationRegistry::Dump(std::ostream &os) const +void JSFinalizationRegistry::Dump(const JSThread *thread, std::ostream &os) const { os << " - CleanupCallback : "; - GetCleanupCallback().DumpTaggedValue(os); + GetCleanupCallback(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - NoUnregister : "; - GetNoUnregister().Dump(os); + GetNoUnregister(thread).Dump(thread, os); os << "\n"; os << " - MaybeUnregister : "; - LinkedHashMap *map = LinkedHashMap::Cast(GetMaybeUnregister().GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(GetMaybeUnregister(thread).GetTaggedObject()); os << " - elements: " << std::dec << map->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << map->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << map->Capacity() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void CellRecord::Dump(std::ostream &os) const +void CellRecord::Dump(const JSThread *thread, std::ostream &os) const { os << " - WeakRefTarget : "; - GetFromWeakRefTarget().DumpTaggedValue(os); + GetFromWeakRefTarget(thread).DumpTaggedValue(thread, os); os << "\n"; os << " - HeldValue : "; - GetHeldValue().DumpTaggedValue(os); + GetHeldValue(thread).DumpTaggedValue(thread, os); os << "\n"; } -void JSSetIterator::Dump(std::ostream &os) const +void JSSetIterator::Dump(const JSThread *thread, std::ostream &os) const { - LinkedHashSet *set = LinkedHashSet::Cast(GetIteratedSet().GetTaggedObject()); + LinkedHashSet *set = LinkedHashSet::Cast(GetIteratedSet(thread).GetTaggedObject()); os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSSharedSetIterator::Dump(std::ostream &os) const +void JSSharedSetIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSSharedSet *iteratedSet = JSSharedSet::Cast(GetIteratedSet().GetTaggedObject()); - LinkedHashSet *set = LinkedHashSet::Cast(iteratedSet->GetLinkedSet().GetTaggedObject()); + JSSharedSet *iteratedSet = JSSharedSet::Cast(GetIteratedSet(thread).GetTaggedObject()); + LinkedHashSet *set = LinkedHashSet::Cast(iteratedSet->GetLinkedSet(thread).GetTaggedObject()); os << " - elements: " << std::dec << set->NumberOfElements() << "\n"; os << " - deleted-elements: " << std::dec << set->NumberOfDeletedElements() << "\n"; os << " - capacity: " << std::dec << set->Capacity() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); os << " NumberOfElements() << "]>\n"; - set->Dump(os); + set->Dump(thread, os); } -void JSRegExpIterator::Dump(std::ostream &os) const +void JSRegExpIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - IteratingRegExp: "; - GetIteratingRegExp().Dump(os); + GetIteratingRegExp(thread).Dump(thread, os); os << "\n"; os << " - IteratedString: "; - GetIteratedString().Dump(os); + GetIteratedString(thread).Dump(thread, os); os << "\n"; os << " - Global: " << std::dec << GetGlobal() << "\n"; os << " - Unicode: " << std::dec << GetUnicode() << "\n"; os << " - Done: " << std::dec << GetDone() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSArray::Dump(std::ostream &os) const +void JSArray::Dump(const JSThread *thread, std::ostream &os) const { os << " - length: " << std::dec << GetArrayLength() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSSharedArray::Dump(std::ostream &os) const +void JSSharedArray::Dump(const JSThread *thread, std::ostream &os) const { os << " - length: " << std::dec << GetArrayLength() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSArrayIterator::Dump(std::ostream &os) const +void JSArrayIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSArray *array = JSArray::Cast(GetIteratedArray().GetTaggedObject()); + JSArray *array = JSArray::Cast(GetIteratedArray(thread).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); + JSObject::Dump(thread, os); } -void JSSharedArrayIterator::Dump(std::ostream &os) const +void JSSharedArrayIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSSharedArray *array = JSSharedArray::Cast(GetIteratedArray().GetTaggedObject()); + JSSharedArray *array = JSSharedArray::Cast(GetIteratedArray(thread).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); + JSObject::Dump(thread, os); } -void JSAPIArrayList::Dump(std::ostream &os) const +void JSAPIArrayList::Dump(const JSThread *thread, std::ostream &os) const { os << " - length: " << std::dec << GetSize() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIArrayListIterator::Dump(std::ostream &os) const +void JSAPIArrayListIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIArrayList *arrayList = JSAPIArrayList::Cast(GetIteratedArrayList().GetTaggedObject()); + JSAPIArrayList *arrayList = JSAPIArrayList::Cast(GetIteratedArrayList(thread).GetTaggedObject()); os << " - length: " << std::dec << arrayList->GetSize() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIDeque::Dump(std::ostream &os) const +void JSAPIDeque::Dump(const JSThread *thread, std::ostream &os) const { os << " - first: " << std::dec << GetFirst() << "\n"; os << " - last: " << std::dec << GetLast() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIDequeIterator::Dump(std::ostream &os) const +void JSAPIDequeIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIDeque *deque = JSAPIDeque::Cast(GetIteratedDeque().GetTaggedObject()); - os << " - length: " << std::dec << deque->GetSize() << "\n"; + JSAPIDeque *deque = JSAPIDeque::Cast(GetIteratedDeque(thread).GetTaggedObject()); + os << " - length: " << std::dec << deque->GetSize(thread) << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPILightWeightMap::Dump(std::ostream &os) const +void JSAPILightWeightMap::Dump(const JSThread *thread, std::ostream &os) const { uint32_t capacity = GetSize(); os << " - length: " << std::dec << capacity << "\n"; uint32_t i = 0; - TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); - TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); - TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *hashArray = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + TaggedArray *valueArray = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); while (capacity > i) { os << " hash: "; - hashArray->Get(i).DumpTaggedValue(os); + hashArray->Get(thread, i).DumpTaggedValue(thread, os); os << " key: "; - keyArray->Get(i).DumpTaggedValue(os); + keyArray->Get(thread, i).DumpTaggedValue(thread, os); os << " value: "; - valueArray->Get(i).DumpTaggedValue(os); + valueArray->Get(thread, i).DumpTaggedValue(thread, os); os << "\n"; i++; } - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPILightWeightMapIterator::Dump(std::ostream &os) const +void JSAPILightWeightMapIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIHashMap::Dump(std::ostream &os) const +void JSAPIHashMap::Dump(const JSThread *thread, std::ostream &os) const { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); os << " - elements: " << std::dec << GetSize() << "\n"; os << " - table capacity: " << std::dec << static_cast(hashArray->GetLength()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIHashMap::DumpForSnapshot(std::vector &vec) const +void JSAPIHashMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetTable().IsInvalidValue())) { - TaggedHashArray *map = TaggedHashArray::Cast(GetTable().GetTaggedObject()); - vec.emplace_back("hashmap", GetTable()); - map->DumpForSnapshot(vec); + if (!(GetTable(thread).IsInvalidValue())) { + TaggedHashArray *map = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); + vec.emplace_back("hashmap", GetTable(thread)); + map->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIHashSet::Dump(std::ostream &os) const +void JSAPIHashSet::Dump(const JSThread *thread, std::ostream &os) const { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); os << " - elements: " << std::dec << GetSize() << "\n"; os << " - table capacity: " << std::dec << static_cast(hashArray->GetLength()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIHashSet::DumpForSnapshot(std::vector &vec) const +void JSAPIHashSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetTable().IsInvalidValue())) { - TaggedHashArray *set = TaggedHashArray::Cast(GetTable().GetTaggedObject()); - vec.emplace_back("hashset", GetTable()); - set->DumpForSnapshot(vec); + if (!(GetTable(thread).IsInvalidValue())) { + TaggedHashArray *set = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); + vec.emplace_back("hashset", GetTable(thread)); + set->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIHashMapIterator::Dump(std::ostream &os) const +void JSAPIHashMapIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIHashMapIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIHashMapIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("IteratedHashMap"), JSTaggedValue(GetIteratedHashMap())); - vec.emplace_back(CString("TaggedQueue"), JSTaggedValue(GetTaggedQueue())); - vec.emplace_back(CString("CurrentNodeResult"), JSTaggedValue(GetCurrentNodeResult())); + vec.emplace_back(CString("IteratedHashMap"), JSTaggedValue(GetIteratedHashMap(thread))); + vec.emplace_back(CString("TaggedQueue"), JSTaggedValue(GetTaggedQueue(thread))); + vec.emplace_back(CString("CurrentNodeResult"), JSTaggedValue(GetCurrentNodeResult(thread))); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIHashSetIterator::Dump(std::ostream &os) const +void JSAPIHashSetIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIHashSetIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIHashSetIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILightWeightSet::Dump(std::ostream &os) const +void JSAPILightWeightSet::Dump(const JSThread *thread, std::ostream &os) const { - TaggedArray *keys = TaggedArray::Cast(GetHashes().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *keys = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); uint32_t len = GetLength(); for (uint32_t i = 0; i < len; i++) { os << " - keys: "; - keys->Get(i).DumpTaggedValue(os); + keys->Get(thread, i).DumpTaggedValue(thread, os); os << "\n"; os << " - values: "; - values->Get(i).DumpTaggedValue(os); + values->Get(thread, i).DumpTaggedValue(thread, os); os << "\n"; } os << " - length: " << std::dec << len << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPILightWeightSetIterator::Dump(std::ostream &os) const +void JSAPILightWeightSetIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIList::Dump(std::ostream &os) const +void JSAPIList::Dump(const JSThread *thread, std::ostream &os) const { - TaggedSingleList *list = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); + TaggedSingleList *list = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); os << " - length: " << std::dec << list->GetCapacityFromTaggedArray() << "\n"; os << " - node num: " << std::dec << list->NumberOfNodes() << "\n"; os << " - delete node num: " << std::dec << list->NumberOfDeletedNodes() << "\n"; os << " - is odered list: " << std::dec << this->IsOrderedList() << "\n"; - JSObject::Dump(os); - list->Dump(os); + JSObject::Dump(thread, os); + list->Dump(thread, os); } -void JSAPIList::DumpForSnapshot(std::vector &vec) const +void JSAPIList::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetSingleList().IsInvalidValue())) { - TaggedSingleList *list = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); - vec.emplace_back("singleList", GetSingleList()); - list->DumpForSnapshot(vec); + if (!(GetSingleList(thread).IsInvalidValue())) { + TaggedSingleList *list = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); + vec.emplace_back("singleList", GetSingleList(thread)); + list->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIListIterator::Dump(std::ostream &os) const +void JSAPIListIterator::Dump(const JSThread *thread, std::ostream &os) const { - TaggedSingleList *list = TaggedSingleList::Cast(GetIteratedList().GetTaggedObject()); + TaggedSingleList *list = TaggedSingleList::Cast(GetIteratedList(thread).GetTaggedObject()); os << " - length: " << std::dec << list->GetCapacityFromTaggedArray() << "\n"; os << " - node num: " << std::dec << list->NumberOfNodes() << "\n"; os << " - delete node num: " << std::dec << list->NumberOfDeletedNodes() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); - list->Dump(os); + JSObject::Dump(thread, os); + list->Dump(thread, os); } -void JSAPIListIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIListIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedList().IsInvalidValue())) { - TaggedSingleList *list = TaggedSingleList::Cast(GetIteratedList().GetTaggedObject()); - vec.emplace_back("iteratedlist", GetIteratedList()); - list->DumpForSnapshot(vec); + if (!(GetIteratedList(thread).IsInvalidValue())) { + TaggedSingleList *list = TaggedSingleList::Cast(GetIteratedList(thread).GetTaggedObject()); + vec.emplace_back("iteratedlist", GetIteratedList(thread)); + list->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILinkedList::Dump(std::ostream &os) const +void JSAPILinkedList::Dump(const JSThread *thread, std::ostream &os) const { - TaggedDoubleList *linkedList = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject()); + TaggedDoubleList *linkedList = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject()); os << " - length: " << std::dec << linkedList->GetCapacityFromTaggedArray() << "\n"; os << " - node num: " << std::dec << linkedList->NumberOfNodes() << "\n"; os << " - delete node num: " << std::dec << linkedList->NumberOfDeletedNodes() << "\n"; - JSObject::Dump(os); - linkedList->Dump(os); + JSObject::Dump(thread, os); + linkedList->Dump(thread, os); } -void JSAPILinkedList::DumpForSnapshot(std::vector &vec) const +void JSAPILinkedList::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetDoubleList().IsInvalidValue())) { - TaggedDoubleList *list = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject()); - vec.emplace_back("doubleList", GetDoubleList()); - list->DumpForSnapshot(vec); + if (!(GetDoubleList(thread).IsInvalidValue())) { + TaggedDoubleList *list = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject()); + vec.emplace_back("doubleList", GetDoubleList(thread)); + list->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILinkedListIterator::Dump(std::ostream &os) const +void JSAPILinkedListIterator::Dump(const JSThread *thread, std::ostream &os) const { - TaggedDoubleList *linkedList = TaggedDoubleList::Cast(GetIteratedLinkedList().GetTaggedObject()); + TaggedDoubleList *linkedList = TaggedDoubleList::Cast(GetIteratedLinkedList(thread).GetTaggedObject()); os << " - length: " << std::dec << linkedList->GetCapacityFromTaggedArray() << "\n"; os << " - node num: " << std::dec << linkedList->NumberOfNodes() << "\n"; os << " - delete node num: " << std::dec << linkedList->NumberOfDeletedNodes() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); - linkedList->Dump(os); + JSObject::Dump(thread, os); + linkedList->Dump(thread, os); } -void JSAPILinkedListIterator::DumpForSnapshot(std::vector &vec) const +void JSAPILinkedListIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedLinkedList().IsInvalidValue())) { - TaggedDoubleList *linkedList = TaggedDoubleList::Cast(GetIteratedLinkedList().GetTaggedObject()); - vec.emplace_back("iteratedlist", GetIteratedLinkedList()); - linkedList->DumpForSnapshot(vec); + if (!(GetIteratedLinkedList(thread).IsInvalidValue())) { + TaggedDoubleList *linkedList = TaggedDoubleList::Cast(GetIteratedLinkedList(thread).GetTaggedObject()); + vec.emplace_back("iteratedlist", GetIteratedLinkedList(thread)); + linkedList->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIQueue::Dump(std::ostream &os) const +void JSAPIQueue::Dump(const JSThread *thread, std::ostream &os) const { - os << " - length: " << std::dec << GetSize() << "\n"; + os << " - length: " << std::dec << GetSize(thread) << "\n"; os << " - front: " << std::dec << GetFront() << "\n"; os << " - tail: " << std::dec << GetTail() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIQueueIterator::Dump(std::ostream &os) const +void JSAPIQueueIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIQueue *queue = JSAPIQueue::Cast(GetIteratedQueue().GetTaggedObject()); - os << " - length: " << std::dec << queue->GetSize() << "\n"; + JSAPIQueue *queue = JSAPIQueue::Cast(GetIteratedQueue(thread).GetTaggedObject()); + os << " - length: " << std::dec << queue->GetSize(thread) << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIStack::Dump(std::ostream &os) const +void JSAPIStack::Dump(const JSThread *thread, std::ostream &os) const { os << " - top: " << std::dec << GetTop() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIStackIterator::Dump(std::ostream &os) const +void JSAPIStackIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIStack *stack = JSAPIStack::Cast(GetIteratedStack().GetTaggedObject()); + JSAPIStack *stack = JSAPIStack::Cast(GetIteratedStack(thread).GetTaggedObject()); os << " - length: " << std::dec << stack->GetSize() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIVector::Dump(std::ostream &os) const +void JSAPIVector::Dump(const JSThread *thread, std::ostream &os) const { os << " - length: " << std::dec << GetSize() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIVectorIterator::Dump(std::ostream &os) const +void JSAPIVectorIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIVector *vector = JSAPIVector::Cast(GetIteratedVector().GetTaggedObject()); + JSAPIVector *vector = JSAPIVector::Cast(GetIteratedVector(thread).GetTaggedObject()); os << " - length: " << std::dec << vector->GetSize() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIBitVector::Dump(std::ostream &os) const +void JSAPIBitVector::Dump(const JSThread *thread, std::ostream &os) const { os << " - length: " << std::dec << GetSize() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIBitVectorIterator::Dump(std::ostream &os) const +void JSAPIBitVectorIterator::Dump(const JSThread *thread, std::ostream &os) const { - JSAPIBitVector *bitVector = JSAPIBitVector::Cast(GetIteratedBitVector().GetTaggedObject()); + JSAPIBitVector *bitVector = JSAPIBitVector::Cast(GetIteratedBitVector(thread).GetTaggedObject()); os << " - length: " << std::dec << bitVector->GetSize() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAPIFastBuffer::Dump(std::ostream &os) const +void JSAPIFastBuffer::Dump(const JSThread *thread, std::ostream &os) const { os << " - ByteLength: " << std::dec << GetSize() << "\n"; os << " - Length: " << std::dec << GetLength() << "\n"; - auto array = JSTypedArray::Cast(GetFastBufferData().GetTaggedObject()); - array->Dump(os); - JSObject::Dump(os); + auto array = JSTypedArray::Cast(GetFastBufferData(thread).GetTaggedObject()); + array->Dump(thread, os); + JSObject::Dump(thread, os); } -void JSStringIterator::Dump(std::ostream &os) const +void JSStringIterator::Dump(const JSThread *thread, std::ostream &os) const { - EcmaString *str = EcmaString::Cast(GetIteratedString().GetTaggedObject()); - os << " - IteratedString: " << EcmaStringAccessor(str).ToCString() << "\n"; + EcmaString *str = EcmaString::Cast(GetIteratedString(thread).GetTaggedObject()); + os << " - IteratedString: " << EcmaStringAccessor(str).ToCString(thread) << "\n"; os << " - StringIteratorNextIndex: " << std::dec << GetStringIteratorNextIndex() << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSTypedArray::Dump(std::ostream &os) const +void JSTypedArray::Dump(const JSThread *thread, std::ostream &os) const { os << " - viewed-array-buffer: "; - GetViewedArrayBufferOrByteArray().Dump(os); + GetViewedArrayBufferOrByteArray(thread).Dump(thread, os); os << " - typed-array-name: "; - GetTypedArrayName().Dump(os); + GetTypedArrayName(thread).Dump(thread, os); os << " - byte-length: " << GetByteLength(); os << " - byte-offset: " << GetByteOffset(); os << " - array-length: " << GetArrayLength(); - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSSharedTypedArray::Dump(std::ostream &os) const +void JSSharedTypedArray::Dump(const JSThread *thread, std::ostream &os) const { os << " - viewed-array-buffer: "; - GetViewedArrayBufferOrByteArray().Dump(os); + GetViewedArrayBufferOrByteArray(thread).Dump(thread, os); os << " - typed-array-name: "; - GetTypedArrayName().Dump(os); + GetTypedArrayName(thread).Dump(thread, os); os << " - byte-length: " << GetByteLength(); os << " - byte-offset: " << GetByteOffset(); os << " - array-length: " << GetArrayLength(); - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void ByteArray::Dump(std::ostream &os) const +void ByteArray::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - array-length: " << GetArrayLength(); os << " - byte-length: " << GetByteLength(); } -void JSRegExp::Dump(std::ostream &os) const +void JSRegExp::Dump(const JSThread *thread, std::ostream &os) const { os << "\n"; os << " - ByteCodeBuffer: "; - GetByteCodeBuffer().Dump(os); + GetByteCodeBuffer(thread).Dump(thread, os); os << "\n"; os << " - OriginalSource: "; - GetOriginalSource().Dump(os); + GetOriginalSource(thread).Dump(thread, os); os << "\n"; os << " - OriginalFlags: "; - GetOriginalFlags().Dump(os); + GetOriginalFlags(thread).Dump(thread, os); os << "\n"; os << " - GroupName: "; - GetGroupName().Dump(os); + GetGroupName(thread).Dump(thread, os); os << "\n"; os << " - Length: " << GetLength(); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSProxy::Dump(std::ostream &os) const +void JSProxy::Dump(const JSThread *thread, std::ostream &os) const { os << " - Target: "; os << "\n"; - JSObject::Cast(GetTarget().GetTaggedObject())->Dump(os); + JSObject::Cast(GetTarget(thread).GetTaggedObject())->Dump(thread, os); os << " - Handler: "; os << "\n"; - JSObject::Cast(GetHandler().GetTaggedObject())->Dump(os); + JSObject::Cast(GetHandler(thread).GetTaggedObject())->Dump(thread, os); os << "\n"; } -void JSSymbol::Dump(std::ostream &os) const +void JSSymbol::Dump(const JSThread *thread, std::ostream &os) const { os << " - hash-field: " << GetHashField(); os << "\n - flags: " << GetFlags(); os << "\n - description: "; - JSTaggedValue description = GetDescription(); - description.Dump(os); + JSTaggedValue description = GetDescription(thread); + description.Dump(thread, os); } -void LexicalEnv::Dump(std::ostream &os) const +void LexicalEnv::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void SFunctionEnv::Dump(std::ostream &os) const +void SFunctionEnv::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void SendableEnv::Dump(std::ostream &os) const +void SendableEnv::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void COWTaggedArray::Dump(std::ostream &os) const +void COWTaggedArray::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void MutantTaggedArray::Dump(std::ostream &os) const +void MutantTaggedArray::Dump(const JSThread *thread, std::ostream &os) const { - DumpMutantTaggedArray(this, os); + DumpMutantTaggedArray(thread, this, os); } -void COWMutantTaggedArray::Dump(std::ostream &os) const +void COWMutantTaggedArray::Dump(const JSThread *thread, std::ostream &os) const { - DumpCOWMutantTaggedArray(this, os); + DumpCOWMutantTaggedArray(thread, this, os); } // NOLINTNEXTLINE(readability-function-size) -void GlobalEnv::Dump(std::ostream &os) const +void GlobalEnv::Dump(const JSThread *thread, std::ostream &os) const { auto globalConst = GetJSThread()->GlobalConstants(); os << " - ObjectFunction: "; - GetObjectFunction().GetTaggedValue().Dump(os); + GetObjectFunction().GetTaggedValue().Dump(thread, os); os << " - FunctionFunction: "; - GetFunctionFunction().GetTaggedValue().Dump(os); + GetFunctionFunction().GetTaggedValue().Dump(thread, os); os << " - NumberFunction: "; - GetNumberFunction().GetTaggedValue().Dump(os); + GetNumberFunction().GetTaggedValue().Dump(thread, os); os << " - BigIntFunction: "; - GetBigIntFunction().GetTaggedValue().Dump(os); + GetBigIntFunction().GetTaggedValue().Dump(thread, os); os << " - DateFunction: "; - GetDateFunction().GetTaggedValue().Dump(os); + GetDateFunction().GetTaggedValue().Dump(thread, os); os << " - BooleanFunction: "; - GetBooleanFunction().GetTaggedValue().Dump(os); + GetBooleanFunction().GetTaggedValue().Dump(thread, os); os << " - ErrorFunction: "; - GetErrorFunction().GetTaggedValue().Dump(os); + GetErrorFunction().GetTaggedValue().Dump(thread, os); os << " - ArrayFunction: "; - GetArrayFunction().GetTaggedValue().Dump(os); + GetArrayFunction().GetTaggedValue().Dump(thread, os); os << " - TypedArrayFunction: "; - GetTypedArrayFunction().GetTaggedValue().Dump(os); + GetTypedArrayFunction().GetTaggedValue().Dump(thread, os); os << " - Int8ArrayFunction: "; - GetInt8ArrayFunction().GetTaggedValue().Dump(os); + GetInt8ArrayFunction().GetTaggedValue().Dump(thread, os); os << " - Uint8ArrayFunction: "; - GetUint8ArrayFunction().GetTaggedValue().Dump(os); + GetUint8ArrayFunction().GetTaggedValue().Dump(thread, os); os << " - Uint8ClampedArrayFunction: "; - GetUint8ClampedArrayFunction().GetTaggedValue().Dump(os); + GetUint8ClampedArrayFunction().GetTaggedValue().Dump(thread, os); os << " - Int16ArrayFunction: "; - GetInt16ArrayFunction().GetTaggedValue().Dump(os); + GetInt16ArrayFunction().GetTaggedValue().Dump(thread, os); os << " - ArrayBufferFunction: "; - GetArrayBufferFunction().GetTaggedValue().Dump(os); + GetArrayBufferFunction().GetTaggedValue().Dump(thread, os); os << " - SharedArrayBufferFunction: "; - GetSharedArrayBufferFunction().GetTaggedValue().Dump(os); + GetSharedArrayBufferFunction().GetTaggedValue().Dump(thread, os); os << " - SymbolFunction: "; - GetSymbolFunction().GetTaggedValue().Dump(os); + GetSymbolFunction().GetTaggedValue().Dump(thread, os); os << " - RangeErrorFunction: "; - GetRangeErrorFunction().GetTaggedValue().Dump(os); + GetRangeErrorFunction().GetTaggedValue().Dump(thread, os); os << " - ReferenceErrorFunction: "; - GetReferenceErrorFunction().GetTaggedValue().Dump(os); + GetReferenceErrorFunction().GetTaggedValue().Dump(thread, os); os << " - TypeErrorFunction: "; - GetTypeErrorFunction().GetTaggedValue().Dump(os); + GetTypeErrorFunction().GetTaggedValue().Dump(thread, os); os << " - AggregateErrorFunction: "; - GetAggregateErrorFunction().GetTaggedValue().Dump(os); + GetAggregateErrorFunction().GetTaggedValue().Dump(thread, os); os << " - URIErrorFunction: "; - GetURIErrorFunction().GetTaggedValue().Dump(os); + GetURIErrorFunction().GetTaggedValue().Dump(thread, os); os << " - SyntaxErrorFunction: "; - GetSyntaxErrorFunction().GetTaggedValue().Dump(os); + GetSyntaxErrorFunction().GetTaggedValue().Dump(thread, os); os << " - EvalErrorFunction: "; - GetEvalErrorFunction().GetTaggedValue().Dump(os); + GetEvalErrorFunction().GetTaggedValue().Dump(thread, os); os << " - OOMErrorFunction: "; - GetOOMErrorFunction().GetTaggedValue().Dump(os); + GetOOMErrorFunction().GetTaggedValue().Dump(thread, os); os << " - TerminationErrorFunction: "; - GetTerminationErrorFunction().GetTaggedValue().Dump(os); + GetTerminationErrorFunction().GetTaggedValue().Dump(thread, os); os << " - RegExpFunction: "; - GetRegExpFunction().GetTaggedValue().Dump(os); + GetRegExpFunction().GetTaggedValue().Dump(thread, os); os << " - BuiltinsSetFunction: "; - GetBuiltinsSetFunction().GetTaggedValue().Dump(os); + GetBuiltinsSetFunction().GetTaggedValue().Dump(thread, os); os << " - BuiltinsMapFunction: "; - GetBuiltinsMapFunction().GetTaggedValue().Dump(os); + GetBuiltinsMapFunction().GetTaggedValue().Dump(thread, os); os << " - BuiltinsWeakSetFunction: "; - GetBuiltinsWeakSetFunction().GetTaggedValue().Dump(os); + GetBuiltinsWeakSetFunction().GetTaggedValue().Dump(thread, os); os << " - BuiltinsWeakMapFunction: "; - GetBuiltinsWeakMapFunction().GetTaggedValue().Dump(os); + GetBuiltinsWeakMapFunction().GetTaggedValue().Dump(thread, os); os << " - BuiltinsWeakRefFunction: "; - GetBuiltinsWeakRefFunction().GetTaggedValue().Dump(os); + GetBuiltinsWeakRefFunction().GetTaggedValue().Dump(thread, os); os << " - BuiltinsFinalizationRegistryFunction: "; - GetBuiltinsFinalizationRegistryFunction().GetTaggedValue().Dump(os); + GetBuiltinsFinalizationRegistryFunction().GetTaggedValue().Dump(thread, os); os << " - MathFunction: "; - GetMathFunction().GetTaggedValue().Dump(os); + GetMathFunction().GetTaggedValue().Dump(thread, os); os << " - AtomicsFunction: "; - GetAtomicsFunction().GetTaggedValue().Dump(os); + GetAtomicsFunction().GetTaggedValue().Dump(thread, os); os << " - JsonFunction: "; - GetJsonFunction().GetTaggedValue().Dump(os); + GetJsonFunction().GetTaggedValue().Dump(thread, os); os << " - StringFunction: "; - GetStringFunction().GetTaggedValue().Dump(os); + GetStringFunction().GetTaggedValue().Dump(thread, os); os << " - ProxyFunction: "; - GetProxyFunction().GetTaggedValue().Dump(os); + GetProxyFunction().GetTaggedValue().Dump(thread, os); os << " - ReflectFunction: "; - GetReflectFunction().GetTaggedValue().Dump(os); + GetReflectFunction().GetTaggedValue().Dump(thread, os); os << " - AsyncFunction: "; - GetAsyncFunction().GetTaggedValue().Dump(os); + GetAsyncFunction().GetTaggedValue().Dump(thread, os); os << " - AsyncFunctionPrototype: "; - GetAsyncFunctionPrototype().GetTaggedValue().Dump(os); + GetAsyncFunctionPrototype().GetTaggedValue().Dump(thread, os); os << " - JSGlobalObject: "; - GetJSGlobalObject().GetTaggedValue().Dump(os); + GetJSGlobalObject().GetTaggedValue().Dump(thread, os); os << " - GlobalPatch: "; - GetGlobalPatch().GetTaggedValue().Dump(os); + GetGlobalPatch().GetTaggedValue().Dump(thread, os); os << " - EmptyArray: "; - globalConst->GetEmptyArray().Dump(os); + globalConst->GetEmptyArray().Dump(thread, os); os << " - EmptyString "; - globalConst->GetEmptyString().Dump(os); + globalConst->GetEmptyString().Dump(thread, os); os << " - EmptyTaggedQueue: "; - globalConst->GetEmptyTaggedQueue().Dump(os); + globalConst->GetEmptyTaggedQueue().Dump(thread, os); os << " - EmptyProfileTypeInfoCell: "; - globalConst->GetEmptyProfileTypeInfoCell().Dump(os); + globalConst->GetEmptyProfileTypeInfoCell().Dump(thread, os); os << " - PrototypeString: "; - globalConst->GetPrototypeString().Dump(os); + globalConst->GetPrototypeString().Dump(thread, os); os << " - HasInstanceSymbol: "; - GetHasInstanceSymbol().GetTaggedValue().Dump(os); + GetHasInstanceSymbol().GetTaggedValue().Dump(thread, os); os << " - IsConcatSpreadableSymbol: "; - GetIsConcatSpreadableSymbol().GetTaggedValue().Dump(os); + GetIsConcatSpreadableSymbol().GetTaggedValue().Dump(thread, os); os << " - ToStringTagSymbol: "; - GetToStringTagSymbol().GetTaggedValue().Dump(os); + GetToStringTagSymbol().GetTaggedValue().Dump(thread, os); os << " - IteratorSymbol: "; - GetIteratorSymbol().GetTaggedValue().Dump(os); + GetIteratorSymbol().GetTaggedValue().Dump(thread, os); os << " - AsyncIteratorSymbol: "; - GetAsyncIteratorSymbol().GetTaggedValue().Dump(os); + GetAsyncIteratorSymbol().GetTaggedValue().Dump(thread, os); os << " - MatchSymbol: "; - GetMatchSymbol().GetTaggedValue().Dump(os); + GetMatchSymbol().GetTaggedValue().Dump(thread, os); os << " - MatchAllSymbol: "; - GetMatchAllSymbol().GetTaggedValue().Dump(os); + GetMatchAllSymbol().GetTaggedValue().Dump(thread, os); os << " - ReplaceSymbol: "; - GetReplaceSymbol().GetTaggedValue().Dump(os); + GetReplaceSymbol().GetTaggedValue().Dump(thread, os); os << " - SearchSymbol: "; - GetSearchSymbol().GetTaggedValue().Dump(os); + GetSearchSymbol().GetTaggedValue().Dump(thread, os); os << " - SpeciesSymbol: "; - GetSpeciesSymbol().GetTaggedValue().Dump(os); + GetSpeciesSymbol().GetTaggedValue().Dump(thread, os); os << " - SplitSymbol: "; - GetSplitSymbol().GetTaggedValue().Dump(os); + GetSplitSymbol().GetTaggedValue().Dump(thread, os); os << " - ToPrimitiveSymbol: "; - GetToPrimitiveSymbol().GetTaggedValue().Dump(os); + GetToPrimitiveSymbol().GetTaggedValue().Dump(thread, os); os << " - UnscopablesSymbol: "; - GetUnscopablesSymbol().GetTaggedValue().Dump(os); + GetUnscopablesSymbol().GetTaggedValue().Dump(thread, os); os << " - HoleySymbol: "; - GetHoleySymbol().GetTaggedValue().Dump(os); + GetHoleySymbol().GetTaggedValue().Dump(thread, os); os << " - NativeBindingSymbol: "; - GetNativeBindingSymbol().GetTaggedValue().Dump(os); + GetNativeBindingSymbol().GetTaggedValue().Dump(thread, os); os << " - ConstructorString: "; - globalConst->GetConstructorString().Dump(os); + globalConst->GetConstructorString().Dump(thread, os); os << " - IteratorPrototype: "; - GetIteratorPrototype().GetTaggedValue().Dump(os); + GetIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - ForinIteratorPrototype: "; - GetForinIteratorPrototype().GetTaggedValue().Dump(os); + GetForinIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - StringIterator: "; - GetStringIterator().GetTaggedValue().Dump(os); + GetStringIterator().GetTaggedValue().Dump(thread, os); os << " - MapIteratorPrototype: "; - GetMapIteratorPrototype().GetTaggedValue().Dump(os); + GetMapIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - SetIteratorPrototype: "; - GetSetIteratorPrototype().GetTaggedValue().Dump(os); + GetSetIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - RegExpIteratorPrototype: "; - GetRegExpIteratorPrototype().GetTaggedValue().Dump(os); + GetRegExpIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - ArrayIteratorPrototype: "; - GetArrayIteratorPrototype().GetTaggedValue().Dump(os); + GetArrayIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - StringIteratorPrototype: "; - GetStringIteratorPrototype().GetTaggedValue().Dump(os); + GetStringIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - LengthString: "; - globalConst->GetLengthString().Dump(os); + globalConst->GetLengthString().Dump(thread, os); os << " - ValueString: "; - globalConst->GetValueString().Dump(os); + globalConst->GetValueString().Dump(thread, os); os << " - WritableString: "; - globalConst->GetWritableString().Dump(os); + globalConst->GetWritableString().Dump(thread, os); os << " - GetString: "; - globalConst->GetGetString().Dump(os); + globalConst->GetGetString().Dump(thread, os); os << " - SetString: "; - globalConst->GetSetString().Dump(os); + globalConst->GetSetString().Dump(thread, os); os << " - EnumerableString: "; - globalConst->GetEnumerableString().Dump(os); + globalConst->GetEnumerableString().Dump(thread, os); os << " - ConfigurableString: "; - globalConst->GetConfigurableString().Dump(os); + globalConst->GetConfigurableString().Dump(thread, os); os << " - NameString: "; - globalConst->GetNameString().Dump(os); + globalConst->GetNameString().Dump(thread, os); os << " - ValueOfString: "; - globalConst->GetValueOfString().Dump(os); + globalConst->GetValueOfString().Dump(thread, os); os << " - ToStringString: "; - globalConst->GetToStringString().Dump(os); + globalConst->GetToStringString().Dump(thread, os); os << " - ToLocaleStringString: "; - globalConst->GetToLocaleStringString().Dump(os); + globalConst->GetToLocaleStringString().Dump(thread, os); os << " - UndefinedString: "; - globalConst->GetUndefinedString().Dump(os); + globalConst->GetUndefinedString().Dump(thread, os); os << " - NullString: "; - globalConst->GetNullString().Dump(os); + globalConst->GetNullString().Dump(thread, os); os << " - TrueString: "; - globalConst->GetTrueString().Dump(os); + globalConst->GetTrueString().Dump(thread, os); os << " - FalseString: "; - globalConst->GetFalseString().Dump(os); + globalConst->GetFalseString().Dump(thread, os); os << " - RegisterSymbols: "; - GetRegisterSymbols().GetTaggedValue().Dump(os); + GetRegisterSymbols().GetTaggedValue().Dump(thread, os); os << " - ThrowTypeError: "; - GetThrowTypeError().GetTaggedValue().Dump(os); + GetThrowTypeError().GetTaggedValue().Dump(thread, os); os << " - GetPrototypeOfString: "; - globalConst->GetGetPrototypeOfString().Dump(os); + globalConst->GetGetPrototypeOfString().Dump(thread, os); os << " - SetPrototypeOfString: "; - globalConst->GetSetPrototypeOfString().Dump(os); + globalConst->GetSetPrototypeOfString().Dump(thread, os); os << " - IsExtensibleString: "; - globalConst->GetIsExtensibleString().Dump(os); + globalConst->GetIsExtensibleString().Dump(thread, os); os << " - PreventExtensionsString: "; - globalConst->GetPreventExtensionsString().Dump(os); + globalConst->GetPreventExtensionsString().Dump(thread, os); os << " - GetOwnPropertyDescriptorString: "; - globalConst->GetGetOwnPropertyDescriptorString().Dump(os); + globalConst->GetGetOwnPropertyDescriptorString().Dump(thread, os); os << " - DefinePropertyString: "; - globalConst->GetDefinePropertyString().Dump(os); + globalConst->GetDefinePropertyString().Dump(thread, os); os << " - HasString: "; - globalConst->GetHasString().Dump(os); + globalConst->GetHasString().Dump(thread, os); os << " - DeletePropertyString: "; - globalConst->GetDeletePropertyString().Dump(os); + globalConst->GetDeletePropertyString().Dump(thread, os); os << " - EnumerateString: "; - globalConst->GetEnumerateString().Dump(os); + globalConst->GetEnumerateString().Dump(thread, os); os << " - OwnKeysString: "; - globalConst->GetOwnKeysString().Dump(os); + globalConst->GetOwnKeysString().Dump(thread, os); os << " - ApplyString: "; - globalConst->GetApplyString().Dump(os); + globalConst->GetApplyString().Dump(thread, os); os << " - ProxyString: "; - globalConst->GetProxyString().Dump(os); + globalConst->GetProxyString().Dump(thread, os); os << " - RevokeString: "; - globalConst->GetRevokeString().Dump(os); + globalConst->GetRevokeString().Dump(thread, os); os << " - ProxyConstructString: "; - globalConst->GetProxyConstructString().Dump(os); + globalConst->GetProxyConstructString().Dump(thread, os); os << " - ProxyCallString: "; - globalConst->GetProxyCallString().Dump(os); + globalConst->GetProxyCallString().Dump(thread, os); os << " - DoneString: "; - globalConst->GetDoneString().Dump(os); + globalConst->GetDoneString().Dump(thread, os); os << " - NegativeZeroString: "; - globalConst->GetNegativeZeroString().Dump(os); + globalConst->GetNegativeZeroString().Dump(thread, os); os << " - NextString: "; - globalConst->GetNextString().Dump(os); + globalConst->GetNextString().Dump(thread, os); os << " - PromiseThenString: "; - globalConst->GetPromiseThenString().Dump(os); + globalConst->GetPromiseThenString().Dump(thread, os); os << " - PromiseFunction: "; - GetPromiseFunction().GetTaggedValue().Dump(os); + GetPromiseFunction().GetTaggedValue().Dump(thread, os); os << " - PromiseReactionJob: "; - GetPromiseReactionJob().GetTaggedValue().Dump(os); + GetPromiseReactionJob().GetTaggedValue().Dump(thread, os); os << " - PromiseResolveThenableJob: "; - GetPromiseResolveThenableJob().GetTaggedValue().Dump(os); + GetPromiseResolveThenableJob().GetTaggedValue().Dump(thread, os); os << " - DynamicImportJob: "; - GetDynamicImportJob().GetTaggedValue().Dump(os); + GetDynamicImportJob().GetTaggedValue().Dump(thread, os); os << " - ScriptJobString: "; - globalConst->GetScriptJobString().Dump(os); + globalConst->GetScriptJobString().Dump(thread, os); os << " - PromiseString: "; - globalConst->GetPromiseString().Dump(os); + globalConst->GetPromiseString().Dump(thread, os); os << " - IdentityString: "; - globalConst->GetIdentityString().Dump(os); + globalConst->GetIdentityString().Dump(thread, os); os << " - AsyncFunctionString: "; - globalConst->GetAsyncFunctionString().Dump(os); + globalConst->GetAsyncFunctionString().Dump(thread, os); os << " - ThrowerString: "; - globalConst->GetThrowerString().Dump(os); + globalConst->GetThrowerString().Dump(thread, os); os << " - Undefined: "; - globalConst->GetUndefined().Dump(os); + globalConst->GetUndefined().Dump(thread, os); } -void JSDataView::Dump(std::ostream &os) const +void JSDataView::Dump(const JSThread *thread, std::ostream &os) const { os << " - data-view: "; - GetDataView().Dump(os); + GetDataView(thread).Dump(thread, os); os << " - buffer: "; - GetViewedArrayBuffer().Dump(os); + GetViewedArrayBuffer(thread).Dump(thread, os); os << "- byte-length: " << GetByteLength(); os << "\n - byte-offset: " << GetByteOffset(); } -void JSArrayBuffer::Dump(std::ostream &os) const +void JSArrayBuffer::Dump(const JSThread *thread, std::ostream &os) const { os << " - byte-length: " << GetArrayBufferByteLength(); os << " - buffer-data: "; - GetArrayBufferData().Dump(os); + GetArrayBufferData(thread).Dump(thread, os); os << " - Shared: " << GetShared(); } -void JSSendableArrayBuffer::Dump(std::ostream &os) const +void JSSendableArrayBuffer::Dump(const JSThread *thread, std::ostream &os) const { os << " - byte-length: " << GetArrayBufferByteLength(); os << " - buffer-data: "; - GetArrayBufferData().Dump(os); + GetArrayBufferData(thread).Dump(thread, os); os << " - Shared: " << GetShared(); } -void PromiseReaction::Dump(std::ostream &os) const +void PromiseReaction::Dump(const JSThread *thread, std::ostream &os) const { os << " - promise-capability: "; - GetPromiseCapability().Dump(os); + GetPromiseCapability(thread).Dump(thread, os); os << " - type: " << static_cast(GetType()); os << " - handler: "; - GetHandler().Dump(os); + GetHandler(thread).Dump(thread, os); } -void PromiseCapability::Dump(std::ostream &os) const +void PromiseCapability::Dump(const JSThread *thread, std::ostream &os) const { os << " - promise: "; - GetPromise().Dump(os); + GetPromise(thread).Dump(thread, os); os << " - resolve: "; - GetResolve().Dump(os); + GetResolve(thread).Dump(thread, os); os << " - reject: "; - GetReject().Dump(os); + GetReject(thread).Dump(thread, os); } -void PromiseIteratorRecord::Dump(std::ostream &os) const +void PromiseIteratorRecord::Dump(const JSThread *thread, std::ostream &os) const { os << " - iterator: "; - GetIterator().Dump(os); + GetIterator(thread).Dump(thread, os); os << " - done: " << GetDone(); } -void PromiseRecord::Dump(std::ostream &os) const +void PromiseRecord::Dump(const JSThread *thread, std::ostream &os) const { os << " - value: "; - GetValue().Dump(os); + GetValue(thread).Dump(thread, os); } -void ResolvingFunctionsRecord::Dump(std::ostream &os) const +void ResolvingFunctionsRecord::Dump(const JSThread *thread, std::ostream &os) const { os << " - resolve-function: "; - GetResolveFunction().Dump(os); + GetResolveFunction(thread).Dump(thread, os); os << " - reject-function: "; - GetRejectFunction().Dump(os); + GetRejectFunction(thread).Dump(thread, os); } -void AsyncGeneratorRequest::Dump(std::ostream &os) const +void AsyncGeneratorRequest::Dump(const JSThread *thread, std::ostream &os) const { os << " - completion: "; - GetCompletion().Dump(os); + GetCompletion(thread).Dump(thread, os); os << " - capability: "; - GetCapability().Dump(os); + GetCapability(thread).Dump(thread, os); } -void AsyncIteratorRecord::Dump(std::ostream &os) const +void AsyncIteratorRecord::Dump(const JSThread *thread, std::ostream &os) const { os << " - completion: "; - GetIterator().Dump(os); + GetIterator(thread).Dump(thread, os); os << " - nextmethod: "; - GetNextMethod().Dump(os); + GetNextMethod(thread).Dump(thread, os); os << " - done: " << GetDone(); } -void JSAsyncFromSyncIterator::Dump(std::ostream &os) const +void JSAsyncFromSyncIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - sync-iterator-record: "; - GetSyncIteratorRecord().Dump(os); - JSObject::Dump(os); + GetSyncIteratorRecord(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSAsyncFromSyncIterUnwarpFunction::Dump(std::ostream &os) const +void JSAsyncFromSyncIterUnwarpFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - done: " ; - GetDone().Dump(os); - JSObject::Dump(os); + GetDone(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromise::Dump(std::ostream &os) const +void JSPromise::Dump(const JSThread *thread, std::ostream &os) const { os << " - promise-state: " << static_cast(GetPromiseState()); os << "\n - promise-result: "; - GetPromiseResult().Dump(os); + GetPromiseResult(thread).Dump(thread, os); os << " - promise-fulfill-reactions: "; - GetPromiseFulfillReactions().Dump(os); + GetPromiseFulfillReactions(thread).Dump(thread, os); os << " - promise-reject-reactions: "; - GetPromiseRejectReactions().Dump(os); + GetPromiseRejectReactions(thread).Dump(thread, os); os << " - promise-is-handled: " << GetPromiseIsHandled(); - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSPromiseReactionsFunction::Dump(std::ostream &os) const +void JSPromiseReactionsFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - promise: "; - GetPromise().Dump(os); + GetPromise(thread).Dump(thread, os); os << " - already-resolved: "; - GetAlreadyResolved().Dump(os); - JSObject::Dump(os); + GetAlreadyResolved(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromiseExecutorFunction::Dump(std::ostream &os) const +void JSPromiseExecutorFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - capability: "; - GetCapability().Dump(os); - JSObject::Dump(os); + GetCapability(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSAsyncModuleFulfilledFunction::Dump(std::ostream &os) const +void JSAsyncModuleFulfilledFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - module: "; - GetModule().Dump(os); - JSObject::Dump(os); + GetModule(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSAsyncModuleRejectedFunction::Dump(std::ostream &os) const +void JSAsyncModuleRejectedFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - module: "; - GetModule().Dump(os); - JSObject::Dump(os); + GetModule(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromiseAllResolveElementFunction::Dump(std::ostream &os) const +void JSPromiseAllResolveElementFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - index: "; - GetIndex().Dump(os); + GetIndex(thread).Dump(thread, os); os << " - values: "; - GetValues().Dump(os); + GetValues(thread).Dump(thread, os); os << " - capability: "; - GetCapabilities().Dump(os); + GetCapabilities(thread).Dump(thread, os); os << " - remaining-elements: "; - GetRemainingElements().Dump(os); + GetRemainingElements(thread).Dump(thread, os); os << " - already-called: "; - GetAlreadyCalled().Dump(os); - JSObject::Dump(os); + GetAlreadyCalled(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromiseAnyRejectElementFunction::Dump(std::ostream &os) const +void JSPromiseAnyRejectElementFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - index: "; - JSTaggedValue(GetIndex()).Dump(os); + JSTaggedValue(GetIndex()).Dump(thread, os); os << " - errors: "; - GetErrors().Dump(os); + GetErrors(thread).Dump(thread, os); os << " - capability: "; - GetCapability().Dump(os); + GetCapability(thread).Dump(thread, os); os << " - remaining-elements: "; - GetRemainingElements().Dump(os); + GetRemainingElements(thread).Dump(thread, os); os << " - already-called: "; - GetAlreadyCalled().Dump(os); - JSObject::Dump(os); + GetAlreadyCalled(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromiseAllSettledElementFunction::Dump(std::ostream &os) const +void JSPromiseAllSettledElementFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - already-called: "; - GetAlreadyCalled().Dump(os); + GetAlreadyCalled(thread).Dump(thread, os); os << " - index: "; - JSTaggedValue(GetIndex()).Dump(os); + JSTaggedValue(GetIndex()).Dump(thread, os); os << " - values: "; - GetValues().Dump(os); + GetValues(thread).Dump(thread, os); os << " - capability: "; - GetCapability().Dump(os); + GetCapability(thread).Dump(thread, os); os << " - remaining-elements: "; - GetRemainingElements().Dump(os); - JSObject::Dump(os); + GetRemainingElements(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromiseFinallyFunction::Dump(std::ostream &os) const +void JSPromiseFinallyFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - constructor: "; - GetConstructor().Dump(os); + GetConstructor(thread).Dump(thread, os); os << " - onFinally: "; - GetOnFinally().Dump(os); - JSObject::Dump(os); + GetOnFinally(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSPromiseValueThunkOrThrowerFunction::Dump(std::ostream &os) const +void JSPromiseValueThunkOrThrowerFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - result: "; - GetResult().Dump(os); - JSObject::Dump(os); + GetResult(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void JSAsyncGeneratorResNextRetProRstFtn::Dump(std::ostream &os) const +void JSAsyncGeneratorResNextRetProRstFtn::Dump(const JSThread *thread, std::ostream &os) const { os << " - AsyncGeneratorObject"; - GetAsyncGeneratorObject().Dump(os); - JSObject::Dump(os); + GetAsyncGeneratorObject(thread).Dump(thread, os); + JSObject::Dump(thread, os); } -void MicroJobQueue::Dump(std::ostream &os) const +void MicroJobQueue::Dump(const JSThread *thread, std::ostream &os) const { os << " - promise-job-queue: "; - GetPromiseJobQueue().Dump(os); + GetPromiseJobQueue(thread).Dump(thread, os); os << " - script-job-queue: "; - GetScriptJobQueue().Dump(os); + GetScriptJobQueue(thread).Dump(thread, os); } -void PendingJob::Dump(std::ostream &os) const +void PendingJob::Dump(const JSThread *thread, std::ostream &os) const { os << " - job: "; - GetJob().Dump(os); + GetJob(thread).Dump(thread, os); os << "\n"; os << " - arguments: "; - GetArguments().Dump(os); + GetArguments(thread).Dump(thread, os); #if defined(ENABLE_HITRACE) os << "\n"; os << " - chainId: " << GetChainId(); @@ -3141,279 +3148,279 @@ void PendingJob::Dump(std::ostream &os) const #endif } -void CompletionRecord::Dump(std::ostream &os) const +void CompletionRecord::Dump(const JSThread *thread, std::ostream &os) const { os << " - type: " << static_cast(GetType()); os << " - value: "; - GetValue().Dump(os); + GetValue(thread).Dump(thread, os); } -void JSProxyRevocFunction::Dump(std::ostream &os) const +void JSProxyRevocFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - RevocableProxy: "; os << "\n"; - GetRevocableProxy().Dump(os); + GetRevocableProxy(thread).Dump(thread, os); os << "\n"; } -void JSAsyncFunction::Dump(std::ostream &os) const +void JSAsyncFunction::Dump(const JSThread *thread, std::ostream &os) const { - JSFunction::Dump(os); + JSFunction::Dump(thread, os); } -void JSAsyncAwaitStatusFunction::Dump(std::ostream &os) const +void JSAsyncAwaitStatusFunction::Dump(const JSThread *thread, std::ostream &os) const { os << " - AsyncContext: "; os << "\n"; - GetAsyncContext().Dump(os); + GetAsyncContext(thread).Dump(thread, os); os << "\n"; } -void JSGeneratorFunction::Dump(std::ostream &os) const +void JSGeneratorFunction::Dump(const JSThread *thread, std::ostream &os) const { - JSFunction::Dump(os); + JSFunction::Dump(thread, os); } -void JSAsyncGeneratorFunction::Dump(std::ostream &os) const +void JSAsyncGeneratorFunction::Dump(const JSThread *thread, std::ostream &os) const { - JSFunction::Dump(os); + JSFunction::Dump(thread, os); } -void JSIntlBoundFunction::Dump(std::ostream &os) const +void JSIntlBoundFunction::Dump(const JSThread *thread, std::ostream &os) const { - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void PropertyBox::Dump(std::ostream &os) const +void PropertyBox::Dump(const JSThread *thread, std::ostream &os) const { os << " - Value: "; - GetValue().Dump(os); + GetValue(thread).Dump(thread, os); os << "\n"; } -void PrototypeHandler::Dump(std::ostream &os) const +void PrototypeHandler::Dump(const JSThread *thread, std::ostream &os) const { os << " - HandlerInfo: "; - GetHandlerInfo().Dump(os); + GetHandlerInfo(thread).Dump(thread, os); os << "\n"; os << " - ProtoCell: "; - GetProtoCell().Dump(os); + GetProtoCell(thread).Dump(thread, os); os << "\n"; os << " - Holder: "; - GetHolder().Dump(os); + GetHolder(thread).Dump(thread, os); os << "\n"; } -void TransitionHandler::Dump(std::ostream &os) const +void TransitionHandler::Dump(const JSThread *thread, std::ostream &os) const { os << " - HandlerInfo: "; - GetHandlerInfo().Dump(os); + GetHandlerInfo(thread).Dump(thread, os); os << "\n"; os << " - TransitionHClass: "; - GetTransitionHClass().Dump(os); + GetTransitionHClass(thread).Dump(thread, os); os << "\n"; } -void TransWithProtoHandler::Dump(std::ostream &os) const +void TransWithProtoHandler::Dump(const JSThread *thread, std::ostream &os) const { os << " - HandlerInfo: "; - GetHandlerInfo().Dump(os); + GetHandlerInfo(thread).Dump(thread, os); os << "\n"; os << " - TransitionHClass: "; - GetTransitionHClass().Dump(os); + GetTransitionHClass(thread).Dump(thread, os); os << "\n"; os << " - ProtoCell: "; - GetProtoCell().Dump(os); + GetProtoCell(thread).Dump(thread, os); os << "\n"; } -void StoreAOTHandler::Dump(std::ostream &os) const +void StoreAOTHandler::Dump(const JSThread *thread, std::ostream &os) const { os << " - HandlerInfo: "; - GetHandlerInfo().Dump(os); + GetHandlerInfo(thread).Dump(thread, os); os << "\n"; os << " - ProtoCell: "; - GetProtoCell().Dump(os); + GetProtoCell(thread).Dump(thread, os); os << "\n"; os << " - Holder: "; - GetHolder().Dump(os); + GetHolder(thread).Dump(thread, os); os << "\n"; } -void JSRealm::Dump(std::ostream &os) const +void JSRealm::Dump(const JSThread *thread, std::ostream &os) const { os << " - Value: "; - GetValue().Dump(os); + GetValue(thread).Dump(thread, os); os << "\n"; os << " - GlobalEnv: "; - GetGlobalEnv().Dump(os); + GetGlobalEnv(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } #ifdef ARK_SUPPORT_INTL -void JSIntl::Dump(std::ostream &os) const +void JSIntl::Dump(const JSThread *thread, std::ostream &os) const { os << " - FallbackSymbol: "; - GetFallbackSymbol().Dump(os); + GetFallbackSymbol(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSLocale::Dump(std::ostream &os) const +void JSLocale::Dump(const JSThread *thread, std::ostream &os) const { os << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSDateTimeFormat::Dump(std::ostream &os) const +void JSDateTimeFormat::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n"; os << " - Calendar: "; - GetCalendar().Dump(os); + GetCalendar(thread).Dump(thread, os); os << "\n"; os << " - NumberingSystem: "; - GetNumberingSystem().Dump(os); + GetNumberingSystem(thread).Dump(thread, os); os << "\n"; os << " - TimeZone: "; - GetTimeZone().Dump(os); + GetTimeZone(thread).Dump(thread, os); os << "\n"; os << " - HourCycle: " << static_cast(GetHourCycle()); os << "\n"; os << " - LocaleIcu: "; - GetLocaleIcu().Dump(os); + GetLocaleIcu(thread).Dump(thread, os); os << "\n"; os << " - SimpleDateTimeFormatIcu: "; - GetSimpleDateTimeFormatIcu().Dump(os); + GetSimpleDateTimeFormatIcu(thread).Dump(thread, os); os << "\n"; os << " - Iso8601: "; - GetIso8601().Dump(os); + GetIso8601(thread).Dump(thread, os); os << "\n"; os << " - DateStyle: " << static_cast(GetDateStyle()); os << "\n"; os << " - TimeStyle: " << static_cast(GetTimeStyle()); os << "\n"; os << " - BoundFormat: "; - GetBoundFormat().Dump(os); + GetBoundFormat(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSRelativeTimeFormat::Dump(std::ostream &os) const +void JSRelativeTimeFormat::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n"; os << " - NumberingSystem: "; - GetNumberingSystem().Dump(os); + GetNumberingSystem(thread).Dump(thread, os); os << "\n"; os << " - Style: " << static_cast(GetStyle()); os << "\n"; os << " - Numeric: " << static_cast(GetNumeric()); os << "\n"; os << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSNumberFormat::Dump(std::ostream &os) const +void JSNumberFormat::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n" << " - NumberingSystem: "; - GetNumberingSystem().Dump(os); + GetNumberingSystem(thread).Dump(thread, os); os << "\n" << " - Style: " << static_cast(GetStyle()); os << "\n" << " - Currency: "; - GetCurrency().Dump(os); + GetCurrency(thread).Dump(thread, os); os << "\n" << " - CurrencyDisplay: " << static_cast(GetCurrencyDisplay()); os << "\n" << " - CurrencySign: " << static_cast(GetCurrencySign()); os << "\n" << " - Unit: "; - GetUnit().Dump(os); + GetUnit(thread).Dump(thread, os); os << "\n" << " - UnitDisplay: " << static_cast(GetUnitDisplay()); os << "\n" << " - MinimumIntegerDigits: "; - GetMinimumIntegerDigits().Dump(os); + GetMinimumIntegerDigits(thread).Dump(thread, os); os << "\n" << " - MinimumFractionDigits: "; - GetMinimumFractionDigits().Dump(os); + GetMinimumFractionDigits(thread).Dump(thread, os); os << "\n" << " - MaximumFractionDigits: "; - GetMaximumFractionDigits().Dump(os); + GetMaximumFractionDigits(thread).Dump(thread, os); os << "\n" << " - MinimumSignificantDigits: "; - GetMinimumSignificantDigits().Dump(os); + GetMinimumSignificantDigits(thread).Dump(thread, os); os << "\n" << " - MaximumSignificantDigits: "; - GetMaximumSignificantDigits().Dump(os); + GetMaximumSignificantDigits(thread).Dump(thread, os); os << "\n" << " - UseGrouping: "; - GetUseGrouping().Dump(os); + GetUseGrouping(thread).Dump(thread, os); os << "\n" << " - RoundingType: " << static_cast(GetRoundingType()); os << "\n" << " - Notation: " << static_cast(GetNotation()); os << "\n" << " - CompactDisplay: " << static_cast(GetCompactDisplay()); os << "\n" << " - SignDisplay: " << static_cast(GetSignDisplay()); os << "\n" << " - BoundFormat: "; - GetBoundFormat().Dump(os); + GetBoundFormat(thread).Dump(thread, os); os << "\n" << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSCollator::Dump(std::ostream &os) const +void JSCollator::Dump(const JSThread *thread, std::ostream &os) const { os << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n - Usage: " << static_cast(GetUsage()); os << "\n - Sensitivity: " << static_cast(GetSensitivity()); os << "\n - IgnorePunctuation: " << GetIgnorePunctuation(); os << "\n - Collation: "; - GetCollation().Dump(os); + GetCollation(thread).Dump(thread, os); os << "\n - Numeric: " << GetNumeric(); os << "\n - CaseFirst: " << static_cast(GetCaseFirst()); os << "\n - BoundCompare: "; - GetBoundCompare().Dump(os); + GetBoundCompare(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSPluralRules::Dump(std::ostream &os) const +void JSPluralRules::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n"; os << " - Type: " << static_cast(GetType()); os << "\n"; os << " - MinimumIntegerDigits: "; - GetMinimumIntegerDigits().Dump(os); + GetMinimumIntegerDigits(thread).Dump(thread, os); os << "\n"; os << " - MinimumFractionDigits: "; - GetMinimumFractionDigits().Dump(os); + GetMinimumFractionDigits(thread).Dump(thread, os); os << "\n"; os << " - MaximumFractionDigits: "; - GetMaximumFractionDigits().Dump(os); + GetMaximumFractionDigits(thread).Dump(thread, os); os << "\n"; os << " - MinimumSignificantDigits: "; - GetMinimumSignificantDigits().Dump(os); + GetMinimumSignificantDigits(thread).Dump(thread, os); os << "\n"; os << " - MaximumSignificantDigits: "; - GetMaximumSignificantDigits().Dump(os); + GetMaximumSignificantDigits(thread).Dump(thread, os); os << "\n"; os << " - RoundingType: " << static_cast(GetRoundingType()); os << "\n"; os << " - IcuPR: "; - GetIcuPR().Dump(os); + GetIcuPR(thread).Dump(thread, os); os << "\n"; os << " - IcuNF: "; - GetIcuNF().Dump(os); + GetIcuNF(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSDisplayNames::Dump(std::ostream &os) const +void JSDisplayNames::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n"; os << " - Type: "<< static_cast(GetType()); os << "\n"; @@ -3422,133 +3429,133 @@ void JSDisplayNames::Dump(std::ostream &os) const os << " - Fallback: "<< static_cast(GetFallback()); os << "\n"; os << " - IcuLDN: "; - GetIcuLDN().Dump(os); + GetIcuLDN(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSSegmenter::Dump(std::ostream &os) const +void JSSegmenter::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n"; os << " - Granularity: "<< static_cast(GetGranularity()); os << "\n"; os << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSSegments::Dump(std::ostream &os) const +void JSSegments::Dump(const JSThread *thread, std::ostream &os) const { os << " - SegmentsString: "; - GetSegmentsString().Dump(os); + GetSegmentsString(thread).Dump(thread, os); os << "\n"; os << " - UnicodeString: "; - GetUnicodeString().Dump(os); + GetUnicodeString(thread).Dump(thread, os); os << "\n"; os << " - Granularity: "<< static_cast(GetGranularity()); os << "\n"; os << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSSegmentIterator::Dump(std::ostream &os) const +void JSSegmentIterator::Dump(const JSThread *thread, std::ostream &os) const { os << " - IteratedString: "; - GetIteratedString().Dump(os); + GetIteratedString(thread).Dump(thread, os); os << "\n"; os << " - UnicodeString: "; - GetUnicodeString().Dump(os); + GetUnicodeString(thread).Dump(thread, os); os << "\n"; os << " - Granularity: "<< static_cast(GetGranularity()); os << "\n"; os << " - IcuField: "; - GetIcuField().Dump(os); + GetIcuField(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSListFormat::Dump(std::ostream &os) const +void JSListFormat::Dump(const JSThread *thread, std::ostream &os) const { os << " - Locale: "; - GetLocale().Dump(os); + GetLocale(thread).Dump(thread, os); os << "\n"; os << " - Type: "<< static_cast(GetType()); os << "\n"; os << " - Style: "<< static_cast(GetStyle()); os << "\n"; os << " - IcuLF: "; - GetIcuLF().Dump(os); + GetIcuLF(thread).Dump(thread, os); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } #endif -void JSGeneratorObject::Dump(std::ostream &os) const +void JSGeneratorObject::Dump(const JSThread *thread, std::ostream &os) const { os << " - GeneratorContext: "; - GetGeneratorContext().Dump(os); + GetGeneratorContext(thread).Dump(thread, os); os << "\n"; os << " - ResumeResult: "; - GetResumeResult().Dump(os); + GetResumeResult(thread).Dump(thread, os); os << "\n"; os << " - GeneratorState: " << static_cast(GetGeneratorState()); os << "\n"; os << " - ResumeMode: " << static_cast(GetResumeMode()); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAsyncGeneratorObject::Dump(std::ostream &os) const +void JSAsyncGeneratorObject::Dump(const JSThread *thread, std::ostream &os) const { os << " - GeneratorContext: "; - GetGeneratorContext().Dump(os); + GetGeneratorContext(thread).Dump(thread, os); os << "\n"; os << " - AsyncGeneratorQueue: "; - GetAsyncGeneratorQueue().Dump(os); + GetAsyncGeneratorQueue(thread).Dump(thread, os); os << "\n"; os << " - GeneratorBrand: "; - GetGeneratorBrand().Dump(os); + GetGeneratorBrand(thread).Dump(thread, os); os << "\n"; os << " - ResumeResult: "; - GetResumeResult().Dump(os); + GetResumeResult(thread).Dump(thread, os); os << "\n"; os << " - AsyncGeneratorState: " << static_cast(GetAsyncGeneratorState()); os << "\n"; os << " - ResumeMode: " << static_cast(GetResumeMode()); os << "\n"; - JSObject::Dump(os); + JSObject::Dump(thread, os); } -void JSAsyncFuncObject::Dump(std::ostream &os) const +void JSAsyncFuncObject::Dump(const JSThread *thread, std::ostream &os) const { os << " - Promise: "; - GetPromise().Dump(os); + GetPromise(thread).Dump(thread, os); os << "\n"; } -void GeneratorContext::Dump(std::ostream &os) const +void GeneratorContext::Dump(const JSThread *thread, std::ostream &os) const { os << " - RegsArray: "; - GetRegsArray().Dump(os); + GetRegsArray(thread).Dump(thread, os); os << "\n"; os << " - Method: "; - GetMethod().Dump(os); + GetMethod(thread).Dump(thread, os); os << "\n"; os << " - This: "; - GetThis().Dump(os); + GetThis(thread).Dump(thread, os); os << "\n"; os << " - Acc: "; - GetAcc().Dump(os); + GetAcc(thread).Dump(thread, os); os << "\n"; os << " - GeneratorObject: "; - GetGeneratorObject().Dump(os); + GetGeneratorObject(thread).Dump(thread, os); os << "\n"; os << " - LexicalEnv: "; - GetLexicalEnv().Dump(os); + GetLexicalEnv(thread).Dump(thread, os); os << "\n"; os << " - NRegs: " << GetNRegs(); os << "\n"; @@ -3556,80 +3563,80 @@ void GeneratorContext::Dump(std::ostream &os) const os << "\n"; } -void EnumCache::Dump(std::ostream &os) const +void EnumCache::Dump(const JSThread *thread, std::ostream &os) const { - os << " - EnumCacheOwn: " << GetEnumCacheOwn(); + os << " - EnumCacheOwn: " << GetEnumCacheOwn(thread); os << "\n"; - os << " - EnumCacheAll: " << GetEnumCacheAll(); + os << " - EnumCacheAll: " << GetEnumCacheAll(thread); os << "\n"; - os << " - ProtoChainInfoEnumCache: " << GetProtoChainInfoEnumCache(); + os << " - ProtoChainInfoEnumCache: " << GetProtoChainInfoEnumCache(thread); os << "\n"; os << " - EnumCacheKind: " << GetEnumCacheKind(); os << "\n"; } -void ProtoChangeMarker::Dump(std::ostream &os) const +void ProtoChangeMarker::Dump([[maybe_unused]]const JSThread *thread, std::ostream &os) const { os << " - HasChanged: " << GetHasChanged() << "\n"; os << " - HasAccessorChanged: " << GetAccessorHasChanged() << "\n"; os << " - HasNotFoundChanged: " << GetNotFoundHasChanged() << "\n"; } -void MarkerCell::Dump(std::ostream &os) const +void MarkerCell::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - IsDetectorInvalid: " << GetIsDetectorInvalid() << "\n"; } -void ProtoChangeDetails::Dump(std::ostream &os) const +void ProtoChangeDetails::Dump(const JSThread *thread, std::ostream &os) const { os << " - ChangeListener: "; - GetChangeListener().Dump(os); + GetChangeListener(thread).Dump(thread, os); os << " \t- RegisterIndex: " << GetRegisterIndex(); os << "\n"; } -void TrackInfo::Dump(std::ostream &os) const +void TrackInfo::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - ElementsKind: " << static_cast(GetElementsKind()) << "\n"; os << " - ArrayLength: " << static_cast(GetArrayLength()) << "\n"; os << " - SpaceFlag: " << static_cast(GetSpaceFlag()) << "\n"; } -void MachineCode::Dump(std::ostream &os) const +void MachineCode::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - InstructionSizeInBytes: " << GetInstructionSizeInBytes(); os << "\n"; } -void ClassInfoExtractor::Dump(std::ostream &os) const +void ClassInfoExtractor::Dump(const JSThread *thread, std::ostream &os) const { os << " - NonStaticKeys: "; - GetNonStaticKeys().Dump(os); + GetNonStaticKeys(thread).Dump(thread, os); os << "\n"; os << " - NonStaticProperties: "; - GetNonStaticProperties().Dump(os); + GetNonStaticProperties(thread).Dump(thread, os); os << "\n"; os << " - NonStaticElements: "; - GetNonStaticElements().Dump(os); + GetNonStaticElements(thread).Dump(thread, os); os << "\n"; os << " - StaticKeys: "; - GetStaticKeys().Dump(os); + GetStaticKeys(thread).Dump(thread, os); os << "\n"; os << " - StaticProperties: "; - GetStaticProperties().Dump(os); + GetStaticProperties(thread).Dump(thread, os); os << "\n"; os << " - StaticElements: "; - GetStaticElements().Dump(os); + GetStaticElements(thread).Dump(thread, os); os << "\n"; } -void SourceTextModule::Dump(std::ostream &os) const +void SourceTextModule::Dump(const JSThread *thread, std::ostream &os) const { os << " - Environment: "; - GetEnvironment().Dump(os); + GetEnvironment(thread).Dump(thread, os); os << "\n"; os << " - Namespace: "; - GetNamespace().Dump(os); + GetNamespace(thread).Dump(thread, os); os << "\n"; os << " - EcmaModuleFilename: "; os << GetEcmaModuleFilenameString(); @@ -3638,28 +3645,28 @@ void SourceTextModule::Dump(std::ostream &os) const os << GetEcmaModuleRecordNameString(); os << "\n"; os << " - ModuleRequests: "; - GetModuleRequests().Dump(os); + GetModuleRequests(thread).Dump(thread, os); os << "\n"; os << " - RequestedModules: "; - GetRequestedModules().Dump(os); + GetRequestedModules(thread).Dump(thread, os); os << "\n"; os << " - ImportEntries: "; - GetImportEntries().Dump(os); + GetImportEntries(thread).Dump(thread, os); os << "\n"; os << " - LocalExportEntries: "; - GetLocalExportEntries().Dump(os); + GetLocalExportEntries(thread).Dump(thread, os); os << "\n"; os << " - IndirectExportEntries: "; - GetIndirectExportEntries().Dump(os); + GetIndirectExportEntries(thread).Dump(thread, os); os << "\n"; os << " - StarExportEntries: "; - GetStarExportEntries().Dump(os); + GetStarExportEntries(thread).Dump(thread, os); os << "\n"; os << " - Status: "; os << static_cast(GetStatus()); os << "\n"; os << " - Exception: "; - GetException().Dump(os); + GetException(thread).Dump(thread, os); os << "\n"; os << " - DFSIndex: "; os << GetDFSIndex(); @@ -3668,24 +3675,24 @@ void SourceTextModule::Dump(std::ostream &os) const os << GetDFSAncestorIndex(); os << "\n"; os << " - NameDictionary: "; - GetNameDictionary().Dump(os); + GetNameDictionary(thread).Dump(thread, os); os << "\n"; os << " - CycleRoot: "; // avoid infinite dump - if (GetCycleRoot() != JSTaggedValue(this)) { - GetCycleRoot().Dump(os); + if (GetCycleRoot(thread) != JSTaggedValue(this)) { + GetCycleRoot(thread).Dump(thread, os); } else { os << "this"; } os << "\n"; os << " - TopLevelCapability: "; - GetTopLevelCapability().Dump(os); + GetTopLevelCapability(thread).Dump(thread, os); os << "\n"; os << " - AsyncParentModules: "; - GetAsyncParentModules().Dump(os); + GetAsyncParentModules(thread).Dump(thread, os); os << "\n"; os << " - SendableEnv: "; - GetSendableEnv().Dump(os); + GetSendableEnv(thread).Dump(thread, os); os << "\n"; os << " - HasTLA: "; os << GetHasTLA(); @@ -3698,138 +3705,138 @@ void SourceTextModule::Dump(std::ostream &os) const os << "\n"; } -void ImportEntry::Dump(std::ostream &os) const +void ImportEntry::Dump(const JSThread *thread, std::ostream &os) const { os << " - ModuleRequestIndex: "; os << GetModuleRequestIndex(); os << "\n"; os << " - ImportName: "; - GetImportName().Dump(os); + GetImportName(thread).Dump(thread, os); os << "\n"; os << " - LocalName: "; - GetLocalName().Dump(os); + GetLocalName(thread).Dump(thread, os); os << "\n"; } -void LocalExportEntry::Dump(std::ostream &os) const +void LocalExportEntry::Dump(const JSThread *thread, std::ostream &os) const { os << " - ExportName: "; - GetExportName().Dump(os); + GetExportName(thread).Dump(thread, os); os << "\n"; os << " - LocalName: "; - GetLocalName().Dump(os); + GetLocalName(thread).Dump(thread, os); os << "\n"; os << " - LocalIndex: " << GetLocalIndex(); os << "\n"; } -void IndirectExportEntry::Dump(std::ostream &os) const +void IndirectExportEntry::Dump(const JSThread *thread, std::ostream &os) const { os << " - ExportName: "; - GetExportName().Dump(os); + GetExportName(thread).Dump(thread, os); os << "\n"; os << " - ModuleRequestIndex: "; os << GetModuleRequestIndex(); os << "\n"; os << " - ImportName: "; - GetImportName().Dump(os); + GetImportName(thread).Dump(thread, os); os << "\n"; } -void StarExportEntry::Dump(std::ostream &os) const +void StarExportEntry::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " - ModuleRequestIndex: "; os << GetModuleRequestIndex(); os << "\n"; } -void ResolvedBinding::Dump(std::ostream &os) const +void ResolvedBinding::Dump(const JSThread *thread, std::ostream &os) const { os << " - Module: "; - GetModule().Dump(os); + GetModule(thread).Dump(thread, os); os << "\n"; os << " - BindingName: "; - GetBindingName().Dump(os); + GetBindingName(thread).Dump(thread, os); os << "\n"; } -void ResolvedIndexBinding::Dump(std::ostream &os) const +void ResolvedIndexBinding::Dump(const JSThread *thread, std::ostream &os) const { os << " - Module: "; - GetModule().Dump(os); + GetModule(thread).Dump(thread, os); os << "\n"; os << " - Index: "; GetIndex(); os << "\n"; } -void ResolvedRecordIndexBinding::Dump(std::ostream &os) const +void ResolvedRecordIndexBinding::Dump(const JSThread *thread, std::ostream &os) const { os << " - Module: "; - GetModuleRecord().Dump(os); + GetModuleRecord(thread).Dump(thread, os); os << "\n"; os << " - AbcFileName: "; - GetAbcFileName().Dump(os); + GetAbcFileName(thread).Dump(thread, os); os << "\n"; os << " - Index: "; GetIndex(); os << "\n"; } -void ResolvedRecordBinding::Dump(std::ostream &os) const +void ResolvedRecordBinding::Dump(const JSThread *thread, std::ostream &os) const { os << " - Module: "; - GetModuleRecord().Dump(os); + GetModuleRecord(thread).Dump(thread, os); os << "\n"; os << " - BindingName: "; - GetBindingName().Dump(os); + GetBindingName(thread).Dump(thread, os); os << "\n"; } -void ModuleNamespace::Dump(std::ostream &os) const +void ModuleNamespace::Dump(const JSThread *thread, std::ostream &os) const { os << " - Exports: "; - GetExports().Dump(os); + GetExports(thread).Dump(thread, os); os << "\n"; } -void NativeModuleFailureInfo::Dump(std::ostream &os) const +void NativeModuleFailureInfo::Dump(const JSThread *thread, std::ostream &os) const { os << " - ArkNativeModuleFailureInfo: "; - GetArkNativeModuleFailureInfo().Dump(os); + GetArkNativeModuleFailureInfo(thread).Dump(thread, os); os << "\n"; } -void CjsModule::Dump(std::ostream &os) const +void CjsModule::Dump(const JSThread *thread, std::ostream &os) const { os << " - current module path: "; - GetPath().Dump(os); + GetPath(thread).Dump(thread, os); os << "\n"; os << " - current module filename: "; - GetFilename().Dump(os); + GetFilename(thread).Dump(thread, os); os << "\n"; } -void CjsRequire::Dump(std::ostream &os) const +void CjsRequire::Dump([[maybe_unused]] const JSThread *thread, std::ostream &os) const { os << " --- CjsRequire is JSFunction: "; os << "\n"; } -void CjsExports::Dump(std::ostream &os) const +void CjsExports::Dump(const JSThread *thread, std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; JSHClass *jshclass = GetJSHClass(); os << " - hclass: " << std::hex << jshclass << "\n"; os << " - prototype: "; - jshclass->GetPrototype().DumpTaggedValue(os); + jshclass->GetPrototype(thread).DumpTaggedValue(thread, os); os << "\n"; - TaggedArray *properties = TaggedArray::Cast(GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); os << " - properties: " << std::hex << properties; if (!properties->IsDictionaryMode()) { - JSTaggedValue attrs = jshclass->GetLayout(); + JSTaggedValue attrs = jshclass->GetLayout(thread); if (attrs.IsNull()) { return; } @@ -3838,19 +3845,19 @@ void CjsExports::Dump(std::ostream &os) const int propNumber = static_cast(jshclass->NumberOfProps()); os << " \n"; for (int i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); - PropertyAttributes attr = layoutInfo->GetAttr(i); + JSTaggedValue key = layoutInfo->GetKey(thread, i); + PropertyAttributes attr = layoutInfo->GetAttr(thread, i); ASSERT(i == static_cast(attr.GetOffset())); os << " " << std::right << std::setw(DUMP_PROPERTY_OFFSET); - DumpPropertyKey(key, os); + DumpPropertyKey(thread, key, os); os << ": ("; JSTaggedValue val; if (attr.IsInlinedProps()) { - val = GetPropertyInlinedPropsWithRep(i, attr); + val = GetPropertyInlinedPropsWithRep(thread, i, attr); } else { - val = properties->Get(i - static_cast(jshclass->GetInlinedProperties())); + val = properties->Get(thread, i - static_cast(jshclass->GetInlinedProperties())); } - val.DumpTaggedValue(os); + val.DumpTaggedValue(thread, os); os << ") "; DumpAttr(attr, true, os); os << "\n"; @@ -3858,24 +3865,24 @@ void CjsExports::Dump(std::ostream &os) const } else { NameDictionary *dict = NameDictionary::Cast(properties); os << " EntriesCount() << "]>\n"; - dict->Dump(os); + dict->Dump(thread, os); } } -void JSFunctionBase::Dump(std::ostream &os) const +void JSFunctionBase::Dump(const JSThread *thread, std::ostream &os) const { os << " - Method: "; - GetMethod().Dump(os); + GetMethod(thread).Dump(thread, os); os << "\n"; } -void Method::Dump(std::ostream &os) const +void Method::Dump(const JSThread *thread, std::ostream &os) const { os << " - MethodName: "; - os << GetMethodName(); + os << GetMethodName(thread); os << "\n"; os << " - ConstantPool: "; - GetConstantPool().Dump(os); + GetConstantPool(thread).Dump(thread, os); os << "\n"; os << " - FunctionKind: " << static_cast(GetFunctionKind()); os << "\n"; @@ -3883,74 +3890,74 @@ void Method::Dump(std::ostream &os) const os << "\n"; } -void ClassLiteral::Dump(std::ostream &os) const +void ClassLiteral::Dump(const JSThread *thread, std::ostream &os) const { os << " - ClassLiteral: "; os << "\n"; os << " - IsAOTUsed: " << std::boolalpha << GetIsAOTUsed(); os << "\n"; os << " - Array: "; - GetArray().Dump(os); + GetArray(thread).Dump(thread, os); os << "\n"; } // ######################################################################################## // Dump for Snapshot // ######################################################################################## -static void DumpArrayClass(const TaggedArray *arr, std::vector &vec) +static void DumpArrayClass(const JSThread *thread, const TaggedArray *arr, std::vector &vec) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); CString str = ToCString(i); vec.emplace_back(str, val); } } -static void DumpMutantTaggedArrayClass(const MutantTaggedArray *arr, std::vector &vec) +static void DumpMutantTaggedArrayClass(const JSThread *thread, const MutantTaggedArray *arr, std::vector &vec) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); CString str = ToCString(i); vec.emplace_back(str, val); } } -static void DumpCOWMutantTaggedArrayClass(const COWMutantTaggedArray *arr, std::vector &vec) +static void DumpCOWMutantTaggedArrayClass(const JSThread *thread, const COWMutantTaggedArray *arr, std::vector &vec) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); CString str = ToCString(i); vec.emplace_back(str, val); } } -static void DumpElementClass(const TaggedArray *arr, std::vector &vec) +static void DumpElementClass(const JSThread *thread, const TaggedArray *arr, std::vector &vec) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->Get(i)); + JSTaggedValue val(arr->Get(thread, i)); vec.emplace_back(i, val, Reference::ReferenceType::ELEMENT); } } -static void DumpConstantPoolClass(const ConstantPool *arr, std::vector &vec) +static void DumpConstantPoolClass(const JSThread *thread, const ConstantPool *arr, std::vector &vec) { DISALLOW_GARBAGE_COLLECTION; uint32_t len = arr->GetCacheLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(arr->GetObjectFromCache(i)); + JSTaggedValue val(arr->GetObjectFromCache(thread, i)); CString str = ToCString(i); vec.emplace_back(str, val); } @@ -3962,7 +3969,7 @@ static void DumpStringClass([[maybe_unused]] const EcmaString *str, [[maybe_unus // If some properties need be shown, add here. } -static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVmMode) +static void DumpObject(const JSThread *thread, TaggedObject *obj, std::vector &vec, bool isVmMode) { JSTaggedValue objValue(obj); DISALLOW_GARBAGE_COLLECTION; @@ -3971,7 +3978,7 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm vec.emplace_back("hclass", JSTaggedValue(jsHclass)); switch (type) { case JSType::HCLASS: - JSHClass::Cast(obj)->DumpForSnapshot(vec); + JSHClass::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::TAGGED_ARRAY: case JSType::TAGGED_DICTIONARY: @@ -3980,30 +3987,30 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm case JSType::SENDABLE_ENV: case JSType::COW_TAGGED_ARRAY: case JSType::AOT_LITERAL_INFO: - DumpArrayClass(TaggedArray::Cast(obj), vec); + DumpArrayClass(thread, TaggedArray::Cast(obj), vec); break; case JSType::MUTANT_TAGGED_ARRAY: - DumpMutantTaggedArrayClass(MutantTaggedArray::Cast(obj), vec); + DumpMutantTaggedArrayClass(thread, MutantTaggedArray::Cast(obj), vec); break; case JSType::COW_MUTANT_TAGGED_ARRAY: - DumpCOWMutantTaggedArrayClass(COWMutantTaggedArray::Cast(obj), vec); + DumpCOWMutantTaggedArrayClass(thread, COWMutantTaggedArray::Cast(obj), vec); break; case JSType::CONSTANT_POOL: - DumpConstantPoolClass(ConstantPool::Cast(obj), vec); + DumpConstantPoolClass(thread, ConstantPool::Cast(obj), vec); break; case JSType::PROFILE_TYPE_INFO_CELL_0: case JSType::PROFILE_TYPE_INFO_CELL_1: case JSType::PROFILE_TYPE_INFO_CELL_N: - ProfileTypeInfoCell::Cast(obj)->DumpForSnapshot(vec); + ProfileTypeInfoCell::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::FUNCTION_TEMPLATE: - FunctionTemplate::Cast(obj)->DumpForSnapshot(vec); + FunctionTemplate::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::VTABLE: - VTable::Cast(obj)->DumpForSnapshot(vec); + VTable::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROFILE_TYPE_INFO: - ProfileTypeInfo::Cast(obj)->DumpForSnapshot(vec); + ProfileTypeInfo::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::LINE_STRING: case JSType::TREE_STRING: @@ -4026,54 +4033,54 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm case JSType::JS_ARGUMENTS: case JSType::JS_GLOBAL_OBJECT: case JSType::JS_SHARED_OBJECT: - JSObject::Cast(obj)->DumpForSnapshot(vec); + JSObject::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_FUNCTION_BASE: case JSType::JS_FUNCTION: case JSType::JS_SHARED_FUNCTION: - JSFunction::Cast(obj)->DumpForSnapshot(vec); + JSFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_BOUND_FUNCTION: - JSBoundFunction::Cast(obj)->DumpForSnapshot(vec); + JSBoundFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SET: - JSSet::Cast(obj)->DumpForSnapshot(vec); + JSSet::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SHARED_SET: - JSSharedSet::Cast(obj)->DumpForSnapshot(vec); + JSSharedSet::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_MAP: - JSMap::Cast(obj)->DumpForSnapshot(vec); + JSMap::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SHARED_MAP: - JSSharedMap::Cast(obj)->DumpForSnapshot(vec); + JSSharedMap::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_WEAK_SET: - JSWeakSet::Cast(obj)->DumpForSnapshot(vec); + JSWeakSet::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_WEAK_MAP: - JSWeakMap::Cast(obj)->DumpForSnapshot(vec); + JSWeakMap::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_WEAK_REF: - JSWeakRef::Cast(obj)->DumpForSnapshot(vec); + JSWeakRef::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_FINALIZATION_REGISTRY: - JSFinalizationRegistry::Cast(obj)->DumpForSnapshot(vec); + JSFinalizationRegistry::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::CELL_RECORD: - CellRecord::Cast(obj)->DumpForSnapshot(vec); + CellRecord::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_REG_EXP: - JSRegExp::Cast(obj)->DumpForSnapshot(vec); + JSRegExp::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_DATE: - JSDate::Cast(obj)->DumpForSnapshot(vec); + JSDate::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ARRAY: - JSArray::Cast(obj)->DumpForSnapshot(vec); + JSArray::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SHARED_ARRAY: - JSSharedArray::Cast(obj)->DumpForSnapshot(vec); + JSSharedArray::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_TYPED_ARRAY: case JSType::JS_INT8_ARRAY: @@ -4087,7 +4094,7 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm case JSType::JS_FLOAT64_ARRAY: case JSType::JS_BIGINT64_ARRAY: case JSType::JS_BIGUINT64_ARRAY: - JSTypedArray::Cast(obj)->DumpForSnapshot(vec); + JSTypedArray::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SHARED_TYPED_ARRAY: case JSType::JS_SHARED_INT8_ARRAY: @@ -4101,98 +4108,98 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm case JSType::JS_SHARED_FLOAT64_ARRAY: case JSType::JS_SHARED_BIGINT64_ARRAY: case JSType::JS_SHARED_BIGUINT64_ARRAY: - JSSharedTypedArray::Cast(obj)->DumpForSnapshot(vec); + JSSharedTypedArray::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::BIGINT: - BigInt::Cast(obj)->DumpForSnapshot(vec); + BigInt::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::BYTE_ARRAY: - ByteArray::Cast(obj)->DumpForSnapshot(vec); + ByteArray::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROXY: - JSProxy::Cast(obj)->DumpForSnapshot(vec); + JSProxy::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PRIMITIVE_REF: - JSPrimitiveRef::Cast(obj)->DumpForSnapshot(vec); + JSPrimitiveRef::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::SYMBOL: - JSSymbol::Cast(obj)->DumpForSnapshot(vec); + JSSymbol::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::ACCESSOR_DATA: case JSType::INTERNAL_ACCESSOR: - AccessorData::Cast(obj)->DumpForSnapshot(vec); + AccessorData::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_DATA_VIEW: - JSDataView::Cast(obj)->DumpForSnapshot(vec); + JSDataView::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROMISE_REACTIONS: - PromiseReaction::Cast(obj)->DumpForSnapshot(vec); + PromiseReaction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROMISE_CAPABILITY: - PromiseCapability::Cast(obj)->DumpForSnapshot(vec); + PromiseCapability::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROMISE_ITERATOR_RECORD: - PromiseIteratorRecord::Cast(obj)->DumpForSnapshot(vec); + PromiseIteratorRecord::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROMISE_RECORD: - PromiseRecord::Cast(obj)->DumpForSnapshot(vec); + PromiseRecord::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::RESOLVING_FUNCTIONS_RECORD: - ResolvingFunctionsRecord::Cast(obj)->DumpForSnapshot(vec); + ResolvingFunctionsRecord::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE: - JSPromise::Cast(obj)->DumpForSnapshot(vec); + JSPromise::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_REACTIONS_FUNCTION: - JSPromiseReactionsFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseReactionsFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_EXECUTOR_FUNCTION: - JSPromiseExecutorFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseExecutorFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_MODULE_FULFILLED_FUNCTION: - JSAsyncModuleFulfilledFunction::Cast(obj)->DumpForSnapshot(vec); + JSAsyncModuleFulfilledFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_MODULE_REJECTED_FUNCTION: - JSAsyncModuleRejectedFunction::Cast(obj)->DumpForSnapshot(vec); + JSAsyncModuleRejectedFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::ASYNC_GENERATOR_REQUEST: - AsyncGeneratorRequest::Cast(obj)->DumpForSnapshot(vec); + AsyncGeneratorRequest::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::ASYNC_ITERATOR_RECORD: - AsyncIteratorRecord::Cast(obj)->DumpForSnapshot(vec); + AsyncIteratorRecord::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_FROM_SYNC_ITERATOR: - JSAsyncFromSyncIterator::Cast(obj)->DumpForSnapshot(vec); + JSAsyncFromSyncIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_FROM_SYNC_ITER_UNWARP_FUNCTION: - JSAsyncFromSyncIterUnwarpFunction::Cast(obj)->DumpForSnapshot(vec); + JSAsyncFromSyncIterUnwarpFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: - JSPromiseAllResolveElementFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseAllResolveElementFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: - JSPromiseAnyRejectElementFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseAnyRejectElementFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: - JSPromiseAllSettledElementFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseAllSettledElementFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_FINALLY_FUNCTION: - JSPromiseFinallyFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseFinallyFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: - JSPromiseValueThunkOrThrowerFunction::Cast(obj)->DumpForSnapshot(vec); + JSPromiseValueThunkOrThrowerFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_GENERATOR_RESUME_NEXT_RETURN_PROCESSOR_RST_FTN: - JSAsyncGeneratorResNextRetProRstFtn::Cast(obj)->DumpForSnapshot(vec); + JSAsyncGeneratorResNextRetProRstFtn::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::MICRO_JOB_QUEUE: - MicroJobQueue::Cast(obj)->DumpForSnapshot(vec); + MicroJobQueue::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PENDING_JOB: - PendingJob::Cast(obj)->DumpForSnapshot(vec); + PendingJob::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::COMPLETION_RECORD: - CompletionRecord::Cast(obj)->DumpForSnapshot(vec); + CompletionRecord::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ITERATOR: case JSType::JS_ASYNCITERATOR: @@ -4206,72 +4213,72 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm case JSType::JS_STRING_ITERATOR: case JSType::JS_REG_EXP_ITERATOR: case JSType::JS_ARRAY_BUFFER: - JSArrayBuffer::Cast(obj)->DumpForSnapshot(vec); + JSArrayBuffer::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SHARED_ARRAY_BUFFER: - JSArrayBuffer::Cast(obj)->DumpForSnapshot(vec); + JSArrayBuffer::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SENDABLE_ARRAY_BUFFER: - JSSendableArrayBuffer::Cast(obj)->DumpForSnapshot(vec); + JSSendableArrayBuffer::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PROXY_REVOC_FUNCTION: - JSProxyRevocFunction::Cast(obj)->DumpForSnapshot(vec); + JSProxyRevocFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_FUNCTION: case JSType::JS_SHARED_ASYNC_FUNCTION: - JSAsyncFunction::Cast(obj)->DumpForSnapshot(vec); + JSAsyncFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION: - JSAsyncAwaitStatusFunction::Cast(obj)->DumpForSnapshot(vec); + JSAsyncAwaitStatusFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_GENERATOR_FUNCTION: - JSGeneratorFunction::Cast(obj)->DumpForSnapshot(vec); + JSGeneratorFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_GENERATOR_FUNCTION: - JSAsyncGeneratorFunction::Cast(obj)->DumpForSnapshot(vec); + JSAsyncGeneratorFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_INTL_BOUND_FUNCTION: - JSIntlBoundFunction::Cast(obj)->DumpForSnapshot(vec); + JSIntlBoundFunction::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_REALM: - JSRealm::Cast(obj)->DumpForSnapshot(vec); + JSRealm::Cast(obj)->DumpForSnapshot(thread, vec); break; #ifdef ARK_SUPPORT_INTL case JSType::JS_INTL: - JSIntl::Cast(obj)->DumpForSnapshot(vec); + JSIntl::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_LOCALE: - JSLocale::Cast(obj)->DumpForSnapshot(vec); + JSLocale::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_DATE_TIME_FORMAT: - JSDateTimeFormat::Cast(obj)->DumpForSnapshot(vec); + JSDateTimeFormat::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_RELATIVE_TIME_FORMAT: - JSRelativeTimeFormat::Cast(obj)->DumpForSnapshot(vec); + JSRelativeTimeFormat::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_NUMBER_FORMAT: - JSNumberFormat::Cast(obj)->DumpForSnapshot(vec); + JSNumberFormat::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_COLLATOR: - JSCollator::Cast(obj)->DumpForSnapshot(vec); + JSCollator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_PLURAL_RULES: - JSPluralRules::Cast(obj)->DumpForSnapshot(vec); + JSPluralRules::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_DISPLAYNAMES: - JSDisplayNames::Cast(obj)->DumpForSnapshot(vec); + JSDisplayNames::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SEGMENTER: - JSSegmenter::Cast(obj)->DumpForSnapshot(vec); + JSSegmenter::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SEGMENTS: - JSSegments::Cast(obj)->DumpForSnapshot(vec); + JSSegments::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_SEGMENT_ITERATOR: - JSSegmentIterator::Cast(obj)->DumpForSnapshot(vec); + JSSegmentIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_LIST_FORMAT: - JSListFormat::Cast(obj)->DumpForSnapshot(vec); + JSListFormat::Cast(obj)->DumpForSnapshot(thread, vec); break; #else case JSType::JS_INTL: @@ -4289,156 +4296,156 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm break; #endif case JSType::JS_CJS_MODULE: - CjsModule::Cast(obj)->DumpForSnapshot(vec); + CjsModule::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_CJS_EXPORTS: - CjsExports::Cast(obj)->DumpForSnapshot(vec); + CjsExports::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_CJS_REQUIRE: - CjsRequire::Cast(obj)->DumpForSnapshot(vec); + CjsRequire::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_GENERATOR_OBJECT: - JSGeneratorObject::Cast(obj)->DumpForSnapshot(vec); + JSGeneratorObject::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_GENERATOR_OBJECT: - JSAsyncGeneratorObject::Cast(obj)->DumpForSnapshot(vec); + JSAsyncGeneratorObject::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_ASYNC_FUNC_OBJECT: - JSAsyncFuncObject::Cast(obj)->DumpForSnapshot(vec); + JSAsyncFuncObject::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_GENERATOR_CONTEXT: - GeneratorContext::Cast(obj)->DumpForSnapshot(vec); + GeneratorContext::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_ARRAY_LIST: - JSAPIArrayList::Cast(obj)->DumpForSnapshot(vec); + JSAPIArrayList::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_ARRAYLIST_ITERATOR: - JSAPIArrayListIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIArrayListIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::LINKED_NODE: - LinkedNode::Cast(obj)->DumpForSnapshot(vec); + LinkedNode::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::RB_TREENODE: break; case JSType::JS_API_HASH_MAP: - JSAPIHashMap::Cast(obj)->DumpForSnapshot(vec); + JSAPIHashMap::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_HASH_SET: - JSAPIHashSet::Cast(obj)->DumpForSnapshot(vec); + JSAPIHashSet::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_HASHMAP_ITERATOR: - JSAPIHashMapIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIHashMapIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_HASHSET_ITERATOR: - JSAPIHashSetIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIHashSetIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LIGHT_WEIGHT_MAP: - JSAPILightWeightMap::Cast(obj)->DumpForSnapshot(vec); + JSAPILightWeightMap::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: - JSAPILightWeightMapIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPILightWeightMapIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LIGHT_WEIGHT_SET: - JSAPILightWeightSet::Cast(obj)->DumpForSnapshot(vec); + JSAPILightWeightSet::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: - JSAPILightWeightSetIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPILightWeightSetIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_TREE_MAP: - JSAPITreeMap::Cast(obj)->DumpForSnapshot(vec); + JSAPITreeMap::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_TREE_SET: - JSAPITreeSet::Cast(obj)->DumpForSnapshot(vec); + JSAPITreeSet::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_TREEMAP_ITERATOR: - JSAPITreeMapIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPITreeMapIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_TREESET_ITERATOR: - JSAPITreeSetIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPITreeSetIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_VECTOR: - JSAPIVector::Cast(obj)->DumpForSnapshot(vec); + JSAPIVector::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_VECTOR_ITERATOR: - JSAPIVectorIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIVectorIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_BITVECTOR: - JSAPIBitVector::Cast(obj)->DumpForSnapshot(vec); + JSAPIBitVector::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_BITVECTOR_ITERATOR: - JSAPIBitVectorIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIBitVectorIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_FAST_BUFFER: - JSAPIFastBuffer::Cast(obj)->DumpForSnapshot(vec); + JSAPIFastBuffer::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_QUEUE: - JSAPIQueue::Cast(obj)->DumpForSnapshot(vec); + JSAPIQueue::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_QUEUE_ITERATOR: - JSAPIQueueIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIQueueIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_DEQUE: - JSAPIDeque::Cast(obj)->DumpForSnapshot(vec); + JSAPIDeque::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_DEQUE_ITERATOR: - JSAPIDequeIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIDequeIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_STACK: - JSAPIStack::Cast(obj)->DumpForSnapshot(vec); + JSAPIStack::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_STACK_ITERATOR: - JSAPIStackIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIStackIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LIST: - JSAPIList::Cast(obj)->DumpForSnapshot(vec); + JSAPIList::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LINKED_LIST: - JSAPILinkedList::Cast(obj)->DumpForSnapshot(vec); + JSAPILinkedList::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LIST_ITERATOR: - JSAPIListIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIListIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_LINKED_LIST_ITERATOR: - JSAPILinkedListIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPILinkedListIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::SOURCE_TEXT_MODULE_RECORD: - SourceTextModule::Cast(obj)->DumpForSnapshot(vec); + SourceTextModule::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::IMPORTENTRY_RECORD: - ImportEntry::Cast(obj)->DumpForSnapshot(vec); + ImportEntry::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::LOCAL_EXPORTENTRY_RECORD: - LocalExportEntry::Cast(obj)->DumpForSnapshot(vec); + LocalExportEntry::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::INDIRECT_EXPORTENTRY_RECORD: - IndirectExportEntry::Cast(obj)->DumpForSnapshot(vec); + IndirectExportEntry::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::STAR_EXPORTENTRY_RECORD: - StarExportEntry::Cast(obj)->DumpForSnapshot(vec); + StarExportEntry::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::RESOLVEDBINDING_RECORD: - ResolvedBinding::Cast(obj)->DumpForSnapshot(vec); + ResolvedBinding::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::RESOLVEDINDEXBINDING_RECORD: - ResolvedIndexBinding::Cast(obj)->DumpForSnapshot(vec); + ResolvedIndexBinding::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::RESOLVEDRECORDINDEXBINDING_RECORD: - ResolvedRecordIndexBinding::Cast(obj)->DumpForSnapshot(vec); + ResolvedRecordIndexBinding::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::RESOLVEDRECORDBINDING_RECORD: - ResolvedRecordBinding::Cast(obj)->DumpForSnapshot(vec); + ResolvedRecordBinding::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_MODULE_NAMESPACE: - ModuleNamespace::Cast(obj)->DumpForSnapshot(vec); + ModuleNamespace::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::NATIVE_MODULE_FAILURE_INFO: - NativeModuleFailureInfo::Cast(obj)->DumpForSnapshot(vec); + NativeModuleFailureInfo::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_PLAIN_ARRAY: - JSAPIPlainArray::Cast(obj)->DumpForSnapshot(vec); + JSAPIPlainArray::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::JS_API_PLAIN_ARRAY_ITERATOR: - JSAPIPlainArrayIterator::Cast(obj)->DumpForSnapshot(vec); + JSAPIPlainArrayIterator::Cast(obj)->DumpForSnapshot(thread, vec); break; default: break; @@ -4446,55 +4453,55 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm if (isVmMode) { switch (type) { case JSType::PROPERTY_BOX: - PropertyBox::Cast(obj)->DumpForSnapshot(vec); + PropertyBox::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::TEMPLATE_MAP: - DumpArrayClass(TaggedArray::Cast(obj), vec); + DumpArrayClass(thread, TaggedArray::Cast(obj), vec); break; case JSType::GLOBAL_ENV: - GlobalEnv::Cast(obj)->DumpForSnapshot(vec); + GlobalEnv::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::ENUM_CACHE: - EnumCache::Cast(obj)->DumpForSnapshot(vec); + EnumCache::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROTO_CHANGE_MARKER: - ProtoChangeMarker::Cast(obj)->DumpForSnapshot(vec); + ProtoChangeMarker::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::MARKER_CELL: - MarkerCell::Cast(obj)->DumpForSnapshot(vec); + MarkerCell::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROTOTYPE_INFO: - ProtoChangeDetails::Cast(obj)->DumpForSnapshot(vec); + ProtoChangeDetails::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::TRACK_INFO: - TrackInfo::Cast(obj)->DumpForSnapshot(vec); + TrackInfo::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROGRAM: - Program::Cast(obj)->DumpForSnapshot(vec); + Program::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::MACHINE_CODE_OBJECT: - MachineCode::Cast(obj)->DumpForSnapshot(vec); + MachineCode::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::TRANSITION_HANDLER: - TransitionHandler::Cast(obj)->DumpForSnapshot(vec); + TransitionHandler::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::TRANS_WITH_PROTO_HANDLER: - TransWithProtoHandler::Cast(obj)->DumpForSnapshot(vec); + TransWithProtoHandler::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::STORE_TS_HANDLER: - StoreAOTHandler::Cast(obj)->DumpForSnapshot(vec); + StoreAOTHandler::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::PROTOTYPE_HANDLER: - PrototypeHandler::Cast(obj)->DumpForSnapshot(vec); + PrototypeHandler::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::CLASS_INFO_EXTRACTOR: - ClassInfoExtractor::Cast(obj)->DumpForSnapshot(vec); + ClassInfoExtractor::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::METHOD: - Method::Cast(obj)->DumpForSnapshot(vec); + Method::Cast(obj)->DumpForSnapshot(thread, vec); break; case JSType::CLASS_LITERAL: - ClassLiteral::Cast(obj)->DumpForSnapshot(vec); + ClassLiteral::Cast(obj)->DumpForSnapshot(thread, vec); break; default: break; @@ -4504,18 +4511,18 @@ static void DumpObject(TaggedObject *obj, std::vector &vec, bool isVm } } -static inline void EcmaStringToStd(CString &res, EcmaString *str) +static inline void EcmaStringToStd(const JSThread *thread, CString &res, EcmaString *str) { if (EcmaStringAccessor(str).GetLength() == 0) { CString emptyStr = "EmptyString"; res.append(emptyStr); } - CString string = ConvertToString(str); + CString string = ConvertToString(thread, str); res.append(string); } -static void KeyToStd(CString &res, JSTaggedValue key) +static void KeyToStd(const JSThread *thread, CString &res, JSTaggedValue key) { if (key.IsInt()) { res = std::to_string(key.GetInt()); @@ -4528,255 +4535,255 @@ static void KeyToStd(CString &res, JSTaggedValue key) key.RemoveWeakTag(); } if (key.IsString()) { - EcmaStringToStd(res, EcmaString::Cast(key.GetTaggedObject())); + EcmaStringToStd(thread, res, EcmaString::Cast(key.GetTaggedObject())); } else if (key.IsSymbol()) { JSSymbol *sym = JSSymbol::Cast(key.GetTaggedObject()); - JSTaggedValue desc = sym->GetDescription(); + JSTaggedValue desc = sym->GetDescription(thread); if (desc.IsString()) { - EcmaStringToStd(res, EcmaString::Cast(desc.GetTaggedObject())); + EcmaStringToStd(thread, res, EcmaString::Cast(desc.GetTaggedObject())); } } } } -void JSAPIPlainArray::DumpForSnapshot(std::vector &vec) const +void JSAPIPlainArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; - TaggedArray *keys = TaggedArray::Cast(GetKeys().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *keys = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); uint32_t len = static_cast(GetLength()); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { CString str; - KeyToStd(str, keys->Get(i)); - vec.emplace_back(str, values->Get(i)); + KeyToStd(thread, str, keys->Get(thread, i)); + vec.emplace_back(str, values->Get(thread, i)); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSTaggedValue::DumpForSnapshot(std::vector &vec, bool isVmMode) const +void JSTaggedValue::DumpForSnapshot(const JSThread *thread, std::vector &vec, bool isVmMode) const { if (IsHeapObject()) { - return DumpObject(GetTaggedObject(), vec, isVmMode); + return DumpObject(thread, GetTaggedObject(), vec, isVmMode); } LOG_ECMA(FATAL) << "this branch is unreachable"; UNREACHABLE(); } -void NumberDictionary::DumpForSnapshot(std::vector &vec) const +void NumberDictionary::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); vec.reserve(vec.size() + size); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(thread, hashIndex)); vec.emplace_back( static_cast(JSTaggedNumber(key).GetNumber()), val, Reference::ReferenceType::ELEMENT); } } } -void NameDictionary::DumpForSnapshot(std::vector &vec) const +void NameDictionary::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); vec.reserve(vec.size() + size); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(thread, hashIndex)); CString str; - KeyToStd(str, key); + KeyToStd(thread, str, key); vec.emplace_back(str, val); } } } -void GlobalDictionary::DumpForSnapshot(std::vector &vec) const +void GlobalDictionary::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int size = Size(); vec.reserve(vec.size() + size); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { CString str; - KeyToStd(str, key); - JSTaggedValue val = GetValue(hashIndex); + KeyToStd(thread, str, key); + JSTaggedValue val = GetValue(thread, hashIndex); vec.emplace_back(str, val); } } } -void LinkedHashSet::DumpForSnapshot(std::vector &vec) const +void LinkedHashSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfElements() + NumberOfDeletedElements(); vec.reserve(vec.size() + capacity); for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { CString str; - KeyToStd(str, key); + KeyToStd(thread, str, key); vec.emplace_back(str, JSTaggedValue::Hole()); } } } -void LinkedHashMap::DumpForSnapshot(std::vector &vec) const +void LinkedHashMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfElements() + NumberOfDeletedElements(); vec.reserve(vec.size() + capacity); for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + JSTaggedValue key(GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val = GetValue(hashIndex); + JSTaggedValue val = GetValue(thread, hashIndex); CString str; - KeyToStd(str, key); + KeyToStd(thread, str, key); vec.emplace_back(str, val); } } } -void TaggedHashArray::Dump(std::ostream &os) const +void TaggedHashArray::Dump(const JSThread *thread, std::ostream &os) const { - DumpArrayClass(this, os); + DumpArrayClass(thread, this, os); } -void TaggedHashArray::DumpForSnapshot(std::vector &vec) const +void TaggedHashArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int capacity = static_cast(GetLength()); vec.reserve(vec.size() + capacity); for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue value = Get(hashIndex); + JSTaggedValue value = Get(thread, hashIndex); if (!value.IsUndefined() && !value.IsHole() && !value.IsNull()) { LinkedNode *node = LinkedNode::Cast(value.GetTaggedObject()); - node->DumpForSnapshot(vec); + node->DumpForSnapshot(thread, vec); } } } template -void DumpForSnapshotTaggedTreeEntry(T tree, int index, std::vector &vec, bool isMap = false) +void DumpForSnapshotTaggedTreeEntry(const JSThread *thread, T tree, int index, std::vector &vec, bool isMap = false) { DISALLOW_GARBAGE_COLLECTION; if (isMap) { - vec.emplace_back("key", JSTaggedValue(tree->GetKey(index))); + vec.emplace_back("key", JSTaggedValue(tree->GetKey(thread, index))); } - vec.emplace_back("value", JSTaggedValue(tree->GetValue(index))); + vec.emplace_back("value", JSTaggedValue(tree->GetValue(thread, index))); vec.emplace_back("parent", JSTaggedValue(tree->GetParent(index))); vec.emplace_back("color", JSTaggedValue(static_cast(tree->GetColor(index)))); vec.emplace_back("left", tree->GetLeftChild(index)); vec.emplace_back("right", tree->GetRightChild(index)); } -void TaggedTreeMap::DumpForSnapshot(std::vector &vec) const +void TaggedTreeMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; - vec.emplace_back("Elements", TaggedArray::Get(NUMBER_OF_ELEMENTS_INDEX)); - vec.emplace_back("Delete", TaggedArray::Get(NUMBER_OF_HOLE_ENTRIES_INDEX)); - vec.emplace_back("Capacity", TaggedArray::Get(CAPACITY_INDEX)); - vec.emplace_back("RootNode", TaggedArray::Get(ROOT_INDEX)); - vec.emplace_back("CompareFunction", TaggedArray::Get(COMPARE_FUNCTION_INDEX)); + vec.emplace_back("Elements", TaggedArray::Get(thread, NUMBER_OF_ELEMENTS_INDEX)); + vec.emplace_back("Delete", TaggedArray::Get(thread, NUMBER_OF_HOLE_ENTRIES_INDEX)); + vec.emplace_back("Capacity", TaggedArray::Get(thread, CAPACITY_INDEX)); + vec.emplace_back("RootNode", TaggedArray::Get(thread, ROOT_INDEX)); + vec.emplace_back("CompareFunction", TaggedArray::Get(thread, COMPARE_FUNCTION_INDEX)); uint32_t capacity = NumberOfElements() + NumberOfDeletedElements(); vec.reserve(vec.size() + capacity); for (uint32_t index = 0; index < capacity; index++) { - JSTaggedValue key(GetKey(index)); + JSTaggedValue key(GetKey(thread, index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val = GetValue(index); + JSTaggedValue val = GetValue(thread, index); CString str; - KeyToStd(str, key); + KeyToStd(thread, str, key); vec.emplace_back(str, val); } else { - DumpForSnapshotTaggedTreeEntry(const_cast(this), index, vec, true); + DumpForSnapshotTaggedTreeEntry(thread, const_cast(this), index, vec, true); } } } -void TaggedTreeSet::DumpForSnapshot(std::vector &vec) const +void TaggedTreeSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; - vec.emplace_back("Elements", TaggedArray::Get(NUMBER_OF_ELEMENTS_INDEX)); - vec.emplace_back("Delete", TaggedArray::Get(NUMBER_OF_HOLE_ENTRIES_INDEX)); - vec.emplace_back("Capacity", TaggedArray::Get(CAPACITY_INDEX)); - vec.emplace_back("RootNode", TaggedArray::Get(ROOT_INDEX)); - vec.emplace_back("CompareFunction", TaggedArray::Get(COMPARE_FUNCTION_INDEX)); + vec.emplace_back("Elements", TaggedArray::Get(thread, NUMBER_OF_ELEMENTS_INDEX)); + vec.emplace_back("Delete", TaggedArray::Get(thread, NUMBER_OF_HOLE_ENTRIES_INDEX)); + vec.emplace_back("Capacity", TaggedArray::Get(thread, CAPACITY_INDEX)); + vec.emplace_back("RootNode", TaggedArray::Get(thread, ROOT_INDEX)); + vec.emplace_back("CompareFunction", TaggedArray::Get(thread, COMPARE_FUNCTION_INDEX)); uint32_t capacity = NumberOfElements() + NumberOfDeletedElements(); vec.reserve(vec.size() + capacity); for (uint32_t index = 0; index < capacity; index++) { - JSTaggedValue key(GetKey(index)); + JSTaggedValue key(GetKey(thread, index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { CString str; - KeyToStd(str, key); + KeyToStd(thread, str, key); vec.emplace_back(str, JSTaggedValue::Hole()); } else { - DumpForSnapshotTaggedTreeEntry(const_cast(this), index, vec, true); + DumpForSnapshotTaggedTreeEntry(thread, const_cast(this), index, vec, true); } } } -void TaggedDoubleList::DumpForSnapshot(std::vector &vec) const +void TaggedDoubleList::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfNodes(); vec.reserve(vec.size() + capacity); for (int index = 0; index < capacity; index++) { - JSTaggedValue val = GetElement(index); + JSTaggedValue val = GetElement(thread, index); CString str; - KeyToStd(str, JSTaggedValue(index)); + KeyToStd(thread, str, JSTaggedValue(index)); vec.emplace_back(str, val); } } -void TaggedSingleList::DumpForSnapshot(std::vector &vec) const +void TaggedSingleList::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; int capacity = NumberOfNodes(); vec.reserve(vec.size() + capacity); for (int index = 0; index < capacity; index++) { - JSTaggedValue val = GetElement(index); + JSTaggedValue val = GetElement(thread, index); CString str; - KeyToStd(str, JSTaggedValue(index)); + KeyToStd(thread, str, JSTaggedValue(index)); vec.emplace_back(str, val); } } -void JSObject::DumpForSnapshot(std::vector &vec) const +void JSObject::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; JSHClass *jshclass = GetJSHClass(); if (jshclass != nullptr) { - vec.emplace_back(CString("__proto__"), jshclass->GetPrototype()); + vec.emplace_back(CString("__proto__"), jshclass->GetPrototype(thread)); } - vec.emplace_back(CString("ArkInternalHash"), JSTaggedValue(GetHash())); - JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + vec.emplace_back(CString("ArkInternalHash"), JSTaggedValue(GetHash(thread))); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, this, HASH_OFFSET); if (JSTaggedValue(hashField).IsHeapObject()) { vec.emplace_back(CString("HashField"), JSTaggedValue(hashField)); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); vec.emplace_back("(object elements)", JSTaggedValue(elements)); if (elements->GetLength() == 0) { } else if (!elements->IsDictionaryMode()) { - DumpElementClass(elements, vec); + DumpElementClass(thread, elements, vec); } else { NumberDictionary *dict = NumberDictionary::Cast(elements); - dict->DumpForSnapshot(vec); + dict->DumpForSnapshot(thread, vec); } - TaggedArray *properties = TaggedArray::Cast(GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); if (IsJSGlobalObject()) { GlobalDictionary *dict = GlobalDictionary::Cast(properties); - dict->DumpForSnapshot(vec); + dict->DumpForSnapshot(thread, vec); return; } vec.emplace_back("(object properties)", JSTaggedValue(properties)); if ((!properties->IsDictionaryMode()) && (jshclass != nullptr)) { - JSTaggedValue attrs = jshclass->GetLayout(); + JSTaggedValue attrs = jshclass->GetLayout(thread); if (attrs.IsNull()) { return; } @@ -4785,592 +4792,592 @@ void JSObject::DumpForSnapshot(std::vector &vec) const int propNumber = static_cast(jshclass->NumberOfProps()); vec.reserve(vec.size() + propNumber); for (int i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); - PropertyAttributes attr = layoutInfo->GetAttr(i); + JSTaggedValue key = layoutInfo->GetKey(thread, i); + PropertyAttributes attr = layoutInfo->GetAttr(thread, i); ASSERT(i == static_cast(attr.GetOffset())); JSTaggedValue val; if (attr.IsInlinedProps()) { - val = GetPropertyInlinedPropsWithRep(i, attr); + val = GetPropertyInlinedPropsWithRep(thread, i, attr); } else { - val = properties->Get(i - static_cast(jshclass->GetInlinedProperties())); + val = properties->Get(thread, i - static_cast(jshclass->GetInlinedProperties())); } CString str; - KeyToStd(str, key); + KeyToStd(thread, str, key); vec.emplace_back(str, val); } } else { NameDictionary *dict = NameDictionary::Cast(properties); - dict->DumpForSnapshot(vec); + dict->DumpForSnapshot(thread, vec); } } -void JSHClass::DumpForSnapshot([[maybe_unused]] std::vector &vec) const +void JSHClass::DumpForSnapshot(const JSThread *thread, [[maybe_unused]] std::vector &vec) const { - vec.emplace_back(CString("__proto__"), GetPrototype()); - vec.emplace_back(CString("Layout"), GetLayout()); - vec.emplace_back(CString("Transitions"), GetTransitions()); - vec.emplace_back(CString("Parent"), GetParent()); - vec.emplace_back(CString("ProtoChangeMarker"), GetProtoChangeMarker()); - vec.emplace_back(CString("ProtoChangeDetails"), GetProtoChangeDetails()); - vec.emplace_back(CString("EnumCache"), GetEnumCache()); + vec.emplace_back(CString("__proto__"), GetPrototype(thread)); + vec.emplace_back(CString("Layout"), GetLayout(thread)); + vec.emplace_back(CString("Transitions"), GetTransitions(thread)); + vec.emplace_back(CString("Parent"), GetParent(thread)); + vec.emplace_back(CString("ProtoChangeMarker"), GetProtoChangeMarker(thread)); + vec.emplace_back(CString("ProtoChangeDetails"), GetProtoChangeDetails(thread)); + vec.emplace_back(CString("EnumCache"), GetEnumCache(thread)); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); vec.emplace_back(CString("BitField1"), JSTaggedValue(GetBitField1())); } -void JSFunction::DumpForSnapshot(std::vector &vec) const +void JSFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ProtoOrHClass"), GetProtoOrHClass()); - vec.emplace_back(CString("LexicalEnv"), GetLexicalEnv()); - vec.emplace_back(CString("RawProfileTypeInfo"), GetRawProfileTypeInfo()); - vec.emplace_back(CString("HomeObject"), GetHomeObject()); - vec.emplace_back(CString("Module"), GetModule()); - vec.emplace_back(CString("Method"), GetMethod()); - if ((!GetMethod().IsNull()) && (!GetMethod().IsUndefined())) { - vec.emplace_back(CString("FunctionKind"), JSTaggedValue(static_cast(GetFunctionKind()))); + vec.emplace_back(CString("ProtoOrHClass"), GetProtoOrHClass(thread)); + vec.emplace_back(CString("LexicalEnv"), GetLexicalEnv(thread)); + vec.emplace_back(CString("RawProfileTypeInfo"), GetRawProfileTypeInfo(thread)); + vec.emplace_back(CString("HomeObject"), GetHomeObject(thread)); + vec.emplace_back(CString("Module"), GetModule(thread)); + vec.emplace_back(CString("Method"), GetMethod(thread)); + if ((!GetMethod(thread).IsNull()) && (!GetMethod(thread).IsUndefined())) { + vec.emplace_back(CString("FunctionKind"), JSTaggedValue(static_cast(GetFunctionKind(thread)))); } - vec.emplace_back(CString("FunctionExtraInfo"), GetFunctionExtraInfo()); - vec.emplace_back(CString("Method"), GetMethod()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("FunctionExtraInfo"), GetFunctionExtraInfo(thread)); + vec.emplace_back(CString("Method"), GetMethod(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void Method::DumpForSnapshot(std::vector &vec) const +void Method::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("MethodName"), JSTaggedValue(GetMethodName())); - vec.emplace_back(CString("ConstantPool"), GetConstantPool()); + vec.emplace_back(CString("MethodName"), JSTaggedValue(GetMethodName(thread))); + vec.emplace_back(CString("ConstantPool"), GetConstantPool(thread)); } -void Program::DumpForSnapshot(std::vector &vec) const +void Program::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("MainFunction"), GetMainFunction()); + vec.emplace_back(CString("MainFunction"), GetMainFunction(thread)); } -void LinkedNode::DumpForSnapshot(std::vector &vec) const +void LinkedNode::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSTaggedValue next = GetNext(); + JSTaggedValue next = GetNext(thread); if (!next.IsUndefined() && !next.IsHole() && !next.IsNull()) { LinkedNode *nextNode = LinkedNode::Cast(next.GetTaggedObject()); vec.emplace_back(CString("Next"), next); - nextNode->DumpForSnapshot(vec); + nextNode->DumpForSnapshot(thread, vec); } - vec.emplace_back(CString("Key"), GetKey()); - JSTaggedValue key = GetKey(); + vec.emplace_back(CString("Key"), GetKey(thread)); + JSTaggedValue key = GetKey(thread); CString str; - KeyToStd(str, key); - vec.emplace_back(str, GetValue()); + KeyToStd(thread, str, key); + vec.emplace_back(str, GetValue(thread)); } -void ConstantPool::DumpForSnapshot(std::vector &vec) const +void ConstantPool::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpArrayClass(this, vec); + DumpArrayClass(thread, this, vec); } -void ProfileTypeInfoCell::DumpForSnapshot(std::vector &vec) const +void ProfileTypeInfoCell::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Value"), GetValue()); - vec.emplace_back(CString("Handle"), GetHandle()); + vec.emplace_back(CString("Value"), GetValue(thread)); + vec.emplace_back(CString("Handle"), GetHandle(thread)); } -void FunctionTemplate::DumpForSnapshot(std::vector &vec) const +void FunctionTemplate::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Method"), GetMethod()); - vec.emplace_back(CString("Module"), GetModule()); - vec.emplace_back(CString("RawProfileTypeInfo"), GetRawProfileTypeInfo()); + vec.emplace_back(CString("Method"), GetMethod(thread)); + vec.emplace_back(CString("Module"), GetModule(thread)); + vec.emplace_back(CString("RawProfileTypeInfo"), GetRawProfileTypeInfo(thread)); vec.emplace_back(CString("Length"), JSTaggedValue(GetLength())); } -void ExtraProfileTypeInfo::DumpForSnapshot(std::vector &vec) const +void ExtraProfileTypeInfo::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Receiver"), GetReceiverObject()); - vec.emplace_back(CString("Holder"), GetHolderObject()); + vec.emplace_back(CString("Receiver"), GetReceiverObject(thread)); + vec.emplace_back(CString("Holder"), GetHolderObject(thread)); } -void VTable::DumpForSnapshot(std::vector &vec) const +void VTable::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpArrayClass(this, vec); + DumpArrayClass(thread, this, vec); } -void ProfileTypeInfo::DumpForSnapshot(std::vector &vec) const +void ProfileTypeInfo::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; uint32_t len = GetIcSlotLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { - JSTaggedValue val(Get(i)); + JSTaggedValue val(Get(thread, i)); CString str = ToCString(i); vec.emplace_back(str, val); } } -void COWTaggedArray::DumpForSnapshot(std::vector &vec) const +void COWTaggedArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpArrayClass(this, vec); + DumpArrayClass(thread, this, vec); } -void MutantTaggedArray::DumpForSnapshot(std::vector &vec) const +void MutantTaggedArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpMutantTaggedArrayClass(this, vec); + DumpMutantTaggedArrayClass(thread, this, vec); } -void COWMutantTaggedArray::DumpForSnapshot(std::vector &vec) const +void COWMutantTaggedArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpCOWMutantTaggedArrayClass(this, vec); + DumpCOWMutantTaggedArrayClass(thread, this, vec); } -void JSBoundFunction::DumpForSnapshot(std::vector &vec) const +void JSBoundFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); - vec.emplace_back(CString("Method"), GetMethod()); - vec.emplace_back(CString("BoundTarget"), GetBoundTarget()); - vec.emplace_back(CString("BoundThis"), GetBoundThis()); - vec.emplace_back(CString("BoundArguments"), GetBoundArguments()); + JSObject::DumpForSnapshot(thread, vec); + vec.emplace_back(CString("Method"), GetMethod(thread)); + vec.emplace_back(CString("BoundTarget"), GetBoundTarget(thread)); + vec.emplace_back(CString("BoundThis"), GetBoundThis(thread)); + vec.emplace_back(CString("BoundArguments"), GetBoundArguments(thread)); } -void JSPrimitiveRef::DumpForSnapshot(std::vector &vec) const +void JSPrimitiveRef::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("subValue"), GetValue()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("subValue"), GetValue(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void BigInt::DumpForSnapshot(std::vector &vec) const +void BigInt::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("Length"), JSTaggedValue(GetLength())); vec.emplace_back(CString("Sign"), JSTaggedValue(GetSign())); } -void JSDate::DumpForSnapshot(std::vector &vec) const +void JSDate::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("time"), GetTime()); - vec.emplace_back(CString("localOffset"), GetLocalOffset()); + vec.emplace_back(CString("time"), GetTime(thread)); + vec.emplace_back(CString("localOffset"), GetLocalOffset(thread)); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSMap::DumpForSnapshot(std::vector &vec) const +void JSMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetLinkedMap().IsInvalidValue())) { - LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject()); - vec.emplace_back("linkedmap", GetLinkedMap()); - map->DumpForSnapshot(vec); + if (!(GetLinkedMap(thread).IsInvalidValue())) { + LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject()); + vec.emplace_back("linkedmap", GetLinkedMap(thread)); + map->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedMap::DumpForSnapshot(std::vector &vec) const +void JSSharedMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject()); - vec.emplace_back("linkedmap", GetLinkedMap()); + LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject()); + vec.emplace_back("linkedmap", GetLinkedMap(thread)); vec.emplace_back("ModRecord", JSTaggedValue(GetModRecord())); - map->DumpForSnapshot(vec); + map->DumpForSnapshot(thread, vec); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSForInIterator::DumpForSnapshot(std::vector &vec) const +void JSForInIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Object"), GetObject()); - vec.emplace_back(CString("CachedHclass"), GetCachedHClass()); - vec.emplace_back(CString("Keys"), GetKeys()); + vec.emplace_back(CString("Object"), GetObject(thread)); + vec.emplace_back(CString("CachedHclass"), GetCachedHClass(thread)); + vec.emplace_back(CString("Keys"), GetKeys(thread)); vec.emplace_back(CString("Index"), JSTaggedValue(GetIndex())); vec.emplace_back(CString("Length"), JSTaggedValue(GetLength())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSMapIterator::DumpForSnapshot(std::vector &vec) const +void JSMapIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedMap().IsInvalidValue())) { - LinkedHashMap *map = LinkedHashMap::Cast(GetIteratedMap().GetTaggedObject()); - vec.emplace_back("iteratedmap", GetIteratedMap()); - map->DumpForSnapshot(vec); + if (!(GetIteratedMap(thread).IsInvalidValue())) { + LinkedHashMap *map = LinkedHashMap::Cast(GetIteratedMap(thread).GetTaggedObject()); + vec.emplace_back("iteratedmap", GetIteratedMap(thread)); + map->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedMapIterator::DumpForSnapshot(std::vector &vec) const +void JSSharedMapIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSSharedMap *iteratedMap = JSSharedMap::Cast(GetIteratedMap().GetTaggedObject()); - LinkedHashMap *map = LinkedHashMap::Cast(iteratedMap->GetLinkedMap().GetTaggedObject()); - vec.emplace_back("iteratedmap", GetIteratedMap()); - map->DumpForSnapshot(vec); + JSSharedMap *iteratedMap = JSSharedMap::Cast(GetIteratedMap(thread).GetTaggedObject()); + LinkedHashMap *map = LinkedHashMap::Cast(iteratedMap->GetLinkedMap(thread).GetTaggedObject()); + vec.emplace_back("iteratedmap", GetIteratedMap(thread)); + map->DumpForSnapshot(thread, vec); vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSet::DumpForSnapshot(std::vector &vec) const +void JSSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetLinkedSet().IsInvalidValue())) { - LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject()); - vec.emplace_back("linkedset", GetLinkedSet()); - set->DumpForSnapshot(vec); + if (!(GetLinkedSet(thread).IsInvalidValue())) { + LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject()); + vec.emplace_back("linkedset", GetLinkedSet(thread)); + set->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedSet::DumpForSnapshot(std::vector &vec) const +void JSSharedSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject()); - vec.emplace_back("linkedset", GetLinkedSet()); + LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject()); + vec.emplace_back("linkedset", GetLinkedSet(thread)); vec.emplace_back("ModRecord", JSTaggedValue(GetModRecord())); - set->DumpForSnapshot(vec); + set->DumpForSnapshot(thread, vec); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSWeakMap::DumpForSnapshot(std::vector &vec) const +void JSWeakMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetLinkedMap().IsInvalidValue())) { - LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject()); - vec.emplace_back("linkedmap", GetLinkedMap()); - map->DumpForSnapshot(vec); + if (!(GetLinkedMap(thread).IsInvalidValue())) { + LinkedHashMap *map = LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject()); + vec.emplace_back("linkedmap", GetLinkedMap(thread)); + map->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSWeakSet::DumpForSnapshot(std::vector &vec) const +void JSWeakSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetLinkedSet().IsInvalidValue())) { - LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject()); - vec.emplace_back("linkeset", GetLinkedSet()); - set->DumpForSnapshot(vec); + if (!(GetLinkedSet(thread).IsInvalidValue())) { + LinkedHashSet *set = LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject()); + vec.emplace_back("linkeset", GetLinkedSet(thread)); + set->DumpForSnapshot(thread, vec); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSWeakRef::DumpForSnapshot(std::vector &vec) const +void JSWeakRef::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("WeakObject"), GetWeakObject()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("WeakObject"), GetWeakObject(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSFinalizationRegistry::DumpForSnapshot(std::vector &vec) const +void JSFinalizationRegistry::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("CleanupCallback"), GetCleanupCallback()); - if (!(GetMaybeUnregister().IsInvalidValue())) { - LinkedHashMap *map = LinkedHashMap::Cast(GetMaybeUnregister().GetTaggedObject()); - vec.emplace_back(CString("MaybeUnregister"), GetMaybeUnregister()); - map->DumpForSnapshot(vec); + vec.emplace_back(CString("CleanupCallback"), GetCleanupCallback(thread)); + if (!(GetMaybeUnregister(thread).IsInvalidValue())) { + LinkedHashMap *map = LinkedHashMap::Cast(GetMaybeUnregister(thread).GetTaggedObject()); + vec.emplace_back(CString("MaybeUnregister"), GetMaybeUnregister(thread)); + map->DumpForSnapshot(thread, vec); } - vec.emplace_back(CString("Next"), GetNext()); - vec.emplace_back(CString("Prev"), GetPrev()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Next"), GetNext(thread)); + vec.emplace_back(CString("Prev"), GetPrev(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void CellRecord::DumpForSnapshot(std::vector &vec) const +void CellRecord::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("WeakRefTarget"), GetWeakRefTarget()); - vec.emplace_back(CString("HeldValue"), GetHeldValue()); + vec.emplace_back(CString("WeakRefTarget"), GetWeakRefTarget(thread)); + vec.emplace_back(CString("HeldValue"), GetHeldValue(thread)); } -void JSSetIterator::DumpForSnapshot(std::vector &vec) const +void JSSetIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedSet().IsInvalidValue())) { - LinkedHashSet *set = LinkedHashSet::Cast(GetIteratedSet().GetTaggedObject()); - vec.emplace_back("iteratedset", GetIteratedSet()); - set->DumpForSnapshot(vec); + if (!(GetIteratedSet(thread).IsInvalidValue())) { + LinkedHashSet *set = LinkedHashSet::Cast(GetIteratedSet(thread).GetTaggedObject()); + vec.emplace_back("iteratedset", GetIteratedSet(thread)); + set->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedSetIterator::DumpForSnapshot(std::vector &vec) const +void JSSharedSetIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSSharedSet *iteratedSet = JSSharedSet::Cast(GetIteratedSet().GetTaggedObject()); - LinkedHashSet *set = LinkedHashSet::Cast(iteratedSet->GetLinkedSet().GetTaggedObject()); - vec.emplace_back("iteratedset", GetIteratedSet()); - set->DumpForSnapshot(vec); + JSSharedSet *iteratedSet = JSSharedSet::Cast(GetIteratedSet(thread).GetTaggedObject()); + LinkedHashSet *set = LinkedHashSet::Cast(iteratedSet->GetLinkedSet(thread).GetTaggedObject()); + vec.emplace_back("iteratedset", GetIteratedSet(thread)); + set->DumpForSnapshot(thread, vec); vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSArray::DumpForSnapshot(std::vector &vec) const +void JSArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("Length"), JSTaggedValue(GetLength())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedArray::DumpForSnapshot(std::vector &vec) const +void JSSharedArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back("ModRecord: ", JSTaggedValue(GetModRecord())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIArrayList::DumpForSnapshot(std::vector &vec) const +void JSAPIArrayList::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("Length"), JSTaggedValue(GetLength())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIArrayListIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIArrayListIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedArrayList().IsInvalidValue())) { - JSAPIArrayList *arraylist = JSAPIArrayList::Cast(GetIteratedArrayList().GetTaggedObject()); - vec.emplace_back("iteratedlist", GetIteratedArrayList()); - arraylist->DumpForSnapshot(vec); + if (!(GetIteratedArrayList(thread).IsInvalidValue())) { + JSAPIArrayList *arraylist = JSAPIArrayList::Cast(GetIteratedArrayList(thread).GetTaggedObject()); + vec.emplace_back("iteratedlist", GetIteratedArrayList(thread)); + arraylist->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILightWeightMap::DumpForSnapshot(std::vector &vec) const +void JSAPILightWeightMap::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; - vec.emplace_back("Hashes", GetHashes()); - vec.emplace_back("Keys", GetKeys()); - TaggedArray *keys = TaggedArray::Cast(GetKeys().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + vec.emplace_back("Hashes", GetHashes(thread)); + vec.emplace_back("Keys", GetKeys(thread)); + TaggedArray *keys = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); uint32_t len = static_cast(GetLength()); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { CString str; - KeyToStd(str, keys->Get(i)); - vec.emplace_back(str, values->Get(i)); + KeyToStd(thread, str, keys->Get(thread, i)); + vec.emplace_back(str, values->Get(thread, i)); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILightWeightMapIterator::DumpForSnapshot(std::vector &vec) const +void JSAPILightWeightMapIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedLightWeightMap().IsInvalidValue())) { + if (!(GetIteratedLightWeightMap(thread).IsInvalidValue())) { JSAPILightWeightMap *map = - JSAPILightWeightMap::Cast(GetIteratedLightWeightMap().GetTaggedObject()); - vec.emplace_back("iteratedmap", GetIteratedLightWeightMap()); - map->DumpForSnapshot(vec); + JSAPILightWeightMap::Cast(GetIteratedLightWeightMap(thread).GetTaggedObject()); + vec.emplace_back("iteratedmap", GetIteratedLightWeightMap(thread)); + map->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIQueue::DumpForSnapshot(std::vector &vec) const +void JSAPIQueue::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Length"), JSTaggedValue(GetLength())); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Length"), JSTaggedValue(GetLength(thread))); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIQueueIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIQueueIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedQueue().IsInvalidValue())) { - JSAPIQueue *queue = JSAPIQueue::Cast(GetIteratedQueue().GetTaggedObject()); - vec.emplace_back("iteratedqueue", GetIteratedQueue()); - queue->DumpForSnapshot(vec); + if (!(GetIteratedQueue(thread).IsInvalidValue())) { + JSAPIQueue *queue = JSAPIQueue::Cast(GetIteratedQueue(thread).GetTaggedObject()); + vec.emplace_back("iteratedqueue", GetIteratedQueue(thread)); + queue->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIDeque::DumpForSnapshot(std::vector &vec) const +void JSAPIDeque::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIDequeIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIDequeIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedDeque().IsInvalidValue())) { - JSAPIDeque *deque = JSAPIDeque::Cast(GetIteratedDeque().GetTaggedObject()); - vec.emplace_back("iterateddeque", GetIteratedDeque()); - deque->DumpForSnapshot(vec); + if (!(GetIteratedDeque(thread).IsInvalidValue())) { + JSAPIDeque *deque = JSAPIDeque::Cast(GetIteratedDeque(thread).GetTaggedObject()); + vec.emplace_back("iterateddeque", GetIteratedDeque(thread)); + deque->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILightWeightSet::DumpForSnapshot(std::vector &vec) const +void JSAPILightWeightSet::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { DISALLOW_GARBAGE_COLLECTION; - TaggedArray *hashes = TaggedArray::Cast(GetHashes().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *hashes = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); uint32_t len = GetLength(); vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { CString str; - KeyToStd(str, hashes->Get(i)); - vec.emplace_back(str, values->Get(i)); + KeyToStd(thread, str, hashes->Get(thread, i)); + vec.emplace_back(str, values->Get(thread, i)); } - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPILightWeightSetIterator::DumpForSnapshot(std::vector &vec) const +void JSAPILightWeightSetIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedLightWeightSet().IsInvalidValue())) { + if (!(GetIteratedLightWeightSet(thread).IsInvalidValue())) { JSAPILightWeightSet *set = - JSAPILightWeightSet::Cast(GetIteratedLightWeightSet().GetTaggedObject()); - vec.emplace_back("iteratedset", GetIteratedLightWeightSet()); - set->DumpForSnapshot(vec); + JSAPILightWeightSet::Cast(GetIteratedLightWeightSet(thread).GetTaggedObject()); + vec.emplace_back("iteratedset", GetIteratedLightWeightSet(thread)); + set->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIStack::DumpForSnapshot(std::vector &vec) const +void JSAPIStack::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIStackIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIStackIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedStack().IsInvalidValue())) { - JSAPIStack *stack = JSAPIStack::Cast(GetIteratedStack().GetTaggedObject()); - vec.emplace_back("iteratedstack", GetIteratedStack()); - stack->DumpForSnapshot(vec); + if (!(GetIteratedStack(thread).IsInvalidValue())) { + JSAPIStack *stack = JSAPIStack::Cast(GetIteratedStack(thread).GetTaggedObject()); + vec.emplace_back("iteratedstack", GetIteratedStack(thread)); + stack->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSArrayIterator::DumpForSnapshot(std::vector &vec) const +void JSArrayIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedArray().IsInvalidValue())) { - JSArray *array = JSArray::Cast(GetIteratedArray().GetTaggedObject()); - vec.emplace_back("iteratedarray", GetIteratedArray()); - array->DumpForSnapshot(vec); + if (!(GetIteratedArray(thread).IsInvalidValue())) { + JSArray *array = JSArray::Cast(GetIteratedArray(thread).GetTaggedObject()); + vec.emplace_back("iteratedarray", GetIteratedArray(thread)); + array->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedArrayIterator::DumpForSnapshot(std::vector &vec) const +void JSSharedArrayIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSSharedArray *array = JSSharedArray::Cast(GetIteratedArray().GetTaggedObject()); - vec.emplace_back("iteratedarray", GetIteratedArray()); - array->DumpForSnapshot(vec); + JSSharedArray *array = JSSharedArray::Cast(GetIteratedArray(thread).GetTaggedObject()); + vec.emplace_back("iteratedarray", GetIteratedArray(thread)); + array->DumpForSnapshot(thread, vec); vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); vec.emplace_back(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIVector::DumpForSnapshot(std::vector &vec) const +void JSAPIVector::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIVectorIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIVectorIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - if (!(GetIteratedVector().IsInvalidValue())) { - JSAPIVector *vector = JSAPIVector::Cast(GetIteratedVector().GetTaggedObject()); - vec.emplace_back("iteratedvector", GetIteratedVector()); - vector->DumpForSnapshot(vec); + if (!(GetIteratedVector(thread).IsInvalidValue())) { + JSAPIVector *vector = JSAPIVector::Cast(GetIteratedVector(thread).GetTaggedObject()); + vec.emplace_back("iteratedvector", GetIteratedVector(thread)); + vector->DumpForSnapshot(thread, vec); } vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIBitVector::DumpForSnapshot(std::vector &vec) const +void JSAPIBitVector::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIBitVectorIterator::DumpForSnapshot(std::vector &vec) const +void JSAPIBitVectorIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSAPIVector *vector = JSAPIVector::Cast(GetIteratedBitVector().GetTaggedObject()); - vec.emplace_back("iteratedbitvector", GetIteratedBitVector()); - vector->DumpForSnapshot(vec); + JSAPIVector *vector = JSAPIVector::Cast(GetIteratedBitVector(thread).GetTaggedObject()); + vec.emplace_back("iteratedbitvector", GetIteratedBitVector(thread)); + vector->DumpForSnapshot(thread, vec); vec.emplace_back(CString("NextIndex"), JSTaggedValue(GetNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAPIFastBuffer::DumpForSnapshot(std::vector &vec) const +void JSAPIFastBuffer::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSStringIterator::DumpForSnapshot(std::vector &vec) const +void JSStringIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("IteratedString"), GetIteratedString()); + vec.emplace_back(CString("IteratedString"), GetIteratedString(thread)); vec.emplace_back(CString("StringIteratorNextIndex"), JSTaggedValue(GetStringIteratorNextIndex())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSTypedArray::DumpForSnapshot(std::vector &vec) const +void JSTypedArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 5; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("viewed-array-buffer"), GetViewedArrayBufferOrByteArray()); - vec.emplace_back(CString("typed-array-name"), GetTypedArrayName()); + vec.emplace_back(CString("viewed-array-buffer"), GetViewedArrayBufferOrByteArray(thread)); + vec.emplace_back(CString("typed-array-name"), GetTypedArrayName(thread)); vec.emplace_back(CString("byte-length"), JSTaggedValue(GetByteLength())); vec.emplace_back(CString("byte-offset"), JSTaggedValue(GetByteOffset())); vec.emplace_back(CString("array-length"), JSTaggedValue(GetArrayLength())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSharedTypedArray::DumpForSnapshot(std::vector &vec) const +void JSSharedTypedArray::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 5; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("viewed-array-buffer"), GetViewedArrayBufferOrByteArray()); - vec.emplace_back(CString("typed-array-name"), GetTypedArrayName()); + vec.emplace_back(CString("viewed-array-buffer"), GetViewedArrayBufferOrByteArray(thread)); + vec.emplace_back(CString("typed-array-name"), GetTypedArrayName(thread)); vec.emplace_back(CString("byte-length"), JSTaggedValue(GetByteLength())); vec.emplace_back(CString("byte-offset"), JSTaggedValue(GetByteOffset())); vec.emplace_back(CString("array-length"), JSTaggedValue(GetArrayLength())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void ByteArray::DumpForSnapshot(std::vector &vec) const +void ByteArray::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("array-length"), JSTaggedValue(GetArrayLength())); vec.emplace_back(CString("byte-length"), JSTaggedValue(GetByteLength())); } -void JSRegExp::DumpForSnapshot(std::vector &vec) const +void JSRegExp::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ByteCodeBuffer"), GetByteCodeBuffer()); - vec.emplace_back(CString("originalSource"), GetOriginalSource()); - vec.emplace_back(CString("originalFlags"), GetOriginalFlags()); - vec.emplace_back(CString("groupName"), GetGroupName()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("ByteCodeBuffer"), GetByteCodeBuffer(thread)); + vec.emplace_back(CString("originalSource"), GetOriginalSource(thread)); + vec.emplace_back(CString("originalFlags"), GetOriginalFlags(thread)); + vec.emplace_back(CString("groupName"), GetGroupName(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSRegExpIterator::DumpForSnapshot(std::vector &vec) const +void JSRegExpIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("IteratingRegExp"), GetIteratingRegExp()); - vec.emplace_back(CString("IteratedString"), GetIteratedString()); + vec.emplace_back(CString("IteratingRegExp"), GetIteratingRegExp(thread)); + vec.emplace_back(CString("IteratedString"), GetIteratedString(thread)); vec.emplace_back(CString("Global"), JSTaggedValue(GetGlobal())); vec.emplace_back(CString("Unicode"), JSTaggedValue(GetUnicode())); vec.emplace_back(CString("Done"), JSTaggedValue(GetDone())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSProxy::DumpForSnapshot(std::vector &vec) const +void JSProxy::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("target"), GetTarget()); - vec.emplace_back(CString("handler"), GetHandler()); - vec.emplace_back(CString("Method"), GetMethod()); - vec.emplace_back(CString("PrivateField"), GetPrivateField()); + vec.emplace_back(CString("target"), GetTarget(thread)); + vec.emplace_back(CString("handler"), GetHandler(thread)); + vec.emplace_back(CString("Method"), GetMethod(thread)); + vec.emplace_back(CString("PrivateField"), GetPrivateField(thread)); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); } -void JSSymbol::DumpForSnapshot(std::vector &vec) const +void JSSymbol::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("hash-field"), JSTaggedValue(GetHashField())); vec.emplace_back(CString("flags"), JSTaggedValue(GetFlags())); - vec.emplace_back(CString("description"), GetDescription()); + vec.emplace_back(CString("description"), GetDescription(thread)); } -void AccessorData::DumpForSnapshot(std::vector &vec) const +void AccessorData::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { if (GetClass()->GetObjectType() == JSType::INTERNAL_ACCESSOR) { vec.emplace_back(CString("getter"), JSTaggedValue(InternalAccessor::ConstCast(this)->GetGetter())); @@ -5378,26 +5385,26 @@ void AccessorData::DumpForSnapshot(std::vector &vec) const return; } - vec.emplace_back(CString("getter"), GetGetter()); - vec.emplace_back(CString("setter"), GetSetter()); + vec.emplace_back(CString("getter"), GetGetter(thread)); + vec.emplace_back(CString("setter"), GetSetter(thread)); } -void LexicalEnv::DumpForSnapshot(std::vector &vec) const +void LexicalEnv::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpArrayClass(this, vec); + DumpArrayClass(thread, this, vec); } -void SFunctionEnv::DumpForSnapshot(std::vector &vec) const +void SFunctionEnv::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpArrayClass(this, vec); + DumpArrayClass(thread, this, vec); } -void SendableEnv::DumpForSnapshot(std::vector &vec) const +void SendableEnv::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - DumpArrayClass(this, vec); + DumpArrayClass(thread, this, vec); } -void GlobalEnv::DumpForSnapshot(std::vector &vec) const +void GlobalEnv::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { auto globalConst = GetJSThread()->GlobalConstants(); #define DUMP_ENV_FIELD(type, name, _) vec.emplace_back(#name, GetRaw##name().GetTaggedValue()); @@ -5417,628 +5424,628 @@ void GlobalEnv::DumpForSnapshot(std::vector &vec) const #undef DUMP_CONST_STRING } -void JSDataView::DumpForSnapshot(std::vector &vec) const +void JSDataView::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("data-view"), GetDataView()); - vec.emplace_back(CString("buffer"), GetViewedArrayBuffer()); + vec.emplace_back(CString("data-view"), GetDataView(thread)); + vec.emplace_back(CString("buffer"), GetViewedArrayBuffer(thread)); vec.emplace_back(CString("byte-length"), JSTaggedValue(GetByteLength())); vec.emplace_back(CString("byte-offset"), JSTaggedValue(GetByteOffset())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSArrayBuffer::DumpForSnapshot(std::vector &vec) const +void JSArrayBuffer::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("buffer-data"), GetArrayBufferData()); + vec.emplace_back(CString("buffer-data"), GetArrayBufferData(thread)); vec.emplace_back(CString("byte-length"), JSTaggedValue(GetArrayBufferByteLength())); vec.emplace_back(CString("shared"), JSTaggedValue(GetShared())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSSendableArrayBuffer::DumpForSnapshot(std::vector &vec) const +void JSSendableArrayBuffer::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("buffer-data"), GetArrayBufferData()); + vec.emplace_back(CString("buffer-data"), GetArrayBufferData(thread)); vec.emplace_back(CString("byte-length"), JSTaggedValue(GetArrayBufferByteLength())); vec.emplace_back(CString("shared"), JSTaggedValue(GetShared())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void PromiseReaction::DumpForSnapshot(std::vector &vec) const +void PromiseReaction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("promise-capability"), GetPromiseCapability()); - vec.emplace_back(CString("handler"), GetHandler()); + vec.emplace_back(CString("promise-capability"), GetPromiseCapability(thread)); + vec.emplace_back(CString("handler"), GetHandler(thread)); vec.emplace_back(CString("type"), JSTaggedValue(static_cast(GetType()))); } -void PromiseCapability::DumpForSnapshot(std::vector &vec) const +void PromiseCapability::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("promise"), GetPromise()); - vec.emplace_back(CString("resolve"), GetResolve()); - vec.emplace_back(CString("reject"), GetReject()); + vec.emplace_back(CString("promise"), GetPromise(thread)); + vec.emplace_back(CString("resolve"), GetResolve(thread)); + vec.emplace_back(CString("reject"), GetReject(thread)); } -void PromiseIteratorRecord::DumpForSnapshot(std::vector &vec) const +void PromiseIteratorRecord::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("iterator"), GetIterator()); + vec.emplace_back(CString("iterator"), GetIterator(thread)); vec.emplace_back(CString("done"), JSTaggedValue(GetDone())); } -void PromiseRecord::DumpForSnapshot(std::vector &vec) const +void PromiseRecord::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("value"), GetValue()); + vec.emplace_back(CString("value"), GetValue(thread)); } -void ResolvingFunctionsRecord::DumpForSnapshot(std::vector &vec) const +void ResolvingFunctionsRecord::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("resolve-function"), GetResolveFunction()); - vec.emplace_back(CString("reject-function"), GetRejectFunction()); + vec.emplace_back(CString("resolve-function"), GetResolveFunction(thread)); + vec.emplace_back(CString("reject-function"), GetRejectFunction(thread)); } -void AsyncGeneratorRequest::DumpForSnapshot(std::vector &vec) const +void AsyncGeneratorRequest::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("completion"), GetCompletion()); - vec.emplace_back(CString("capability"), GetCapability()); + vec.emplace_back(CString("completion"), GetCompletion(thread)); + vec.emplace_back(CString("capability"), GetCapability(thread)); } -void AsyncIteratorRecord::DumpForSnapshot(std::vector &vec) const +void AsyncIteratorRecord::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("iterator"), GetIterator()); - vec.emplace_back(CString("nextmethod"), GetNextMethod()); + vec.emplace_back(CString("iterator"), GetIterator(thread)); + vec.emplace_back(CString("nextmethod"), GetNextMethod(thread)); vec.emplace_back(CString("done"), JSTaggedValue(GetDone())); } -void JSAsyncFromSyncIterator::DumpForSnapshot(std::vector &vec) const +void JSAsyncFromSyncIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("synciteratorrecord"), GetSyncIteratorRecord()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("synciteratorrecord"), GetSyncIteratorRecord(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSAsyncFromSyncIterUnwarpFunction::DumpForSnapshot(std::vector &vec) const +void JSAsyncFromSyncIterUnwarpFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("done"), JSTaggedValue(GetDone())); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("done"), JSTaggedValue(GetDone(thread))); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromise::DumpForSnapshot(std::vector &vec) const +void JSPromise::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("promise-state"), JSTaggedValue(static_cast(GetPromiseState()))); - vec.emplace_back(CString("promise-result"), GetPromiseResult()); - vec.emplace_back(CString("promise-fulfill-reactions"), GetPromiseFulfillReactions()); - vec.emplace_back(CString("promise-reject-reactions"), GetPromiseRejectReactions()); + vec.emplace_back(CString("promise-result"), GetPromiseResult(thread)); + vec.emplace_back(CString("promise-fulfill-reactions"), GetPromiseFulfillReactions(thread)); + vec.emplace_back(CString("promise-reject-reactions"), GetPromiseRejectReactions(thread)); vec.emplace_back(CString("promise-is-handled"), JSTaggedValue(GetPromiseIsHandled())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSPromiseReactionsFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseReactionsFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("promise"), GetPromise()); - vec.emplace_back(CString("already-resolved"), GetAlreadyResolved()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("promise"), GetPromise(thread)); + vec.emplace_back(CString("already-resolved"), GetAlreadyResolved(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSAsyncGeneratorResNextRetProRstFtn::DumpForSnapshot(std::vector &vec) const +void JSAsyncGeneratorResNextRetProRstFtn::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("async-generator-object"), GetAsyncGeneratorObject()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("async-generator-object"), GetAsyncGeneratorObject(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromiseExecutorFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseExecutorFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("capability"), GetCapability()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("capability"), GetCapability(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSAsyncModuleFulfilledFunction::DumpForSnapshot(std::vector &vec) const +void JSAsyncModuleFulfilledFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("module"), GetModule()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("module"), GetModule(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSAsyncModuleRejectedFunction::DumpForSnapshot(std::vector &vec) const +void JSAsyncModuleRejectedFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("module"), GetModule()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("module"), GetModule(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromiseAllResolveElementFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseAllResolveElementFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("index"), GetIndex()); - vec.emplace_back(CString("values"), GetValues()); - vec.emplace_back(CString("capabilities"), GetCapabilities()); - vec.emplace_back(CString("remaining-elements"), GetRemainingElements()); - vec.emplace_back(CString("already-called"), GetAlreadyCalled()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("index"), GetIndex(thread)); + vec.emplace_back(CString("values"), GetValues(thread)); + vec.emplace_back(CString("capabilities"), GetCapabilities(thread)); + vec.emplace_back(CString("remaining-elements"), GetRemainingElements(thread)); + vec.emplace_back(CString("already-called"), GetAlreadyCalled(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromiseAnyRejectElementFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseAnyRejectElementFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("index"), JSTaggedValue(GetIndex())); - vec.emplace_back(CString("errors"), GetErrors()); - vec.emplace_back(CString("capability"), GetCapability()); - vec.emplace_back(CString("remaining-elements"), GetRemainingElements()); - vec.emplace_back(CString("already-called"), GetAlreadyCalled()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("errors"), GetErrors(thread)); + vec.emplace_back(CString("capability"), GetCapability(thread)); + vec.emplace_back(CString("remaining-elements"), GetRemainingElements(thread)); + vec.emplace_back(CString("already-called"), GetAlreadyCalled(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromiseAllSettledElementFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseAllSettledElementFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("already-called"), GetAlreadyCalled()); + vec.emplace_back(CString("already-called"), GetAlreadyCalled(thread)); vec.emplace_back(CString("index"), JSTaggedValue(GetIndex())); - vec.emplace_back(CString("values"), GetValues()); - vec.emplace_back(CString("capability"), GetCapability()); - vec.emplace_back(CString("remaining-elements"), GetRemainingElements()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("values"), GetValues(thread)); + vec.emplace_back(CString("capability"), GetCapability(thread)); + vec.emplace_back(CString("remaining-elements"), GetRemainingElements(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromiseFinallyFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseFinallyFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("constructor"), GetConstructor()); - vec.emplace_back(CString("onFinally"), GetOnFinally()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("constructor"), GetConstructor(thread)); + vec.emplace_back(CString("onFinally"), GetOnFinally(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSPromiseValueThunkOrThrowerFunction::DumpForSnapshot(std::vector &vec) const +void JSPromiseValueThunkOrThrowerFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("result"), GetResult()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("result"), GetResult(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void MicroJobQueue::DumpForSnapshot(std::vector &vec) const +void MicroJobQueue::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("promise-job-queue"), GetPromiseJobQueue()); - vec.emplace_back(CString("script-job-queue"), GetScriptJobQueue()); + vec.emplace_back(CString("promise-job-queue"), GetPromiseJobQueue(thread)); + vec.emplace_back(CString("script-job-queue"), GetScriptJobQueue(thread)); } -void PendingJob::DumpForSnapshot(std::vector &vec) const +void PendingJob::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("job"), GetJob()); - vec.emplace_back(CString("arguments"), GetArguments()); + vec.emplace_back(CString("job"), GetJob(thread)); + vec.emplace_back(CString("arguments"), GetArguments(thread)); } -void CompletionRecord::DumpForSnapshot(std::vector &vec) const +void CompletionRecord::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("value"), GetValue()); + vec.emplace_back(CString("value"), GetValue(thread)); vec.emplace_back(CString("type"), JSTaggedValue(static_cast(GetType()))); } -void JSProxyRevocFunction::DumpForSnapshot(std::vector &vec) const +void JSProxyRevocFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("RevocableProxy"), GetRevocableProxy()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("RevocableProxy"), GetRevocableProxy(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSAsyncFunction::DumpForSnapshot(std::vector &vec) const +void JSAsyncFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSFunction::DumpForSnapshot(vec); + JSFunction::DumpForSnapshot(thread, vec); } -void JSAsyncAwaitStatusFunction::DumpForSnapshot(std::vector &vec) const +void JSAsyncAwaitStatusFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("AsyncContext"), GetAsyncContext()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("AsyncContext"), GetAsyncContext(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void JSGeneratorFunction::DumpForSnapshot(std::vector &vec) const +void JSGeneratorFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSFunction::DumpForSnapshot(vec); + JSFunction::DumpForSnapshot(thread, vec); } -void JSAsyncGeneratorFunction::DumpForSnapshot(std::vector &vec) const +void JSAsyncGeneratorFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - JSFunction::DumpForSnapshot(vec); + JSFunction::DumpForSnapshot(thread, vec); } -void JSIntlBoundFunction::DumpForSnapshot(std::vector &vec) const +void JSIntlBoundFunction::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("NumberFormat"), GetNumberFormat()); - vec.emplace_back(CString("DateTimeFormat"), GetDateTimeFormat()); - vec.emplace_back(CString("Collator"), GetCollator()); - JSFunction::DumpForSnapshot(vec); + vec.emplace_back(CString("NumberFormat"), GetNumberFormat(thread)); + vec.emplace_back(CString("DateTimeFormat"), GetDateTimeFormat(thread)); + vec.emplace_back(CString("Collator"), GetCollator(thread)); + JSFunction::DumpForSnapshot(thread, vec); } -void PropertyBox::DumpForSnapshot(std::vector &vec) const +void PropertyBox::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Value"), GetValue()); + vec.emplace_back(CString("Value"), GetValue(thread)); } -void PrototypeHandler::DumpForSnapshot(std::vector &vec) const +void PrototypeHandler::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo()); - vec.emplace_back(CString("ProtoCell"), GetProtoCell()); - vec.emplace_back(CString("Holder"), GetHolder()); + vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo(thread)); + vec.emplace_back(CString("ProtoCell"), GetProtoCell(thread)); + vec.emplace_back(CString("Holder"), GetHolder(thread)); } -void TransitionHandler::DumpForSnapshot(std::vector &vec) const +void TransitionHandler::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo()); - vec.emplace_back(CString("TransitionHClass"), GetTransitionHClass()); + vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo(thread)); + vec.emplace_back(CString("TransitionHClass"), GetTransitionHClass(thread)); } -void TransWithProtoHandler::DumpForSnapshot(std::vector &vec) const +void TransWithProtoHandler::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo()); - vec.emplace_back(CString("TransitionHClass"), GetTransitionHClass()); - vec.emplace_back(CString("ProtoCell"), GetProtoCell()); + vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo(thread)); + vec.emplace_back(CString("TransitionHClass"), GetTransitionHClass(thread)); + vec.emplace_back(CString("ProtoCell"), GetProtoCell(thread)); } -void StoreAOTHandler::DumpForSnapshot(std::vector &vec) const +void StoreAOTHandler::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo()); - vec.emplace_back(CString("ProtoCell"), GetProtoCell()); - vec.emplace_back(CString("Holder"), GetHolder()); + vec.emplace_back(CString("HandlerInfo"), GetHandlerInfo(thread)); + vec.emplace_back(CString("ProtoCell"), GetProtoCell(thread)); + vec.emplace_back(CString("Holder"), GetHolder(thread)); } -void JSRealm::DumpForSnapshot(std::vector &vec) const +void JSRealm::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Value"), GetValue()); - vec.emplace_back(CString("GLobalEnv"), GetGlobalEnv()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Value"), GetValue(thread)); + vec.emplace_back(CString("GLobalEnv"), GetGlobalEnv(thread)); + JSObject::DumpForSnapshot(thread, vec); } #ifdef ARK_SUPPORT_INTL -void JSIntl::DumpForSnapshot(std::vector &vec) const +void JSIntl::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("FallbackSymbol"), GetFallbackSymbol()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("FallbackSymbol"), GetFallbackSymbol(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSLocale::DumpForSnapshot(std::vector &vec) const +void JSLocale::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("IcuField"), GetIcuField()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSDateTimeFormat::DumpForSnapshot(std::vector &vec) const +void JSDateTimeFormat::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 11; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("Locale"), GetLocale()); - vec.emplace_back(CString("Calendar"), GetCalendar()); - vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem()); - vec.emplace_back(CString("TimeZone"), GetTimeZone()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); + vec.emplace_back(CString("Calendar"), GetCalendar(thread)); + vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem(thread)); + vec.emplace_back(CString("TimeZone"), GetTimeZone(thread)); vec.emplace_back(CString("HourCycle"), JSTaggedValue(static_cast(GetHourCycle()))); - vec.emplace_back(CString("LocaleIcu"), GetLocaleIcu()); - vec.emplace_back(CString("SimpleDateTimeFormatIcu"), GetSimpleDateTimeFormatIcu()); - vec.emplace_back(CString("Iso8601"), GetIso8601()); + vec.emplace_back(CString("LocaleIcu"), GetLocaleIcu(thread)); + vec.emplace_back(CString("SimpleDateTimeFormatIcu"), GetSimpleDateTimeFormatIcu(thread)); + vec.emplace_back(CString("Iso8601"), GetIso8601(thread)); vec.emplace_back(CString("DateStyle"), JSTaggedValue(static_cast(GetDateStyle()))); vec.emplace_back(CString("TimeStyle"), JSTaggedValue(static_cast(GetTimeStyle()))); - vec.emplace_back(CString("BoundFormat"), GetBoundFormat()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("BoundFormat"), GetBoundFormat(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSRelativeTimeFormat::DumpForSnapshot(std::vector &vec) const +void JSRelativeTimeFormat::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Locale"), GetLocale()); - vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); + vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem(thread)); vec.emplace_back(CString("Style"), JSTaggedValue(static_cast(GetStyle()))); vec.emplace_back(CString("Numeric"), JSTaggedValue(static_cast(GetNumeric()))); - vec.emplace_back(CString("IcuField"), GetIcuField()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSNumberFormat::DumpForSnapshot(std::vector &vec) const +void JSNumberFormat::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 20; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("Locale"), GetLocale()); - vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); + vec.emplace_back(CString("NumberingSystem"), GetNumberingSystem(thread)); vec.emplace_back(CString("Style"), JSTaggedValue(static_cast(GetStyle()))); - vec.emplace_back(CString("Currency"), GetCurrency()); + vec.emplace_back(CString("Currency"), GetCurrency(thread)); vec.emplace_back(CString("CurrencyDisplay"), JSTaggedValue(static_cast(GetCurrencyDisplay()))); vec.emplace_back(CString("CurrencySign"), JSTaggedValue(static_cast(GetCurrencySign()))); - vec.emplace_back(CString("Unit"), GetUnit()); + vec.emplace_back(CString("Unit"), GetUnit(thread)); vec.emplace_back(CString("UnitDisplay"), JSTaggedValue(static_cast(GetUnitDisplay()))); - vec.emplace_back(CString("MinimumIntegerDigits"), GetMinimumIntegerDigits()); - vec.emplace_back(CString("MinimumFractionDigits"), GetMinimumFractionDigits()); - vec.emplace_back(CString("MaximumFractionDigits"), GetMaximumFractionDigits()); - vec.emplace_back(CString("MinimumSignificantDigits"), GetMinimumSignificantDigits()); - vec.emplace_back(CString("MaximumSignificantDigits"), GetMaximumSignificantDigits()); - vec.emplace_back(CString("UseGrouping"), GetUseGrouping()); + vec.emplace_back(CString("MinimumIntegerDigits"), GetMinimumIntegerDigits(thread)); + vec.emplace_back(CString("MinimumFractionDigits"), GetMinimumFractionDigits(thread)); + vec.emplace_back(CString("MaximumFractionDigits"), GetMaximumFractionDigits(thread)); + vec.emplace_back(CString("MinimumSignificantDigits"), GetMinimumSignificantDigits(thread)); + vec.emplace_back(CString("MaximumSignificantDigits"), GetMaximumSignificantDigits(thread)); + vec.emplace_back(CString("UseGrouping"), GetUseGrouping(thread)); vec.emplace_back(CString("RoundingType"), JSTaggedValue(static_cast(GetRoundingType()))); vec.emplace_back(CString("Notation"), JSTaggedValue(static_cast(GetNotation()))); vec.emplace_back(CString("CompactDisplay"), JSTaggedValue(static_cast(GetCompactDisplay()))); vec.emplace_back(CString("SignDisplay"), JSTaggedValue(static_cast(GetSignDisplay()))); - vec.emplace_back(CString("BoundFormat"), GetBoundFormat()); - vec.emplace_back(CString("IcuField"), GetIcuField()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("BoundFormat"), GetBoundFormat(thread)); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSCollator::DumpForSnapshot(std::vector &vec) const +void JSCollator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 9; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("IcuField"), GetIcuField()); - vec.emplace_back(CString("Locale"), GetLocale()); - vec.emplace_back(CString("Collation"), GetCollation()); - vec.emplace_back(CString("BoundCompare"), GetBoundCompare()); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + vec.emplace_back(CString("Locale"), GetLocale(thread)); + vec.emplace_back(CString("Collation"), GetCollation(thread)); + vec.emplace_back(CString("BoundCompare"), GetBoundCompare(thread)); vec.emplace_back(CString("CaseFirst"), JSTaggedValue(static_cast(GetCaseFirst()))); vec.emplace_back(CString("Usage"), JSTaggedValue(static_cast(GetUsage()))); vec.emplace_back(CString("Sensitivity"), JSTaggedValue(static_cast(GetSensitivity()))); vec.emplace_back(CString("IgnorePunctuation"), JSTaggedValue(GetIgnorePunctuation())); vec.emplace_back(CString("Numeric"), JSTaggedValue(GetNumeric())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSPluralRules::DumpForSnapshot(std::vector &vec) const +void JSPluralRules::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 10; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("Locale"), GetLocale()); - vec.emplace_back(CString("MinimumIntegerDigits"), GetMinimumIntegerDigits()); - vec.emplace_back(CString("MinimumFractionDigits"), GetMinimumFractionDigits()); - vec.emplace_back(CString("MaximumFractionDigits"), GetMaximumFractionDigits()); - vec.emplace_back(CString("MinimumSignificantDigits"), GetMinimumSignificantDigits()); - vec.emplace_back(CString("MaximumSignificantDigits"), GetMaximumSignificantDigits()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); + vec.emplace_back(CString("MinimumIntegerDigits"), GetMinimumIntegerDigits(thread)); + vec.emplace_back(CString("MinimumFractionDigits"), GetMinimumFractionDigits(thread)); + vec.emplace_back(CString("MaximumFractionDigits"), GetMaximumFractionDigits(thread)); + vec.emplace_back(CString("MinimumSignificantDigits"), GetMinimumSignificantDigits(thread)); + vec.emplace_back(CString("MaximumSignificantDigits"), GetMaximumSignificantDigits(thread)); vec.emplace_back(CString("RoundingType"), JSTaggedValue(static_cast(GetRoundingType()))); - vec.emplace_back(CString("IcuPR"), GetIcuPR()); - vec.emplace_back(CString("IcuNF"), GetIcuNF()); + vec.emplace_back(CString("IcuPR"), GetIcuPR(thread)); + vec.emplace_back(CString("IcuNF"), GetIcuNF(thread)); vec.emplace_back(CString("Type"), JSTaggedValue(static_cast(GetType()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSDisplayNames::DumpForSnapshot(std::vector &vec) const +void JSDisplayNames::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Locale"), GetLocale()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); vec.emplace_back(CString("Type"), JSTaggedValue(static_cast(GetType()))); vec.emplace_back(CString("Style"), JSTaggedValue(static_cast(GetStyle()))); vec.emplace_back(CString("Fallback"), JSTaggedValue(static_cast(GetFallback()))); - vec.emplace_back(CString("IcuLDN"), GetIcuLDN()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuLDN"), GetIcuLDN(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSSegmenter::DumpForSnapshot(std::vector &vec) const +void JSSegmenter::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Locale"), GetLocale()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); vec.emplace_back(CString("Granularity"), JSTaggedValue(static_cast(GetGranularity()))); - vec.emplace_back(CString("IcuField"), GetIcuField()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSSegments::DumpForSnapshot(std::vector &vec) const +void JSSegments::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("SegmentsString"), GetSegmentsString()); - vec.emplace_back(CString("UnicodeString"), GetUnicodeString()); + vec.emplace_back(CString("SegmentsString"), GetSegmentsString(thread)); + vec.emplace_back(CString("UnicodeString"), GetUnicodeString(thread)); vec.emplace_back(CString("Granularity"), JSTaggedValue(static_cast(GetGranularity()))); - vec.emplace_back(CString("IcuField"), GetIcuField()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSSegmentIterator::DumpForSnapshot(std::vector &vec) const +void JSSegmentIterator::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("IteratedString"), GetIteratedString()); - vec.emplace_back(CString("UnicodeString"), GetUnicodeString()); + vec.emplace_back(CString("IteratedString"), GetIteratedString(thread)); + vec.emplace_back(CString("UnicodeString"), GetUnicodeString(thread)); vec.emplace_back(CString("Granularity"), JSTaggedValue(static_cast(GetGranularity()))); - vec.emplace_back(CString("IcuField"), GetIcuField()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuField"), GetIcuField(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void JSListFormat::DumpForSnapshot(std::vector &vec) const +void JSListFormat::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Locale"), GetLocale()); + vec.emplace_back(CString("Locale"), GetLocale(thread)); vec.emplace_back(CString("Type"), JSTaggedValue(static_cast(GetType()))); vec.emplace_back(CString("Style"), JSTaggedValue(static_cast(GetStyle()))); - vec.emplace_back(CString("IcuLF"), GetIcuLF()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("IcuLF"), GetIcuLF(thread)); + JSObject::DumpForSnapshot(thread, vec); } #endif -void JSGeneratorObject::DumpForSnapshot(std::vector &vec) const +void JSGeneratorObject::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("GeneratorContext"), GetGeneratorContext()); - vec.emplace_back(CString("ResumeResult"), GetResumeResult()); + vec.emplace_back(CString("GeneratorContext"), GetGeneratorContext(thread)); + vec.emplace_back(CString("ResumeResult"), GetResumeResult(thread)); vec.emplace_back(CString("GeneratorState"), JSTaggedValue(static_cast(GetGeneratorState()))); vec.emplace_back(CString("ResumeMode"), JSTaggedValue(static_cast(GetResumeMode()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAsyncGeneratorObject::DumpForSnapshot(std::vector &vec) const +void JSAsyncGeneratorObject::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("GeneratorContext"), GetGeneratorContext()); - vec.emplace_back(CString("AsyncGeneratorQueue"), GetAsyncGeneratorQueue()); - vec.emplace_back(CString("GeneratorBrand"), GetGeneratorBrand()); - vec.emplace_back(CString("ResumeResult"), GetResumeResult()); + vec.emplace_back(CString("GeneratorContext"), GetGeneratorContext(thread)); + vec.emplace_back(CString("AsyncGeneratorQueue"), GetAsyncGeneratorQueue(thread)); + vec.emplace_back(CString("GeneratorBrand"), GetGeneratorBrand(thread)); + vec.emplace_back(CString("ResumeResult"), GetResumeResult(thread)); vec.emplace_back(CString("AsyncGeneratorState"), JSTaggedValue(static_cast(GetAsyncGeneratorState()))); vec.emplace_back(CString("ResumeMode"), JSTaggedValue(static_cast(GetResumeMode()))); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void JSAsyncFuncObject::DumpForSnapshot(std::vector &vec) const +void JSAsyncFuncObject::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Promise"), GetPromise()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Promise"), GetPromise(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void GeneratorContext::DumpForSnapshot(std::vector &vec) const +void GeneratorContext::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 8; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("RegsArray"), GetRegsArray()); - vec.emplace_back(CString("Method"), GetMethod()); - vec.emplace_back(CString("This"), GetThis()); - vec.emplace_back(CString("Acc"), GetAcc()); - vec.emplace_back(CString("GeneratorObject"), GetGeneratorObject()); - vec.emplace_back(CString("LexicalEnv"), GetLexicalEnv()); + vec.emplace_back(CString("RegsArray"), GetRegsArray(thread)); + vec.emplace_back(CString("Method"), GetMethod(thread)); + vec.emplace_back(CString("This"), GetThis(thread)); + vec.emplace_back(CString("Acc"), GetAcc(thread)); + vec.emplace_back(CString("GeneratorObject"), GetGeneratorObject(thread)); + vec.emplace_back(CString("LexicalEnv"), GetLexicalEnv(thread)); vec.emplace_back(CString("NRegs"), JSTaggedValue(GetNRegs())); vec.emplace_back(CString("BCOffset"), JSTaggedValue(GetBCOffset())); } -void EnumCache::DumpForSnapshot(std::vector &vec) const +void EnumCache::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { constexpr int16_t NUM_OF_ITEMS = 4; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("EnumCacheOwn"), GetEnumCacheOwn()); - vec.emplace_back(CString("EnumCacheAll"), GetEnumCacheAll()); - vec.emplace_back(CString("ProtoChainInfoEnumCache"), GetProtoChainInfoEnumCache()); + vec.emplace_back(CString("EnumCacheOwn"), GetEnumCacheOwn(thread)); + vec.emplace_back(CString("EnumCacheAll"), GetEnumCacheAll(thread)); + vec.emplace_back(CString("ProtoChainInfoEnumCache"), GetProtoChainInfoEnumCache(thread)); vec.emplace_back(CString("EnumCacheKind"), JSTaggedValue(GetEnumCacheKind())); } -void ProtoChangeMarker::DumpForSnapshot(std::vector &vec) const +void ProtoChangeMarker::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("HasChanged"), JSTaggedValue(GetHasChanged())); } -void MarkerCell::DumpForSnapshot(std::vector &vec) const +void MarkerCell::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("IsDetectorInvalid"), JSTaggedValue(GetIsDetectorInvalid())); } -void ProtoChangeDetails::DumpForSnapshot(std::vector &vec) const +void ProtoChangeDetails::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ChangeListener"), GetChangeListener()); + vec.emplace_back(CString("ChangeListener"), GetChangeListener(thread)); vec.emplace_back(CString("RegisterIndex"), JSTaggedValue(GetRegisterIndex())); } -void MachineCode::DumpForSnapshot(std::vector &vec) const +void MachineCode::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("InstructionSizeInBytes"), JSTaggedValue(GetInstructionSizeInBytes())); } -void TrackInfo::DumpForSnapshot(std::vector &vec) const +void TrackInfo::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back("ElementsKind", JSTaggedValue(static_cast(GetElementsKind()))); - vec.emplace_back(CString("CachedHClass"), GetCachedHClass()); - vec.emplace_back(CString("CachedFunc"), GetCachedFunc()); + vec.emplace_back(CString("CachedHClass"), GetCachedHClass(thread)); + vec.emplace_back(CString("CachedFunc"), GetCachedFunc(thread)); vec.emplace_back(CString("ArrayLength"), JSTaggedValue(GetArrayLength())); } -void ClassInfoExtractor::DumpForSnapshot(std::vector &vec) const +void ClassInfoExtractor::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 6; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("NonStaticKeys"), GetNonStaticKeys()); - vec.emplace_back(CString("NonStaticProperties"), GetNonStaticProperties()); - vec.emplace_back(CString("NonStaticElements"), GetNonStaticElements()); - vec.emplace_back(CString("StaticKeys"), GetStaticKeys()); - vec.emplace_back(CString("StaticProperties"), GetStaticProperties()); - vec.emplace_back(CString("StaticElements"), GetStaticElements()); - vec.emplace_back(CString("ConstructorMethod"), GetConstructorMethod()); + vec.emplace_back(CString("NonStaticKeys"), GetNonStaticKeys(thread)); + vec.emplace_back(CString("NonStaticProperties"), GetNonStaticProperties(thread)); + vec.emplace_back(CString("NonStaticElements"), GetNonStaticElements(thread)); + vec.emplace_back(CString("StaticKeys"), GetStaticKeys(thread)); + vec.emplace_back(CString("StaticProperties"), GetStaticProperties(thread)); + vec.emplace_back(CString("StaticElements"), GetStaticElements(thread)); + vec.emplace_back(CString("ConstructorMethod"), GetConstructorMethod(thread)); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); } -void SourceTextModule::DumpForSnapshot(std::vector &vec) const +void SourceTextModule::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { // please update the NUM_OF_ITEMS if you change the items below constexpr int16_t NUM_OF_ITEMS = 14; vec.reserve(vec.size() + NUM_OF_ITEMS); - vec.emplace_back(CString("Environment"), GetEnvironment()); - vec.emplace_back(CString("Namespace"), GetNamespace()); - vec.emplace_back(CString("ModuleRequests"), GetModuleRequests()); - vec.emplace_back(CString("RequestedModules"), GetRequestedModules()); - vec.emplace_back(CString("ImportEntries"), GetImportEntries()); - vec.emplace_back(CString("LocalExportEntries"), GetLocalExportEntries()); - vec.emplace_back(CString("IndirectExportEntries"), GetIndirectExportEntries()); - vec.emplace_back(CString("StarExportEntries"), GetStarExportEntries()); + vec.emplace_back(CString("Environment"), GetEnvironment(thread)); + vec.emplace_back(CString("Namespace"), GetNamespace(thread)); + vec.emplace_back(CString("ModuleRequests"), GetModuleRequests(thread)); + vec.emplace_back(CString("RequestedModules"), GetRequestedModules(thread)); + vec.emplace_back(CString("ImportEntries"), GetImportEntries(thread)); + vec.emplace_back(CString("LocalExportEntries"), GetLocalExportEntries(thread)); + vec.emplace_back(CString("IndirectExportEntries"), GetIndirectExportEntries(thread)); + vec.emplace_back(CString("StarExportEntries"), GetStarExportEntries(thread)); vec.emplace_back(CString("Status"), JSTaggedValue(static_cast(GetStatus()))); - vec.emplace_back(CString("Exception"), GetException()); + vec.emplace_back(CString("Exception"), GetException(thread)); vec.emplace_back(CString("DFSIndex"), JSTaggedValue(GetDFSIndex())); vec.emplace_back(CString("DFSAncestorIndex"), JSTaggedValue(GetDFSAncestorIndex())); - vec.emplace_back(CString("NameDictionary"), GetNameDictionary()); - vec.emplace_back(CString("CycleRoot"), GetCycleRoot()); - vec.emplace_back(CString("TopLevelCapability"), GetTopLevelCapability()); - vec.emplace_back(CString("AsyncParentModules"), GetAsyncParentModules()); - vec.emplace_back(CString("SendableEnv"), GetSendableEnv()); + vec.emplace_back(CString("NameDictionary"), GetNameDictionary(thread)); + vec.emplace_back(CString("CycleRoot"), GetCycleRoot(thread)); + vec.emplace_back(CString("TopLevelCapability"), GetTopLevelCapability(thread)); + vec.emplace_back(CString("AsyncParentModules"), GetAsyncParentModules(thread)); + vec.emplace_back(CString("SendableEnv"), GetSendableEnv(thread)); vec.emplace_back(CString("HasTLA"), JSTaggedValue(GetHasTLA())); vec.emplace_back(CString("AsyncEvaluatingOrdinal"), JSTaggedValue(GetAsyncEvaluatingOrdinal())); vec.emplace_back(CString("PendingAsyncDependencies"), JSTaggedValue(GetPendingAsyncDependencies())); } -void ImportEntry::DumpForSnapshot(std::vector &vec) const +void ImportEntry::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("ModuleRequestIndex"), JSTaggedValue(GetModuleRequestIndex())); - vec.emplace_back(CString("ImportName"), GetImportName()); - vec.emplace_back(CString("LocalName"), GetLocalName()); + vec.emplace_back(CString("ImportName"), GetImportName(thread)); + vec.emplace_back(CString("LocalName"), GetLocalName(thread)); } -void LocalExportEntry::DumpForSnapshot(std::vector &vec) const +void LocalExportEntry::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ExportName"), GetExportName()); - vec.emplace_back(CString("LocalName"), GetLocalName()); + vec.emplace_back(CString("ExportName"), GetExportName(thread)); + vec.emplace_back(CString("LocalName"), GetLocalName(thread)); } -void IndirectExportEntry::DumpForSnapshot(std::vector &vec) const +void IndirectExportEntry::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ExportName"), GetExportName()); + vec.emplace_back(CString("ExportName"), GetExportName(thread)); vec.emplace_back(CString("ModuleRequest"), JSTaggedValue(GetModuleRequestIndex())); - vec.emplace_back(CString("ImportName"), GetImportName()); + vec.emplace_back(CString("ImportName"), GetImportName(thread)); } -void StarExportEntry::DumpForSnapshot(std::vector &vec) const +void StarExportEntry::DumpForSnapshot([[maybe_unused]] const JSThread *thread, std::vector &vec) const { vec.emplace_back(CString("ModuleRequest"), JSTaggedValue(GetModuleRequestIndex())); } -void ResolvedBinding::DumpForSnapshot(std::vector &vec) const +void ResolvedBinding::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Module"), GetModule()); - vec.emplace_back(CString("BindingName"), GetBindingName()); + vec.emplace_back(CString("Module"), GetModule(thread)); + vec.emplace_back(CString("BindingName"), GetBindingName(thread)); } -void ResolvedIndexBinding::DumpForSnapshot(std::vector &vec) const +void ResolvedIndexBinding::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Module"), GetModule()); + vec.emplace_back(CString("Module"), GetModule(thread)); vec.emplace_back(CString("Index"), JSTaggedValue(GetIndex())); } -void ResolvedRecordIndexBinding::DumpForSnapshot(std::vector &vec) const +void ResolvedRecordIndexBinding::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ModuleRecord"), GetModuleRecord()); - vec.emplace_back(CString("AbcFileName"), GetAbcFileName()); + vec.emplace_back(CString("ModuleRecord"), GetModuleRecord(thread)); + vec.emplace_back(CString("AbcFileName"), GetAbcFileName(thread)); vec.emplace_back(CString("Index"), JSTaggedValue(GetIndex())); } -void ResolvedRecordBinding::DumpForSnapshot(std::vector &vec) const +void ResolvedRecordBinding::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ModuleRecord"), GetModuleRecord()); - vec.emplace_back(CString("BindingName"), GetBindingName()); + vec.emplace_back(CString("ModuleRecord"), GetModuleRecord(thread)); + vec.emplace_back(CString("BindingName"), GetBindingName(thread)); } -void ModuleNamespace::DumpForSnapshot(std::vector &vec) const +void ModuleNamespace::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Module"), GetModule()); - vec.emplace_back(CString("Exports"), GetExports()); - vec.emplace_back(CString("DeregisterProcession"), GetDeregisterProcession()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Module"), GetModule(thread)); + vec.emplace_back(CString("Exports"), GetExports(thread)); + vec.emplace_back(CString("DeregisterProcession"), GetDeregisterProcession(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void NativeModuleFailureInfo::DumpForSnapshot(std::vector &vec) const +void NativeModuleFailureInfo::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("ArkNativeModuleFailureInfo"), GetArkNativeModuleFailureInfo()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("ArkNativeModuleFailureInfo"), GetArkNativeModuleFailureInfo(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void CjsModule::DumpForSnapshot(std::vector &vec) const +void CjsModule::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Id"), GetId()); - vec.emplace_back(CString("Path"), GetPath()); - vec.emplace_back(CString("Exports"), GetExports()); - vec.emplace_back(CString("Filename"), GetFilename()); + vec.emplace_back(CString("Id"), GetId(thread)); + vec.emplace_back(CString("Path"), GetPath(thread)); + vec.emplace_back(CString("Exports"), GetExports(thread)); + vec.emplace_back(CString("Filename"), GetFilename(thread)); vec.emplace_back(CString("BitField"), JSTaggedValue(GetBitField())); - JSObject::DumpForSnapshot(vec); + JSObject::DumpForSnapshot(thread, vec); } -void CjsExports::DumpForSnapshot(std::vector &vec) const +void CjsExports::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Exports"), GetExports()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Exports"), GetExports(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void CjsRequire::DumpForSnapshot(std::vector &vec) const +void CjsRequire::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Cache"), GetCache()); - vec.emplace_back(CString("Parent"), GetParent()); - JSObject::DumpForSnapshot(vec); + vec.emplace_back(CString("Cache"), GetCache(thread)); + vec.emplace_back(CString("Parent"), GetParent(thread)); + JSObject::DumpForSnapshot(thread, vec); } -void ClassLiteral::DumpForSnapshot(std::vector &vec) const +void ClassLiteral::DumpForSnapshot(const JSThread *thread, std::vector &vec) const { - vec.emplace_back(CString("Array"), GetArray()); + vec.emplace_back(CString("Array"), GetArray(thread)); vec.emplace_back(CString("IsAOTUsed"), JSTaggedValue(GetIsAOTUsed())); - if (!GetArray().IsUndefined()) { - DumpArrayClass(TaggedArray::Cast(GetArray().GetTaggedObject()), vec); + if (!GetArray(thread).IsUndefined()) { + DumpArrayClass(thread, TaggedArray::Cast(GetArray(thread).GetTaggedObject()), vec); } } } // namespace panda::ecmascript diff --git a/ecmascript/ecma_macros.h b/ecmascript/ecma_macros.h index 20bf7e315e..6edef61f4f 100644 --- a/ecmascript/ecma_macros.h +++ b/ecmascript/ecma_macros.h @@ -56,7 +56,7 @@ /* 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) -#define GET_VALUE(addr, offset) Barriers::GetTaggedValue((addr), (offset)) +#define GET_VALUE(thread, addr, offset) Barriers::GetTaggedValue((thread), (addr), (offset)) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SET_VALUE_WITH_BARRIER(thread, addr, offset, value) \ @@ -73,11 +73,11 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ACCESSORS(name, offset, endOffset) \ static constexpr size_t endOffset = (offset) + JSTaggedValue::TaggedTypeSize(); \ - JSTaggedValue Get##name() const \ + JSTaggedValue Get##name(const JSThread *thread) const \ { \ /* 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. */ \ - return JSTaggedValue(Barriers::GetTaggedValue(this, offset)); \ + return JSTaggedValue(Barriers::GetTaggedValue(thread, this, offset)); \ } \ template \ void Set##name(const JSThread *thread, JSHandle value, BarrierMode mode = WRITE_BARRIER) \ @@ -122,12 +122,12 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ACCESSORS_SYNCHRONIZED(name, offset, endOffset) \ static constexpr size_t endOffset = (offset) + JSTaggedValue::TaggedTypeSize(); \ - JSTaggedValue Get##name() const \ + JSTaggedValue Get##name(const JSThread *thread) const \ { \ /* 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. */ \ /* Synchronized means it will restrain the store and load in atomic. */ \ - return JSTaggedValue(Barriers::GetTaggedValueAtomic(this, offset)); \ + return JSTaggedValue(Barriers::GetTaggedValueAtomic(thread, this, offset)); \ } \ template \ void Set##name(const JSThread *thread, JSHandle value) \ @@ -155,7 +155,7 @@ } \ inline type Get##name() const \ { \ - return Barriers::GetValue(this, offset); \ + return Barriers::GetPrimitive(this, offset); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -318,7 +318,7 @@ if (!msg->IsDate()) { \ THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ } \ - if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ + if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue(thread).GetDouble())) { \ THROW_RANGE_ERROR_AND_RETURN(thread, "range error", JSTaggedValue::Exception()); \ } \ return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ @@ -335,7 +335,7 @@ if (!msg->IsDate()) { \ THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ } \ - if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ + if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue(thread).GetDouble())) { \ return thread->GetEcmaVM()->GetFactory()->NewFromASCII("Invalid Date").GetTaggedValue(); \ } \ return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ @@ -353,7 +353,7 @@ THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ } \ JSHandle jsDate(msg); \ - double result = jsDate->GetDateValue(thread, jsDate->GetTimeValue().GetDouble(), code, isLocal); \ + double result = jsDate->GetDateValue(thread, jsDate->GetTimeValue(thread).GetDouble(), code, isLocal); \ return GetTaggedDouble(result); \ } @@ -485,20 +485,20 @@ if ((value).GetTaggedValue().IsCompletionRecord()) { \ JSHandle record = JSHandle::Cast(value); \ if (record->IsThrow()) { \ - JSHandle reject(thread, (capability)->GetReject()); \ + JSHandle reject(thread, (capability)->GetReject(thread)); \ JSHandle undefine = globalConst->GetHandledUndefined(); \ EcmaRuntimeCallInfo *info = \ EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefine, undefine, 1); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); \ - info->SetCallArg(record->GetValue()); \ + info->SetCallArg(record->GetValue(thread)); \ JSTaggedValue res = JSFunction::Call(info); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, res); \ - return (capability)->GetPromise(); \ + return (capability)->GetPromise(thread); \ } \ } \ if ((thread)->HasPendingException()) { \ (thread)->ClearException(); \ - JSHandle reject(thread, (capability)->GetReject()); \ + JSHandle reject(thread, (capability)->GetReject(thread)); \ JSHandle undefined = globalConst->GetHandledUndefined(); \ EcmaRuntimeCallInfo *info = \ EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); \ @@ -506,7 +506,7 @@ info->SetCallArg(value.GetTaggedValue()); \ JSTaggedValue res = JSFunction::Call(info); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, res); \ - return (capability)->GetPromise(); \ + return (capability)->GetPromise(thread); \ } \ } while (false) @@ -531,13 +531,13 @@ } while (false) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECL_DUMP() \ - void Dump(std::ostream &os) const DUMP_API_ATTR; \ - void Dump() const DUMP_API_ATTR \ - { \ - Dump(std::cout); \ - } \ - void DumpForSnapshot(std::vector &vec) const; +#define DECL_DUMP() \ + void Dump(const JSThread *thread, std::ostream &os) const DUMP_API_ATTR; \ + void Dump(const JSThread *thread) const DUMP_API_ATTR \ + { \ + Dump(thread, std::cout); \ + } \ + void DumpForSnapshot(const JSThread *thread, std::vector &vec) const; #endif // defined(__cplusplus) diff --git a/ecmascript/ecma_string-inl.h b/ecmascript/ecma_string-inl.h index c621044423..12e7f59604 100644 --- a/ecmascript/ecma_string-inl.h +++ b/ecmascript/ecma_string-inl.h @@ -283,19 +283,19 @@ inline uint16_t* EcmaString::GetDataUtf16Writable() return ToBaseString()->GetDataUtf16Writable(); } -inline size_t EcmaString::GetUtf8Length(bool modify, bool isGetBufferSize) const +inline size_t EcmaString::GetUtf8Length(const JSThread *thread, bool modify, bool isGetBufferSize) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->GetUtf8Length(std::move(readBarrier), modify, isGetBufferSize); } template -uint16_t EcmaString::At(int32_t index) const +uint16_t EcmaString::At(const JSThread *thread, int32_t index) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->At(std::move(readBarrier), index); } @@ -305,78 +305,80 @@ inline void EcmaString::WriteData(uint32_t index, uint16_t src) return ToBaseString()->WriteData(index, src); } -inline bool EcmaString::IsFlat() const +inline bool EcmaString::IsFlat(const JSThread *thread) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->IsFlat(std::move(readBarrier)); } template -void EcmaString::WriteToFlat(EcmaString* src, Char* buf, uint32_t maxLength) +void EcmaString::WriteToFlat(const JSThread *thread, EcmaString* src, Char* buf, uint32_t maxLength) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::WriteToFlat(std::move(readBarrier), src->ToBaseString(), buf, maxLength); } template -void EcmaString::WriteToFlatWithPos(EcmaString* src, Char* buf, uint32_t length, uint32_t pos) +void EcmaString::WriteToFlatWithPos(const JSThread *thread, EcmaString* src, Char* buf, uint32_t length, uint32_t pos) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::WriteToFlatWithPos(std::move(readBarrier), src->ToBaseString(), buf, length, pos); } // It allows user to copy into buffer even if maxLength < length -inline size_t EcmaString::WriteUtf8(uint8_t* buf, size_t maxLength, bool isWriteBuffer) const +inline size_t EcmaString::WriteUtf8(const JSThread *thread, uint8_t* buf, size_t maxLength, bool isWriteBuffer) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->WriteUtf8(std::move(readBarrier), buf, maxLength, isWriteBuffer); } // It allows user to copy into buffer even if maxLength < length -inline size_t EcmaString::WriteUtf16(uint16_t* buf, uint32_t targetLength, uint32_t bufLength) const +inline size_t EcmaString::WriteUtf16(const JSThread *thread, uint16_t* buf, + uint32_t targetLength, uint32_t bufLength) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->WriteUtf16(std::move(readBarrier), buf, targetLength, bufLength); } -inline size_t EcmaString::WriteOneByte(uint8_t* buf, size_t maxLength) const +inline size_t EcmaString::WriteOneByte(const JSThread *thread, uint8_t* buf, size_t maxLength) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->WriteOneByte(std::move(readBarrier), buf, maxLength); } -inline uint32_t EcmaString::CopyDataUtf16(uint16_t* buf, uint32_t maxLength) const +inline uint32_t EcmaString::CopyDataUtf16(const JSThread *thread, uint16_t* buf, uint32_t maxLength) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->CopyDataUtf16(std::move(readBarrier), buf, maxLength); } -inline Span EcmaString::ToUtf8Span(CVector& buf, bool modify, bool cesu8) +inline Span EcmaString::ToUtf8Span(const JSThread *thread, CVector& buf, + bool modify, bool cesu8) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->ToUtf8Span(std::move(readBarrier), buf, modify, cesu8); } -inline Span EcmaString::DebuggerToUtf8Span(CVector& buf, bool modify) +inline Span EcmaString::DebuggerToUtf8Span(const JSThread *thread, CVector& buf, bool modify) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->DebuggerToUtf8Span(std::move(readBarrier), buf, modify); } @@ -411,15 +413,15 @@ inline const uint16_t *EcmaStringAccessor::GetDataUtf16() return string_->GetDataUtf16(); } -inline size_t EcmaStringAccessor::GetUtf8Length(bool isGetBufferSize) const +inline size_t EcmaStringAccessor::GetUtf8Length(const JSThread *thread, bool isGetBufferSize) const { - return string_->GetUtf8Length(true, isGetBufferSize); + return string_->GetUtf8Length(thread, true, isGetBufferSize); } -inline void EcmaStringAccessor::ReadData(EcmaString *dst, EcmaString *src, - uint32_t start, uint32_t destSize, uint32_t length) +inline void EcmaStringAccessor::ReadData(const JSThread *thread, EcmaString *dst, + EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length) { - dst->WriteData(src, start, destSize, length); + dst->WriteData(thread, src, start, destSize, length); } } // namespace panda::ecmascript #endif diff --git a/ecmascript/ecma_string.cpp b/ecmascript/ecma_string.cpp index 03d1296117..18685bd995 100755 --- a/ecmascript/ecma_string.cpp +++ b/ecmascript/ecma_string.cpp @@ -159,10 +159,10 @@ EcmaString *EcmaString::GetSubString(const EcmaVM *vm, ASSERT((start + length) <= src->GetLength()); if (length == 1) { JSThread *thread = vm->GetJSThread(); - uint16_t res = EcmaStringAccessor(src).Get(start); + uint16_t res = EcmaStringAccessor(src).Get(thread, start); if (EcmaStringAccessor::CanBeCompressed(&res, 1)) { JSHandle singleCharTable(thread, thread->GetSingleCharTable()); - return EcmaString::Cast(singleCharTable->GetStringFromSingleCharTable(res).GetTaggedObject()); + return EcmaString::Cast(singleCharTable->GetStringFromSingleCharTable(thread, res).GetTaggedObject()); } } if (static_cast(length) >= SlicedString::MIN_SLICED_STRING_LENGTH) { @@ -198,10 +198,10 @@ bool EcmaString::SubStringIsUtf8(const EcmaVM *vm, return CanBeCompressed(srcFlat.GetDataUtf16() + start, length); } -void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length) +void EcmaString::WriteData(const JSThread *thread, EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; ToBaseString()->WriteData(std::move(readBarrier), src->ToBaseString(), start, destSize, length); } @@ -405,10 +405,10 @@ int32_t EcmaString::LastIndexOf(const EcmaVM *vm, } } -std::u16string EcmaString::ToU16String(uint32_t len) +std::u16string EcmaString::ToU16String(const JSThread *thread, uint32_t len) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->ToU16String(std::move(readBarrier), len); } @@ -431,7 +431,8 @@ uint32_t EcmaString::CalculateDataConcatHashCode(const T1 *dataFirst, size_t siz #endif // static -uint32_t EcmaString::CalculateConcatHashCode(const JSHandle &firstString, +uint32_t EcmaString::CalculateConcatHashCode(const JSThread *thread, + const JSHandle &firstString, const JSHandle &secondString) { bool isFirstStringUtf8 = EcmaStringAccessor(firstString).IsUtf8(); @@ -443,26 +444,26 @@ uint32_t EcmaString::CalculateConcatHashCode(const JSHandle &firstSt CVector bufFirstUint16; CVector bufSecondUint16; if (isFirstStringUtf8 && isSecondStringUtf8) { - const uint8_t *dataFirst = EcmaString::GetUtf8DataFlat(firstStr, bufFirstUint8); - const uint8_t *dataSecond = EcmaString::GetUtf8DataFlat(secondStr, bufSecondUint8); + const uint8_t *dataFirst = EcmaString::GetUtf8DataFlat(thread, firstStr, bufFirstUint8); + const uint8_t *dataSecond = EcmaString::GetUtf8DataFlat(thread, secondStr, bufSecondUint8); return CalculateDataConcatHashCode(dataFirst, firstStr->GetLength(), dataSecond, secondStr->GetLength()); } if (!isFirstStringUtf8 && isSecondStringUtf8) { - const uint16_t *dataFirst = EcmaString::GetUtf16DataFlat(firstStr, bufFirstUint16); - const uint8_t *dataSecond = EcmaString::GetUtf8DataFlat(secondStr, bufSecondUint8); + const uint16_t *dataFirst = EcmaString::GetUtf16DataFlat(thread, firstStr, bufFirstUint16); + const uint8_t *dataSecond = EcmaString::GetUtf8DataFlat(thread, secondStr, bufSecondUint8); return CalculateDataConcatHashCode(dataFirst, firstStr->GetLength(), dataSecond, secondStr->GetLength()); } if (isFirstStringUtf8 && !isSecondStringUtf8) { - const uint8_t *dataFirst = EcmaString::GetUtf8DataFlat(firstStr, bufFirstUint8); - const uint16_t *dataSecond = EcmaString::GetUtf16DataFlat(secondStr, bufSecondUint16); + const uint8_t *dataFirst = EcmaString::GetUtf8DataFlat(thread, firstStr, bufFirstUint8); + const uint16_t *dataSecond = EcmaString::GetUtf16DataFlat(thread, secondStr, bufSecondUint16); return CalculateDataConcatHashCode(dataFirst, firstStr->GetLength(), dataSecond, secondStr->GetLength()); } { - const uint16_t *dataFirst = EcmaString::GetUtf16DataFlat(firstStr, bufFirstUint16); - const uint16_t *dataSecond = EcmaString::GetUtf16DataFlat(secondStr, bufSecondUint16); + const uint16_t *dataFirst = EcmaString::GetUtf16DataFlat(thread, firstStr, bufFirstUint16); + const uint16_t *dataSecond = EcmaString::GetUtf16DataFlat(thread, secondStr, bufSecondUint16); return CalculateDataConcatHashCode(dataFirst, firstStr->GetLength(), dataSecond, secondStr->GetLength()); } @@ -486,19 +487,19 @@ bool EcmaString::CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len) return BaseString::CanBeCompressed(utf16Data, utf16Len); } -bool EcmaString::EqualToSplicedString(const EcmaString *str1, const EcmaString *str2) +bool EcmaString::EqualToSplicedString(const JSThread *thread, const EcmaString *str1, const EcmaString *str2) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->EqualToSplicedString(std::move(readBarrier), str1->ToBaseString(), str2->ToBaseString()); } /* static */ -bool EcmaString::StringsAreEqualDiffUtfEncoding(EcmaString *left, EcmaString *right) +bool EcmaString::StringsAreEqualDiffUtfEncoding(const JSThread *thread, EcmaString *left, EcmaString *right) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::StringsAreEqualDiffUtfEncoding(std::move(readBarrier), left->ToBaseString(), right->ToBaseString()); @@ -559,30 +560,31 @@ bool EcmaString::StringsAreEqual(const EcmaVM *vm, const JSHandle &s } /* static */ -bool EcmaString::StringsAreEqual(EcmaString* str1, EcmaString* str2) +bool EcmaString::StringsAreEqual(const JSThread *thread, EcmaString* str1, EcmaString* str2) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::StringsAreEqual(std::move(readBarrier), str1->ToBaseString(), str2->ToBaseString()); } /* static */ -bool EcmaString::StringIsEqualUint8Data(const EcmaString* str1, const uint8_t* dataAddr, uint32_t dataLen, - bool canBeCompressToUtf8) +bool EcmaString::StringIsEqualUint8Data(const JSThread *thread, const EcmaString* str1, const uint8_t* dataAddr, + uint32_t dataLen, bool canBeCompressToUtf8) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::StringIsEqualUint8Data(std::move(readBarrier), str1->ToBaseString(), dataAddr, dataLen, canBeCompressToUtf8); } /* static */ -bool EcmaString::StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len) +bool EcmaString::StringsAreEqualUtf16(const JSThread *thread, + const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::StringsAreEqualUtf16(std::move(readBarrier), str1->ToBaseString(), utf16Data, utf16Len); } @@ -600,10 +602,10 @@ bool EcmaString::MemCopyChars(Span &dst, size_t dstMax, Span &src, s } // hashSeed only be used when computing two separate strings merged hashcode. -uint32_t EcmaString::ComputeRawHashcode() const +uint32_t EcmaString::ComputeRawHashcode(const JSThread *thread) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToBaseString()->ComputeRawHashcode(std::move(readBarrier)); } @@ -620,7 +622,7 @@ uint32_t EcmaString::ComputeHashcodeUtf16(const uint16_t *utf16Data, uint32_t le return BaseString::ComputeHashcodeUtf16(utf16Data, length); } -bool EcmaString::ToElementIndex(uint32_t *index) +bool EcmaString::ToElementIndex(const JSThread *thread, uint32_t *index) { uint32_t len = GetLength(); if (UNLIKELY(len == 0 || len > MAX_ELEMENT_INDEX_LEN)) { // NOLINTNEXTLINEreadability-magic-numbers) @@ -631,7 +633,7 @@ bool EcmaString::ToElementIndex(uint32_t *index) } CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(this, buf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, this, buf); constexpr uint64_t maxValue = std::numeric_limits::max() - 1; if (NumberHelper::StringToUint(std::basic_string_view(data, GetLength()), *index, maxValue)) { return true; @@ -639,7 +641,7 @@ bool EcmaString::ToElementIndex(uint32_t *index) return false; } -bool EcmaString::ToInt(int32_t *index, bool *negative) +bool EcmaString::ToInt(const JSThread *thread, int32_t *index, bool *negative) { uint32_t len = GetLength(); if (UNLIKELY(len == 0 || len > MAX_ELEMENT_INDEX_LEN)) { // NOLINTNEXTLINEreadability-magic-numbers) @@ -649,7 +651,7 @@ bool EcmaString::ToInt(int32_t *index, bool *negative) return false; } CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(this, buf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, this, buf); uint32_t c = data[0]; uint32_t loopStart = 0; uint64_t n = 0; @@ -688,7 +690,7 @@ bool EcmaString::ToUInt64FromLoopStart(uint64_t *index, uint32_t loopStart, cons return true; } -bool EcmaString::ToTypedArrayIndex(uint32_t *index) +bool EcmaString::ToTypedArrayIndex(const JSThread *thread, uint32_t *index) { uint32_t len = GetLength(); if (UNLIKELY(len == 0 || len > MAX_ELEMENT_INDEX_LEN)) { @@ -699,7 +701,7 @@ bool EcmaString::ToTypedArrayIndex(uint32_t *index) } CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(this, buf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, this, buf); uint32_t c = data[0]; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) uint64_t n = 0; if (c == '0') { @@ -895,14 +897,14 @@ EcmaString *EcmaString::SlowFlatten(const EcmaVM *vm, const JSHandle EcmaString *result = nullptr; if (string->IsUtf8()) { result = CreateLineStringWithSpaceType(vm, length, true, type); - WriteToFlat(*string, result->GetDataUtf8Writable(), length); + WriteToFlat(thread, *string, result->GetDataUtf8Writable(), length); } else { result = CreateLineStringWithSpaceType(vm, length, false, type); - WriteToFlat(*string, result->GetDataUtf16Writable(), length); + WriteToFlat(thread, *string, result->GetDataUtf16Writable(), length); } if (string->IsTreeString()) { JSHandle tree(string); - ASSERT(EcmaString::Cast(tree->GetSecond())->GetLength() != 0); + ASSERT(EcmaString::Cast(tree->GetSecond(thread))->GetLength() != 0); tree->SetFirst(thread, JSTaggedValue(result)); tree->SetSecond(thread, JSTaggedValue(*vm->GetFactory()->GetEmptyString())); } @@ -915,11 +917,12 @@ EcmaString *EcmaString::Flatten(const EcmaVM *vm, const JSHandle &st if (!s->IsTreeString()) { return s; } + JSThread *thread = vm->GetJSThread(); JSHandle tree = JSHandle::Cast(string); - if (!tree->IsFlat()) { + if (!tree->IsFlat(thread)) { return SlowFlatten(vm, string, type); } - return EcmaString::Cast(tree->GetFirst()); + return EcmaString::Cast(tree->GetFirst(thread)); } FlatStringInfo EcmaString::FlattenAllString(const EcmaVM *vm, const JSHandle &string, MemSpaceType type) @@ -930,15 +933,16 @@ FlatStringInfo EcmaString::FlattenAllString(const EcmaVM *vm, const JSHandleIsLineString()) { return FlatStringInfo(s, startIndex, s->GetLength()); } + JSThread *thread = vm->GetJSThread(); if (string->IsTreeString()) { JSHandle tree = JSHandle::Cast(string); - if (!tree->IsFlat()) { + if (!tree->IsFlat(thread)) { s = SlowFlatten(vm, string, type); } else { - s = EcmaString::Cast(tree->GetFirst()); + s = EcmaString::Cast(tree->GetFirst(thread)); } } else if (string->IsSlicedString()) { - s = EcmaString::Cast(SlicedEcmaString::Cast(*string)->GetParent()); + s = EcmaString::Cast(SlicedEcmaString::Cast(*string)->GetParent(thread)); startIndex = SlicedEcmaString::Cast(*string)->GetStartIndex(); } return FlatStringInfo(s, startIndex, string->GetLength()); @@ -952,17 +956,18 @@ EcmaString *EcmaString::FlattenNoGCForSnapshot(const EcmaVM *vm, EcmaString *str } if (string->IsTreeString()) { TreeEcmaString *tree = TreeEcmaString::Cast(string); - if (tree->IsFlat()) { - string = EcmaString::Cast(tree->GetFirst()); + JSThread *thread = vm->GetJSThread(); + if (tree->IsFlat(thread)) { + string = EcmaString::Cast(tree->GetFirst(thread)); } else { uint32_t length = tree->GetLength(); EcmaString *result = nullptr; if (tree->IsUtf8()) { result = CreateLineStringNoGC(vm, length, true); - WriteToFlat(tree, result->GetDataUtf8Writable(), length); + WriteToFlat(thread, tree, result->GetDataUtf8Writable(), length); } else { result = CreateLineStringNoGC(vm, length, false); - WriteToFlat(tree, result->GetDataUtf16Writable(), length); + WriteToFlat(thread, tree, result->GetDataUtf16Writable(), length); } tree->SetFirst(vm->GetJSThread(), JSTaggedValue(result)); tree->SetSecond(vm->GetJSThread(), JSTaggedValue(*vm->GetFactory()->GetEmptyString())); @@ -971,47 +976,48 @@ EcmaString *EcmaString::FlattenNoGCForSnapshot(const EcmaVM *vm, EcmaString *str } else if (string->IsSlicedString()) { SlicedEcmaString *str = SlicedEcmaString::Cast(string); uint32_t length = str->GetLength(); + JSThread *thread = vm->GetJSThread(); EcmaString *result = nullptr; if (str->IsUtf8()) { result = CreateLineStringNoGC(vm, length, true); - WriteToFlat(str, result->GetDataUtf8Writable(), length); + WriteToFlat(thread, str, result->GetDataUtf8Writable(), length); } else { result = CreateLineStringNoGC(vm, length, false); - WriteToFlat(str, result->GetDataUtf16Writable(), length); + WriteToFlat(thread, str, result->GetDataUtf16Writable(), length); } return result; } return string; } -const uint8_t *EcmaString::GetUtf8DataFlat(const EcmaString *src, CVector &buf) +const uint8_t *EcmaString::GetUtf8DataFlat(const JSThread *thread, const EcmaString *src, CVector &buf) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::GetUtf8DataFlat(std::move(readBarrier), src->ToBaseString(), buf); } -const uint8_t *EcmaString::GetNonTreeUtf8Data(const EcmaString *src) +const uint8_t *EcmaString::GetNonTreeUtf8Data(const JSThread *thread, const EcmaString *src) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::GetNonTreeUtf8Data(std::move(readBarrier), src->ToBaseString()); } -const uint16_t *EcmaString::GetUtf16DataFlat(const EcmaString *src, CVector &buf) +const uint16_t *EcmaString::GetUtf16DataFlat(const JSThread *thread, const EcmaString *src, CVector &buf) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::GetUtf16DataFlat(std::move(readBarrier), src->ToBaseString(), buf); } -const uint16_t *EcmaString::GetNonTreeUtf16Data(const EcmaString *src) +const uint16_t *EcmaString::GetNonTreeUtf16Data(const JSThread *thread, const EcmaString *src) { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return BaseString::GetNonTreeUtf16Data(std::move(readBarrier), src->ToBaseString()); } @@ -1047,14 +1053,14 @@ EcmaStringAccessor::EcmaStringAccessor(const JSHandle &strHandle) { } -std::string EcmaStringAccessor::ToStdString(StringConvertedUsage usage) +std::string EcmaStringAccessor::ToStdString(const JSThread *thread, StringConvertedUsage usage) { if (string_ == nullptr) { return ""; } bool modify = (usage != StringConvertedUsage::PRINT); CVector buf; - Span sp = string_->ToUtf8Span(buf, modify); + Span sp = string_->ToUtf8Span(thread, buf, modify); #if ENABLE_NEXT_OPTIMIZATION return std::string(reinterpret_cast(sp.data()), sp.size()); #else @@ -1067,7 +1073,7 @@ std::string EcmaStringAccessor::ToStdString(StringConvertedUsage usage) #endif } -CString EcmaStringAccessor::Utf8ConvertToString() +CString EcmaStringAccessor::Utf8ConvertToString(const JSThread *thread) { if (string_ == nullptr) { return CString(""); @@ -1078,14 +1084,14 @@ CString EcmaStringAccessor::Utf8ConvertToString() return base::StringHelper::Utf8ToCString(GetDataUtf8(), GetLength()); } CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(string_, buf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, string_, buf); return base::StringHelper::Utf8ToCString(data, GetLength()); } else { - return ToCString(); + return ToCString(thread); } } -std::string EcmaStringAccessor::DebuggerToStdString(StringConvertedUsage usage) +std::string EcmaStringAccessor::DebuggerToStdString(const JSThread *thread, StringConvertedUsage usage) { if (string_ == nullptr) { return ""; @@ -1093,7 +1099,7 @@ std::string EcmaStringAccessor::DebuggerToStdString(StringConvertedUsage usage) bool modify = (usage != StringConvertedUsage::PRINT); CVector buf; - Span sp = string_->DebuggerToUtf8Span(buf, modify); + Span sp = string_->DebuggerToUtf8Span(thread, buf, modify); #if ENABLE_NEXT_OPTIMIZATION return std::string(reinterpret_cast(sp.data()), sp.size()); #else @@ -1106,14 +1112,14 @@ std::string EcmaStringAccessor::DebuggerToStdString(StringConvertedUsage usage) #endif } -CString EcmaStringAccessor::ToCString(StringConvertedUsage usage, bool cesu8) +CString EcmaStringAccessor::ToCString(const JSThread *thread, StringConvertedUsage usage, bool cesu8) { if (string_ == nullptr) { return ""; } bool modify = (usage != StringConvertedUsage::PRINT); CVector buf; - Span sp = string_->ToUtf8Span(buf, modify, cesu8); + Span sp = string_->ToUtf8Span(thread, buf, modify, cesu8); #if ENABLE_NEXT_OPTIMIZATION return CString(reinterpret_cast(sp.data()), sp.size()); #else @@ -1127,7 +1133,7 @@ CString EcmaStringAccessor::ToCString(StringConvertedUsage usage, bool cesu8) } #if ENABLE_NEXT_OPTIMIZATION -void EcmaStringAccessor::AppendToCString(CString &str) +void EcmaStringAccessor::AppendToCString(const JSThread *thread, CString &str) { if (string_ == nullptr) { return; @@ -1135,11 +1141,11 @@ void EcmaStringAccessor::AppendToCString(CString &str) size_t strLen = GetLength(); CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(string_, buf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, string_, buf); str.append(reinterpret_cast(data), strLen); } -void EcmaStringAccessor::AppendToC16String(C16String &str) +void EcmaStringAccessor::AppendToC16String(const JSThread *thread, C16String &str) { if (string_ == nullptr) { return; @@ -1148,12 +1154,12 @@ void EcmaStringAccessor::AppendToC16String(C16String &str) // In real world, space is usually utf8. if LIKELY(string_->IsUtf8()) { CVector buf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(string_, buf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, string_, buf); // only ascii codes, no need to convert to UTF-16, just append. AppendString(str, reinterpret_cast(data), GetLength()); } else { CVector buf; - const uint16_t *data = EcmaString::GetUtf16DataFlat(string_, buf); + const uint16_t *data = EcmaString::GetUtf16DataFlat(thread, string_, buf); str.append(reinterpret_cast(data), GetLength()); } } diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index e2c93943aa..c2b886c603 100755 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -124,7 +124,8 @@ private: template static uint32_t CalculateDataConcatHashCode(const T1 *dataFirst, size_t sizeFirst, const T2 *dataSecond, size_t sizeSecond); - static uint32_t CalculateConcatHashCode(const JSHandle &firstString, + static uint32_t CalculateConcatHashCode(const JSThread *thread, + const JSHandle &firstString, const JSHandle &secondString); static EcmaString *CopyStringToOldSpace(const EcmaVM *vm, const JSHandle &original, uint32_t length, bool compressed); @@ -173,7 +174,7 @@ private: ToBaseString()->InitLengthAndFlags(length, compressed, isIntern); } - inline size_t GetUtf8Length(bool modify = true, bool isGetBufferSize = false) const; + inline size_t GetUtf8Length(const JSThread *thread, bool modify = true, bool isGetBufferSize = false) const; inline void SetIsInternString() { @@ -197,24 +198,24 @@ private: // not change this data structure. // if string is not flat, this func has low efficiency. - uint32_t PUBLIC_API GetHashcode() + uint32_t PUBLIC_API GetHashcode(const JSThread *thread) { uint32_t hashcode = ToBaseString()->GetRawHashcode(); // GetLength() == 0 means it's an empty array.No need to computeHashCode again when hashseed is 0. if (hashcode == 0 && GetLength() != 0) { - hashcode = ComputeRawHashcode(); + hashcode = ComputeRawHashcode(thread); SetRawHashcode(hashcode); } return hashcode; } - uint32_t PUBLIC_API ComputeRawHashcode() const; + uint32_t PUBLIC_API ComputeRawHashcode(const JSThread *thread) const; static uint32_t ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len, bool canBeCompress); static uint32_t ComputeHashcodeUtf16(const uint16_t *utf16Data, uint32_t length); template - uint16_t At(int32_t index) const; + uint16_t At(const JSThread *thread, int32_t index) const; // require is LineString void WriteData(uint32_t index, uint16_t src); @@ -234,24 +235,26 @@ private: } // Compares string1 + string2 by bytes, It doesn't check canonical unicode equivalence. - bool EqualToSplicedString(const EcmaString *str1, const EcmaString *str2); + bool EqualToSplicedString(const JSThread *thread, const EcmaString *str1, const EcmaString *str2); // Compares strings by bytes, It doesn't check canonical unicode equivalence. static PUBLIC_API bool StringsAreEqual(const EcmaVM *vm, const JSHandle &str1, const JSHandle &str2); // Compares strings by bytes, It doesn't check canonical unicode equivalence. - static PUBLIC_API bool StringsAreEqual(EcmaString *str1, EcmaString *str2); + static PUBLIC_API bool StringsAreEqual(const JSThread *thread, EcmaString *str1, EcmaString *str2); // Two strings have the same type of utf encoding format. - static bool StringsAreEqualDiffUtfEncoding(EcmaString *str1, EcmaString *str2); + static bool StringsAreEqualDiffUtfEncoding(const JSThread *thread, EcmaString *str1, EcmaString *str2); static bool StringsAreEqualDiffUtfEncoding(const FlatStringInfo &str1, const FlatStringInfo &str2); // Compares strings by bytes, It doesn't check canonical unicode equivalence. // not change str1 data structure. // if str1 is not flat, this func has low efficiency. - static bool StringIsEqualUint8Data(const EcmaString *str1, const uint8_t *dataAddr, uint32_t dataLen, + static bool StringIsEqualUint8Data(const JSThread *thread, + const EcmaString *str1, const uint8_t *dataAddr, uint32_t dataLen, bool canBeCompress); // Compares strings by bytes, It doesn't check canonical unicode equivalence. // not change str1 data structure. // if str1 is not flat, this func has low efficiency. - static bool StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len); + static bool StringsAreEqualUtf16(const JSThread *thread, + const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len); // can change receiver and search data structure static int32_t IndexOf(const EcmaVM *vm, @@ -262,31 +265,32 @@ private: const JSHandle &receiver, const JSHandle &search, int pos = 0); // It allows user to copy into buffer even if maxLength < length - size_t WriteUtf8(uint8_t *buf, size_t maxLength, bool isWriteBuffer = false) const; + size_t WriteUtf8(const JSThread *thread, uint8_t *buf, size_t maxLength, bool isWriteBuffer = false) const; // It allows user to copy into buffer even if maxLength < length - size_t WriteUtf16(uint16_t *buf, uint32_t targetLength, uint32_t bufLength) const; + size_t WriteUtf16(const JSThread *thread, uint16_t *buf, uint32_t targetLength, uint32_t bufLength) const; - size_t WriteOneByte(uint8_t *buf, size_t maxLength) const; + size_t WriteOneByte(const JSThread *thread, uint8_t *buf, size_t maxLength) const; - uint32_t CopyDataUtf16(uint16_t *buf, uint32_t maxLength) const; + uint32_t CopyDataUtf16(const JSThread *thread, uint16_t *buf, uint32_t maxLength) const; - std::u16string ToU16String(uint32_t len = 0); + std::u16string ToU16String(const JSThread *thread, uint32_t len = 0); - Span ToUtf8Span(CVector &buf, bool modify = true, bool cesu8 = false); + Span ToUtf8Span(const JSThread *thread, CVector &buf, bool modify = true, + bool cesu8 = false); - Span DebuggerToUtf8Span(CVector &buf, bool modify = true); + Span DebuggerToUtf8Span(const JSThread *thread, CVector &buf, bool modify = true); - Span ToUtf16Span(CVector &buf) + Span ToUtf16Span(const JSThread *thread, CVector &buf) { Span str; uint32_t strLen = GetLength(); if (UNLIKELY(IsUtf16())) { - const uint16_t *data = EcmaString::GetUtf16DataFlat(this, buf); + const uint16_t *data = EcmaString::GetUtf16DataFlat(thread, this, buf); str = Span(data, strLen); } else { CVector tmpBuf; - const uint8_t *data = EcmaString::GetUtf8DataFlat(this, tmpBuf); + const uint8_t *data = EcmaString::GetUtf8DataFlat(thread, this, tmpBuf); buf.reserve(strLen); auto utf16Len = base::utf_helper::ConvertRegionUtf8ToUtf16(data, buf.data(), strLen, strLen); #if !defined(NDEBUG) @@ -298,19 +302,19 @@ private: return str; } - void WriteData(EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length); + void WriteData(const JSThread *thread, EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length); static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len); static bool CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len); static bool CanBeCompressed(const EcmaString *string); - bool PUBLIC_API ToElementIndex(uint32_t *index); + bool PUBLIC_API ToElementIndex(const JSThread *thread, uint32_t *index); - bool ToInt(int32_t *index, bool *negative); + bool ToInt(const JSThread *thread, int32_t *index, bool *negative); bool ToUInt64FromLoopStart(uint64_t *index, uint32_t loopStart, const uint8_t *data); - bool PUBLIC_API ToTypedArrayIndex(uint32_t *index); + bool PUBLIC_API ToTypedArrayIndex(const JSThread *thread, uint32_t *index); template static EcmaString *TrimBody(const JSThread *thread, const JSHandle &src, Span &data, TrimMode mode); @@ -327,7 +331,7 @@ private: template static int32_t LastIndexOf(Span &lhsSp, Span &rhsSp, int32_t pos); - bool IsFlat() const; + bool IsFlat(const JSThread *thread) const; bool IsLineString() const { @@ -348,18 +352,18 @@ private: } template - static void WriteToFlat(EcmaString *src, Char *buf, uint32_t maxLength); + static void WriteToFlat(const JSThread *thread, EcmaString *src, Char *buf, uint32_t maxLength); template - static void WriteToFlatWithPos(EcmaString *src, Char *buf, uint32_t length, uint32_t pos); + static void WriteToFlatWithPos(const JSThread *thread, EcmaString *src, Char *buf, uint32_t length, uint32_t pos); - static const uint8_t *PUBLIC_API GetUtf8DataFlat(const EcmaString *src, CVector &buf); + static const uint8_t *PUBLIC_API GetUtf8DataFlat(const JSThread *thread, const EcmaString *src, CVector &buf); - static const uint8_t *PUBLIC_API GetNonTreeUtf8Data(const EcmaString *src); + static const uint8_t *PUBLIC_API GetNonTreeUtf8Data(const JSThread *thread, const EcmaString *src); - static const uint16_t *PUBLIC_API GetUtf16DataFlat(const EcmaString *src, CVector &buf); + static const uint16_t *PUBLIC_API GetUtf16DataFlat(const JSThread *thread, const EcmaString *src, CVector &buf); - static const uint16_t *PUBLIC_API GetNonTreeUtf16Data(const EcmaString *src); + static const uint16_t *PUBLIC_API GetNonTreeUtf16Data(const JSThread *thread, const EcmaString *src); // string must be not flat static EcmaString *SlowFlatten(const EcmaVM *vm, const JSHandle &string, MemSpaceType type); @@ -500,10 +504,10 @@ public: return ToSlicedString()->SetHasBackingStore(hasBackingStore); } - JSTaggedValue GetParent() const + JSTaggedValue GetParent(const JSThread* thread) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return JSTaggedValue(ToSlicedString()->GetParent(std::move(readBarrier))); } @@ -547,10 +551,10 @@ private: // Minimum length for a sliced string template - uint16_t Get(int32_t index) const + uint16_t Get(const JSThread *thread, int32_t index) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToSlicedString()->Get(std::move(readBarrier), index); } @@ -589,10 +593,10 @@ public: return reinterpret_cast(str); } - JSTaggedValue GetFirst() const + JSTaggedValue GetFirst(const JSThread *thread) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return JSTaggedValue(ToTreeString()->GetFirst(std::move(readBarrier))); } @@ -618,10 +622,10 @@ public: ToTreeString()->SetFirst(std::move(writeBarrier), value.GetTaggedObject()); }; - JSTaggedValue GetSecond() const + JSTaggedValue GetSecond(const JSThread *thread) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return JSTaggedValue(ToTreeString()->GetSecond(std::move(readBarrier))); } @@ -647,19 +651,19 @@ public: ToTreeString()->SetSecond(std::move(writeBarrier), value.GetTaggedObject()); }; - bool IsFlat() const + bool IsFlat(const JSThread *thread) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToTreeString()->IsFlat(std::move(readBarrier)); } template - uint16_t Get(int32_t index) const + uint16_t Get(const JSThread *thread, int32_t index) const { - auto readBarrier = [](const void* obj, size_t offset)-> TaggedObject* { - return Barriers::GetTaggedObject(obj, offset); + auto readBarrier = [thread](const void* obj, size_t offset)-> TaggedObject* { + return Barriers::GetTaggedObject(thread, obj, offset); }; return ToTreeString()->Get(std::move(readBarrier), index); } @@ -735,10 +739,11 @@ public: explicit EcmaStringAccessor(const JSHandle &strHandle); - static uint32_t CalculateAllConcatHashCode(const JSHandle &firstString, + static uint32_t CalculateAllConcatHashCode(const JSThread *thread, + const JSHandle &firstString, const JSHandle &secondString) { - return EcmaString::CalculateConcatHashCode(firstString, secondString); + return EcmaString::CalculateConcatHashCode(thread, firstString, secondString); } static EcmaString *CreateLineString(const EcmaVM *vm, size_t length, bool compressed); @@ -819,7 +824,7 @@ public: } // require is LineString - inline size_t GetUtf8Length(bool isGetBufferSize = false) const; + inline size_t GetUtf8Length(const JSThread *thread, bool isGetBufferSize = false) const; size_t ObjectSize() const { @@ -860,83 +865,83 @@ public: // not change string data structure. // if string is not flat, this func has low efficiency. - std::u16string ToU16String(uint32_t len = 0) + std::u16string ToU16String(const JSThread *thread, uint32_t len = 0) { - return string_->ToU16String(len); + return string_->ToU16String(thread, len); } // not change string data structure. // if string is not flat, this func has low efficiency. - Span ToUtf8Span(CVector &buf) + Span ToUtf8Span(const JSThread *thread, CVector &buf) { - return string_->ToUtf8Span(buf); + return string_->ToUtf8Span(thread, buf); } // not change string data structure. // if string is not flat, this func has low efficiency. - std::string ToStdString(StringConvertedUsage usage = StringConvertedUsage::PRINT); + std::string ToStdString(const JSThread *thread, StringConvertedUsage usage = StringConvertedUsage::PRINT); // this function convert for Utf8 - CString Utf8ConvertToString(); + CString Utf8ConvertToString(const JSThread *thread); - std::string DebuggerToStdString(StringConvertedUsage usage = StringConvertedUsage::PRINT); + std::string DebuggerToStdString(const JSThread *thread, StringConvertedUsage usage = StringConvertedUsage::PRINT); // not change string data structure. // if string is not flat, this func has low efficiency. - CString ToCString(StringConvertedUsage usage = StringConvertedUsage::LOGICOPERATION, bool cesu8 = false); + CString ToCString(const JSThread *thread, StringConvertedUsage usage = StringConvertedUsage::LOGICOPERATION, bool cesu8 = false); #if ENABLE_NEXT_OPTIMIZATION - void AppendToCString(CString &str); - void AppendToC16String(C16String &str); + void AppendToCString(const JSThread *thread, CString &str); + void AppendToC16String(const JSThread *thread, C16String &str); #endif // not change string data structure. // if string is not flat, this func has low efficiency. - uint32_t WriteToFlatUtf8(uint8_t *buf, uint32_t maxLength, bool isWriteBuffer = false) + uint32_t WriteToFlatUtf8(const JSThread *thread, uint8_t *buf, uint32_t maxLength, bool isWriteBuffer = false) { - return string_->WriteUtf8(buf, maxLength, isWriteBuffer); + return string_->WriteUtf8(thread, buf, maxLength, isWriteBuffer); } - uint32_t WriteToUtf16(uint16_t *buf, uint32_t bufLength) + uint32_t WriteToUtf16(const JSThread *thread, uint16_t *buf, uint32_t bufLength) { - return string_->WriteUtf16(buf, GetLength(), bufLength); + return string_->WriteUtf16(thread, buf, GetLength(), bufLength); } - uint32_t WriteToOneByte(uint8_t *buf, uint32_t maxLength) + uint32_t WriteToOneByte(const JSThread *thread, uint8_t *buf, uint32_t maxLength) { - return string_->WriteOneByte(buf, maxLength); + return string_->WriteOneByte(thread, buf, maxLength); } // not change string data structure. // if string is not flat, this func has low efficiency. - uint32_t WriteToFlatUtf16(uint16_t *buf, uint32_t maxLength) const + uint32_t WriteToFlatUtf16(const JSThread *thread, uint16_t *buf, uint32_t maxLength) const { - return string_->CopyDataUtf16(buf, maxLength); + return string_->CopyDataUtf16(thread, buf, maxLength); } template - static void WriteToFlatWithPos(EcmaString *src, Char *buf, uint32_t length, uint32_t pos) + static void WriteToFlatWithPos(const JSThread *thread, EcmaString *src, Char *buf, uint32_t length, uint32_t pos) { - src->WriteToFlatWithPos(src, buf, length, pos); + src->WriteToFlatWithPos(thread, src, buf, length, pos); } template - static void WriteToFlat(EcmaString *src, Char *buf, uint32_t maxLength) + static void WriteToFlat(const JSThread *thread, EcmaString *src, Char *buf, uint32_t maxLength) { - src->WriteToFlat(src, buf, maxLength); + src->WriteToFlat(thread, src, buf, maxLength); } // require dst is LineString // not change src data structure. // if src is not flat, this func has low efficiency. - inline static void ReadData(EcmaString * dst, EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length); + inline static void ReadData(const JSThread *thread, EcmaString * dst, EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length); // not change src data structure. // if src is not flat, this func has low efficiency. template - uint16_t Get(uint32_t index) const + uint16_t Get(const JSThread *thread, uint32_t index) const { - return string_->At(index); + return string_->At(thread, index); } // require string is LineString. @@ -947,14 +952,14 @@ public: // not change src data structure. // if src is not flat, this func has low efficiency. - uint32_t GetHashcode() + uint32_t GetHashcode(const JSThread *thread) { - return string_->GetHashcode(); + return string_->GetHashcode(thread); } - uint32_t ComputeHashcode() + uint32_t ComputeHashcode(const JSThread *thread) { - return string_->ComputeRawHashcode(); + return string_->ComputeRawHashcode(thread); } static uint32_t ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len, bool canBeCompress) @@ -1003,39 +1008,40 @@ public: // not change str1 and str2 data structure. // if str1 or str2 is not flat, this func has low efficiency. - static bool StringsAreEqual(EcmaString *str1, EcmaString *str2) + static bool StringsAreEqual(const JSThread *thread, EcmaString *str1, EcmaString *str2) { - return EcmaString::StringsAreEqual(str1, str2); + return EcmaString::StringsAreEqual(thread, str1, str2); } // not change str1 and str2 data structure. // if str1 or str2 is not flat, this func has low efficiency. - static bool StringsAreEqualDiffUtfEncoding(EcmaString *str1, EcmaString *str2) + static bool StringsAreEqualDiffUtfEncoding(const JSThread *thread, EcmaString *str1, EcmaString *str2) { - return EcmaString::StringsAreEqualDiffUtfEncoding(str1, str2); + return EcmaString::StringsAreEqualDiffUtfEncoding(thread, str1, str2); } // not change str1 data structure. // if str1 is not flat, this func has low efficiency. - static bool StringIsEqualUint8Data(const EcmaString *str1, const uint8_t *dataAddr, uint32_t dataLen, + static bool StringIsEqualUint8Data(const JSThread *thread, + const EcmaString *str1, const uint8_t *dataAddr, uint32_t dataLen, bool canBeCompress) { - return EcmaString::StringIsEqualUint8Data(str1, dataAddr, dataLen, canBeCompress); + return EcmaString::StringIsEqualUint8Data(thread, str1, dataAddr, dataLen, canBeCompress); } // not change str1 data structure. // if str1 is not flat, this func has low efficiency. - static bool StringsAreEqualUtf16(const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len) + static bool StringsAreEqualUtf16(const JSThread *thread, const EcmaString *str1, const uint16_t *utf16Data, uint32_t utf16Len) { - return EcmaString::StringsAreEqualUtf16(str1, utf16Data, utf16Len); + return EcmaString::StringsAreEqualUtf16(thread, str1, utf16Data, utf16Len); } // require str1 and str2 are LineString. // not change string data structure. // if string is not flat, this func has low efficiency. - bool EqualToSplicedString(const EcmaString *str1, const EcmaString *str2) + bool EqualToSplicedString(const JSThread *thread, const EcmaString *str1, const EcmaString *str2) { - return string_->EqualToSplicedString(str1, str2); + return string_->EqualToSplicedString(thread, str1, str2); } static bool CanBeCompressed(const uint8_t *utf8Data, uint32_t utf8Len) @@ -1056,23 +1062,23 @@ public: // not change string data structure. // if string is not flat, this func has low efficiency. - bool ToElementIndex(uint32_t *index) + bool ToElementIndex(const JSThread *thread, uint32_t *index) { - return string_->ToElementIndex(index); + return string_->ToElementIndex(thread, index); } // not change string data structure. // if string is not flat, this func has low efficiency. - bool ToInt(int32_t *index, bool *negative) + bool ToInt(const JSThread *thread, int32_t *index, bool *negative) { - return string_->ToInt(index, negative); + return string_->ToInt(thread, index, negative); } // not change string data structure. // if string is not flat, this func has low efficiency. - bool PUBLIC_API ToTypedArrayIndex(uint32_t *index) + bool PUBLIC_API ToTypedArrayIndex(const JSThread *thread, uint32_t *index) { - return string_->ToTypedArrayIndex(index); + return string_->ToTypedArrayIndex(thread, index); } static EcmaString *ToLower(const EcmaVM *vm, const JSHandle &src) @@ -1120,9 +1126,9 @@ public: return data <= base::utf_helper::UTF8_1B_MAX; } - bool IsFlat() const + bool IsFlat(const JSThread *thread) const { - return string_->IsFlat(); + return string_->IsFlat(thread); } bool IsLineString() const @@ -1169,24 +1175,24 @@ public: return EcmaString::FlattenNoGCForSnapshot(vm, string); } - static const uint8_t *GetUtf8DataFlat(const EcmaString *src, CVector &buf) + static const uint8_t *GetUtf8DataFlat(const JSThread *thread, const EcmaString *src, CVector &buf) { - return EcmaString::GetUtf8DataFlat(src, buf); + return EcmaString::GetUtf8DataFlat(thread, src, buf); } - static const uint8_t *GetNonTreeUtf8Data(const EcmaString *src) + static const uint8_t *GetNonTreeUtf8Data(const JSThread *thread, const EcmaString *src) { - return EcmaString::GetNonTreeUtf8Data(src); + return EcmaString::GetNonTreeUtf8Data(thread, src); } - static const uint16_t *GetUtf16DataFlat(const EcmaString *src, CVector &buf) + static const uint16_t *GetUtf16DataFlat(const JSThread *thread, const EcmaString *src, CVector &buf) { - return EcmaString::GetUtf16DataFlat(src, buf); + return EcmaString::GetUtf16DataFlat(thread, src, buf); } - static const uint16_t *GetNonTreeUtf16Data(const EcmaString *src) + static const uint16_t *GetNonTreeUtf16Data(const JSThread *thread, const EcmaString *src) { - return EcmaString::GetNonTreeUtf16Data(src); + return EcmaString::GetNonTreeUtf16Data(thread, src); } static JSTaggedValue StringToList(JSThread *thread, JSHandle &str); diff --git a/ecmascript/ecma_string_table.cpp b/ecmascript/ecma_string_table.cpp index c23e46fd34..913d5c2575 100644 --- a/ecmascript/ecma_string_table.cpp +++ b/ecmascript/ecma_string_table.cpp @@ -92,7 +92,7 @@ EcmaString *EcmaStringTable::GetStringFromCompressedSubString(JSThread *thread, auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, true)) { + if (EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, true)) { return foundString; } } @@ -112,7 +112,7 @@ EcmaString *EcmaStringTable::GetString(JSThread *thread, JSHandle st auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringsAreEqual(foundString, str)) { + if (EcmaStringAccessor::StringsAreEqual(thread, foundString, str)) { return foundString; } } @@ -136,7 +136,7 @@ EcmaString *EcmaStringTable::GetString(JSThread *thread, const JSHandlesecond; - if (EcmaStringAccessor(foundString).EqualToSplicedString(firstStr, secondStr)) { + if (EcmaStringAccessor(foundString).EqualToSplicedString(thread, firstStr, secondStr)) { return foundString; } } @@ -156,7 +156,7 @@ EcmaString *EcmaStringTable::GetString(JSThread *thread, const uint8_t *utf8Data auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, canBeCompress)) { + if (EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, canBeCompress)) { return foundString; } } @@ -176,20 +176,20 @@ EcmaString *EcmaStringTable::GetString(JSThread *thread, const uint16_t *utf16Da auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringsAreEqualUtf16(foundString, utf16Data, utf16Len)) { + if (EcmaStringAccessor::StringsAreEqualUtf16(thread, foundString, utf16Data, utf16Len)) { return foundString; } } return nullptr; } -EcmaString *EcmaStringTable::GetStringThreadUnsafe(EcmaString *string, uint32_t hashcode) const +EcmaString *EcmaStringTable::GetStringThreadUnsafe(JSThread *thread, EcmaString *string, uint32_t hashcode) const { ASSERT(EcmaStringAccessor(string).NotTreeString()); auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringsAreEqual(foundString, string)) { + if (EcmaStringAccessor::StringsAreEqual(thread, foundString, string)) { return foundString; } } @@ -228,7 +228,7 @@ EcmaString *EcmaStringTable::AtomicGetOrInternStringImpl(JSThread *thread, const } #endif EcmaString *str = *string; - EcmaString *result = GetStringThreadUnsafe(str, hashcode); + EcmaString *result = GetStringThreadUnsafe(thread, str, hashcode); if (result == nullptr) { InternStringThreadUnsafe(str, hashcode); return str; @@ -244,7 +244,7 @@ EcmaString *EcmaStringTable::GetOrInternFlattenString(EcmaVM *vm, EcmaString *st } JSThread *thread = vm->GetJSThread(); JSHandle stringHandle(thread, string); - uint32_t hashcode = EcmaStringAccessor(string).GetHashcode(); + uint32_t hashcode = EcmaStringAccessor(string).GetHashcode(thread); return AtomicGetOrInternStringImpl(thread, stringHandle, hashcode); } @@ -278,7 +278,7 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, EcmaString *string) if (EcmaStringAccessor(strFlat).IsInternString()) { return strFlat; } - uint32_t hashcode = EcmaStringAccessor(strFlat).GetHashcode(); + uint32_t hashcode = EcmaStringAccessor(strFlat).GetHashcode(thread); JSHandle strFlatHandle(thread, strFlat); EcmaString *result = GetString(thread, strFlatHandle, hashcode); if (result != nullptr) { @@ -297,7 +297,7 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const JSHandleGetJSThread(); JSHandle firstFlat(thread, EcmaStringAccessor::Flatten(vm, firstString)); JSHandle secondFlat(thread, EcmaStringAccessor::Flatten(vm, secondString)); - uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(firstFlat, secondFlat); + uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(thread, firstFlat, secondFlat); EcmaString *result = GetString(thread, firstFlat, secondFlat, hashcode); if (result != nullptr) { return result; @@ -338,7 +338,7 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const uint8_t *utf8Da JSThread *thread = vm->GetJSThread(); EcmaString *str = EcmaStringAccessor::CreateUtf16StringFromUtf8(vm, utf8Data, utf16Len, type); JSHandle strHandle(thread, str); - uint32_t hashcode = EcmaStringAccessor(str).GetHashcode(); + uint32_t hashcode = EcmaStringAccessor(str).GetHashcode(thread); return AtomicGetOrInternStringImpl(thread, strHandle, hashcode); } @@ -357,7 +357,7 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const uint16_t *utf16 return AtomicGetOrInternStringImpl(thread, strHandle, hashcode); } -void EcmaStringTable::InsertStringToTableWithHashThreadUnsafe(EcmaString* string, uint32_t hashcode) +void EcmaStringTable::InsertStringToTableWithHashThreadUnsafe([[maybe_unused]] JSThread *thread, EcmaString* string, uint32_t hashcode) { // Strings in string table should not be in the young space. #ifdef USE_CMC_GC @@ -366,7 +366,7 @@ void EcmaStringTable::InsertStringToTableWithHashThreadUnsafe(EcmaString* string ASSERT(Region::ObjectAddressToRange(reinterpret_cast(string))->InSharedHeap()); #endif ASSERT(EcmaStringAccessor(string).NotTreeString()); - ASSERT(EcmaStringAccessor(string).GetHashcode() == hashcode); + ASSERT(EcmaStringAccessor(string).GetHashcode(thread) == hashcode); stringTable_[GetTableId(hashcode)].table_.emplace(hashcode, string); EcmaStringAccessor(string).SetInternString(); } @@ -376,7 +376,7 @@ EcmaString *EcmaStringTable::InsertStringToTable(EcmaVM *vm, const JSHandleGetJSThread(); EcmaString *strFlat = EcmaStringAccessor::Flatten(vm, strHandle, MemSpaceType::SHARED_OLD_SPACE); JSHandle strFlatHandle(thread, strFlat); - uint32_t hashcode = EcmaStringAccessor(strFlat).GetHashcode(); + uint32_t hashcode = EcmaStringAccessor(strFlat).GetHashcode(thread); RuntimeLockHolder locker(thread, stringTable_[GetTableId(hashcode)].mutex_); #if ECMASCRIPT_ENABLE_SCOPE_LOCK_STAT if (vm->IsCollectingScopeLockStats()) { @@ -390,7 +390,7 @@ EcmaString *EcmaStringTable::InsertStringToTable(EcmaVM *vm, const JSHandle &string) { - uint32_t hashcode = EcmaStringAccessor(*string).GetHashcode(); + uint32_t hashcode = EcmaStringAccessor(*string).GetHashcode(thread); return GetString(thread, string, hashcode); } @@ -408,7 +408,7 @@ EcmaString *EcmaStringTable::GetOrInternStringWithoutJSHandleForJit(EcmaVM *vm, vm->IncreaseStringTableLockCount(); } #endif - EcmaString *result = GetStringThreadUnsafe(utf8Data, utf8Len, canBeCompress, hashcode); + EcmaString *result = GetStringThreadUnsafe(thread, utf8Data, utf8Len, canBeCompress, hashcode); if (result != nullptr) { return result; } @@ -429,13 +429,14 @@ EcmaString *EcmaStringTable::GetOrInternStringWithoutJSHandleForJit(EcmaVM *vm, CVector u16Buffer(utf16Len); utf::ConvertRegionMUtf8ToUtf16(utf8Data, u16Buffer.data(), utf::Mutf8Size(utf8Data), utf16Len, 0); uint32_t hashcode = EcmaStringAccessor::ComputeHashcodeUtf16(u16Buffer.data(), utf16Len); - RuntimeLockHolder locker(vm->GetJSThread(), stringTable_[GetTableId(hashcode)].mutex_); + JSThread *thread = vm->GetJSThread(); + RuntimeLockHolder locker(thread, stringTable_[GetTableId(hashcode)].mutex_); #if ECMASCRIPT_ENABLE_SCOPE_LOCK_STAT if (vm->IsCollectingScopeLockStats()) { vm->IncreaseStringTableLockCount(); } #endif - EcmaString *result = GetStringThreadUnsafe(u16Buffer.data(), utf16Len, hashcode); + EcmaString *result = GetStringThreadUnsafe(thread, u16Buffer.data(), utf16Len, hashcode); if (result != nullptr) { return result; } @@ -514,11 +515,11 @@ bool EcmaStringTable::CheckStringTableValidity(JSThread *thread) return false; } int counter = 0; - auto hashcode = EcmaStringAccessor(outerString).GetHashcode(); + auto hashcode = EcmaStringAccessor(outerString).GetHashcode(thread); auto range = table.equal_range(hashcode); for (auto it = range.first; it != range.second; ++it) { auto foundString = it->second; - counter += EcmaStringAccessor::StringsAreEqual(foundString, outerString) ? 1 : 0; + counter += EcmaStringAccessor::StringsAreEqual(thread, foundString, outerString) ? 1 : 0; } if (counter > 1) { return false; @@ -549,8 +550,8 @@ EcmaString *EcmaStringTable::GetOrInternStringThreadUnsafe(EcmaVM *vm, JSThread *thread = vm->GetJSThreadNoCheck(); JSHandle firstFlat(thread, EcmaStringAccessor::Flatten(vm, firstString)); JSHandle secondFlat(thread, EcmaStringAccessor::Flatten(vm, secondString)); - uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(firstFlat, secondFlat); - EcmaString *result = GetStringThreadUnsafe(firstFlat, secondFlat, hashcode); + uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(thread, firstFlat, secondFlat); + EcmaString *result = GetStringThreadUnsafe(thread, firstFlat, secondFlat, hashcode); if (result != nullptr) { return result; } @@ -568,7 +569,7 @@ EcmaString *EcmaStringTable::GetOrInternStringThreadUnsafe(EcmaVM *vm, const uin { ASSERT(vm->GetJsDebuggerManager()->GetSignalState()); uint32_t hashcode = EcmaStringAccessor::ComputeHashcodeUtf8(utf8Data, utf8Len, canBeCompress); - EcmaString *result = GetStringThreadUnsafe(utf8Data, utf8Len, canBeCompress, hashcode); + EcmaString *result = GetStringThreadUnsafe(vm->GetJSThread(), utf8Data, utf8Len, canBeCompress, hashcode); if (result != nullptr) { return result; } @@ -580,7 +581,8 @@ EcmaString *EcmaStringTable::GetOrInternStringThreadUnsafe(EcmaVM *vm, const uin } // This should only call in Debugger Signal, and need to fix and remove -EcmaString *EcmaStringTable::GetStringThreadUnsafe(const JSHandle firstString, +EcmaString *EcmaStringTable::GetStringThreadUnsafe(JSThread *thread, + const JSHandle firstString, const JSHandle secondString, uint32_t hashcode) const { @@ -591,7 +593,7 @@ EcmaString *EcmaStringTable::GetStringThreadUnsafe(const JSHandle fi auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor(foundString).EqualToSplicedString(firstStr, secondStr)) { + if (EcmaStringAccessor(foundString).EqualToSplicedString(thread, firstStr, secondStr)) { return foundString; } } @@ -599,13 +601,14 @@ EcmaString *EcmaStringTable::GetStringThreadUnsafe(const JSHandle fi } // This should only call in Debugger Signal, and need to fix and remove -EcmaString *EcmaStringTable::GetStringThreadUnsafe(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, +EcmaString *EcmaStringTable::GetStringThreadUnsafe(JSThread *thread, + const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, uint32_t hashcode) const { auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, canBeCompress)) { + if (EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, canBeCompress)) { return foundString; } } @@ -613,13 +616,14 @@ EcmaString *EcmaStringTable::GetStringThreadUnsafe(const uint8_t *utf8Data, uint } // This should only call in JIT Thread, and need to fix and remove -EcmaString *EcmaStringTable::GetStringThreadUnsafe(const uint16_t *utf16Data, uint32_t utf16Len, +EcmaString *EcmaStringTable::GetStringThreadUnsafe(JSThread *thread, + const uint16_t *utf16Data, uint32_t utf16Len, uint32_t hashcode) const { auto range = stringTable_[GetTableId(hashcode)].table_.equal_range(hashcode); for (auto item = range.first; item != range.second;) { auto foundString = (item++)->second; - if (EcmaStringAccessor::StringsAreEqualUtf16(foundString, utf16Data, utf16Len)) { + if (EcmaStringAccessor::StringsAreEqualUtf16(thread, foundString, utf16Data, utf16Len)) { return foundString; } } diff --git a/ecmascript/ecma_string_table.h b/ecmascript/ecma_string_table.h index 07a29733b6..fc24260966 100644 --- a/ecmascript/ecma_string_table.h +++ b/ecmascript/ecma_string_table.h @@ -162,17 +162,17 @@ public: } }; - HashTrieMapLoadResult Load(const uint32_t key, EcmaString *value); + HashTrieMapLoadResult Load(JSThread *thread, const uint32_t key, EcmaString *value); EcmaString *StoreOrLoad(EcmaVM *vm, const uint32_t key, HashTrieMapLoadResult loadResult, JSHandle str); - HashTrieMapLoadResult Load(const uint32_t key, const JSHandle &string, uint32_t offset, - uint32_t utf8Len); + HashTrieMapLoadResult Load(JSThread *thread, const uint32_t key, const JSHandle &string, + uint32_t offset, uint32_t utf8Len); template EcmaString *StoreOrLoad(EcmaVM *vm, const uint32_t key, HashTrieMapLoadResult loadResult, LoaderCallback loaderCallback, EqualsCallback equalsCallback); template - EcmaString *Load(const uint32_t key, EcmaString *value); + EcmaString *Load(JSThread *thread, const uint32_t key, EcmaString *value); template EcmaString *LoadOrStore(EcmaVM *vm, const uint32_t key, LoaderCallback loaderCallback, EqualsCallback equalsCallback); @@ -190,9 +190,9 @@ public: #endif // Iterator - void Range(bool &isValid) + void Range(JSThread *thread, bool &isValid) { - Iter(root_.load(std::memory_order_relaxed), isValid); + Iter(thread, root_.load(std::memory_order_relaxed), isValid); } void Clear(); // ut used @@ -213,12 +213,12 @@ private: std::atomic inuseCount_ {0}; template Node *Expand(Entry *oldEntry, Entry *newEntry, uint32_t newHash, uint32_t hashShift, Indirect *parent); - void Iter(Indirect *node, bool &isValid); + void Iter(JSThread *thread, Indirect *node, bool &isValid); bool CheckWeakRef(const WeakRootVisitor &visitor, Entry *entry); #ifdef USE_CMC_GC bool CheckWeakRef(WeakVisitor &visitor, Entry *entry); #endif - bool CheckValidity(EcmaString *value, bool &isValid); + bool CheckValidity(JSThread *thread, EcmaString *value, bool &isValid); }; class HashTrieMapInUseScope { @@ -330,7 +330,7 @@ public: MemSpaceType type); EcmaString *GetOrInternStringWithoutJSHandleForJit(EcmaVM *vm, const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, MemSpaceType type); - EcmaString *TryGetInternString(const JSHandle &string); + EcmaString *TryGetInternString(JSThread *thread, const JSHandle &string); void SweepWeakRef(const WeakRootVisitor &visitor); void SweepWeakRef(const WeakRootVisitor &visitor, uint32_t index); @@ -340,7 +340,7 @@ public: void IterWeakRoot(WeakVisitor &visitor, uint32_t index); #endif - bool CheckStringTableValidity(); + bool CheckStringTableValidity(JSThread *thread); EcmaStringTableCleaner *GetCleaner() { @@ -351,7 +351,7 @@ private: NO_COPY_SEMANTIC(EcmaStringTable); NO_MOVE_SEMANTIC(EcmaStringTable); - EcmaString *GetString(const JSHandle string, uint32_t hashcode); + EcmaString *GetString(JSThread *thread, const JSHandle string, uint32_t hashcode); /** * * These are some "incorrect" functions, which need to fix the call chain to be removed. @@ -377,9 +377,9 @@ public: return reinterpret_cast(object); } static JSTaggedValue CreateSingleCharTable(JSThread *thread); - JSTaggedValue GetStringFromSingleCharTable(int32_t ch) + JSTaggedValue GetStringFromSingleCharTable(JSThread *thread, int32_t ch) { - return Get(ch); + return Get(thread, ch); } private: @@ -509,7 +509,7 @@ private: NO_COPY_SEMANTIC(EcmaStringTable); NO_MOVE_SEMANTIC(EcmaStringTable); - EcmaString *GetStringThreadUnsafe(EcmaString *string, uint32_t hashcode) const; + EcmaString *GetStringThreadUnsafe(JSThread *thread, EcmaString *string, uint32_t hashcode) const; void InternStringThreadUnsafe(EcmaString *string, uint32_t hashcode); EcmaString *AtomicGetOrInternStringImpl(JSThread *thread, const JSHandle string, uint32_t hashcode); @@ -525,7 +525,7 @@ private: EcmaString *GetString(JSThread *thread, const uint16_t *utf16Data, uint32_t utf16Len, uint32_t hashcode); // This used only for SnapShot. - void InsertStringToTableWithHashThreadUnsafe(EcmaString* string, uint32_t hashcode); + void InsertStringToTableWithHashThreadUnsafe(JSThread *thread, EcmaString* string, uint32_t hashcode); /** * * These are some "incorrect" functions, which need to fix the call chain to be removed. @@ -539,13 +539,13 @@ private: EcmaString *GetOrInternStringThreadUnsafe(EcmaVM *vm, const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress); // This should only call in Debugger Signal, and need to fix and remove - EcmaString *GetStringThreadUnsafe(const JSHandle firstString, const JSHandle secondString, + EcmaString *GetStringThreadUnsafe(JSThread *thread, const JSHandle firstString, const JSHandle secondString, uint32_t hashcode) const; // This should only call in Debugger Signal or from JIT, and need to fix and remove - EcmaString *GetStringThreadUnsafe(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, + EcmaString *GetStringThreadUnsafe(JSThread *thread, const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress, uint32_t hashcode) const; // This should only call in JIT Thread, and need to fix and remove - EcmaString *GetStringThreadUnsafe(const uint16_t *utf16Data, uint32_t utf16Len, uint32_t hashcode) const; + EcmaString *GetStringThreadUnsafe(JSThread *thread, const uint16_t *utf16Data, uint32_t utf16Len, uint32_t hashcode) const; struct Segment { CUnorderedMultiMap table_; @@ -566,9 +566,9 @@ public: return reinterpret_cast(object); } static JSTaggedValue CreateSingleCharTable(JSThread *thread); - JSTaggedValue GetStringFromSingleCharTable(int32_t ch) + JSTaggedValue GetStringFromSingleCharTable(JSThread *thread, int32_t ch) { - return Get(ch); + return Get(thread, ch); } private: SingleCharTable() = default; diff --git a/ecmascript/ecma_string_table_optimization-inl.h b/ecmascript/ecma_string_table_optimization-inl.h index 628f119fc0..13b84a0fa5 100644 --- a/ecmascript/ecma_string_table_optimization-inl.h +++ b/ecmascript/ecma_string_table_optimization-inl.h @@ -72,7 +72,7 @@ HashTrieMap::Node *HashTrieMap::Expand(Entry *oldEntry, Entry *newEntry, uint32_ // Load returns the value of the key stored in the mapping, or nullptr value if not template -EcmaString *HashTrieMap::Load(const uint32_t key, EcmaString *value) +EcmaString *HashTrieMap::Load(JSThread *thread, const uint32_t key, EcmaString *value) { uint32_t hash = key; Indirect *current = root_.load(std::memory_order_relaxed); @@ -89,7 +89,8 @@ EcmaString *HashTrieMap::Load(const uint32_t key, EcmaString *value) for (Entry *currentEntry = node->AsEntry(); currentEntry != nullptr; currentEntry = currentEntry->Overflow().load(std::memory_order_acquire)) { if (currentEntry->Key() == key) { - bool valuesEqual = EcmaStringAccessor::StringsAreEqual(currentEntry->Value(), value); + bool valuesEqual = + EcmaStringAccessor::StringsAreEqual(thread, currentEntry->Value(), value); if constexpr (IsCheck) { if (!valuesEqual) { return currentEntry->Value(); diff --git a/ecmascript/ecma_string_table_optimization.cpp b/ecmascript/ecma_string_table_optimization.cpp index 2af131832d..5fe96f9eb3 100644 --- a/ecmascript/ecma_string_table_optimization.cpp +++ b/ecmascript/ecma_string_table_optimization.cpp @@ -79,10 +79,10 @@ bool EcmaStringTableCleaner::SweepWeakRefTask::Run([[maybe_unused]] uint32_t thr return true; } -EcmaString *EcmaStringTable::GetString(JSHandle string, uint32_t hashcode) +EcmaString *EcmaStringTable::GetString(JSThread *thread, JSHandle string, uint32_t hashcode) { EcmaString *str = *string; - return stringTable_.Load(hashcode, str); + return stringTable_.Load(thread, hashcode, str); } EcmaString *EcmaStringTable::GetOrInternFlattenString(EcmaVM *vm, EcmaString *string) @@ -91,7 +91,8 @@ EcmaString *EcmaStringTable::GetOrInternFlattenString(EcmaVM *vm, EcmaString *st if (EcmaStringAccessor(string).IsInternString()) { return string; } - uint32_t hashcode = EcmaStringAccessor(string).GetHashcode(); + JSThread *thread = vm->GetAssociatedJSThread(); + uint32_t hashcode = EcmaStringAccessor(string).GetHashcode(thread); ASSERT(!EcmaStringAccessor(string).IsInternString()); ASSERT(EcmaStringAccessor(string).NotTreeString()); // Strings in string table should not be in the young space. @@ -100,11 +101,10 @@ EcmaString *EcmaStringTable::GetOrInternFlattenString(EcmaVM *vm, EcmaString *st #else ASSERT(Region::ObjectAddressToRange(reinterpret_cast(string))->InSharedHeap()); #endif - auto loadResult = stringTable_.Load(hashcode, string); + auto loadResult = stringTable_.Load(thread, hashcode, string); if (loadResult) { return loadResult.value; } - JSThread *thread = vm->GetJSThread(); JSHandle stringHandle(thread, string); EcmaString *result = stringTable_.StoreOrLoad(vm, hashcode, loadResult, stringHandle); ASSERT(result != nullptr); @@ -116,7 +116,8 @@ EcmaString *EcmaStringTable::GetOrInternStringFromCompressedSubString(EcmaVM *vm { const uint8_t *utf8Data = EcmaStringAccessor(string).GetDataUtf8() + offset; uint32_t hashcode = EcmaStringAccessor::ComputeHashcodeUtf8(utf8Data, utf8Len, true); - auto loadResult = stringTable_.Load(hashcode, string, offset, utf8Len); + JSThread *thread = vm->GetAssociatedJSThread(); + auto loadResult = stringTable_.Load(thread, hashcode, string, offset, utf8Len); if (loadResult) { return loadResult.value; } @@ -138,9 +139,10 @@ EcmaString *EcmaStringTable::GetOrInternStringFromCompressedSubString(EcmaVM *vm JSHandle strHandle(thread, str); return strHandle; }, - [utf8Len, string, offset](EcmaString *foundString) { + [vm, utf8Len, string, offset](EcmaString *foundString) { + JSThread *thread = vm->GetAssociatedJSThread(); const uint8_t *utf8Data = EcmaStringAccessor(string).GetDataUtf8() + offset; - return EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, true); + return EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, true); }); ASSERT(result != nullptr); return result; @@ -158,8 +160,8 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, EcmaString *string) if (EcmaStringAccessor(strFlat).IsInternString()) { return strFlat; } - uint32_t hashcode = EcmaStringAccessor(strFlat).GetHashcode(); - auto loadResult = stringTable_.Load(hashcode, strFlat); + uint32_t hashcode = EcmaStringAccessor(strFlat).GetHashcode(thread); + auto loadResult = stringTable_.Load(thread, hashcode, strFlat); if (loadResult) { return loadResult.value; } @@ -179,7 +181,7 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const JSHandleGetJSThread(); JSHandle firstFlat(thread, EcmaStringAccessor::Flatten(vm, firstString)); JSHandle secondFlat(thread, EcmaStringAccessor::Flatten(vm, secondString)); - uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(firstFlat, secondFlat); + uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(thread, firstFlat, secondFlat); ASSERT(EcmaStringAccessor(firstFlat).NotTreeString()); ASSERT(EcmaStringAccessor(secondFlat).NotTreeString()); EcmaString *result = stringTable_.LoadOrStore( @@ -200,10 +202,10 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const JSHandle stringHandle(thread, value); return stringHandle; }, - [firstFlat, secondFlat](EcmaString *foundString) { + [thread, firstFlat, secondFlat](EcmaString *foundString) { EcmaString *firstStr = *firstFlat; EcmaString *secondStr = *secondFlat; - return EcmaStringAccessor(foundString).EqualToSplicedString(firstStr, secondStr); + return EcmaStringAccessor(foundString).EqualToSplicedString(thread, firstStr, secondStr); }); ASSERT(result != nullptr); return result; @@ -235,8 +237,9 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const uint8_t *utf8Da JSHandle stringHandle(thread, value); return stringHandle; }, - [utf8Data, utf8Len, canBeCompress](EcmaString *foundString) { - return EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, canBeCompress); + [vm, utf8Data, utf8Len, canBeCompress](EcmaString *foundString) { + JSThread *thread = vm->GetAssociatedJSThread(); + return EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, canBeCompress); }); ASSERT(result != nullptr); return result; @@ -249,8 +252,8 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const uint8_t *utf8Da ASSERT(type == MemSpaceType::SHARED_NON_MOVABLE || type == MemSpaceType::SHARED_OLD_SPACE); JSThread *thread = vm->GetJSThread(); EcmaString *str = EcmaStringAccessor::CreateUtf16StringFromUtf8(vm, utf8Data, utf16Len, type); - uint32_t hashcode = EcmaStringAccessor(str).GetHashcode(); - auto loadResult = stringTable_.Load(hashcode, str); + uint32_t hashcode = EcmaStringAccessor(str).GetHashcode(thread); + auto loadResult = stringTable_.Load(thread, hashcode, str); if (loadResult) { return loadResult.value; } @@ -283,17 +286,18 @@ EcmaString *EcmaStringTable::GetOrInternString(EcmaVM *vm, const uint16_t *utf16 JSHandle stringHandle(thread, value); return stringHandle; }, - [utf16Data, utf16Len](EcmaString *foundString) { - return EcmaStringAccessor::StringsAreEqualUtf16(foundString, utf16Data, utf16Len); + [vm, utf16Data, utf16Len](EcmaString *foundString) { + JSThread *thread = vm->GetAssociatedJSThread(); + return EcmaStringAccessor::StringsAreEqualUtf16(thread, foundString, utf16Data, utf16Len); }); ASSERT(result != nullptr); return result; } -EcmaString *EcmaStringTable::TryGetInternString(const JSHandle &string) +EcmaString *EcmaStringTable::TryGetInternString(JSThread *thread, const JSHandle &string) { - uint32_t hashcode = EcmaStringAccessor(*string).GetHashcode(); - return GetString(string, hashcode); + uint32_t hashcode = EcmaStringAccessor(*string).GetHashcode(thread); + return GetString(thread, string, hashcode); } // used in jit thread, which unsupport create jshandle @@ -320,8 +324,9 @@ EcmaString *EcmaStringTable::GetOrInternStringWithoutJSHandleForJit(EcmaVM *vm, #endif return value; }, - [utf8Data, utf8Len, canBeCompress](EcmaString *foundString) { - return EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, canBeCompress); + [vm, utf8Data, utf8Len, canBeCompress](EcmaString *foundString) { + JSThread *thread = vm->GetAssociatedJSThread(); + return EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, canBeCompress); }); ASSERT(result != nullptr); return result; @@ -354,8 +359,9 @@ EcmaString *EcmaStringTable::GetOrInternStringWithoutJSHandleForJit(EcmaVM *vm, #endif return value; }, - [utf16Data, utf16Len](EcmaString *foundString) { - return EcmaStringAccessor::StringsAreEqualUtf16(foundString, utf16Data, utf16Len); + [vm, utf16Data, utf16Len](EcmaString *foundString) { + JSThread *thread = vm->GetAssociatedJSThread(); + return EcmaStringAccessor::StringsAreEqualUtf16(thread, foundString, utf16Data, utf16Len); }); ASSERT(result != nullptr); return result; @@ -381,10 +387,10 @@ void EcmaStringTable::SweepWeakRef(const WeakRootVisitor &visitor, uint32_t inde stringTable_.ClearNodeFromGC(root_node, index, visitor); } -bool EcmaStringTable::CheckStringTableValidity() +bool EcmaStringTable::CheckStringTableValidity(JSThread *thread) { bool isValid = true; - stringTable_.Range(isValid); + stringTable_.Range(thread, isValid); return isValid; } @@ -408,7 +414,7 @@ EcmaString *EcmaStringTable::GetOrInternStringThreadUnsafe(EcmaVM *vm, const JSH JSThread *thread = vm->GetJSThreadNoCheck(); JSHandle firstFlat(thread, EcmaStringAccessor::Flatten(vm, firstString)); JSHandle secondFlat(thread, EcmaStringAccessor::Flatten(vm, secondString)); - uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(firstFlat, secondFlat); + uint32_t hashcode = EcmaStringAccessor::CalculateAllConcatHashCode(thread, firstFlat, secondFlat); ASSERT(EcmaStringAccessor(firstFlat).NotTreeString()); ASSERT(EcmaStringAccessor(secondFlat).NotTreeString()); EcmaString *result = stringTable_.LoadOrStore( @@ -429,10 +435,11 @@ EcmaString *EcmaStringTable::GetOrInternStringThreadUnsafe(EcmaVM *vm, const JSH JSHandle stringHandle(thread, concatString); return stringHandle; }, - [firstFlat, secondFlat](EcmaString *foundString) { + [vm, firstFlat, secondFlat](EcmaString *foundString) { EcmaString *firstStr = *firstFlat; EcmaString *secondStr = *secondFlat; - return EcmaStringAccessor(foundString).EqualToSplicedString(firstStr, secondStr); + JSThread *thread = vm->GetAssociatedJSThread(); + return EcmaStringAccessor(foundString).EqualToSplicedString(thread, firstStr, secondStr); }); ASSERT(result != nullptr); return result; @@ -454,15 +461,17 @@ EcmaString *EcmaStringTable::GetOrInternStringThreadUnsafe(EcmaVM *vm, const uin JSHandle stringHandle(thread, value); return stringHandle; }, - [utf8Data, utf8Len, canBeCompress](EcmaString *foundString) { - return EcmaStringAccessor::StringIsEqualUint8Data(foundString, utf8Data, utf8Len, canBeCompress); + [vm, utf8Data, utf8Len, canBeCompress](EcmaString *foundString) { + JSThread *thread = vm->GetAssociatedJSThread(); + return EcmaStringAccessor::StringIsEqualUint8Data(thread, foundString, utf8Data, utf8Len, canBeCompress); }); ASSERT(result != nullptr); return result; } // Load returns the value of the key stored in the mapping, or HashTrieMapLoadResult for StoreOrLoad -HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(const uint32_t key, EcmaString *value) +HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(JSThread *thread, const uint32_t key, + EcmaString *value) { uint32_t hash = key; Indirect *current = root_.load(std::memory_order_relaxed); @@ -477,7 +486,8 @@ HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(const uint32_t key, EcmaStr if (node->IsEntry()) { for (Entry *currentEntry = node->AsEntry(); currentEntry != nullptr; currentEntry = currentEntry->Overflow().load(std::memory_order_acquire)) { - if (currentEntry->Key() == key && EcmaStringAccessor::StringsAreEqual(currentEntry->Value(), value)) { + if (currentEntry->Key() == key && + EcmaStringAccessor::StringsAreEqual(thread, currentEntry->Value(), value)) { return {currentEntry->Value(), nullptr, hashShift, nullptr}; } } @@ -491,8 +501,8 @@ HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(const uint32_t key, EcmaStr } // Load returns the value of the key stored in the mapping, or HashTrieMapLoadResult for StoreOrLoad -HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(const uint32_t key, const JSHandle &string, - uint32_t offset, uint32_t utf8Len) +HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(JSThread *thread, const uint32_t key, + const JSHandle &string, uint32_t offset, uint32_t utf8Len) { uint32_t hash = key; Indirect *current = root_.load(std::memory_order_relaxed); @@ -509,7 +519,8 @@ HashTrieMap::HashTrieMapLoadResult HashTrieMap::Load(const uint32_t key, const J for (Entry *currentEntry = node->AsEntry(); currentEntry != nullptr; currentEntry = currentEntry->Overflow().load(std::memory_order_acquire)) { if (currentEntry->Key() == key && - EcmaStringAccessor::StringIsEqualUint8Data(currentEntry->Value(), utf8Data, utf8Len, true)) { + EcmaStringAccessor::StringIsEqualUint8Data(thread, + currentEntry->Value(), utf8Data, utf8Len, true)) { return {currentEntry->Value(), nullptr, hashShift, nullptr}; } } @@ -534,6 +545,7 @@ EcmaString *HashTrieMap::StoreOrLoad(EcmaVM *vm, const uint32_t key, HashTrieMap Node *node = nullptr; bool haveInsertPoint = true; Indirect *current = loadResult.current; + JSThread *thread = vm->GetAssociatedJSThread(); RuntimeLock(vm->GetJSThread(), current->GetMutex()); #if ECMASCRIPT_ENABLE_SCOPE_LOCK_STAT if (vm->IsCollectingScopeLockStats()) { @@ -560,7 +572,7 @@ EcmaString *HashTrieMap::StoreOrLoad(EcmaVM *vm, const uint32_t key, HashTrieMap for (Entry *currentEntry = node->AsEntry(); currentEntry != nullptr; currentEntry = currentEntry->Overflow().load(std::memory_order_acquire)) { if (currentEntry->Key() == key && - EcmaStringAccessor::StringsAreEqual(currentEntry->Value(), *str)) { + EcmaStringAccessor::StringsAreEqual(thread, currentEntry->Value(), *str)) { return currentEntry->Value(); } } @@ -600,7 +612,8 @@ EcmaString *HashTrieMap::StoreOrLoad(EcmaVM *vm, const uint32_t key, HashTrieMap oldEntry = node->AsEntry(); for (Entry *currentEntry = oldEntry; currentEntry; currentEntry = currentEntry->Overflow().load(std::memory_order_acquire)) { - if (currentEntry->Key() == key && EcmaStringAccessor::StringsAreEqual(currentEntry->Value(), *str)) { + if (currentEntry->Key() == key && + EcmaStringAccessor::StringsAreEqual(thread, currentEntry->Value(), *str)) { RuntimeUnLock(current->GetMutex()); return currentEntry->Value(); } @@ -643,21 +656,21 @@ bool HashTrieMap::CheckWeakRef(const WeakRootVisitor &visitor, HashTrieMap::Entr return false; } -bool HashTrieMap::CheckValidity(EcmaString *value, bool &isValid) +bool HashTrieMap::CheckValidity(JSThread *thread, EcmaString *value, bool &isValid) { if (!EcmaStringAccessor(value).NotTreeString()) { isValid = false; return false; } - uint32_t hashcode = EcmaStringAccessor(value).GetHashcode(); - if (this->Load(hashcode, value) != nullptr) { + uint32_t hashcode = EcmaStringAccessor(value).GetHashcode(thread); + if (this->Load(thread, hashcode, value) != nullptr) { isValid = false; return false; } return true; } -void HashTrieMap::Iter(Indirect *node, bool &isValid) +void HashTrieMap::Iter(JSThread *thread, Indirect *node, bool &isValid) { if (node == nullptr) return; @@ -669,12 +682,12 @@ void HashTrieMap::Iter(Indirect *node, bool &isValid) if (!(childNode->IsEntry())) { // Recursive traversal of indirect nodes - Iter(childNode->AsIndirect(), isValid); + Iter(thread, childNode->AsIndirect(), isValid); continue; } for (Entry *e = childNode->AsEntry(); e != nullptr; e = e->Overflow().load(std::memory_order_relaxed)) { - if (!CheckValidity(e->Value(), isValid)) { + if (!CheckValidity(thread, e->Value(), isValid)) { return; // 用户终止迭代 } } diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 6ed692b09a..c975086f26 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -1072,7 +1072,8 @@ bool EcmaVM::LoadAOTFiles(const std::string& aotFileName, void EcmaVM::LoadProtoTransitionTable(JSTaggedValue constpool) { - JSTaggedValue protoTransitionTable = ConstantPool::Cast(constpool.GetTaggedObject())->GetProtoTransTableInfo(); + JSTaggedValue protoTransitionTable = + ConstantPool::Cast(constpool.GetTaggedObject())->GetProtoTransTableInfo(thread_); functionProtoTransitionTable_->UpdateProtoTransitionTable( thread_, JSHandle(thread_, protoTransitionTable)); } @@ -1263,7 +1264,7 @@ void EcmaVM::TriggerConcurrentCallback(JSTaggedValue result, JSTaggedValue hint) result = JSHandle::Cast(factory_->GetJSError( ErrorType::ERROR, "Can't return Promise in pending state", StackCheck::NO)).GetTaggedValue(); } else { - result = promise->GetPromiseResult(); + result = promise->GetPromiseResult(thread_); } if (status != PromiseState::FULFILLED) { @@ -1284,7 +1285,7 @@ void EcmaVM::TriggerConcurrentCallback(JSTaggedValue result, JSTaggedValue hint) void *taskInfo = reinterpret_cast(thread_->GetTaskInfo()); if (UNLIKELY(taskInfo == nullptr)) { - JSTaggedValue extraInfoValue = functionInfo->GetFunctionExtraInfo(); + JSTaggedValue extraInfoValue = functionInfo->GetFunctionExtraInfo(thread_); if (!extraInfoValue.IsJSNativePointer()) { LOG_ECMA(INFO) << "FunctionExtraInfo is not JSNativePointer"; return; @@ -1525,8 +1526,8 @@ bool EcmaVM::HasPendingJob() const if (UNLIKELY(thread_->HasTerminated())) { return false; } - TaggedQueue* promiseQueue = TaggedQueue::Cast(GetMicroJobQueue()->GetPromiseJobQueue().GetTaggedObject()); - return !promiseQueue->Empty(); + TaggedQueue* promiseQueue = TaggedQueue::Cast(GetMicroJobQueue()->GetPromiseJobQueue(thread_).GetTaggedObject()); + return !promiseQueue->Empty(thread_); } bool EcmaVM::ExecutePromisePendingJob() @@ -1950,7 +1951,7 @@ Expected EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *js GetJsDebuggerManager()->GetNotificationManager()->LoadModuleEvent( jsPandaFile->GetJSPandaFileDesc(), entryPoint); - JSHandle func(thread_, program->GetMainFunction()); + JSHandle func(thread_, program->GetMainFunction(thread_)); Expected result = CommonInvokeEcmaEntrypoint(jsPandaFile, entryPoint, func, executeType); CheckHasPendingException(thread_); @@ -1963,10 +1964,10 @@ Expected EcmaVM::InvokeEcmaEntrypointForHotReload( [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle program = JSPandaFileManager::GetInstance()->GenerateProgram(this, jsPandaFile, entryPoint); - JSHandle func(thread_, program->GetMainFunction()); + JSHandle func(thread_, program->GetMainFunction(thread_)); Expected result = CommonInvokeEcmaEntrypoint(jsPandaFile, entryPoint, func, executeType); - JSHandle finalModuleRecord(thread_, func->GetModule()); + JSHandle finalModuleRecord(thread_, func->GetModule(thread_)); // avoid GC problems. GlobalHandleCollection gloalHandleCollection(thread_); JSHandle moduleRecordHandle = @@ -1976,7 +1977,7 @@ Expected EcmaVM::InvokeEcmaEntrypointForHotReload( // print exception information if (thread_->HasPendingException() && - Method::Cast(func->GetMethod())->GetMethodName() != JSPandaFile::PATCH_FUNCTION_NAME_0) { + Method::Cast(func->GetMethod(thread_))->GetMethodName(thread_) != JSPandaFile::PATCH_FUNCTION_NAME_0) { return Unexpected(false); } return result; @@ -1994,9 +1995,9 @@ void EcmaVM::CJSExecution(JSHandle &func, JSHandle &t if (jsPandaFile->IsBundlePack()) { ModulePathHelper::ResolveCurrentPath(dirNameStr, fileNameStr, jsPandaFile); } else { - JSTaggedValue funcFileName = func->GetModule(); + JSTaggedValue funcFileName = func->GetModule(thread_); ASSERT(funcFileName.IsString()); - fileNameStr = ModulePathHelper::Utf8ConvertToString(funcFileName); + fileNameStr = ModulePathHelper::Utf8ConvertToString(thread_, funcFileName); dirNameStr = PathHelper::ResolveDirPath(fileNameStr); } JSHandle fileName = JSHandle::Cast(factory_->NewFromUtf8(fileNameStr)); diff --git a/ecmascript/element_accessor-inl.h b/ecmascript/element_accessor-inl.h index ed7dc03188..8669bd0315 100644 --- a/ecmascript/element_accessor-inl.h +++ b/ecmascript/element_accessor-inl.h @@ -38,7 +38,7 @@ inline void ElementAccessor::Set(const JSThread *thread, JSHandle rece Elements::MigrateArrayWithKind(thread, receiver, oldKind, newKind); } - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); ASSERT(idx < elements->GetLength()); if (UNLIKELY(thread->IsEnableMutantArray())) { ElementsKind kind = receiver->GetClass()->GetElementsKind(); diff --git a/ecmascript/element_accessor.cpp b/ecmascript/element_accessor.cpp index 5f279d60e1..78fb399125 100644 --- a/ecmascript/element_accessor.cpp +++ b/ecmascript/element_accessor.cpp @@ -21,13 +21,13 @@ namespace panda::ecmascript { JSTaggedValue ElementAccessor::Get(const JSThread *thread, JSHandle receiver, uint32_t idx) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); ASSERT(idx < elements->GetLength()); // Note: Here 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. size_t offset = JSTaggedValue::TaggedTypeSize() * idx; // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) - JSTaggedType rawValue = Barriers::GetTaggedValue(elements->GetData(), offset); + JSTaggedType rawValue = Barriers::GetTaggedValue(thread, elements->GetData(), offset); if (UNLIKELY(thread->IsEnableMutantArray())) { ElementsKind kind = receiver->GetClass()->GetElementsKind(); if (!elements->GetClass()->IsMutantTaggedArray()) { @@ -41,13 +41,13 @@ JSTaggedValue ElementAccessor::Get(const JSThread *thread, JSHandle re JSTaggedValue ElementAccessor::Get(const JSThread *thread, JSObject *receiver, uint32_t idx) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); ASSERT(idx < elements->GetLength()); // Note: Here 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. size_t offset = JSTaggedValue::TaggedTypeSize() * idx; // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) - JSTaggedType rawValue = Barriers::GetTaggedValue(elements->GetData(), offset); + JSTaggedType rawValue = Barriers::GetTaggedValue(thread, elements->GetData(), offset); if (UNLIKELY(thread->IsEnableMutantArray())) { ElementsKind kind = receiver->GetClass()->GetElementsKind(); if (!elements->GetClass()->IsMutantTaggedArray()) { @@ -59,36 +59,36 @@ JSTaggedValue ElementAccessor::Get(const JSThread *thread, JSObject *receiver, u } } -JSTaggedValue ElementAccessor::FastGet(JSHandle elements, uint32_t idx, ElementsKind kind) +JSTaggedValue ElementAccessor::FastGet(const JSThread *thread, JSHandle elements, uint32_t idx, ElementsKind kind) { ASSERT(idx < elements->GetLength()); size_t offset = JSTaggedValue::TaggedTypeSize() * idx; // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) - JSTaggedType rawValue = Barriers::GetTaggedValue(elements->GetData(), offset); + JSTaggedType rawValue = Barriers::GetTaggedValue(thread, elements->GetData(), offset); return GetTaggedValueWithElementsKind(rawValue, kind); } -bool ElementAccessor::IsDictionaryMode(JSHandle receiver) +bool ElementAccessor::IsDictionaryMode(const JSThread *thread, JSHandle receiver) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); return elements->GetClass()->IsDictionary(); } -bool ElementAccessor::IsDictionaryMode(JSObject *receiver) +bool ElementAccessor::IsDictionaryMode(const JSThread *thread, JSObject *receiver) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); return elements->GetClass()->IsDictionary(); } -uint32_t ElementAccessor::GetElementsLength(JSHandle receiver) +uint32_t ElementAccessor::GetElementsLength(const JSThread *thread, JSHandle receiver) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); return elements->GetLength(); } -uint32_t ElementAccessor::GetElementsLength(JSObject *receiver) +uint32_t ElementAccessor::GetElementsLength(const JSThread *thread, JSObject *receiver) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread)); return elements->GetLength(); } @@ -162,8 +162,8 @@ JSTaggedType ElementAccessor::ConvertTaggedValueWithElementsKind(JSTaggedValue r void ElementAccessor::CopyJSArrayObject(const JSThread *thread, JSHandlesrcObj, JSHandledstObj, uint32_t effectiveLength) { - ASSERT(effectiveLength <= GetElementsLength(srcObj)); - ASSERT(effectiveLength <= GetElementsLength(dstObj)); + ASSERT(effectiveLength <= GetElementsLength(thread, srcObj)); + ASSERT(effectiveLength <= GetElementsLength(thread, dstObj)); for (uint32_t i = 0; i < effectiveLength; i++) { JSHandle value(thread, Get(thread, srcObj, i)); Set(thread, dstObj, i, value, true); @@ -173,7 +173,7 @@ void ElementAccessor::CopyJSArrayObject(const JSThread *thread, JSHandlesrcObj, JSHandledstElements, uint32_t effectiveLength) { - ASSERT(effectiveLength <= GetElementsLength(srcObj)); + ASSERT(effectiveLength <= GetElementsLength(thread, srcObj)); ASSERT(effectiveLength <= dstElements->GetLength()); for (uint32_t i = 0; i < effectiveLength; i++) { JSHandle value(thread, Get(thread, srcObj, i)); diff --git a/ecmascript/element_accessor.h b/ecmascript/element_accessor.h index bf49bcbef4..6785d95d61 100644 --- a/ecmascript/element_accessor.h +++ b/ecmascript/element_accessor.h @@ -27,7 +27,7 @@ class ElementAccessor { public: static JSTaggedValue PUBLIC_API Get(const JSThread *thread, JSHandle receiver, uint32_t idx); static JSTaggedValue Get(const JSThread *thread, JSObject *receiver, uint32_t idx); - static JSTaggedValue PUBLIC_API FastGet(JSHandle elements, uint32_t idx, ElementsKind kind); + static JSTaggedValue PUBLIC_API FastGet(const JSThread *thread, JSHandle elements, uint32_t idx, ElementsKind kind); template static void Set(const JSThread *thread, JSHandle receiver, uint32_t idx, const JSHandle &value, @@ -36,10 +36,10 @@ public: template static void FastSet(const JSThread *thread, JSHandle elements, uint32_t idx, const JSHandle &value, ElementsKind kind); - static bool IsDictionaryMode(JSHandle receiver); - static bool IsDictionaryMode(JSObject *receiver); - static uint32_t GetElementsLength(JSHandle receiver); - static uint32_t GetElementsLength(JSObject *receiver); + static bool IsDictionaryMode(const JSThread *thread, JSHandle receiver); + static bool IsDictionaryMode(const JSThread *thread, JSObject *receiver); + static uint32_t GetElementsLength(const JSThread *thread, JSHandle receiver); + static uint32_t GetElementsLength(const JSThread *thread, JSObject *receiver); static JSTaggedValue GetTaggedValueWithElementsKind(JSTaggedType rawValue, ElementsKind kind); diff --git a/ecmascript/elements.cpp b/ecmascript/elements.cpp index 13b0db1a8f..94440b61af 100644 --- a/ecmascript/elements.cpp +++ b/ecmascript/elements.cpp @@ -147,7 +147,7 @@ void Elements::MigrateArrayWithKind(const JSThread *thread, const JSHandleGetElements().IsCOWArray(); + bool needCOW = object->GetElements(thread).IsCOWArray(); if (oldKind == ElementsKind::INT || oldKind == ElementsKind::HOLE_INT) { HandleIntKindMigration(thread, object, newKind, needCOW); @@ -162,7 +162,7 @@ JSTaggedValue Elements::MigrateFromRawValueToHeapValue(const JSThread *thread, c bool needCOW, bool isIntKind) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle elements = JSHandle(thread, object->GetElements()); + JSHandle elements = JSHandle(thread, object->GetElements(thread)); uint32_t length = elements->GetLength(); JSMutableHandle newElements(thread, JSTaggedValue::Undefined()); if (needCOW) { @@ -171,7 +171,7 @@ JSTaggedValue Elements::MigrateFromRawValueToHeapValue(const JSThread *thread, c newElements.Update(factory->NewTaggedArray(length)); } for (uint32_t i = 0; i < length; i++) { - JSTaggedType value = elements->Get(i).GetRawData(); + JSTaggedType value = elements->Get(thread, i).GetRawData(); if (value == base::SPECIAL_HOLE) { newElements->Set(thread, i, JSTaggedValue::Hole()); } else if (isIntKind) { @@ -189,7 +189,7 @@ JSTaggedValue Elements::MigrateFromHeapValueToRawValue(const JSThread *thread, c bool needCOW, bool isIntKind) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle elements = JSHandle(thread, object->GetElements()); + JSHandle elements = JSHandle(thread, object->GetElements(thread)); uint32_t length = elements->GetLength(); JSMutableHandle newElements(thread, JSTaggedValue::Undefined()); if (needCOW) { @@ -198,7 +198,7 @@ JSTaggedValue Elements::MigrateFromHeapValueToRawValue(const JSThread *thread, c newElements.Update(factory->NewMutantTaggedArray(length)); } for (uint32_t i = 0; i < length; i++) { - JSTaggedValue value = elements->Get(i); + JSTaggedValue value = elements->Get(thread, i); JSTaggedType convertedValue = 0; // To distinguish Hole (0x5) in taggedvalue with Interger 5 if (value.IsHole()) { @@ -218,14 +218,14 @@ JSTaggedValue Elements::MigrateFromHeapValueToRawValue(const JSThread *thread, c void Elements::MigrateFromHoleIntToHoleNumber(const JSThread *thread, const JSHandle object) { - JSHandle elements = JSHandle(thread, object->GetElements()); + JSHandle elements = JSHandle(thread, object->GetElements(thread)); uint32_t length = elements->GetLength(); for (uint32_t i = 0; i < length; i++) { - JSTaggedType value = elements->Get(i).GetRawData(); + JSTaggedType value = elements->Get(thread, i).GetRawData(); if (value == base::SPECIAL_HOLE) { continue; } - int intValue = static_cast(elements->Get(i).GetRawData()); + int intValue = static_cast(elements->Get(thread, i).GetRawData()); double convertedValue = static_cast(intValue); elements->Set(thread, i, JSTaggedValue(base::bit_cast(convertedValue))); } @@ -233,14 +233,14 @@ void Elements::MigrateFromHoleIntToHoleNumber(const JSThread *thread, const JSHa void Elements::MigrateFromHoleNumberToHoleInt(const JSThread *thread, const JSHandle object) { - JSHandle elements = JSHandle(thread, object->GetElements()); + JSHandle elements = JSHandle(thread, object->GetElements(thread)); uint32_t length = elements->GetLength(); for (uint32_t i = 0; i < length; i++) { - JSTaggedType value = elements->Get(i).GetRawData(); + JSTaggedType value = elements->Get(thread, i).GetRawData(); if (value == base::SPECIAL_HOLE) { continue; } - double intValue = base::bit_cast(elements->Get(i).GetRawData()); + double intValue = base::bit_cast(elements->Get(thread, i).GetRawData()); int64_t convertedValue = static_cast(intValue); elements->Set(thread, i, JSTaggedValue(base::bit_cast(convertedValue))); } diff --git a/ecmascript/enum_cache.h b/ecmascript/enum_cache.h index c6bcb3de5e..7f3e276daa 100644 --- a/ecmascript/enum_cache.h +++ b/ecmascript/enum_cache.h @@ -55,32 +55,33 @@ public: static constexpr size_t ENUM_CACHE_OWN_OFFSET = TaggedObjectSize(); - static bool CheckSelfAndProtoEnumCache(JSTaggedValue enumCacheOwn, JSTaggedValue enumCacheProto) + static bool CheckSelfAndProtoEnumCache(const JSThread *thread, JSTaggedValue enumCacheOwn, + JSTaggedValue enumCacheProto) { if (!enumCacheOwn.IsEnumCache() || !enumCacheProto.IsEnumCache()) { return false; } - auto keyOwn = EnumCache::Cast(enumCacheOwn.GetTaggedObject())->GetProtoChainInfoEnumCache(); - auto keyProto = EnumCache::Cast(enumCacheProto.GetTaggedObject())->GetEnumCacheAll(); + auto keyOwn = EnumCache::Cast(enumCacheOwn.GetTaggedObject())->GetProtoChainInfoEnumCache(thread); + auto keyProto = EnumCache::Cast(enumCacheProto.GetTaggedObject())->GetEnumCacheAll(thread); if (keyOwn != keyProto || keyOwn == JSTaggedValue::Null()) { return false; } return true; } - inline bool IsEnumCacheAllValid() const + inline bool IsEnumCacheAllValid(const JSThread *thread) const { - return GetEnumCacheAll() != JSTaggedValue::Null(); + return GetEnumCacheAll(thread) != JSTaggedValue::Null(); } - inline bool IsEnumCacheOwnValid() const + inline bool IsEnumCacheOwnValid(const JSThread *thread) const { - return GetEnumCacheOwn() != JSTaggedValue::Null(); + return GetEnumCacheOwn(thread) != JSTaggedValue::Null(); } - inline bool IsEnumCacheProtoInfoUndefined() const + inline bool IsEnumCacheProtoInfoUndefined(const JSThread *thread) const { - return GetProtoChainInfoEnumCache() == JSTaggedValue::Undefined(); + return GetProtoChainInfoEnumCache(thread) == JSTaggedValue::Undefined(); } inline void SetInvalidState(const JSThread *thread) diff --git a/ecmascript/frames.cpp b/ecmascript/frames.cpp index 9de0152bc5..7d1d89d628 100644 --- a/ecmascript/frames.cpp +++ b/ecmascript/frames.cpp @@ -44,7 +44,7 @@ Method *FrameIterator::CheckAndGetMethod() const { auto function = GetFunction(); if (function.CheckIsJSFunctionBase() || function.CheckIsJSProxy()) { - return ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(); + return ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(thread_); } return nullptr; } @@ -556,7 +556,8 @@ uint32_t FrameIterator::GetBaselineBytecodeOffset() const auto *frame = this->GetFrame(); JSHandle funcVal = JSHandle(thread_, frame->function); JSHandle func = JSHandle::Cast(funcVal); - uint32_t curBytecodePcOfst = RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(func, baselineNativePc_); + uint32_t curBytecodePcOfst = RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline( + const_cast(thread_), func, baselineNativePc_); return curBytecodePcOfst; } @@ -572,7 +573,7 @@ uint32_t FrameIterator::GetBytecodeOffset() const // for baselinejit return GetBaselineBytecodeOffset(); } else { - Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(thread_); auto offset = pc - method->GetBytecodeArray(); return static_cast(offset); } @@ -580,7 +581,7 @@ uint32_t FrameIterator::GetBytecodeOffset() const case FrameType::INTERPRETER_FRAME: case FrameType::INTERPRETER_FAST_NEW_FRAME: { auto *frame = this->GetFrame(); - Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(thread_); auto offset = frame->GetPc() - method->GetBytecodeArray(); return static_cast(offset); } @@ -611,7 +612,7 @@ void FrameIterator::GetStackTraceInfos(std::vectorfunction.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(thread_); offset = frame->GetPc() - method->GetBytecodeArray(); } stackTraceInfos.push_back(std::make_pair(frame->function.GetRawData(), static_cast(offset))); @@ -620,7 +621,7 @@ void FrameIterator::GetStackTraceInfos(std::vectorGetFrame(); - Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(thread_); auto offset = frame->GetPc() - method->GetBytecodeArray(); stackTraceInfos.push_back(std::make_pair(frame->function.GetRawData(), static_cast(offset))); break; diff --git a/ecmascript/free_object.cpp b/ecmascript/free_object.cpp index c68ffee17b..880981b7cc 100644 --- a/ecmascript/free_object.cpp +++ b/ecmascript/free_object.cpp @@ -55,8 +55,10 @@ uint32_t FreeObject::Available() const if (hclass->IsFreeObjectWithShortField()) { return hclass->GetObjectSize(); } - ASSERT(GetSize().IsInt()); - return GetSize().GetInt(); + // bypass the load barrier + auto taggedInt = JSTaggedValue(Barriers::GetPrimitive(this, SIZE_OFFSET)); + ASSERT(taggedInt.IsInt()); + return taggedInt.GetInt(); } bool FreeObject::IsFreeObject() const diff --git a/ecmascript/generator_helper.cpp b/ecmascript/generator_helper.cpp index 656924406b..9fb45464aa 100644 --- a/ecmascript/generator_helper.cpp +++ b/ecmascript/generator_helper.cpp @@ -25,7 +25,7 @@ namespace panda::ecmascript { JSHandle GeneratorHelper::Next(JSThread *thread, const JSHandle &genContext, JSTaggedValue value) { - JSHandle genObject(thread, genContext->GetGeneratorObject()); + JSHandle genObject(thread, genContext->GetGeneratorObject(thread)); genObject->SetResumeResult(thread, value); genObject->SetGeneratorState(JSGeneratorState::EXECUTING); genObject->SetResumeMode(GeneratorResumeMode::NEXT); @@ -44,7 +44,7 @@ JSHandle GeneratorHelper::Next(JSThread *thread, const JSHandle GeneratorHelper::Return(JSThread *thread, const JSHandle &genContext, JSTaggedValue value) { - JSHandle genObject(thread, genContext->GetGeneratorObject()); + JSHandle genObject(thread, genContext->GetGeneratorObject(thread)); genObject->SetResumeMode(GeneratorResumeMode::RETURN); genObject->SetResumeResult(thread, value); @@ -61,7 +61,7 @@ JSHandle GeneratorHelper::Return(JSThread *thread, const JSHandle GeneratorHelper::Throw(JSThread *thread, const JSHandle &genContext, JSTaggedValue value) { - JSHandle genObject(thread, genContext->GetGeneratorObject()); + JSHandle genObject(thread, genContext->GetGeneratorObject(thread)); genObject->SetResumeMode(GeneratorResumeMode::THROW); genObject->SetResumeResult(thread, value); diff --git a/ecmascript/global_dictionary-inl.h b/ecmascript/global_dictionary-inl.h index a77633e647..2d592882e5 100644 --- a/ecmascript/global_dictionary-inl.h +++ b/ecmascript/global_dictionary-inl.h @@ -25,7 +25,7 @@ namespace panda { namespace ecmascript { -int GlobalDictionary::Hash(const JSTaggedValue &key) +int GlobalDictionary::Hash(const JSThread *thread, const JSTaggedValue &key) { if (key.IsHeapObject()) { if (key.IsSymbol()) { @@ -34,7 +34,7 @@ int GlobalDictionary::Hash(const JSTaggedValue &key) } if (key.IsString()) { auto keyString = EcmaString::Cast(key.GetTaggedObject()); - return EcmaStringAccessor(keyString).GetHashcode(); + return EcmaStringAccessor(keyString).GetHashcode(thread); } } // key must be object @@ -42,26 +42,27 @@ int GlobalDictionary::Hash(const JSTaggedValue &key) UNREACHABLE(); } -bool GlobalDictionary::IsMatch(const JSTaggedValue &key, const JSTaggedValue &other) +bool GlobalDictionary::IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &other) { return key == other; } -PropertyBox *GlobalDictionary::GetBox(int entry) const +PropertyBox *GlobalDictionary::GetBox(const JSThread *thread, int entry) const { int index = GetEntryIndex(entry) + ENTRY_VALUE_INDEX; - return PropertyBox::Cast(Get(index).GetTaggedObject()); + return PropertyBox::Cast(Get(thread, index).GetTaggedObject()); } -JSTaggedValue GlobalDictionary::GetValue(int entry) const +JSTaggedValue GlobalDictionary::GetValue(const JSThread *thread, int entry) const { - return GetBox(entry)->GetValue(); + return GetBox(thread, entry)->GetValue(thread); } -PropertyAttributes GlobalDictionary::GetAttributes(int entry) const +PropertyAttributes GlobalDictionary::GetAttributes(const JSThread *thread, int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return PropertyAttributes(Get(index)); + return PropertyAttributes(Get(thread, index)); } void GlobalDictionary::SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, @@ -106,9 +107,9 @@ void GlobalDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArra CVector> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); std::pair pair(key, attr.GetOffset()); sortArr.push_back(pair); } @@ -130,9 +131,9 @@ void GlobalDictionary::GetAllKeysByFilter(const JSThread *thread, CVector> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); bool bIgnore = FilterHelper::IgnoreKeyByFilter(attr, filter); if (bIgnore) { continue; @@ -155,15 +156,15 @@ void GlobalDictionary::GetAllKeysByFilter(const JSThread *thread, } } -std::pair GlobalDictionary::GetNumOfEnumKeys() const +std::pair GlobalDictionary::GetNumOfEnumKeys(const JSThread *thread) const { uint32_t enumKeys = 0; uint32_t shadowKeys = 0; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (key.IsString()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); if (attr.IsEnumerable()) { enumKeys++; } else { @@ -177,16 +178,16 @@ std::pair GlobalDictionary::GetNumOfEnumKeys() const void GlobalDictionary::GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const { - ASSERT_PRINT(offset + GetNumOfEnumKeys().first <= static_cast(keyArray->GetLength()), + ASSERT_PRINT(offset + GetNumOfEnumKeys(thread).first <= static_cast(keyArray->GetLength()), "keyArray capacity is not enough for dictionary"); int arrayIndex = 0; int size = Size(); CVector> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (key.IsString()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); if (attr.IsEnumerable()) { std::pair pair(key, attr.GetOffset()); sortArr.push_back(pair); @@ -209,29 +210,29 @@ bool GlobalDictionary::CompKey(const std::pair &a, cons void GlobalDictionary::InvalidatePropertyBox(JSThread *thread, const JSHandle &dictHandle, int entry) { - PropertyBox *box = dictHandle->GetBox(entry); + PropertyBox *box = dictHandle->GetBox(thread, entry); - ASSERT(!box->GetValue().IsHole()); - JSHandle oldValue(thread, box->GetValue()); + ASSERT(!box->GetValue(thread).IsHole()); + JSHandle oldValue(thread, box->GetValue(thread)); GlobalDictionary::InvalidateAndReplaceEntry(thread, dictHandle, entry, oldValue); } void GlobalDictionary::InvalidateAndReplaceEntry(JSThread *thread, const JSHandle &dictHandle, int entry, const JSHandle &oldValue) { - if (!dictHandle->IsValidateBox(entry)) { + if (!dictHandle->IsValidateBox(thread, entry)) { return; } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Swap with a copy. JSHandle newBox = factory->NewPropertyBox(oldValue); - PropertyBox *box = dictHandle->GetBox(entry); - PropertyAttributes attr = dictHandle->GetAttributes(entry); - if (!attr.IsConfigurable() || box->GetValue().IsHole()) { + PropertyBox *box = dictHandle->GetBox(thread, entry); + PropertyAttributes attr = dictHandle->GetAttributes(thread, entry); + if (!attr.IsConfigurable() || box->GetValue(thread).IsHole()) { return; } ASSERT_PRINT(attr.IsConfigurable(), "property must be configurable"); - ASSERT_PRINT(!box->GetValue().IsHole(), "value must not be hole"); + ASSERT_PRINT(!box->GetValue(thread).IsHole(), "value must not be hole"); // Cell is officially mutable henceforth. attr.SetBoxType(PropertyBoxType::MUTABLE); @@ -240,10 +241,10 @@ void GlobalDictionary::InvalidateAndReplaceEntry(JSThread *thread, const JSHandl box->Clear(thread); } -bool GlobalDictionary::IsValidateBox(int entry) const +bool GlobalDictionary::IsValidateBox(const JSThread *thread, int entry) const { int index = GetEntryIndex(entry) + ENTRY_VALUE_INDEX; - return !Get(index).IsUndefined(); + return !Get(thread, index).IsUndefined(); } } // namespace ecmascript } // namespace panda diff --git a/ecmascript/global_dictionary.h b/ecmascript/global_dictionary.h index 749ebd7dc8..5b77775689 100644 --- a/ecmascript/global_dictionary.h +++ b/ecmascript/global_dictionary.h @@ -46,21 +46,22 @@ public: { return ENTRY_SIZE; } - static inline bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other); + static inline bool IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &other); - static inline int Hash(const JSTaggedValue &key); + static inline int Hash(const JSThread *thread, const JSTaggedValue &key); inline static void InvalidatePropertyBox(JSThread *thread, const JSHandle &dictHandle, int entry); inline static void InvalidateAndReplaceEntry(JSThread *thread, const JSHandle &dictHandle, int entry, const JSHandle &oldValue); - inline bool IsValidateBox(int entry) const; + inline bool IsValidateBox(const JSThread *thread, int entry) const; - inline PropertyBox *GetBox(int entry) const; + inline PropertyBox *GetBox(const JSThread *thread, int entry) const; - inline JSTaggedValue GetValue(int entry) const; + inline JSTaggedValue GetValue(const JSThread *thread, int entry) const; - inline PropertyAttributes GetAttributes(int entry) const; + inline PropertyAttributes GetAttributes(const JSThread *thread, int entry) const; inline void SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, const PropertyAttributes &detail); @@ -80,17 +81,17 @@ public: inline void GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const; - inline std::pair GetNumOfEnumKeys() const; + inline std::pair GetNumOfEnumKeys(const JSThread *thread) const; static bool inline CompKey(const std::pair &a, const std::pair &b); - void Dump(std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; - void Dump() const DUMP_API_ATTR + void Dump(const JSThread *thread, std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; + void Dump(const JSThread *thread) const DUMP_API_ATTR { - Dump(std::cout); + Dump(thread, std::cout); } - void DumpForSnapshot(std::vector &vec) const; + void DumpForSnapshot(const JSThread *thread, std::vector &vec) const; public: static constexpr int ENTRY_KEY_INDEX = 0; diff --git a/ecmascript/global_env.cpp b/ecmascript/global_env.cpp index 0491eb2c43..2469781ebf 100644 --- a/ecmascript/global_env.cpp +++ b/ecmascript/global_env.cpp @@ -71,7 +71,7 @@ JSHandle GlobalEnv::GetStringPrototypeFunctionByName(JSThread *th { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle stringFuncPrototype(thread, - JSObject::GetPrototype(JSHandle(GetStringFunction()))); + JSObject::GetPrototype(thread, JSHandle(GetStringFunction()))); JSHandle nameKey(factory->NewFromUtf8(name)); return JSObject::GetProperty(thread, stringFuncPrototype, nameKey).GetValue(); } diff --git a/ecmascript/global_env.h b/ecmascript/global_env.h index 170d786eca..fd5c6489ae 100644 --- a/ecmascript/global_env.h +++ b/ecmascript/global_env.h @@ -112,7 +112,7 @@ public: { if (!value.IsInternalAccessor()) { SnapshotEnv *snapshotEnv = thread->GetEcmaVM()->GetSnapshotEnv(); - if (!RemoveValueFromSnapshotEnv(snapshotEnv, value, offset)) { + if (!RemoveValueFromSnapshotEnv(thread, snapshotEnv, value, offset)) { return; } size_t globalConstCount = thread->GlobalConstants()->GetConstantCount(); @@ -121,9 +121,9 @@ public: } // For work serialize, remove old value from snapshot env map - bool RemoveValueFromSnapshotEnv(SnapshotEnv *snapshotEnv, JSTaggedValue value, uint32_t offset) + bool RemoveValueFromSnapshotEnv(const JSThread *thread, SnapshotEnv *snapshotEnv, JSTaggedValue value, uint32_t offset) { - JSTaggedValue oldValue(Barriers::GetTaggedValue(this, offset)); + JSTaggedValue oldValue(Barriers::GetTaggedValue(thread, this, offset)); if (oldValue == value) { return false; } @@ -229,7 +229,7 @@ public: inline JSTaggedValue GetTagged##name() const \ { \ uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \ - JSTaggedValue result(Barriers::GetTaggedValue(this, offset)); \ + JSTaggedValue result(Barriers::GetPrimitive(this, offset)); \ if (result.IsInternalAccessor()) { \ JSThread *thread = GetJSThread(); \ AccessorData *accessor = AccessorData::Cast(result.GetTaggedObject()); \ @@ -253,7 +253,7 @@ public: Barriers::SetObject(thread, this, offset, value.GetTaggedValue().GetRawData()); \ } else { \ SnapshotEnv *snapshotEnv = thread->GetEcmaVM()->GetSnapshotEnv(); \ - RemoveValueFromSnapshotEnv(snapshotEnv, value.GetTaggedValue(), offset); \ + RemoveValueFromSnapshotEnv(thread, snapshotEnv, value.GetTaggedValue(), offset); \ Barriers::SetPrimitive(this, offset, value.GetTaggedValue().GetRawData()); \ } \ } \ @@ -265,7 +265,7 @@ public: Barriers::SetObject(thread, this, offset, value.GetRawData()); \ } else { \ SnapshotEnv *snapshotEnv = thread->GetEcmaVM()->GetSnapshotEnv(); \ - RemoveValueFromSnapshotEnv(snapshotEnv, value, offset); \ + RemoveValueFromSnapshotEnv(thread, snapshotEnv, value, offset); \ Barriers::SetPrimitive(this, offset, value.GetRawData()); \ } \ } diff --git a/ecmascript/ic/ic_handler.cpp b/ecmascript/ic/ic_handler.cpp index a9a3c66ed8..ba5d3990ae 100644 --- a/ecmascript/ic/ic_handler.cpp +++ b/ecmascript/ic/ic_handler.cpp @@ -26,7 +26,7 @@ void UpdateHandlerKind(const JSThread *thread, const ObjectOperator &op, uint64_ JSHandle key = op.GetKey(); EcmaString *proKey = key->IsString() ? EcmaString::Cast(key->GetTaggedObject()) : nullptr; if (proKey != nullptr && - EcmaStringAccessor::StringsAreEqual(proKey, EcmaString::Cast(lenKey.GetTaggedObject()))) { + EcmaStringAccessor::StringsAreEqual(thread, proKey, EcmaString::Cast(lenKey.GetTaggedObject()))) { HandlerBase::KindBit::Set(HandlerBase::HandlerKind::STRING_LENGTH, &handler); } else { HandlerBase::KindBit::Set(HandlerBase::HandlerKind::STRING, &handler); @@ -106,7 +106,7 @@ JSHandle StoreHandler::StoreProperty(const JSThread *thread, cons { uint64_t handler = 0; JSHandle receiver = JSHandle::Cast(op.GetReceiver()); - SFieldTypeBitSet(op, receiver, &handler); + SFieldTypeBitSet(thread, op, receiver, &handler); if (op.IsElement()) { SOutOfBoundsBit::Set(op.GetElementOutOfBounds(), &handler); return StoreElement(thread, op.GetReceiver(), handler); @@ -169,14 +169,14 @@ JSHandle PrototypeHandler::LoadPrototype(const JSThread *thread, if (op.IsAccessorDescriptor()) { JSTaggedValue result = op.GetValue(); if (result.IsPropertyBox()) { - result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(); + result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread); } AccessorData *accessor = AccessorData::Cast(result.GetTaggedObject()); if (!accessor->IsInternal()) { - JSTaggedValue getter = accessor->GetGetter(); + JSTaggedValue getter = accessor->GetGetter(thread); if (!getter.IsUndefined()) { JSHandle func(thread, getter); - uint32_t methodOffset = Method::Cast(func->GetMethod())->GetMethodId().GetOffset(); + uint32_t methodOffset = Method::Cast(func->GetMethod(thread))->GetMethodId().GetOffset(); handler->SetAccessorMethodId(methodOffset); handler->SetAccessorJSFunction(thread, getter); } @@ -198,14 +198,14 @@ JSHandle PrototypeHandler::StorePrototype(const JSThread *thread, if (op.IsAccessorDescriptor()) { JSTaggedValue result = op.GetValue(); if (result.IsPropertyBox()) { - result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(); + result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread); } AccessorData *accessor = AccessorData::Cast(result.GetTaggedObject()); - if (!accessor->IsInternal() && accessor->HasSetter()) { - JSTaggedValue setter = accessor->GetSetter(); + if (!accessor->IsInternal() && accessor->HasSetter(thread)) { + JSTaggedValue setter = accessor->GetSetter(thread); JSHandle func(thread, setter); handler->SetAccessorMethodId( - Method::Cast(func->GetMethod())->GetMethodId().GetOffset()); + Method::Cast(func->GetMethod(thread))->GetMethodId().GetOffset()); handler->SetAccessorJSFunction(thread, setter); } } diff --git a/ecmascript/ic/ic_handler.h b/ecmascript/ic/ic_handler.h index df4c674912..2e7bf0ce2c 100644 --- a/ecmascript/ic/ic_handler.h +++ b/ecmascript/ic/ic_handler.h @@ -261,10 +261,11 @@ public: return JSHandle(thread, JSTaggedValue::WrapUint64(handler)); } - static inline void SFieldTypeBitSet(const ObjectOperator &op, JSHandle &receiver, uint64_t *handler) + static inline void SFieldTypeBitSet(const JSThread *thread, const ObjectOperator &op, + JSHandle &receiver, uint64_t *handler) { SSharedBit::Set(op.GetReceiver()->IsJSShared(), handler); - TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(receiver->GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { SFieldTypeBit::Set(op.GetAttr().GetSharedFieldType(), handler); } else { diff --git a/ecmascript/ic/ic_runtime.cpp b/ecmascript/ic/ic_runtime.cpp index 8c1006bef8..28ee0c97ad 100644 --- a/ecmascript/ic/ic_runtime.cpp +++ b/ecmascript/ic/ic_runtime.cpp @@ -70,7 +70,7 @@ bool ICRuntime::GetHandler(const ObjectOperator &op, const JSHandle &h if (hclass->IsJSGlobalObject()) { return false; } - JSTaggedValue proto = hclass->GetPrototype(); + JSTaggedValue proto = hclass->GetPrototype(thread_); // If proto is not an EcmaObject, // it means that there is no need to search for the prototype chain. if (!proto.IsECMAObject()) { @@ -281,7 +281,7 @@ JSTaggedValue LoadICRuntime::LoadMiss(JSHandle receiver, JSHandle if (icAccessor_.GetICState() != ProfileTypeAccessor::ICState::MEGA) { icAccessor_.AddGlobalRecordHandler(JSHandle(thread_, box)); } - return PropertyBox::Cast(box.GetTaggedObject())->GetValue(); + return PropertyBox::Cast(box.GetTaggedObject())->GetValue(thread_); } } @@ -346,7 +346,7 @@ JSTaggedValue LoadICRuntime::LoadTypedArrayValueMiss(JSHandle rec JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(GetThread(), propKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); if (!numericIndex.IsUndefined()) { - if (!JSTypedArray::IsValidIntegerIndex(receiver, numericIndex) || !GetThread()->GetEcmaVM()->ICEnabled()) { + if (!JSTypedArray::IsValidIntegerIndex(GetThread(), receiver, numericIndex) || !GetThread()->GetEcmaVM()->ICEnabled()) { icAccessor_.SetAsMega(); return JSTaggedValue::GetProperty(GetThread(), receiver, propKey).GetValue().GetTaggedValue(); } @@ -489,7 +489,7 @@ JSTaggedValue StoreICRuntime::StoreTypedArrayValueMiss(JSHandle r JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(GetThread(), propKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(GetThread()); if (!numericIndex.IsUndefined()) { - if (!JSTypedArray::IsValidIntegerIndex(receiver, numericIndex) || value->IsECMAObject() || + if (!JSTypedArray::IsValidIntegerIndex(GetThread(), receiver, numericIndex) || value->IsECMAObject() || !GetThread()->GetEcmaVM()->ICEnabled()) { icAccessor_.SetAsMega(); bool success = JSTaggedValue::SetProperty(GetThread(), receiver, propKey, value, true); @@ -577,7 +577,7 @@ void ICRuntime::TraceIC([[maybe_unused]] JSThread *thread, auto state = ProfileTypeAccessor::ICStateToString(icAccessor_.GetICState()); if (key->IsString()) { auto keyStrHandle = JSHandle::Cast(key); - LOG_ECMA(ERROR) << kind << " miss, key is: " << EcmaStringAccessor(keyStrHandle).ToCString() + LOG_ECMA(ERROR) << kind << " miss, key is: " << EcmaStringAccessor(keyStrHandle).ToCString(thread) << ", icstate is: " << state << ", slotid is: " << GetSlotId(); } else { diff --git a/ecmascript/ic/ic_runtime_stub-inl.h b/ecmascript/ic/ic_runtime_stub-inl.h index 82a1c4926d..a07c4dd1f3 100644 --- a/ecmascript/ic/ic_runtime_stub-inl.h +++ b/ecmascript/ic/ic_runtime_stub-inl.h @@ -41,9 +41,9 @@ JSTaggedValue ICRuntimeStub::LoadGlobalICByName(JSThread *thread, ProfileTypeInf bool tryLoad) { INTERPRETER_TRACE(thread, LoadGlobalICByName); - JSTaggedValue handler = profileTypeInfo->Get(slotId); + JSTaggedValue handler = profileTypeInfo->Get(thread, slotId); if (handler.IsHeapObject()) { - auto result = LoadGlobal(handler); + auto result = LoadGlobal(thread, handler); if (!result.IsHole()) { return result; } @@ -57,7 +57,7 @@ JSTaggedValue ICRuntimeStub::StoreGlobalICByName(JSThread *thread, ProfileTypeIn JSTaggedValue value, uint32_t slotId, bool tryStore) { INTERPRETER_TRACE(thread, StoreGlobalICByName); - JSTaggedValue handler = profileTypeInfo->Get(slotId); + JSTaggedValue handler = profileTypeInfo->Get(thread, slotId); if (handler.IsHeapObject()) { auto result = StoreGlobal(thread, value, handler); if (!result.IsHole()) { @@ -68,16 +68,16 @@ JSTaggedValue ICRuntimeStub::StoreGlobalICByName(JSThread *thread, ProfileTypeIn return StoreMiss(thread, profileTypeInfo, globalValue, key, value, slotId, kind); } -JSTaggedValue ICRuntimeStub::CheckPolyHClass(JSTaggedValue cachedValue, JSHClass* hclass) +JSTaggedValue ICRuntimeStub::CheckPolyHClass(const JSThread *thread, JSTaggedValue cachedValue, JSHClass* hclass) { if (!cachedValue.IsWeak()) { ASSERT(cachedValue.IsTaggedArray()); 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); + auto result = array->Get(thread, i); if (!result.IsUndefined() && result.GetWeakReferent() == hclass) { - return array->Get(i + 1); + return array->Get(thread, i + 1); } } } @@ -93,13 +93,13 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::TryLoadICByName(JSThread *thread, JSTagg if (LIKELY(firstValue.GetWeakReferentUnChecked() == hclass)) { return LoadICWithHandler(thread, receiver, receiver, secondValue); } - JSTaggedValue cachedHandler = CheckPolyHClass(firstValue, hclass); + JSTaggedValue cachedHandler = CheckPolyHClass(thread, firstValue, hclass); if (!cachedHandler.IsHole()) { return LoadICWithHandler(thread, receiver, receiver, cachedHandler); } } else if (receiver.IsNumber()) { JSHandle function(thread->GetEcmaVM()->GetGlobalEnv()->GetNumberFunction()); - auto hclass = reinterpret_cast(function->GetProtoOrHClass().GetTaggedObject()); + auto hclass = reinterpret_cast(function->GetProtoOrHClass(thread).GetTaggedObject()); if (firstValue.GetWeakReferentUnChecked() == hclass) { return LoadICWithHandler(thread, receiver, receiver, secondValue); } @@ -131,12 +131,12 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::TryLoadICByValue(JSThread *thread, JSTag } // check ploy if (secondValue.IsHole() && !firstValue.IsHole()) { - JSTaggedValue cachedHandler = CheckPolyHClass(firstValue, hclass); + JSTaggedValue cachedHandler = CheckPolyHClass(thread, firstValue, hclass); return LoadICWithElementHandler(thread, receiver, cachedHandler, key); } // Check key if (firstValue == key) { - JSTaggedValue cachedHandler = CheckPolyHClass(secondValue, hclass); + JSTaggedValue cachedHandler = CheckPolyHClass(thread, secondValue, hclass); if (!cachedHandler.IsHole()) { return LoadICWithHandler(thread, receiver, receiver, cachedHandler); } @@ -164,7 +164,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::TryStoreICByValue(JSThread *thread, JSTa } // Check key if (firstValue == key) { - JSTaggedValue cachedHandler = CheckPolyHClass(secondValue, hclass); + JSTaggedValue cachedHandler = CheckPolyHClass(thread, secondValue, hclass); if (!cachedHandler.IsHole()) { return StoreICWithHandler(thread, receiver, receiver, value, cachedHandler); } @@ -200,7 +200,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::TryStoreICByName(JSThread *thread, JSTag if (firstValue.GetWeakReferentUnChecked() == hclass) { return StoreICWithHandler(thread, receiver, receiver, value, secondValue); } - JSTaggedValue cachedHandler = CheckPolyHClass(firstValue, hclass); + JSTaggedValue cachedHandler = CheckPolyHClass(thread, firstValue, hclass); if (!cachedHandler.IsHole()) { return StoreICWithHandler(thread, receiver, receiver, value, cachedHandler); } @@ -253,7 +253,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::StoreICWithHandler(JSThread *thread, JST JSTaggedValue::WrapUint64(handlerInfo)); } ASSERT(HandlerBase::IsAccessor(handlerInfo)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); + auto accessor = LoadFromField(thread, JSObject::Cast(holder.GetTaggedObject()), handlerInfo); return FastRuntimeStub::CallSetter(thread, JSTaggedValue(receiver), value, accessor); } if (handler.IsTransitionHandler()) { @@ -282,7 +282,7 @@ JSTaggedValue ICRuntimeStub::StorePrototype(JSThread *thread, JSTaggedValue rece ASSERT(handler.IsPrototypeHandler()); PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); if (!receiver.IsJSShared()) { - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(thread); if (cellValue.IsNull()) { return JSTaggedValue::Hole(); } @@ -292,8 +292,8 @@ JSTaggedValue ICRuntimeStub::StorePrototype(JSThread *thread, JSTaggedValue rece return JSTaggedValue::Hole(); } } - auto holder = prototypeHandler->GetHolder(); - JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(); + auto holder = prototypeHandler->GetHolder(thread); + JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(thread); return StoreICWithHandler(thread, receiver, holder, value, handlerInfo); } @@ -303,7 +303,7 @@ JSTaggedValue ICRuntimeStub::StoreWithTS(JSThread *thread, JSTaggedValue receive INTERPRETER_TRACE(thread, StoreWithAOT); ASSERT(handler.IsStoreAOTHandler()); StoreAOTHandler *storeAOTHandler = StoreAOTHandler::Cast(handler.GetTaggedObject()); - auto cellValue = storeAOTHandler->GetProtoCell(); + auto cellValue = storeAOTHandler->GetProtoCell(thread); if (cellValue == JSTaggedValue::Undefined()) { return JSTaggedValue::Hole(); } @@ -312,15 +312,15 @@ JSTaggedValue ICRuntimeStub::StoreWithTS(JSThread *thread, JSTaggedValue receive if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } - auto holder = storeAOTHandler->GetHolder(); - JSTaggedValue handlerInfo = storeAOTHandler->GetHandlerInfo(); + auto holder = storeAOTHandler->GetHolder(thread); + JSTaggedValue handlerInfo = storeAOTHandler->GetHandlerInfo(thread); auto handlerInfoInt = JSTaggedValue::UnwrapToUint64(handlerInfo); if (HandlerBase::IsField(handlerInfoInt)) { StoreField(thread, JSObject::Cast(receiver.GetTaggedObject()), value, handlerInfoInt); return JSTaggedValue::Undefined(); } ASSERT(HandlerBase::IsAccessor(handlerInfoInt)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfoInt); + auto accessor = LoadFromField(thread, JSObject::Cast(holder.GetTaggedObject()), handlerInfoInt); return FastRuntimeStub::CallSetter(thread, JSTaggedValue(receiver), value, accessor); } @@ -334,17 +334,17 @@ void ICRuntimeStub::StoreWithTransition(JSThread *thread, JSObject *receiver, JS if (withPrototype) { TransWithProtoHandler *transWithProtoHandler = TransWithProtoHandler::Cast(handler.GetTaggedObject()); - newHClass = JSHClass::Cast(transWithProtoHandler->GetTransitionHClass().GetTaggedObject()); - handlerInfo = JSTaggedValue::UnwrapToUint64(transWithProtoHandler->GetHandlerInfo()); + newHClass = JSHClass::Cast(transWithProtoHandler->GetTransitionHClass(thread).GetTaggedObject()); + handlerInfo = JSTaggedValue::UnwrapToUint64(transWithProtoHandler->GetHandlerInfo(thread)); } else { TransitionHandler *transitionHandler = TransitionHandler::Cast(handler.GetTaggedObject()); - newHClass = JSHClass::Cast(transitionHandler->GetTransitionHClass().GetTaggedObject()); - handlerInfo = JSTaggedValue::UnwrapToUint64(transitionHandler->GetHandlerInfo()); + newHClass = JSHClass::Cast(transitionHandler->GetTransitionHClass(thread).GetTaggedObject()); + handlerInfo = JSTaggedValue::UnwrapToUint64(transitionHandler->GetHandlerInfo(thread)); } JSHandle newHClassHandle(thread, newHClass); JSHandle oldHClassHandle(thread, receiver->GetJSHClass()); if (newHClassHandle->IsPrototype()) { - newHClassHandle->SetProtoChangeDetails(thread, oldHClassHandle->GetProtoChangeDetails()); + newHClassHandle->SetProtoChangeDetails(thread, oldHClassHandle->GetProtoChangeDetails(thread)); } JSHandle objHandle(thread, receiver); ElementsKind oldKind = receiver->GetJSHClass()->GetElementsKind(); @@ -355,7 +355,7 @@ void ICRuntimeStub::StoreWithTransition(JSThread *thread, JSObject *receiver, JS ASSERT(HandlerBase::IsField(handlerInfo)); if (!HandlerBase::IsInlinedProps(handlerInfo)) { - TaggedArray *array = TaggedArray::Cast(objHandle->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(objHandle->GetProperties(thread).GetTaggedObject()); int capacity = static_cast(array->GetLength()); int index = HandlerBase::GetOffset(handlerInfo); if (index >= capacity) { @@ -390,7 +390,7 @@ JSTaggedValue ICRuntimeStub::StoreTransWithProto(JSThread *thread, JSObject *rec ASSERT(handler.IsTransWithProtoHandler()); ASSERT(!receiver->GetClass()->IsJSShared()); TransWithProtoHandler *transWithProtoHandler = TransWithProtoHandler::Cast(handler.GetTaggedObject()); - auto cellValue = transWithProtoHandler->GetProtoCell(); + auto cellValue = transWithProtoHandler->GetProtoCell(thread); if (cellValue == JSTaggedValue::Undefined()) { return JSTaggedValue::Hole(); } @@ -412,28 +412,28 @@ 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().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(receiver->GetProperties(thread).GetTaggedObject()); ASSERT(index < static_cast(array->GetLength())); array->Set(thread, index, value); } -ARK_INLINE JSTaggedValue ICRuntimeStub::LoadFromField(JSObject *receiver, uint64_t handlerInfo) +ARK_INLINE JSTaggedValue ICRuntimeStub::LoadFromField(const JSThread *thread, JSObject *receiver, uint64_t handlerInfo) { int index = HandlerBase::GetOffset(handlerInfo); if (HandlerBase::IsInlinedProps(handlerInfo)) { - return JSTaggedValue(GET_VALUE(receiver, static_cast(index) * JSTaggedValue::TaggedTypeSize())); + return JSTaggedValue(GET_VALUE(thread, receiver, static_cast(index) * JSTaggedValue::TaggedTypeSize())); } - return TaggedArray::Cast(receiver->GetProperties().GetTaggedObject())->Get(index); + return TaggedArray::Cast(receiver->GetProperties(thread).GetTaggedObject())->Get(thread, index); } -ARK_INLINE JSTaggedValue ICRuntimeStub::LoadGlobal(JSTaggedValue handler) +ARK_INLINE JSTaggedValue ICRuntimeStub::LoadGlobal(const JSThread *thread, JSTaggedValue handler) { ASSERT(handler.IsPropertyBox()); PropertyBox *cell = PropertyBox::Cast(handler.GetTaggedObject()); - if (cell->IsInvalid() || cell->GetValue().IsAccessorData()) { + if (cell->IsInvalid(thread) || cell->GetValue(thread).IsAccessorData()) { return JSTaggedValue::Hole(); } - JSTaggedValue ret = cell->GetValue(); + JSTaggedValue ret = cell->GetValue(thread); ASSERT(!ret.IsAccessorData()); return ret; } @@ -443,10 +443,10 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::StoreGlobal(JSThread *thread, JSTaggedVa INTERPRETER_TRACE(thread, StoreGlobal); ASSERT(handler.IsPropertyBox()); PropertyBox *cell = PropertyBox::Cast(handler.GetTaggedObject()); - if (cell->IsInvalid() || cell->GetValue().IsAccessorData()) { + if (cell->IsInvalid(thread) || cell->GetValue(thread).IsAccessorData()) { return JSTaggedValue::Hole(); } - ASSERT(!cell->GetValue().IsAccessorData()); + ASSERT(!cell->GetValue(thread).IsAccessorData()); cell->SetValue(thread, value); return JSTaggedValue::Undefined(); } @@ -456,9 +456,9 @@ JSTaggedValue ICRuntimeStub::LoadPrototype(JSThread *thread, JSTaggedValue recei INTERPRETER_TRACE(thread, LoadPrototype); ASSERT(handler.IsPrototypeHandler()); PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(thread); if (!receiver.IsJSShared()) { - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(thread); if (cellValue == JSTaggedValue::Undefined()) { return JSTaggedValue::Hole(); } @@ -478,7 +478,7 @@ JSTaggedValue ICRuntimeStub::LoadPrototype(JSThread *thread, JSTaggedValue recei } } - JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(); + JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(thread); return LoadICWithHandler(thread, receiver, holder, handlerInfo); } @@ -490,10 +490,10 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTa auto handlerInfo = JSTaggedValue::UnwrapToUint64(handler); HandlerBase::PrintLoadHandler(handlerInfo, std::cout); if (LIKELY(HandlerBase::IsField(handlerInfo))) { - return LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); + return LoadFromField(thread, JSObject::Cast(holder.GetTaggedObject()), handlerInfo); } if (HandlerBase::IsSupportedPrimitiveTypeICHandler(handlerInfo)) { - return LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); + return LoadFromField(thread, JSObject::Cast(holder.GetTaggedObject()), handlerInfo); } // For the special "Not Found" case we may generate ic by "LoadHandler::LoadProperty". @@ -506,7 +506,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTa return JSTaggedNumber((EcmaStringAccessor(EcmaString::Cast(holder)).GetLength())); } ASSERT(HandlerBase::IsAccessor(handlerInfo)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); + auto accessor = LoadFromField(thread, JSObject::Cast(holder.GetTaggedObject()), handlerInfo); return FastRuntimeStub::CallGetter(thread, receiver, holder, accessor); } @@ -514,7 +514,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTa return LoadPrototype(thread, receiver, handler); } - return LoadGlobal(handler); + return LoadGlobal(thread, handler); } ARK_INLINE JSTaggedValue ICRuntimeStub::LoadICWithElementHandler(JSThread *thread, JSTaggedValue receiver, @@ -536,12 +536,12 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadICWithElementHandler(JSThread *threa ARK_INLINE JSTaggedValue ICRuntimeStub::LoadElement(JSThread *thread, JSObject *receiver, JSTaggedValue key) { - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index < 0) { return JSTaggedValue::Hole(); } uint32_t elementIndex = static_cast(index); - if (ElementAccessor::GetElementsLength(receiver) <= elementIndex) { + if (ElementAccessor::GetElementsLength(thread, receiver) <= elementIndex) { return JSTaggedValue::Hole(); } @@ -552,7 +552,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadElement(JSThread *thread, JSObject * ARK_INLINE JSTaggedValue ICRuntimeStub::LoadStringElement(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) { - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index < 0) { return JSTaggedValue::Hole(); } @@ -564,7 +564,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadStringElement(JSThread *thread, JSTa if (EcmaStringAccessor(strFlat).GetLength() <= elementIndex) { return JSTaggedValue::Hole(); } - tmpChar = EcmaStringAccessor(strFlat).Get(elementIndex); + tmpChar = EcmaStringAccessor(strFlat).Get(thread, elementIndex); } auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle value(factory->NewFromUtf16(&tmpChar, 1)); @@ -574,7 +574,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadStringElement(JSThread *thread, JSTa ARK_INLINE JSTaggedValue ICRuntimeStub::LoadTypedArrayElement(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) { - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index < 0) { return JSTaggedValue::Hole(); } @@ -591,7 +591,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, JSTaggedValue value, JSTaggedValue handler) { INTERPRETER_TRACE(thread, StoreElement); - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index < 0) { return JSTaggedValue::Hole(); } @@ -606,7 +606,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, return StoreTypedArrayElement(thread, JSTaggedValue::Cast(receiver), key, value); } else if (HandlerBase::IsJSArray(handlerInfo)) { JSTaggedValue receiveValue = receiverHandle.GetTaggedValue(); - if (receiveValue.IsJSCOWArray()) { + if (receiveValue.IsJSCOWArray(thread)) { // Copy on write array. JSArray::CheckAndCopyArray(thread, JSHandle::Cast(receiverHandle)); } @@ -616,7 +616,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, arr->SetArrayLength(thread, elementIndex + 1); } } - TaggedArray *elements = TaggedArray::Cast(receiverHandle->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiverHandle->GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); if (elementIndex >= capacity) { if (JSObject::ShouldTransToDict(capacity, elementIndex)) { @@ -635,7 +635,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, GET_MESSAGE_STRING(SetTypeMismatchedSharedProperty), JSTaggedValue::Exception()); } PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(thread); if (cellValue == JSTaggedValue::Undefined()) { return JSTaggedValue::Hole(); } @@ -644,7 +644,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } - JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(); + JSTaggedValue handlerInfo = prototypeHandler->GetHandlerInfo(thread); return StoreElement(thread, receiver, key, value, handlerInfo); } return JSTaggedValue::Undefined(); @@ -653,7 +653,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, ARK_INLINE JSTaggedValue ICRuntimeStub::StoreTypedArrayElement(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value) { - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index < 0) { return JSTaggedValue::Hole(); } @@ -666,7 +666,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::StoreTypedArrayElement(JSThread *thread, return JSTypedArray::FastSetPropertyByIndex(thread, receiver, index, value, type); } -ARK_INLINE int64_t ICRuntimeStub::TryToElementsIndex(JSTaggedValue key) +ARK_INLINE int64_t ICRuntimeStub::TryToElementsIndex(JSThread *thread, JSTaggedValue key) { if (LIKELY(key.IsInt())) { return key.GetInt(); @@ -674,7 +674,7 @@ ARK_INLINE int64_t ICRuntimeStub::TryToElementsIndex(JSTaggedValue key) if (key.IsString()) { uint32_t index = 0; - if (JSTaggedValue::StringToElementIndex(key, &index)) { + if (JSTaggedValue::StringToElementIndex(thread, key, &index)) { return static_cast(index); } } diff --git a/ecmascript/ic/ic_runtime_stub.h b/ecmascript/ic/ic_runtime_stub.h index e80b3fccd2..6c7291d5f4 100644 --- a/ecmascript/ic/ic_runtime_stub.h +++ b/ecmascript/ic/ic_runtime_stub.h @@ -39,7 +39,7 @@ public: static inline JSTaggedValue StoreICByName(JSThread *thread, ProfileTypeInfo *profileTypeInfo, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value, uint32_t slotId); - static inline JSTaggedValue CheckPolyHClass(JSTaggedValue cachedValue, JSHClass* hclass); + static inline JSTaggedValue CheckPolyHClass(const JSThread *thread, JSTaggedValue cachedValue, JSHClass* hclass); static inline JSTaggedValue LoadICWithHandler(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue handler); static inline JSTaggedValue LoadICWithElementHandler(JSThread *thread, JSTaggedValue receiver, @@ -54,9 +54,9 @@ public: JSTaggedValue value, JSTaggedValue handler); static inline JSTaggedValue StorePrototype(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, JSTaggedValue handler); - static inline JSTaggedValue LoadFromField(JSObject *receiver, uint64_t handlerInfo); + static inline JSTaggedValue LoadFromField(const JSThread *thread, JSObject *receiver, uint64_t handlerInfo); static inline void StoreField(JSThread *thread, JSObject *receiver, JSTaggedValue value, uint64_t handler); - static inline JSTaggedValue LoadGlobal(JSTaggedValue handler); + static inline JSTaggedValue LoadGlobal(const JSThread *thread, JSTaggedValue handler); static inline JSTaggedValue StoreGlobal(JSThread *thread, JSTaggedValue value, JSTaggedValue handler); static inline JSTaggedValue LoadPrototype(JSThread *thread, JSTaggedValue receiver, JSTaggedValue handler); @@ -80,7 +80,7 @@ public: JSTaggedValue value, JSTaggedValue handlerInfo); static inline JSTaggedValue StoreTypedArrayElement(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value); - static inline int64_t TryToElementsIndex(JSTaggedValue key); + static inline int64_t TryToElementsIndex(JSThread *thread, JSTaggedValue key); static inline JSTaggedValue LoadMiss(JSThread *thread, ProfileTypeInfo *profileTypeInfo, JSTaggedValue receiver, JSTaggedValue key, uint32_t slotId, ICKind kind); static inline JSTaggedValue LoadValueMiss(JSThread *thread, ProfileTypeInfo *profileTypeInfo, diff --git a/ecmascript/ic/mega_ic_cache.cpp b/ecmascript/ic/mega_ic_cache.cpp index 240f76ff3a..4beab599f2 100644 --- a/ecmascript/ic/mega_ic_cache.cpp +++ b/ecmascript/ic/mega_ic_cache.cpp @@ -18,10 +18,9 @@ #include "ecmascript/js_thread.h" namespace panda::ecmascript { -void MegaICCache::Set(JSHClass *jsHclass, JSTaggedValue key, JSTaggedValue handler, - [[maybe_unused]] JSThread *thread) +void MegaICCache::Set(JSHClass *jsHclass, JSTaggedValue key, JSTaggedValue handler, JSThread *thread) { - int hash = PrimaryHash(jsHclass, key); + int hash = PrimaryHash(thread, jsHclass, key); PropertyKey &primaryProp = primary_[hash]; if (primaryProp.key_ != JSTaggedValue::Hole()) { JSHClass* oldHclass = primaryProp.hclass_; diff --git a/ecmascript/ic/mega_ic_cache.h b/ecmascript/ic/mega_ic_cache.h index dea4778606..95e0d94e55 100644 --- a/ecmascript/ic/mega_ic_cache.h +++ b/ecmascript/ic/mega_ic_cache.h @@ -34,9 +34,9 @@ public: Load, Store, }; - JSTaggedValue Get(JSHClass *jsHclass, JSTaggedValue key) + JSTaggedValue Get(const JSThread *thread, JSHClass *jsHclass, JSTaggedValue key) { - int hash = PrimaryHash(jsHclass, key); + int hash = PrimaryHash(thread, jsHclass, key); PropertyKey &prop = primary_[hash]; if ((prop.hclass_ == jsHclass) && (prop.key_ == key)) { return primary_[hash].results_; @@ -181,12 +181,12 @@ private: ~MegaICCache() = default; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) - static inline int PrimaryHash(JSHClass *cls, JSTaggedValue key) + static inline int PrimaryHash(const JSThread *thread, JSHClass *cls, JSTaggedValue key) { uint32_t clsHash = static_cast( reinterpret_cast(cls) ^ (reinterpret_cast(cls) >> PRIMARY_LENGTH_BIT)); - uint32_t keyHash = key.GetStringKeyHashCode(); + uint32_t keyHash = key.GetStringKeyHashCode(thread); uint32_t hash = clsHash + keyHash; return static_cast((hash) & PRIMARY_LENGTH_MASK); } diff --git a/ecmascript/ic/profile_type_info.cpp b/ecmascript/ic/profile_type_info.cpp index 5d9413ec0b..f0cb6ef7eb 100644 --- a/ecmascript/ic/profile_type_info.cpp +++ b/ecmascript/ic/profile_type_info.cpp @@ -25,7 +25,7 @@ namespace panda::ecmascript { void ProfileTypeAccessor::AddElementHandler(JSHandle hclass, JSHandle handler) const { ALLOW_LOCAL_TO_SHARE_WEAK_REF_HANDLE; - auto profileData = profileTypeInfo_->GetIcSlot(slotId_); + auto profileData = profileTypeInfo_->GetIcSlot(thread_, slotId_); ASSERT(!profileData.IsHole()); auto index = slotId_; if (profileData.IsUndefined()) { @@ -46,7 +46,7 @@ void ProfileTypeAccessor::AddWithoutKeyPoly(JSHandle hclass, JSHa uint32_t index, JSTaggedValue profileData, JSHandle keyForMegaIC, MegaICCache::MegaICKind kind) const { - ASSERT(profileTypeInfo_->GetIcSlot(index + 1).IsHole()); + ASSERT(profileTypeInfo_->GetIcSlot(thread_, index + 1).IsHole()); JSHandle arr(thread_, profileData); const uint32_t step = 2; uint32_t newLen = arr->GetLength() + step; @@ -69,11 +69,11 @@ void ProfileTypeAccessor::AddWithoutKeyPoly(JSHandle hclass, JSHa uint32_t i = 0; for (; i < arr->GetLength(); i += step) { - if (arr->Get(i) == JSTaggedValue::Undefined()) { + if (arr->Get(thread_, i) == JSTaggedValue::Undefined()) { continue; } - cache->Set(JSHClass::Cast(arr->Get(i).GetWeakReferentUnChecked()), keyForMegaIC.GetTaggedValue(), - arr->Get(i + 1), thread_); + cache->Set(JSHClass::Cast(arr->Get(thread_, i).GetWeakReferentUnChecked()), keyForMegaIC.GetTaggedValue(), + arr->Get(thread_, i + 1), thread_); } profileTypeInfo_->SetMultiIcSlotLocked(thread_, index, JSTaggedValue::Hole(), index + 1, keyForMegaIC.GetTaggedValue()); @@ -84,8 +84,8 @@ void ProfileTypeAccessor::AddWithoutKeyPoly(JSHandle hclass, JSHa JSHandle newArr = factory->NewTaggedArray(newLen); uint32_t i = 0; for (; i < arr->GetLength(); i += step) { - newArr->Set(thread_, i, arr->Get(i)); - newArr->Set(thread_, i + 1, arr->Get(i + 1)); + newArr->Set(thread_, i, arr->Get(thread_, i)); + newArr->Set(thread_, i + 1, arr->Get(thread_, i + 1)); } newArr->Set(thread_, i, GetWeakRef(hclass.GetTaggedValue())); newArr->Set(thread_, i + 1, handler.GetTaggedValue()); @@ -102,7 +102,7 @@ void ProfileTypeAccessor::AddHandlerWithoutKey(JSHandle hclass, J profileTypeInfo_->SetIcSlot(thread_, index, handler.GetTaggedValue()); return; } - auto profileData = profileTypeInfo_->GetIcSlot(slotId_); + auto profileData = profileTypeInfo_->GetIcSlot(thread_, slotId_); ASSERT(!profileData.IsHole()); if (profileData.IsUndefined()) { profileTypeInfo_->SetMultiIcSlotLocked(thread_, index, GetWeakRef(hclass.GetTaggedValue()), @@ -117,8 +117,8 @@ void ProfileTypeAccessor::AddHandlerWithoutKey(JSHandle hclass, J auto factory = thread_->GetEcmaVM()->GetFactory(); JSHandle newArr = factory->NewTaggedArray(POLY_CASE_NUM); uint32_t arrIndex = 0; - newArr->Set(thread_, arrIndex++, profileTypeInfo_->GetIcSlot(index)); - newArr->Set(thread_, arrIndex++, profileTypeInfo_->GetIcSlot(index + 1)); + newArr->Set(thread_, arrIndex++, profileTypeInfo_->GetIcSlot(thread_, index)); + newArr->Set(thread_, arrIndex++, profileTypeInfo_->GetIcSlot(thread_, index + 1)); newArr->Set(thread_, arrIndex++, GetWeakRef(hclass.GetTaggedValue())); newArr->Set(thread_, arrIndex, handler.GetTaggedValue()); @@ -133,7 +133,7 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl AddGlobalHandlerKey(key, handler); return; } - auto profileData = profileTypeInfo_->GetIcSlot(slotId_); + auto profileData = profileTypeInfo_->GetIcSlot(thread_, slotId_); ASSERT(!profileData.IsHole()); auto index = slotId_; if (profileData.IsUndefined()) { @@ -150,7 +150,7 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl profileTypeInfo_->SetMultiIcSlotLocked(thread_, index, JSTaggedValue::Hole(), index + 1, JSTaggedValue::Hole()); return; } - JSTaggedValue patchValue = profileTypeInfo_->GetIcSlot(index + 1); + JSTaggedValue patchValue = profileTypeInfo_->GetIcSlot(thread_, index + 1); ASSERT(patchValue.IsTaggedArray()); JSHandle arr(thread_, patchValue); const uint32_t step = 2; @@ -166,8 +166,8 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl newArr->Set(thread_, 0, GetWeakRef(hclass.GetTaggedValue())); newArr->Set(thread_, 1, handler.GetTaggedValue()); for (uint32_t i = 0; i < arr->GetLength(); i += step) { - newArr->Set(thread_, i + step, arr->Get(i)); - newArr->Set(thread_, i + step + 1, arr->Get(i + 1)); + newArr->Set(thread_, i + step, arr->Get(thread_, i)); + newArr->Set(thread_, i + step + 1, arr->Get(thread_, i + 1)); } profileTypeInfo_->SetIcSlot(thread_, index + 1, newArr.GetTaggedValue()); return; @@ -176,8 +176,8 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl auto factory = thread_->GetEcmaVM()->GetFactory(); JSHandle newArr = factory->NewTaggedArray(POLY_CASE_NUM); uint32_t arrIndex = 0; - newArr->Set(thread_, arrIndex++, arr->Get(0)); - newArr->Set(thread_, arrIndex++, arr->Get(1)); + newArr->Set(thread_, arrIndex++, arr->Get(thread_, 0)); + newArr->Set(thread_, arrIndex++, arr->Get(thread_, 1)); newArr->Set(thread_, arrIndex++, GetWeakRef(hclass.GetTaggedValue())); newArr->Set(thread_, arrIndex++, handler.GetTaggedValue()); @@ -189,7 +189,7 @@ void ProfileTypeAccessor::AddGlobalHandlerKey(JSHandle key, JSHan ALLOW_LOCAL_TO_SHARE_WEAK_REF_HANDLE; auto index = slotId_; const uint8_t step = 2; // key and value pair - JSTaggedValue indexVal = profileTypeInfo_->GetIcSlot(index); + JSTaggedValue indexVal = profileTypeInfo_->GetIcSlot(thread_, index); if (indexVal.IsUndefined()) { auto factory = thread_->GetEcmaVM()->GetFactory(); JSHandle newArr = factory->NewTaggedArray(step); @@ -211,8 +211,8 @@ void ProfileTypeAccessor::AddGlobalHandlerKey(JSHandle key, JSHan newArr->Set(thread_, 1, handler.GetTaggedValue()); for (uint32_t i = 0; i < arr->GetLength(); i += step) { - newArr->Set(thread_, i + step, arr->Get(i)); - newArr->Set(thread_, i + step + 1, arr->Get(i + 1)); + newArr->Set(thread_, i + step, arr->Get(thread_, i)); + newArr->Set(thread_, i + step + 1, arr->Get(thread_, i + 1)); } profileTypeInfo_->SetIcSlot(thread_, index, newArr.GetTaggedValue()); } @@ -307,7 +307,7 @@ std::string ProfileTypeAccessor::ICStateToString(ProfileTypeAccessor::ICState st } ProfileTypeAccessor::ICState ProfileTypeAccessor::GetMegaState() const { - auto profileDataSecond = profileTypeInfo_->Get(slotId_ + 1); + auto profileDataSecond = profileTypeInfo_->Get(thread_, slotId_ + 1); if (profileDataSecond.IsString()) { return ICState::IC_MEGA; } else { @@ -317,7 +317,7 @@ ProfileTypeAccessor::ICState ProfileTypeAccessor::GetMegaState() const ProfileTypeAccessor::ICState ProfileTypeAccessor::GetICState() const { - auto profileData = profileTypeInfo_->GetIcSlot(slotId_); + auto profileData = profileTypeInfo_->GetIcSlot(thread_, slotId_); if (profileData.IsUndefined()) { return ICState::UNINIT; } @@ -343,7 +343,7 @@ ProfileTypeAccessor::ICState ProfileTypeAccessor::GetICState() const TaggedArray *array = TaggedArray::Cast(profileData.GetTaggedObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } - profileData = profileTypeInfo_->GetIcSlot(slotId_ + 1); + profileData = profileTypeInfo_->GetIcSlot(thread_, slotId_ + 1); TaggedArray *array = TaggedArray::Cast(profileData.GetTaggedObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } diff --git a/ecmascript/ic/profile_type_info.h b/ecmascript/ic/profile_type_info.h index 9eccf9f6a4..d6a1b28e26 100644 --- a/ecmascript/ic/profile_type_info.h +++ b/ecmascript/ic/profile_type_info.h @@ -242,9 +242,9 @@ public: return GetPeriodIndex() == BIG_METHOD_PERIOD_INDEX; } - JSTaggedValue GetExtraInfoMap() const + JSTaggedValue GetExtraInfoMap(const JSThread *thread) const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetExtraInfoMapOffset())); + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), GetExtraInfoMapOffset())); } void SetExtraInfoMap(const JSThread *thread, JSHandle extraInfoMap) @@ -255,7 +255,7 @@ public: uint16_t GetJitHotnessThreshold() const { - return Barriers::GetValue(GetData(), GetJitHotnessThresholdBitfieldOffset()); + return Barriers::GetPrimitive(GetData(), GetJitHotnessThresholdBitfieldOffset()); } void SetJitHotnessThreshold(uint16_t count) @@ -265,7 +265,7 @@ public: uint16_t GetOsrHotnessThreshold() const { - return Barriers::GetValue(GetData(), GetOsrHotnessThresholdBitfieldOffset()); + return Barriers::GetPrimitive(GetData(), GetOsrHotnessThresholdBitfieldOffset()); } void SetOsrHotnessThreshold(uint16_t count) @@ -275,7 +275,7 @@ public: uint16_t GetBaselineJitHotnessThreshold() const { - return Barriers::GetValue(GetData(), GetBaselineJitHotnessThresholdBitfieldOffset()); + return Barriers::GetPrimitive(GetData(), GetBaselineJitHotnessThresholdBitfieldOffset()); } void SetBaselineJitHotnessThreshold(uint16_t count) @@ -290,7 +290,7 @@ public: uint16_t GetJitHotnessCnt() const { - return Barriers::GetValue(GetData(), GetJitHotnessCntBitfieldOffset()); + return Barriers::GetPrimitive(GetData(), GetJitHotnessCntBitfieldOffset()); } void SetJitHotnessCnt(uint16_t count) @@ -303,10 +303,10 @@ public: Barriers::SetPrimitive(GetData(), GetOsrHotnessCntBitfieldOffset(), count); } - inline JSTaggedValue GetIcSlot(uint32_t idx) const + inline JSTaggedValue GetIcSlot(const JSThread* thread, uint32_t idx) const { ASSERT(idx < GetIcSlotLength()); - return TaggedArray::Get(idx); + return TaggedArray::Get(thread, idx); } inline void SetIcSlot(const JSThread* thread, uint32_t idx, const JSTaggedValue& value) @@ -328,12 +328,12 @@ public: static JSHandle CreateOrGetExtraInfoMap(const JSThread *thread, JSHandle profileTypeInfo) { - if (profileTypeInfo->GetExtraInfoMap().IsUndefined()) { + if (profileTypeInfo->GetExtraInfoMap(thread).IsUndefined()) { JSHandle dictJShandle = NumberDictionary::Create(thread); profileTypeInfo->SetExtraInfoMap(thread, dictJShandle); return dictJShandle; } - JSHandle dictJShandle(thread, profileTypeInfo->GetExtraInfoMap()); + JSHandle dictJShandle(thread, profileTypeInfo->GetExtraInfoMap(thread)); return dictJShandle; } @@ -361,7 +361,7 @@ public: private: uint32_t GetPeriodIndex() const { - return Barriers::GetValue(GetData(), GetBitfieldOffset()); + return Barriers::GetPrimitive(GetData(), GetBitfieldOffset()); } void SetPeriodIndex(uint32_t count) diff --git a/ecmascript/ic/properties_cache.h b/ecmascript/ic/properties_cache.h index 1b385e5e87..2dd7f6fc8e 100644 --- a/ecmascript/ic/properties_cache.h +++ b/ecmascript/ic/properties_cache.h @@ -27,18 +27,18 @@ namespace panda::ecmascript { class EcmaVM; class PropertiesCache { public: - inline int Get(JSHClass *jsHclass, JSTaggedValue key) + inline int Get(const JSThread *thread, JSHClass *jsHclass, JSTaggedValue key) { - int hash = Hash(jsHclass, key); + int hash = Hash(thread, jsHclass, key); PropertyKey &prop = keys_[hash]; if ((prop.hclass_ == jsHclass) && (prop.key_ == key)) { return keys_[hash].results_; } return NOT_FOUND; } - inline void Set(JSHClass *jsHclass, JSTaggedValue key, int index) + inline void Set(const JSThread *thread, JSHClass *jsHclass, JSTaggedValue key, int index) { - int hash = Hash(jsHclass, key); + int hash = Hash(thread, jsHclass, key); PropertyKey &prop = keys_[hash]; prop.hclass_ = jsHclass; prop.key_ = key; @@ -114,10 +114,10 @@ private: // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) - static inline int Hash(JSHClass *cls, JSTaggedValue key) + static inline int Hash(const JSThread *thread, JSHClass *cls, JSTaggedValue key) { uint32_t clsHash = static_cast(reinterpret_cast(cls)) >> 3U; // skip 8bytes - uint32_t keyHash = key.GetKeyHashCode(); + uint32_t keyHash = key.GetKeyHashCode(thread); return static_cast((clsHash ^ keyHash) & CACHE_LENGTH_MASK); } diff --git a/ecmascript/ic/property_box.cpp b/ecmascript/ic/property_box.cpp index 6c347c5037..f9c286f88e 100644 --- a/ecmascript/ic/property_box.cpp +++ b/ecmascript/ic/property_box.cpp @@ -18,7 +18,7 @@ namespace panda::ecmascript { void PropertyBox::Clear(const JSThread *thread) { - ASSERT_PRINT(!GetValue().IsHole(), "value must not be hole"); + ASSERT_PRINT(!GetValue(thread).IsHole(), "value must not be hole"); SetValue(thread, JSTaggedValue::Hole()); } } // namespace panda::ecmascript diff --git a/ecmascript/ic/property_box.h b/ecmascript/ic/property_box.h index 532e29ca14..8f2cc939d8 100644 --- a/ecmascript/ic/property_box.h +++ b/ecmascript/ic/property_box.h @@ -35,9 +35,9 @@ public: void Clear(const JSThread *thread); - inline bool IsInvalid() const + inline bool IsInvalid(const JSThread *thread) const { - return GetValue().IsHole(); + return GetValue(thread).IsHole(); } static constexpr size_t VALUE_OFFSET = TaggedObjectSize(); diff --git a/ecmascript/ic/proto_change_details.cpp b/ecmascript/ic/proto_change_details.cpp index 8680dcd4d5..18cfd8945a 100644 --- a/ecmascript/ic/proto_change_details.cpp +++ b/ecmascript/ic/proto_change_details.cpp @@ -32,7 +32,7 @@ JSHandle ChangeListener::Add(const JSThread *thread, const JSHan UNREACHABLE(); } // if exist hole, use it. - uint32_t holeIndex = CheckHole(array); + uint32_t holeIndex = CheckHole(thread, array); if (holeIndex != TaggedArray::MAX_ARRAY_INDEX) { weakValue = JSTaggedValue(value.GetTaggedValue().CreateAndGetWeakRef()); array->Set(thread, holeIndex, weakValue); @@ -52,10 +52,10 @@ JSHandle ChangeListener::Add(const JSThread *thread, const JSHan return JSHandle(newArray); } -uint32_t ChangeListener::CheckHole(const JSHandle &array) +uint32_t ChangeListener::CheckHole(const JSThread *thread, const JSHandle &array) { for (uint32_t i = 0; i < array->GetEnd(); i++) { - JSTaggedValue value = array->Get(i); + JSTaggedValue value = array->Get(thread, i); if (value.IsHole() || value.IsUndefined()) { return i; } @@ -63,9 +63,9 @@ uint32_t ChangeListener::CheckHole(const JSHandle &array) return TaggedArray::MAX_ARRAY_INDEX; } -JSTaggedValue ChangeListener::Get(uint32_t index) +JSTaggedValue ChangeListener::Get(const JSThread *thread, uint32_t index) { - JSTaggedValue value = WeakVector::Get(index); + JSTaggedValue value = WeakVector::Get(thread, index); if (!value.IsHeapObject()) { return value; } diff --git a/ecmascript/ic/proto_change_details.h b/ecmascript/ic/proto_change_details.h index 1a54c64a36..7f0b5fb277 100644 --- a/ecmascript/ic/proto_change_details.h +++ b/ecmascript/ic/proto_change_details.h @@ -82,9 +82,9 @@ public: static JSHandle Add(const JSThread *thread, const JSHandle &array, const JSHandle &value, uint32_t *index); - static uint32_t CheckHole(const JSHandle &array); + static uint32_t CheckHole(const JSThread *thread, const JSHandle &array); - JSTaggedValue Get(uint32_t index); + JSTaggedValue Get(const JSThread *thread, uint32_t index); }; } // namespace ecmascript } // namespace panda diff --git a/ecmascript/ic/tests/ic_handler_test.cpp b/ecmascript/ic/tests/ic_handler_test.cpp index fe8dac5753..c33bb0532e 100644 --- a/ecmascript/ic/tests/ic_handler_test.cpp +++ b/ecmascript/ic/tests/ic_handler_test.cpp @@ -199,8 +199,8 @@ HWTEST_F_L0(ICHandlerTest, StoreTransition) JSHandle handlerValue = TransitionHandler::StoreTransition(thread, handleOp); JSHandle handler = JSHandle::Cast(handlerValue); - EXPECT_TRUE(handler->GetHandlerInfo().IsPropertyBox()); - EXPECT_TRUE(handler->GetTransitionHClass().IsHeapObject()); + EXPECT_TRUE(handler->GetHandlerInfo(thread).IsPropertyBox()); + EXPECT_TRUE(handler->GetTransitionHClass(thread).IsHeapObject()); } /** @@ -235,11 +235,11 @@ HWTEST_F_L0(ICHandlerTest, LoadPrototype) // test op is Found and hclass has Prototype JSHandle handlerValue2 = PrototypeHandler::LoadPrototype(thread, handleOp2, obj2Class); JSHandle handler2 = JSHandle::Cast(handlerValue2); - JSHandle handlerInfo2(thread, handler2->GetHandlerInfo()); + JSHandle handlerInfo2(thread, handler2->GetHandlerInfo(thread)); EXPECT_EQ(HandlerBase::GetOffset(handlerInfo2->GetInt()), 2); - JSHandle resultMarker(thread, handler2->GetProtoCell()); + JSHandle resultMarker(thread, handler2->GetProtoCell(thread)); EXPECT_TRUE(resultMarker->IsProtoChangeMarker()); - EXPECT_TRUE(handler2->GetHolder().IsJSGlobalObject()); + EXPECT_TRUE(handler2->GetHolder(thread).IsJSGlobalObject()); } /** @@ -269,10 +269,10 @@ HWTEST_F_L0(ICHandlerTest, StorePrototype) // test hclass has Prototype JSHandle handlerValue = PrototypeHandler::StorePrototype(thread, handleOp, objClass); JSHandle handler = JSHandle::Cast(handlerValue); - JSHandle handlerInfo(thread, handler->GetHandlerInfo()); + JSHandle handlerInfo(thread, handler->GetHandlerInfo(thread)); EXPECT_EQ(HandlerBase::GetOffset(handlerInfo->GetInt()), 2); - JSHandle resultMarker(thread, handler->GetProtoCell()); + JSHandle resultMarker(thread, handler->GetProtoCell(thread)); EXPECT_TRUE(resultMarker->IsProtoChangeMarker()); - EXPECT_TRUE(handler->GetHolder().IsJSGlobalObject()); + EXPECT_TRUE(handler->GetHolder(thread).IsJSGlobalObject()); } } // namespace panda::test diff --git a/ecmascript/ic/tests/ic_runtime_stub_test.cpp b/ecmascript/ic/tests/ic_runtime_stub_test.cpp index bb668a82dc..f1fd51746e 100644 --- a/ecmascript/ic/tests/ic_runtime_stub_test.cpp +++ b/ecmascript/ic/tests/ic_runtime_stub_test.cpp @@ -89,7 +89,7 @@ HWTEST_F_L0(ICRuntimeStubTest, LoadGlobalICByName) ICRuntimeStub::LoadGlobalICByName(thread, *handleProfileTypeInfo, globalValue.GetTaggedValue(), propKey.GetTaggedValue(), 1, true); EXPECT_EQ(resultValue2.GetInt(), 2); - EXPECT_TRUE(handleProfileTypeInfo->Get(1).IsPropertyBox()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 1).IsPropertyBox()); } HWTEST_F_L0(ICRuntimeStubTest, StoreGlobalICByName) @@ -113,7 +113,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreGlobalICByName) ICRuntimeStub::StoreGlobalICByName(thread, *handleProfileTypeInfo, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), handleValue, 0, true); EXPECT_TRUE(resultValue1.IsUndefined()); - EXPECT_EQ(handleBoxValue->GetValue().GetInt(), 2); + EXPECT_EQ(handleBoxValue->GetValue(thread).GetInt(), 2); // the globalValue is jsobject then call storeMiss function can find global variable from global record firstly // so need store global record. SlowRuntimeStub::StGlobalRecord(thread, propKey.GetTaggedValue(), handleBoxValue.GetTaggedValue(), false); @@ -121,7 +121,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreGlobalICByName) ICRuntimeStub::StoreGlobalICByName(thread, *handleProfileTypeInfo, globalValue.GetTaggedValue(), propKey.GetTaggedValue(), handleValue, 1, true); EXPECT_TRUE(resultValue2.IsUndefined()); - EXPECT_TRUE(handleProfileTypeInfo->Get(1).IsPropertyBox()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 1).IsPropertyBox()); } HWTEST_F_L0(ICRuntimeStubTest, CheckPolyHClass) @@ -148,7 +148,7 @@ HWTEST_F_L0(ICRuntimeStubTest, CheckPolyHClass) handleCacheArray->Set(thread, 4, handleEmptyStr.GetTaggedValue()); // 4 : 4 set value in four JSTaggedValue handleWeakCacheValue(handleCacheArray.GetTaggedValue()); - JSTaggedValue resultValue = ICRuntimeStub::CheckPolyHClass(handleWeakCacheValue, handleObjClass); + JSTaggedValue resultValue = ICRuntimeStub::CheckPolyHClass(thread, handleWeakCacheValue, handleObjClass); EXPECT_TRUE(resultValue.IsPropertyBox()); } @@ -198,7 +198,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByValue) handleKey.GetTaggedValue(), 0); EXPECT_TRUE(resultValue.IsString()); JSHandle handleEcmaStrTo(JSHandle(thread, resultValue)); - EXPECT_STREQ("1", EcmaStringAccessor(handleEcmaStrTo).ToCString().c_str()); + EXPECT_STREQ("1", EcmaStringAccessor(handleEcmaStrTo).ToCString(thread).c_str()); } HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByName) @@ -362,7 +362,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreICWithHandler) ICRuntimeStub::StoreICWithHandler(thread, handleReceiver.GetTaggedValue(), handleHolder.GetTaggedValue(), JSTaggedValue(2), boxHandler.GetTaggedValue()); EXPECT_TRUE(resultValue2.IsUndefined()); - EXPECT_EQ(ICRuntimeStub::LoadGlobal(boxHandler.GetTaggedValue()).GetInt(), 2); + EXPECT_EQ(ICRuntimeStub::LoadGlobal(thread, boxHandler.GetTaggedValue()).GetInt(), 2); // HandlerBase Is NonExist and This situation is not judged. KindBit::Set(HandlerKind::NON_EXIST, &handler); JSTaggedValue resultValue3 = @@ -456,7 +456,7 @@ HWTEST_F_L0(ICRuntimeStubTest, Prototype_StoreAndLoad) // test loadPrototype function JSTaggedValue resultValue2 = ICRuntimeStub::LoadPrototype(thread, handleObj.GetTaggedValue(), handleProtoHandler.GetTaggedValue()); - EXPECT_EQ(ICRuntimeStub::LoadFromField(*handleObj, handler).GetInt(), resultValue2.GetInt()); + EXPECT_EQ(ICRuntimeStub::LoadFromField(thread, *handleObj, handler).GetInt(), resultValue2.GetInt()); } HWTEST_F_L0(ICRuntimeStubTest, StoreWithTransition_In_Filed) @@ -486,8 +486,8 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreWithTransition_In_Filed) // test handler is InlinedProps and store in filed InlinedPropsBit::Set(true, &handler); ICRuntimeStub::StoreWithTransition(thread, *handleObj, JSTaggedValue(2), handleTranHandler.GetTaggedValue()); - auto resultArray = TaggedArray::Cast(handleObj->GetProperties().GetTaggedObject()); - EXPECT_EQ(resultArray->Get(bitOffset).GetInt(), 2); + auto resultArray = TaggedArray::Cast(handleObj->GetProperties(thread).GetTaggedObject()); + EXPECT_EQ(resultArray->Get(thread, bitOffset).GetInt(), 2); handleObj->SynchronizedTransitionClass(thread, *originHClass); } @@ -509,12 +509,12 @@ HWTEST_F_L0(ICRuntimeStubTest, Field_StoreAndLoad) handleObj->SetProperties(thread, handleTaggedArr.GetTaggedValue()); // test handler is not InlinedProps ICRuntimeStub::StoreField(thread, *handleObj, JSTaggedValue(3), handler); - JSTaggedValue resultValue1 = ICRuntimeStub::LoadFromField(*handleObj, handler); + JSTaggedValue resultValue1 = ICRuntimeStub::LoadFromField(thread, *handleObj, handler); EXPECT_EQ(resultValue1.GetInt(), 3); // test handler is InlinedProps InlinedPropsBit::Set(true, &handler); ICRuntimeStub::StoreField(thread, *handleObj, JSTaggedValue(2), handler); - JSTaggedValue resultValue = ICRuntimeStub::LoadFromField(*handleObj, handler); + JSTaggedValue resultValue = ICRuntimeStub::LoadFromField(thread, *handleObj, handler); EXPECT_EQ(resultValue.GetInt(), 2); } @@ -526,14 +526,14 @@ HWTEST_F_L0(ICRuntimeStubTest, Global_StoreAndLoad) JSTaggedValue resultValue1 = ICRuntimeStub::StoreGlobal(thread, JSTaggedValue(2), handlerValue.GetTaggedValue()); EXPECT_TRUE(resultValue1.IsUndefined()); - JSTaggedValue resultValue2 = ICRuntimeStub::LoadGlobal(handlerValue.GetTaggedValue()); + JSTaggedValue resultValue2 = ICRuntimeStub::LoadGlobal(thread, handlerValue.GetTaggedValue()); EXPECT_EQ(resultValue2.GetInt(), 2); handlerValue->Clear(thread); JSTaggedValue resultValue3 = ICRuntimeStub::StoreGlobal(thread, JSTaggedValue(3), handlerValue.GetTaggedValue()); EXPECT_TRUE(resultValue3.IsHole()); - JSTaggedValue resultValue4 = ICRuntimeStub::LoadGlobal(handlerValue.GetTaggedValue()); + JSTaggedValue resultValue4 = ICRuntimeStub::LoadGlobal(thread, handlerValue.GetTaggedValue()); EXPECT_TRUE(resultValue4.IsHole()); } @@ -573,11 +573,11 @@ HWTEST_F_L0(ICRuntimeStubTest, TryToElementsIndex) JSHandle handleStrKey1(factory->NewFromASCII("1234")); JSHandle handleStrKey2(factory->NewFromASCII("xy")); - EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(hanldeIntKey1), 0); - EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(hanldeIntKey2), 1); - EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(handleDoubleKey1), 1); - EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(handleDoubleKey2), -1); - EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(handleStrKey1.GetTaggedValue()), 1234); - EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(handleStrKey2.GetTaggedValue()), -1); + EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(thread, hanldeIntKey1), 0); + EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(thread, hanldeIntKey2), 1); + EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(thread, handleDoubleKey1), 1); + EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(thread, handleDoubleKey2), -1); + EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(thread, handleStrKey1.GetTaggedValue()), 1234); + EXPECT_EQ(ICRuntimeStub::TryToElementsIndex(thread, handleStrKey2.GetTaggedValue()), -1); } } // namespace panda::test diff --git a/ecmascript/ic/tests/ic_runtime_test.cpp b/ecmascript/ic/tests/ic_runtime_test.cpp index 963e1f4ac9..ccb70f7d88 100644 --- a/ecmascript/ic/tests/ic_runtime_test.cpp +++ b/ecmascript/ic/tests/ic_runtime_test.cpp @@ -82,15 +82,15 @@ HWTEST_F_L0(ICRunTimeTest, UpdateLoadHandler) uint32_t slotId = 2; ICRuntime icRuntime(thread, handleProfileTypeInfo, slotId, ICKind::LoadIC); icRuntime.UpdateLoadHandler(handleOp1, handleKeyWithElement, handleReceiver); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsTaggedArray()); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsTaggedArray()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsHole()); // test op is not Element ObjectOperator handleOp2(thread, handleKeyWithString); slotId = 0; ICRuntime icRuntime1(thread, handleProfileTypeInfo, slotId, ICKind::NamedLoadIC); icRuntime1.UpdateLoadHandler(handleOp2, handleKeyWithString, handleReceiver); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsTaggedArray()); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsTaggedArray()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsHole()); } HWTEST_F_L0(ICRunTimeTest, UpdateStoreHandler) @@ -127,8 +127,8 @@ HWTEST_F_L0(ICRunTimeTest, UpdateStoreHandler) ICRuntime icRuntime(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); icRuntime.UpdateReceiverHClass(JSHandle(thread, JSHandle(handleReceiver)->GetJSHClass())); icRuntime.UpdateStoreHandler(handleOp1, handleKeyWithElement, handleReceiver); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsWeak()); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsPrototypeHandler()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsWeak()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsPrototypeHandler()); // test op is Transition slotId = 1; ObjectOperator handleOp2(thread, handleReceiver, handleKeyWithString, OperatorType::OWN); @@ -138,8 +138,8 @@ HWTEST_F_L0(ICRunTimeTest, UpdateStoreHandler) ICRuntime icRuntime1(thread, handleProfileTypeInfo, slotId, ICKind::NamedStoreIC); icRuntime1.UpdateReceiverHClass(env->GetArgumentsClass()); icRuntime1.UpdateStoreHandler(handleOp2, handleKeyWithString, handleReceiver); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsWeak()); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsTransitionHandler()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsWeak()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsTransitionHandler()); } HWTEST_F_L0(ICRunTimeTest, TraceIC) @@ -177,14 +177,14 @@ HWTEST_F_L0(ICRunTimeTest, StoreMiss) StoreICRuntime storeICRuntime(thread, handleProfileTypeInfo, 0, ICKind::NamedGlobalStoreIC); storeICRuntime.StoreMiss(handleReceiver, handleKeyWithString, handleValueWithElement); EXPECT_EQ(JSObject::GetProperty(thread, handleReceiver, handleKeyWithString).GetValue(), handleValueWithElement); - EXPECT_TRUE(handleProfileTypeInfo->Get(0).IsHole()); - EXPECT_TRUE(handleProfileTypeInfo->Get(1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 0).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 1).IsHole()); SlowRuntimeStub::StGlobalRecord(thread, handleKeyWithString.GetTaggedValue(), handleKeyWithString.GetTaggedValue(), false); handleProfileTypeInfo->Set(thread, 0, JSTaggedValue::Undefined()); storeICRuntime.StoreMiss(handleReceiver1, handleKeyWithString, handleValueWithElement); - EXPECT_TRUE(handleProfileTypeInfo->Get(0).IsPropertyBox()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 0).IsPropertyBox()); } HWTEST_F_L0(ICRunTimeTest, LoadMiss) @@ -205,7 +205,7 @@ HWTEST_F_L0(ICRunTimeTest, LoadMiss) handleProfileTypeInfo->Set(thread, 1, JSTaggedValue::Hole()); LoadICRuntime loadICRuntime(thread, handleProfileTypeInfo, 0, ICKind::NamedGlobalStoreIC); EXPECT_EQ(loadICRuntime.LoadMiss(handleReceiver, handleKeyWithString), handleValueWithElement.GetTaggedValue()); - EXPECT_TRUE(handleProfileTypeInfo->Get(0).IsHole()); - EXPECT_TRUE(handleProfileTypeInfo->Get(1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 0).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 1).IsHole()); } } // namespace panda::test diff --git a/ecmascript/ic/tests/profile_type_info_test.cpp b/ecmascript/ic/tests/profile_type_info_test.cpp index f86fd10b59..038ffe1133 100644 --- a/ecmascript/ic/tests/profile_type_info_test.cpp +++ b/ecmascript/ic/tests/profile_type_info_test.cpp @@ -149,29 +149,29 @@ HWTEST_F_L0(ProfileTypeInfoTest, AddHandlerWithoutKey) uint32_t slotId = 0; // test profileData is Undefined ProfileTypeAccessor handleProfileTypeAccessor0(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor0.AddHandlerWithoutKey(objClassVal, HandlerValue); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsWeak()); - EXPECT_EQ(handleProfileTypeInfo->Get(slotId + 1).GetInt(), 2); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsWeak()); + EXPECT_EQ(handleProfileTypeInfo->Get(thread, slotId + 1).GetInt(), 2); slotId = 1; // test POLY handleProfileTypeInfo->Set(thread, slotId, handleTaggedArray.GetTaggedValue()); // Reset Value ProfileTypeAccessor handleProfileTypeAccessor1(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor1.AddHandlerWithoutKey(objClassVal, HandlerValue); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsTaggedArray()); - JSHandle resultArr1(thread, handleProfileTypeInfo->Get(slotId)); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsTaggedArray()); + JSHandle resultArr1(thread, handleProfileTypeInfo->Get(thread, slotId)); EXPECT_EQ(resultArr1->GetLength(), 4U); // 4 = 2 + 2 - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsHole()); slotId = 2; // test MONO to POLY handleProfileTypeInfo->Set(thread, slotId, HandlerValue.GetTaggedValue()); // Reset Value ProfileTypeAccessor handleProfileTypeAccessor2(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor2.AddHandlerWithoutKey(objClassVal, HandlerValue); - JSHandle resultArr2(thread, handleProfileTypeInfo->Get(slotId)); + JSHandle resultArr2(thread, handleProfileTypeInfo->Get(thread, slotId)); EXPECT_EQ(resultArr2->GetLength(), 4U); // POLY_DEFAULT_LEN - EXPECT_EQ(resultArr2->Get(0).GetInt(), 2); - EXPECT_TRUE(resultArr2->Get(1).IsUndefined()); - EXPECT_TRUE(resultArr2->Get(2).IsWeak()); - EXPECT_EQ(resultArr2->Get(3).GetInt(), 2); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsHole()); + EXPECT_EQ(resultArr2->Get(thread, 0).GetInt(), 2); + EXPECT_TRUE(resultArr2->Get(thread, 1).IsUndefined()); + EXPECT_TRUE(resultArr2->Get(thread, 2).IsWeak()); + EXPECT_EQ(resultArr2->Get(thread, 3).GetInt(), 2); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsHole()); } /** @@ -199,8 +199,8 @@ HWTEST_F_L0(ProfileTypeInfoTest, AddElementHandler) uint32_t slotId = 0; ProfileTypeAccessor handleProfileTypeAccessor0(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor0.AddElementHandler(objClassVal, HandlerValue); - EXPECT_TRUE(handleProfileTypeInfo->Get(0).IsWeak()); - EXPECT_EQ(handleProfileTypeInfo->Get(1).GetInt(), 3); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 0).IsWeak()); + EXPECT_EQ(handleProfileTypeInfo->Get(thread, 1).GetInt(), 3); } /** @@ -237,21 +237,21 @@ HWTEST_F_L0(ProfileTypeInfoTest, AddHandlerWithKey) uint32_t slotId = 0; // test profileData is Undefined ProfileTypeAccessor handleProfileTypeAccessor0(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor0.AddHandlerWithKey(HandleKey1, objClassVal, HandlerValue); - EXPECT_TRUE(handleProfileTypeInfo->Get(0).IsString()); - EXPECT_TRUE(handleProfileTypeInfo->Get(1).IsTaggedArray()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 0).IsString()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 1).IsTaggedArray()); slotId = 1; // test profileData is equal the key handleProfileTypeInfo->Set(thread, slotId, HandleKey1.GetTaggedValue()); // Reset Value ProfileTypeAccessor handleProfileTypeAccessor1(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor1.AddHandlerWithKey(HandleKey1, objClassVal, HandlerValue); - JSHandle resultArr1(thread, handleProfileTypeInfo->Get(slotId + 1)); + JSHandle resultArr1(thread, handleProfileTypeInfo->Get(thread, slotId + 1)); EXPECT_EQ(resultArr1->GetLength(), 4U); // 4 = 2 + 2 slotId = 2; // test profileData is not equal the key ProfileTypeAccessor handleProfileTypeAccessor2(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor2.AddHandlerWithKey(HandleKey0, objClassVal, HandlerValue); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId).IsHole()); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsHole()); } /** @@ -279,20 +279,20 @@ HWTEST_F_L0(ProfileTypeInfoTest, AddGlobalHandlerKey) uint32_t slotId = 0; ProfileTypeAccessor handleProfileTypeAccessor0(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor0.AddGlobalHandlerKey(arrayKey, HandlerValue); - JSHandle resultArr1(thread, handleProfileTypeInfo->Get(slotId)); + JSHandle resultArr1(thread, handleProfileTypeInfo->Get(thread, slotId)); EXPECT_EQ(resultArr1->GetLength(), 2U); - EXPECT_TRUE(resultArr1->Get(0).IsWeak()); - EXPECT_EQ(resultArr1->Get(1).GetInt(), 222); + EXPECT_TRUE(resultArr1->Get(thread, 0).IsWeak()); + EXPECT_EQ(resultArr1->Get(thread, 1).GetInt(), 222); slotId = 1; ProfileTypeAccessor handleProfileTypeAccessor1(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor1.AddGlobalHandlerKey(arrayKey, HandlerValue); - JSHandle resultArr2(thread, handleProfileTypeInfo->Get(slotId)); + JSHandle resultArr2(thread, handleProfileTypeInfo->Get(thread, slotId)); EXPECT_EQ(resultArr2->GetLength(), 4U); - EXPECT_TRUE(resultArr2->Get(0).IsWeak()); - EXPECT_EQ(resultArr2->Get(1).GetInt(), 222); - EXPECT_EQ(resultArr2->Get(2).GetInt(), 111); - EXPECT_EQ(resultArr2->Get(3).GetInt(), 333); + EXPECT_TRUE(resultArr2->Get(thread, 0).IsWeak()); + EXPECT_EQ(resultArr2->Get(thread, 1).GetInt(), 222); + EXPECT_EQ(resultArr2->Get(thread, 2).GetInt(), 111); + EXPECT_EQ(resultArr2->Get(thread, 3).GetInt(), 333); } /** @@ -315,12 +315,12 @@ HWTEST_F_L0(ProfileTypeInfoTest, AddGlobalRecordHandler) uint32_t slotId = 0; ProfileTypeAccessor handleProfileTypeAccessor(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor.AddGlobalRecordHandler(HandlerValue1); - EXPECT_EQ(handleProfileTypeInfo->Get(slotId).GetInt(), 232); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsUndefined()); + EXPECT_EQ(handleProfileTypeInfo->Get(thread, slotId).GetInt(), 232); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsUndefined()); handleProfileTypeAccessor.AddGlobalRecordHandler(HandlerValue2); - EXPECT_EQ(handleProfileTypeInfo->Get(slotId).GetInt(), 5); - EXPECT_TRUE(handleProfileTypeInfo->Get(slotId + 1).IsUndefined()); + EXPECT_EQ(handleProfileTypeInfo->Get(thread, slotId).GetInt(), 5); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, slotId + 1).IsUndefined()); } /** @@ -343,8 +343,8 @@ HWTEST_F_L0(ProfileTypeInfoTest, SetAsMega) ProfileTypeAccessor handleProfileTypeAccessor(thread, handleProfileTypeInfo, slotId, ICKind::StoreIC); handleProfileTypeAccessor.SetAsMega(); - EXPECT_TRUE(handleProfileTypeInfo->Get(0).IsHole()); - EXPECT_TRUE(handleProfileTypeInfo->Get(1).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 0).IsHole()); + EXPECT_TRUE(handleProfileTypeInfo->Get(thread, 1).IsHole()); } /** diff --git a/ecmascript/ic/tests/properties_cache_test.cpp b/ecmascript/ic/tests/properties_cache_test.cpp index 101da69c26..ec95bc7671 100644 --- a/ecmascript/ic/tests/properties_cache_test.cpp +++ b/ecmascript/ic/tests/properties_cache_test.cpp @@ -69,18 +69,20 @@ HWTEST_F_L0(PropertiesCacheTest, SetAndGet) for (int i = 0; i < 10; i++) { JSHandle handleNumKey(thread, JSTaggedValue(1)); JSHandle handleStrKey(JSTaggedValue::ToString(thread, handleNumKey)); - handleProCache->Set(FuncHClass, handleStrKey.GetTaggedValue(), i); - EXPECT_EQ(handleProCache->Get(FuncHClass, handleStrKey.GetTaggedValue()), i); + handleProCache->Set(thread, FuncHClass, handleStrKey.GetTaggedValue(), i); + EXPECT_EQ(handleProCache->Get(thread, FuncHClass, handleStrKey.GetTaggedValue()), i); } - EXPECT_EQ(handleProCache->Get(FuncHClass, handleKey10.GetTaggedValue()), -1); // PropertiesCache::NOT_FOUND + EXPECT_EQ(handleProCache->Get(thread, FuncHClass, + handleKey10.GetTaggedValue()), -1); // PropertiesCache::NOT_FOUND // key is symbol for (int i = 0; i < 10; i++) { handleSymbol->SetHashField(static_cast(i)); - handleProCache->Set(FuncHClass, handleSymbol.GetTaggedValue(), i); - EXPECT_EQ(handleProCache->Get(FuncHClass, handleSymbol.GetTaggedValue()), i); + handleProCache->Set(thread, FuncHClass, handleSymbol.GetTaggedValue(), i); + EXPECT_EQ(handleProCache->Get(thread, FuncHClass, handleSymbol.GetTaggedValue()), i); } handleSymbol->SetHashField(static_cast(10)); - EXPECT_EQ(handleProCache->Get(FuncHClass, handleSymbol.GetTaggedValue()), -1); // PropertiesCache::NOT_FOUND + EXPECT_EQ(handleProCache->Get(thread, FuncHClass, + handleSymbol.GetTaggedValue()), -1); // PropertiesCache::NOT_FOUND handleProCache->Clear(); } @@ -101,9 +103,9 @@ HWTEST_F_L0(PropertiesCacheTest, Clear) JSHClass *FuncHClass = JSObject::Cast(handleFunction->GetTaggedObject())->GetJSHClass(); PropertiesCache *handleProCache = thread->GetPropertiesCache(); - handleProCache->Set(FuncHClass, handleKey.GetTaggedValue(), 10); - EXPECT_EQ(handleProCache->Get(FuncHClass, handleKey.GetTaggedValue()), 10); + handleProCache->Set(thread, FuncHClass, handleKey.GetTaggedValue(), 10); + EXPECT_EQ(handleProCache->Get(thread, FuncHClass, handleKey.GetTaggedValue()), 10); handleProCache->Clear(); - EXPECT_EQ(handleProCache->Get(FuncHClass, handleKey.GetTaggedValue()), -1); // PropertiesCache::NOT_FOUND + EXPECT_EQ(handleProCache->Get(thread, FuncHClass, handleKey.GetTaggedValue()), -1); // PropertiesCache::NOT_FOUND } } // namespace panda::test diff --git a/ecmascript/ic/tests/property_box_test.cpp b/ecmascript/ic/tests/property_box_test.cpp index caa260f099..c1b5e765ff 100644 --- a/ecmascript/ic/tests/property_box_test.cpp +++ b/ecmascript/ic/tests/property_box_test.cpp @@ -59,11 +59,11 @@ HWTEST_F_L0(PropertyBoxTest, Clear) JSHandle handleValue(thread, JSTaggedValue(1)); JSHandle handlePropertyBox = factory->NewPropertyBox(handleValue); - EXPECT_FALSE(handlePropertyBox->GetValue().IsHole()); + EXPECT_FALSE(handlePropertyBox->GetValue(thread).IsHole()); handlePropertyBox->Clear(thread); - EXPECT_TRUE(handlePropertyBox->GetValue().IsHole()); - EXPECT_TRUE(handlePropertyBox->IsInvalid()); + EXPECT_TRUE(handlePropertyBox->GetValue(thread).IsHole()); + EXPECT_TRUE(handlePropertyBox->IsInvalid(thread)); } /** @@ -81,7 +81,7 @@ HWTEST_F_L0(PropertyBoxTest, SetValue) JSHandle handlePropertyBox = JSHandle::Cast(handlePropertyBoxVal); handlePropertyBox->SetValue(thread, JSTaggedValue(2)); - EXPECT_EQ(handlePropertyBox->GetValue().GetInt(), 2); - EXPECT_FALSE(handlePropertyBox->IsInvalid()); + EXPECT_EQ(handlePropertyBox->GetValue(thread).GetInt(), 2); + EXPECT_FALSE(handlePropertyBox->IsInvalid(thread)); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/ic/tests/proto_change_details_test.cpp b/ecmascript/ic/tests/proto_change_details_test.cpp index 7b27a91b37..03edc9cad4 100644 --- a/ecmascript/ic/tests/proto_change_details_test.cpp +++ b/ecmascript/ic/tests/proto_change_details_test.cpp @@ -102,9 +102,9 @@ HWTEST_F_L0(ProtoChangeDetailsTest, SetChangeListener) JSHandle handleChangeDetails = factory->NewProtoChangeDetails(); handleChangeDetails->SetChangeListener(thread, handleValue.GetTaggedValue()); - EXPECT_EQ(handleChangeDetails->GetChangeListener().GetInt(), 1); + EXPECT_EQ(handleChangeDetails->GetChangeListener(thread).GetInt(), 1); handleChangeDetails->SetChangeListener(thread, handleChangeListener.GetTaggedValue()); - EXPECT_EQ(handleChangeDetails->GetChangeListener(), handleChangeListener.GetTaggedValue()); + EXPECT_EQ(handleChangeDetails->GetChangeListener(thread), handleChangeListener.GetTaggedValue()); } /** @@ -150,7 +150,7 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_001) EXPECT_EQ(index, 9U); JSTaggedValue weakRefValue(objClassVal.GetTaggedValue()); weakRefValue.CreateWeakRef(); - EXPECT_EQ(resultListenerArray->Get(index).GetTaggedObject(), weakRefValue.GetTaggedWeakRef()); + EXPECT_EQ(resultListenerArray->Get(thread, index).GetTaggedObject(), weakRefValue.GetTaggedWeakRef()); } /** @@ -183,7 +183,7 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_002) EXPECT_EQ(index, 1U); JSTaggedValue weakRefValue(objClassVal.GetTaggedValue()); weakRefValue.CreateWeakRef(); - EXPECT_EQ(resultListenerArray->Get(index).GetTaggedObject(), weakRefValue.GetTaggedWeakRef()); + EXPECT_EQ(resultListenerArray->Get(thread, index).GetTaggedObject(), weakRefValue.GetTaggedWeakRef()); } /** @@ -215,7 +215,7 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_003) EXPECT_EQ(index, 10U); JSTaggedValue weakRefValue(objClassVal.GetTaggedValue()); weakRefValue.CreateWeakRef(); - EXPECT_EQ(resultListenerArray->Get(index).GetTaggedObject(), weakRefValue.GetTaggedWeakRef()); + EXPECT_EQ(resultListenerArray->Get(thread, index).GetTaggedObject(), weakRefValue.GetTaggedWeakRef()); } /** @@ -235,9 +235,9 @@ HWTEST_F_L0(ProtoChangeDetailsTest, CheckHole) weakVector->PushBack(thread, JSTaggedValue(i)); // Set Value and End } JSHandle handleChangeListenerArr = JSHandle::Cast(weakVector); - EXPECT_EQ(ChangeListener::CheckHole(handleChangeListenerArr), TaggedArray::MAX_ARRAY_INDEX); + EXPECT_EQ(ChangeListener::CheckHole(thread, handleChangeListenerArr), TaggedArray::MAX_ARRAY_INDEX); weakVector->Delete(thread, 1); - EXPECT_EQ(ChangeListener::CheckHole(handleChangeListenerArr), 1U); + EXPECT_EQ(ChangeListener::CheckHole(thread, handleChangeListenerArr), 1U); } /** @@ -265,9 +265,9 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Get) weakVector->Set(thread, 2, JSTaggedValue::Undefined()); JSHandle handleChangeListenerArr = JSHandle::Cast(weakVector); EXPECT_TRUE(*handleChangeListenerArr != nullptr); - EXPECT_EQ(handleChangeListenerArr->Get(0).GetInt(), 0); + EXPECT_EQ(handleChangeListenerArr->Get(thread, 0).GetInt(), 0); // the value is the weakRef of objValue - EXPECT_EQ(handleChangeListenerArr->Get(1).GetTaggedObject(), objValue.GetTaggedWeakRef()); - EXPECT_TRUE(handleChangeListenerArr->Get(2).IsUndefined()); + EXPECT_EQ(handleChangeListenerArr->Get(thread, 1).GetTaggedObject(), objValue.GetTaggedWeakRef()); + EXPECT_TRUE(handleChangeListenerArr->Get(thread, 2).IsUndefined()); } } // namespace panda::test diff --git a/ecmascript/interpreter/fast_runtime_stub-inl.h b/ecmascript/interpreter/fast_runtime_stub-inl.h index 15ca6c80b5..205ba2077d 100644 --- a/ecmascript/interpreter/fast_runtime_stub-inl.h +++ b/ecmascript/interpreter/fast_runtime_stub-inl.h @@ -120,7 +120,7 @@ JSTaggedValue FastRuntimeStub::FastEqual(JSTaggedValue left, JSTaggedValue right return JSTaggedValue::Hole(); } -JSTaggedValue FastRuntimeStub::FastStrictEqual(JSTaggedValue left, JSTaggedValue right) +JSTaggedValue FastRuntimeStub::FastStrictEqual(JSThread *thread, JSTaggedValue left, JSTaggedValue right) { if (left.IsNumber()) { if (right.IsNumber()) { @@ -139,8 +139,9 @@ JSTaggedValue FastRuntimeStub::FastStrictEqual(JSTaggedValue left, JSTaggedValue if (left.IsString() && right.IsString()) { auto leftStr = static_cast(left.GetTaggedObject()); auto rightStr = static_cast(right.GetTaggedObject()); - if (EcmaStringAccessor(leftStr).IsFlat() && EcmaStringAccessor(rightStr).IsFlat()) { - return EcmaStringAccessor::StringsAreEqual(static_cast(left.GetTaggedObject()), + if (EcmaStringAccessor(leftStr).IsFlat(thread) && EcmaStringAccessor(rightStr).IsFlat(thread)) { + return EcmaStringAccessor::StringsAreEqual(thread, + static_cast(left.GetTaggedObject()), static_cast(right.GetTaggedObject())) ? JSTaggedValue::True() : JSTaggedValue::False(); } @@ -215,11 +216,11 @@ JSTaggedValue FastRuntimeStub::SetPropertyByValue(JSThread *thread, JSTaggedValu JSTaggedValue FastRuntimeStub::GetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) { JSObject *obj = JSObject::Cast(receiver); - TaggedArray *properties = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); GlobalDictionary *dict = GlobalDictionary::Cast(properties); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { - auto value = dict->GetValue(entry); + auto value = dict->GetValue(thread, entry); if (UNLIKELY(value.IsAccessor())) { return CallGetter(thread, receiver, receiver, value); } @@ -278,7 +279,7 @@ JSTaggedValue FastRuntimeStub::NewLexicalEnv(JSThread *thread, ObjectFactory *fa JSTaggedValue currentEnv = thread->GetCurrentLexenv(); // currentEnv is LexicalEnv/GlobalEnv for normal function, and is SFunctionEnv/Undefined for SharedFunction. if LIKELY(currentEnv.IsHeapObject()) { - newEnv->SetGlobalEnv(thread, BaseEnv::Cast(currentEnv.GetTaggedObject())->GetGlobalEnv()); + newEnv->SetGlobalEnv(thread, BaseEnv::Cast(currentEnv.GetTaggedObject())->GetGlobalEnv(thread)); } newEnv->SetParentEnv(thread, currentEnv); return JSTaggedValue(newEnv); @@ -295,11 +296,11 @@ JSTaggedValue FastRuntimeStub::NewThisObject(JSThread *thread, JSTaggedValue cto JSHandle obj = factory->NewJSObjectByConstructor(ctorHandle, newTargetHandle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - Method *method = Method::Cast(ctorHandle->GetMethod().GetTaggedObject()); + Method *method = Method::Cast(ctorHandle->GetMethod(thread).GetTaggedObject()); state->function = ctorHandle.GetTaggedValue(); - state->constpool = method->GetConstantPool(); - state->profileTypeInfo = ctorHandle->GetProfileTypeInfo(); - state->env = ctorHandle->GetLexicalEnv(); + state->constpool = method->GetConstantPool(thread); + state->profileTypeInfo = ctorHandle->GetProfileTypeInfo(thread); + state->env = ctorHandle->GetLexicalEnv(thread); return obj.GetTaggedValue(); } diff --git a/ecmascript/interpreter/fast_runtime_stub.h b/ecmascript/interpreter/fast_runtime_stub.h index ea6c768111..754b765fe2 100644 --- a/ecmascript/interpreter/fast_runtime_stub.h +++ b/ecmascript/interpreter/fast_runtime_stub.h @@ -33,7 +33,7 @@ public: static inline JSTaggedValue FastMod(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue FastEqual(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue FastTypeOf(JSThread *thread, JSTaggedValue obj); - static inline JSTaggedValue FastStrictEqual(JSTaggedValue left, JSTaggedValue right); + static inline JSTaggedValue FastStrictEqual(JSThread *thread, JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue NewLexicalEnv(JSThread *thread, ObjectFactory *factory, uint16_t numVars); static inline JSTaggedValue GetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); template diff --git a/ecmascript/interpreter/frame_handler.cpp b/ecmascript/interpreter/frame_handler.cpp index ddb95246c1..0025a658e1 100644 --- a/ecmascript/interpreter/frame_handler.cpp +++ b/ecmascript/interpreter/frame_handler.cpp @@ -20,7 +20,7 @@ #include "ecmascript/stubs/runtime_stubs-inl.h" namespace panda::ecmascript { -FrameHandler::FrameHandler(const JSThread *thread) +FrameHandler::FrameHandler(JSThread *thread) : sp_(const_cast(thread->GetCurrentFrame())), thread_(thread) { AdvanceToJSFrame(); @@ -146,7 +146,7 @@ uint32_t FrameHandler::GetBytecodeOffset() const reinterpret_cast(curNativePc); JSHandle funcVal = JSHandle(thread_, GetFunction()); JSHandle func = JSHandle::Cast(funcVal); - uint32_t curBytecodePcOfst = RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(func, curNativePc); + uint32_t curBytecodePcOfst = RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(thread_, func, curNativePc); return curBytecodePcOfst; } } @@ -155,13 +155,13 @@ Method *FrameHandler::GetMethod() const { ASSERT(IsJSFrame()); auto function = GetFunction(); - return ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(); + return ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(thread_); } const JSPandaFile* FrameHandler::GetJSPandaFile() const { auto method = GetMethod(); - return method->GetJSPandaFile(); + return method->GetJSPandaFile(thread_); } std::string FrameHandler::GetFileName() const @@ -192,7 +192,7 @@ Method *FrameHandler::CheckAndGetMethod() const ASSERT(IsJSFrame()); auto function = GetFunction(); if (function.IsJSFunctionBase() || function.IsJSProxy()) { - return ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(); + return ECMAObject::Cast(function.GetTaggedObject())->GetCallTarget(thread_); } return nullptr; } @@ -288,7 +288,7 @@ ConstantPool *FrameHandler::GetConstpool() const { ASSERT(IsInterpretedFrame()); auto method = GetMethod(); - JSTaggedValue constpool = method->GetConstantPool(); + JSTaggedValue constpool = method->GetConstantPool(thread_); return ConstantPool::Cast(constpool.GetTaggedObject()); } @@ -311,7 +311,7 @@ void FrameHandler::DumpStack(std::ostream &os) const FrameHandler frameHandler(thread_); for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) { os << "[" << i++ - << "]:" << frameHandler.GetMethod()->ParseFunctionName() + << "]:" << frameHandler.GetMethod()->ParseFunctionName(thread_) << "\n"; } } diff --git a/ecmascript/interpreter/frame_handler.h b/ecmascript/interpreter/frame_handler.h index 729af57f78..6163b7fc87 100644 --- a/ecmascript/interpreter/frame_handler.h +++ b/ecmascript/interpreter/frame_handler.h @@ -33,7 +33,7 @@ namespace kungfu { class FrameHandler { public: - explicit FrameHandler(const JSThread *thread); + explicit FrameHandler(JSThread *thread); ~FrameHandler() = default; @@ -264,6 +264,11 @@ public: void IterateAssembleStack(RootVisitor &visitor); void IterateEcmaRuntimeCallInfo(RootVisitor &visitor); + JSThread *GetJSThread() const + { + return thread_; + } + private: FrameType GetFrameType() const { @@ -279,7 +284,7 @@ private: JSTaggedType *sp_ {nullptr}; JSTaggedType *fp_ {nullptr}; uintptr_t baselineNativePc_ {0}; // For baselineJit upFrame - const JSThread *thread_ {nullptr}; + JSThread *thread_ {nullptr}; const kungfu::ArkStackMapParser *arkStackMapParser_ {nullptr}; }; diff --git a/ecmascript/interpreter/interpreter-inl.cpp b/ecmascript/interpreter/interpreter-inl.cpp index 2168780613..70642e271a 100644 --- a/ecmascript/interpreter/interpreter-inl.cpp +++ b/ecmascript/interpreter/interpreter-inl.cpp @@ -251,7 +251,7 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; INTERPRETER_GOTO_EXCEPTION_HANDLER(); \ } \ funcObject = ECMAObject::Cast(funcValue.GetTaggedObject()); \ - methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget())); \ + methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget(thread))); \ newSp = sp - InterpretedFrame::NumOfMembers(); \ } while (false) @@ -277,7 +277,7 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; INTERPRETER_GOTO_EXCEPTION_HANDLER(); \ } \ funcObject = ECMAObject::Cast(funcValue.GetTaggedObject()); \ - methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget())); \ + methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget(thread))); \ newSp = sp - InterpretedFrame::NumOfMembers(); \ } while (false) @@ -620,7 +620,7 @@ JSTaggedValue EcmaInterpreter::ExecuteNative(EcmaRuntimeCallInfo *info) thread->SetCurrentSPFrame(newSp); thread->CheckSafepoint(); ECMAObject *callTarget = reinterpret_cast(info->GetFunctionValue().GetTaggedObject()); - void *nativePointer = callTarget->GetNativePointer(); + void *nativePointer = callTarget->GetNativePointer(thread); LOG_INST() << "Entry: Runtime Call."; JSTaggedValue tagged; { @@ -662,7 +662,7 @@ JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) JSHandle func = info->GetFunction(); ECMAObject *callTarget = reinterpret_cast(func.GetTaggedValue().GetTaggedObject()); ASSERT(callTarget != nullptr); - Method *method = callTarget->GetCallTarget(); + Method *method = callTarget->GetCallTarget(thread); if (method->IsNativeWithCallField()) { return EcmaInterpreter::ExecuteNative(info); } @@ -738,12 +738,12 @@ JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) state->thisObj = info->GetThisValue(); state->acc = JSTaggedValue::Hole(); - state->constpool = method->GetConstantPool(); + state->constpool = method->GetConstantPool(thread); JSHandle thisFunc = JSHandle::Cast(func); - state->profileTypeInfo = thisFunc->GetProfileTypeInfo(); + state->profileTypeInfo = thisFunc->GetProfileTypeInfo(thread); state->base.prev = sp; state->base.type = FrameType::INTERPRETER_FRAME; - state->env = thisFunc->GetLexicalEnv(); + state->env = thisFunc->GetLexicalEnv(thread); thread->SetCurrentSPFrame(newSp); thread->CheckSafepoint(); LOG_INST() << "Entry: Runtime Call " << std::hex << reinterpret_cast(newSp) << " " @@ -780,7 +780,8 @@ 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())); + JSHandle func = + JSHandle::Cast(JSHandle(thread, context->GetMethod(thread))); if (func->IsCompiledCode()) { return GeneratorReEnterAot(thread, context); } @@ -813,25 +814,26 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) { return JSTaggedValue::Exception(); } - JSHandle regsArray(thread, context->GetRegsArray()); + JSHandle regsArray(thread, context->GetRegsArray(thread)); for (size_t i = 0; i < nregs; i++) { - newSp[i] = regsArray->Get(i).GetRawData(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + newSp[i] = regsArray->Get(thread, i).GetRawData(); } uint32_t pcOffset = context->GetBCOffset(); - Method *method = func->GetCallTarget(); + Method *method = func->GetCallTarget(thread); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) const uint8_t *resumePc = method->GetBytecodeArray() + pcOffset; InterpretedFrame *state = GET_FRAME(newSp); state->pc = resumePc; state->function = func.GetTaggedValue(); - state->thisObj = context->GetThis(); - state->constpool = method->GetConstantPool(); - state->profileTypeInfo = func->GetProfileTypeInfo(); - state->acc = context->GetAcc(); + state->thisObj = context->GetThis(thread); + state->constpool = method->GetConstantPool(thread); + state->profileTypeInfo = func->GetProfileTypeInfo(thread); + state->acc = context->GetAcc(thread); state->base.prev = breakSp; state->base.type = FrameType::INTERPRETER_FRAME; - JSTaggedValue env = context->GetLexicalEnv(); + JSTaggedValue env = context->GetLexicalEnv(thread); state->env = env; // execute interpreter thread->SetCurrentSPFrame(newSp); @@ -850,7 +852,8 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH JSTaggedValue EcmaInterpreter::GeneratorReEnterAot(JSThread *thread, JSHandle context) { - JSHandle func = JSHandle::Cast(JSHandle(thread, context->GetMethod())); + JSHandle func = + JSHandle::Cast(JSHandle(thread, context->GetMethod(thread))); if (func->IsClassConstructor()) { { EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -862,13 +865,13 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterAot(JSThread *thread, JSHandleGetException(); } - Method *method = func->GetCallTarget(); - JSTaggedValue genObject = context->GetGeneratorObject(); + Method *method = func->GetCallTarget(thread); + JSTaggedValue genObject = context->GetGeneratorObject(thread); std::vector args(method->GetNumArgs() + NUM_MANDATORY_JSFUNC_ARGS, JSTaggedValue::Undefined().GetRawData()); args[0] = func.GetTaggedValue().GetRawData(); args[1] = genObject.GetRawData(); - args[2] = context->GetThis().GetRawData(); // 2: this + args[2] = context->GetThis(thread).GetRawData(); // 2: this const JSTaggedType *prevFp = thread->GetLastLeaveFrame(); #if ECMASCRIPT_ENABLE_FUNCTION_CALL_TIMER RuntimeStubs::StartCallTimer(thread->GetGlueAddr(), func.GetTaggedType(), true); @@ -964,7 +967,7 @@ const JSPandaFile *EcmaInterpreter::GetNativeCallPandafile(JSThread *thread) if (method->IsNativeWithCallField()) { continue; } - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); return jsPandaFile; } LOG_ECMA(FATAL) << "this branch is unreachable"; @@ -987,14 +990,14 @@ std::pair EcmaInterpreter::GetCurrentEntryPoint(JSThread *thre continue; } JSTaggedValue func = frameHandler.GetFunction(); - JSHandle module(thread, JSFunction::Cast(func.GetTaggedObject())->GetModule()); + JSHandle module(thread, JSFunction::Cast(func.GetTaggedObject())->GetModule(thread)); if (module->IsSourceTextModule()) { SourceTextModule *sourceTextModule = SourceTextModule::Cast(module->GetTaggedObject()); recordName = sourceTextModule->GetEcmaModuleRecordNameString(); fileName = sourceTextModule->GetEcmaModuleFilenameString(); } else if (module->IsString()) { - recordName = ConvertToString(module.GetTaggedValue()); + recordName = ConvertToString(thread, module.GetTaggedValue()); } else { continue; } @@ -1009,7 +1012,7 @@ void EcmaInterpreter::UpdateProfileTypeInfoCellToFunction(JSThread *thread, JSHa { if (!profileTypeInfo.IsUndefined()) { JSHandle profileTypeArray(thread, profileTypeInfo); - JSTaggedValue slotValue = profileTypeArray->Get(slotId); + JSTaggedValue slotValue = profileTypeArray->Get(thread, slotId); if (slotValue.IsUndefined()) { JSHandle handleUndefined(thread, JSTaggedValue::Undefined()); JSHandle newProfileTypeInfoCell = @@ -1419,7 +1422,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t thread->SetCurrentSPFrame(newSp); LOG_INST() << "Entry: Runtime Call."; SAVE_PC(); - void *nativePointer = funcObject->GetNativePointer(); + void *nativePointer = funcObject->GetNativePointer(thread); JSTaggedValue retValue = reinterpret_cast(nativePointer)(ecmaRuntimeCallInfo); thread->SetCurrentSPFrame(sp); HANDLE_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1476,9 +1479,9 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t state->function = JSTaggedValue(funcTagged); state->thisObj = JSTaggedValue(thisObj); state->acc = JSTaggedValue::Hole(); - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = func->GetProfileTypeInfo(); - JSTaggedValue env = func->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = func->GetProfileTypeInfo(thread); + JSTaggedValue env = func->GetLexicalEnv(thread); state->env = env; thread->SetCurrentSPFrame(newSp); LOG_INST() << "Entry: Runtime Call " << std::hex << reinterpret_cast(sp) << " " @@ -1526,7 +1529,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); - methodHandle.Update(JSFunction::Cast(state->function.GetTaggedObject())->GetMethod()); + methodHandle.Update(JSFunction::Cast(state->function.GetTaggedObject())->GetMethod(thread)); [[maybe_unused]] auto fistPC = methodHandle->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); @@ -1547,7 +1550,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t INTERPRETER_HANDLE_RETURN(); } - if (func->IsBase()) { + if (func->IsBase(thread)) { JSTaggedValue thisObject = GetThis(currentSp); SET_ACC(thisObject); INTERPRETER_HANDLE_RETURN(); @@ -1575,7 +1578,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); - methodHandle.Update(JSFunction::Cast(state->function.GetTaggedObject())->GetMethod()); + methodHandle.Update(JSFunction::Cast(state->function.GetTaggedObject())->GetMethod(thread)); [[maybe_unused]] auto fistPC = methodHandle->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER_NON_ACC(-(pc - fistPC)); @@ -1592,7 +1595,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t thread->SetCurrentSPFrame(sp); if (IsFastNewFrameExit(currentSp)) { JSFunction *func = JSFunction::Cast(GetFunction(currentSp).GetTaggedObject()); - if (func->IsBase()) { + if (func->IsBase(thread)) { JSTaggedValue thisObject = GetThis(currentSp); SET_ACC(thisObject); INTERPRETER_HANDLE_RETURN(); @@ -1660,7 +1663,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::getunmappedargs"; uint32_t startIdx = 0; - uint32_t actualNumArgs = GetNumArgs(sp, 0, startIdx); + uint32_t actualNumArgs = GetNumArgs(thread, sp, 0, startIdx); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::GetUnmapedArgs(thread, sp, actualNumArgs, startIdx); @@ -2230,11 +2233,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue instOfHandler = JSTaggedValue::Hole(); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); instOfHandler = ICRuntimeStub::TryLoadICByName(thread, target, firstValue, secondValue); } if (LIKELY(!instOfHandler.IsHole())) { @@ -2272,7 +2275,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " v" << v0; JSTaggedValue left = GET_VREG_VALUE(v0); JSTaggedValue right = GET_ACC(); - JSTaggedValue res = FastRuntimeStub::FastStrictEqual(left, right); + JSTaggedValue res = FastRuntimeStub::FastStrictEqual(thread, left, right); if (!res.IsHole()) { res = res.IsTrue() ? JSTaggedValue::False() : JSTaggedValue::True(); SET_ACC(res); @@ -2291,7 +2294,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " v" << v0; JSTaggedValue left = GET_VREG_VALUE(v0); JSTaggedValue right = GET_ACC(); - JSTaggedValue res = FastRuntimeStub::FastStrictEqual(left, right); + JSTaggedValue res = FastRuntimeStub::FastStrictEqual(thread, left, right); if (!res.IsHole()) { SET_ACC(res); } else { @@ -2442,7 +2445,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue pattern = GET_STR_FROM_CACHE(stringId); uint8_t flags = READ_INST_8_3(); LOG_INST() << "intrinsics::createregexpwithliteral " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(pattern.GetTaggedObject())) + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(pattern.GetTaggedObject())) << ", flags:" << flags; JSTaggedValue res = SlowRuntimeStub::CreateRegExpWithLiteral(thread, pattern, flags); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -2456,7 +2460,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue pattern = GET_STR_FROM_CACHE(stringId); uint8_t flags = READ_INST_8_4(); LOG_INST() << "intrinsics::createregexpwithliteral " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(pattern.GetTaggedObject())) + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(pattern.GetTaggedObject())) << ", flags:" << flags; JSTaggedValue res = SlowRuntimeStub::CreateRegExpWithLiteral(thread, pattern, flags); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -2549,14 +2554,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v1); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -2612,14 +2617,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v1); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -2687,7 +2692,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t auto prop = GET_STR_FROM_CACHE(stringId); LOG_INST() << "intrinsics::tryldglobalbyname " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(prop.GetTaggedObject())); + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject())); #if ECMASCRIPT_ENABLE_IC auto profileTypeInfo = GetRuntimeProfileTypeInfo(sp); @@ -2706,7 +2712,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // order: 1. global record 2. global object JSTaggedValue result = SlowRuntimeStub::LdGlobalRecord(thread, prop); if (!result.IsUndefined()) { - SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue()); + SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread)); } else { JSTaggedValue globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, prop); if (!globalResult.IsHole()) { @@ -2728,7 +2734,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t auto prop = GET_STR_FROM_CACHE(stringId); LOG_INST() << "intrinsics::tryldglobalbyname " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(prop.GetTaggedObject())); + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject())); #if ECMASCRIPT_ENABLE_IC auto profileTypeInfo = GetRuntimeProfileTypeInfo(sp); @@ -2747,7 +2754,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // order: 1. global record 2. global object JSTaggedValue result = SlowRuntimeStub::LdGlobalRecord(thread, prop); if (!result.IsUndefined()) { - SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue()); + SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread)); } else { JSTaggedValue globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, prop); if (!globalResult.IsHole()) { @@ -2770,7 +2777,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::trystglobalbyname" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); #if ECMASCRIPT_ENABLE_IC auto profileTypeInfo = GetRuntimeProfileTypeInfo(sp); @@ -2930,14 +2938,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } if (LIKELY(!res.IsHole())) { @@ -3004,14 +3012,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } if (LIKELY(!res.IsHole())) { @@ -3081,7 +3089,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::stsuperbyname" << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData() << ", value:" << value.GetRawData(); // slow path @@ -3102,7 +3111,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue value = GET_ACC(); LOG_INST() << "intrinsics::stglobalvar " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(prop.GetTaggedObject())) + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject())) << ", value:" << value.GetRawData(); #if ECMASCRIPT_ENABLE_IC auto profileTypeInfo = GetRuntimeProfileTypeInfo(sp); @@ -3194,7 +3204,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SET_ACC(res); InterpretedFrame *state = GET_FRAME(sp); - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); LOG_INST() << "Exit: AsyncGeneratorResolve " << std::hex << reinterpret_cast(sp) << " " @@ -3247,7 +3257,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GetFunction(sp); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -3255,8 +3265,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -3302,10 +3312,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(SUPERCALLTHISRANGE_IMM8_IMM8_V8); } - if (IsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -3325,22 +3335,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -3383,7 +3393,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GetFunction(sp); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -3391,8 +3401,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -3438,10 +3448,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8); } - if (IsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -3461,22 +3471,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -3519,7 +3529,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GET_ACC(); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -3527,8 +3537,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -3574,10 +3584,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(SUPERCALLARROWRANGE_IMM8_IMM8_V8); } - if (IsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -3597,22 +3607,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -3655,7 +3665,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GET_ACC(); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -3663,8 +3673,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -3710,10 +3720,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8); } - if (IsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -3733,22 +3743,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -3790,7 +3800,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " array: v" << v0; JSTaggedValue thisFunc = GET_ACC(); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); JSTaggedValue array = GET_VREG_VALUE(v0); SAVE_PC(); @@ -3804,10 +3814,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsic::callruntime.supercallforwardallargs" << "thisFunc: v" << v0; JSTaggedValue thisFunc = GET_VREG_VALUE(v0); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); uint32_t restIdx = 0; uint32_t startIdx = 0; - uint32_t restNumArgs = GetNumArgs(sp, restIdx, startIdx); + uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::SuperCallForwardAllArgs(thread, sp, thisFunc, newTarget, restNumArgs, @@ -3836,7 +3846,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::ldhomeobject"; JSTaggedValue thisFunc = GetFunction(sp); - JSTaggedValue homeObject = JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(); + JSTaggedValue homeObject = JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(thread); SET_ACC(homeObject); DISPATCH(DEPRECATED_LDHOMEOBJECT_PREF_NONE); @@ -3890,7 +3900,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t return; } auto method = frameHandler.GetMethod(); - pcOffset = method->FindCatchBlock(frameHandler.GetBytecodeOffset()); + pcOffset = method->FindCatchBlock(thread, frameHandler.GetBytecodeOffset()); if (pcOffset != INVALID_INDEX) { sp = frameHandler.GetSp(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -4067,8 +4077,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); - methodHandle.Update(ctorFunc->GetMethod()); - if (ctorFunc->IsBuiltinConstructor()) { + methodHandle.Update(ctorFunc->GetMethod(thread)); + if (ctorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4; // 2: numArgs & thread // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -4115,10 +4125,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(NEWOBJRANGE_IMM8_IMM8_V8); } - if (IsFastNewFrameEnter(ctorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, ctorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = ctorFunc->IsBase() ? + uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -4138,22 +4148,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (ctorFunc->IsBase()) { + if (ctorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(ctorFunc->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor(thread)); newSp[index++] = ctor.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = ctor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(); - state->env = ctorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread); + state->env = ctorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -4202,8 +4212,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); - methodHandle.Update(ctorFunc->GetMethod()); - if (ctorFunc->IsBuiltinConstructor()) { + methodHandle.Update(ctorFunc->GetMethod(thread)); + if (ctorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4; // 4: newtarget/this & numArgs & thread @@ -4251,10 +4261,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(NEWOBJRANGE_IMM16_IMM8_V8); } - if (IsFastNewFrameEnter(ctorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, ctorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = ctorFunc->IsBase() ? + uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -4274,22 +4284,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (ctorFunc->IsBase()) { + if (ctorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(ctorFunc->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor(thread)); newSp[index++] = ctor.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = ctor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(); - state->env = ctorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread); + state->env = ctorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -4338,8 +4348,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); - methodHandle.Update(ctorFunc->GetMethod()); - if (ctorFunc->IsBuiltinConstructor()) { + methodHandle.Update(ctorFunc->GetMethod(thread)); + if (ctorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4; // 3: this & numArgs & thread // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -4386,10 +4396,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t DISPATCH(WIDE_NEWOBJRANGE_PREF_IMM16_V8); } - if (IsFastNewFrameEnter(ctorFunc, methodHandle)) { + if (IsFastNewFrameEnter(thread, ctorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = ctorFunc->IsBase() ? + uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -4409,22 +4419,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t // this JSTaggedValue thisObj; - if (ctorFunc->IsBase()) { + if (ctorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(ctorFunc->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor(thread)); newSp[index++] = ctor.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = ctor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(); - state->env = ctorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread); + state->env = ctorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -4534,14 +4544,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t HANDLE_OPCODE(POPLEXENV) { InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue currentLexenv = state->env; - JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(); + JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(thread); GET_FRAME(sp)->env = parentLexenv; DISPATCH(POPLEXENV); } HANDLE_OPCODE(DEPRECATED_POPLEXENV_PREF_NONE) { InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue currentLexenv = state->env; - JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(); + JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(thread); GET_FRAME(sp)->env = parentLexenv; DISPATCH(DEPRECATED_POPLEXENV_PREF_NONE); } @@ -4637,7 +4647,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " imm:" << imm; auto constpool = GetUnsharedConstpool(thread, sp); JSArray *result = JSArray::Cast(GET_LITERA_FROM_CACHE(imm, ConstPoolType::ARRAY_LITERAL, - GetEcmaModule(sp)).GetTaggedObject()); + GetEcmaModule(thread, sp)).GetTaggedObject()); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CreateArrayWithBuffer(thread, factory, result); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -4650,7 +4660,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " imm:" << imm; auto constpool = GetUnsharedConstpool(thread, sp); JSArray *result = JSArray::Cast(GET_LITERA_FROM_CACHE(imm, ConstPoolType::ARRAY_LITERAL, - GetEcmaModule(sp)).GetTaggedObject()); + GetEcmaModule(thread, sp)).GetTaggedObject()); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CreateArrayWithBuffer(thread, factory, result); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -4675,7 +4685,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " imm:" << imm; auto constpool = GetUnsharedConstpool(thread, sp); JSObject *result = JSObject::Cast(GET_LITERA_FROM_CACHE(imm, ConstPoolType::OBJECT_LITERAL, - GetEcmaModule(sp)).GetTaggedObject()); + GetEcmaModule(thread, sp)).GetTaggedObject()); SAVE_PC(); InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue res = SlowRuntimeStub::CreateObjectHavingMethod(thread, factory, result, state->env); @@ -4689,7 +4699,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " imm:" << imm; auto constpool = GetUnsharedConstpool(thread, sp); JSObject *result = JSObject::Cast(GET_LITERA_FROM_CACHE(imm, ConstPoolType::OBJECT_LITERAL, - GetEcmaModule(sp)).GetTaggedObject()); + GetEcmaModule(thread, sp)).GetTaggedObject()); SAVE_PC(); InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue res = SlowRuntimeStub::CreateObjectHavingMethod(thread, factory, result, state->env); @@ -4973,8 +4983,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue envHandle = state->env; JSFunction *currentFunc = JSFunction::Cast((GET_FRAME(sp)->function).GetTaggedObject()); - auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, currentFunc->GetModule(), - length, envHandle, currentFunc->GetHomeObject()); + auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, currentFunc->GetModule(thread), + length, envHandle, currentFunc->GetHomeObject(thread)); { [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle jsFunc(thread, res); @@ -4999,8 +5009,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue envHandle = state->env; JSFunction *currentFunc = JSFunction::Cast((GET_FRAME(sp)->function).GetTaggedObject()); - auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, currentFunc->GetModule(), - length, envHandle, currentFunc->GetHomeObject()); + auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, currentFunc->GetModule(thread), + length, envHandle, currentFunc->GetHomeObject(thread)); { [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle jsFunc(thread, res); @@ -5030,7 +5040,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue taggedCurEnv = state->env; - auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetEcmaModule(sp)); + auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetEcmaModule(thread, sp)); INTERPRETER_RETURN_IF_ABRUPT(res); JSFunction *result = JSFunction::Cast(res.GetTaggedObject()); SET_ACC(JSTaggedValue(result)); @@ -5052,7 +5062,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue taggedCurEnv = state->env; - auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetEcmaModule(sp)); + auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetEcmaModule(thread, sp)); INTERPRETER_RETURN_IF_ABRUPT(res); JSFunction *result = JSFunction::Cast(res.GetTaggedObject()); SET_ACC(JSTaggedValue(result)); @@ -5073,7 +5083,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue res = SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(sp), - methodId, literaId, GetEcmaModule(sp), JSTaggedValue(length)); + methodId, literaId, GetEcmaModule(thread, sp), JSTaggedValue(length)); INTERPRETER_RETURN_IF_ABRUPT(res); ASSERT(res.IsClassConstructor()); @@ -5095,7 +5105,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(sp), - methodId, literaId, GetEcmaModule(sp), JSTaggedValue(length)); + methodId, literaId, GetEcmaModule(thread, sp), JSTaggedValue(length)); INTERPRETER_RETURN_IF_ABRUPT(res); ASSERT(res.IsClassConstructor()); @@ -5117,7 +5127,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CreateClassWithBuffer(thread, proto, lexenv, GetConstantPool(sp), - methodId, methodId + 1, GetEcmaModule(sp), + methodId, methodId + 1, GetEcmaModule(thread, sp), JSTaggedValue(length)); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -5132,13 +5142,13 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (objVal.IsAsyncGeneratorObject()) { JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } else { JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject()); uintptr_t taskInfo = obj->GetTaskInfo(); thread->SetTaskInfo(taskInfo); obj->SetTaskInfo(reinterpret_cast(nullptr)); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } DISPATCH(RESUMEGENERATOR); } @@ -5148,10 +5158,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue objVal = GET_VREG_VALUE(vs); if (objVal.IsAsyncGeneratorObject()) { JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } else { JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } DISPATCH(DEPRECATED_RESUMEGENERATOR_PREF_V8); } @@ -5257,7 +5267,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SET_ACC(res); InterpretedFrame *state = GET_FRAME(sp); - methodHandle.Update(JSFunction::Cast(state->function.GetTaggedObject())->GetMethod()); + methodHandle.Update(JSFunction::Cast(state->function.GetTaggedObject())->GetMethod(thread)); [[maybe_unused]] auto fistPC = methodHandle->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " @@ -5291,7 +5301,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SET_ACC(res); InterpretedFrame *state = GET_FRAME(sp); - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " @@ -5423,11 +5433,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -5478,11 +5488,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -5791,11 +5801,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SAVE_ACC(); uint32_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, JSTaggedValue(index), firstValue, secondValue, value); } @@ -5848,11 +5858,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SAVE_ACC(); uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, JSTaggedValue(index), firstValue, secondValue, value); } @@ -5926,7 +5936,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " index: " << restIdx; uint32_t startIdx = 0; - uint32_t restNumArgs = GetNumArgs(sp, restIdx, startIdx); + uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, sp, restNumArgs, startIdx); @@ -5940,7 +5950,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " index: " << restIdx; uint32_t startIdx = 0; - uint32_t restNumArgs = GetNumArgs(sp, restIdx, startIdx); + uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, sp, restNumArgs, startIdx); @@ -5958,11 +5968,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue currentLexenv = state->env; JSTaggedValue env(currentLexenv); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(LDLEXVAR_IMM4_IMM4); } HANDLE_OPCODE(LDLEXVAR_IMM8_IMM8) { @@ -5975,11 +5985,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue currentLexenv = state->env; JSTaggedValue env(currentLexenv); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(LDLEXVAR_IMM8_IMM8); } HANDLE_OPCODE(WIDE_LDLEXVAR_PREF_IMM16_IMM16) { @@ -5992,11 +6002,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue currentLexenv = state->env; JSTaggedValue env(currentLexenv); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(WIDE_LDLEXVAR_PREF_IMM16_IMM16); } HANDLE_OPCODE(STLEXVAR_IMM4_IMM4) { @@ -6009,7 +6019,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6027,7 +6037,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6045,7 +6055,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6064,7 +6074,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6083,7 +6093,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6102,7 +6112,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t InterpretedFrame *state = GET_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6136,7 +6146,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t auto localName = GET_STR_FROM_CACHE(stringId); LOG_INST() << "intrinsics::getmodulenamespace " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(localName.GetTaggedObject())); + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(localName.GetTaggedObject())); JSTaggedValue moduleNamespace = SlowRuntimeStub::GetModuleNamespace(thread, localName); INTERPRETER_RETURN_IF_ABRUPT(moduleNamespace); @@ -6175,7 +6186,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t RESTORE_ACC(); LOG_INST() << "intrinsics::stmodulevar " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(key.GetTaggedObject())); + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(key.GetTaggedObject())); JSTaggedValue value = GET_ACC(); @@ -6228,7 +6240,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stconsttoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -6244,7 +6257,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stconsttoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -6260,7 +6274,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stlettoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -6276,7 +6291,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stlettoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -6292,7 +6308,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stclasstoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -6309,7 +6326,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue key = GET_STR_FROM_CACHE(stringId); LOG_INST() << "intrinsics::ldmodulevar " << "string_id:" << stringId << ", " - << "key: " << ConvertToString(EcmaString::Cast(key.GetTaggedObject())); + << "key: " << ConvertToString(thread, EcmaString::Cast(key.GetTaggedObject())); JSTaggedValue moduleVar = SlowRuntimeStub::LdModuleVar(thread, key, innerFlag != 0); INTERPRETER_RETURN_IF_ABRUPT(moduleVar); @@ -6322,12 +6339,12 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -6359,7 +6376,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t RESTORE_ACC(); JSTaggedValue receiver = GET_ACC(); LOG_INST() << "intrinsics::ldobjbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path JSTaggedValue res = FastRuntimeStub::GetPropertyByName(thread, receiver, propKey); @@ -6384,12 +6402,12 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -6421,7 +6439,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t RESTORE_ACC(); JSTaggedValue receiver = GET_ACC(); LOG_INST() << "intrinsics::ldobjbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -6450,7 +6469,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue receiver = GET_VREG_VALUE(v0); LOG_INST() << "intrinsics::ldobjbyname " << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -6479,7 +6499,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue obj = GET_ACC(); LOG_INST() << "intrinsics::ldsuperbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData(); SAVE_PC(); JSTaggedValue thisFunc = GetFunction(sp); @@ -6498,7 +6519,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue obj = GET_ACC(); LOG_INST() << "intrinsics::ldsuperbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData(); SAVE_PC(); JSTaggedValue thisFunc = GetFunction(sp); @@ -6517,7 +6539,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::ldsuperbyname" << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData(); SAVE_PC(); JSTaggedValue thisFunc = GetFunction(sp); @@ -6657,7 +6680,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::trystglobalbyname" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); #if ECMASCRIPT_ENABLE_IC auto profileTypeInfo = GetRuntimeProfileTypeInfo(sp); @@ -6714,7 +6738,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::stsuperbyname" << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData() << ", value:" << value.GetRawData(); // slow path @@ -6933,11 +6958,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -6986,11 +7011,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -7040,14 +7065,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -7102,14 +7127,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -7158,12 +7183,12 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GetThis(sp); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -7191,7 +7216,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); JSTaggedValue receiver = GetThis(sp); LOG_INST() << "intrinsics::ldthisbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -7216,12 +7242,12 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GetThis(sp); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -7249,7 +7275,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue propKey = GET_STR_FROM_CACHE(stringId); JSTaggedValue receiver = GetThis(sp); LOG_INST() << "intrinsics::ldthisbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -7274,14 +7301,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GetThis(sp); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } if (LIKELY(!res.IsHole())) { @@ -7346,14 +7373,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GetThis(sp); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } if (LIKELY(!res.IsHole())) { @@ -7473,7 +7500,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue obj = GET_VREG_VALUE(v0); LOG_INST() << "intrinsics::callruntime.definefieldbyname " << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData() << ", value:" << value.GetRawData(); JSTaggedValue res = SlowRuntimeStub::DefineField(thread, obj, propKey, value); @@ -7493,7 +7521,8 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue obj = GET_VREG_VALUE(v0); LOG_INST() << "intrinsics::callruntime.definepropertybyname " << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << obj.GetRawData() << ", value:" << value.GetRawData(); JSTaggedValue res = SlowRuntimeStub::DefineField(thread, obj, propKey, value); @@ -7548,7 +7577,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t HANDLE_OPCODE(CALLRUNTIME_CREATEPRIVATEPROPERTY_PREF_IMM16_ID16) { JSTaggedValue lexicalEnv = GET_FRAME(sp)->env; JSTaggedValue constpool = GetConstantPool(sp); - JSTaggedValue module = GetEcmaModule(sp); + JSTaggedValue module = GetEcmaModule(thread, sp); uint32_t count = READ_INST_16_1(); uint32_t literalId = READ_INST_16_3(); LOG_INST() << "intrinsics::callruntime.createprivateproperty " @@ -7594,7 +7623,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CreateSharedClass(thread, base, GetConstantPool(sp), methodId, - literaId, length, GetEcmaModule(sp)); + literaId, length, GetEcmaModule(thread, sp)); INTERPRETER_RETURN_IF_ABRUPT(res); ASSERT(res.IsClassConstructor()); @@ -7660,7 +7689,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue res = SlowRuntimeStub::NewSendableEnv(thread, numVars); INTERPRETER_RETURN_IF_ABRUPT(res); SET_ACC(res); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); moduleRecord->SetSendableEnv(thread, res); DISPATCH(CALLRUNTIME_NEWSENDABLEENV_PREF_IMM8); } @@ -7673,7 +7702,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t JSTaggedValue res = SlowRuntimeStub::NewSendableEnv(thread, numVars); INTERPRETER_RETURN_IF_ABRUPT(res); SET_ACC(res); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); moduleRecord->SetSendableEnv(thread, res); DISPATCH(CALLRUNTIME_WIDENEWSENDABLEENV_PREF_IMM16); } @@ -7684,10 +7713,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " level:" << level << " slot:" << slot; JSTaggedValue value = GET_ACC(); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -7702,10 +7731,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " level:" << level << " slot:" << slot; JSTaggedValue value = GET_ACC(); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -7720,10 +7749,10 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t << " level:" << level << " slot:" << slot; JSTaggedValue value = GET_ACC(); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -7737,14 +7766,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::ldsendablevar4" << " level:" << level << " slot:" << slot; - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM4_IMM4); } HANDLE_OPCODE(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM8_IMM8) { @@ -7753,14 +7782,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::ldsendablevar8" << " level:" << level << " slot:" << slot; - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM8_IMM8); } HANDLE_OPCODE(CALLRUNTIME_WIDELDSENDABLEVAR_PREF_IMM16_IMM16) { @@ -7769,14 +7798,14 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, const uint8_t LOG_INST() << "intrinsics::ldsendablevar16" << " level:" << level << " slot:" << slot; - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetEcmaModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(CALLRUNTIME_WIDELDSENDABLEVAR_PREF_IMM16_IMM16); } HANDLE_OPCODE(CALLRUNTIME_LDLAZYMODULEVAR_PREF_IMM8) { @@ -7858,22 +7887,22 @@ JSTaggedValue EcmaInterpreter::GetThis(JSTaggedType *sp) return state->thisObj; } -JSTaggedValue EcmaInterpreter::GetNewTarget(JSTaggedType *sp) +JSTaggedValue EcmaInterpreter::GetNewTarget(JSThread *thread, JSTaggedType *sp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) InterpretedFrame *state = reinterpret_cast(sp) - 1; - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); ASSERT(method->HaveNewTargetWithCallField()); uint32_t numVregs = method->GetNumVregsWithCallField(); bool haveFunc = method->HaveFuncWithCallField(); return JSTaggedValue(sp[numVregs + haveFunc]); } -uint32_t EcmaInterpreter::GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx) +uint32_t EcmaInterpreter::GetNumArgs(JSThread *thread, JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) InterpretedFrame *state = reinterpret_cast(sp) - 1; - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); ASSERT(method->HaveExtraWithCallField()); uint32_t numVregs = method->GetNumVregsWithCallField(); @@ -7915,11 +7944,11 @@ JSTaggedValue EcmaInterpreter::GetRuntimeProfileTypeInfo(JSTaggedType *sp) return state->profileTypeInfo; } -JSTaggedValue EcmaInterpreter::GetEcmaModule(JSTaggedType *sp) +JSTaggedValue EcmaInterpreter::GetEcmaModule(JSThread* thread, JSTaggedType *sp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSFunction *currentFunc = JSFunction::Cast((GET_FRAME(sp)->function).GetTaggedObject()); - return currentFunc->GetModule(); + return currentFunc->GetModule(thread); } JSTaggedValue EcmaInterpreter::GetConstantPool(JSTaggedType *sp) @@ -7938,7 +7967,7 @@ JSTaggedValue EcmaInterpreter::GetUnsharedConstpool(JSThread* thread, JSTaggedTy bool EcmaInterpreter::UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp, JSTaggedValue acc, int32_t offset) { InterpretedFrame *state = GET_FRAME(sp); - auto method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + auto method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); auto hotnessCounter = method->GetHotnessCounter(); hotnessCounter += offset; @@ -7947,12 +7976,12 @@ bool EcmaInterpreter::UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp, J SAVE_ACC(); needRestoreAcc = thread->CheckSafepoint(); RESTORE_ACC(); - method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); if (state->profileTypeInfo.IsUndefined()) { state->acc = acc; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) auto thisFunc = JSFunction::Cast(state->function.GetTaggedObject()); - method = thisFunc->GetCallTarget(); // for CheckSafepoint, method need retrieve. + method = thisFunc->GetCallTarget(thread); // for CheckSafepoint, method need retrieve. method->SetHotnessCounter(EcmaInterpreter::METHOD_HOTNESS_THRESHOLD); auto res = SlowRuntimeStub::NotifyInlineCache(thread, thisFunc); state->profileTypeInfo = res; @@ -7966,17 +7995,17 @@ bool EcmaInterpreter::UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp, J return false; } -bool EcmaInterpreter::IsFastNewFrameEnter(JSFunction *ctor, JSHandle method) +bool EcmaInterpreter::IsFastNewFrameEnter(JSThread *thread, JSFunction *ctor, JSHandle method) { if (method->IsNativeWithCallField()) { return false; } - if (ctor->IsBase()) { + if (ctor->IsBase(thread)) { return method->OnlyHaveThisWithCallField(); } - if (ctor->IsDerivedConstructor()) { + if (ctor->IsDerivedConstructor(thread)) { return method->OnlyHaveNewTagetAndThisWithCallField(); } diff --git a/ecmascript/interpreter/interpreter-inl.h b/ecmascript/interpreter/interpreter-inl.h index c83749a245..d4a5108390 100644 --- a/ecmascript/interpreter/interpreter-inl.h +++ b/ecmascript/interpreter/interpreter-inl.h @@ -272,7 +272,7 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; INTERPRETER_GOTO_EXCEPTION_HANDLER(); \ } \ funcObject = ECMAObject::Cast(funcValue.GetTaggedObject()); \ - methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget())); \ + methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget(thread))); \ newSp = sp - InterpretedFrame::NumOfMembers(); \ } while (false) @@ -298,7 +298,7 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; INTERPRETER_GOTO_EXCEPTION_HANDLER(); \ } \ funcObject = ECMAObject::Cast(funcValue.GetTaggedObject()); \ - methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget())); \ + methodHandle.Update(JSTaggedValue(funcObject->GetCallTarget(thread))); \ newSp = sp - InterpretedFrame::NumOfMembers(); \ } while (false) diff --git a/ecmascript/interpreter/interpreter.h b/ecmascript/interpreter/interpreter.h index de79ea1c5d..697ab00aaa 100644 --- a/ecmascript/interpreter/interpreter.h +++ b/ecmascript/interpreter/interpreter.h @@ -62,7 +62,7 @@ public: static JSTaggedValue GetRuntimeProfileTypeInfo(JSTaggedType *sp); static JSTaggedValue GetConstantPool(JSTaggedType *sp); static JSTaggedValue GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp); - static JSTaggedValue GetEcmaModule(JSTaggedType *sp); + static JSTaggedValue GetEcmaModule(JSThread *thread, JSTaggedType *sp); static bool UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp, JSTaggedValue acc, int32_t offset); static void NotifyBytecodePcChanged(JSThread *thread); static void NotifyDebuggerStmt(JSThread *thread); @@ -71,10 +71,10 @@ public: static const JSPandaFile *GetNativeCallPandafile(JSThread *thread); static std::pair GetCurrentEntryPoint(JSThread *thread); static JSTaggedValue GetFunction(JSTaggedType *sp); - static JSTaggedValue GetNewTarget(JSTaggedType *sp); + static JSTaggedValue GetNewTarget(JSThread *thread, JSTaggedType *sp); static JSTaggedValue GetThis(JSTaggedType *sp); - static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); - static bool IsFastNewFrameEnter(JSFunction *ctor, JSHandle method); + static uint32_t GetNumArgs(JSThread *thread, JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); + static bool IsFastNewFrameEnter(JSThread *thread, JSFunction *ctor, JSHandle method); static bool IsFastNewFrameExit(JSTaggedType *sp); static int16_t GetHotnessCounter(uint32_t codeSize, bool cancelThreshold); static JSTaggedType *GetInterpreterFrameEnd(JSThread *thread, JSTaggedType *sp); diff --git a/ecmascript/interpreter/interpreter_assembly.cpp b/ecmascript/interpreter/interpreter_assembly.cpp index 77244f4ba6..4b1f0909b2 100644 --- a/ecmascript/interpreter/interpreter_assembly.cpp +++ b/ecmascript/interpreter/interpreter_assembly.cpp @@ -56,7 +56,7 @@ using panda::ecmascript::kungfu::CommonStubCSigns; SAVE_PC(); \ SAVE_ACC(); \ AsmInterpretedFrame *frame = GET_ASM_FRAME(sp); \ - auto currentMethod = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(); \ + auto currentMethod = ECMAObject::Cast(frame->function.GetTaggedObject())->GetCallTarget(thread); \ currentMethod->SetHotnessCounter(static_cast(hotnessCounter)); \ return; \ } while (false) @@ -89,7 +89,7 @@ using panda::ecmascript::kungfu::CommonStubCSigns; #define INTERPRETER_HANDLE_RETURN() \ do { \ JSFunction* prevFunc = JSFunction::Cast(prevState->function.GetTaggedObject()); \ - method = prevFunc->GetCallTarget(); \ + method = prevFunc->GetCallTarget(thread); \ hotnessCounter = static_cast(method->GetHotnessCounter()); \ ASSERT(prevState->callSize == GetJumpSizeAfterCall(pc)); \ DISPATCH_OFFSET(prevState->callSize); \ @@ -213,8 +213,8 @@ JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info) // In this case, the AotWithCall field may be updated. // This causes a Construct that is not a ClassConstructor to call jit code. ECMAObject *callTarget = reinterpret_cast(info->GetFunctionValue().GetTaggedObject()); - Method *method = callTarget->GetCallTarget(); - bool isCompiledCode = JSFunctionBase::IsCompiledCodeFromCallTarget(info->GetFunctionValue()); + Method *method = callTarget->GetCallTarget(thread); + bool isCompiledCode = JSFunctionBase::IsCompiledCodeFromCallTarget(thread, info->GetFunctionValue()); // check is or not debugger thread->CheckSwitchDebuggerBCStub(); @@ -224,7 +224,7 @@ JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info) auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_AsmInterpreterEntry); callTarget = reinterpret_cast(info->GetFunctionValue().GetTaggedObject()); - method = callTarget->GetCallTarget(); + method = callTarget->GetCallTarget(thread); if (isCompiledCode) { JSHandle func(thread, info->GetFunctionValue()); if (func->IsClassConstructor()) { @@ -255,13 +255,13 @@ JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info) #endif if (thread->IsDebugMode() && !method->IsNativeWithCallField()) { JSHandle func(thread, info->GetFunctionValue()); - JSTaggedValue env = func->GetLexicalEnv(); + JSTaggedValue env = func->GetLexicalEnv(thread); MethodEntry(thread, method, env); } #ifdef USE_READ_BARRIER if (thread->IsCMCGCConcurrentCopying()) { - base::GCHelper::CopyCallTarget(callTarget); // callTarget should be ToSpace Reference - method = callTarget->GetCallTarget(); + base::GCHelper::CopyCallTarget(thread, callTarget); // callTarget should be ToSpace Reference + method = callTarget->GetCallTarget(thread); } #endif auto acc = reinterpret_cast(entry)(thread->GetGlueAddr(), @@ -316,18 +316,18 @@ JSTaggedValue InterpreterAssembly::GeneratorReEnterInterpreter(JSThread *thread, // check is or not debugger thread->CheckSwitchDebuggerBCStub(); auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_GeneratorReEnterAsmInterp); - JSTaggedValue func = context->GetMethod(); - Method *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget(); - JSTaggedValue env = context->GetLexicalEnv(); + JSTaggedValue func = context->GetMethod(thread); + Method *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget(thread); + JSTaggedValue env = context->GetLexicalEnv(thread); if (thread->IsDebugMode() && !method->IsNativeWithCallField()) { MethodEntry(thread, method, env); } #ifdef USE_READ_BARRIER if (thread->IsCMCGCConcurrentCopying()) { // func should be ToSpace Reference - base::GCHelper::CopyCallTarget(func.GetTaggedObject()); + base::GCHelper::CopyCallTarget(thread, func.GetTaggedObject()); // context should be ToSpace Reference - base::GCHelper::CopyGeneratorContext(context.GetObject()); + base::GCHelper::CopyGeneratorContext(thread, context.GetObject()); } #endif auto acc = reinterpret_cast(entry)(thread->GetGlueAddr(), context.GetTaggedType()); @@ -376,7 +376,7 @@ void InterpreterAssembly::HandleLdaStrId16( { uint16_t stringId = READ_INST_16_0(); LOG_INST() << "lda.str " << std::hex << stringId; - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); SET_ACC(ConstantPool::GetStringFromCache(thread, constpool, stringId)); DISPATCH(LDA_STR_ID16); } @@ -556,7 +556,7 @@ void InterpreterAssembly::HandleReturn( AsmInterpretedFrame *state = GET_ASM_FRAME(sp); LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); - Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); method->SetHotnessCounter(static_cast(hotnessCounter)); @@ -584,7 +584,7 @@ void InterpreterAssembly::HandleReturnundefined( AsmInterpretedFrame *state = GET_ASM_FRAME(sp); LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); - Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); method->SetHotnessCounter(static_cast(hotnessCounter)); @@ -689,7 +689,7 @@ void InterpreterAssembly::HandleGetunmappedargs( LOG_INST() << "intrinsics::getunmappedargs"; uint32_t startIdx = 0; - uint32_t actualNumArgs = GetNumArgs(sp, 0, startIdx); + uint32_t actualNumArgs = GetNumArgs(thread, sp, 0, startIdx); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::GetUnmapedArgs(thread, sp, actualNumArgs, startIdx); @@ -871,10 +871,10 @@ void InterpreterAssembly::HandleResumegenerator( JSTaggedValue objVal = GET_ACC(); if (objVal.IsAsyncGeneratorObject()) { JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } else { JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } DISPATCH(RESUMEGENERATOR); } @@ -1620,7 +1620,7 @@ void InterpreterAssembly::HandleStrictnoteqImm8V8( << " v" << v0; JSTaggedValue left = GET_VREG_VALUE(v0); JSTaggedValue right = GET_ACC(); - JSTaggedValue res = FastRuntimeStub::FastStrictEqual(left, right); + JSTaggedValue res = FastRuntimeStub::FastStrictEqual(thread, left, right); if (!res.IsHole()) { res = res.IsTrue() ? JSTaggedValue::False() : JSTaggedValue::True(); SET_ACC(res); @@ -1642,7 +1642,7 @@ void InterpreterAssembly::HandleStricteqImm8V8( << " v" << v0; JSTaggedValue left = GET_VREG_VALUE(v0); JSTaggedValue right = GET_ACC(); - JSTaggedValue res = FastRuntimeStub::FastStrictEqual(left, right); + JSTaggedValue res = FastRuntimeStub::FastStrictEqual(thread, left, right); if (!res.IsHole()) { SET_ACC(res); } else { @@ -1667,11 +1667,11 @@ void InterpreterAssembly::HandleLdlexvarImm8Imm8( JSTaggedValue currentLexenv = state->env; JSTaggedValue env(currentLexenv); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(LDLEXVAR_IMM8_IMM8); } @@ -1688,11 +1688,11 @@ void InterpreterAssembly::HandleLdlexvarImm4Imm4( JSTaggedValue currentLexenv = state->env; JSTaggedValue env(currentLexenv); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(LDLEXVAR_IMM4_IMM4); } @@ -1709,7 +1709,7 @@ void InterpreterAssembly::HandleWideStlexvarPrefImm16Imm16( AsmInterpretedFrame *state = GET_ASM_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -1731,7 +1731,7 @@ void InterpreterAssembly::HandleStlexvarImm8Imm8( AsmInterpretedFrame *state = GET_ASM_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -1753,7 +1753,7 @@ void InterpreterAssembly::HandleStlexvarImm4Imm4( AsmInterpretedFrame *state = GET_ASM_FRAME(sp); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -1787,7 +1787,7 @@ void InterpreterAssembly::HandlePoplexenv( { AsmInterpretedFrame *state = GET_ASM_FRAME(sp); JSTaggedValue currentLexenv = state->env; - JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(); + JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(thread); GET_ASM_FRAME(sp)->env = parentLexenv; DISPATCH(POPLEXENV); } @@ -1826,7 +1826,7 @@ void InterpreterAssembly::HandleSuspendgeneratorV8( SET_ACC(res); AsmInterpretedFrame *state = GET_ASM_FRAME(sp); - Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " @@ -1943,7 +1943,7 @@ void InterpreterAssembly::HandleThrowUndefinedifholewithnamePrefId16( uint16_t stringId = READ_INST_16_1(); LOG_INST() << "intrinsic::throwundefinedifholewithname" << std::hex << stringId; - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue obj = ConstantPool::GetStringFromCache(thread, constpool, stringId); ASSERT(obj.IsString()); SAVE_PC(); @@ -1963,7 +1963,7 @@ void InterpreterAssembly::HandleStownbynameImm8Id16V8( JSTaggedValue receiver = GET_VREG_VALUE(v0); if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) { SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); @@ -1981,7 +1981,7 @@ void InterpreterAssembly::HandleStownbynameImm8Id16V8( } SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); // Maybe moved by GC RESTORE_ACC(); auto value = GET_ACC(); // Maybe moved by GC @@ -2043,11 +2043,12 @@ void InterpreterAssembly::HandleCreateregexpwithliteralImm8Id16Imm8( { uint16_t stringId = READ_INST_16_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue pattern = ConstantPool::GetStringFromCache(thread, constpool, stringId); uint8_t flags = READ_INST_8_3(); LOG_INST() << "intrinsics::createregexpwithliteral " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(pattern.GetTaggedObject())) + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(pattern.GetTaggedObject())) << ", flags:" << flags; JSTaggedValue res = SlowRuntimeStub::CreateRegExpWithLiteral(thread, pattern, flags); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -2210,7 +2211,7 @@ void InterpreterAssembly::HandleCopyrestargsImm8( << " index: " << restIdx; uint32_t startIdx = 0; - uint32_t restNumArgs = GetNumArgs(sp, restIdx, startIdx); + uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx); JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, sp, restNumArgs, startIdx); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -2290,14 +2291,14 @@ void InterpreterAssembly::HandleStobjbyvalueImm8V8V8( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v1); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -2369,7 +2370,7 @@ void InterpreterAssembly::HandleTryldglobalbynameImm8Id16( JSTaggedValue acc, int16_t hotnessCounter) { uint16_t stringId = READ_INST_16_1(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); auto prop = ConstantPool::GetStringFromCache(thread, constpool, stringId); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -2377,7 +2378,7 @@ void InterpreterAssembly::HandleTryldglobalbynameImm8Id16( JSTaggedValue globalObj = globalEnv->GetGlobalObject(); LOG_INST() << "intrinsics::tryldglobalbyname " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(prop.GetTaggedObject())); + << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject())); #if ECMSCRIPT_ENABLE_IC InterpretedFrame *state = reinterpret_cast(sp) - 1; @@ -2397,7 +2398,7 @@ void InterpreterAssembly::HandleTryldglobalbynameImm8Id16( // order: 1. global record 2. global object JSTaggedValue result = SlowRuntimeStub::LdGlobalRecord(thread, prop); if (!result.IsUndefined()) { - SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue()); + SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread)); } else { JSTaggedValue globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, prop); if (!globalResult.IsHole()) { @@ -2420,7 +2421,7 @@ void InterpreterAssembly::HandleTrystglobalbynameImm8Id16( { uint16_t stringId = READ_INST_16_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -2429,7 +2430,8 @@ void InterpreterAssembly::HandleTrystglobalbynameImm8Id16( RESTORE_ACC(); LOG_INST() << "intrinsics::trystglobalbyname" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); #if ECMSCRIPT_ENABLE_IC InterpretedFrame *state = reinterpret_cast(sp) - 1; @@ -2526,8 +2528,8 @@ void InterpreterAssembly::HandleStownbynamewithnamesetImm8Id16V8( JSTaggedValue receiver = GET_VREG_VALUE(v0); if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) { SAVE_ACC(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); // fast path @@ -2546,8 +2548,9 @@ void InterpreterAssembly::HandleStownbynamewithnamesetImm8Id16V8( SAVE_ACC(); SAVE_PC(); receiver = GET_VREG_VALUE(v0); - constpool = GetConstantPool(sp); // Maybe moved by GC - auto propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); // Maybe moved by GC + constpool = GetConstantPool(thread, sp); // Maybe moved by GC + auto propKey = + ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); // Maybe moved by GC RESTORE_ACC(); auto value = GET_ACC(); // Maybe moved by GC JSTaggedValue res = SlowRuntimeStub::StOwnByNameWithNameSet(thread, receiver, propKey, value); @@ -2563,7 +2566,7 @@ void InterpreterAssembly::HandleLdglobalvarImm16Id16( uint16_t stringId = READ_INST_16_2(); LOG_INST() << "intrinsics::ldglobalvar stringId:" << stringId; SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -2609,14 +2612,14 @@ void InterpreterAssembly::HandleStobjbynameImm8Id16V8( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } if (LIKELY(!res.IsHole())) { @@ -2626,7 +2629,7 @@ void InterpreterAssembly::HandleStobjbynameImm8Id16V8( } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic uint16_t stringId = READ_INST_16_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); value = GET_ACC(); @@ -2647,7 +2650,7 @@ void InterpreterAssembly::HandleStobjbynameImm8Id16V8( JSTaggedValue receiver = GET_VREG_VALUE(v0); if (receiver.IsHeapObject()) { SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); @@ -2664,7 +2667,7 @@ void InterpreterAssembly::HandleStobjbynameImm8Id16V8( // slow path SAVE_ACC(); SAVE_PC(); - constpool = GetConstantPool(sp); // Maybe moved by GC + constpool = GetConstantPool(thread, sp); // Maybe moved by GC auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); // Maybe moved by GC RESTORE_ACC(); JSTaggedValue value = GET_ACC(); // Maybe moved by GC @@ -2684,14 +2687,14 @@ void InterpreterAssembly::HandleStsuperbynameImm8Id16V8( JSTaggedValue obj = GET_VREG_VALUE(v0); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); LOG_INST() << "intrinsics::stsuperbyname" << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() << ", value:" << value.GetRawData(); // slow path @@ -2710,13 +2713,13 @@ void InterpreterAssembly::HandleStglobalvarImm16Id16( { uint16_t stringId = READ_INST_16_2(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue prop = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); LOG_INST() << "intrinsics::stglobalvar " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(prop.GetTaggedObject())) + << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject())) << ", value:" << value.GetRawData(); #if ECMSCRIPT_ENABLE_IC InterpretedFrame *state = reinterpret_cast(sp) - 1; @@ -2789,7 +2792,7 @@ void InterpreterAssembly::HandleAsyncgeneratorresolveV8V8V8( SET_ACC(res); InterpretedFrame *state = (reinterpret_cast(sp) - 1); - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); LOG_INST() << "Exit: AsyncGeneratorresolve " << std::hex << reinterpret_cast(sp) << " " @@ -2892,8 +2895,8 @@ void InterpreterAssembly::HandleLdbigintId16( uint16_t stringId = READ_INST_16_0(); LOG_INST() << "intrinsic::ldbigint"; SAVE_ACC(); - constpool = GetConstantPool(sp); - JSTaggedValue numberBigInt = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue numberBigInt = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::LdBigInt(thread, numberBigInt); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -2929,7 +2932,7 @@ void InterpreterAssembly::HandleSupercallspreadImm8V8( << " array: v" << v0; JSTaggedValue thisFunc = GET_ACC(); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); JSTaggedValue array = GET_VREG_VALUE(v0); SAVE_PC(); @@ -3125,14 +3128,14 @@ void InterpreterAssembly::HandleStobjbyvalueImm16V8V8( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v1); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -3415,11 +3418,11 @@ void InterpreterAssembly::HandleWideLdlexvarPrefImm16Imm16( JSTaggedValue currentLexenv = state->env; JSTaggedValue env(currentLexenv); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(WIDE_LDLEXVAR_PREF_IMM16_IMM16); } @@ -3432,7 +3435,7 @@ void InterpreterAssembly::HandleWideCopyrestargsPrefImm16( << " index: " << restIdx; uint32_t startIdx = 0; - uint32_t restNumArgs = GetNumArgs(sp, restIdx, startIdx); + uint32_t restNumArgs = GetNumArgs(thread, sp, restIdx, startIdx); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CopyRestArgs(thread, sp, restNumArgs, startIdx); @@ -3534,17 +3537,17 @@ void InterpreterAssembly::HandleWideLdobjbyindexPrefImm32( DISPATCH(WIDE_LDOBJBYINDEX_PREF_IMM32); } -bool InterpreterAssembly::AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle method) +bool InterpreterAssembly::AssemblyIsFastNewFrameEnter(JSThread *thread, JSFunction *ctor, JSHandle method) { if (method->IsNativeWithCallField()) { return false; } - if (ctor->IsBase()) { + if (ctor->IsBase(thread)) { return method->OnlyHaveThisWithCallField(); } - if (ctor->IsDerivedConstructor()) { + if (ctor->IsDerivedConstructor(thread)) { return method->OnlyHaveNewTagetAndThisWithCallField(); } @@ -3562,7 +3565,7 @@ void InterpreterAssembly::HandleWideSupercallarrowrangePrefImm16V8( << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GET_ACC(); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -3570,8 +3573,8 @@ void InterpreterAssembly::HandleWideSupercallarrowrangePrefImm16V8( if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -3619,10 +3622,10 @@ void InterpreterAssembly::HandleWideSupercallarrowrangePrefImm16V8( DISPATCH(WIDE_SUPERCALLARROWRANGE_PREF_IMM16_V8); } - if (AssemblyIsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this // +1 for hidden this, explicit this may be overwritten after bc optimizer @@ -3643,22 +3646,22 @@ void InterpreterAssembly::HandleWideSupercallarrowrangePrefImm16V8( // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -3705,7 +3708,7 @@ void InterpreterAssembly::HandleWideSupercallthisrangePrefImm16V8( << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GetFunction(sp); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -3713,8 +3716,8 @@ void InterpreterAssembly::HandleWideSupercallthisrangePrefImm16V8( if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -3762,10 +3765,10 @@ void InterpreterAssembly::HandleWideSupercallthisrangePrefImm16V8( DISPATCH(WIDE_SUPERCALLTHISRANGE_PREF_IMM16_V8); } - if (AssemblyIsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this // +1 for hidden this, explicit this may be overwritten after bc optimizer @@ -3786,22 +3789,22 @@ void InterpreterAssembly::HandleWideSupercallthisrangePrefImm16V8( // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -3901,8 +3904,8 @@ void InterpreterAssembly::HandleWideNewobjrangePrefImm16V8( JSTaggedValue ctor = GET_VREG_VALUE(firstArgRegIdx); if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); - methodHandle.Update(ctorFunc->GetMethod()); - if (ctorFunc->IsBuiltinConstructor()) { + methodHandle.Update(ctorFunc->GetMethod(thread)); + if (ctorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4; // 3: this & numArgs & thread // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -3951,10 +3954,10 @@ void InterpreterAssembly::HandleWideNewobjrangePrefImm16V8( DISPATCH(WIDE_NEWOBJRANGE_PREF_IMM16_V8); } - if (AssemblyIsFastNewFrameEnter(ctorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, ctorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = ctorFunc->IsBase() ? + uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -3974,22 +3977,22 @@ void InterpreterAssembly::HandleWideNewobjrangePrefImm16V8( // this JSTaggedValue thisObj; - if (ctorFunc->IsBase()) { + if (ctorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(ctorFunc->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor(thread)); newSp[index++] = ctor.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = ctor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(); - state->env = ctorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread); + state->env = ctorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -4057,7 +4060,7 @@ void InterpreterAssembly::HandleDeprecatedCreateobjecthavingmethodPrefImm16( LOG_INST() << "intrinsics::createobjecthavingmethod" << " imm:" << imm; SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSObject *result = JSObject::Cast(ConstantPool::GetMethodFromCache(thread, constpool, imm).GetTaggedObject()); RESTORE_ACC(); @@ -4079,7 +4082,7 @@ void InterpreterAssembly::HandleDeprecatedLdhomeobjectPrefNone( LOG_INST() << "intrinsics::ldhomeobject"; JSTaggedValue thisFunc = GetFunction(sp); - JSTaggedValue homeObject = JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(); + JSTaggedValue homeObject = JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(thread); SET_ACC(homeObject); DISPATCH(DEPRECATED_LDHOMEOBJECT_PREF_NONE); @@ -4091,11 +4094,12 @@ void InterpreterAssembly::HandleDeprecatedStclasstoglobalrecordPrefId32( { uint16_t stringId = READ_INST_32_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stclasstoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -4111,11 +4115,12 @@ void InterpreterAssembly::HandleDeprecatedStlettoglobalrecordPrefId32( { uint16_t stringId = READ_INST_32_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stlettoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -4131,11 +4136,12 @@ void InterpreterAssembly::HandleDeprecatedStconsttoglobalrecordPrefId32( { uint16_t stringId = READ_INST_32_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stconsttoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -4152,11 +4158,11 @@ void InterpreterAssembly::HandleDeprecatedLdmodulevarPrefId32Imm8( uint16_t stringId = READ_INST_16_1(); uint8_t innerFlag = READ_INST_8_5(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue key = ConstantPool::GetStringFromCache(thread, constpool, stringId); LOG_INST() << "intrinsics::ldmodulevar " << "string_id:" << stringId << ", " - << "key: " << ConvertToString(EcmaString::Cast(key.GetTaggedObject())); + << "key: " << ConvertToString(thread, EcmaString::Cast(key.GetTaggedObject())); JSTaggedValue moduleVar = SlowRuntimeStub::LdModuleVar(thread, key, innerFlag != 0); INTERPRETER_RETURN_IF_ABRUPT(moduleVar); @@ -4170,12 +4176,12 @@ void InterpreterAssembly::HandleDeprecatedLdsuperbynamePrefId32V8( uint32_t stringId = READ_INST_32_1(); uint32_t v0 = READ_INST_8_5(); JSTaggedValue obj = GET_VREG_VALUE(v0); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); LOG_INST() << "intrinsics::ldsuperbyname" << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); SAVE_PC(); JSTaggedValue thisFunc = GetFunction(sp); @@ -4193,11 +4199,12 @@ void InterpreterAssembly::HandleDeprecatedLdobjbynamePrefId32V8( JSTaggedValue receiver = GET_VREG_VALUE(v0); uint16_t stringId = READ_INST_32_1(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); LOG_INST() << "intrinsics::ldobjbyname " << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -4224,12 +4231,12 @@ void InterpreterAssembly::HandleDeprecatedStmodulevarPrefId32( { uint16_t stringId = READ_INST_32_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); auto key = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stmodulevar " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(key.GetTaggedObject())); + << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(key.GetTaggedObject())); JSTaggedValue value = GET_ACC(); @@ -4243,11 +4250,12 @@ void InterpreterAssembly::HandleDeprecatedGetmodulenamespacePrefId32( JSTaggedValue acc, int16_t hotnessCounter) { uint16_t stringId = READ_INST_32_1(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); auto localName = ConstantPool::GetStringFromCache(thread, constpool, stringId); LOG_INST() << "intrinsics::getmodulenamespace " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(localName.GetTaggedObject())); + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(localName.GetTaggedObject())); JSTaggedValue moduleNamespace = SlowRuntimeStub::GetModuleNamespace(thread, localName); INTERPRETER_RETURN_IF_ABRUPT(moduleNamespace); @@ -4269,7 +4277,7 @@ void InterpreterAssembly::HandleDeprecatedStlexvarPrefImm16Imm16V8( InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -4292,7 +4300,7 @@ void InterpreterAssembly::HandleDeprecatedStlexvarPrefImm8Imm8V8( InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -4315,7 +4323,7 @@ void InterpreterAssembly::HandleDeprecatedStlexvarPrefImm4Imm4V8( InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue env = state->env; for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -4511,7 +4519,7 @@ void InterpreterAssembly::HandleDeprecatedSuspendgeneratorPrefV8V8( SET_ACC(res); InterpretedFrame *state = (reinterpret_cast(sp) - 1); - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " @@ -4593,10 +4601,10 @@ void InterpreterAssembly::HandleDeprecatedResumegeneratorPrefV8( JSTaggedValue objVal = GET_VREG_VALUE(vs); if (objVal.IsAsyncGeneratorObject()) { JSAsyncGeneratorObject *obj = JSAsyncGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } else { JSGeneratorObject *obj = JSGeneratorObject::Cast(objVal.GetTaggedObject()); - SET_ACC(obj->GetResumeResult()); + SET_ACC(obj->GetResumeResult(thread)); } DISPATCH(DEPRECATED_RESUMEGENERATOR_PREF_V8); } @@ -4617,8 +4625,8 @@ void InterpreterAssembly::HandleDeprecatedDefineclasswithbufferPrefId16Imm16Imm1 SAVE_PC(); JSTaggedValue res = - SlowRuntimeStub::CreateClassWithBuffer(thread, proto, lexenv, GetConstantPool(sp), - methodId, methodId + 1, GetModule(sp), + SlowRuntimeStub::CreateClassWithBuffer(thread, proto, lexenv, GetConstantPool(thread, sp), + methodId, methodId + 1, GetModule(thread, sp), JSTaggedValue(length)); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -4848,7 +4856,7 @@ void InterpreterAssembly::HandleDeprecatedCreateobjectwithbufferPrefImm16( uint16_t imm = READ_INST_16_1(); LOG_INST() << "intrinsics::createobjectwithbuffer" << " imm:" << imm; - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSObject *result = JSObject::Cast(ConstantPool::GetMethodFromCache(thread, constpool, imm).GetTaggedObject()); @@ -4868,7 +4876,7 @@ void InterpreterAssembly::HandleDeprecatedCreatearraywithbufferPrefImm16( uint16_t imm = READ_INST_16_1(); LOG_INST() << "intrinsics::createarraywithbuffer" << " imm:" << imm; - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSArray *result = JSArray::Cast(ConstantPool::GetMethodFromCache(thread, constpool, imm).GetTaggedObject()); SAVE_PC(); @@ -4903,7 +4911,7 @@ void InterpreterAssembly::HandleDeprecatedPoplexenvPrefNone( { InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue currentLexenv = state->env; - JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(); + JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(thread); (reinterpret_cast(sp) - 1)->env = parentLexenv; DISPATCH(DEPRECATED_POPLEXENV_PREF_NONE); } @@ -5104,7 +5112,7 @@ void InterpreterAssembly::HandleStownbynamewithnamesetImm16Id16V8( { uint16_t stringId = READ_INST_16_2(); uint32_t v0 = READ_INST_8_4(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); LOG_INST() << "intrinsics::stownbynamewithnameset " << "v" << v0 << " stringId:" << stringId; @@ -5211,11 +5219,12 @@ void InterpreterAssembly::HandleSttoglobalrecordImm16Id16( { uint16_t stringId = READ_INST_16_2(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); LOG_INST() << "intrinsics::stconsttoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_PC(); @@ -5233,9 +5242,10 @@ void InterpreterAssembly::HandleStconsttoglobalrecordImm16Id16( InterpretedFrame *state = reinterpret_cast(sp) - 1; JSTaggedValue constantPool = state->constpool; JSTaggedValue propKey = ConstantPool::Cast(constantPool.GetTaggedObject()) - ->GetObjectFromCache(stringId); + ->GetObjectFromCache(thread, stringId); LOG_INST() << "intrinsics::stconsttoglobalrecord" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); JSTaggedValue value = GET_ACC(); SAVE_ACC(); @@ -5266,7 +5276,7 @@ void InterpreterAssembly::HandleStsuperbynameImm16Id16V8( { uint16_t stringId = READ_INST_16_2(); uint32_t v0 = READ_INST_8_4(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue obj = GET_VREG_VALUE(v0); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); @@ -5274,7 +5284,7 @@ void InterpreterAssembly::HandleStsuperbynameImm16Id16V8( LOG_INST() << "intrinsics::stsuperbyname" << "v" << v0 << " stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData() << ", value:" << value.GetRawData(); // slow path @@ -5293,13 +5303,13 @@ void InterpreterAssembly::HandleLdsuperbynameImm16Id16( { uint16_t stringId = READ_INST_16_2(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue obj = GET_ACC(); LOG_INST() << "intrinsics::ldsuperbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); SAVE_PC(); JSTaggedValue thisFunc = GetFunction(sp); @@ -5316,13 +5326,13 @@ void InterpreterAssembly::HandleLdsuperbynameImm8Id16( { uint16_t stringId = READ_INST_16_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue obj = GET_ACC(); LOG_INST() << "intrinsics::ldsuperbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << obj.GetRawData(); SAVE_PC(); JSTaggedValue thisFunc = GetFunction(sp); @@ -5345,7 +5355,7 @@ void InterpreterAssembly::HandleStownbynameImm16Id16V8( JSTaggedValue receiver = GET_VREG_VALUE(v0); if (receiver.IsJSObject() && !receiver.IsClassConstructor() && !receiver.IsClassPrototype()) { SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); @@ -5363,7 +5373,7 @@ void InterpreterAssembly::HandleStownbynameImm16Id16V8( } SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); // Maybe moved by GC RESTORE_ACC(); auto value = GET_ACC(); // Maybe moved by GC @@ -5386,14 +5396,14 @@ void InterpreterAssembly::HandleStobjbynameImm16Id16V8( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } if (LIKELY(!res.IsHole())) { @@ -5402,7 +5412,7 @@ void InterpreterAssembly::HandleStobjbynameImm16Id16V8( DISPATCH(STOBJBYNAME_IMM16_ID16_V8); } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); value = GET_ACC(); @@ -5422,7 +5432,7 @@ void InterpreterAssembly::HandleStobjbynameImm16Id16V8( JSTaggedValue receiver = GET_VREG_VALUE(v0); if (receiver.IsHeapObject()) { SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); @@ -5439,7 +5449,7 @@ void InterpreterAssembly::HandleStobjbynameImm16Id16V8( // slow path SAVE_ACC(); SAVE_PC(); - constpool = GetConstantPool(sp); // Maybe moved by GC + constpool = GetConstantPool(thread, sp); // Maybe moved by GC auto propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); // Maybe moved by GC RESTORE_ACC(); JSTaggedValue value = GET_ACC(); // Maybe moved by GC @@ -5460,12 +5470,12 @@ void InterpreterAssembly::HandleLdobjbynameImm16Id16( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -5475,7 +5485,7 @@ void InterpreterAssembly::HandleLdobjbynameImm16Id16( } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic uint16_t stringId = READ_INST_16_2(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); receiver = GET_ACC(); @@ -5491,12 +5501,13 @@ void InterpreterAssembly::HandleLdobjbynameImm16Id16( #endif uint16_t stringId = READ_INST_16_2(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue receiver = GET_ACC(); LOG_INST() << "intrinsics::ldobjbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -5527,12 +5538,12 @@ void InterpreterAssembly::HandleLdobjbynameImm8Id16( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -5542,7 +5553,7 @@ void InterpreterAssembly::HandleLdobjbynameImm8Id16( } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic uint16_t stringId = READ_INST_16_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); receiver = GET_ACC(); @@ -5558,12 +5569,13 @@ void InterpreterAssembly::HandleLdobjbynameImm8Id16( #endif uint16_t stringId = READ_INST_16_1(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); RESTORE_ACC(); JSTaggedValue receiver = GET_ACC(); LOG_INST() << "intrinsics::ldobjbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -5589,7 +5601,7 @@ void InterpreterAssembly::HandleTrystglobalbynameImm16Id16( JSTaggedValue acc, int16_t hotnessCounter) { uint16_t stringId = READ_INST_16_2(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue propKey = ConstantPool::GetStringFromCache(thread, constpool, stringId); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -5597,7 +5609,8 @@ void InterpreterAssembly::HandleTrystglobalbynameImm16Id16( JSTaggedValue globalObj = globalEnv->GetGlobalObject(); LOG_INST() << "intrinsics::trystglobalbyname" - << " stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())); + << " stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())); #if ECMSCRIPT_ENABLE_IC InterpretedFrame *state = reinterpret_cast(sp) - 1; @@ -5646,7 +5659,7 @@ void InterpreterAssembly::HandleTryldglobalbynameImm16Id16( JSTaggedValue acc, int16_t hotnessCounter) { uint16_t stringId = READ_INST_16_2(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); auto prop = ConstantPool::GetStringFromCache(thread, constpool, stringId); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -5654,7 +5667,7 @@ void InterpreterAssembly::HandleTryldglobalbynameImm16Id16( JSTaggedValue globalObj = globalEnv->GetGlobalObject(); LOG_INST() << "intrinsics::tryldglobalbyname " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(prop.GetTaggedObject())); + << "stringId:" << stringId << ", " << ConvertToString(thread, EcmaString::Cast(prop.GetTaggedObject())); #if ECMSCRIPT_ENABLE_IC InterpretedFrame *state = reinterpret_cast(sp) - 1; @@ -5674,7 +5687,7 @@ void InterpreterAssembly::HandleTryldglobalbynameImm16Id16( // order: 1. global record 2. global object JSTaggedValue result = SlowRuntimeStub::LdGlobalRecord(thread, prop); if (!result.IsUndefined()) { - SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue()); + SET_ACC(PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread)); } else { JSTaggedValue globalResult = FastRuntimeStub::GetGlobalOwnProperty(thread, globalObj, prop); if (!globalResult.IsHole()) { @@ -5854,11 +5867,11 @@ void InterpreterAssembly::HandleLdobjbyvalueImm16V8( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profiltmpProfileTypeInfoeTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -5910,11 +5923,11 @@ void InterpreterAssembly::HandleLdobjbyvalueImm8V8( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -5979,8 +5992,8 @@ void InterpreterAssembly::HandleDefineclasswithbufferImm16Id16Id16Imm16V8( SAVE_PC(); JSTaggedValue res = - SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(sp), - methodId, literaId, GetModule(sp), JSTaggedValue(length)); + SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(thread, sp), + methodId, literaId, GetModule(thread, sp), JSTaggedValue(length)); INTERPRETER_RETURN_IF_ABRUPT(res); ASSERT(res.IsClassConstructor()); @@ -6005,8 +6018,8 @@ void InterpreterAssembly::HandleDefineclasswithbufferImm8Id16Id16Imm16V8( SAVE_PC(); InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue res = - SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(sp), - methodId, literaId, GetModule(sp), JSTaggedValue(length)); + SlowRuntimeStub::CreateClassWithBuffer(thread, proto, state->env, GetConstantPool(thread, sp), + methodId, literaId, GetModule(thread, sp), JSTaggedValue(length)); INTERPRETER_RETURN_IF_ABRUPT(res); ASSERT(res.IsClassConstructor()); @@ -6144,8 +6157,8 @@ void InterpreterAssembly::HandleCallRuntimeDefineSendableClassPrefImm16Id16Id16I SAVE_PC(); JSTaggedValue res = - SlowRuntimeStub::CreateSharedClass(thread, base, GetConstantPool(sp), methodId, literaId, - length, GetModule(sp)); + SlowRuntimeStub::CreateSharedClass(thread, base, GetConstantPool(thread, sp), methodId, literaId, + length, GetModule(thread, sp)); INTERPRETER_RETURN_IF_ABRUPT(res); ASSERT(res.IsClassConstructor()); @@ -6181,14 +6194,14 @@ void InterpreterAssembly::HandleStthisbyvalueImm16V8( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -6245,14 +6258,14 @@ void InterpreterAssembly::HandleStthisbyvalueImm8V8( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue propKey = GET_VREG_VALUE(v0); JSTaggedValue value = GET_ACC(); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByValue(thread, receiver, propKey, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -6310,11 +6323,11 @@ void InterpreterAssembly::HandleLdthisbyvalueImm16( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -6364,11 +6377,11 @@ void InterpreterAssembly::HandleLdthisbyvalueImm8( if (!tmpProfileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(tmpProfileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByValue(thread, receiver, propKey, firstValue, secondValue); } // IC miss and not enter the megamorphic state, store as polymorphic @@ -6411,25 +6424,25 @@ void InterpreterAssembly::HandleStthisbynameImm16Id16( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GetThis(sp); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic if (res.IsHole() && !firstValue.IsHole()) { uint16_t stringId = READ_INST_16_2(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); RESTORE_ACC(); value = GET_ACC(); receiver = GetThis(sp); - profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(sp).GetTaggedObject()); + profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject()); res = ICRuntimeStub::StoreICByName(thread, profileTypeArray, receiver, propKey, value, slotId); } @@ -6447,8 +6460,8 @@ void InterpreterAssembly::HandleStthisbynameImm16Id16( JSTaggedValue receiver = GetThis(sp); if (receiver.IsHeapObject()) { SAVE_ACC(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); receiver = GetThis(sp); @@ -6464,8 +6477,9 @@ void InterpreterAssembly::HandleStthisbynameImm16Id16( // slow path SAVE_ACC(); SAVE_PC(); - constpool = GetConstantPool(sp); - auto propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); // Maybe moved by GC + constpool = GetConstantPool(thread, sp); + auto propKey = + ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); // Maybe moved by GC RESTORE_ACC(); JSTaggedValue value = GET_ACC(); // Maybe moved by GC receiver = GetThis(sp); // Maybe moved by GC @@ -6483,25 +6497,25 @@ void InterpreterAssembly::HandleStthisbynameImm8Id16( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); SAVE_ACC(); JSTaggedValue receiver = GetThis(sp); JSTaggedValue value = GET_ACC(); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryStoreICByName(thread, receiver, firstValue, secondValue, value); } // IC miss and not enter the megamorphic state, store as polymorphic if (res.IsHole() && !firstValue.IsHole()) { uint16_t stringId = READ_INST_16_1(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); RESTORE_ACC(); value = GET_ACC(); receiver = GetThis(sp); - profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(sp).GetTaggedObject()); + profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject()); res = ICRuntimeStub::StoreICByName(thread, profileTypeArray, receiver, propKey, value, slotId); } @@ -6519,8 +6533,8 @@ void InterpreterAssembly::HandleStthisbynameImm8Id16( JSTaggedValue receiver = GetThis(sp); if (receiver.IsHeapObject()) { SAVE_ACC(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); RESTORE_ACC(); JSTaggedValue value = GET_ACC(); receiver = GetThis(sp); @@ -6536,8 +6550,9 @@ void InterpreterAssembly::HandleStthisbynameImm8Id16( // slow path SAVE_ACC(); SAVE_PC(); - constpool = GetConstantPool(sp); - auto propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); // Maybe moved by GC + constpool = GetConstantPool(thread, sp); + auto propKey = + ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); // Maybe moved by GC RESTORE_ACC(); JSTaggedValue value = GET_ACC(); // Maybe moved by GC receiver = GetThis(sp); // Maybe moved by GC @@ -6555,12 +6570,12 @@ void InterpreterAssembly::HandleLdthisbynameImm16Id16( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_16_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GetThis(sp); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -6569,10 +6584,10 @@ void InterpreterAssembly::HandleLdthisbynameImm16Id16( DISPATCH(LDTHISBYNAME_IMM16_ID16); } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic uint16_t stringId = READ_INST_16_2(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); receiver = GetThis(sp); - profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(sp).GetTaggedObject()); + profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject()); res = ICRuntimeStub::LoadICByName(thread, profileTypeArray, receiver, propKey, slotId); @@ -6583,11 +6598,12 @@ void InterpreterAssembly::HandleLdthisbynameImm16Id16( } #endif uint16_t stringId = READ_INST_16_2(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); JSTaggedValue receiver = GetThis(sp); LOG_INST() << "intrinsics::ldthisbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -6616,12 +6632,12 @@ void InterpreterAssembly::HandleLdthisbynameImm8Id16( if (!profileTypeInfo.IsUndefined()) { uint16_t slotId = READ_INST_8_0(); auto profileTypeArray = ProfileTypeInfo::Cast(profileTypeInfo.GetTaggedObject()); - JSTaggedValue firstValue = profileTypeArray->Get(slotId); + JSTaggedValue firstValue = profileTypeArray->Get(thread, slotId); JSTaggedValue res = JSTaggedValue::Hole(); JSTaggedValue receiver = GetThis(sp); if (LIKELY(firstValue.IsHeapObject())) { - JSTaggedValue secondValue = profileTypeArray->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeArray->Get(thread, slotId + 1); res = ICRuntimeStub::TryLoadICByName(thread, receiver, firstValue, secondValue); } if (LIKELY(!res.IsHole())) { @@ -6630,10 +6646,10 @@ void InterpreterAssembly::HandleLdthisbynameImm8Id16( DISPATCH(LDTHISBYNAME_IMM8_ID16); } else if (!firstValue.IsHole()) { // IC miss and not enter the megamorphic state, store as polymorphic uint16_t stringId = READ_INST_16_1(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); receiver = GetThis(sp); - profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(sp).GetTaggedObject()); + profileTypeArray = ProfileTypeInfo::Cast(GetProfileTypeInfo(thread, sp).GetTaggedObject()); res = ICRuntimeStub::LoadICByName(thread, profileTypeArray, receiver, propKey, slotId); @@ -6644,11 +6660,12 @@ void InterpreterAssembly::HandleLdthisbynameImm8Id16( } #endif uint16_t stringId = READ_INST_16_1(); - constpool = GetConstantPool(sp); - JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); + constpool = GetConstantPool(thread, sp); + JSTaggedValue propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(thread, stringId); JSTaggedValue receiver = GetThis(sp); LOG_INST() << "intrinsics::ldthisbyname stringId:" << stringId << ", " - << ConvertToString(EcmaString::Cast(propKey.GetTaggedObject())) << ", obj:" << receiver.GetRawData(); + << ConvertToString(thread, EcmaString::Cast(propKey.GetTaggedObject())) + << ", obj:" << receiver.GetRawData(); if (LIKELY(receiver.IsHeapObject())) { // fast path @@ -6706,7 +6723,7 @@ void InterpreterAssembly::HandleCallRuntimeNewSendableEnvImm8( JSTaggedValue res = SlowRuntimeStub::NewSendableEnv(thread, numVars); INTERPRETER_RETURN_IF_ABRUPT(res); SET_ACC(res); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); moduleRecord->SetSendableEnv(thread, res); DISPATCH(CALLRUNTIME_NEWSENDABLEENV_PREF_IMM8); } @@ -6723,7 +6740,7 @@ void InterpreterAssembly::HandleCallRuntimeNewSendableEnvImm16( JSTaggedValue res = SlowRuntimeStub::NewSendableEnv(thread, numVars); INTERPRETER_RETURN_IF_ABRUPT(res); SET_ACC(res); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); moduleRecord->SetSendableEnv(thread, res); DISPATCH(CALLRUNTIME_WIDENEWSENDABLEENV_PREF_IMM16); } @@ -6738,10 +6755,10 @@ void InterpreterAssembly::HandleCallRuntimeStSendableVarImm4Imm4( << " level:" << level << " slot:" << slot; JSTaggedValue value = GET_ACC(); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6760,10 +6777,10 @@ void InterpreterAssembly::HandleCallRuntimeStSendableVarImm8Imm8( << " level:" << level << " slot:" << slot; JSTaggedValue value = GET_ACC(); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6782,10 +6799,10 @@ void InterpreterAssembly::HandleCallRuntimeStSendableVarImm16Imm16( << " level:" << level << " slot:" << slot; JSTaggedValue value = GET_ACC(); - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } @@ -6803,14 +6820,14 @@ void InterpreterAssembly::HandleCallRuntimeLdSendableVarImm4Imm4( LOG_INST() << "intrinsics::ldsendablevar" << " level:" << level << " slot:" << slot; - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM4_IMM4); } @@ -6823,14 +6840,14 @@ void InterpreterAssembly::HandleCallRuntimeLdSendableVarImm8Imm8( LOG_INST() << "intrinsics::ldsendablevar" << " level:" << level << " slot:" << slot; - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(CALLRUNTIME_LDSENDABLEVAR_PREF_IMM8_IMM8); } @@ -6843,14 +6860,14 @@ void InterpreterAssembly::HandleCallRuntimeLdSendableVarImm16Imm16( LOG_INST() << "intrinsics::ldsendablevar" << " level:" << level << " slot:" << slot; - SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(sp)); - JSTaggedValue env = moduleRecord->GetSendableEnv(); + SourceTextModule *moduleRecord = SourceTextModule::Cast(GetModule(thread, sp)); + JSTaggedValue env = moduleRecord->GetSendableEnv(thread); for (uint32_t i = 0; i < level; i++) { - JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + JSTaggedValue taggedParentEnv = SendableEnv::Cast(env.GetTaggedObject())->GetParentEnv(thread); ASSERT(!taggedParentEnv.IsUndefined()); env = taggedParentEnv; } - SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(slot)); + SET_ACC(SendableEnv::Cast(env.GetTaggedObject())->GetProperties(thread, slot) ); DISPATCH(CALLRUNTIME_WIDELDSENDABLEVAR_PREF_IMM16_IMM16); } @@ -6862,7 +6879,7 @@ void InterpreterAssembly::HandleDefinemethodImm16Id16Imm8( uint16_t length = READ_INST_8_4(); LOG_INST() << "intrinsics::definemethod length: " << length; SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); Method *method = Method::Cast(ConstantPool::GetMethodFromCache(thread, constpool, methodId).GetTaggedObject()); ASSERT(method != nullptr); @@ -6873,7 +6890,7 @@ void InterpreterAssembly::HandleDefinemethodImm16Id16Imm8( InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue taggedCurEnv = state->env; - auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetModule(sp)); + auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetModule(thread, sp)); INTERPRETER_RETURN_IF_ABRUPT(res); JSFunction *result = JSFunction::Cast(res.GetTaggedObject()); @@ -6972,7 +6989,7 @@ void InterpreterAssembly::HandleDefinemethodImm8Id16Imm8( uint16_t length = READ_INST_8_3(); LOG_INST() << "intrinsics::definemethod length: " << length; SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); Method *method = Method::Cast(ConstantPool::GetMethodFromCache(thread, constpool, methodId).GetTaggedObject()); ASSERT(method != nullptr); @@ -6982,7 +6999,7 @@ void InterpreterAssembly::HandleDefinemethodImm8Id16Imm8( JSTaggedValue homeObject = GET_ACC(); InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue taggedCurEnv = state->env; - auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetModule(sp)); + auto res = SlowRuntimeStub::DefineMethod(thread, method, homeObject, length, taggedCurEnv, GetModule(thread, sp)); INTERPRETER_RETURN_IF_ABRUPT(res); JSFunction *result = JSFunction::Cast(res.GetTaggedObject()); @@ -6998,14 +7015,14 @@ void InterpreterAssembly::HandleDefinefuncImm16Id16Imm8( uint16_t length = READ_INST_8_4(); LOG_INST() << "intrinsics::definefunc length: " << length; - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); InterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue envHandle = state->env; JSFunction *currentFunc = JSFunction::Cast(((reinterpret_cast(sp) - 1)->function).GetTaggedObject()); - auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, GetModule(sp), - length, envHandle, currentFunc->GetHomeObject()); + auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, GetModule(thread, sp), + length, envHandle, currentFunc->GetHomeObject(thread)); JSFunction *jsFunc = JSFunction::Cast(res.GetTaggedObject()); SET_ACC(JSTaggedValue(jsFunc)); @@ -7020,14 +7037,14 @@ void InterpreterAssembly::HandleDefinefuncImm8Id16Imm8( uint16_t length = READ_INST_8_3(); LOG_INST() << "intrinsics::definefunc length: " << length; - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); AsmInterpretedFrame *state = (reinterpret_cast(sp) - 1); JSTaggedValue envHandle = state->env; JSFunction *currentFunc = JSFunction::Cast(((reinterpret_cast(sp) - 1)->function).GetTaggedObject()); - auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, GetModule(sp), - length, envHandle, currentFunc->GetHomeObject()); + auto res = SlowRuntimeStub::DefineFunc(thread, constpool, methodId, GetModule(thread, sp), + length, envHandle, currentFunc->GetHomeObject(thread)); JSFunction *jsFunc = JSFunction::Cast(res.GetTaggedObject()); SET_ACC(JSTaggedValue(jsFunc)); @@ -7044,7 +7061,7 @@ void InterpreterAssembly::HandleSupercallarrowrangeImm8Imm8V8( << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GET_ACC(); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -7053,8 +7070,8 @@ void InterpreterAssembly::HandleSupercallarrowrangeImm8Imm8V8( if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -7102,10 +7119,10 @@ void InterpreterAssembly::HandleSupercallarrowrangeImm8Imm8V8( DISPATCH(SUPERCALLARROWRANGE_IMM8_IMM8_V8); } - if (AssemblyIsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this // +1 for hidden this, explicit this may be overwritten after bc optimizer @@ -7126,22 +7143,22 @@ void InterpreterAssembly::HandleSupercallarrowrangeImm8Imm8V8( // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -7187,7 +7204,7 @@ void InterpreterAssembly::HandleSupercallthisrangeImm8Imm8V8( << " range: " << range << " v" << v0; JSTaggedValue thisFunc = GetFunction(sp); - JSTaggedValue newTarget = GetNewTarget(sp); + JSTaggedValue newTarget = GetNewTarget(thread, sp); SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); @@ -7196,8 +7213,8 @@ void InterpreterAssembly::HandleSupercallthisrangeImm8Imm8V8( JSMutableHandle methodHandle(thread, JSTaggedValue::Undefined()); if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); - methodHandle.Update(superCtorFunc->GetMethod()); - if (superCtorFunc->IsBuiltinConstructor()) { + methodHandle.Update(superCtorFunc->GetMethod(thread)); + if (superCtorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs @@ -7245,10 +7262,10 @@ void InterpreterAssembly::HandleSupercallthisrangeImm8Imm8V8( DISPATCH(SUPERCALLTHISRANGE_IMM8_IMM8_V8); } - if (AssemblyIsFastNewFrameEnter(superCtorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, superCtorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = superCtorFunc->IsBase() ? + uint32_t numDeclaredArgs = superCtorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this // +1 for hidden this, explicit this may be overwritten after bc optimizer @@ -7269,22 +7286,22 @@ void InterpreterAssembly::HandleSupercallthisrangeImm8Imm8V8( // this JSTaggedValue thisObj; - if (superCtorFunc->IsBase()) { + if (superCtorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, superCtor, newTarget, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(superCtorFunc->IsDerivedConstructor()); + ASSERT(superCtorFunc->IsDerivedConstructor(thread)); newSp[index++] = newTarget.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = superCtor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(); - state->env = superCtorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = superCtorFunc->GetProfileTypeInfo(thread); + state->env = superCtorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -7371,8 +7388,8 @@ void InterpreterAssembly::HandleNewobjrangeImm16Imm8V8( if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); - methodHandle.Update(ctorFunc->GetMethod()); - if (ctorFunc->IsBuiltinConstructor()) { + methodHandle.Update(ctorFunc->GetMethod(thread)); + if (ctorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4; // 4: newtarget/this & numArgs & thread @@ -7422,10 +7439,10 @@ void InterpreterAssembly::HandleNewobjrangeImm16Imm8V8( DISPATCH(NEWOBJRANGE_IMM16_IMM8_V8); } - if (AssemblyIsFastNewFrameEnter(ctorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, ctorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = ctorFunc->IsBase() ? + uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -7445,22 +7462,22 @@ void InterpreterAssembly::HandleNewobjrangeImm16Imm8V8( // this JSTaggedValue thisObj; - if (ctorFunc->IsBase()) { + if (ctorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(ctorFunc->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor(thread)); newSp[index++] = ctor.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = ctor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(); - state->env = ctorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread); + state->env = ctorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -7514,8 +7531,8 @@ void InterpreterAssembly::HandleNewobjrangeImm8Imm8V8( if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); - methodHandle.Update(ctorFunc->GetMethod()); - if (ctorFunc->IsBuiltinConstructor()) { + methodHandle.Update(ctorFunc->GetMethod(thread)); + if (ctorFunc->IsBuiltinConstructor(thread)) { ASSERT(methodHandle->GetNumVregsWithCallField() == 0); size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 4; // 2: numArgs & thread // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -7564,10 +7581,10 @@ void InterpreterAssembly::HandleNewobjrangeImm8Imm8V8( DISPATCH(NEWOBJRANGE_IMM8_IMM8_V8); } - if (AssemblyIsFastNewFrameEnter(ctorFunc, methodHandle)) { + if (AssemblyIsFastNewFrameEnter(thread, ctorFunc, methodHandle)) { SAVE_PC(); uint32_t numVregs = methodHandle->GetNumVregsWithCallField(); - uint32_t numDeclaredArgs = ctorFunc->IsBase() ? + uint32_t numDeclaredArgs = ctorFunc->IsBase(thread) ? methodHandle->GetNumArgsWithCallField() + 1 : // +1 for this methodHandle->GetNumArgsWithCallField() + 2; // +2 for newTarget and this size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs; @@ -7587,22 +7604,22 @@ void InterpreterAssembly::HandleNewobjrangeImm8Imm8V8( // this JSTaggedValue thisObj; - if (ctorFunc->IsBase()) { + if (ctorFunc->IsBase(thread)) { thisObj = FastRuntimeStub::NewThisObject(thread, ctor, ctor, state); INTERPRETER_RETURN_IF_ABRUPT(thisObj); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); } else { - ASSERT(ctorFunc->IsDerivedConstructor()); + ASSERT(ctorFunc->IsDerivedConstructor(thread)); newSp[index++] = ctor.GetRawData(); thisObj = JSTaggedValue::Undefined(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = thisObj.GetRawData(); state->function = ctor; - state->constpool = methodHandle->GetConstantPool(); - state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(); - state->env = ctorFunc->GetLexicalEnv(); + state->constpool = methodHandle->GetConstantPool(thread); + state->profileTypeInfo = ctorFunc->GetProfileTypeInfo(thread); + state->env = ctorFunc->GetLexicalEnv(thread); } // the second condition ensure not push extra args @@ -7666,11 +7683,12 @@ void InterpreterAssembly::HandleCreateregexpwithliteralImm16Id16Imm8( { uint16_t stringId = READ_INST_16_2(); SAVE_ACC(); - constpool = GetConstantPool(sp); + constpool = GetConstantPool(thread, sp); JSTaggedValue pattern = ConstantPool::GetStringFromCache(thread, constpool, stringId); uint8_t flags = READ_INST_8_4(); LOG_INST() << "intrinsics::createregexpwithliteral " - << "stringId:" << stringId << ", " << ConvertToString(EcmaString::Cast(pattern.GetTaggedObject())) + << "stringId:" << stringId << ", " + << ConvertToString(thread, EcmaString::Cast(pattern.GetTaggedObject())) << ", flags:" << flags; JSTaggedValue res = SlowRuntimeStub::CreateRegExpWithLiteral(thread, pattern, flags); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -7688,7 +7706,7 @@ void InterpreterAssembly::HandleCreateobjectwithbufferImm16Id16( constpool = GetUnsharedConstpool(thread, sp); JSObject *result = JSObject::Cast( ConstantPool::GetLiteralFromCache( - thread, constpool, imm, GetModule(sp)).GetTaggedObject()); + thread, constpool, imm, GetModule(thread, sp)).GetTaggedObject()); SAVE_PC(); InterpretedFrame *state = (reinterpret_cast(sp) - 1); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -7709,7 +7727,7 @@ void InterpreterAssembly::HandleCreateobjectwithbufferImm8Id16( constpool = GetUnsharedConstpool(thread, sp); JSObject *result = JSObject::Cast( ConstantPool::GetLiteralFromCache( - thread, constpool, imm, GetModule(sp)).GetTaggedObject()); + thread, constpool, imm, GetModule(thread, sp)).GetTaggedObject()); SAVE_PC(); InterpretedFrame *state = (reinterpret_cast(sp) - 1); EcmaVM *ecmaVm = thread->GetEcmaVM(); @@ -7746,7 +7764,7 @@ void InterpreterAssembly::HandleCreatearraywithbufferImm8Id16( constpool = GetUnsharedConstpool(thread, sp); JSArray *result = JSArray::Cast( ConstantPool::GetLiteralFromCache( - thread, constpool, imm, GetModule(sp)).GetTaggedObject()); + thread, constpool, imm, GetModule(thread, sp)).GetTaggedObject()); SAVE_PC(); EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory(); @@ -7768,7 +7786,7 @@ void InterpreterAssembly::HandleCreatearraywithbufferImm16Id16( InterpretedFrame *state = reinterpret_cast(sp) - 1; JSTaggedValue constantPool = state->constpool; JSArray *result = JSArray::Cast(ConstantPool::Cast(constantPool.GetTaggedObject()) - ->GetObjectFromCache(imm).GetTaggedObject()); + ->GetObjectFromCache(thread, imm).GetTaggedObject()); SAVE_PC(); JSTaggedValue res = SlowRuntimeStub::CreateArrayWithBuffer(thread, factory, result); INTERPRETER_RETURN_IF_ABRUPT(res); @@ -7810,7 +7828,7 @@ void InterpreterAssembly::ExceptionHandler( return; } auto method = frameHandler.GetMethod(); - pcOffset = method->FindCatchBlock(frameHandler.GetBytecodeOffset()); + pcOffset = method->FindCatchBlock(thread, frameHandler.GetBytecodeOffset()); if (pcOffset != INVALID_INDEX) { thread->SetCurrentFrame(frameHandler.GetSp()); thread->SetLastFp(frameHandler.GetFp()); @@ -7928,45 +7946,45 @@ JSTaggedValue InterpreterAssembly::GetThis(JSTaggedType *sp) return JSTaggedValue(state->thisObj); } -JSTaggedValue InterpreterAssembly::GetNewTarget(JSTaggedType *sp) +JSTaggedValue InterpreterAssembly::GetNewTarget(JSThread *thread, JSTaggedType *sp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) AsmInterpretedFrame *state = reinterpret_cast(sp) - 1; - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); ASSERT(method->HaveNewTargetWithCallField()); uint32_t numVregs = method->GetNumVregsWithCallField(); bool haveFunc = method->HaveFuncWithCallField(); return JSTaggedValue(sp[numVregs + haveFunc]); } -JSTaggedValue InterpreterAssembly::GetConstantPool(JSTaggedType *sp) +JSTaggedValue InterpreterAssembly::GetConstantPool(JSThread *thread, JSTaggedType *sp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) AsmInterpretedFrame *state = reinterpret_cast(sp) - 1; - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); - return method->GetConstantPool(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); + return method->GetConstantPool(thread); } JSTaggedValue InterpreterAssembly::GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp) { AsmInterpretedFrame *state = reinterpret_cast(sp) - 1; - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); - return thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(method->GetConstantPool()); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); + return thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(method->GetConstantPool(thread)); } -JSTaggedValue InterpreterAssembly::GetModule(JSTaggedType *sp) +JSTaggedValue InterpreterAssembly::GetModule(JSThread* thread, JSTaggedType *sp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) AsmInterpretedFrame *state = reinterpret_cast(sp) - 1; - return JSFunction::Cast(state->function.GetTaggedObject())->GetModule(); + return JSFunction::Cast(state->function.GetTaggedObject())->GetModule(thread); } -JSTaggedValue InterpreterAssembly::GetProfileTypeInfo(JSTaggedType *sp) +JSTaggedValue InterpreterAssembly::GetProfileTypeInfo(JSThread* thread, JSTaggedType *sp) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) AsmInterpretedFrame *state = reinterpret_cast(sp) - 1; JSFunction *function = JSFunction::Cast(state->function.GetTaggedObject()); - return function->GetProfileTypeInfo(); + return function->GetProfileTypeInfo(thread); } JSTaggedType *InterpreterAssembly::GetAsmInterpreterFramePointer(AsmInterpretedFrame *state) @@ -7974,11 +7992,11 @@ JSTaggedType *InterpreterAssembly::GetAsmInterpreterFramePointer(AsmInterpretedF return state->GetCurrentFramePointer(); } -uint32_t InterpreterAssembly::GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx) +uint32_t InterpreterAssembly::GetNumArgs(JSThread *thread, JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) AsmInterpretedFrame *state = reinterpret_cast(sp) - 1; - Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(); + Method *method = JSFunction::Cast(state->function.GetTaggedObject())->GetCallTarget(thread); ASSERT(method->HaveExtraWithCallField()); uint32_t numVregs = method->GetNumVregsWithCallField(); @@ -8011,7 +8029,7 @@ inline JSTaggedValue InterpreterAssembly::UpdateHotnessCounter(JSThread* thread, AsmInterpretedFrame *state = GET_ASM_FRAME(sp); thread->CheckSafepoint(); JSFunction* function = JSFunction::Cast(state->function.GetTaggedObject()); - JSTaggedValue profileTypeInfo = function->GetProfileTypeInfo(); + JSTaggedValue profileTypeInfo = function->GetProfileTypeInfo(thread); if (profileTypeInfo.IsUndefined()) { return SlowRuntimeStub::NotifyInlineCache(thread, function); } diff --git a/ecmascript/interpreter/interpreter_assembly.h b/ecmascript/interpreter/interpreter_assembly.h index 6ae1af040f..0ef203d193 100644 --- a/ecmascript/interpreter/interpreter_assembly.h +++ b/ecmascript/interpreter/interpreter_assembly.h @@ -47,16 +47,16 @@ public: static inline void InterpreterFrameCopyArgs(JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, uint32_t numDeclaredArgs, bool haveExtraArgs = true); static JSTaggedValue GetFunction(JSTaggedType *sp); - static JSTaggedValue GetNewTarget(JSTaggedType *sp); + static JSTaggedValue GetNewTarget(JSThread *thread, JSTaggedType *sp); static JSTaggedValue GetThis(JSTaggedType *sp); - static JSTaggedValue GetConstantPool(JSTaggedType *sp); + static JSTaggedValue GetConstantPool(JSThread *thread, JSTaggedType *sp); static JSTaggedValue GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp); - static JSTaggedValue GetModule(JSTaggedType *sp); - static JSTaggedValue GetProfileTypeInfo(JSTaggedType *sp); - static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); + static JSTaggedValue GetModule(JSThread *thread, JSTaggedType *sp); + static JSTaggedValue GetProfileTypeInfo(JSThread *thread, JSTaggedType *sp); + static uint32_t GetNumArgs(JSThread *thread, JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state); - static bool AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle method); + static bool AssemblyIsFastNewFrameEnter(JSThread *thread, JSFunction *ctor, JSHandle method); static PUBLIC_API int64_t GetCallSize(EcmaOpcode opcode); #ifndef EXCLUDE_C_INTERPRETER diff --git a/ecmascript/interpreter/slow_runtime_stub.cpp b/ecmascript/interpreter/slow_runtime_stub.cpp index 1c3262dd77..d818118416 100644 --- a/ecmascript/interpreter/slow_runtime_stub.cpp +++ b/ecmascript/interpreter/slow_runtime_stub.cpp @@ -853,7 +853,7 @@ JSTaggedValue SlowRuntimeStub::TryLdGlobalByNameFromGlobalProto(JSThread *thread INTERPRETER_TRACE(thread, Trygetobjprop); [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj(thread, global.GetTaggedObject()->GetClass()->GetPrototype()); + JSHandle obj(thread, global.GetTaggedObject()->GetClass()->GetPrototype(thread)); JSHandle propHandle(thread, prop); return RuntimeStubs::RuntimeTryLdGlobalByName(thread, obj, propHandle); } @@ -1029,7 +1029,7 @@ JSTaggedValue SlowRuntimeStub::LdSendableClass(JSThread *thread, JSTaggedValue e INTERPRETER_TRACE(thread, LdSendableClass); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle envHandle(thread, env); - return RuntimeStubs::RuntimeLdSendableClass(envHandle, level); + return RuntimeStubs::RuntimeLdSendableClass(thread, envHandle, level); } JSTaggedValue SlowRuntimeStub::LdSendableExternalModuleVar(JSThread *thread, int32_t index, JSTaggedValue thisFunc) @@ -1109,7 +1109,7 @@ JSTaggedValue SlowRuntimeStub::NotifyInlineCache(JSThread *thread, JSFunction *f [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle functionHandle(thread, function); - uint32_t slotSize = functionHandle->GetCallTarget()->GetSlotSize(); + uint32_t slotSize = functionHandle->GetCallTarget(thread)->GetSlotSize(); return RuntimeStubs::RuntimeNotifyInlineCache(thread, functionHandle, slotSize); } diff --git a/ecmascript/intl/global_intl_helper.cpp b/ecmascript/intl/global_intl_helper.cpp index f0348a7d53..23fda6aa53 100644 --- a/ecmascript/intl/global_intl_helper.cpp +++ b/ecmascript/intl/global_intl_helper.cpp @@ -197,9 +197,9 @@ int64_t GlobalIntlHelper::DoubleToInt64(double value) return static_cast(round(value)); } -std::string GlobalIntlHelper::EcmaConvertToStr(const JSHandle &string) +std::string GlobalIntlHelper::EcmaConvertToStr(const JSThread *thread, const JSHandle &string) { - return std::string(ConvertToString(*string, StringConvertedUsage::LOGICOPERATION)); + return std::string(ConvertToString(thread, *string, StringConvertedUsage::LOGICOPERATION)); } std::vector GlobalIntlHelper::LocalesToVector(JSThread *thread, @@ -217,7 +217,7 @@ std::vector GlobalIntlHelper::TaggedArrayToVector(JSThread *thread, uint32_t availablecalesLength = taggedarray->GetLength(); for (uint32_t i = 0; i < availablecalesLength; i++) { availableItem.Update(taggedarray->Get(thread, i)); - availableStringLocales.emplace_back(intl::LocaleHelper::ConvertToStdString(availableItem)); + availableStringLocales.emplace_back(intl::LocaleHelper::ConvertToStdString(thread, availableItem)); } return availableStringLocales; } diff --git a/ecmascript/intl/global_intl_helper.h b/ecmascript/intl/global_intl_helper.h index 3793f20420..997fbc1cdc 100644 --- a/ecmascript/intl/global_intl_helper.h +++ b/ecmascript/intl/global_intl_helper.h @@ -107,7 +107,7 @@ public: } EcmaVM *ecmaVm = thread->GetEcmaVM(); std::string cacheEntry = locales->IsUndefined() ? "" : - EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(thread); if (cache) { void *cachedCollator = ecmaVm->GetIntlCache().GetIcuFormatterFromCache(icuType, cacheEntry); if (cachedCollator != nullptr) { diff --git a/ecmascript/intl/locale_helper.cpp b/ecmascript/intl/locale_helper.cpp index 8a714981d4..0457e3a0f4 100644 --- a/ecmascript/intl/locale_helper.cpp +++ b/ecmascript/intl/locale_helper.cpp @@ -153,7 +153,7 @@ JSHandle LocaleHelper::CanonicalizeHelper(JSThread *thread, JSHandl bool isExist = false; uint32_t seenLen = seen->GetLength(); for (uint32_t i = 0; i < seenLen; i++) { - if (JSTaggedValue::SameValue(seen->Get(thread, i), tag.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, seen->Get(thread, i), tag.GetTaggedValue())) { isExist = true; } } @@ -173,7 +173,7 @@ JSHandle LocaleHelper::CanonicalizeHelper(JSThread *thread, JSHandl JSHandle LocaleHelper::CanonicalizeUnicodeLocaleId(JSThread *thread, const JSHandle &locale) { [[maybe_unused]] ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - if (!IsStructurallyValidLanguageTag(locale)) { + if (!IsStructurallyValidLanguageTag(thread, locale)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid locale", factory->GetEmptyString()); } @@ -181,7 +181,7 @@ JSHandle LocaleHelper::CanonicalizeUnicodeLocaleId(JSThread *thread, THROW_RANGE_ERROR_AND_RETURN(thread, "invalid locale", factory->GetEmptyString()); } - std::string localeCStr = ConvertToStdString(locale); + std::string localeCStr = ConvertToStdString(thread, locale); std::transform(localeCStr.begin(), localeCStr.end(), localeCStr.begin(), AsciiAlphaToLower); UErrorCode status = U_ZERO_ERROR; icu::Locale formalLocale; @@ -262,9 +262,9 @@ JSHandle LocaleHelper::ToLanguageTag(JSThread *thread, const icu::Lo } // 6.2.2 IsStructurallyValidLanguageTag( locale ) -bool LocaleHelper::IsStructurallyValidLanguageTag(const JSHandle &tag) +bool LocaleHelper::IsStructurallyValidLanguageTag(JSThread *thread, const JSHandle &tag) { - std::string tagCollection = ConvertToStdString(tag); + std::string tagCollection = ConvertToStdString(thread, tag); std::vector containers; std::string substring; std::set uniqueSubtags; @@ -290,9 +290,9 @@ bool LocaleHelper::IsStructurallyValidLanguageTag(const JSHandle &ta return result; } -std::string LocaleHelper::ConvertToStdString(const JSHandle &ecmaStr) +std::string LocaleHelper::ConvertToStdString(const JSThread *thread, const JSHandle &ecmaStr) { - return std::string(ConvertToString(*ecmaStr, StringConvertedUsage::LOGICOPERATION)); + return std::string(ConvertToString(thread, *ecmaStr, StringConvertedUsage::LOGICOPERATION)); } bool LocaleHelper::DealwithLanguageTag(const std::vector &containers, size_t &address) @@ -382,9 +382,9 @@ void LocaleHelper::HandleLocaleExtension(size_t &start, size_t &extensionEnd, co } } -LocaleHelper::ParsedLocale LocaleHelper::HandleLocale(const JSHandle &localeString) +LocaleHelper::ParsedLocale LocaleHelper::HandleLocale(JSThread *thread, const JSHandle &localeString) { - return LocaleHelper::HandleLocale(ConvertToStdString(localeString)); + return LocaleHelper::HandleLocale(ConvertToStdString(thread, localeString)); } LocaleHelper::ParsedLocale LocaleHelper::HandleLocale(const std::string &localeString) @@ -429,7 +429,7 @@ std::vector LocaleHelper::GetAvailableLocales(JSThread *thread, con UErrorCode status = U_ZERO_ERROR; auto globalConst = thread->GlobalConstants(); JSHandle specialValue = JSHandle::Cast(globalConst->GetHandledEnUsPosixString()); - std::string specialString = ConvertToStdString(specialValue); + std::string specialString = ConvertToStdString(thread, specialValue); UEnumeration *uenum = nullptr; { ThreadNativeScope nativeScope(thread); diff --git a/ecmascript/intl/locale_helper.h b/ecmascript/intl/locale_helper.h index 9669eb2a0f..0722994f7e 100644 --- a/ecmascript/intl/locale_helper.h +++ b/ecmascript/intl/locale_helper.h @@ -42,16 +42,16 @@ public: static std::string ToStdStringLanguageTag(JSThread *thread, const icu::Locale &locale); static JSHandle ToLanguageTag(JSThread *thread, const icu::Locale &locale); static std::vector GetAvailableLocales(JSThread *thread, const char *key, const char *path); - static bool IsStructurallyValidLanguageTag(const JSHandle &tag); + static bool IsStructurallyValidLanguageTag(JSThread *thread, const JSHandle &tag); // 9.2.2 BestAvailableLocale ( availableLocales, locale ) static std::string BestAvailableLocale(const std::vector &availableLocales, const std::string &locale); static const std::string& StdStringDefaultLocale(JSThread *thread); static JSHandle DefaultLocale(JSThread *thread); - static LocaleHelper::ParsedLocale HandleLocale(const JSHandle &localeString); + static LocaleHelper::ParsedLocale HandleLocale(JSThread *thread, const JSHandle &localeString); static LocaleHelper::ParsedLocale HandleLocale(const std::string &localeString); static void HandleLocaleExtension(size_t &start, size_t &extensionEnd, const std::string result, size_t len); - static std::string ConvertToStdString(const JSHandle &ecmaStr); + static std::string ConvertToStdString(const JSThread *thread, const JSHandle &ecmaStr); private: template static JSHandle CanonicalizeHelper(JSThread *thread, JSHandle &obj, JSHandle &seen); diff --git a/ecmascript/jit/compile_decision.cpp b/ecmascript/jit/compile_decision.cpp index da895da902..8d91a2ae1d 100644 --- a/ecmascript/jit/compile_decision.cpp +++ b/ecmascript/jit/compile_decision.cpp @@ -139,20 +139,22 @@ CString CompileDecision::GetMethodInfo() const CString CompileDecision::GetMethodName() const { - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); + JSThread *thread = vm_->GetJSThread(); + Method *method = Method::Cast(jsFunction_->GetMethod(thread).GetTaggedObject()); ASSERT(method != nullptr); - auto jSPandaFile = method->GetJSPandaFile(); + auto jSPandaFile = method->GetJSPandaFile(thread); CString fileDesc; if (jSPandaFile != nullptr) { fileDesc = jSPandaFile->GetJSPandaFileDesc(); } - return fileDesc + ":" + method->GetRecordNameStr() + "." + CString(method->GetMethodName()); + return fileDesc + ":" + method->GetRecordNameStr(thread) + "." + CString(method->GetMethodName(thread)); } uint32_t CompileDecision::GetCodeSize() const { - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); - return method->GetCodeSize(); + JSThread *thread = vm_->GetJSThread(); + Method *method = Method::Cast(jsFunction_->GetMethod(thread).GetTaggedObject()); + return method->GetCodeSize(thread); } bool CompileDecision::Decision() @@ -191,8 +193,8 @@ bool CompileDecision::IsJsFunctionSupportCompile() const LOG_JIT(DEBUG) << tier_ << "skip jit task, as too large:" << GetMethodInfo(); return false; } - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); - if (vm_->IsEnableOsr() && osrOffset_ != MachineCode::INVALID_OSR_OFFSET && method->HasCatchBlock()) { + Method *method = Method::Cast(jsFunction_->GetMethod(vm_->GetJSThread()).GetTaggedObject()); + if (vm_->IsEnableOsr() && osrOffset_ != MachineCode::INVALID_OSR_OFFSET && method->HasCatchBlock(vm_->GetJSThread())) { LOG_JIT(DEBUG) << "skip jit task, as osr does not support catch blocks: " << GetMethodInfo(); return false; } @@ -206,7 +208,7 @@ bool CompileDecision::IsJsFunctionSupportCompile() const bool CompileDecision::IsSupportFunctionKind() const { - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); + Method *method = Method::Cast(jsFunction_->GetMethod(vm_->GetJSThread()).GetTaggedObject()); if (jsFunction_.GetTaggedValue().IsJSSharedFunction()) { LOG_JIT(DEBUG) << tier_ << "method does not support compile shared function:" << GetMethodInfo(); return false; @@ -241,7 +243,7 @@ bool CompileDecision::CheckJsFunctionStatus() const } if (tier_.IsFast() && jsFunction_->IsCompiledCode()) { - JSTaggedValue machineCode = jsFunction_->GetMachineCode(); + JSTaggedValue machineCode = jsFunction_->GetMachineCode(vm_->GetJSThread()); if (machineCode.IsMachineCodeObject() && MachineCode::Cast(machineCode.GetTaggedObject())->GetOSROffset() == MachineCode::INVALID_OSR_OFFSET) { return false; @@ -249,7 +251,7 @@ bool CompileDecision::CheckJsFunctionStatus() const return true; } - if (tier_.IsBaseLine() && !jsFunction_->GetBaselineCode().IsUndefined()) { + if (tier_.IsBaseLine() && !jsFunction_->GetBaselineCode(vm_->GetJSThread()).IsUndefined()) { return false; } return true; @@ -257,7 +259,7 @@ bool CompileDecision::CheckJsFunctionStatus() const void CompileDecision::DisableJitCompile() const { - jsFunction_->SetJitHotnessCnt(ProfileTypeInfo::JIT_DISABLE_FLAG); + jsFunction_->SetJitHotnessCnt(vm_->GetJSThread(), ProfileTypeInfo::JIT_DISABLE_FLAG); } bool CompileDecision::CheckVmState() const diff --git a/ecmascript/jit/jit.cpp b/ecmascript/jit/jit.cpp index 44013c6859..c95f593575 100644 --- a/ecmascript/jit/jit.cpp +++ b/ecmascript/jit/jit.cpp @@ -237,13 +237,14 @@ Jit::~Jit() { } -void Jit::CountInterpExecFuncs(JSHandle &jsFunction) +void Jit::CountInterpExecFuncs(JSThread *jsThread, JSHandle &jsFunction) { - Method *method = Method::Cast(jsFunction->GetMethod().GetTaggedObject()); - auto jSPandaFile = method->GetJSPandaFile(); + Method *method = Method::Cast(jsFunction->GetMethod(jsThread).GetTaggedObject()); + auto jSPandaFile = method->GetJSPandaFile(jsThread); ASSERT(jSPandaFile != nullptr); CString fileDesc = jSPandaFile->GetJSPandaFileDesc(); - CString methodInfo = fileDesc + ":" + method->GetRecordNameStr() + "." + CString(method->GetMethodName()); + CString methodInfo = + fileDesc + ":" + method->GetRecordNameStr(jsThread) +"." + CString(method->GetMethodName(jsThread)); auto &profMap = JitWarmupProfiler::GetInstance()->profMap_; if (profMap.find(methodInfo) == profMap.end()) { profMap.insert({methodInfo, false}); diff --git a/ecmascript/jit/jit.h b/ecmascript/jit/jit.h index f596a59b59..0ad596f28c 100644 --- a/ecmascript/jit/jit.h +++ b/ecmascript/jit/jit.h @@ -88,7 +88,7 @@ public: void ChangeTaskPoolState(bool inBackground); // dfx for jit warmup compile - static void CountInterpExecFuncs(JSHandle &jsFunction); + static void CountInterpExecFuncs(JSThread *jsThread, JSHandle &jsFunction); bool IsAppJit() const { diff --git a/ecmascript/jit/jit_dfx.cpp b/ecmascript/jit/jit_dfx.cpp index 98ab381c03..ea829b7c25 100644 --- a/ecmascript/jit/jit_dfx.cpp +++ b/ecmascript/jit/jit_dfx.cpp @@ -92,14 +92,14 @@ std::ostream &JitDfx::GetLogFileStream() return logFiles_[threadId]; } -void JitDfx::DumpBytecodeInst(Method *method) +void JitDfx::DumpBytecodeInst(JSThread *thread, Method *method) { if (!isEnableDump_) { return; } - CString methodInfo = method->GetRecordNameStr() + "." + CString(method->GetMethodName()); - MethodLiteral *methodLiteral = method->GetMethodLiteral(); - auto jsPandaFile = method->GetJSPandaFile(); + CString methodInfo = method->GetRecordNameStr(thread) + "." + CString(method->GetMethodName(thread)); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); + auto jsPandaFile = method->GetJSPandaFile(thread); const panda_file::File *pf = jsPandaFile->GetPandaFile(); ASSERT(methodLiteral != nullptr); panda_file::File::EntityId methodIdx = methodLiteral->GetMethodId(); @@ -122,7 +122,7 @@ void JitDfx::DumpBytecodeInst(Method *method) GetLogFileStream() << ss.str() << std::endl; } -void JitDfx::TraceJitCode(Method *method, bool isEntry) +void JitDfx::TraceJitCode(JSThread *thread, Method *method, bool isEntry) { if (!isEnableDump_) { return; @@ -131,7 +131,7 @@ void JitDfx::TraceJitCode(Method *method, bool isEntry) prefixOffset_ -= 1; } CString prefixStr = isEntry ? CString("JitCodeEntry:") : CString("JitCodeExit :"); - CString methodInfo = method->GetRecordNameStr() + "." + CString(method->GetMethodName()); + CString methodInfo = method->GetRecordNameStr(thread) + "." + CString(method->GetMethodName(thread)); static CString blackSpace(" "); CString prefix; for (uint32_t i = 0; i < prefixOffset_; i++) { diff --git a/ecmascript/jit/jit_dfx.h b/ecmascript/jit/jit_dfx.h index 5fc24d3067..47cb2ccb14 100644 --- a/ecmascript/jit/jit_dfx.h +++ b/ecmascript/jit/jit_dfx.h @@ -62,8 +62,8 @@ public: std::ostream &GetLogFileStream(); - void DumpBytecodeInst(Method *method); - void TraceJitCode(Method *method, bool isEntry); + void DumpBytecodeInst(JSThread *thread, Method *method); + void TraceJitCode(JSThread *thread, Method *method, bool isEntry); void SetBundleName(CString bundleName) { diff --git a/ecmascript/jit/jit_profiler.cpp b/ecmascript/jit/jit_profiler.cpp index de8567d4f3..0fe283848d 100644 --- a/ecmascript/jit/jit_profiler.cpp +++ b/ecmascript/jit/jit_profiler.cpp @@ -366,7 +366,7 @@ void JITProfiler::ProfileBytecode(JSThread *thread, const JSHandleGet(slotId); + JSTaggedValue slotValue = profileTypeInfo_->Get(mainThread_, slotId); if (slotValue.IsInt()) { auto type = slotValue.GetInt(); UpdatePGOType(bcOffset, chunk_->New(type)); @@ -375,7 +375,7 @@ void JITProfiler::ConvertOpType(uint32_t slotId, long bcOffset) void JITProfiler::ConvertCall(uint32_t slotId, long bcOffset) { - JSTaggedValue slotValue = profileTypeInfo_->Get(slotId); + JSTaggedValue slotValue = profileTypeInfo_->Get(mainThread_, slotId); ProfileType::Kind kind; int calleeMethodId = 0; ApEntityId calleeAbcId = 0; @@ -389,7 +389,7 @@ void JITProfiler::ConvertCall(uint32_t slotId, long bcOffset) kind = ProfileType::Kind::BuiltinFunctionId; } else if (slotValue.IsJSFunction()) { JSFunction *callee = JSFunction::Cast(slotValue); - Method *calleeMethod = Method::Cast(callee->GetMethod()); + Method *calleeMethod = Method::Cast(callee->GetMethod(mainThread_)); calleeMethodId = static_cast(calleeMethod->GetMethodId().GetOffset()); if (compilationEnv_->SupportHeapConstant() && calleeMethod->GetFunctionKind() != FunctionKind::ARROW_FUNCTION && @@ -397,13 +397,13 @@ void JITProfiler::ConvertCall(uint32_t slotId, long bcOffset) auto *jitCompilationEnv = static_cast(compilationEnv_); JSHandle calleeHandle = jitCompilationEnv->NewJSHandle(JSTaggedValue(callee)); auto heapConstantIndex = jitCompilationEnv->RecordHeapConstant(calleeHandle); - if (calleeMethod->GetMethodLiteral()->IsTypedCall() && callee->IsCompiledCode()) { + if (calleeMethod->GetMethodLiteral(mainThread_)->IsTypedCall() && callee->IsCompiledCode()) { jitCompilationEnv->RecordCallMethodId2HeapConstantIndex(calleeMethodId, heapConstantIndex); } else { jitCompilationEnv->RecordOnlyInlineMethodId2HeapConstantIndex(calleeMethodId, heapConstantIndex); } } - calleeAbcId = PGOProfiler::GetMethodAbcId(callee); + calleeAbcId = PGOProfiler::GetMethodAbcId(mainThread_, callee); static_cast(compilationEnv_) ->UpdateFuncSlotIdMap(calleeMethodId, methodId_.GetOffset(), slotId); kind = ProfileType::Kind::MethodId; @@ -416,7 +416,7 @@ void JITProfiler::ConvertCall(uint32_t slotId, long bcOffset) void JITProfiler::ConvertNewObjRange(uint32_t slotId, long bcOffset) { - JSTaggedValue slotValue = profileTypeInfo_->Get(slotId); + JSTaggedValue slotValue = profileTypeInfo_->Get(mainThread_, slotId); int ctorMethodId = 0; JSHClass* hclass = nullptr; if (slotValue.IsInt()) { @@ -427,9 +427,9 @@ void JITProfiler::ConvertNewObjRange(uint32_t slotId, long bcOffset) } } else if (slotValue.IsJSFunction()) { JSFunction *callee = JSFunction::Cast(slotValue); - Method *calleeMethod = Method::Cast(callee->GetMethod()); + Method *calleeMethod = Method::Cast(callee->GetMethod(mainThread_)); ctorMethodId = static_cast(calleeMethod->GetMethodId().GetOffset()); - JSTaggedValue protoOrHClass = callee->GetProtoOrHClass(); + JSTaggedValue protoOrHClass = callee->GetProtoOrHClass(mainThread_); if (protoOrHClass.IsJSHClass()) { hclass = JSHClass::Cast(protoOrHClass.GetTaggedObject()); } else { @@ -455,7 +455,7 @@ void JITProfiler::ConvertGetIterator(uint32_t slotId, long bcOffset) if (mainThread_->GetEnableLazyBuiltins()) { return; } - JSTaggedValue value = profileTypeInfo_->Get(slotId); + JSTaggedValue value = profileTypeInfo_->Get(mainThread_, slotId); if (!value.IsInt()) { return; } @@ -468,7 +468,7 @@ void JITProfiler::ConvertGetIterator(uint32_t slotId, long bcOffset) void JITProfiler::ConvertCreateObject(uint32_t slotId, long bcOffset, [[maybe_unused]]int32_t traceId) { - JSTaggedValue slotValue = profileTypeInfo_->Get(slotId); + JSTaggedValue slotValue = profileTypeInfo_->Get(mainThread_, slotId); if (!slotValue.IsHeapObject()) { return; } @@ -482,7 +482,7 @@ void JITProfiler::ConvertCreateObject(uint32_t slotId, long bcOffset, [[maybe_un } } else if (slotValue.IsTrackInfoObject()) { TrackInfo *trackInfo = TrackInfo::Cast(slotValue.GetTaggedObject()); - auto hclass = JSHClass::Cast(trackInfo->GetCachedHClass().GetTaggedObject()); + auto hclass = JSHClass::Cast(trackInfo->GetCachedHClass(mainThread_).GetTaggedObject()); PGODefineOpType* objDefType = chunk_->New(ProfileType::CreateJITType(), hclass); ptManager_->RecordAndGetHclassIndexForJIT(hclass); auto elementsKind = trackInfo->GetElementsKind(); @@ -496,9 +496,9 @@ void JITProfiler::ConvertCreateObject(uint32_t slotId, long bcOffset, [[maybe_un void JITProfiler::ConvertICByName(int32_t bcOffset, uint32_t slotId, BCType type) { ProfileTypeAccessorLockScope accessorLockScope(vm_->GetJSThreadNoCheck()); - JSTaggedValue firstValue = profileTypeInfo_->Get(slotId); + JSTaggedValue firstValue = profileTypeInfo_->Get(mainThread_, slotId); if (!firstValue.IsHeapObject()) { - JSTaggedValue secondValue = profileTypeInfo_->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo_->Get(mainThread_, slotId + 1); if (firstValue.IsHole() && secondValue.IsString()) { // Mega state AddObjectInfoWithMega(bcOffset); @@ -508,7 +508,7 @@ void JITProfiler::ConvertICByName(int32_t bcOffset, uint32_t slotId, BCType type if (firstValue.IsWeak()) { TaggedObject *object = firstValue.GetWeakReferentUnChecked(); if (object->GetClass()->IsHClass()) { - JSTaggedValue secondValue = profileTypeInfo_->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo_->Get(mainThread_, slotId + 1); JSHClass *hclass = JSHClass::Cast(object); ConvertICByNameWithHandler(abcId_, bcOffset, hclass, secondValue, type, slotId + 1); } @@ -558,7 +558,7 @@ void JITProfiler::HandleLoadTypePrototypeHandler(ApEntityId &abcId, int32_t &bcO JSTaggedValue &secondValue, uint32_t slotId, JSTaggedValue name) { auto prototypeHandler = PrototypeHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(mainThread_); if (cellValue.IsUndefined()) { return; } @@ -566,9 +566,9 @@ void JITProfiler::HandleLoadTypePrototypeHandler(ApEntityId &abcId, int32_t &bcO if (cell->GetHasChanged()) { return; } - JSTaggedValue handlerInfoVal = prototypeHandler->GetHandlerInfo(); + JSTaggedValue handlerInfoVal = prototypeHandler->GetHandlerInfo(mainThread_); auto accessorMethodId = prototypeHandler->GetAccessorMethodId(); - auto accessor = prototypeHandler->GetAccessorJSFunction(); + auto accessor = prototypeHandler->GetAccessorJSFunction(mainThread_); if (!handlerInfoVal.IsInt()) { return; } @@ -576,11 +576,11 @@ void JITProfiler::HandleLoadTypePrototypeHandler(ApEntityId &abcId, int32_t &bcO if (HandlerBase::IsNonExist(handlerInfo)) { return; } - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(mainThread_); auto holderHClass = holder.GetTaggedObject()->GetClass(); if (accessor.IsJSFunction()) { auto accessorFunction = JSFunction::Cast(accessor); - auto methodId = Method::Cast(accessorFunction->GetMethod())->GetMethodId().GetOffset(); + auto methodId = Method::Cast(accessorFunction->GetMethod(mainThread_))->GetMethodId().GetOffset(); ASSERT(accessorMethodId == methodId); accessorMethodId = methodId; static_cast(compilationEnv_) @@ -622,7 +622,7 @@ void JITProfiler::HandleTransitionHandler(ApEntityId &abcId, int32_t &bcOffset, JSHClass *hclass, JSTaggedValue &secondValue) { auto transitionHandler = TransitionHandler::Cast(secondValue.GetTaggedObject()); - auto transitionHClassVal = transitionHandler->GetTransitionHClass(); + auto transitionHClassVal = transitionHandler->GetTransitionHClass(mainThread_); if (transitionHClassVal.IsJSHClass()) { auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); AddObjectInfo(abcId, bcOffset, hclass, hclass, transitionHClass); @@ -633,13 +633,13 @@ void JITProfiler::HandleTransWithProtoHandler(ApEntityId &abcId, int32_t &bcOffs JSHClass *hclass, JSTaggedValue &secondValue) { auto transWithProtoHandler = TransWithProtoHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = transWithProtoHandler->GetProtoCell(); + auto cellValue = transWithProtoHandler->GetProtoCell(mainThread_); ASSERT(cellValue.IsProtoChangeMarker()); ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetTaggedObject()); if (cell->GetHasChanged()) { return; } - auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(); + auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(mainThread_); if (transitionHClassVal.IsJSHClass()) { auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); AddObjectInfo(abcId, bcOffset, hclass, hclass, transitionHClass); @@ -650,7 +650,7 @@ void JITProfiler::HandleOtherTypesPrototypeHandler(ApEntityId &abcId, int32_t &b JSHClass *hclass, JSTaggedValue &secondValue, uint32_t slotId) { auto prototypeHandler = PrototypeHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(mainThread_); if (cellValue.IsUndefined()) { return; } @@ -658,13 +658,13 @@ void JITProfiler::HandleOtherTypesPrototypeHandler(ApEntityId &abcId, int32_t &b if (cell->GetHasChanged()) { return; } - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(mainThread_); auto holderHClass = holder.GetTaggedObject()->GetClass(); auto accessorMethodId = prototypeHandler->GetAccessorMethodId(); - auto accessor = prototypeHandler->GetAccessorJSFunction(); + auto accessor = prototypeHandler->GetAccessorJSFunction(mainThread_); if (accessor.IsJSFunction()) { auto accessorFunction = JSFunction::Cast(accessor); - auto methodId = Method::Cast(accessorFunction->GetMethod())->GetMethodId().GetOffset(); + auto methodId = Method::Cast(accessorFunction->GetMethod(mainThread_))->GetMethodId().GetOffset(); ASSERT(accessorMethodId == methodId); accessorMethodId = methodId; static_cast(compilationEnv_) @@ -677,13 +677,13 @@ void JITProfiler::HandleStoreAOTHandler(ApEntityId &abcId, int32_t &bcOffset, JSHClass *hclass, JSTaggedValue &secondValue) { StoreAOTHandler *storeAOTHandler = StoreAOTHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = storeAOTHandler->GetProtoCell(); + auto cellValue = storeAOTHandler->GetProtoCell(mainThread_); ASSERT(cellValue.IsProtoChangeMarker()); ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetTaggedObject()); if (cell->GetHasChanged()) { return; } - auto holder = storeAOTHandler->GetHolder(); + auto holder = storeAOTHandler->GetHolder(mainThread_); auto holderHClass = holder.GetTaggedObject()->GetClass(); AddObjectInfo(abcId, bcOffset, hclass, holderHClass, holderHClass); } @@ -698,8 +698,8 @@ void JITProfiler::ConvertICByNameWithPoly(ApEntityId abcId, int32_t bcOffset, JS auto array = TaggedArray::Cast(cacheValue); 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); - auto handler = array->Get(i + 1); + auto result = array->Get(mainThread_, i); + auto handler = array->Get(mainThread_, i + 1); if (!result.IsHeapObject() || !result.IsWeak()) { continue; } @@ -715,7 +715,7 @@ void JITProfiler::ConvertICByNameWithPoly(ApEntityId abcId, int32_t bcOffset, JS void JITProfiler::ConvertICByValue(int32_t bcOffset, uint32_t slotId, BCType type) { ProfileTypeAccessorLockScope accessorLockScope(vm_->GetJSThreadNoCheck()); - JSTaggedValue firstValue = profileTypeInfo_->Get(slotId); + JSTaggedValue firstValue = profileTypeInfo_->Get(mainThread_, slotId); if (!firstValue.IsHeapObject()) { if (firstValue.IsHole()) { // Mega state @@ -726,7 +726,7 @@ void JITProfiler::ConvertICByValue(int32_t bcOffset, uint32_t slotId, BCType typ if (firstValue.IsWeak()) { TaggedObject *object = firstValue.GetWeakReferentUnChecked(); if (object->GetClass()->IsHClass()) { - JSTaggedValue secondValue = profileTypeInfo_->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo_->Get(mainThread_, slotId + 1); JSHClass *hclass = JSHClass::Cast(object); ConvertICByValueWithHandler(abcId_, bcOffset, hclass, secondValue, type, slotId); } @@ -734,7 +734,7 @@ void JITProfiler::ConvertICByValue(int32_t bcOffset, uint32_t slotId, BCType typ } // Check key if ((firstValue.IsString() || firstValue.IsSymbol())) { - JSTaggedValue secondValue = profileTypeInfo_->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo_->Get(mainThread_, slotId + 1); ConvertICByValueWithPoly(abcId_, bcOffset, firstValue, secondValue, type, slotId); return; } @@ -800,11 +800,11 @@ void JITProfiler::HandleTransition(ApEntityId &abcId, int32_t &bcOffset, JSHClass *hclass, JSTaggedValue &secondValue) { auto transitionHandler = TransitionHandler::Cast(secondValue.GetTaggedObject()); - auto transitionHClassVal = transitionHandler->GetTransitionHClass(); + auto transitionHClassVal = transitionHandler->GetTransitionHClass(mainThread_); if (!transitionHClassVal.IsJSHClass()) { return ; } - auto handlerInfoValue = transitionHandler->GetHandlerInfo(); + auto handlerInfoValue = transitionHandler->GetHandlerInfo(mainThread_); auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); if (handlerInfoValue.IsInt()) { auto handlerInfo = static_cast(handlerInfoValue.GetInt()); @@ -821,11 +821,11 @@ void JITProfiler::HandleTransWithProto(ApEntityId &abcId, int32_t &bcOffset, JSHClass *hclass, JSTaggedValue &secondValue) { auto transWithProtoHandler = TransWithProtoHandler::Cast(secondValue.GetTaggedObject()); - auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(); + auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(mainThread_); if (!transitionHClassVal.IsJSHClass()) { return ; } - auto handlerInfoValue = transWithProtoHandler->GetHandlerInfo(); + auto handlerInfoValue = transWithProtoHandler->GetHandlerInfo(mainThread_); auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); if (handlerInfoValue.IsInt()) { auto handlerInfo = static_cast(handlerInfoValue.GetInt()); @@ -842,7 +842,7 @@ void JITProfiler::HandlePrototypeHandler(ApEntityId &abcId, int32_t &bcOffset, JSHClass *hclass, JSTaggedValue &secondValue) { PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(mainThread_); if (!cellValue.IsProtoChangeMarker()) { return; } @@ -851,7 +851,7 @@ void JITProfiler::HandlePrototypeHandler(ApEntityId &abcId, int32_t &bcOffset, if (cell->GetHasChanged()) { return; } - JSTaggedValue handlerInfoValue = prototypeHandler->GetHandlerInfo(); + JSTaggedValue handlerInfoValue = prototypeHandler->GetHandlerInfo(mainThread_); if (handlerInfoValue.IsInt()) { auto handlerInfo = static_cast(handlerInfoValue.GetInt()); if (HandlerBase::IsElement(handlerInfo)) { @@ -860,7 +860,7 @@ void JITProfiler::HandlePrototypeHandler(ApEntityId &abcId, int32_t &bcOffset, return; } } - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(mainThread_); auto holderHClass = holder.GetTaggedObject()->GetClass(); AddObjectInfo(abcId, bcOffset, hclass, holderHClass, holderHClass); } @@ -880,8 +880,8 @@ void JITProfiler::ConvertICByValueWithPoly(ApEntityId abcId, int32_t bcOffset, auto array = TaggedArray::Cast(cacheValue); 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); - auto handler = array->Get(i + 1); + auto result = array->Get(mainThread_, i); + auto handler = array->Get(mainThread_, i + 1); if (!result.IsHeapObject() || !result.IsWeak()) { continue; } @@ -902,7 +902,7 @@ void JITProfiler::ConvertExternalModuleVar(uint32_t index, uint32_t bcOffset) if (jsfunc == nullptr) { return; } - if (!ModuleManager::CheckModuleValueOutterResolved(index, jsfunc)) { + if (!ModuleManager::CheckModuleValueOutterResolved(mainThread_, index, jsfunc)) { return; } @@ -911,7 +911,7 @@ void JITProfiler::ConvertExternalModuleVar(uint32_t index, uint32_t bcOffset) void JITProfiler::ConvertInstanceof(int32_t bcOffset, uint32_t slotId) { - JSTaggedValue firstValue = profileTypeInfo_->Get(slotId); + JSTaggedValue firstValue = profileTypeInfo_->Get(mainThread_, slotId); if (!firstValue.IsHeapObject()) { if (firstValue.IsHole()) { // Mega state @@ -945,11 +945,11 @@ void JITProfiler::ConvertTryldGlobalByName(uint32_t bcOffset, uint32_t slotId) if (!jitCompilationEnv->SupportHeapConstant()) { return; } - JSTaggedValue handler = profileTypeInfo_->Get(slotId); + JSTaggedValue handler = profileTypeInfo_->Get(mainThread_, slotId); if (handler.IsHeapObject()) { ASSERT(handler.IsPropertyBox()); PropertyBox *cell = PropertyBox::Cast(handler.GetTaggedObject()); - if (cell->IsInvalid() || cell->GetValue().IsAccessorData()) { + if (cell->IsInvalid(mainThread_) || cell->GetValue(mainThread_).IsAccessorData()) { return; } JSHandle boxHandle = jitCompilationEnv->NewJSHandle(handler); @@ -975,15 +975,15 @@ JSTaggedValue JITProfiler::TryFindKeyInPrototypeChain(TaggedObject *currObj, JSH return JSTaggedValue(currHC); } } else { - TaggedArray *array = TaggedArray::Cast(JSObject::Cast(currObj)->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(JSObject::Cast(currObj)->GetProperties(mainThread_).GetTaggedObject()); ASSERT(array->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(mainThread_, key); if (entry != -1) { return JSTaggedValue(currHC); } } - auto proto = currHC->GetProto(); + auto proto = currHC->GetProto(mainThread_); if (!proto.IsHeapObject()) { return JSTaggedValue::Undefined(); } @@ -1029,7 +1029,7 @@ bool JITProfiler::AddObjectInfo(ApEntityId abcId, int32_t bcOffset, JSHClass *re { PGOSampleType accessor = PGOSampleType::CreateProfileType(abcId, accessorMethodId, ProfileType::Kind::MethodId); // case: obj = Object.create(null) => LowerProtoChangeMarkerCheck Crash - if (receiver->GetPrototype().IsNull()) { + if (receiver->GetPrototype(mainThread_).IsNull()) { return false; } return AddTranstionObjectInfo(bcOffset, receiver, hold, holdTra, accessor, primitiveType, name); @@ -1182,12 +1182,12 @@ bool JITProfiler::IsIncompleteProfileTypeInfo() // We may receive an incomplete profile typeinfo. During the execution of a larger function, when the upper part of // the function is executed, profiltypeinfo has not yet been created. When profiltypeinfo is created and Jit is // triggered, the first half of profiltypeinfo becomes empty. - return profileTypeInfo_->Get(0).IsUndefined(); + return profileTypeInfo_->Get(mainThread_, 0).IsUndefined(); } bool JITProfiler::SlotValueIsUndefined(uint32_t slotId) { - return profileTypeInfo_->Get(slotId).IsUndefined(); + return profileTypeInfo_->Get(mainThread_, slotId).IsUndefined(); } void JITProfiler::UpdateBcOffsetBool(uint32_t offset, uint32_t slotId) diff --git a/ecmascript/jit/jit_task.cpp b/ecmascript/jit/jit_task.cpp index 01733eeeeb..5a1cfbe8f0 100644 --- a/ecmascript/jit/jit_task.cpp +++ b/ecmascript/jit/jit_task.cpp @@ -57,8 +57,8 @@ void JitTask::PrepareCompile() SustainingJSHandles(); compilerTask_ = jit_->CreateJitCompilerTask(this); - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); - JSTaggedValue constpool = method->GetConstantPool(); + Method *method = Method::Cast(jsFunction_->GetMethod(hostThread_).GetTaggedObject()); + JSTaggedValue constpool = method->GetConstantPool(hostThread_); if (!ConstantPool::CheckUnsharedConstpool(constpool)) { hostThread_->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpool); } @@ -90,7 +90,7 @@ void JitTask::Finalize() void JitTask::InstallOsrCode(JSHandle &codeObj) { - auto profile = jsFunction_->GetProfileTypeInfo(); + auto profile = jsFunction_->GetProfileTypeInfo(hostThread_); if (profile.IsUndefined()) { LOG_JIT(DEBUG) << "[OSR] Empty profile for installing code:" << GetMethodName(); return; @@ -99,7 +99,7 @@ void JitTask::InstallOsrCode(JSHandle &codeObj) JSHandle profileInfoHandle = JSHandle::Cast(JSHandle(hostThread_, profile)); uint32_t slotId = profileInfoHandle->GetIcSlotToOsrLength() - 1; // 1 : get last slot - auto profileData = profileInfoHandle->Get(slotId); + auto profileData = profileInfoHandle->Get(hostThread_, slotId); auto factory = hostThread_->GetEcmaVM()->GetFactory(); if (!profileData.IsTaggedArray()) { const uint32_t initLen = 1; @@ -115,7 +115,7 @@ void JitTask::InstallOsrCode(JSHandle &codeObj) JSHandle newArr = factory->NewTaggedArray(arr->GetLength() + 1); // 1 : added for current codeObj uint32_t i = 0; for (; i < arr->GetLength(); i++) { - newArr->Set(hostThread_, i, arr->Get(i)); + newArr->Set(hostThread_, i, arr->Get(hostThread_, i)); } newArr->Set(hostThread_, i, codeObj.GetTaggedValue()); profileInfoHandle->Set(hostThread_, slotId, newArr.GetTaggedValue()); @@ -215,7 +215,7 @@ size_t JitTask::ComputePayLoadSize(MachineCodeDesc &codeDesc) } } -void DumpJitCode(JSHandle &machineCode, JSHandle &method) +void DumpJitCode(const JSThread *thread, JSHandle &machineCode, JSHandle &method) { if (!ohos::JitTools::GetJitDumpObjEanble()) { return; @@ -229,7 +229,7 @@ void DumpJitCode(JSHandle &machineCode, JSHandle &method) LOG_JIT(DEBUG) << "Fail to get machineCode on function addr: " << funcAddr; } jitDumpElf.AppendData(vec); - const char *filename = method->GetMethodName(); + const char *filename = method->GetMethodName(thread); std::string fileName = std::string(filename); uintptr_t addr = machineCode->GetFuncAddr(); fileName = fileName + "_" + std::to_string(addr) + "+" + std::to_string(len); @@ -280,7 +280,7 @@ void JitTask::InstallCode() return; } [[maybe_unused]] EcmaHandleScope handleScope(hostThread_); - JSHandle methodHandle(hostThread_, Method::Cast(jsFunction_->GetMethod().GetTaggedObject())); + JSHandle methodHandle(hostThread_, Method::Cast(jsFunction_->GetMethod(hostThread_).GetTaggedObject())); size_t size = ComputePayLoadSize(codeDesc_); codeDesc_.isAsyncCompileMode = IsAsyncTask(); @@ -340,7 +340,7 @@ void JitTask::InstallCode() if (compilerTier_.IsFast()) { jsFunction_->SetJitCompilingFlag(false); - jsFunction_->SetJitHotnessCnt(0); + jsFunction_->SetJitHotnessCnt(hostThread_, 0); } else { ASSERT(compilerTier_.IsBaseLine()); jsFunction_->SetBaselinejitCompilingFlag(false); @@ -394,9 +394,9 @@ void JitTask::CloneProfileTypeInfo() { [[maybe_unused]] EcmaHandleScope handleScope(hostThread_); - Method *method = Method::Cast(jsFunction_->GetMethod().GetTaggedObject()); + Method *method = Method::Cast(jsFunction_->GetMethod(hostThread_).GetTaggedObject()); uint32_t slotSize = method->GetSlotSize(); - JSTaggedValue profileTypeInfoVal = jsFunction_->GetProfileTypeInfo(); + JSTaggedValue profileTypeInfoVal = jsFunction_->GetProfileTypeInfo(hostThread_); JSHandle newProfileTypeInfo; ObjectFactory *factory = hostThread_->GetEcmaVM()->GetFactory(); if (profileTypeInfoVal.IsUndefined() || slotSize == 0) { @@ -407,7 +407,7 @@ void JitTask::CloneProfileTypeInfo() ProfileTypeInfo::Cast(profileTypeInfoVal.GetTaggedObject())); newProfileTypeInfo = factory->NewProfileTypeInfo(slotSize); for (uint32_t i = 0; i < slotSize; i++) { - JSTaggedValue value = profileTypeInfo->Get(i); + JSTaggedValue value = profileTypeInfo->Get(hostThread_, i); newProfileTypeInfo->Set(hostThread_, i, value); } } diff --git a/ecmascript/jobs/micro_job_queue.cpp b/ecmascript/jobs/micro_job_queue.cpp index 9bfef5e085..274e1bb314 100644 --- a/ecmascript/jobs/micro_job_queue.cpp +++ b/ecmascript/jobs/micro_job_queue.cpp @@ -24,8 +24,8 @@ namespace panda::ecmascript::job { uint32_t MicroJobQueue::GetPromiseQueueSize(JSThread *thread, JSHandle jobQueue) { [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); - return promiseQueue->Size(); + JSHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue(thread)); + return promiseQueue->Size(thread); } void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle jobQueue, QueueType queueType, @@ -43,12 +43,12 @@ void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle jobQueu ENQUEUE_JOB_TRACE(thread, pendingJob); if (queueType == QueueType::QUEUE_PROMISE) { - JSHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); + JSHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue(thread)); TaggedQueue *newPromiseQueue = TaggedQueue::Push(thread, promiseQueue, JSHandle(pendingJob)); jobQueue->SetPromiseJobQueue(thread, JSTaggedValue(newPromiseQueue)); - LOG_ECMA(VERBOSE) << "EnqueueJob length: " << newPromiseQueue->Size(); + LOG_ECMA(VERBOSE) << "EnqueueJob length: " << newPromiseQueue->Size(thread); } else if (queueType == QueueType::QUEUE_SCRIPT) { - JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue()); + JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue(thread)); TaggedQueue *newScriptQueue = TaggedQueue::Push(thread, scriptQueue, JSHandle(pendingJob)); jobQueue->SetScriptJobQueue(thread, JSTaggedValue(newScriptQueue)); } @@ -57,10 +57,10 @@ void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle jobQueu void MicroJobQueue::ExecutePendingJob(JSThread *thread, JSHandle jobQueue) { [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSMutableHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); + JSMutableHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue(thread)); JSMutableHandle pendingJob(thread, JSTaggedValue::Undefined()); - while (!promiseQueue->Empty()) { - LOG_ECMA(VERBOSE) << "ExecutePendingJob length: " << promiseQueue->Size(); + while (!promiseQueue->Empty(thread)) { + LOG_ECMA(VERBOSE) << "ExecutePendingJob length: " << promiseQueue->Size(thread); pendingJob.Update(promiseQueue->Pop(thread)); PendingJob::ExecutePendingJob(pendingJob, thread); if (!thread->IsInConcurrentScope()) { @@ -74,11 +74,11 @@ void MicroJobQueue::ExecutePendingJob(JSThread *thread, JSHandle jobQueue->SetPromiseJobQueue(thread, emptyQueue); return; } - promiseQueue.Update(jobQueue->GetPromiseJobQueue()); + promiseQueue.Update(jobQueue->GetPromiseJobQueue(thread)); } - JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue()); - while (!scriptQueue->Empty()) { + JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue(thread)); + while (!scriptQueue->Empty(thread)) { pendingJob.Update(scriptQueue->Pop(thread)); PendingJob::ExecutePendingJob(pendingJob, thread); if (thread->HasPendingException()) { diff --git a/ecmascript/jobs/pending_job.h b/ecmascript/jobs/pending_job.h index aa439bf94b..eaf143e332 100644 --- a/ecmascript/jobs/pending_job.h +++ b/ecmascript/jobs/pending_job.h @@ -42,21 +42,21 @@ public: EXECUTE_JOB_HITRACE(pendingJob); EXECUTE_JOB_TRACE(thread, pendingJob); - JSHandle job(thread, pendingJob->GetJob()); + JSHandle job(thread, pendingJob->GetJob(thread)); ASSERT(job->IsCallable()); - JSHandle argv(thread, pendingJob->GetArguments()); + JSHandle argv(thread, pendingJob->GetArguments(thread)); const uint32_t argsLength = argv->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); bool stackTrace = thread->GetEcmaVM()->GetJsDebuggerManager()->IsAsyncStackTrace(); if (stackTrace && argsLength >= 1) { - thread->GetEcmaVM()->GetAsyncStackTrace()->InsertCurrentAsyncTaskStack(argv->Get(0)); + thread->GetEcmaVM()->GetAsyncStackTrace()->InsertCurrentAsyncTaskStack(argv->Get(thread, 0)); } EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, job, undefined, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(argsLength, argv); JSTaggedValue result = JSFunction::Call(info); if (stackTrace && argsLength >= 1) { - thread->GetEcmaVM()->GetAsyncStackTrace()->RemoveAsyncTaskStack(argv->Get(0)); + thread->GetEcmaVM()->GetAsyncStackTrace()->RemoveAsyncTaskStack(argv->Get(thread, 0)); } return result; } diff --git a/ecmascript/jobs/tests/micro_job_queue_test.cpp b/ecmascript/jobs/tests/micro_job_queue_test.cpp index 7f2feef7fd..2afae72fda 100644 --- a/ecmascript/jobs/tests/micro_job_queue_test.cpp +++ b/ecmascript/jobs/tests/micro_job_queue_test.cpp @@ -77,14 +77,14 @@ HWTEST_F_L0(MicroJobQueueTest, GetJobQueue) handleMicroJobQueue->SetPromiseJobQueue(thread, handlePromiseQueue.GetTaggedValue()); handleMicroJobQueue->SetScriptJobQueue(thread, handleScriptQueue.GetTaggedValue()); - JSHandle promiseQueue(thread, handleMicroJobQueue->GetPromiseJobQueue()); - JSHandle scriptQueue(thread, handleMicroJobQueue->GetScriptJobQueue()); + JSHandle promiseQueue(thread, handleMicroJobQueue->GetPromiseJobQueue(thread)); + JSHandle scriptQueue(thread, handleMicroJobQueue->GetScriptJobQueue(thread)); - EXPECT_EQ(promiseQueue->Size(), 1U); - EXPECT_EQ(scriptQueue->Size(), 0U); + EXPECT_EQ(promiseQueue->Size(thread), 1U); + EXPECT_EQ(scriptQueue->Size(thread), 0U); - EXPECT_EQ(promiseQueue->Back().GetInt(), 123); - EXPECT_TRUE(scriptQueue->Back().IsHole()); + EXPECT_EQ(promiseQueue->Back(thread).GetInt(), 123); + EXPECT_TRUE(scriptQueue->Back(thread).IsHole()); } /** @@ -100,8 +100,8 @@ HWTEST_F_L0(MicroJobQueueTest, EnqueuePromiseJob) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle handleMicrojob = thread->GetEcmaVM()->GetMicroJobQueue(); - JSHandle originalPromiseQueue(thread, handleMicrojob->GetPromiseJobQueue()); - JSHandle scriptQueue(thread, handleMicrojob->GetScriptJobQueue()); + JSHandle originalPromiseQueue(thread, handleMicrojob->GetPromiseJobQueue(thread)); + JSHandle scriptQueue(thread, handleMicrojob->GetScriptJobQueue(thread)); JSHandle arguments = factory->NewTaggedArray(2); arguments->Set(thread, 0, JSTaggedValue::Undefined()); @@ -111,16 +111,16 @@ HWTEST_F_L0(MicroJobQueueTest, EnqueuePromiseJob) QueueType type = QueueType::QUEUE_PROMISE; MicroJobQueue::EnqueueJob(thread, handleMicrojob, type, promiseReactionsJob, arguments); - JSHandle promiseQueue(thread, handleMicrojob->GetPromiseJobQueue()); - EXPECT_EQ(JSTaggedValue::SameValue(promiseQueue.GetTaggedValue(), originalPromiseQueue.GetTaggedValue()), false); - EXPECT_EQ(JSTaggedValue::SameValue(handleMicrojob->GetScriptJobQueue(), scriptQueue.GetTaggedValue()), true); + JSHandle promiseQueue(thread, handleMicrojob->GetPromiseJobQueue(thread)); + EXPECT_EQ(JSTaggedValue::SameValue(thread, promiseQueue.GetTaggedValue(), originalPromiseQueue.GetTaggedValue()), false); + EXPECT_EQ(JSTaggedValue::SameValue(thread, handleMicrojob->GetScriptJobQueue(thread), scriptQueue.GetTaggedValue()), true); JSTaggedValue result = promiseQueue->Pop(thread); EXPECT_TRUE(result.IsPendingJob()); JSHandle pendingJob(thread, result); - EXPECT_EQ(JSTaggedValue::SameValue(pendingJob->GetJob(), promiseReactionsJob.GetTaggedValue()), true); - EXPECT_EQ(JSTaggedValue::SameValue(pendingJob->GetArguments(), arguments.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, pendingJob->GetJob(thread), promiseReactionsJob.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, pendingJob->GetArguments(thread), arguments.GetTaggedValue()), true); } /** @@ -136,8 +136,8 @@ HWTEST_F_L0(MicroJobQueueTest, EnqueueScriptJob) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle handleMicrojob = thread->GetEcmaVM()->GetMicroJobQueue(); - JSHandle promiseQueue(thread, handleMicrojob->GetPromiseJobQueue()); - JSHandle originalScriptQueue(thread, handleMicrojob->GetScriptJobQueue()); + JSHandle promiseQueue(thread, handleMicrojob->GetPromiseJobQueue(thread)); + JSHandle originalScriptQueue(thread, handleMicrojob->GetScriptJobQueue(thread)); JSHandle arguments1 = factory->NewTaggedArray(2); JSHandle promiseReactionsJob(globalEnv->GetPromiseReactionJob()); @@ -151,22 +151,22 @@ HWTEST_F_L0(MicroJobQueueTest, EnqueueScriptJob) arguments2->Set(thread, 1, JSTaggedValue::Undefined()); MicroJobQueue::EnqueueJob(thread, handleMicrojob, type, promiseResolveThenableJob, arguments2); - JSHandle scriptQueue(thread, handleMicrojob->GetScriptJobQueue()); - EXPECT_EQ(JSTaggedValue::SameValue(scriptQueue.GetTaggedValue(), originalScriptQueue.GetTaggedValue()), false); - EXPECT_EQ(JSTaggedValue::SameValue(handleMicrojob->GetPromiseJobQueue(), promiseQueue.GetTaggedValue()), true); + JSHandle scriptQueue(thread, handleMicrojob->GetScriptJobQueue(thread)); + EXPECT_EQ(JSTaggedValue::SameValue(thread, scriptQueue.GetTaggedValue(), originalScriptQueue.GetTaggedValue()), false); + EXPECT_EQ(JSTaggedValue::SameValue(thread, handleMicrojob->GetPromiseJobQueue(thread), promiseQueue.GetTaggedValue()), true); JSTaggedValue result1 = scriptQueue->Pop(thread); EXPECT_TRUE(result1.IsPendingJob()); // FIFO JSHandle pendingJob1(thread, result1); - EXPECT_EQ(JSTaggedValue::SameValue(pendingJob1->GetJob(), promiseReactionsJob.GetTaggedValue()), true); - EXPECT_EQ(JSTaggedValue::SameValue(pendingJob1->GetArguments(), arguments1.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, pendingJob1->GetJob(thread), promiseReactionsJob.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, pendingJob1->GetArguments(thread), arguments1.GetTaggedValue()), true); JSTaggedValue result2 = scriptQueue->Pop(thread); EXPECT_TRUE(result2.IsPendingJob()); JSHandle pendingJob2(thread, result2); - EXPECT_EQ(JSTaggedValue::SameValue(pendingJob2->GetJob(), promiseResolveThenableJob.GetTaggedValue()), true); - EXPECT_EQ(JSTaggedValue::SameValue(pendingJob2->GetArguments(), arguments2.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, pendingJob2->GetJob(thread), promiseResolveThenableJob.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, pendingJob2->GetArguments(thread), arguments2.GetTaggedValue()), true); } /** @@ -187,7 +187,7 @@ HWTEST_F_L0(MicroJobQueueTest, ExecutePendingJob_001) JSHandle promiseFunc = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promiseFunc); - JSHandle resolve(thread, capbility->GetResolve()); + JSHandle resolve(thread, capbility->GetResolve(thread)); JSHandle fulfillReaction = factory->NewPromiseReaction(); fulfillReaction->SetPromiseCapability(thread, capbility.GetTaggedValue()); @@ -206,9 +206,9 @@ HWTEST_F_L0(MicroJobQueueTest, ExecutePendingJob_001) if (!thread->HasPendingException()) { MicroJobQueue::ExecutePendingJob(thread, handleMicrojob); } - JSHandle jsPromise(thread, capbility->GetPromise()); + JSHandle jsPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(jsPromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(jsPromise->GetPromiseResult(), JSTaggedValue::Undefined()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsPromise->GetPromiseResult(thread), JSTaggedValue::Undefined()), true); } /** @@ -230,7 +230,7 @@ HWTEST_F_L0(MicroJobQueueTest, ExecutePendingJob_002) JSHandle promiseFunc = env->GetPromiseFunction(); JSHandle capbility1 = JSPromise::NewPromiseCapability(thread, promiseFunc); - JSHandle resolve(thread, capbility1->GetResolve()); + JSHandle resolve(thread, capbility1->GetResolve(thread)); JSHandle fulfillReaction = factory->NewPromiseReaction(); fulfillReaction->SetPromiseCapability(thread, capbility1.GetTaggedValue()); @@ -242,7 +242,7 @@ HWTEST_F_L0(MicroJobQueueTest, ExecutePendingJob_002) MicroJobQueue::EnqueueJob(thread, handleMicrojob, QueueType::QUEUE_PROMISE, promiseReactionsJob, arguments1); JSHandle capbility2 = JSPromise::NewPromiseCapability(thread, promiseFunc); - JSHandle reject(thread, capbility2->GetReject()); + JSHandle reject(thread, capbility2->GetReject(thread)); JSHandle rejectReaction = factory->NewPromiseReaction(); rejectReaction->SetPromiseCapability(thread, capbility2.GetTaggedValue()); rejectReaction->SetHandler(thread, reject.GetTaggedValue()); @@ -256,12 +256,12 @@ HWTEST_F_L0(MicroJobQueueTest, ExecutePendingJob_002) if (!thread->HasPendingException()) { MicroJobQueue::ExecutePendingJob(thread, handleMicrojob); } - JSHandle resolvePromise(thread, capbility1->GetPromise()); + JSHandle resolvePromise(thread, capbility1->GetPromise(thread)); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue::Undefined()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resolvePromise->GetPromiseResult(thread), JSTaggedValue::Undefined()), true); - JSHandle rejectPromise(thread, capbility2->GetPromise()); + JSHandle rejectPromise(thread, capbility2->GetPromise(thread)); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(32)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejectPromise->GetPromiseResult(thread), JSTaggedValue(32)), true); } } // namespace panda::test diff --git a/ecmascript/jobs/tests/pending_job_test.cpp b/ecmascript/jobs/tests/pending_job_test.cpp index 005c79035b..a56d0157a7 100644 --- a/ecmascript/jobs/tests/pending_job_test.cpp +++ b/ecmascript/jobs/tests/pending_job_test.cpp @@ -70,11 +70,11 @@ HWTEST_F_L0(PendingJobTest, GetJob) JSHandle handlePendingJobVal(factory->NewPendingJob(handleFunc, handleArgv)); EXPECT_TRUE(handlePendingJobVal->IsPendingJob()); JSHandle handlePendingJob(handlePendingJobVal); - EXPECT_TRUE(handlePendingJob->GetJob().IsJSFunction()); + EXPECT_TRUE(handlePendingJob->GetJob(thread).IsJSFunction()); JSHandle handleNativeFunc(env->GetTypedArrayFunction()); handlePendingJob->SetJob(thread, handleNativeFunc.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(handlePendingJob->GetJob(), handleNativeFunc.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, handlePendingJob->GetJob(thread), handleNativeFunc.GetTaggedValue()), true); } /** @@ -94,15 +94,15 @@ HWTEST_F_L0(PendingJobTest, GetArguments) JSHandle handlePendingJobVal(factory->NewPendingJob(handleFunc, handleArgv1)); EXPECT_TRUE(handlePendingJobVal->IsPendingJob()); JSHandle handlePendingJob(handlePendingJobVal); - EXPECT_TRUE(handlePendingJob->GetArguments().IsTaggedArray()); + EXPECT_TRUE(handlePendingJob->GetArguments(thread).IsTaggedArray()); JSHandle handleArgv2 = factory->NewTaggedArray(1); handleArgv2->Set(thread, 0, JSTaggedValue(1)); handlePendingJob->SetArguments(thread, handleArgv2.GetTaggedValue()); - JSHandle resultArray(thread, handlePendingJob->GetArguments()); + JSHandle resultArray(thread, handlePendingJob->GetArguments(thread)); EXPECT_EQ(resultArray->GetLength(), 1U); - EXPECT_EQ(resultArray->Get(0).GetInt(), 1); + EXPECT_EQ(resultArray->Get(thread, 0).GetInt(), 1); } /** @@ -121,7 +121,7 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_001) JSHandle promiseFunc = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promiseFunc); - JSHandle reject(thread, capbility->GetReject()); + JSHandle reject(thread, capbility->GetReject(thread)); JSHandle rejectReaction = factory->NewPromiseReaction(); rejectReaction->SetPromiseCapability(thread, capbility.GetTaggedValue()); @@ -135,9 +135,9 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_001) JSHandle handlePendingJob = factory->NewPendingJob(promiseReactionsJob, handleArgv); JSTaggedValue callResult = PendingJob::ExecutePendingJob(handlePendingJob, thread); EXPECT_EQ(callResult, JSTaggedValue::Undefined()); - JSHandle jsPromise(thread, capbility->GetPromise()); + JSHandle jsPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(jsPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(jsPromise->GetPromiseResult(), JSTaggedValue(44)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsPromise->GetPromiseResult(thread), JSTaggedValue(44)), true); } /** @@ -157,7 +157,7 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_002) JSHandle paramMsg(factory->NewFromASCII("resolve")); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promiseFunc); - JSHandle resolve(thread, capbility->GetResolve()); + JSHandle resolve(thread, capbility->GetResolve(thread)); JSHandle fulfillReaction = factory->NewPromiseReaction(); fulfillReaction->SetPromiseCapability(thread, capbility.GetTaggedValue()); @@ -171,9 +171,9 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_002) JSHandle handlePendingJob = factory->NewPendingJob(promiseReactionsJob, handleArgv); JSTaggedValue callResult = PendingJob::ExecutePendingJob(handlePendingJob, thread); EXPECT_EQ(callResult, JSTaggedValue::Undefined()); - JSHandle jsPromise(thread, capbility->GetPromise()); + JSHandle jsPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(jsPromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(jsPromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsPromise->GetPromiseResult(thread), paramMsg.GetTaggedValue()), true); } /** @@ -205,20 +205,21 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_003) JSHandle handlePendingJob = factory->NewPendingJob(promiseReactionsJob, handleArgv); JSTaggedValue callResult = PendingJob::ExecutePendingJob(handlePendingJob, thread); EXPECT_EQ(callResult, JSTaggedValue::Undefined()); - JSHandle jsPromise(thread, capbility->GetPromise()); + JSHandle jsPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(jsPromise->GetPromiseState(), PromiseState::REJECTED); - EXPECT_EQ(JSTaggedValue::SameValue(jsPromise->GetPromiseResult(), JSTaggedValue::Undefined()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsPromise->GetPromiseResult(thread), JSTaggedValue::Undefined()), true); } JSTaggedValue TestPromiseOnResolved(EcmaRuntimeCallInfo *argv) { - auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); + auto thread = argv->GetThread(); + auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle result = BuiltinsBase::GetCallArg(argv, 0); EXPECT_TRUE(result->IsPromiseReaction()); auto handlerMsg = factory->NewFromASCII("after_resolve"); JSHandle reaction = JSHandle::Cast(result); - JSHandle handler(argv->GetThread(), reaction->GetHandler()); - EXPECT_EQ(JSTaggedValue::SameValue(handler.GetTaggedValue(), handlerMsg.GetTaggedValue()), true); + JSHandle handler(argv->GetThread(), reaction->GetHandler(argv->GetThread())); + EXPECT_EQ(JSTaggedValue::SameValue(thread, handler.GetTaggedValue(), handlerMsg.GetTaggedValue()), true); return JSTaggedValue::Undefined(); } @@ -239,7 +240,7 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_004) JSHandle paramMsg(factory->NewFromASCII("after_resolve")); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promiseFunc); - JSHandle resolve(thread, capbility->GetResolve()); + JSHandle resolve(thread, capbility->GetResolve(thread)); JSHandle fulfillReaction = factory->NewPromiseReaction(); fulfillReaction->SetPromiseCapability(thread, capbility.GetTaggedValue()); @@ -254,9 +255,9 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_004) JSHandle handlePendingJob = factory->NewPendingJob(testPromiseResolved, handleArgv); JSTaggedValue callResult = PendingJob::ExecutePendingJob(handlePendingJob, thread); EXPECT_EQ(callResult, JSTaggedValue::Undefined()); - JSHandle jsPromise(thread, capbility->GetPromise()); + JSHandle jsPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(jsPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(jsPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(jsPromise->GetPromiseResult(thread).IsUndefined(), true); } JSTaggedValue TestPromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) @@ -302,6 +303,6 @@ HWTEST_F_L0(PendingJobTest, ExecutePendingJob_005) EXPECT_EQ(callResult, JSTaggedValue::Undefined()); EXPECT_EQ(jsPromise->GetPromiseState(), PromiseState::FULFILLED); - EXPECT_EQ(JSTaggedValue::SameValue(jsPromise->GetPromiseResult(), JSTaggedValue(44)), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsPromise->GetPromiseResult(thread), JSTaggedValue(44)), true); } } // namespace panda::test diff --git a/ecmascript/js_api/js_api_arraylist.cpp b/ecmascript/js_api/js_api_arraylist.cpp index 490380e5c9..a9ef176c9a 100644 --- a/ecmascript/js_api/js_api_arraylist.cpp +++ b/ecmascript/js_api/js_api_arraylist.cpp @@ -26,19 +26,19 @@ using ErrorFlag = containers::ErrorFlag; bool JSAPIArrayList::Add(JSThread *thread, const JSHandle &arrayList, const JSHandle &value) { - uint32_t length = arrayList->GetLength().GetArrayLength(); + uint32_t length = arrayList->GetLength(); JSHandle elements = GrowCapacity(thread, arrayList, length + 1); ASSERT(!elements->IsDictionaryMode()); elements->Set(thread, length, value); - arrayList->SetLength(thread, JSTaggedValue(++length)); + arrayList->SetLength(++length); return true; } void JSAPIArrayList::Insert(JSThread *thread, const JSHandle &arrayList, const JSHandle &value, const int &index) { - int length = arrayList->GetLength().GetInt(); + int length = arrayList->GetLength(); if (index < 0 || index > length) { std::ostringstream oss; oss << "The value of \"index\" is out of range. It must be >= 0 && <= " << length @@ -49,34 +49,34 @@ void JSAPIArrayList::Insert(JSThread *thread, const JSHandle &ar JSHandle elements = GrowCapacity(thread, arrayList, length + 1); ASSERT(!elements->IsDictionaryMode()); for (int i = length - 1; i >= index; --i) { - elements->Set(thread, i + 1, elements->Get(i)); + elements->Set(thread, i + 1, elements->Get(thread, i)); } elements->Set(thread, index, value); - arrayList->SetLength(thread, JSTaggedValue(++length)); + arrayList->SetLength(++length); } void JSAPIArrayList::Clear(JSThread *thread, const JSHandle &arrayList) { if (!arrayList.IsEmpty()) { - int length = arrayList->GetLength().GetInt(); - JSHandle elements(thread, arrayList->GetElements()); + int length = arrayList->GetLength(); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); for (int i = 0; i < length; ++i) { elements->Set(thread, i, JSTaggedValue::Hole()); } - arrayList->SetLength(thread, JSTaggedValue(0)); + arrayList->SetLength(0); } } JSHandle JSAPIArrayList::Clone(JSThread *thread, const JSHandle &obj) { - JSHandle srcElements(thread, obj->GetElements()); + JSHandle srcElements(thread, obj->GetElements(thread)); ASSERT(!srcElements->IsDictionaryMode()); uint32_t length = obj->GetSize(); auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle newArrayList = factory->NewJSAPIArrayList(0); - newArrayList->SetLength(thread, JSTaggedValue(length)); + newArrayList->SetLength(length); JSHandle dstElements = factory->NewAndCopyTaggedArray(srcElements, length, length); newArrayList->SetElements(thread, dstElements); @@ -85,7 +85,7 @@ JSHandle JSAPIArrayList::Clone(JSThread *thread, const JSHandle< uint32_t JSAPIArrayList::GetCapacity(JSThread *thread, const JSHandle &obj) { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); uint32_t capacity = elements->GetLength(); return capacity; @@ -94,9 +94,9 @@ uint32_t JSAPIArrayList::GetCapacity(JSThread *thread, const JSHandle &arrayList, int capacity) { - JSHandle elementData(thread, arrayList->GetElements()); + JSHandle elementData(thread, arrayList->GetElements(thread)); ASSERT(!elementData->IsDictionaryMode()); - int length = arrayList->GetLength().GetInt(); + int length = arrayList->GetLength(); int oldElementLength = static_cast(elementData->GetLength()); if (oldElementLength != capacity && length < capacity) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -108,9 +108,9 @@ void JSAPIArrayList::IncreaseCapacityTo(JSThread *thread, const JSHandle &arrayList) { - uint32_t length = arrayList->GetLength().GetArrayLength(); + uint32_t length = arrayList->GetLength(); uint32_t capacity = JSAPIArrayList::GetCapacity(thread, arrayList); - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); if (capacity > length) { elements->Trim(thread, length); @@ -119,21 +119,21 @@ void JSAPIArrayList::TrimToCurrentLength(JSThread *thread, const JSHandle= GetLength().GetArrayLength()) { - ASSERT(GetLength().GetArrayLength() > 0); + if (index >= GetLength()) { + ASSERT(GetLength() > 0); std::ostringstream oss; oss << "The value of \"index\" is out of range. It must be >= 0 && <= " - << (GetLength().GetArrayLength() - 1) << ". Received value is: " << index; + << (GetLength() - 1) << ". Received value is: " << index; JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); - return elements->Get(index); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); + return elements->Get(thread, index); } bool JSAPIArrayList::IsEmpty(const JSHandle &arrayList) @@ -144,12 +144,12 @@ bool JSAPIArrayList::IsEmpty(const JSHandle &arrayList) int JSAPIArrayList::GetIndexOf(JSThread *thread, const JSHandle &arrayList, const JSHandle &value) { - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); - uint32_t length = arrayList->GetLength().GetArrayLength(); + uint32_t length = arrayList->GetLength(); JSTaggedValue targetValue = value.GetTaggedValue(); for (uint32_t i = 0; i < length; ++i) { - if (JSTaggedValue::StrictEqual(targetValue, elements->Get(i))) { + if (JSTaggedValue::StrictEqual(thread, targetValue, elements->Get(thread, i))) { return i; } } @@ -159,12 +159,12 @@ int JSAPIArrayList::GetIndexOf(JSThread *thread, const JSHandle int JSAPIArrayList::GetLastIndexOf(JSThread *thread, const JSHandle &arrayList, const JSHandle &value) { - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); JSTaggedValue targetValue = value.GetTaggedValue(); - int length = arrayList->GetLength().GetInt(); + int length = arrayList->GetLength(); for (int i = length - 1; i >= 0; --i) { - if (JSTaggedValue::StrictEqual(targetValue, elements->Get(i))) { + if (JSTaggedValue::StrictEqual(thread, targetValue, elements->Get(thread, i))) { return i; } } @@ -173,7 +173,7 @@ int JSAPIArrayList::GetLastIndexOf(JSThread *thread, const JSHandle &arrayList, int index) { - int length = arrayList->GetLength().GetInt(); + int length = arrayList->GetLength(); if (length <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); @@ -186,14 +186,14 @@ JSTaggedValue JSAPIArrayList::RemoveByIndex(JSThread *thread, const JSHandleGetElements().GetTaggedObject()); - JSTaggedValue oldValue = resElements->Get(index); + TaggedArray *resElements = TaggedArray::Cast(arrayList->GetElements(thread).GetTaggedObject()); + JSTaggedValue oldValue = resElements->Get(thread, index); if (index >= 0) { - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); TaggedArray::RemoveElementByIndex(thread, elements, index, length); - arrayList->SetLength(thread, JSTaggedValue(length - 1)); + arrayList->SetLength(length - 1); } return oldValue; @@ -205,10 +205,10 @@ bool JSAPIArrayList::Remove(JSThread *thread, const JSHandle &ar int index = GetIndexOf(thread, arrayList, value); uint32_t length = arrayList->GetSize(); if (index >= 0) { - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); TaggedArray::RemoveElementByIndex(thread, elements, index, length); - arrayList->SetLength(thread, JSTaggedValue(length - 1)); + arrayList->SetLength(length - 1); return true; } return false; @@ -220,7 +220,7 @@ JSTaggedValue JSAPIArrayList::RemoveByRange(JSThread *thread, const JSHandleGetLength().GetInt(); + int32_t length = arrayList->GetLength(); if (length <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); @@ -243,15 +243,15 @@ JSTaggedValue JSAPIArrayList::RemoveByRange(JSThread *thread, const JSHandle= length ? length : endIndex; - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); int32_t numMoved = length - toIndex; for (int32_t i = 0; i < numMoved; i++) { - elements->Set(thread, startIndex + i, elements->Get(static_cast(endIndex + i))); + elements->Set(thread, startIndex + i, elements->Get(thread, static_cast(endIndex + i))); } int32_t newLength = length - (endIndex - startIndex); - arrayList->SetLength(thread, JSTaggedValue(newLength)); + arrayList->SetLength(newLength); elements->Trim(thread, newLength); return JSTaggedValue::Undefined(); } @@ -284,20 +284,20 @@ JSTaggedValue JSAPIArrayList::ReplaceAllElements(JSThread *thread, const JSHandl JSTaggedValue JSAPIArrayList::Set(JSThread *thread, const uint32_t index, JSTaggedValue value) { - if (GetLength().GetArrayLength() == 0) { + if (GetLength() == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - if (index >= GetLength().GetArrayLength()) { - ASSERT(GetLength().GetArrayLength() > 0); + if (index >= GetLength()) { + ASSERT(GetLength() > 0); std::ostringstream oss; oss << "The value of \"index\" is out of range. It must be >= 0 && <= " - << (GetLength().GetArrayLength() - 1) << ". Received value is: " << index; + << (GetLength() - 1) << ". Received value is: " << index; JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); elements->Set(thread, index, value); return JSTaggedValue::Undefined(); } @@ -306,7 +306,7 @@ JSTaggedValue JSAPIArrayList::SubArrayList(JSThread *thread, const JSHandle &value1, const JSHandle &value2) { - int length = arrayList->GetLength().GetInt(); + int length = arrayList->GetLength(); int fromIndex = JSTaggedValue::ToInt32(thread, value1); int toIndex = JSTaggedValue::ToInt32(thread, value2); int32_t size = length > toIndex ? toIndex : length; @@ -335,12 +335,12 @@ JSTaggedValue JSAPIArrayList::SubArrayList(JSThread *thread, const JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); - subArrayList->SetLength(thread, JSTaggedValue(newLength)); + subArrayList->SetLength(newLength); for (int i = 0; i < newLength; i++) { - subArrayList->Set(thread, i, elements->Get(fromIndex + i)); + subArrayList->Set(thread, i, elements->Get(thread, fromIndex + i)); } return subArrayList.GetTaggedValue(); @@ -376,7 +376,7 @@ JSTaggedValue JSAPIArrayList::ForEach(JSThread *thread, const JSHandle JSAPIArrayList::GrowCapacity(const JSThread *thread, const JSHandle &obj, uint32_t capacity) { - JSHandle oldElements(thread, obj->GetElements()); + JSHandle oldElements(thread, obj->GetElements(thread)); ASSERT(!oldElements->IsDictionaryMode()); uint32_t oldCapacity = oldElements->GetLength(); if (capacity < oldCapacity) { @@ -390,16 +390,16 @@ JSHandle JSAPIArrayList::GrowCapacity(const JSThread *thread, const return newElements; } -bool JSAPIArrayList::Has(const JSTaggedValue value) const +bool JSAPIArrayList::Has(JSThread *thread, const JSTaggedValue value) const { - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t length = GetSize(); if (length == 0) { return false; } for (uint32_t i = 0; i < length; i++) { - if (JSTaggedValue::SameValue(elements->Get(i), value)) { + if (JSTaggedValue::SameValue(thread, elements->Get(thread, i), value)) { return true; } } @@ -420,17 +420,17 @@ bool JSAPIArrayList::GetOwnProperty(JSThread *thread, const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"index\" can not obtain attributes of no-number type. Received value is: " - + ConvertToString(*result); + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - uint32_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength(); if (length == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); @@ -460,7 +460,7 @@ JSTaggedValue JSAPIArrayList::GetIteratorObj(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - int length = obj->GetLength().GetInt(); + int length = obj->GetLength(); JSHandle indexKey = key; if (indexKey->IsDouble()) { // Math.floor(1) will produce TaggedDouble, we need to cast into TaggedInt @@ -491,7 +491,7 @@ bool JSAPIArrayList::SetProperty(JSThread *thread, const JSHandle &key, const JSHandle &value) { - int length = obj->GetLength().GetInt(); + int length = obj->GetLength(); int index = static_cast(key->GetNumber()); if (index < 0 || index >= length) { return false; diff --git a/ecmascript/js_api/js_api_arraylist.h b/ecmascript/js_api/js_api_arraylist.h index 636f45da35..7be5125e2d 100644 --- a/ecmascript/js_api/js_api_arraylist.h +++ b/ecmascript/js_api/js_api_arraylist.h @@ -67,7 +67,7 @@ public: JSTaggedValue PUBLIC_API Set(JSThread *thread, const uint32_t index, JSTaggedValue value); JSTaggedValue Get(JSThread *thread, const uint32_t index); - bool Has(const JSTaggedValue value) const; + bool Has(JSThread *thread, const JSTaggedValue value) const; static JSHandle OwnKeys(JSThread *thread, const JSHandle &obj); static JSHandle OwnEnumKeys(JSThread *thread, const JSHandle &obj); static bool GetOwnProperty(JSThread *thread, const JSHandle &obj, @@ -79,13 +79,14 @@ public: const JSHandle &value); inline uint32_t GetSize() const { - return GetLength().GetInt(); + return GetLength(); } static constexpr size_t LENGTH_OFFSET = JSObject::SIZE; - ACCESSORS(Length, LENGTH_OFFSET, SIZE); + // Use uint64_t to keep the object size unchanged + ACCESSORS_FIXED_SIZE_FIELD(Length, uint32_t, uint64_t, LENGTH_OFFSET, SIZE); - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LENGTH_OFFSET, SIZE) + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, SIZE, SIZE) DECL_DUMP() private: diff --git a/ecmascript/js_api/js_api_arraylist_iterator.cpp b/ecmascript/js_api/js_api_arraylist_iterator.cpp index c98209503f..f191d6451b 100644 --- a/ecmascript/js_api/js_api_arraylist_iterator.cpp +++ b/ecmascript/js_api/js_api_arraylist_iterator.cpp @@ -37,7 +37,7 @@ JSTaggedValue JSAPIArrayListIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle arrayList(thread, iter->GetIteratedArrayList()); + JSHandle arrayList(thread, iter->GetIteratedArrayList(thread)); if (arrayList->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -48,7 +48,7 @@ JSTaggedValue JSAPIArrayListIterator::Next(EcmaRuntimeCallInfo *argv) uint32_t length = 0; if (arrayList->IsJSAPIArrayList()) { - length = JSHandle(arrayList)->GetLength().GetArrayLength(); + length = JSHandle(arrayList)->GetLength(); } if (index >= length) { diff --git a/ecmascript/js_api/js_api_bitvector.cpp b/ecmascript/js_api/js_api_bitvector.cpp index 241bf29865..1b25fb8d18 100644 --- a/ecmascript/js_api/js_api_bitvector.cpp +++ b/ecmascript/js_api/js_api_bitvector.cpp @@ -27,7 +27,7 @@ bool JSAPIBitVector::Push( [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(bitVector)); uint32_t length = static_cast(bitVector->GetLength()); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); if ((length & TAGGED_VALUE_BIT_OFFSET) == 0) { std::bitset increaseSet; @@ -50,7 +50,7 @@ JSTaggedValue JSAPIBitVector::Pop(JSThread* thread, const JSHandle(bitVector->GetLength() - 1); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); JSTaggedValue bit = GetBit(elements, lastIndex); @@ -73,7 +73,7 @@ JSTaggedValue JSAPIBitVector::Set(JSThread* thread, const uint32_t index, JSTagg JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - JSNativePointer* np = JSNativePointer::Cast(GetNativePointer().GetTaggedObject()); + JSNativePointer* np = JSNativePointer::Cast(GetNativePointer(thread).GetTaggedObject()); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); SetBit(elements, index, value); return JSTaggedValue::Undefined(); @@ -89,7 +89,7 @@ JSTaggedValue JSAPIBitVector::Get(JSThread* thread, const uint32_t index) JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - JSNativePointer* np = JSNativePointer::Cast(GetNativePointer().GetTaggedObject()); + JSNativePointer* np = JSNativePointer::Cast(GetNativePointer(thread).GetTaggedObject()); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); return GetBit(elements, index); } @@ -118,7 +118,7 @@ bool JSAPIBitVector::Has(JSThread* thread, const JSHandle& bitVe if (length == 0) { return false; } - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (int index = startIndex; index <= endIndex; index++) { std::pair pair = ComputeElementIdAndBitId(index); @@ -132,13 +132,13 @@ bool JSAPIBitVector::Has(JSThread* thread, const JSHandle& bitVe return false; } -bool JSAPIBitVector::Has(const JSTaggedValue& value) const +bool JSAPIBitVector::Has(JSThread* thread, const JSTaggedValue& value) const { uint32_t length = GetSize(); if (length == 0) { return false; } - JSNativePointer* np = JSNativePointer::Cast(GetNativePointer().GetTaggedObject()); + JSNativePointer* np = JSNativePointer::Cast(GetNativePointer(thread).GetTaggedObject()); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (uint32_t index = 0; index < length; index++) { std::pair pair = ComputeElementIdAndBitId(index); @@ -176,7 +176,7 @@ JSTaggedValue JSAPIBitVector::SetBitsByRange(JSThread* thread, const JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (int32_t index = startIndex; index < endIndex; index++) { SetBit(elements, index, value.GetTaggedValue()); @@ -209,11 +209,11 @@ JSTaggedValue JSAPIBitVector::GetBitsByRange(JSThread* thread, const JSHandleGetEcmaVM()->GetFactory(); - JSHandle srcNp(thread, bitVector->GetNativePointer()); + JSHandle srcNp(thread, bitVector->GetNativePointer(thread)); auto srcElements = reinterpret_cast>*>(srcNp->GetExternalPointer()); JSHandle newBitVector = factory->NewJSAPIBitVector(dstLength); - JSHandle dstNp(thread, newBitVector->GetNativePointer()); + JSHandle dstNp(thread, newBitVector->GetNativePointer(thread)); auto dstElements = reinterpret_cast>*>(dstNp->GetExternalPointer()); for (int32_t index = 0; index < dstLength; index++) { @@ -231,7 +231,7 @@ JSTaggedValue JSAPIBitVector::SetAllBits( { [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(bitVector)); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); int size = static_cast(elements->size()); if (value->IsZero()) { @@ -269,7 +269,7 @@ JSTaggedValue JSAPIBitVector::GetBitCountByRange(JSThread* thread, const JSHandl JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (int32_t index = startIndex; index < endIndex; index++) { std::pair pair = ComputeElementIdAndBitId(index); @@ -305,7 +305,7 @@ int JSAPIBitVector::GetIndexOf(JSThread* thread, const JSHandle& JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, -1); } - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (int32_t index = startIndex; index < endIndex; index++) { std::pair pair = ComputeElementIdAndBitId(index); @@ -341,7 +341,7 @@ int JSAPIBitVector::GetLastIndexOf(JSThread* thread, const JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (int32_t index = endIndex - 1; index >= startIndex; index--) { std::pair pair = ComputeElementIdAndBitId(index); @@ -367,7 +367,7 @@ JSTaggedValue JSAPIBitVector::FlipBitByIndex(JSThread* thread, const JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); std::pair pair = ComputeElementIdAndBitId(index); @@ -400,7 +400,7 @@ JSTaggedValue JSAPIBitVector::FlipBitsByRange(JSThread* thread, const JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); for (int32_t index = startIndex; index < endIndex; index++) { std::pair pair = ComputeElementIdAndBitId(index); @@ -425,7 +425,7 @@ void JSAPIBitVector::Resize(JSThread* thread, const JSHandle& bi uint32_t elementsLength = static_cast((length - 1) / BIT_SET_LENGTH + 1); uint32_t newElementsLength = static_cast((newSize - 1) / BIT_SET_LENGTH + 1); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast>*>(np->GetExternalPointer()); if (elementsLength == newElementsLength && length < newSize) { for (int32_t index = length; index < newSize; index++) { @@ -464,11 +464,11 @@ bool JSAPIBitVector::GetOwnProperty( JSThread* thread, const JSHandle& obj, const JSHandle& key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"index\" can not obtain attributes of no-number type. Received value is: " + - ConvertToString(*result); + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } diff --git a/ecmascript/js_api/js_api_bitvector.h b/ecmascript/js_api/js_api_bitvector.h index 2aa0052f92..3161d24a5a 100644 --- a/ecmascript/js_api/js_api_bitvector.h +++ b/ecmascript/js_api/js_api_bitvector.h @@ -58,7 +58,7 @@ public: const JSHandle& value1, const JSHandle& value2); JSTaggedValue PUBLIC_API Set(JSThread* thread, const uint32_t index, JSTaggedValue value); JSTaggedValue Get(JSThread* thread, const uint32_t index); - bool Has(const JSTaggedValue& value) const; + bool Has(JSThread* thread, const JSTaggedValue& value) const; static bool Has(JSThread* thread, const JSHandle& bitVector, const JSHandle& value, const JSHandle& value1, const JSHandle& value2); diff --git a/ecmascript/js_api/js_api_bitvector_iterator.cpp b/ecmascript/js_api/js_api_bitvector_iterator.cpp index 9ef35ac1e3..18fb44bfba 100644 --- a/ecmascript/js_api/js_api_bitvector_iterator.cpp +++ b/ecmascript/js_api/js_api_bitvector_iterator.cpp @@ -34,7 +34,7 @@ JSTaggedValue JSAPIBitVectorIterator::Next(EcmaRuntimeCallInfo* argv) } JSHandle iter(input); // Let a be O.[[IteratedBitVectorLike]]. - JSHandle bitVector(thread, iter->GetIteratedBitVector()); + JSHandle bitVector(thread, iter->GetIteratedBitVector(thread)); // If a is undefined, return an undefinedIteratorResult. if (bitVector->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); diff --git a/ecmascript/js_api/js_api_buffer.cpp b/ecmascript/js_api/js_api_buffer.cpp index d31f47d9ab..449b811bee 100644 --- a/ecmascript/js_api/js_api_buffer.cpp +++ b/ecmascript/js_api/js_api_buffer.cpp @@ -87,40 +87,41 @@ EncodingType JSAPIFastBuffer::GetEncodingType(string encode) return EncodingType::INVALID; } -EncodingType JSAPIFastBuffer::GetEncodingType(const JSHandle &encode) +EncodingType JSAPIFastBuffer::GetEncodingType(JSThread *thread, const JSHandle &encode) { auto strAccessor = EcmaStringAccessor(JSHandle(encode)); - auto str = strAccessor.ToStdString(); + auto str = strAccessor.ToStdString(thread); return GetEncodingType(str); } -JSTypedArray *GetUInt8ArrayFromBufferObject(JSTaggedValue buffer) +JSTypedArray *GetUInt8ArrayFromBufferObject(JSThread *thread, JSTaggedValue buffer) { if (buffer.IsJSUint8Array()) { return JSTypedArray::Cast(buffer.GetTaggedObject()); } ASSERT(buffer.IsJSAPIBuffer()); - return JSTypedArray::Cast(JSAPIFastBuffer::Cast(buffer.GetTaggedObject())->GetFastBufferData().GetTaggedObject()); + return JSTypedArray::Cast(JSAPIFastBuffer::Cast(buffer.GetTaggedObject())->GetFastBufferData(thread) + .GetTaggedObject()); } -JSTypedArray *GetUInt8ArrayFromBufferObject(JSHandle buffer) +JSTypedArray *GetUInt8ArrayFromBufferObject(JSThread *thread, JSHandle buffer) { - return GetUInt8ArrayFromBufferObject(buffer.GetTaggedValue()); + return GetUInt8ArrayFromBufferObject(thread, buffer.GetTaggedValue()); } -uint8_t *GetBufferData(JSHandle &buffer, uint32_t offset) +uint8_t *GetBufferData(JSThread *thread, JSHandle &buffer, uint32_t offset) { if (!RangeChecker(0, buffer->GetLength(), offset, offset)) { return nullptr; } - JSTypedArray *array = GetUInt8ArrayFromBufferObject(buffer.GetTaggedValue()); - JSTaggedValue arrayBuffer = array->GetViewedArrayBufferOrByteArray(); + JSTypedArray *array = GetUInt8ArrayFromBufferObject(thread, buffer.GetTaggedValue()); + JSTaggedValue arrayBuffer = array->GetViewedArrayBufferOrByteArray(thread); // If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(arrayBuffer)) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, arrayBuffer)) { return nullptr; } auto res = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(arrayBuffer, buffer->GetOffset() + offset)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrayBuffer, buffer->GetOffset() + offset)); return res; } @@ -139,45 +140,45 @@ uint32_t GetValueUInt32(JSHandle valueHandle) return static_cast(GetValueInt32(valueHandle)); } -string FromStringUtf8(const JSHandle &str) +string FromStringUtf8(JSThread *thread, const JSHandle &str) { auto strAccessor = EcmaStringAccessor(JSHandle(str)); - auto res = strAccessor.ToStdString(); + auto res = strAccessor.ToStdString(thread); return res; } -string_view FromStringUtf16(const JSHandle &str, string &stringDecoded) +string_view FromStringUtf16(JSThread *thread, const JSHandle &str, string &stringDecoded) { auto strAccessor = EcmaStringAccessor(JSHandle(str)); - auto u16string = StringConverter::Utf8ToUtf16BE(strAccessor.ToStdString()); + auto u16string = StringConverter::Utf8ToUtf16BE(strAccessor.ToStdString(thread)); stringDecoded = StringConverter::Utf16StrToStr(u16string); return string_view(stringDecoded); } -string_view FromStringASCII(const JSHandle &str, string &stringDecoded) +string_view FromStringASCII(JSThread *thread, const JSHandle &str, string &stringDecoded) { auto strAccessor = EcmaStringAccessor(JSHandle(str)); uint32_t length = strAccessor.GetLength(); stringDecoded.reserve(length); stringDecoded.resize(length); - strAccessor.WriteToOneByte(reinterpret_cast(stringDecoded.data()), length); + strAccessor.WriteToOneByte(thread, reinterpret_cast(stringDecoded.data()), length); return string_view(stringDecoded); } -string_view FromStringBase64(const JSHandle &str, string &stringDecoded) +string_view FromStringBase64(JSThread *thread, const JSHandle &str, string &stringDecoded) { auto strAccessor = EcmaStringAccessor(JSHandle(str)); CVector buf; - Span sp = strAccessor.ToUtf8Span(buf); + Span sp = strAccessor.ToUtf8Span(thread, buf); StringConverter::Base64Decode(string_view(reinterpret_cast(sp.data()), sp.size()), stringDecoded); return std::string_view(stringDecoded); } -std::string ConvertEcmaStringToStdString(const JSHandle &str) +std::string ConvertEcmaStringToStdString(JSThread *thread, const JSHandle &str) { ASSERT(str->IsString()); auto strAccessor = EcmaStringAccessor(JSHandle(str)); - return strAccessor.ToStdString(); + return strAccessor.ToStdString(thread); } JSHandle JSAPIFastBuffer::NewUint8Array(JSThread *thread, uint32_t length, uint32_t byteOffset) @@ -202,8 +203,8 @@ JSTaggedValue JSAPIFastBuffer::Copy(JSThread *thread, const JSHandle= 0 && sStart >= 0 && sStart <= sEnd); uint32_t copyLength = sEnd - sStart; - JSHandle srcArray = JSHandle(thread, GetUInt8ArrayFromBufferObject(src)); - JSHandle dstArray = JSHandle(thread, GetUInt8ArrayFromBufferObject(dst)); + JSHandle srcArray = JSHandle(thread, GetUInt8ArrayFromBufferObject(thread, src)); + JSHandle dstArray = JSHandle(thread, GetUInt8ArrayFromBufferObject(thread, dst)); uint32_t dstLength = dstArray->GetByteLength(); if (dstLength <= tStart) { return JSTaggedValue(0); @@ -215,14 +216,14 @@ JSTaggedValue JSAPIFastBuffer::Copy(JSThread *thread, const JSHandleIsJSAPIBuffer()) { tStart += JSHandle(dst)->GetOffset(); } - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcArray->GetViewedArrayBufferOrByteArray())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcArray->GetViewedArrayBufferOrByteArray(thread))) { THROW_TYPE_ERROR_AND_RETURN(thread, "srcBuffer is Detached Buffer", JSTaggedValue::Exception()); } - if (BuiltinsArrayBuffer::IsDetachedBuffer(dstArray->GetViewedArrayBufferOrByteArray())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, dstArray->GetViewedArrayBufferOrByteArray(thread))) { THROW_TYPE_ERROR_AND_RETURN(thread, "dstBuffer is Detached Buffer", JSTaggedValue::Exception()); } - WriteBytes(thread, JSHandle(thread, srcArray->GetViewedArrayBufferOrByteArray()), - JSHandle(thread, dstArray->GetViewedArrayBufferOrByteArray()), sStart, tStart, + WriteBytes(thread, JSHandle(thread, srcArray->GetViewedArrayBufferOrByteArray(thread)), + JSHandle(thread, dstArray->GetViewedArrayBufferOrByteArray(thread)), sStart, tStart, copyLength); return JSTaggedValue(copyLength); } @@ -257,7 +258,7 @@ JSTaggedValue JSAPIFastBuffer::CreateBufferFromArrayLike(JSThread *thread, const JSTaggedValue JSAPIFastBuffer::FromArrayBuffer(JSThread *thread, const JSHandle &buffer, const JSHandle &src, uint32_t byteOffset, uint32_t length) { - if (BuiltinsArrayBuffer::IsDetachedBuffer(src.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, src.GetTaggedValue())) { THROW_REFERENCE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } auto srcBuffer = JSHandle(src); @@ -276,10 +277,10 @@ JSTaggedValue JSAPIFastBuffer::FromArrayBuffer(JSThread *thread, const JSHandle< return buffer.GetTaggedValue(); } -string_view FromStringHex(const JSHandle &str, string &stringDecoded) +string_view FromStringHex(JSThread *thread, const JSHandle &str, string &stringDecoded) { auto strAccessor = EcmaStringAccessor(JSHandle(str)); - auto hexStr = strAccessor.ToStdString(); + auto hexStr = strAccessor.ToStdString(thread); StringConverter::HexDecode(hexStr, stringDecoded); return std::string_view(stringDecoded); } @@ -398,29 +399,29 @@ string StringConverter::Utf8ToUtf16BEToANSI(const string &str) return ret; } -string JSAPIFastBuffer::GetString(const JSHandle &str, EncodingType encodingType) +string JSAPIFastBuffer::GetString(JSThread *thread, const JSHandle &str, EncodingType encodingType) { string_view data; string strDecoded; switch (encodingType) { case UTF8: - strDecoded = FromStringUtf8(str); + strDecoded = FromStringUtf8(thread, str); data = strDecoded; break; case ASCII: case LATIN1: case BINARY: - data = FromStringASCII(str, strDecoded); + data = FromStringASCII(thread, str, strDecoded); break; case UTF16LE: - data = FromStringUtf16(str, strDecoded); + data = FromStringUtf16(thread, str, strDecoded); break; case BASE64: case BASE64URL: - data = FromStringBase64(str, strDecoded); + data = FromStringBase64(thread, str, strDecoded); break; case HEX: - data = FromStringHex(str, strDecoded); + data = FromStringHex(thread, str, strDecoded); break; default: return ""; @@ -428,11 +429,11 @@ string JSAPIFastBuffer::GetString(const JSHandle &str, EncodingTy return strDecoded; } -string JSAPIFastBuffer::GetString(const JSHandle &str, JSHandle encoding) +string JSAPIFastBuffer::GetString(JSThread *thread, const JSHandle &str, JSHandle encoding) { EncodingType encodingType = UTF8; - encodingType = GetEncodingType(ConvertEcmaStringToStdString(encoding)); - return GetString(str, encodingType); + encodingType = GetEncodingType(ConvertEcmaStringToStdString(thread, encoding)); + return GetString(thread, str, encodingType); } JSTaggedValue JSAPIFastBuffer::FromString(JSThread *thread, const JSHandle &buffer, @@ -441,7 +442,7 @@ JSTaggedValue JSAPIFastBuffer::FromString(JSThread *thread, const JSHandleIsUndefined() || encoding->IsNull()) { return FromString(thread, buffer, str); } - EncodingType encodingType = GetEncodingType(encoding); + EncodingType encodingType = GetEncodingType(thread, encoding); return FromString(thread, buffer, str, encodingType); } @@ -452,23 +453,23 @@ JSTaggedValue JSAPIFastBuffer::FromString(JSThread *thread, const JSHandle array = NewUint8Array(thread, length); buffer->SetFastBufferData(thread, array); buffer->SetLength(length); - auto *dst = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(array->GetViewedArrayBufferOrByteArray(), - buffer->GetOffset()); + auto *dst = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, + array->GetViewedArrayBufferOrByteArray(thread), buffer->GetOffset()); WriteBytes(thread, reinterpret_cast(data.data()), length, reinterpret_cast(dst)); return buffer.GetTaggedValue(); } @@ -495,14 +496,14 @@ JSTaggedValue JSAPIFastBuffer::ToString(JSThread *thread, JSHandle( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(arrayBuffer, buffer->GetOffset() + start)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, arrayBuffer, buffer->GetOffset() + start)); uint32_t len = end - start; string strDecoded; switch (encodingType) { @@ -546,24 +547,24 @@ JSTaggedValue JSAPIFastBuffer::WriteString(JSThread *thread, JSHandle typedArray = - JSHandle(thread, GetUInt8ArrayFromBufferObject(buffer.GetTaggedValue())); + JSHandle(thread, GetUInt8ArrayFromBufferObject(thread, buffer.GetTaggedValue())); auto *dst = static_cast(builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer( - typedArray->GetViewedArrayBufferOrByteArray(), buffer->GetOffset() + offset)); + thread, typedArray->GetViewedArrayBufferOrByteArray(thread), buffer->GetOffset() + offset)); WriteBytes(thread, reinterpret_cast(data.data()), maxLen, reinterpret_cast(dst)); return JSTaggedValue(maxLen); } @@ -591,7 +592,7 @@ JSTaggedValue JSAPIFastBuffer::AllocateFromBufferObject(JSThread *thread, const const JSHandle &src, uint32_t byteLength, uint32_t byteOffset) { - auto handleUint8Array = JSTaggedValue(GetUInt8ArrayFromBufferObject(src)); + auto handleUint8Array = JSTaggedValue(GetUInt8ArrayFromBufferObject(thread, src)); buffer->SetFastBufferData(thread, handleUint8Array); buffer->SetLength(byteLength); buffer->SetOffset(byteOffset); @@ -601,7 +602,8 @@ JSTaggedValue JSAPIFastBuffer::AllocateFromBufferObject(JSThread *thread, const JSTaggedValue JSAPIFastBuffer::GetArrayBuffer(JSThread *thread, JSHandle &buffer) { // if buffer size smaller than Buffer.poolSize, it may return the pool arraybuffer. - auto array = JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); + auto array = JSHandle(thread, + JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); return JSTypedArray::GetOffHeapBuffer(thread, array); } @@ -612,7 +614,7 @@ JSTaggedValue JSAPIFastBuffer::FromBufferToArray(JSThread *thread, JSHandle(buffer->GetLength()); JSHandle array = JSArray::ArrayCreate(thread, JSTaggedNumber(length)); JSHandle typedArray = - JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); for (int i = 0; i < length; i++) { JSTaggedValue bufferValue = GetValueByIndex(thread, typedArray.GetTaggedValue(), i, JSType::JS_UINT8_ARRAY); JSArray::FastSetPropertyByValue(thread, array, i, JSHandle(thread, bufferValue)); @@ -622,7 +624,8 @@ JSTaggedValue JSAPIFastBuffer::FromBufferToArray(JSThread *thread, JSHandle &buffer) { - auto array = JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); + auto array = + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle iter( factory->NewJSArrayIterator(JSHandle(thread, array.GetTaggedValue()), IterationKind::KEY_AND_VALUE)); @@ -631,7 +634,8 @@ JSTaggedValue JSAPIFastBuffer::Entries(JSThread *thread, JSHandle &buffer) { - auto array = JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); + auto array = + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle iter( factory->NewJSArrayIterator(JSHandle(thread, array.GetTaggedValue()), IterationKind::KEY)); @@ -640,7 +644,8 @@ JSTaggedValue JSAPIFastBuffer::Keys(JSThread *thread, JSHandle JSTaggedValue JSAPIFastBuffer::Values(JSThread *thread, JSHandle &buffer) { - auto array = JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); + auto array = + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle iter( factory->NewJSArrayIterator(JSHandle(thread, array.GetTaggedValue()), IterationKind::VALUE)); @@ -665,7 +670,7 @@ JSTaggedValue JSAPIFastBuffer::FillString(JSThread *thread, JSHandle &valueHandle, EncodingType encoding, uint32_t start, uint32_t end) { - string str = GetString(valueHandle, encoding); + string str = GetString(thread, valueHandle, encoding); if (str.length() == 0) { str.push_back(0); } @@ -687,8 +692,8 @@ JSTaggedValue JSAPIFastBuffer::Fill(JSThread *thread, JSHandle uint8_t value = static_cast(valueHandle->GetInt() & 255); uint32_t length = end - start; JSHandle typedArray = - JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); - uint8_t *data = GetBufferData(buffer, start); + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); + uint8_t *data = GetBufferData(thread, buffer, start); if (memset_s(data, length, value, length) != EOK) { std::ostringstream oss; oss << "Buffer fill number memset failed"; @@ -698,7 +703,7 @@ JSTaggedValue JSAPIFastBuffer::Fill(JSThread *thread, JSHandle } else if (valueHandle->IsString()) { FillString(thread, buffer, valueHandle, encoding, start, end); } else if (valueHandle->IsJSAPIBuffer() || valueHandle->IsTypedArray()) { - WriteBufferObjectLoop(buffer, valueHandle, start, end); + WriteBufferObjectLoop(thread, buffer, valueHandle, start, end); } return buffer.GetTaggedValue(); } @@ -707,8 +712,8 @@ JSTaggedValue JSAPIFastBuffer::Compare(JSThread *thread, JSHandle typedArrayA = - JSHandle(thread, JSTypedArray::Cast(a->GetFastBufferData().GetTaggedObject())); - JSHandle typedArrayB = JSHandle(thread, GetUInt8ArrayFromBufferObject(bObj)); + JSHandle(thread, JSTypedArray::Cast(a->GetFastBufferData(thread).GetTaggedObject())); + JSHandle typedArrayB = JSHandle(thread, GetUInt8ArrayFromBufferObject(thread, bObj)); uint32_t aCmpLength = sEnd - sStart; uint32_t bCmpLength = tEnd - tStart; if (typedArrayA->GetByteLength() < aCmpLength || typedArrayB->GetByteLength() < bCmpLength) { @@ -722,14 +727,14 @@ JSTaggedValue JSAPIFastBuffer::Compare(JSThread *thread, JSHandle bufferB = JSHandle(thread, JSTypedArray::GetOffHeapBuffer(thread, typedArrayB)); // If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(bufferA.GetTaggedValue()) || - BuiltinsArrayBuffer::IsDetachedBuffer(bufferA.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, bufferA.GetTaggedValue()) || + BuiltinsArrayBuffer::IsDetachedBuffer(thread, bufferA.GetTaggedValue())) { THROW_REFERENCE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception()); } auto aPointer = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(bufferA.GetTaggedValue(), sStart)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, bufferA.GetTaggedValue(), sStart)); auto bPointer = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(bufferB.GetTaggedValue(), tStart)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, bufferB.GetTaggedValue(), tStart)); if (aPointer == nullptr || bPointer == nullptr) { THROW_REFERENCE_ERROR_AND_RETURN(thread, "Buffer Compare memory ptr is nullptr.", JSTaggedValue::Exception()); } @@ -758,15 +763,17 @@ int32_t JSAPIFastBuffer::StringMatch(JSThread *thread, JSHandle if (buffer->GetLength() < strLength) { return -1; } - auto array = JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); - JSHandle srcBuffer = JSHandle(thread, array->GetViewedArrayBufferOrByteArray()); + auto array = JSHandle(thread, + JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); + JSHandle srcBuffer = JSHandle(thread, + array->GetViewedArrayBufferOrByteArray(thread)); // If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(thread, srcBuffer.GetTaggedValue())) { THROW_REFERENCE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", false); } int32_t offset = static_cast(buffer->GetOffset()); auto src = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(srcBuffer.GetTaggedValue(), offset)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcBuffer.GetTaggedValue(), offset)); uint32_t end = buffer->GetLength() - strLength; // reverse is mean enumeration order if (isReverse) { @@ -793,15 +800,15 @@ JSTaggedValue JSAPIFastBuffer::IndexOf(JSThread *thread, JSHandleIsString()) { - auto str = GetString(valueHandle, encoding); + auto str = GetString(thread, valueHandle, encoding); data = reinterpret_cast(str.data()); len = str.length(); } else if (valueHandle->IsJSAPIBuffer() || valueHandle->IsJSUint8Array()) { auto srcData = JSHandle( - thread, GetUInt8ArrayFromBufferObject(valueHandle)->GetViewedArrayBufferOrByteArray()); + thread, GetUInt8ArrayFromBufferObject(thread, valueHandle)->GetViewedArrayBufferOrByteArray(thread)); data = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(srcData.GetTaggedValue())); - len = GetUInt8ArrayFromBufferObject(valueHandle)->GetByteLength(); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcData.GetTaggedValue())); + len = GetUInt8ArrayFromBufferObject(thread, valueHandle)->GetByteLength(); } else { THROW_TYPE_ERROR_AND_RETURN(thread, "IndexOf value invalid.", JSTaggedValue::Exception()); } @@ -878,9 +885,10 @@ JSTaggedValue JSAPIFastBuffer::WriteStringLoop(JSThread *thread, JSHandle( - thread, GetUInt8ArrayFromBufferObject(buffer.GetTaggedValue())->GetViewedArrayBufferOrByteArray()); + thread, GetUInt8ArrayFromBufferObject(thread, + buffer.GetTaggedValue())->GetViewedArrayBufferOrByteArray(thread)); uint8_t *dst = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(dstData.GetTaggedValue(), buffer->GetOffset())); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, dstData.GetTaggedValue(), buffer->GetOffset())); uint8_t *str = const_cast(reinterpret_cast(data.data())); if (!WriteDataLoop(str, dst, length, start, end)) { std::ostringstream oss; @@ -891,16 +899,16 @@ JSTaggedValue JSAPIFastBuffer::WriteStringLoop(JSThread *thread, JSHandle &buffer, JSHandle &srcObj, +JSTaggedValue JSAPIFastBuffer::WriteBufferObjectLoop(JSThread *thread, JSHandle &buffer, JSHandle &srcObj, uint32_t start, uint32_t end) { ASSERT(end - start <= buffer->GetLength()); - auto srcArray = GetUInt8ArrayFromBufferObject(srcObj); + auto srcArray = GetUInt8ArrayFromBufferObject(thread, srcObj); uint32_t length = srcArray->GetByteLength(); - auto srcData = srcArray->GetViewedArrayBufferOrByteArray(); + auto srcData = srcArray->GetViewedArrayBufferOrByteArray(thread); uint8_t *src = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(srcData, buffer->GetOffset())); - uint8_t *dst = GetBufferData(buffer, 0); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcData, buffer->GetOffset())); + uint8_t *dst = GetBufferData(thread, buffer, 0); WriteDataLoop(src, dst, length, start, end); return JSTaggedValue(length); } @@ -911,9 +919,9 @@ bool JSAPIFastBuffer::WriteBytes(JSThread *thread, JSHandle srcDa ASSERT(srcData->IsByteArray() || srcData->IsArrayBuffer()); ASSERT(dstData->IsByteArray() || dstData->IsArrayBuffer()); auto src = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(srcData.GetTaggedValue(), sStart)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcData.GetTaggedValue(), sStart)); auto dst = reinterpret_cast( - builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(dstData.GetTaggedValue(), tStart)); + builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, dstData.GetTaggedValue(), tStart)); return WriteBytes(thread, src, size, dst); } @@ -926,7 +934,7 @@ JSTaggedValue JSAPIFastBuffer::SetValueByIndex(JSThread *thread, const JSTaggedV if (UNLIKELY(value.IsECMAObject())) { return JSTaggedValue::Hole(); } - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); DataViewType elementType = TypedArrayHelper::GetType(valueType); auto valueHandle = JSHandle(thread, value); return BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, index, elementType, valueHandle, littleEndian); @@ -938,8 +946,8 @@ JSTaggedValue JSAPIFastBuffer::GetValueByIndex(JSThread *thread, const JSTaggedV ASSERT(typedarray.IsTypedArray() || typedarray.IsSharedTypedArray()); // Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTypedArray *typedarrayObj = JSTypedArray::Cast(typedarray.GetTaggedObject()); - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); - if (buffer.IsArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); + if (buffer.IsArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { return JSTaggedValue::Undefined(); } DataViewType elementType = TypedArrayHelper::GetType(jsType); @@ -1322,7 +1330,7 @@ JSTaggedValue JSAPIFastBuffer::WriteBigUInt64(JSThread *thread, const JSHandle typedArray = - JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); uint64_t valueNum; bool isLossLess; ASSERT(value->IsBigInt() || value->IsNumber() || value->IsBoolean()); @@ -1353,7 +1361,7 @@ JSTaggedValue JSAPIFastBuffer::ReadBigUInt64(JSThread *thread, const JSHandle typedArray = - JSHandle(thread, JSTypedArray ::Cast(buffer->GetFastBufferData().GetTaggedObject())); + JSHandle(thread, JSTypedArray ::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); if (offset < 0 || offset + NumberSize::BIGUINT64 > buffer->GetLength()) { std::ostringstream oss; oss << std::fixed << "The value of \"offset\" is out of range. It must be >= " << 0 @@ -1370,7 +1378,7 @@ JSTaggedValue JSAPIFastBuffer::WriteBigInt64(JSThread *thread, const JSHandle typedArray = - JSHandle(thread, JSTypedArray ::Cast(buffer->GetFastBufferData().GetTaggedObject())); + JSHandle(thread, JSTypedArray ::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); int64_t valueNum; bool isLossLess; ASSERT(value->IsBigInt() || value->IsNumber() || value->IsBoolean()); @@ -1401,7 +1409,7 @@ JSTaggedValue JSAPIFastBuffer::ReadBigInt64(JSThread *thread, const JSHandle typedArray = - JSHandle(thread, JSTypedArray ::Cast(buffer->GetFastBufferData().GetTaggedObject())); + JSHandle(thread, JSTypedArray ::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); if (offset < 0 || offset + NumberSize::BIGINT64 > buffer->GetLength()) { std::ostringstream oss; oss << std::fixed << "The value of \"offset\" is out of range. It must be >= " << 0 diff --git a/ecmascript/js_api/js_api_buffer.h b/ecmascript/js_api/js_api_buffer.h index fc562b386c..6406123e21 100644 --- a/ecmascript/js_api/js_api_buffer.h +++ b/ecmascript/js_api/js_api_buffer.h @@ -47,7 +47,7 @@ using BuiltinsArrayBuffer = builtins::BuiltinsArrayBuffer; JSType type = JSType::JS_##type##_ARRAY; \ auto byteSize = base::TypedArrayHelper::GetElementSize(type); \ JSHandle typedArray = \ - JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); \ + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); \ double valueNum = value->GetNumber(); \ double left = (type##_MIN); \ double right = (type##_MAX); \ @@ -79,7 +79,7 @@ using BuiltinsArrayBuffer = builtins::BuiltinsArrayBuffer; { \ JSType type = JSType::JS_##type##_ARRAY; \ JSHandle typedArray = \ - JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData().GetTaggedObject())); \ + JSHandle(thread, JSTypedArray::Cast(buffer->GetFastBufferData(thread).GetTaggedObject())); \ if (offset + NumberSize::type > buffer->GetLength()) { \ std::ostringstream oss; \ oss << "The value of \"offset\" is out of range. It must be >= " << 0 \ @@ -163,8 +163,8 @@ public: static void ExtendBufferCapacity(JSThread *thread, JSHandle &dst, uint32_t capacity); static JSTaggedValue WriteStringLoop(JSThread *thread, JSHandle &buffer, std::string_view data, uint32_t start, uint32_t end); - static JSTaggedValue WriteBufferObjectLoop(JSHandle &buffer, JSHandle &srcObj, - uint32_t start, uint32_t end); + static JSTaggedValue WriteBufferObjectLoop(JSThread *thread, JSHandle &buffer, + JSHandle &srcObj, uint32_t start, uint32_t end); static JSTaggedValue Copy(JSThread *thread, const JSHandle &dst, const JSHandle &src, uint32_t tStart, uint32_t sStart, uint32_t sEnd); static JSTaggedValue FromArrayBuffer(JSThread *thread, const JSHandle &buffer, @@ -175,8 +175,10 @@ public: const JSHandle &str, EncodingType encoding = UTF8); static JSTaggedValue ToString(JSThread *thread, JSHandle &buffer, EncodingType encodingType, uint32_t start, uint32_t end); - static std::string GetString(const JSHandle &str, JSHandle encoding); - static std::string GetString(const JSHandle &str, EncodingType encodingType = UTF8); + static std::string GetString(JSThread *thread, const JSHandle &str, + JSHandle encoding); + static std::string GetString(JSThread *thread, const JSHandle &str, + EncodingType encodingType = UTF8); static std::string_view FastGetString(const JSHandle &str, EncodingType encodingType, std::string &strDecoded); static JSTaggedValue AllocateFromBufferObject(JSThread *thread, const JSHandle &buffer, @@ -201,7 +203,7 @@ public: static JSTaggedValue CreateBufferFromArrayLike(JSThread *thread, const JSHandle &buffer, const JSHandle &obj); static EncodingType GetEncodingType(std::string encode); - static EncodingType GetEncodingType(const JSHandle &encode); + static EncodingType GetEncodingType(JSThread *thread, const JSHandle &encode); static OperationResult GetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key); static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, @@ -245,7 +247,7 @@ private: JSTaggedValue SetValueByIndex(JSThread *thread, uint32_t index, JSTaggedValue value, JSType jsType, bool littleEndian = true) { - auto typeArray = this->GetFastBufferData(); + auto typeArray = this->GetFastBufferData(thread); return SetValueByIndex(thread, typeArray, index, value, jsType, littleEndian); } static JSTaggedValue SetValueByIndex(JSThread *thread, const JSTaggedValue typedarray, uint32_t index, diff --git a/ecmascript/js_api/js_api_deque.cpp b/ecmascript/js_api/js_api_deque.cpp index caad1eed11..d0c2578323 100644 --- a/ecmascript/js_api/js_api_deque.cpp +++ b/ecmascript/js_api/js_api_deque.cpp @@ -26,7 +26,7 @@ class JSAPIDequelterator; void JSAPIDeque::InsertFront(JSThread *thread, const JSHandle &deque, const JSHandle &value) { - JSHandle elements(thread, deque->GetElements()); + JSHandle elements(thread, deque->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); uint32_t capacity = elements->GetLength(); uint32_t first = deque->GetFirst(); @@ -47,7 +47,7 @@ void JSAPIDeque::InsertFront(JSThread *thread, const JSHandle &deque void JSAPIDeque::InsertEnd(JSThread *thread, const JSHandle &deque, const JSHandle &value) { - JSHandle elements(thread, deque->GetElements()); + JSHandle elements(thread, deque->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); uint32_t capacity = elements->GetLength(); uint32_t first = deque->GetFirst(); @@ -66,37 +66,37 @@ void JSAPIDeque::InsertEnd(JSThread *thread, const JSHandle &deque, deque->SetLast(last); } -JSTaggedValue JSAPIDeque::GetFront() +JSTaggedValue JSAPIDeque::GetFront(const JSThread *thread) { if (JSAPIDeque::IsEmpty()) { return JSTaggedValue::Undefined(); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); - return elements->Get(GetFirst()); + return elements->Get(thread, GetFirst()); } -JSTaggedValue JSAPIDeque::GetTail() +JSTaggedValue JSAPIDeque::GetTail(const JSThread *thread) { if (JSAPIDeque::IsEmpty()) { return JSTaggedValue::Undefined(); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); uint32_t capacity = elements->GetLength(); uint32_t last = GetLast(); ASSERT(capacity != 0); - return elements->Get((last + capacity - 1) % capacity); + return elements->Get(thread, (last + capacity - 1) % capacity); } JSHandle JSAPIDeque::GrowCapacity(JSThread *thread, const JSHandle &deque, uint32_t oldCapacity, uint32_t first, uint32_t last) { - JSHandle oldElements(thread, deque->GetElements()); + JSHandle oldElements(thread, deque->GetElements(thread)); ASSERT(!oldElements->IsDictionaryMode()); uint32_t newCapacity = ComputeCapacity(oldCapacity); - uint32_t size = deque->GetSize(); + uint32_t size = deque->GetSize(thread); JSHandle newElements = thread->GetEcmaVM()->GetFactory()->CopyDeque(oldElements, newCapacity, size, first, last); deque->SetElements(thread, newElements); @@ -109,10 +109,10 @@ JSTaggedValue JSAPIDeque::PopFirst(JSThread *thread) return JSTaggedValue::Undefined(); } uint32_t first = GetFirst(); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); uint32_t capacity = elements->GetLength(); - JSTaggedValue firstElement = elements->Get(first); + JSTaggedValue firstElement = elements->Get(thread, first); ASSERT(capacity != 0); elements->Set(thread, first, JSTaggedValue::Hole()); first = (first + 1) % capacity; @@ -126,13 +126,13 @@ JSTaggedValue JSAPIDeque::PopLast(JSThread *thread) return JSTaggedValue::Undefined(); } uint32_t last = GetLast(); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); uint32_t capacity = elements->GetLength(); ASSERT(capacity != 0); elements->Set(thread, last, JSTaggedValue::Hole()); last = (last + capacity - 1) % capacity; - JSTaggedValue lastElement = elements->Get(last); + JSTaggedValue lastElement = elements->Get(thread, last); SetLast(last); return lastElement; } @@ -144,9 +144,9 @@ bool JSAPIDeque::IsEmpty() return first == last; } -uint32_t JSAPIDeque::GetSize() const +uint32_t JSAPIDeque::GetSize(const JSThread *thread) const { - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); uint32_t first = GetFirst(); uint32_t last = GetLast(); @@ -154,24 +154,24 @@ uint32_t JSAPIDeque::GetSize() const return (last - first + capacity) % capacity; } -JSTaggedValue JSAPIDeque::Get(const uint32_t index) +JSTaggedValue JSAPIDeque::Get(const JSThread *thread, const uint32_t index) { - ASSERT(index < GetSize()); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + ASSERT(index < GetSize(thread)); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); uint32_t first = GetFirst(); ASSERT(capacity != 0); uint32_t curIndex = (first + index) % capacity; - return elements->Get(curIndex); + return elements->Get(thread, curIndex); } JSTaggedValue JSAPIDeque::Set(JSThread *thread, const uint32_t index, JSTaggedValue value) { - uint32_t length = static_cast(GetSize()); + uint32_t length = static_cast(GetSize(thread)); if (index < 0 || index >= length) { return JSTaggedValue::False(); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); uint32_t first = GetFirst(); ASSERT(capacity != 0); @@ -180,15 +180,15 @@ JSTaggedValue JSAPIDeque::Set(JSThread *thread, const uint32_t index, JSTaggedVa return JSTaggedValue::True(); } -bool JSAPIDeque::Has(JSTaggedValue value) const +bool JSAPIDeque::Has(const JSThread *thread, JSTaggedValue value) const { uint32_t first = GetFirst(); uint32_t last = GetLast(); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); uint32_t index = first; while (index != last) { - if (JSTaggedValue::SameValue(elements->Get(index), value)) { + if (JSTaggedValue::SameValue(thread, elements->Get(thread, index), value)) { return true; } ASSERT(capacity != 0); @@ -199,9 +199,9 @@ bool JSAPIDeque::Has(JSTaggedValue value) const JSHandle JSAPIDeque::OwnKeys(JSThread *thread, const JSHandle &deque) { - uint32_t length = deque->GetSize(); + uint32_t length = deque->GetSize(thread); - JSHandle oldElements(thread, deque->GetElements()); + JSHandle oldElements(thread, deque->GetElements(thread)); uint32_t oldCapacity = oldElements->GetLength(); uint32_t newCapacity = ComputeCapacity(oldCapacity); uint32_t firstIndex = deque->GetFirst(); @@ -217,9 +217,9 @@ JSHandle JSAPIDeque::OwnKeys(JSThread *thread, const JSHandle JSAPIDeque::OwnEnumKeys(JSThread *thread, const JSHandle &deque) { - uint32_t length = deque->GetSize(); + uint32_t length = deque->GetSize(thread); - JSHandle oldElements(thread, deque->GetElements()); + JSHandle oldElements(thread, deque->GetElements(thread)); ASSERT(!oldElements->IsDictionaryMode()); uint32_t oldCapacity = oldElements->GetLength(); uint32_t newCapacity = ComputeCapacity(oldCapacity); @@ -238,17 +238,17 @@ bool JSAPIDeque::GetOwnProperty(JSThread *thread, const JSHandle &de const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"key\" can not obtain attributes of no-number type. Received value is: " - + ConvertToString(*result); + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - uint32_t length = deque->GetSize(); + uint32_t length = deque->GetSize(thread); if (index >= length) { ASSERT(length > 0); std::ostringstream oss; @@ -258,7 +258,7 @@ bool JSAPIDeque::GetOwnProperty(JSThread *thread, const JSHandle &de THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - deque->Get(index); + deque->Get(thread, index); return true; } @@ -273,7 +273,7 @@ JSTaggedValue JSAPIDeque::GetIteratorObj(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - int length = static_cast(obj->GetSize()); + int length = static_cast(obj->GetSize(thread)); if (length == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, OperationResult(thread, @@ -304,14 +304,14 @@ OperationResult JSAPIDeque::GetProperty(JSThread *thread, const JSHandleGet(index), PropertyMetaData(false)); + return OperationResult(thread, obj->Get(thread, index), PropertyMetaData(false)); } bool JSAPIDeque::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - int length = static_cast(obj->GetSize()); + int length = static_cast(obj->GetSize(thread)); JSHandle indexKey = key; if (indexKey->IsDouble()) { // Math.floor(1) will produce TaggedDouble, we need to cast into TaggedInt diff --git a/ecmascript/js_api/js_api_deque.h b/ecmascript/js_api/js_api_deque.h index 3d6e0a0779..7bf010b4cc 100644 --- a/ecmascript/js_api/js_api_deque.h +++ b/ecmascript/js_api/js_api_deque.h @@ -57,21 +57,21 @@ public: static bool SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value); - JSTaggedValue GetFront(); + JSTaggedValue GetFront(const JSThread *thread); - JSTaggedValue GetTail(); + JSTaggedValue GetTail(const JSThread *thread); JSTaggedValue PopFirst(JSThread *thread); JSTaggedValue PopLast(JSThread *thread); - JSTaggedValue Get(const uint32_t index); + JSTaggedValue Get(const JSThread *thread, const uint32_t index); JSTaggedValue PUBLIC_API Set(JSThread *thread, const uint32_t index, JSTaggedValue value); - uint32_t GetSize() const; + uint32_t GetSize(const JSThread *thread) const; - bool Has(JSTaggedValue value) const; + bool Has(const JSThread *thread, JSTaggedValue value) const; static constexpr size_t FIRST_OFFSET = JSObject::SIZE; ACCESSORS_PRIMITIVE_FIELD(First, uint32_t, FIRST_OFFSET, LAST_OFFSET) diff --git a/ecmascript/js_api/js_api_deque_iterator.cpp b/ecmascript/js_api/js_api_deque_iterator.cpp index 52ed43ccb5..aa3eb1f4b6 100644 --- a/ecmascript/js_api/js_api_deque_iterator.cpp +++ b/ecmascript/js_api/js_api_deque_iterator.cpp @@ -39,7 +39,7 @@ JSTaggedValue JSAPIDequeIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle iteratorDeque(thread, iter->GetIteratedDeque()); + JSHandle iteratorDeque(thread, iter->GetIteratedDeque(thread)); if (iteratorDeque->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return env->GetUndefinedIteratorResult().GetTaggedValue(); @@ -47,7 +47,7 @@ JSTaggedValue JSAPIDequeIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle deque = JSHandle::Cast(iteratorDeque); uint32_t index = iter->GetNextIndex(); - JSHandle elements(thread, deque->GetElements()); + JSHandle elements(thread, deque->GetElements(thread)); uint32_t capacity = elements->GetLength(); uint32_t first = deque->GetFirst(); uint32_t last = deque->GetLast(); @@ -60,7 +60,7 @@ JSTaggedValue JSAPIDequeIterator::Next(EcmaRuntimeCallInfo *argv) ASSERT(capacity != 0); iter->SetNextIndex((index + 1) % capacity); uint32_t elementIndex = (index + capacity - first) % capacity; - JSHandle value(thread, JSHandle::Cast(iteratorDeque)->Get(elementIndex)); + JSHandle value(thread, JSHandle::Cast(iteratorDeque)->Get(thread, elementIndex)); return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } diff --git a/ecmascript/js_api/js_api_hasharray_iterator.h b/ecmascript/js_api/js_api_hasharray_iterator.h index 78888fdfdb..b3e86f4498 100644 --- a/ecmascript/js_api/js_api_hasharray_iterator.h +++ b/ecmascript/js_api/js_api_hasharray_iterator.h @@ -34,23 +34,23 @@ public: { JSTaggedValue rootValue; uint32_t index = iter->GetNextIndex(); - if (queue->Empty()) { - rootValue = tableArr->Get(index); + if (queue->Empty(thread)) { + rootValue = tableArr->Get(thread, index); ASSERT(rootValue.IsRBTreeNode()); } else { rootValue = queue->Pop(thread); } JSHandle root = JSHandle(thread, rootValue); - if (!root->GetLeft().IsHole()) { - JSHandle left(thread, root->GetLeft()); + if (!root->GetLeft(thread).IsHole()) { + JSHandle left(thread, root->GetLeft(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left))); } - if (!root->GetRight().IsHole()) { - JSHandle right(thread, root->GetRight()); + if (!root->GetRight(thread).IsHole()) { + JSHandle right(thread, root->GetRight(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right))); } // iter == RBTree.end(), move index to next position - if (queue->Empty()) { + if (queue->Empty(thread)) { iter->SetNextIndex(++index); } iter->SetTaggedQueue(thread, queue.GetTaggedValue()); @@ -65,9 +65,9 @@ public: ASSERT((std::is_same_v) || (std::is_same_v)); uint32_t index = iter->GetNextIndex(); // judge type of tableArr[index](Hole, LinkList, RBTree) - JSHandle root(thread, tableArr->Get(index)); + JSHandle root(thread, tableArr->Get(thread, index)); if (root->IsHole()) { - JSHandle rootValue = JSHandle(thread, tableArr->Get(index)); + JSHandle rootValue = JSHandle(thread, tableArr->Get(thread, index)); return rootValue; } // RBTree @@ -75,12 +75,12 @@ public: return GetRBTreeCurrentNode(thread, iter, queue, tableArr); } // LinkList - JSHandle currentNodeValue(thread, iter->GetCurrentNodeResult()); + JSHandle currentNodeValue(thread, iter->GetCurrentNodeResult(thread)); if (!currentNodeValue->IsLinkedNode()) { currentNodeValue = root; } JSHandle currentNode = JSHandle::Cast(currentNodeValue); - JSTaggedValue next = currentNode->GetNext(); + JSTaggedValue next = currentNode->GetNext(thread); // iter == linklist.end(), move index to next position if (next.IsHole()) { iter->SetNextIndex(++index); diff --git a/ecmascript/js_api/js_api_hashmap.cpp b/ecmascript/js_api/js_api_hashmap.cpp index 8e76f65df9..db2eaad536 100644 --- a/ecmascript/js_api/js_api_hashmap.cpp +++ b/ecmascript/js_api/js_api_hashmap.cpp @@ -28,7 +28,7 @@ JSTaggedValue JSAPIHashMap::IsEmpty() JSTaggedValue JSAPIHashMap::HasKey(JSThread *thread, JSTaggedValue key) { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); int hash = TaggedNode::Hash(thread, key); return JSTaggedValue(!(hashArray->GetNode(thread, hash, key).IsHole())); } @@ -36,7 +36,7 @@ JSTaggedValue JSAPIHashMap::HasKey(JSThread *thread, JSTaggedValue key) JSTaggedValue JSAPIHashMap::HasValue(JSThread *thread, JSHandle hashMap, JSHandle value) { - JSHandle hashArray(thread, hashMap->GetTable()); + JSHandle hashArray(thread, hashMap->GetTable(thread)); uint32_t tabLength = hashArray->GetLength(); JSTaggedType *array = hashArray->GetData(); JSTaggedValue taggedValue = value.GetTaggedValue(); @@ -46,11 +46,11 @@ JSTaggedValue JSAPIHashMap::HasValue(JSThread *thread, JSHandle ha continue; } if (node.IsLinkedNode()) { - if (HasValueLinkedNode(node, taggedValue)) { + if (HasValueLinkedNode(thread, node, taggedValue)) { return JSTaggedValue::True(); } } else { - if (HasValueRBTreeNode(node, taggedValue)) { + if (HasValueRBTreeNode(thread, node, taggedValue)) { return JSTaggedValue::True(); } } @@ -58,32 +58,32 @@ JSTaggedValue JSAPIHashMap::HasValue(JSThread *thread, JSHandle ha return JSTaggedValue::False(); } -bool JSAPIHashMap::HasValueLinkedNode(JSTaggedValue node, JSTaggedValue value) +bool JSAPIHashMap::HasValueLinkedNode(JSThread *thread, JSTaggedValue node, JSTaggedValue value) { ASSERT(node.IsLinkedNode()); while (!node.IsHole()) { LinkedNode *p = LinkedNode::Cast(node.GetTaggedObject()); - if (JSTaggedValue::SameValue(p->GetValue(), value)) { + if (JSTaggedValue::SameValue(thread, p->GetValue(thread), value)) { return true; } - node = p->GetNext(); + node = p->GetNext(thread); } return false; } -bool JSAPIHashMap::HasValueRBTreeNode(JSTaggedValue node, JSTaggedValue value) +bool JSAPIHashMap::HasValueRBTreeNode(JSThread *thread, JSTaggedValue node, JSTaggedValue value) { ASSERT(node.IsRBTreeNode()); RBTreeNode *p = RBTreeNode::Cast(node.GetTaggedObject()); - if (JSTaggedValue::SameValue(p->GetValue(), value)) { + if (JSTaggedValue::SameValue(thread, p->GetValue(thread), value)) { return true; } - JSTaggedValue left = p->GetLeft(); - if (!left.IsHole() && HasValueRBTreeNode(left, value)) { + JSTaggedValue left = p->GetLeft(thread); + if (!left.IsHole() && HasValueRBTreeNode(thread, left, value)) { return true; } - JSTaggedValue right = p->GetRight(); - if (!right.IsHole() && HasValueRBTreeNode(right, value)) { + JSTaggedValue right = p->GetRight(thread); + if (!right.IsHole() && HasValueRBTreeNode(thread, right, value)) { return true; } return false; @@ -91,7 +91,7 @@ bool JSAPIHashMap::HasValueRBTreeNode(JSTaggedValue node, JSTaggedValue value) bool JSAPIHashMap::Replace(JSThread *thread, JSTaggedValue key, JSTaggedValue newValue) { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); int hash = TaggedNode::Hash(thread, key); JSTaggedValue nodeVa = hashArray->GetNode(thread, hash, key); if (nodeVa.IsHole()) { @@ -111,11 +111,11 @@ void JSAPIHashMap::Set(JSThread *thread, JSHandle hashMap, if (key.GetTaggedValue().IsUndefined()) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); CString errorMsg = - "The type of \"key\" must be Key of JS. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be Key of JS. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN(thread, error); } - JSHandle hashArray(thread, hashMap->GetTable()); + JSHandle hashArray(thread, hashMap->GetTable(thread)); int hash = TaggedNode::Hash(thread, key.GetTaggedValue()); JSTaggedValue setValue = TaggedHashArray::SetVal(thread, hashArray, hash, key, value); uint32_t nodeNum = hashMap->GetSize(); @@ -131,25 +131,25 @@ void JSAPIHashMap::Set(JSThread *thread, JSHandle hashMap, JSTaggedValue JSAPIHashMap::Get(JSThread *thread, JSTaggedValue key) { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); int hash = TaggedNode::Hash(thread, key); JSTaggedValue node = hashArray->GetNode(thread, hash, key); if (node.IsHole()) { return JSTaggedValue::Undefined(); } else if (node.IsRBTreeNode()) { - return RBTreeNode::Cast(node.GetTaggedObject())->GetValue(); + return RBTreeNode::Cast(node.GetTaggedObject())->GetValue(thread); } else { - return LinkedNode::Cast(node.GetTaggedObject())->GetValue(); + return LinkedNode::Cast(node.GetTaggedObject())->GetValue(thread); } } void JSAPIHashMap::SetAll(JSThread *thread, JSHandle dst, JSHandle src) { - JSHandle hashArray(thread, src->GetTable()); + JSHandle hashArray(thread, src->GetTable(thread)); uint32_t srcTabLength = hashArray->GetLength(); JSMutableHandle node(thread, JSTaggedValue::Hole()); for (uint32_t index = 0; index < srcTabLength; index++) { - node.Update(hashArray->Get(index)); + node.Update(hashArray->Get(thread, index)); if (node->IsHole()) { continue; } @@ -165,28 +165,28 @@ void JSAPIHashMap::SetAllLinkedNode(JSThread *thread, JSHandle has { ASSERT(node.GetTaggedValue().IsLinkedNode()); while (!node.GetTaggedValue().IsHole()) { - if (!hashMap->Replace(thread, node->GetKey(), node->GetValue())) { - JSHandle key(thread, node->GetKey()); - JSHandle value(thread, node->GetValue()); + if (!hashMap->Replace(thread, node->GetKey(thread), node->GetValue(thread))) { + JSHandle key(thread, node->GetKey(thread)); + JSHandle value(thread, node->GetValue(thread)); Set(thread, hashMap, key, value); } - node.Update(node->GetNext()); + node.Update(node->GetNext(thread)); } } void JSAPIHashMap::SetAllRBTreeNode(JSThread *thread, JSHandle hashMap, JSHandle node) { ASSERT(node.GetTaggedValue().IsRBTreeNode()); - JSMutableHandle key(thread, node->GetKey()); - JSMutableHandle value(thread, node->GetValue()); + JSMutableHandle key(thread, node->GetKey(thread)); + JSMutableHandle value(thread, node->GetValue(thread)); if (!hashMap->Replace(thread, key.GetTaggedValue(), value.GetTaggedValue())) { Set(thread, hashMap, key, value); } - JSMutableHandle left(thread, node->GetLeft()); + JSMutableHandle left(thread, node->GetLeft(thread)); if (!left.GetTaggedValue().IsHole()) { SetAllRBTreeNode(thread, hashMap, left); } - JSMutableHandle right(thread, node->GetRight()); + JSMutableHandle right(thread, node->GetRight(thread)); if (!right.GetTaggedValue().IsHole()) { SetAllRBTreeNode(thread, hashMap, right); } @@ -194,7 +194,7 @@ void JSAPIHashMap::SetAllRBTreeNode(JSThread *thread, JSHandle has void JSAPIHashMap::Clear(JSThread *thread) { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); uint32_t nodeLength = GetSize(); if (nodeLength > 0) { hashArray->Clear(thread); @@ -208,7 +208,7 @@ JSTaggedValue JSAPIHashMap::Remove(JSThread *thread, JSHandle hash return JSTaggedValue::Undefined(); } - JSHandle hashArray(thread, hashMap->GetTable()); + JSHandle hashArray(thread, hashMap->GetTable(thread)); uint32_t nodeNum = hashMap->GetSize(); if (nodeNum == 0) { return JSTaggedValue::Undefined(); @@ -224,7 +224,7 @@ JSTaggedValue JSAPIHashMap::Remove(JSThread *thread, JSHandle hash "TaggedHashArray length must greater than or equal to the default minimum value"); uint32_t index = (length - 1) & hash; - JSTaggedValue rootVa = hashArray->Get(index); + JSTaggedValue rootVa = hashArray->Get(thread, index); if (rootVa.IsRBTreeNode()) { uint32_t numTreeNode = RBTreeNode::Count(rootVa); if (numTreeNode < TaggedHashArray::UNTREEIFY_THRESHOLD) { diff --git a/ecmascript/js_api/js_api_hashmap.h b/ecmascript/js_api/js_api_hashmap.h index 1259ce6c9d..dafbb96d9b 100644 --- a/ecmascript/js_api/js_api_hashmap.h +++ b/ecmascript/js_api/js_api_hashmap.h @@ -57,8 +57,8 @@ public: private: static void SetAllLinkedNode(JSThread *thread, JSHandle hashMap, JSMutableHandle node); static void SetAllRBTreeNode(JSThread *thread, JSHandle hashMap, JSHandle node); - static bool HasValueLinkedNode(JSTaggedValue node, JSTaggedValue value); - static bool HasValueRBTreeNode(JSTaggedValue node, JSTaggedValue value); + static bool HasValueLinkedNode(JSThread *thread, JSTaggedValue node, JSTaggedValue value); + static bool HasValueRBTreeNode(JSThread *thread, JSTaggedValue node, JSTaggedValue value); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JS_API_JS_API_HASHMAP_H diff --git a/ecmascript/js_api/js_api_hashmap_iterator.cpp b/ecmascript/js_api/js_api_hashmap_iterator.cpp index b9f98a32f5..1b53a027b8 100644 --- a/ecmascript/js_api/js_api_hashmap_iterator.cpp +++ b/ecmascript/js_api/js_api_hashmap_iterator.cpp @@ -36,17 +36,17 @@ JSTaggedValue JSAPIHashMapIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter = JSHandle::Cast(input); - JSHandle iteratedHashMap(thread, iter->GetIteratedHashMap()); + JSHandle iteratedHashMap(thread, iter->GetIteratedHashMap(thread)); // If m is undefined, return undefinedIteratorResult. if (iteratedHashMap->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return env->GetUndefinedIteratorResult().GetTaggedValue(); } - JSHandle tableArr(thread, JSHandle::Cast(iteratedHashMap)->GetTable()); + JSHandle tableArr(thread, JSHandle::Cast(iteratedHashMap)->GetTable(thread)); uint32_t tableLength = tableArr->GetLength(); uint32_t index = iter->GetNextIndex(); - JSMutableHandle queue(thread, iter->GetTaggedQueue()); + JSMutableHandle queue(thread, iter->GetTaggedQueue(thread)); JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle currentNode(thread, JSTaggedValue::Undefined()); @@ -58,12 +58,12 @@ JSTaggedValue JSAPIHashMapIterator::Next(EcmaRuntimeCallInfo *argv) iter->SetNextIndex(++index); continue; } - JSTaggedValue key = currentNode->GetKey(); + JSTaggedValue key = currentNode->GetKey(thread); keyHandle.Update(key); if (itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, keyHandle, false).GetTaggedValue(); } - valueHandle.Update(currentNode->GetValue()); + valueHandle.Update(currentNode->GetValue(thread)); if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, valueHandle, false).GetTaggedValue(); } diff --git a/ecmascript/js_api/js_api_hashset.cpp b/ecmascript/js_api/js_api_hashset.cpp index bb11cbf343..64b1a85f25 100644 --- a/ecmascript/js_api/js_api_hashset.cpp +++ b/ecmascript/js_api/js_api_hashset.cpp @@ -32,11 +32,11 @@ JSTaggedValue JSAPIHashSet::Has(JSThread *thread, JSTaggedValue value) JSHandle result = JSTaggedValue::ToString(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"value\" must be Key of JS. Received value is: " + ConvertToString(*result); + "The type of \"value\" must be Key of JS. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); int hash = TaggedNode::Hash(thread, value); return JSTaggedValue(!(hashArray->GetNode(thread, hash, value).IsHole())); } @@ -46,11 +46,11 @@ void JSAPIHashSet::Add(JSThread *thread, JSHandle hashSet, JSHandl if (!TaggedHashArray::IsKey(value.GetTaggedValue())) { JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); CString errorMsg = - "The type of \"value\" must be Key of JS. Received value is: " + ConvertToString(*result); + "The type of \"value\" must be Key of JS. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN(thread, error); } - JSHandle hashArray(thread, hashSet->GetTable()); + JSHandle hashArray(thread, hashSet->GetTable(thread)); int hash = TaggedNode::Hash(thread, value.GetTaggedValue()); JSHandle nullHandle(thread, JSTaggedValue::Null()); JSTaggedValue setValue = TaggedHashArray::SetVal(thread, hashArray, hash, value, nullHandle); @@ -67,7 +67,7 @@ void JSAPIHashSet::Add(JSThread *thread, JSHandle hashSet, JSHandl void JSAPIHashSet::Clear(JSThread *thread) { - TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable().GetTaggedObject()); + TaggedHashArray *hashArray = TaggedHashArray::Cast(GetTable(thread).GetTaggedObject()); uint32_t nodeLength = GetSize(); if (nodeLength > 0) { hashArray->Clear(thread); @@ -81,12 +81,12 @@ JSTaggedValue JSAPIHashSet::Remove(JSThread *thread, JSHandle hash JSHandle result = JSTaggedValue::ToString(thread, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be not null. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be not null. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - JSHandle hashArray(thread, hashSet->GetTable()); + JSHandle hashArray(thread, hashSet->GetTable(thread)); uint32_t nodeNum = hashSet->GetSize(); if (nodeNum == 0) { return JSTaggedValue::False(); @@ -100,7 +100,7 @@ JSTaggedValue JSAPIHashSet::Remove(JSThread *thread, JSHandle hash uint32_t length = hashArray->GetLength(); ASSERT(length > 0); uint32_t index = (length - 1) & hash; - JSTaggedValue rootVa = hashArray->Get(index); + JSTaggedValue rootVa = hashArray->Get(thread, index); if (rootVa.IsRBTreeNode()) { uint32_t numTreeNode = RBTreeNode::Count(rootVa); if (numTreeNode < TaggedHashArray::UNTREEIFY_THRESHOLD) { diff --git a/ecmascript/js_api/js_api_hashset_iterator.cpp b/ecmascript/js_api/js_api_hashset_iterator.cpp index c10888e841..88d3a4eb6a 100644 --- a/ecmascript/js_api/js_api_hashset_iterator.cpp +++ b/ecmascript/js_api/js_api_hashset_iterator.cpp @@ -36,16 +36,16 @@ JSTaggedValue JSAPIHashSetIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter = JSHandle::Cast(input); - JSHandle iteratedHashSet(thread, iter->GetIteratedHashSet()); + JSHandle iteratedHashSet(thread, iter->GetIteratedHashSet(thread)); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); if (iteratedHashSet->IsUndefined()) { return env->GetUndefinedIteratorResult().GetTaggedValue(); } JSHandle hashSet = JSHandle::Cast(iteratedHashSet); - JSHandle tableArr(thread, hashSet->GetTable()); + JSHandle tableArr(thread, hashSet->GetTable(thread)); uint32_t tableLength = tableArr->GetLength(); uint32_t index = iter->GetNextIndex(); - JSMutableHandle queue(thread, iter->GetTaggedQueue()); + JSMutableHandle queue(thread, iter->GetTaggedQueue(thread)); JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle currentNode(thread, JSTaggedValue::Undefined()); IterationKind itemKind = iter->GetIterationKind(); @@ -55,7 +55,7 @@ JSTaggedValue JSAPIHashSetIterator::Next(EcmaRuntimeCallInfo *argv) iter->SetNextIndex(++index); continue; } - valueHandle.Update(currentNode->GetKey()); + valueHandle.Update(currentNode->GetKey(thread)); if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, valueHandle, false).GetTaggedValue(); } diff --git a/ecmascript/js_api/js_api_lightweightmap.cpp b/ecmascript/js_api/js_api_lightweightmap.cpp index d7a91afc16..cd7b5aa055 100644 --- a/ecmascript/js_api/js_api_lightweightmap.cpp +++ b/ecmascript/js_api/js_api_lightweightmap.cpp @@ -94,7 +94,7 @@ JSTaggedValue JSAPILightWeightMap::Get(JSThread *thread, const JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); - return valueArray->Get(index); + return valueArray->Get(thread, index); } JSTaggedValue JSAPILightWeightMap::HasAll(JSThread *thread, const JSHandle &lightWeightMap, @@ -115,16 +115,16 @@ JSTaggedValue JSAPILightWeightMap::HasAll(JSThread *thread, const JSHandleGet(num); + dealKey = newKeyArray->Get(thread, num); hash = Hash(thread, dealKey); - index = BinarySearchHashes(oldHashArray, hash, static_cast(len)); + index = BinarySearchHashes(thread, oldHashArray, hash, static_cast(len)); if (index < 0 || index >= static_cast(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))) { + index = AvoidHashCollision(thread, params, index, len, hash); + if (!JSTaggedValue::SameValue(thread, oldKeyArray->Get(thread, index), dealKey) || + !JSTaggedValue::SameValue(thread, oldValueArray->Get(thread, index), newValueArray->Get(thread, num))) { // avoid Hash collision return JSTaggedValue::False(); } @@ -145,7 +145,7 @@ JSTaggedValue JSAPILightWeightMap::HasValue(JSThread *thread, const JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); uint32_t length = lightWeightMap->GetSize(); for (uint32_t num = 0; num < length; num++) { - if (JSTaggedValue::SameValue(valueArray->Get(num), value.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, valueArray->Get(thread, num), value.GetTaggedValue())) { return JSTaggedValue::True(); } } @@ -165,20 +165,20 @@ KeyState JSAPILightWeightMap::GetStateOfKey(JSThread *thread, const JSHandle(lightWeightMap->GetSize()); JSHandle hashArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::HASH); - int32_t index = BinarySearchHashes(hashArray, hash, length); + int32_t index = BinarySearchHashes(thread, 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())) { + while ((right < length) && (hashArray->Get(thread, right).GetInt() == hash)) { + if (JSTaggedValue::SameValue(thread, keyArray->Get(thread, right), key.GetTaggedValue())) { return KeyState {true, hash, right}; } right++; } int32_t left = index - 1; - while ((left >= 0) && ((hashArray->Get(left).GetInt() == hash))) { - if (JSTaggedValue::SameValue(keyArray->Get(left), key.GetTaggedValue())) { + while ((left >= 0) && ((hashArray->Get(thread, left).GetInt() == hash))) { + if (JSTaggedValue::SameValue(thread, keyArray->Get(thread, left), key.GetTaggedValue())) { return KeyState {true, hash, left}; } left--; @@ -195,7 +195,7 @@ int32_t JSAPILightWeightMap::GetIndexOfValue(JSThread *thread, const JSHandleGetSize(); JSTaggedValue compValue = value.GetTaggedValue(); for (uint32_t i = 0; i < length; i++) { - if (valueArray->Get(i) == compValue) { + if (valueArray->Get(thread, i) == compValue) { return i; } } @@ -218,7 +218,7 @@ JSTaggedValue JSAPILightWeightMap::GetKeyAt(JSThread *thread, const JSHandle keyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); - return keyArray->Get(index); + return keyArray->Get(thread, index); } JSTaggedValue JSAPILightWeightMap::GetValueAt(JSThread *thread, const JSHandle &lightWeightMap, @@ -237,7 +237,7 @@ JSTaggedValue JSAPILightWeightMap::GetValueAt(JSThread *thread, const JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); - return valueArray->Get(index); + return valueArray->Get(thread, index); } void JSAPILightWeightMap::SetAll(JSThread *thread, const JSHandle &lightWeightMap, @@ -249,8 +249,8 @@ void JSAPILightWeightMap::SetAll(JSThread *thread, const JSHandle value(thread, JSTaggedValue::Undefined()); uint32_t length = needLightWeightMap->GetSize(); for (uint32_t num = 0; num < length; num++) { - key.Update(needKeyArray->Get(num)); - value.Update(needValueArray->Get(num)); + key.Update(needKeyArray->Get(thread, num)); + value.Update(needValueArray->Get(thread, num)); JSAPILightWeightMap::Set(thread, lightWeightMap, key, value); } } @@ -264,7 +264,7 @@ JSTaggedValue JSAPILightWeightMap::Remove(JSThread *thread, const JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); - JSTaggedValue value = valueArray->Get(index); + JSTaggedValue value = valueArray->Get(thread, index); RemoveValue(thread, lightWeightMap, index, AccossorsKind::HASH); RemoveValue(thread, lightWeightMap, index, AccossorsKind::VALUE); RemoveValue(thread, lightWeightMap, index, AccossorsKind::KEY); @@ -327,18 +327,18 @@ JSTaggedValue JSAPILightWeightMap::SetValueAt(JSThread *thread, const JSHandle(size)) && ((params.hashArray)->Get(right).GetInt() == hash)) { - if (JSTaggedValue::SameValue((params.keyArray)->Get(right), *(params.key))) { + while ((right < static_cast(size)) && ((params.hashArray)->Get(thread, right).GetInt() == hash)) { + if (JSTaggedValue::SameValue(thread, (params.keyArray)->Get(thread, 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))) { + while ((left >= 0) && ((params.hashArray)->Get(thread, left).GetInt() == hash)) { + if (JSTaggedValue::SameValue(thread, (params.keyArray)->Get(thread, left), *(params.key))) { return left; } left--; @@ -374,7 +374,7 @@ JSTaggedValue JSAPILightWeightMap::ToString(JSThread *thread, const JSHandleIsUndefined() && !valueHandle->IsNull()) { JSHandle valueStringHandle = JSTaggedValue::ToString(thread, valueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - valueStr = EcmaStringAccessor(valueStringHandle).ToU16String(); + valueStr = EcmaStringAccessor(valueStringHandle).ToU16String(thread); } std::u16string nextStr; @@ -383,7 +383,7 @@ JSTaggedValue JSAPILightWeightMap::ToString(JSThread *thread, const JSHandleIsUndefined() && !keyHandle->IsNull()) { JSHandle keyStringHandle = JSTaggedValue::ToString(thread, keyHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - nextStr = EcmaStringAccessor(keyStringHandle).ToU16String(); + nextStr = EcmaStringAccessor(keyStringHandle).ToU16String(thread); } nextStr.append(colonStr); @@ -444,13 +444,13 @@ JSHandle JSAPILightWeightMap::GetArrayByKind(const JSThread *thread JSHandle array; switch (kind) { case AccossorsKind::HASH: - array = JSHandle(thread, lightWeightMap->GetHashes()); + array = JSHandle(thread, lightWeightMap->GetHashes(thread)); break; case AccossorsKind::KEY: - array = JSHandle(thread, lightWeightMap->GetKeys()); + array = JSHandle(thread, lightWeightMap->GetKeys(thread)); break; case AccossorsKind::VALUE: - array = JSHandle(thread, lightWeightMap->GetValues()); + array = JSHandle(thread, lightWeightMap->GetValues(thread)); break; default: LOG_ECMA(FATAL) << "this branch is unreachable"; @@ -470,10 +470,10 @@ int32_t JSAPILightWeightMap::Hash(const JSThread *thread, JSTaggedValue key) } if (key.IsString()) { auto keyString = EcmaString::Cast(key.GetTaggedObject()); - return EcmaStringAccessor(keyString).GetHashcode(); + return EcmaStringAccessor(keyString).GetHashcode(thread); } if (key.IsECMAObject()) { - uint32_t hash = static_cast(ECMAObject::Cast(key.GetTaggedObject())->GetHash()); + uint32_t hash = static_cast(ECMAObject::Cast(key.GetTaggedObject())->GetHash(thread)); if (hash == 0) { hash = base::RandomGenerator::GenerateIdentityHash(); JSHandle ecmaObj(thread, key); @@ -493,13 +493,13 @@ int32_t JSAPILightWeightMap::Hash(const JSThread *thread, JSTaggedValue key) return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); } -int32_t JSAPILightWeightMap::BinarySearchHashes(JSHandle &array, int32_t hash, int32_t size) +int32_t JSAPILightWeightMap::BinarySearchHashes(const JSThread *thread, 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(); + int32_t midHash = array->Get(thread, mid).GetInt(); if (midHash < hash) { low = static_cast(mid) + 1; } else { diff --git a/ecmascript/js_api/js_api_lightweightmap.h b/ecmascript/js_api/js_api_lightweightmap.h index 83496b21a9..dee1b1560f 100644 --- a/ecmascript/js_api/js_api_lightweightmap.h +++ b/ecmascript/js_api/js_api_lightweightmap.h @@ -114,11 +114,11 @@ private: static void SetValue(const JSThread *thread, const JSHandle &lightWeightMap, int32_t index, const JSHandle &value, AccossorsKind kind); static int32_t Hash(const JSThread *thread, JSTaggedValue key); - static int32_t BinarySearchHashes(JSHandle &array, int32_t hash, int32_t size); + static int32_t BinarySearchHashes(const JSThread *thread, JSHandle &array, int32_t hash, int32_t size); static JSHandle GetArrayByKind(const JSThread *thread, const JSHandle &lightWeightMap, AccossorsKind kind); - static int32_t AvoidHashCollision(HashParams ¶ms, int32_t index, uint32_t size, int32_t hash); + static int32_t AvoidHashCollision(const JSThread *thread, HashParams ¶ms, int32_t index, uint32_t size, int32_t hash); }; } // namespace panda::ecmascript diff --git a/ecmascript/js_api/js_api_lightweightmap_iterator.cpp b/ecmascript/js_api/js_api_lightweightmap_iterator.cpp index 0ded707461..0f7666bc63 100644 --- a/ecmascript/js_api/js_api_lightweightmap_iterator.cpp +++ b/ecmascript/js_api/js_api_lightweightmap_iterator.cpp @@ -37,7 +37,7 @@ JSTaggedValue JSAPILightWeightMapIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle oldlightWeightMap(thread, iter->GetIteratedLightWeightMap()); + JSHandle oldlightWeightMap(thread, iter->GetIteratedLightWeightMap(thread)); JSHandle lightWeightMap(oldlightWeightMap); IterationKind itemKind = IterationKind(iter->GetIterationKind()); if (oldlightWeightMap->IsUndefined()) { @@ -77,8 +77,8 @@ JSHandle JSAPILightWeightMapIterator::CreateLightWeightMapIterato { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSAPILightWeightMap()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPILightWeightMap()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPILightWeightMap()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/js_api/js_api_lightweightset.cpp b/ecmascript/js_api/js_api_lightweightset.cpp index 17b0053372..ca89ccf033 100644 --- a/ecmascript/js_api/js_api_lightweightset.cpp +++ b/ecmascript/js_api/js_api_lightweightset.cpp @@ -30,8 +30,8 @@ bool JSAPILightWeightSet::Add(JSThread *thread, const JSHandleHash(thread, value.GetTaggedValue()); - JSHandle hashArray(thread, obj->GetHashes()); - JSHandle valueArray(thread, obj->GetValues()); + JSHandle hashArray(thread, obj->GetHashes(thread)); + JSHandle valueArray(thread, obj->GetValues(thread)); int32_t size = static_cast(obj->GetLength()); int32_t index = obj->GetHashIndex(thread, value, size); if (index >= 0) { @@ -58,10 +58,10 @@ bool JSAPILightWeightSet::Add(JSThread *thread, const JSHandleGet(index); + TaggedArray *valueArray = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + return valueArray->Get(thread, index); } JSHandle JSAPILightWeightSet::CreateSlot(const JSThread *thread, const uint32_t capacity) @@ -78,25 +78,25 @@ JSHandle JSAPILightWeightSet::CreateSlot(const JSThread *thread, co int32_t JSAPILightWeightSet::GetHashIndex(const JSThread *thread, const JSHandle &value, int32_t size) { uint32_t hashCode = Hash(thread, value.GetTaggedValue()); - int32_t index = BinarySearchHashes(hashCode, size); + int32_t index = BinarySearchHashes(thread, hashCode, size); if (index < 0) { return index; } - TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); - if (index < size && (JSTaggedValue::SameValue(valueArray->Get(index), value.GetTaggedValue()))) { + TaggedArray *valueArray = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + if (index < size && (JSTaggedValue::SameValue(thread, valueArray->Get(thread, index), value.GetTaggedValue()))) { return index; } - TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); + TaggedArray *hashArray = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); int32_t right = index; - while (right < size && (hashArray->Get(right).GetNumber() == hashCode)) { - if (JSTaggedValue::SameValue(valueArray->Get(right), value.GetTaggedValue())) { + while (right < size && (hashArray->Get(thread, right).GetNumber() == hashCode)) { + if (JSTaggedValue::SameValue(thread, valueArray->Get(thread, 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())) { + while (left >= 0 && ((hashArray->Get(thread, left).GetNumber() == hashCode))) { + if (JSTaggedValue::SameValue(thread, valueArray->Get(thread, left), value.GetTaggedValue())) { return left; } left--; @@ -104,14 +104,14 @@ int32_t JSAPILightWeightSet::GetHashIndex(const JSThread *thread, const JSHandle return -right; } -int32_t JSAPILightWeightSet::BinarySearchHashes(uint32_t hash, int32_t size) +int32_t JSAPILightWeightSet::BinarySearchHashes(const JSThread *thread, uint32_t hash, int32_t size) { int32_t low = 0; int32_t high = size - 1; - TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); + TaggedArray *hashArray = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); while (low <= high) { int32_t mid = (low + high) >> 1U; - uint32_t midVal = (uint32_t)(hashArray->Get(static_cast(mid)).GetNumber()); + uint32_t midVal = (uint32_t)(hashArray->Get(thread, static_cast(mid)).GetNumber()); if (midVal < hash) { low = mid + 1; } else { @@ -134,7 +134,7 @@ bool JSAPILightWeightSet::AddAll(JSThread *thread, const JSHandleEnsureCapacity(thread, obj, size + srcSize); JSMutableHandle element(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < srcSize; i++) { - element.Update(srcLightWeightSet->GetValueAt(i)); + element.Update(srcLightWeightSet->GetValueAt(thread, i)); changed |= JSAPILightWeightSet::Add(thread, obj, element); } return changed; @@ -143,7 +143,7 @@ bool JSAPILightWeightSet::AddAll(JSThread *thread, const JSHandle &obj, uint32_t minimumCapacity) { - TaggedArray *hashes = TaggedArray::Cast(obj->GetValues().GetTaggedObject()); + TaggedArray *hashes = TaggedArray::Cast(obj->GetValues(thread).GetTaggedObject()); uint32_t capacity = hashes->GetLength(); uint32_t newCapacity = capacity; if (capacity > minimumCapacity) { @@ -159,8 +159,8 @@ void JSAPILightWeightSet::EnsureCapacity(const JSThread *thread, const JSHandle< 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()); + JSHandle hashArray(thread, obj->GetHashes(thread)); + JSHandle valueArray(thread, obj->GetValues(thread)); hashArray = thread->GetEcmaVM()->GetFactory()->CopyArray(hashArray, capacity, newCapacity); valueArray = thread->GetEcmaVM()->GetFactory()->CopyArray(valueArray, capacity, newCapacity); @@ -173,43 +173,43 @@ bool JSAPILightWeightSet::IsEmpty() return GetLength() == 0; } -JSTaggedValue JSAPILightWeightSet::GetValueAt(int32_t index) +JSTaggedValue JSAPILightWeightSet::GetValueAt(const JSThread *thread, 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); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + return values->Get(thread, index); } -JSTaggedValue JSAPILightWeightSet::GetHashAt(int32_t index) +JSTaggedValue JSAPILightWeightSet::GetHashAt(const JSThread *thread, 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); + TaggedArray *values = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); + return values->Get(thread, index); } -bool JSAPILightWeightSet::HasAll(const JSHandle &value) +bool JSAPILightWeightSet::HasAll(const JSThread *thread, 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()); + TaggedArray *hashes = TaggedArray::Cast(GetHashes(thread).GetTaggedObject()); + TaggedArray *destHashes = TaggedArray::Cast(lightweightSet->GetHashes(thread).GetTaggedObject()); if (destSize > size) { return result; } for (uint32_t i = 0; i < destSize; i++) { - uint32_t destHashCode = destHashes->Get(i).GetNumber(); + uint32_t destHashCode = destHashes->Get(thread, i).GetNumber(); result = false; for (uint32_t j = relocate; j < size; j++) { - uint32_t hashCode = hashes->Get(j).GetNumber(); + uint32_t hashCode = hashes->Get(thread, j).GetNumber(); if (destHashCode == hashCode) { result = true; relocate = j + 1; @@ -233,10 +233,10 @@ bool JSAPILightWeightSet::Has(const JSThread *thread, const JSHandle &hashCode) +bool JSAPILightWeightSet::HasHash(const JSThread *thread, const JSHandle &hashCode) { uint32_t size = GetLength(); - int32_t index = BinarySearchHashes(hashCode.GetTaggedValue().GetNumber(), size); + int32_t index = BinarySearchHashes(thread, hashCode.GetTaggedValue().GetNumber(), size); if (index < 0) { return false; } @@ -247,17 +247,17 @@ bool JSAPILightWeightSet::Equal(JSThread *thread, const JSHandle &value) { bool result = false; - JSHandle destHashes(thread, obj->GetValues()); + JSHandle destHashes(thread, obj->GetValues(thread)); uint32_t destSize = obj->GetLength(); uint32_t srcSize = 0; - JSMutableHandle srcHashes(thread, obj->GetHashes()); + JSMutableHandle srcHashes(thread, obj->GetHashes(thread)); 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()); + srcHashes.Update(srcLightWeightSet->GetHashes(thread)); } if (value.GetTaggedValue().IsJSArray()) { srcHashes.Update(JSArray::ToTaggedArray(thread, value)); @@ -270,14 +270,15 @@ bool JSAPILightWeightSet::Equal(JSThread *thread, const JSHandleGet(i); - JSTaggedValue values = srcHashes->Get(i); + JSTaggedValue compareValue = destHashes->Get(thread, i); + JSTaggedValue values = srcHashes->Get(thread, i); if (compareValue.IsNumber() && values.IsNumber()) { result = JSTaggedValue::SameValueNumberic(compareValue, values); } if (compareValue.IsString() && values.IsString()) { result = - JSTaggedValue::StringCompare(EcmaString::Cast(compareValue.GetTaggedObject()), + JSTaggedValue::StringCompare(thread, + EcmaString::Cast(compareValue.GetTaggedObject()), EcmaString::Cast(values.GetTaggedObject())); } if (!result) { @@ -290,7 +291,7 @@ bool JSAPILightWeightSet::Equal(JSThread *thread, const JSHandle &obj, int32_t minCapacity) { - uint32_t capacity = TaggedArray::Cast(obj->GetValues().GetTaggedObject())->GetLength(); + uint32_t capacity = TaggedArray::Cast(obj->GetValues(thread).GetTaggedObject())->GetLength(); int32_t intCapacity = static_cast(capacity); if (minCapacity <= 0 || intCapacity >= minCapacity) { std::ostringstream oss; @@ -299,7 +300,7 @@ void JSAPILightWeightSet::IncreaseCapacityTo(JSThread *thread, const JSHandle hashArray(thread, obj->GetHashes()); + JSHandle hashArray(thread, obj->GetHashes(thread)); JSHandle newElements = thread->GetEcmaVM()->GetFactory()->NewAndCopyTaggedArray(hashArray, static_cast(minCapacity), capacity); @@ -324,7 +325,7 @@ JSTaggedValue JSAPILightWeightSet::ForEach(JSThread *thread, const JSHandleGetSize(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (uint32_t k = 0; k < length; k++) { - JSTaggedValue kValue = lightweightset->GetValueAt(k); + JSTaggedValue kValue = lightweightset->GetValueAt(thread, k); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, 3); // 3:three args RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -348,12 +349,12 @@ int32_t JSAPILightWeightSet::GetIndexOf(const JSThread *thread, JSHandle &value) { uint32_t size = GetLength(); - TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *valueArray = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); int32_t index = GetHashIndex(thread, value, size); if (index < 0) { return JSTaggedValue::Undefined(); } - JSTaggedValue result = valueArray->Get(index); + JSTaggedValue result = valueArray->Get(thread, index); RemoveAt(thread, index); return result; } @@ -364,8 +365,8 @@ bool JSAPILightWeightSet::RemoveAt(JSThread *thread, int32_t index) if (index < 0 || index >= static_cast(size)) { return false; } - JSHandle valueArray(thread, GetValues()); - JSHandle hashArray(thread, GetHashes()); + JSHandle valueArray(thread, GetValues(thread)); + JSHandle hashArray(thread, GetHashes(thread)); RemoveValue(thread, hashArray, static_cast(index), true); RemoveValue(thread, valueArray, static_cast(index)); SetLength(size - 1); @@ -387,7 +388,7 @@ void JSAPILightWeightSet::AdjustArray(JSThread *thread, JSHandle sr uint32_t idx = size - 1; if (direction) { while (fromIndex < toIndex) { - JSTaggedValue value = srcArray->Get(idx); + JSTaggedValue value = srcArray->Get(thread, idx); srcArray->Set(thread, idx + 1, value); idx--; fromIndex++; @@ -396,7 +397,7 @@ void JSAPILightWeightSet::AdjustArray(JSThread *thread, JSHandle sr uint32_t moveSize = size - fromIndex; for (uint32_t i = 0; i < moveSize; i++) { if ((fromIndex + i) < size) { - JSTaggedValue value = srcArray->Get(fromIndex + i); + JSTaggedValue value = srcArray->Get(thread, fromIndex + i); srcArray->Set(thread, toIndex + i, value); } else { srcArray->Set(thread, toIndex + i, JSTaggedValue::Hole()); @@ -411,16 +412,16 @@ JSTaggedValue JSAPILightWeightSet::ToString(JSThread *thread, const JSHandle, char16_t> {}.from_bytes(","); uint32_t length = obj->GetSize(); - JSHandle valueArray(thread, obj->GetValues()); + JSHandle valueArray(thread, obj->GetValues(thread)); std::u16string concatStr; JSMutableHandle values(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < length; k++) { std::u16string nextStr; - values.Update(valueArray->Get(k)); + values.Update(valueArray->Get(thread, k)); if (!values->IsUndefined() && !values->IsNull()) { JSHandle nextStringHandle = JSTaggedValue::ToString(thread, values); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - nextStr = EcmaStringAccessor(nextStringHandle).ToU16String(); + nextStr = EcmaStringAccessor(nextStringHandle).ToU16String(thread); } if (k > 0) { concatStr.append(sepStr); @@ -437,8 +438,8 @@ JSTaggedValue JSAPILightWeightSet::ToString(JSThread *thread, const JSHandleSet(thread, index, JSTaggedValue::Hole()); @@ -458,10 +459,10 @@ uint32_t JSAPILightWeightSet::Hash(const JSThread *thread, JSTaggedValue key) } if (key.IsString()) { auto keyString = EcmaString::Cast(key.GetTaggedObject()); - return EcmaStringAccessor(keyString).GetHashcode(); + return EcmaStringAccessor(keyString).GetHashcode(thread); } if (key.IsECMAObject()) { - uint32_t hash = static_cast(ECMAObject::Cast(key.GetTaggedObject())->GetHash()); + uint32_t hash = static_cast(ECMAObject::Cast(key.GetTaggedObject())->GetHash(thread)); if (hash == 0) { hash = static_cast(base::RandomGenerator::GenerateIdentityHash()); JSHandle ecmaObj(thread, key); @@ -479,7 +480,7 @@ uint32_t JSAPILightWeightSet::Hash(const JSThread *thread, JSTaggedValue key) void JSAPILightWeightSet::CheckAndCopyValues(const JSThread *thread, JSHandle obj) { - JSHandle values(thread, obj->GetValues()); + JSHandle values(thread, obj->GetValues(thread)); // Check whether array is shared in the nonmovable space before set properties and elements. // If true, then really copy array in the semi space. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); diff --git a/ecmascript/js_api/js_api_lightweightset.h b/ecmascript/js_api/js_api_lightweightset.h index 02d2daf288..c342a025f8 100644 --- a/ecmascript/js_api/js_api_lightweightset.h +++ b/ecmascript/js_api/js_api_lightweightset.h @@ -48,19 +48,19 @@ public: 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 Get(const JSThread *thread, const uint32_t index); + JSTaggedValue GetHashAt(const JSThread *thread, int32_t index); + JSTaggedValue GetValueAt(const JSThread *thread, int32_t index); JSTaggedValue Remove(JSThread *thread, JSHandle &value); bool Has(const JSThread *thread, const JSHandle &value); - bool HasHash(const JSHandle &hashCode); - bool HasAll(const JSHandle &value); + bool HasHash(const JSThread *thread, const JSHandle &hashCode); + bool HasAll(const JSThread *thread, const JSHandle &value); bool RemoveAt(JSThread *thread, int32_t index); void RemoveValue(const JSThread *thread, JSHandle &taggedArray, uint32_t index, bool isHash = false); bool IsEmpty(); int32_t GetIndexOf(const JSThread *thread, JSHandle &value); - int32_t BinarySearchHashes(uint32_t hash, int32_t size); + int32_t BinarySearchHashes(const JSThread *thread, uint32_t hash, int32_t size); int32_t GetHashIndex(const JSThread *thread, const JSHandle &value, int32_t size); uint32_t Hash(const JSThread *thread, JSTaggedValue key); inline uint32_t GetSize() const diff --git a/ecmascript/js_api/js_api_lightweightset_iterator.cpp b/ecmascript/js_api/js_api_lightweightset_iterator.cpp index b45c6a0739..7b1600a10e 100644 --- a/ecmascript/js_api/js_api_lightweightset_iterator.cpp +++ b/ecmascript/js_api/js_api_lightweightset_iterator.cpp @@ -37,7 +37,7 @@ JSTaggedValue JSAPILightWeightSetIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle lightWeightSet(thread, iter->GetIteratedLightWeightSet()); + JSHandle lightWeightSet(thread, iter->GetIteratedLightWeightSet(thread)); uint32_t index = iter->GetNextIndex(); IterationKind itemKind = IterationKind(iter->GetIterationKind()); if (lightWeightSet->IsUndefined()) { @@ -58,8 +58,8 @@ JSTaggedValue JSAPILightWeightSetIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle lightWeightSetHandle(lightWeightSet); JSAPILightWeightSet::CheckAndCopyValues(thread, lightWeightSetHandle); JSHandle valueArray( - thread, TaggedArray::Cast(lightWeightSetHandle->GetValues().GetTaggedObject())); - JSHandle value(thread, valueArray->Get(index)); + thread, TaggedArray::Cast(lightWeightSetHandle->GetValues(thread).GetTaggedObject())); + JSHandle value(thread, valueArray->Get(thread, index)); if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } diff --git a/ecmascript/js_api/js_api_linked_list.cpp b/ecmascript/js_api/js_api_linked_list.cpp index d45dcf947f..25cf255131 100644 --- a/ecmascript/js_api/js_api_linked_list.cpp +++ b/ecmascript/js_api/js_api_linked_list.cpp @@ -22,7 +22,7 @@ using ErrorFlag = containers::ErrorFlag; JSTaggedValue JSAPILinkedList::Insert(JSThread *thread, const JSHandle &list, const JSHandle &value, const int index) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (index < 0 || index > nodeLength) { std::ostringstream oss; @@ -38,7 +38,7 @@ JSTaggedValue JSAPILinkedList::Insert(JSThread *thread, const JSHandleNumberOfNodes() > 0) { doubleList->Clear(thread); } @@ -46,7 +46,7 @@ void JSAPILinkedList::Clear(JSThread *thread) JSHandle JSAPILinkedList::Clone(JSThread *thread, const JSHandle &list) { - JSTaggedValue doubleListTaggedValue = list->GetDoubleList(); + JSTaggedValue doubleListTaggedValue = list->GetDoubleList(thread); JSHandle srcDoubleList(thread, doubleListTaggedValue); JSHandle srcTaggedArray(thread, doubleListTaggedValue); ASSERT(!srcDoubleList->IsDictionaryMode()); @@ -64,7 +64,7 @@ JSHandle JSAPILinkedList::Clone(JSThread *thread, const JSHandl JSTaggedValue JSAPILinkedList::RemoveFirst(JSThread *thread, const JSHandle &list) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::IS_EMPTY_ERROR, "Container is empty"); @@ -75,7 +75,7 @@ JSTaggedValue JSAPILinkedList::RemoveFirst(JSThread *thread, const JSHandle &list) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::IS_EMPTY_ERROR, "Container is empty"); @@ -86,7 +86,7 @@ JSTaggedValue JSAPILinkedList::RemoveLast(JSThread *thread, const JSHandle &list, const int index) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -105,7 +105,7 @@ JSTaggedValue JSAPILinkedList::RemoveByIndex(JSThread *thread, JSHandleLength(); if (nodeLength < 0) { return JSTaggedValue::False(); @@ -116,7 +116,7 @@ JSTaggedValue JSAPILinkedList::Remove(JSThread *thread, const JSTaggedValue &ele JSTaggedValue JSAPILinkedList::RemoveFirstFound(JSThread *thread, JSHandle &list, const JSTaggedValue &element) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::IS_EMPTY_ERROR, "Container is empty"); @@ -128,7 +128,7 @@ JSTaggedValue JSAPILinkedList::RemoveFirstFound(JSThread *thread, JSHandle &list, const JSTaggedValue &element) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (nodeLength < 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::IS_EMPTY_ERROR, "Container is empty"); @@ -139,7 +139,7 @@ JSTaggedValue JSAPILinkedList::RemoveLastFound(JSThread *thread, JSHandle &list, const JSHandle &value) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); JSTaggedValue newLinkedList = TaggedDoubleList::Add(thread, doubleList, value); list->SetDoubleList(thread, newLinkedList); } @@ -147,23 +147,23 @@ void JSAPILinkedList::Add(JSThread *thread, const JSHandle &lis void JSAPILinkedList::AddFirst(JSThread *thread, const JSHandle &list, const JSHandle &value) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); JSTaggedValue newLinkedList = TaggedDoubleList::AddFirst(thread, doubleList, value); list->SetDoubleList(thread, newLinkedList); } -JSTaggedValue JSAPILinkedList::GetFirst() +JSTaggedValue JSAPILinkedList::GetFirst(const JSThread *thread) { - JSTaggedValue res = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject())->GetFirst(); + JSTaggedValue res = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject())->GetFirst(thread); if (res.IsHole()) { return JSTaggedValue::Undefined(); } return res; } -JSTaggedValue JSAPILinkedList::GetLast() +JSTaggedValue JSAPILinkedList::GetLast(const JSThread *thread) { - JSTaggedValue res = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject())->GetLast(); + JSTaggedValue res = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject())->GetLast(thread); if (res.IsHole()) { return JSTaggedValue::Undefined(); } @@ -173,7 +173,7 @@ JSTaggedValue JSAPILinkedList::GetLast() JSTaggedValue JSAPILinkedList::Set(JSThread *thread, const JSHandle &list, const int index, const JSHandle &value) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -191,43 +191,43 @@ JSTaggedValue JSAPILinkedList::Set(JSThread *thread, const JSHandleHas(element); + TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject()); + return doubleList->Has(thread, element); } -JSTaggedValue JSAPILinkedList::Get(const int index) +JSTaggedValue JSAPILinkedList::Get(const JSThread *thread, const int index) { - TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject()); + TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject()); int nodeLength = doubleList->Length(); if (index < 0 || index >= nodeLength) { return JSTaggedValue::Undefined(); } - return doubleList->Get(index); + return doubleList->Get(thread, index); } -JSTaggedValue JSAPILinkedList::GetIndexOf(const JSTaggedValue &element) +JSTaggedValue JSAPILinkedList::GetIndexOf(const JSThread *thread, const JSTaggedValue &element) { - TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject()); - return JSTaggedValue(doubleList->GetIndexOf(element)); + TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject()); + return JSTaggedValue(doubleList->GetIndexOf(thread, element)); } -JSTaggedValue JSAPILinkedList::GetLastIndexOf(const JSTaggedValue &element) +JSTaggedValue JSAPILinkedList::GetLastIndexOf(const JSThread *thread, const JSTaggedValue &element) { - TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject()); - return JSTaggedValue(doubleList->GetLastIndexOf(element)); + TaggedDoubleList *doubleList = TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject()); + return JSTaggedValue(doubleList->GetLastIndexOf(thread, element)); } JSTaggedValue JSAPILinkedList::ConvertToArray(const JSThread *thread, const JSHandle &list) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); return TaggedDoubleList::ConvertToArray(thread, doubleList); } JSHandle JSAPILinkedList::OwnKeys(JSThread *thread, const JSHandle &list) { - JSHandle doubleList(thread, list->GetDoubleList().GetTaggedObject()); + JSHandle doubleList(thread, list->GetDoubleList(thread).GetTaggedObject()); return TaggedDoubleList::OwnKeys(thread, doubleList); } @@ -235,16 +235,16 @@ bool JSAPILinkedList::GetOwnProperty(JSThread *thread, const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"index\" can not obtain attributes of no-number type. Received value is: " - + ConvertToString(*result); + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); uint32_t length = static_cast(doubleList->Length()); if (length == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -259,14 +259,14 @@ bool JSAPILinkedList::GetOwnProperty(JSThread *thread, const JSHandleGet(index); + list->Get(thread, index); return true; } OperationResult JSAPILinkedList::GetProperty(JSThread *thread, const JSHandle &list, const JSHandle &key) { - JSHandle doubleList(thread, list->GetDoubleList()); + JSHandle doubleList(thread, list->GetDoubleList(thread)); int nodeLength = doubleList->Length(); JSHandle indexKey = key; if (indexKey->IsDouble()) { @@ -292,14 +292,14 @@ OperationResult JSAPILinkedList::GetProperty(JSThread *thread, const JSHandleGet(index), PropertyMetaData(false)); + return OperationResult(thread, doubleList->Get(thread, index), PropertyMetaData(false)); } bool JSAPILinkedList::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - JSHandle doubleList(thread, obj->GetDoubleList()); + JSHandle doubleList(thread, obj->GetDoubleList(thread)); int nodeLength = doubleList->Length(); JSHandle indexKey = key; if (indexKey->IsDouble()) { diff --git a/ecmascript/js_api/js_api_linked_list.h b/ecmascript/js_api/js_api_linked_list.h index 2c05260a14..97713edc89 100644 --- a/ecmascript/js_api/js_api_linked_list.h +++ b/ecmascript/js_api/js_api_linked_list.h @@ -54,16 +54,16 @@ public: static JSTaggedValue RemoveLastFound(JSThread *thread, JSHandle &list, const JSTaggedValue &element); void Clear(JSThread *thread); - bool Has(const JSTaggedValue &element); - JSTaggedValue GetFirst(); - JSTaggedValue GetLast(); - JSTaggedValue Get(const int index); + bool Has(const JSThread *thread, const JSTaggedValue &element); + JSTaggedValue GetFirst(const JSThread *thread); + JSTaggedValue GetLast(const JSThread *thread); + JSTaggedValue Get(const JSThread *thread, const int index); JSTaggedValue Remove(JSThread *thread, const JSTaggedValue &element); - JSTaggedValue GetIndexOf(const JSTaggedValue &element); - JSTaggedValue GetLastIndexOf(const JSTaggedValue &element); - inline uint32_t Length() + JSTaggedValue GetIndexOf(const JSThread *thread, const JSTaggedValue &element); + JSTaggedValue GetLastIndexOf(const JSThread *thread, const JSTaggedValue &element); + inline uint32_t Length(JSThread *thread) { - return TaggedDoubleList::Cast(GetDoubleList().GetTaggedObject())->Length(); + return TaggedDoubleList::Cast(GetDoubleList(thread).GetTaggedObject())->Length(); } static constexpr size_t DOUBLE_LIST_OFFSET = JSObject::SIZE; ACCESSORS(DoubleList, DOUBLE_LIST_OFFSET, SIZE); diff --git a/ecmascript/js_api/js_api_linked_list_iterator.cpp b/ecmascript/js_api/js_api_linked_list_iterator.cpp index 825eda786f..e9af827832 100644 --- a/ecmascript/js_api/js_api_linked_list_iterator.cpp +++ b/ecmascript/js_api/js_api_linked_list_iterator.cpp @@ -36,7 +36,7 @@ JSTaggedValue JSAPILinkedListIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle linkedList(thread, iter->GetIteratedLinkedList()); + JSHandle linkedList(thread, iter->GetIteratedLinkedList(thread)); JSHandle list(linkedList); if (linkedList->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -52,7 +52,7 @@ JSTaggedValue JSAPILinkedListIterator::Next(EcmaRuntimeCallInfo *argv) } iter->SetNextIndex(index + 1); int dataIndex = static_cast(iter->GetDataIndex()); - std::pair resultPair = list->GetByDataIndex(dataIndex); + std::pair resultPair = list->GetByDataIndex(thread, dataIndex); iter->SetDataIndex(resultPair.first); JSHandle value(thread, resultPair.second); return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); @@ -63,8 +63,8 @@ JSHandle JSAPILinkedListIterator::CreateLinkedListIterator(JSThre { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSAPILinkedList()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPILinkedList()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPILinkedList()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/js_api/js_api_list.cpp b/ecmascript/js_api/js_api_list.cpp index e6cee55f28..e32dd3525a 100644 --- a/ecmascript/js_api/js_api_list.cpp +++ b/ecmascript/js_api/js_api_list.cpp @@ -22,23 +22,23 @@ using ContainerError = containers::ContainerError; using ErrorFlag = containers::ErrorFlag; void JSAPIList::Add(JSThread *thread, const JSHandle &list, const JSHandle &value) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); JSTaggedValue newList = TaggedSingleList::Add(thread, singleList, value); list->SetSingleList(thread, newList); } -JSTaggedValue JSAPIList::GetFirst() +JSTaggedValue JSAPIList::GetFirst(const JSThread *thread) { - JSTaggedValue res = TaggedSingleList::Cast(GetSingleList().GetTaggedObject())->GetFirst(); + JSTaggedValue res = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject())->GetFirst(thread); if (res.IsHole()) { return JSTaggedValue::Undefined(); } return res; } -JSTaggedValue JSAPIList::GetLast() +JSTaggedValue JSAPIList::GetLast(const JSThread *thread) { - JSTaggedValue res = TaggedSingleList::Cast(GetSingleList().GetTaggedObject())->GetLast(); + JSTaggedValue res = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject())->GetLast(thread); if (res.IsHole()) { return JSTaggedValue::Undefined(); } @@ -48,7 +48,7 @@ JSTaggedValue JSAPIList::GetLast() JSTaggedValue JSAPIList::Insert(JSThread *thread, const JSHandle &list, const JSHandle &value, const int index) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); int nodeLength = singleList->Length(); if (index < 0 || index > nodeLength) { std::ostringstream oss; @@ -68,7 +68,7 @@ JSTaggedValue JSAPIList::Insert(JSThread *thread, const JSHandle &lis JSTaggedValue JSAPIList::Set(JSThread *thread, const JSHandle &list, const int index, const JSHandle &value) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); int nodeLength = singleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -86,30 +86,30 @@ JSTaggedValue JSAPIList::Set(JSThread *thread, const JSHandle &list, return value.GetTaggedValue(); } -bool JSAPIList::Has(const JSTaggedValue &element) +bool JSAPIList::Has(const JSThread *thread, const JSTaggedValue &element) { - TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); - return singleList->Has(element); + TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); + return singleList->Has(thread, element); } -bool JSAPIList::IsEmpty() +bool JSAPIList::IsEmpty(const JSThread *thread) { - return TaggedSingleList::Cast(GetSingleList().GetTaggedObject())->IsEmpty(); + return TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject())->IsEmpty(); } -JSTaggedValue JSAPIList::Get(const int index) +JSTaggedValue JSAPIList::Get(const JSThread *thread, const int index) { - TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); + TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); int nodeLength = singleList->Length(); if (index < 0 || index >= nodeLength) { return JSTaggedValue::Undefined(); } - return singleList->Get(index); + return singleList->Get(thread, index); } JSTaggedValue JSAPIList::FastGet(JSThread *thread, const int index, const JSHandle &list) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); if (index < 0 || index >= singleList->Length()) { return JSTaggedValue::Undefined(); } @@ -122,26 +122,26 @@ JSTaggedValue JSAPIList::FastGet(JSThread *thread, const int index, const JSHand } list->SetSingleList(thread, newSingleList); list->SetIsOrderedList(true); - return newList->GetElement(dataIndex); + return newList->GetElement(thread, dataIndex); } - return singleList->GetElement(dataIndex); + return singleList->GetElement(thread, dataIndex); } -JSTaggedValue JSAPIList::GetIndexOf(const JSTaggedValue &element) +JSTaggedValue JSAPIList::GetIndexOf(const JSThread *thread, const JSTaggedValue &element) { - TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); - return JSTaggedValue(singleList->GetIndexOf(element)); + TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); + return JSTaggedValue(singleList->GetIndexOf(thread, element)); } -JSTaggedValue JSAPIList::GetLastIndexOf(const JSTaggedValue &element) +JSTaggedValue JSAPIList::GetLastIndexOf(const JSThread *thread, const JSTaggedValue &element) { - TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); - return JSTaggedValue(singleList->GetLastIndexOf(element)); + TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); + return JSTaggedValue(singleList->GetLastIndexOf(thread, element)); } void JSAPIList::Clear(JSThread *thread) { - TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList().GetTaggedObject()); + TaggedSingleList *singleList = TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject()); if (singleList->NumberOfNodes() > 0) { singleList->Clear(thread); } @@ -150,7 +150,7 @@ void JSAPIList::Clear(JSThread *thread) JSTaggedValue JSAPIList::RemoveByIndex(JSThread *thread, const JSHandle &list, const int &index) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); int nodeLength = singleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -170,7 +170,7 @@ JSTaggedValue JSAPIList::RemoveByIndex(JSThread *thread, const JSHandleRemove(thread, element); } @@ -180,7 +180,7 @@ JSTaggedValue JSAPIList::ReplaceAllElements(JSThread *thread, const JSHandle &thisArg) { JSHandle list = JSHandle::Cast(thisHandle); - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); return TaggedSingleList::ReplaceAllElements(thread, thisHandle, callbackFn, thisArg, singleList); } @@ -188,27 +188,27 @@ JSTaggedValue JSAPIList::Sort(JSThread *thread, const JSHandle &t const JSHandle &callbackFn) { JSHandle list = JSHandle::Cast(thisHandle); - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); list->SetIsOrderedList(false); return TaggedSingleList::Sort(thread, callbackFn, singleList); } JSTaggedValue JSAPIList::Equal(JSThread *thread, const JSHandle &list) { - JSHandle compareList(thread, list->GetSingleList()); - return TaggedSingleList::Cast(GetSingleList().GetTaggedObject())->Equal(compareList); + JSHandle compareList(thread, list->GetSingleList(thread)); + return TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject())->Equal(thread, compareList); } JSTaggedValue JSAPIList::ConvertToArray(const JSThread *thread, const JSHandle &list) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); return TaggedSingleList::ConvertToArray(thread, singleList); } JSTaggedValue JSAPIList::GetSubList(JSThread *thread, const JSHandle &list, const int fromIndex, const int toIndex) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); int nodeLength = singleList->Length(); if (nodeLength <= 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -241,23 +241,23 @@ JSTaggedValue JSAPIList::GetSubList(JSThread *thread, const JSHandle JSHandle JSAPIList::OwnKeys(JSThread *thread, const JSHandle &list) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); return TaggedSingleList::OwnKeys(thread, singleList); } bool JSAPIList::GetOwnProperty(JSThread *thread, const JSHandle &list, const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"index\" can not obtain attributes of no-number type. Received value is: " - + ConvertToString(*result); + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); uint32_t length = static_cast(singleList->Length()); if (index >= length) { std::ostringstream oss; @@ -266,14 +266,14 @@ bool JSAPIList::GetOwnProperty(JSThread *thread, const JSHandle &list JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - list->Get(index); + list->Get(thread, index); return true; } OperationResult JSAPIList::GetProperty(JSThread *thread, const JSHandle &list, const JSHandle &key) { - JSHandle singleList(thread, list->GetSingleList()); + JSHandle singleList(thread, list->GetSingleList(thread)); int nodeLength = singleList->Length(); JSHandle indexKey = key; if (indexKey->IsDouble()) { @@ -299,14 +299,14 @@ OperationResult JSAPIList::GetProperty(JSThread *thread, const JSHandleGet(index), PropertyMetaData(false)); + return OperationResult(thread, singleList->Get(thread, index), PropertyMetaData(false)); } bool JSAPIList::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - JSHandle singleList(thread, obj->GetSingleList()); + JSHandle singleList(thread, obj->GetSingleList(thread)); int nodeLength = singleList->Length(); int index = static_cast(key->GetNumber()); if (index < 0 || index >= nodeLength) { diff --git a/ecmascript/js_api/js_api_list.h b/ecmascript/js_api/js_api_list.h index d906d5b1c0..c435dad186 100644 --- a/ecmascript/js_api/js_api_list.h +++ b/ecmascript/js_api/js_api_list.h @@ -78,19 +78,19 @@ public: const JSHandle &value); static JSTaggedValue FastGet(JSThread *thread, const int index, const JSHandle &list); - JSTaggedValue GetFirst(); - JSTaggedValue GetLast(); - bool IsEmpty(); - JSTaggedValue Get(const int index); - bool Has(const JSTaggedValue &element); - JSTaggedValue GetIndexOf(const JSTaggedValue &element); - JSTaggedValue GetLastIndexOf(const JSTaggedValue &element); + JSTaggedValue GetFirst(const JSThread *thread); + JSTaggedValue GetLast(const JSThread *thread); + bool IsEmpty(const JSThread *thread); + JSTaggedValue Get(const JSThread *thread, const int index); + bool Has(const JSThread *thread, const JSTaggedValue &element); + JSTaggedValue GetIndexOf(const JSThread *thread, const JSTaggedValue &element); + JSTaggedValue GetLastIndexOf(const JSThread *thread, const JSTaggedValue &element); JSTaggedValue Equal(JSThread *thread, const JSHandle &list); void Clear(JSThread *thread); JSTaggedValue Remove(JSThread *thread, const JSTaggedValue &element); - inline uint32_t Length() + inline uint32_t Length(const JSThread *thread) { - return TaggedSingleList::Cast(GetSingleList().GetTaggedObject())->Length(); + return TaggedSingleList::Cast(GetSingleList(thread).GetTaggedObject())->Length(); } static constexpr size_t SINGLY_LIST_OFFSET = JSObject::SIZE; diff --git a/ecmascript/js_api/js_api_list_iterator.cpp b/ecmascript/js_api/js_api_list_iterator.cpp index cd66a87661..bf25b43414 100644 --- a/ecmascript/js_api/js_api_list_iterator.cpp +++ b/ecmascript/js_api/js_api_list_iterator.cpp @@ -35,7 +35,7 @@ JSTaggedValue JSAPIListIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle list(thread, iter->GetIteratedList()); + JSHandle list(thread, iter->GetIteratedList(thread)); JSHandle singleList(list); if (list->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -51,7 +51,7 @@ JSTaggedValue JSAPIListIterator::Next(EcmaRuntimeCallInfo *argv) } iter->SetNextIndex(index + 1); int dataIndex = static_cast(iter->GetDataIndex()); - std::pair resultPair = singleList->GetByDataIndex(dataIndex); + std::pair resultPair = singleList->GetByDataIndex(thread, dataIndex); iter->SetDataIndex(resultPair.first); JSHandle value(thread, resultPair.second); return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); @@ -61,8 +61,8 @@ JSHandle JSAPIListIterator::CreateListIterator(JSThread *thread, { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSAPIList()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPIList()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPIList()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/js_api/js_api_plain_array.cpp b/ecmascript/js_api/js_api_plain_array.cpp index 770000e6f4..b730eab97c 100644 --- a/ecmascript/js_api/js_api_plain_array.cpp +++ b/ecmascript/js_api/js_api_plain_array.cpp @@ -26,10 +26,10 @@ using ErrorFlag = containers::ErrorFlag; void JSAPIPlainArray::Add(JSThread *thread, const JSHandle &obj, JSHandle key, JSHandle value) { - JSHandle keyArray(thread, obj->GetKeys()); - JSHandle valueArray(thread, obj->GetValues()); + JSHandle keyArray(thread, obj->GetKeys(thread)); + JSHandle valueArray(thread, obj->GetValues(thread)); uint32_t size = obj->GetLength(); - int32_t index = obj->BinarySearch(*keyArray, 0, size, key.GetTaggedValue().GetNumber()); + int32_t index = obj->BinarySearch(thread, *keyArray, 0, size, key.GetTaggedValue().GetNumber()); if (index >= 0) { keyArray->Set(thread, index, key); valueArray->Set(thread, index, value); @@ -67,8 +67,8 @@ JSHandle JSAPIPlainArray::CreateSlot(const JSThread *thread, const bool JSAPIPlainArray::AdjustForward(JSThread *thread, int32_t index, int32_t forwardSize) { uint32_t size = GetLength(); - TaggedArray *keys = TaggedArray::Cast(GetKeys().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *keys = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); AdjustPrimitiveArray(keys, index + forwardSize, index); AdjustArray(thread, values, index + forwardSize, index, false); size = size - static_cast(forwardSize); @@ -103,7 +103,7 @@ void JSAPIPlainArray::AdjustArray(JSThread *thread, TaggedArray *srcArray, int32 uint32_t idx = size - 1; if (direction) { while (fromIndex < toIndex) { - JSTaggedValue value = srcArray->Get(idx); + JSTaggedValue value = srcArray->Get(thread, idx); srcArray->Set(thread, idx + 1, value); idx--; fromIndex++; @@ -128,13 +128,13 @@ void JSAPIPlainArray::AdjustArray(JSThread *thread, TaggedArray *srcArray, int32 } } -int32_t JSAPIPlainArray::BinarySearch(TaggedArray *array, int32_t fromIndex, int32_t toIndex, int32_t key) +int32_t JSAPIPlainArray::BinarySearch(JSThread *thread, TaggedArray *array, int32_t fromIndex, int32_t toIndex, int32_t key) { int32_t low = fromIndex; int32_t high = toIndex - 1; while (low <= high) { int32_t mid = static_cast(static_cast(low + high) >> 1U); - int32_t midVal = static_cast(array->Get(mid).GetNumber()); + int32_t midVal = static_cast(array->Get(thread, mid).GetNumber()); if (midVal < key) { low = mid + 1; } else { @@ -149,8 +149,8 @@ int32_t JSAPIPlainArray::BinarySearch(TaggedArray *array, int32_t fromIndex, int void JSAPIPlainArray::Clear(JSThread *thread) { - TaggedArray *keys = TaggedArray::Cast(GetKeys().GetTaggedObject()); - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *keys = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); uint32_t size = GetLength(); for (uint32_t index = 0; index < size; index++) { keys->Set(thread, index, JSTaggedValue::Hole()); @@ -196,13 +196,13 @@ JSTaggedValue JSAPIPlainArray::Set(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - TaggedArray *keyArray = TaggedArray::Cast(obj->GetKeys().GetTaggedObject()); + TaggedArray *keyArray = TaggedArray::Cast(obj->GetKeys(thread).GetTaggedObject()); uint32_t size = obj->GetLength(); if (size == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - int32_t index = obj->BinarySearch(keyArray, 0, size, key.GetTaggedValue().GetInt()); + int32_t index = obj->BinarySearch(thread, keyArray, 0, size, key.GetTaggedValue().GetInt()); if (index < 0 || index >= static_cast(size)) { ASSERT(size > 0); std::ostringstream oss; @@ -212,14 +212,14 @@ bool JSAPIPlainArray::GetOwnProperty(JSThread *thread, const JSHandleGet(key.GetTaggedValue()); + obj->Get(thread, key.GetTaggedValue()); return true; } OperationResult JSAPIPlainArray::GetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - TaggedArray *keyArray = TaggedArray::Cast(obj->GetKeys().GetTaggedObject()); + TaggedArray *keyArray = TaggedArray::Cast(obj->GetKeys(thread).GetTaggedObject()); uint32_t size = obj->GetLength(); if (size == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); @@ -241,7 +241,7 @@ OperationResult JSAPIPlainArray::GetProperty(JSThread *thread, const JSHandleGetInt(); - int32_t index = obj->BinarySearch(keyArray, 0, size, keyVal); + int32_t index = obj->BinarySearch(thread, keyArray, 0, size, keyVal); if (index < 0 || index >= static_cast(size)) { std::ostringstream oss; ASSERT(size > 0); @@ -253,14 +253,14 @@ OperationResult JSAPIPlainArray::GetProperty(JSThread *thread, const JSHandleGet(JSTaggedValue(index)), PropertyMetaData(false)); + return OperationResult(thread, obj->Get(thread, JSTaggedValue(index)), PropertyMetaData(false)); } bool JSAPIPlainArray::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - TaggedArray *keyArray = TaggedArray::Cast(obj->GetKeys().GetTaggedObject()); + TaggedArray *keyArray = TaggedArray::Cast(obj->GetKeys(thread).GetTaggedObject()); uint32_t size = obj->GetLength(); JSHandle indexKey = key; if (indexKey->IsDouble()) { @@ -271,7 +271,7 @@ bool JSAPIPlainArray::SetProperty(JSThread *thread, const JSHandleIsInt()) { return false; } - int32_t index = obj->BinarySearch(keyArray, 0, size, indexKey->GetInt()); + int32_t index = obj->BinarySearch(thread, keyArray, 0, size, indexKey->GetInt()); if (index < 0 || index >= static_cast(size)) { return false; } @@ -282,15 +282,15 @@ bool JSAPIPlainArray::SetProperty(JSThread *thread, const JSHandle JSAPIPlainArray::Clone(JSThread *thread, const JSHandle &obj) { - JSHandle srckeys(thread, obj->GetKeys()); - JSHandle srcvalues(thread, obj->GetValues()); + JSHandle srckeys(thread, obj->GetKeys(thread)); + JSHandle srcvalues(thread, obj->GetValues(thread)); auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle newPlainArray = factory->NewJSAPIPlainArray(0); uint32_t length = obj->GetLength(); newPlainArray->SetLength(length); - JSHandle srcKeyArray(thread, obj->GetKeys()); - JSHandle srcValueArray(thread, obj->GetValues()); + JSHandle srcKeyArray(thread, obj->GetKeys(thread)); + JSHandle srcValueArray(thread, obj->GetValues(thread)); JSHandle dstKeyArray = factory->NewAndCopyTaggedArray(srcKeyArray, length, length); JSHandle dstValueArray = factory->NewAndCopyTaggedArray(srcValueArray, length, length); @@ -300,27 +300,27 @@ JSHandle JSAPIPlainArray::Clone(JSThread *thread, const JSHandl return newPlainArray; } -bool JSAPIPlainArray::Has(const int32_t key) +bool JSAPIPlainArray::Has(JSThread *thread, const int32_t key) { uint32_t size = GetLength(); - TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); - int32_t index = BinarySearch(keyArray, 0, size, key); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + int32_t index = BinarySearch(thread, keyArray, 0, size, key); if (index < 0) { return false; } return true; } -JSTaggedValue JSAPIPlainArray::Get(const JSTaggedValue key) +JSTaggedValue JSAPIPlainArray::Get(JSThread *thread, const JSTaggedValue key) { uint32_t size = GetLength(); - TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); - int32_t index = BinarySearch(keyArray, 0, size, key.GetNumber()); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + int32_t index = BinarySearch(thread, keyArray, 0, size, key.GetNumber()); if (index < 0) { return JSTaggedValue::Undefined(); } - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); - return values->Get(index); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + return values->Get(thread, index); } JSHandle JSAPIPlainArray::GetIteratorObj(JSThread *thread, const JSHandle &obj, @@ -339,11 +339,11 @@ JSTaggedValue JSAPIPlainArray::ForEach(JSThread *thread, const JSHandleGetTaggedObject()); uint32_t length = plainarray->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - JSHandle keyArray(thread, plainarray->GetKeys()); - JSHandle valueArray(thread, plainarray->GetValues()); + JSHandle keyArray(thread, plainarray->GetKeys(thread)); + JSHandle valueArray(thread, plainarray->GetValues(thread)); for (uint32_t k = 0; k < length; k++) { - JSTaggedValue kValue = valueArray->Get(k); - JSTaggedValue key = keyArray->Get(k); + JSTaggedValue kValue = valueArray->Get(thread, k); + JSTaggedValue key = keyArray->Get(thread, k); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, 3); // 3: three args RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -371,15 +371,15 @@ JSTaggedValue JSAPIPlainArray::ToString(JSThread *thread, const JSHandleIsUndefined() && !valueHandle->IsNull()) { JSHandle valueStringHandle = JSTaggedValue::ToString(thread, valueHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - valueStr = EcmaStringAccessor(valueStringHandle).ToU16String(); + valueStr = EcmaStringAccessor(valueStringHandle).ToU16String(thread); } std::u16string nextStr; - keyHandle.Update(plainarray->GetKeyAt(k)); + keyHandle.Update(plainarray->GetKeyAt(thread, k)); if (!keyHandle->IsUndefined() && !keyHandle->IsNull()) { JSHandle keyStringHandle = JSTaggedValue::ToString(thread, keyHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - nextStr = EcmaStringAccessor(keyStringHandle).ToU16String(); + nextStr = EcmaStringAccessor(keyStringHandle).ToU16String(thread); } nextStr.append(colonStr); @@ -398,22 +398,22 @@ JSTaggedValue JSAPIPlainArray::ToString(JSThread *thread, const JSHandleNewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); } -JSTaggedValue JSAPIPlainArray::GetIndexOfKey(int32_t key) +JSTaggedValue JSAPIPlainArray::GetIndexOfKey(JSThread *thread, int32_t key) { uint32_t size = GetLength(); - TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); - int32_t index = BinarySearch(keyArray, 0, size, key); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + int32_t index = BinarySearch(thread, keyArray, 0, size, key); if (index < 0) { return JSTaggedValue(-1); } return JSTaggedValue(index); } -JSTaggedValue JSAPIPlainArray::TryFastGetIndexOfValue(TaggedArray *values, JSTaggedValue value) +JSTaggedValue JSAPIPlainArray::TryFastGetIndexOfValue(JSThread *thread, TaggedArray *values, JSTaggedValue value) { uint32_t size = GetLength(); for (uint32_t i = 0; i < size; ++i) { - JSTaggedValue currVal = values->Get(i); + JSTaggedValue currVal = values->Get(thread, i); if (currVal.IsInt() && (currVal == value)) { return JSTaggedValue(i); } @@ -421,15 +421,15 @@ JSTaggedValue JSAPIPlainArray::TryFastGetIndexOfValue(TaggedArray *values, JSTag return JSTaggedValue(-1); } -JSTaggedValue JSAPIPlainArray::GetIndexOfValue(JSTaggedValue value) +JSTaggedValue JSAPIPlainArray::GetIndexOfValue(JSThread *thread, JSTaggedValue value) { - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); if (value.IsInt()) { - return TryFastGetIndexOfValue(values, value); + return TryFastGetIndexOfValue(thread, values, value); } else { uint32_t size = GetLength(); for (uint32_t i = 0; i < size; ++i) { - if (JSTaggedValue::SameValue(values->Get(i), value)) { + if (JSTaggedValue::SameValue(thread, values->Get(thread, i), value)) { return JSTaggedValue(i); } } @@ -443,14 +443,14 @@ bool JSAPIPlainArray::IsEmpty() return length == 0; } -JSTaggedValue JSAPIPlainArray::GetKeyAt(int32_t index) +JSTaggedValue JSAPIPlainArray::GetKeyAt(JSThread *thread, int32_t index) { uint32_t size = GetLength(); - TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); if (index < 0 || index >= static_cast(size)) { return JSTaggedValue::Undefined(); } - return keyArray->Get(index); + return keyArray->Get(thread, index); } JSTaggedValue JSAPIPlainArray::GetValueAt(JSThread *thread, int32_t index) @@ -468,20 +468,20 @@ JSTaggedValue JSAPIPlainArray::GetValueAt(JSThread *thread, int32_t index) JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); - return values->Get(index); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + return values->Get(thread, index); } JSTaggedValue JSAPIPlainArray::Remove(JSThread *thread, JSTaggedValue key) { uint32_t size = GetLength(); - TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); - int32_t index = BinarySearch(keyArray, 0, size, key.GetNumber()); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys(thread).GetTaggedObject()); + int32_t index = BinarySearch(thread, keyArray, 0, size, key.GetNumber()); if (index < 0 || index >= static_cast(size)) { return JSTaggedValue::Undefined(); } - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); - JSTaggedValue value = values->Get(index); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + JSTaggedValue value = values->Get(thread, index); AdjustForward(thread, index, 1); // 1 means the length of array return value; } @@ -493,8 +493,8 @@ JSTaggedValue JSAPIPlainArray::RemoveAt(JSThread *thread, JSTaggedValue index) if (seat < 0 || static_cast(seat) >= size) { return JSTaggedValue::Undefined(); } - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); - JSTaggedValue value = values->Get(seat); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); + JSTaggedValue value = values->Get(thread, seat); AdjustForward(thread, seat, 1); return value; } @@ -514,7 +514,7 @@ bool JSAPIPlainArray::SetValueAt(JSThread *thread, JSTaggedValue index, JSTagged JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues(thread).GetTaggedObject()); values->Set(thread, seat, value); return true; } diff --git a/ecmascript/js_api/js_api_plain_array.h b/ecmascript/js_api/js_api_plain_array.h index cbcd7aafa1..ef98d1b210 100644 --- a/ecmascript/js_api/js_api_plain_array.h +++ b/ecmascript/js_api/js_api_plain_array.h @@ -47,18 +47,18 @@ public: static JSTaggedValue PUBLIC_API Set(JSThread *thread, const JSHandle &obj, const uint32_t index, JSTaggedValue value); JSTaggedValue RemoveAt(JSThread *thread, JSTaggedValue index); - JSTaggedValue GetIndexOfKey(int32_t key); - JSTaggedValue GetIndexOfValue(JSTaggedValue value); - JSTaggedValue GetKeyAt(int32_t index); + JSTaggedValue GetIndexOfKey(JSThread *thread, int32_t key); + JSTaggedValue GetIndexOfValue(JSThread *thread, JSTaggedValue value); + JSTaggedValue GetKeyAt(JSThread *thread, int32_t index); JSTaggedValue GetValueAt(JSThread *thread, int32_t index); - JSTaggedValue Get(const JSTaggedValue key); + JSTaggedValue Get(JSThread *thread, const JSTaggedValue key); JSTaggedValue Remove(JSThread *thread, JSTaggedValue key); JSTaggedValue RemoveRangeFrom(JSThread *thread, int32_t index, int32_t batchSize); bool SetValueAt(JSThread *thread, JSTaggedValue index, JSTaggedValue value); - bool Has(const int32_t key); + bool Has(JSThread *thread, const int32_t key); bool IsEmpty(); bool AdjustForward(JSThread *thread, int32_t index, int32_t forwardSize); - int32_t BinarySearch(TaggedArray *array, int32_t fromIndex, int32_t toIndex, int32_t key); + int32_t BinarySearch(JSThread *thread, TaggedArray *array, int32_t fromIndex, int32_t toIndex, int32_t key); void Clear(JSThread *thread); void AdjustArray(JSThread *thread, TaggedArray *srcArray, int32_t fromIndex, int32_t toIndex, bool direction); @@ -82,7 +82,7 @@ private: return newCapacity > DEFAULT_CAPACITY_LENGTH ? newCapacity : DEFAULT_CAPACITY_LENGTH; } - JSTaggedValue TryFastGetIndexOfValue(TaggedArray *values, JSTaggedValue value); + JSTaggedValue TryFastGetIndexOfValue(JSThread *thread, TaggedArray *values, JSTaggedValue value); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JS_API_JS_API_PLAIN_ARRAY_H diff --git a/ecmascript/js_api/js_api_plain_array_iterator.cpp b/ecmascript/js_api/js_api_plain_array_iterator.cpp index 1bb398ebeb..5e26e0fdfe 100644 --- a/ecmascript/js_api/js_api_plain_array_iterator.cpp +++ b/ecmascript/js_api/js_api_plain_array_iterator.cpp @@ -36,7 +36,7 @@ JSTaggedValue JSAPIPlainArrayIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle plainArray(thread, iter->GetIteratedPlainArray()); + JSHandle plainArray(thread, iter->GetIteratedPlainArray(thread)); JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); if (plainArray->IsUndefined()) { return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); @@ -52,11 +52,11 @@ JSTaggedValue JSAPIPlainArrayIterator::Next(EcmaRuntimeCallInfo *argv) return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } iter->SetNextIndex(index + 1); - JSHandle valueArray(thread, TaggedArray::Cast(apiPlainArray->GetValues().GetTaggedObject())); - JSHandle value(thread, valueArray->Get(index)); + JSHandle valueArray(thread, TaggedArray::Cast(apiPlainArray->GetValues(thread).GetTaggedObject())); + JSHandle value(thread, valueArray->Get(thread, index)); JSHandle keyArray(thread, TaggedArray:: - Cast(JSHandle(plainArray)->GetKeys().GetTaggedObject())); - JSHandle keyHandle(thread, keyArray->Get(index)); + Cast(JSHandle(plainArray)->GetKeys(thread).GetTaggedObject())); + JSHandle keyHandle(thread, keyArray->Get(thread, index)); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle array(factory->NewTaggedArray(2)); // 2 means the length of array array->Set(thread, 0, keyHandle); diff --git a/ecmascript/js_api/js_api_queue.cpp b/ecmascript/js_api/js_api_queue.cpp index 347ec130a8..70ca5d4e22 100644 --- a/ecmascript/js_api/js_api_queue.cpp +++ b/ecmascript/js_api/js_api_queue.cpp @@ -21,7 +21,7 @@ using ContainerError = containers::ContainerError; using ErrorFlag = containers::ErrorFlag; void JSAPIQueue::Add(JSThread *thread, const JSHandle &queue, const JSHandle &value) { - uint32_t length = queue->GetLength().GetArrayLength(); + uint32_t length = queue->GetLength(thread).GetArrayLength(); JSHandle elements = GrowCapacity(thread, queue, length + 1); ASSERT(!elements->IsDictionaryMode()); @@ -41,7 +41,7 @@ JSHandle JSAPIQueue::GrowCapacity(const JSThread *thread, const JSH JSHandle newElements; uint32_t front = obj->GetFront(); uint32_t tail = obj->GetTail(); - JSHandle oldElements(thread, obj->GetElements()); + JSHandle oldElements(thread, obj->GetElements(thread)); ASSERT(!oldElements->IsDictionaryMode()); uint32_t oldLength = oldElements->GetLength(); uint32_t newCapacity = 0; @@ -65,29 +65,29 @@ JSHandle JSAPIQueue::GrowCapacity(const JSThread *thread, const JSH JSTaggedValue JSAPIQueue::GetFirst(JSThread *thread, const JSHandle &queue) { - if (queue->GetLength().GetArrayLength() < 1) { + if (queue->GetLength(thread).GetArrayLength() < 1) { return JSTaggedValue::Undefined(); } uint32_t index = queue->GetFront(); - JSHandle elements(thread, queue->GetElements()); + JSHandle elements(thread, queue->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); - return elements->Get(index); + return elements->Get(thread, index); } JSTaggedValue JSAPIQueue::Pop(JSThread *thread, const JSHandle &queue) { - uint32_t length = queue->GetLength().GetArrayLength(); + uint32_t length = queue->GetLength(thread).GetArrayLength(); if (length < 1) { return JSTaggedValue::Undefined(); } - JSHandle elements(thread, queue->GetElements()); + JSHandle elements(thread, queue->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); uint32_t front = queue->GetFront(); - JSTaggedValue value = elements->Get(front); + JSTaggedValue value = elements->Get(thread, front); queue->SetLength(thread, JSTaggedValue(length - 1)); uint32_t elementsSize = elements->GetLength(); ASSERT(elementsSize != 0); @@ -99,7 +99,7 @@ JSTaggedValue JSAPIQueue::Pop(JSThread *thread, const JSHandle &queu JSTaggedValue JSAPIQueue::Get(JSThread *thread, const uint32_t index) { - uint32_t length = GetSize(); + uint32_t length = GetSize(thread); if (index >= length) { ASSERT(length > 0); std::ostringstream oss; @@ -109,43 +109,43 @@ JSTaggedValue JSAPIQueue::Get(JSThread *thread, const uint32_t index) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); uint32_t front = GetCurrentFront(); ASSERT(capacity != 0); uint32_t curIndex = (front + index) % capacity; - return elements->Get(curIndex); + return elements->Get(thread, curIndex); } JSTaggedValue JSAPIQueue::Set(JSThread *thread, const uint32_t index, JSTaggedValue value) { - if (GetLength().GetArrayLength() == 0) { + if (GetLength(thread).GetArrayLength() == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - if (index < 0 || index >= GetLength().GetArrayLength()) { + if (index < 0 || index >= GetLength(thread).GetArrayLength()) { std::ostringstream oss; oss << "The value of \"Set property index\" is out of range. It must be >= 0 && <= " - << (GetLength().GetArrayLength() - 1) << ". Received value is: " << index; + << (GetLength(thread).GetArrayLength() - 1) << ". Received value is: " << index; JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, oss.str().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); elements->Set(thread, index, value); return JSTaggedValue::Undefined(); } -bool JSAPIQueue::Has(JSTaggedValue value) const +bool JSAPIQueue::Has(const JSThread *thread, JSTaggedValue value) const { uint32_t begin = GetCurrentFront(); uint32_t end = GetCurrentTail(); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t capacity = elements->GetLength(); uint32_t index = begin; while (index != end) { - if (JSTaggedValue::SameValue(elements->Get(index), value)) { + if (JSTaggedValue::SameValue(thread, elements->Get(thread, index), value)) { return true; } ASSERT(capacity != 0); @@ -156,9 +156,9 @@ bool JSAPIQueue::Has(JSTaggedValue value) const JSHandle JSAPIQueue::OwnKeys(JSThread *thread, const JSHandle &obj) { - uint32_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength(thread).GetArrayLength(); - JSHandle oldElements(thread, obj->GetElements()); + JSHandle oldElements(thread, obj->GetElements(thread)); uint32_t oldCapacity = oldElements->GetLength(); uint32_t newCapacity = ComputeCapacity(oldCapacity); uint32_t front = obj->GetFront(); @@ -174,9 +174,9 @@ JSHandle JSAPIQueue::OwnKeys(JSThread *thread, const JSHandle JSAPIQueue::OwnEnumKeys(JSThread *thread, const JSHandle &obj) { - uint32_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength(thread).GetArrayLength(); - JSHandle oldElements(thread, obj->GetElements()); + JSHandle oldElements(thread, obj->GetElements(thread)); ASSERT(!oldElements->IsDictionaryMode()); uint32_t oldCapacity = oldElements->GetLength(); uint32_t newCapacity = ComputeCapacity(oldCapacity); @@ -195,17 +195,17 @@ bool JSAPIQueue::GetOwnProperty(JSThread *thread, const JSHandle &ob const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"index\" can not obtain attributes of no-number type. Received value is: " - + ConvertToString(*result); + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - uint32_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength(thread).GetArrayLength(); if (length == 0) { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::RANGE_ERROR, "Container is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); @@ -227,7 +227,7 @@ bool JSAPIQueue::GetOwnProperty(JSThread *thread, const JSHandle &ob OperationResult JSAPIQueue::GetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - int32_t length = static_cast(obj->GetSize()); + int32_t length = static_cast(obj->GetSize(thread)); JSHandle indexKey = key; if (indexKey->IsDouble()) { // Math.floor(1) will produce TaggedDouble, we need to cast into TaggedInt @@ -259,7 +259,7 @@ bool JSAPIQueue::SetProperty(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value) { - uint32_t length = obj->GetSize(); + uint32_t length = obj->GetSize(thread); double index = key->GetNumber(); if (index < 0 || static_cast(index) >= length) { return false; @@ -274,7 +274,7 @@ uint32_t JSAPIQueue::GetArrayLength(JSThread *thread, const JSHandle { uint32_t begin = queue->GetCurrentFront(); uint32_t end = queue->GetCurrentTail(); - JSHandle elements(thread, queue->GetElements()); + JSHandle elements(thread, queue->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); uint32_t elementsSize = elements->GetLength(); ASSERT(elementsSize != 0); @@ -282,10 +282,10 @@ uint32_t JSAPIQueue::GetArrayLength(JSThread *thread, const JSHandle return length; } -uint32_t JSAPIQueue::GetNextPosition(uint32_t current) +uint32_t JSAPIQueue::GetNextPosition(JSThread *thread, uint32_t current) { uint32_t next = 0; - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t elementsSize = elements->GetLength(); ASSERT(elementsSize != 0); next = (current + 1) % elementsSize; diff --git a/ecmascript/js_api/js_api_queue.h b/ecmascript/js_api/js_api_queue.h index 30494be650..ee98394bbe 100644 --- a/ecmascript/js_api/js_api_queue.h +++ b/ecmascript/js_api/js_api_queue.h @@ -36,7 +36,7 @@ public: JSTaggedValue Get(JSThread *thread, const uint32_t index); JSTaggedValue PUBLIC_API Set(JSThread *thread, const uint32_t index, JSTaggedValue value); - bool Has(JSTaggedValue value) const; + bool Has(const JSThread *thread, JSTaggedValue value) const; static JSHandle OwnKeys(JSThread *thread, const JSHandle &obj); static JSHandle OwnEnumKeys(JSThread *thread, const JSHandle &obj); @@ -47,9 +47,9 @@ public: const JSHandle &key, const JSHandle &value); - inline uint32_t GetSize() const + inline uint32_t GetSize(const JSThread *thread) const { - return GetLength().GetArrayLength(); + return GetLength(thread).GetArrayLength(); } inline uint32_t GetCurrentFront() const @@ -73,7 +73,7 @@ public: static uint32_t GetArrayLength(JSThread *thread, const JSHandle &queue); - uint32_t GetNextPosition(uint32_t currentPosition); + uint32_t GetNextPosition(JSThread *thread, uint32_t currentPosition); private: inline static uint32_t ComputeCapacity(uint32_t oldCapacity) diff --git a/ecmascript/js_api/js_api_queue_iterator.cpp b/ecmascript/js_api/js_api_queue_iterator.cpp index 15da310ee3..9b4a703832 100644 --- a/ecmascript/js_api/js_api_queue_iterator.cpp +++ b/ecmascript/js_api/js_api_queue_iterator.cpp @@ -37,7 +37,7 @@ JSTaggedValue JSAPIQueueIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle queue(thread, iter->GetIteratedQueue()); + JSHandle queue(thread, iter->GetIteratedQueue(thread)); if (queue->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return env->GetUndefinedIteratorResult().GetTaggedValue(); diff --git a/ecmascript/js_api/js_api_stack.cpp b/ecmascript/js_api/js_api_stack.cpp index a9a0a6e9ac..d8ff92354e 100644 --- a/ecmascript/js_api/js_api_stack.cpp +++ b/ecmascript/js_api/js_api_stack.cpp @@ -41,16 +41,16 @@ JSTaggedValue JSAPIStack::Push(JSThread *thread, const JSHandle &sta return value.GetTaggedValue(); } -JSTaggedValue JSAPIStack::Peek() +JSTaggedValue JSAPIStack::Peek(JSThread *thread) { int top = this->GetTop(); if (top == -1) { return JSTaggedValue::Undefined(); } - TaggedArray *elements = TaggedArray::Cast(this->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(this->GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); - return elements->Get(top); + return elements->Get(thread, top); } JSTaggedValue JSAPIStack::Pop(JSThread *thread) @@ -59,21 +59,21 @@ JSTaggedValue JSAPIStack::Pop(JSThread *thread) if (top == -1) { return JSTaggedValue::Undefined(); } - JSHandle elements(thread, TaggedArray::Cast(this->GetElements().GetTaggedObject())); + JSHandle elements(thread, TaggedArray::Cast(this->GetElements(thread).GetTaggedObject())); ASSERT(!elements->IsDictionaryMode()); - JSTaggedValue ret = elements->Get(top); + JSTaggedValue ret = elements->Get(thread, top); elements->Set(thread, top, JSTaggedValue::Hole()); this->SetTop(--top); return ret; } -int JSAPIStack::Search(const JSHandle &value) +int JSAPIStack::Search(JSThread *thread, const JSHandle &value) { int top = this->GetTop(); - TaggedArray *elements = TaggedArray::Cast(this->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(this->GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); for (int i = 0; i <= top; i++) { - if (value.GetTaggedValue() == elements->Get(i)) { + if (value.GetTaggedValue() == elements->Get(thread, i)) { return i; } } @@ -83,7 +83,7 @@ int JSAPIStack::Search(const JSHandle &value) JSHandle JSAPIStack::GrowCapacity(const JSThread *thread, const JSHandle &obj, uint32_t capacity) { - JSHandle oldElements(thread, obj->GetElements()); + JSHandle oldElements(thread, obj->GetElements(thread)); uint32_t oldLength = oldElements->GetLength(); if (capacity < oldLength) { return oldElements; @@ -97,11 +97,11 @@ JSHandle JSAPIStack::GrowCapacity(const JSThread *thread, const JSH } -JSTaggedValue JSAPIStack::Get(const uint32_t index) +JSTaggedValue JSAPIStack::Get(JSThread *thread, const uint32_t index) { ASSERT(static_cast(index) <= GetTop()); - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); - return elements->Get(index); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); + return elements->Get(thread, index); } JSTaggedValue JSAPIStack::Set(JSThread *thread, const uint32_t index, JSTaggedValue value) @@ -110,21 +110,21 @@ JSTaggedValue JSAPIStack::Set(JSThread *thread, const uint32_t index, JSTaggedVa if (index >= length) { return JSTaggedValue::Undefined(); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); elements->Set(thread, index, value); return JSTaggedValue::Undefined(); } -bool JSAPIStack::Has(JSTaggedValue value) const +bool JSAPIStack::Has(JSThread *thread, JSTaggedValue value) const { - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); int top = static_cast(GetTop()); if (top == -1) { return false; } for (int i = 0; i < top + 1; i++) { - if (JSTaggedValue::SameValue(elements->Get(i), value)) { + if (JSTaggedValue::SameValue(thread, elements->Get(thread, i), value)) { return true; } } @@ -145,12 +145,12 @@ bool JSAPIStack::GetOwnProperty(JSThread *thread, const JSHandle &ob const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); CString errorMsg = "The type of \"index\" can not obtain attributes of no-number type. Received value is: " - + ConvertToString(*result); + + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } @@ -169,7 +169,7 @@ bool JSAPIStack::GetOwnProperty(JSThread *thread, const JSHandle &ob THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - obj->Get(index); + obj->Get(thread, index); return true; } @@ -207,7 +207,7 @@ OperationResult JSAPIStack::GetProperty(JSThread *thread, const JSHandleGet(index), PropertyMetaData(false)); + return OperationResult(thread, obj->Get(thread, index), PropertyMetaData(false)); } bool JSAPIStack::SetProperty(JSThread *thread, const JSHandle &obj, diff --git a/ecmascript/js_api/js_api_stack.h b/ecmascript/js_api/js_api_stack.h index d7c169c839..f5c42abf40 100644 --- a/ecmascript/js_api/js_api_stack.h +++ b/ecmascript/js_api/js_api_stack.h @@ -44,20 +44,20 @@ public: const JSHandle &value); bool Empty(); - bool Has(JSTaggedValue value) const; + bool Has(JSThread *thread, JSTaggedValue value) const; - int Search(const JSHandle &value); + int Search(JSThread *thread, const JSHandle &value); inline int32_t GetSize() const { return GetTop(); } - JSTaggedValue Peek(); + JSTaggedValue Peek(JSThread *thread); JSTaggedValue Pop(JSThread *thread); - JSTaggedValue Get(const uint32_t index); + JSTaggedValue Get(JSThread *thread, const uint32_t index); JSTaggedValue PUBLIC_API Set(JSThread *thread, const uint32_t index, JSTaggedValue value); diff --git a/ecmascript/js_api/js_api_stack_iterator.cpp b/ecmascript/js_api/js_api_stack_iterator.cpp index 16ceca44c7..848f5f4d78 100644 --- a/ecmascript/js_api/js_api_stack_iterator.cpp +++ b/ecmascript/js_api/js_api_stack_iterator.cpp @@ -37,7 +37,7 @@ JSTaggedValue JSAPIStackIterator::Next(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); } JSHandle iter(input); - JSHandle stack(thread, iter->GetIteratedStack()); + JSHandle stack(thread, iter->GetIteratedStack(thread)); if (stack->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return env->GetUndefinedIteratorResult().GetTaggedValue(); @@ -56,7 +56,7 @@ JSTaggedValue JSAPIStackIterator::Next(EcmaRuntimeCallInfo *argv) } iter->SetNextIndex(index + 1); JSHandle key(thread, JSTaggedValue(index)); - JSHandle value(thread, JSHandle::Cast(stack)->Get(index)); + JSHandle value(thread, JSHandle::Cast(stack)->Get(thread, index)); return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } } // namespace panda::ecmascript diff --git a/ecmascript/js_api/js_api_tree_map.cpp b/ecmascript/js_api/js_api_tree_map.cpp index 71498f17f0..ada0b2b185 100644 --- a/ecmascript/js_api/js_api_tree_map.cpp +++ b/ecmascript/js_api/js_api_tree_map.cpp @@ -28,11 +28,11 @@ void JSAPITreeMap::Set(JSThread *thread, const JSHandle &map, cons JSHandle result = JSTaggedValue::ToString(thread, key.GetTaggedValue()); RETURN_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"key\" must be not null. Received value is: " + ConvertToString(*result); + "The type of \"key\" must be not null. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN(thread, error); } - JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())); + JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())); JSTaggedValue newMap = TaggedTreeMap::Set(thread, mapHandle, key, value); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -41,39 +41,39 @@ void JSAPITreeMap::Set(JSThread *thread, const JSHandle &map, cons JSTaggedValue JSAPITreeMap::Get(JSThread *thread, const JSHandle &map, const JSHandle &key) { - JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())); + JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())); return TaggedTreeMap::Get(thread, mapHandle, key); } -int JSAPITreeMap::GetSize() const +int JSAPITreeMap::GetSize(const JSThread *thread) const { - return TaggedTreeMap::Cast(GetTreeMap().GetTaggedObject())->NumberOfElements(); + return TaggedTreeMap::Cast(GetTreeMap(thread).GetTaggedObject())->NumberOfElements(); } -JSTaggedValue JSAPITreeMap::GetKey(int entry) const +JSTaggedValue JSAPITreeMap::GetKey(const JSThread *thread, int entry) const { - ASSERT_PRINT(entry < GetSize(), "entry must less than capacity"); - JSTaggedValue key = TaggedTreeMap::Cast(GetTreeMap().GetTaggedObject())->GetKey(entry); + ASSERT_PRINT(entry < GetSize(thread), "entry must less than capacity"); + JSTaggedValue key = TaggedTreeMap::Cast(GetTreeMap(thread).GetTaggedObject())->GetKey(thread, entry); return key.IsHole() ? JSTaggedValue::Undefined() : key; } -JSTaggedValue JSAPITreeMap::GetValue(int entry) const +JSTaggedValue JSAPITreeMap::GetValue(const JSThread *thread, int entry) const { - ASSERT_PRINT(entry < GetSize(), "entry must less than capacity"); - JSTaggedValue value = TaggedTreeMap::Cast(GetTreeMap().GetTaggedObject())->GetValue(entry); + ASSERT_PRINT(entry < GetSize(thread), "entry must less than capacity"); + JSTaggedValue value = TaggedTreeMap::Cast(GetTreeMap(thread).GetTaggedObject())->GetValue(thread, entry); return value.IsHole() ? JSTaggedValue::Undefined() : value; } JSTaggedValue JSAPITreeMap::Delete(JSThread *thread, const JSHandle &map, const JSHandle &key) { - JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())); + JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())); int entry = TaggedTreeMap::FindEntry(thread, mapHandle, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (entry < 0) { return JSTaggedValue::Undefined(); } - JSHandle value(thread, mapHandle->GetValue(entry)); + JSHandle value(thread, mapHandle->GetValue(thread, entry)); JSTaggedValue newMap = TaggedTreeMap::Delete(thread, mapHandle, entry); map->SetTreeMap(thread, newMap); return value.GetTaggedValue(); @@ -81,23 +81,23 @@ JSTaggedValue JSAPITreeMap::Delete(JSThread *thread, const JSHandle &map, const JSHandle &key) { - JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())); + JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())); return TaggedTreeMap::FindEntry(thread, mapHandle, key) >= 0; } bool JSAPITreeMap::HasValue(JSThread *thread, const JSHandle &value) const { - JSHandle mapHandle(thread, TaggedTreeMap::Cast(GetTreeMap().GetTaggedObject())); + JSHandle mapHandle(thread, TaggedTreeMap::Cast(GetTreeMap(thread).GetTaggedObject())); return mapHandle->HasValue(thread, value.GetTaggedValue()); } void JSAPITreeMap::Clear(const JSThread *thread, const JSHandle &map) { - int cap = map->GetSize(); + int cap = map->GetSize(thread); if (cap == 0) { return; } - JSTaggedValue fn = TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())->GetCompare(); + JSTaggedValue fn = TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())->GetCompare(thread); JSHandle compareFn = JSHandle(thread, fn); cap = std::max(cap, TaggedTreeMap::MIN_CAPACITY); JSTaggedValue internal = TaggedTreeMap::Create(thread, cap); @@ -110,7 +110,7 @@ void JSAPITreeMap::Clear(const JSThread *thread, const JSHandle &m bool JSAPITreeMap::Replace(JSThread *thread, const JSHandle &map, const JSHandle &key, const JSHandle &value) { - JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap().GetTaggedObject())); + JSHandle mapHandle(thread, TaggedTreeMap::Cast(map->GetTreeMap(thread).GetTaggedObject())); int index = TaggedTreeMap::FindEntry(thread, mapHandle, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (index < 0) { diff --git a/ecmascript/js_api/js_api_tree_map.h b/ecmascript/js_api/js_api_tree_map.h index 40e91b8c38..031299706c 100644 --- a/ecmascript/js_api/js_api_tree_map.h +++ b/ecmascript/js_api/js_api_tree_map.h @@ -47,11 +47,11 @@ public: static bool Replace(JSThread *thread, const JSHandle &map, const JSHandle &key, const JSHandle &value); - int GetSize() const; + int GetSize(const JSThread *thread) const; - JSTaggedValue GetKey(int entry) const; + JSTaggedValue GetKey(const JSThread *thread, int entry) const; - JSTaggedValue GetValue(int entry) const; + JSTaggedValue GetValue(const JSThread *thread, int entry) const; static constexpr size_t TREE_MAP_OFFSET = JSObject::SIZE; ACCESSORS(TreeMap, TREE_MAP_OFFSET, SIZE) diff --git a/ecmascript/js_api/js_api_tree_map_iterator.cpp b/ecmascript/js_api/js_api_tree_map_iterator.cpp index 4430ade5af..b642b49cb3 100644 --- a/ecmascript/js_api/js_api_tree_map_iterator.cpp +++ b/ecmascript/js_api/js_api_tree_map_iterator.cpp @@ -40,18 +40,18 @@ JSTaggedValue JSAPITreeMapIterator::Next(EcmaRuntimeCallInfo *argv) } JSHandle iter(input); // Let it be [[IteratedMap]]. - JSHandle iteratedMap(thread, iter->GetIteratedMap()); + JSHandle iteratedMap(thread, iter->GetIteratedMap(thread)); // If it is undefined, return undefinedIteratorResult. if (iteratedMap->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return env->GetUndefinedIteratorResult().GetTaggedValue(); } - JSHandle map(thread, JSHandle::Cast(iteratedMap)->GetTreeMap()); + JSHandle map(thread, JSHandle::Cast(iteratedMap)->GetTreeMap(thread)); uint32_t elements = static_cast(map->NumberOfElements()); - JSMutableHandle entries(thread, iter->GetEntries()); - if ((iter->GetEntries().IsHole()) || (elements != entries->GetLength())) { + JSMutableHandle entries(thread, iter->GetEntries(thread)); + if ((iter->GetEntries(thread).IsHole()) || (elements != entries->GetLength())) { entries.Update(TaggedTreeMap::GetArrayFromMap(thread, map).GetTaggedValue()); iter->SetEntries(thread, entries); } @@ -61,15 +61,15 @@ JSTaggedValue JSAPITreeMapIterator::Next(EcmaRuntimeCallInfo *argv) if (index < elements) { IterationKind itemKind = IterationKind(iter->GetIterationKind()); - int keyIndex = entries->Get(index).GetInt(); + int keyIndex = entries->Get(thread, index).GetInt(); iter->SetNextIndex(index + 1); - JSHandle key(thread, map->GetKey(keyIndex)); + JSHandle key(thread, map->GetKey(thread, keyIndex)); // If itemKind is key, let result be e.[[Key]] if (itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); } - JSHandle value(thread, map->GetValue(keyIndex)); + JSHandle value(thread, map->GetValue(thread, keyIndex)); // Else if itemKind is value, let result be e.[[Value]]. if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); @@ -94,8 +94,8 @@ JSHandle JSAPITreeMapIterator::CreateTreeMapIterator(JSThread *th { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSAPITreeMap()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPITreeMap()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPITreeMap()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/js_api/js_api_tree_set.cpp b/ecmascript/js_api/js_api_tree_set.cpp index c46fcc3190..cb03fd8119 100644 --- a/ecmascript/js_api/js_api_tree_set.cpp +++ b/ecmascript/js_api/js_api_tree_set.cpp @@ -27,32 +27,32 @@ void JSAPITreeSet::Add(JSThread *thread, const JSHandle &set, cons JSHandle result = JSTaggedValue::ToString(thread, value.GetTaggedValue()); RETURN_IF_ABRUPT_COMPLETION(thread); CString errorMsg = - "The type of \"value\" must be Key of JS. Received value is: " + ConvertToString(*result); + "The type of \"value\" must be Key of JS. Received value is: " + ConvertToString(thread, *result); JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::TYPE_ERROR, errorMsg.c_str()); THROW_NEW_ERROR_AND_RETURN(thread, error); } - JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())); + JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())); JSTaggedValue newSet = TaggedTreeSet::Add(thread, setHandle, value); RETURN_IF_ABRUPT_COMPLETION(thread); set->SetTreeSet(thread, newSet); } -int JSAPITreeSet::GetSize() const +int JSAPITreeSet::GetSize(const JSThread *thread) const { - return TaggedTreeSet::Cast(GetTreeSet().GetTaggedObject())->NumberOfElements(); + return TaggedTreeSet::Cast(GetTreeSet(thread).GetTaggedObject())->NumberOfElements(); } -JSTaggedValue JSAPITreeSet::GetKey(int entry) const +JSTaggedValue JSAPITreeSet::GetKey(JSThread *thread, int entry) const { - ASSERT_PRINT(entry < GetSize(), "entry must less than capacity"); - JSTaggedValue key = TaggedTreeSet::Cast(GetTreeSet().GetTaggedObject())->GetKey(entry); + ASSERT_PRINT(entry < GetSize(thread), "entry must less than capacity"); + JSTaggedValue key = TaggedTreeSet::Cast(GetTreeSet(thread).GetTaggedObject())->GetKey(thread, entry); return key.IsHole() ? JSTaggedValue::Undefined() : key; } bool JSAPITreeSet::Delete(JSThread *thread, const JSHandle &set, const JSHandle &key) { - JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())); + JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())); int entry = TaggedTreeSet::FindEntry(thread, setHandle, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -66,17 +66,17 @@ bool JSAPITreeSet::Delete(JSThread *thread, const JSHandle &set, c bool JSAPITreeSet::Has(JSThread *thread, const JSHandle &set, const JSHandle &key) { - JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())); + JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())); return TaggedTreeSet::FindEntry(thread, setHandle, key) >= 0; } void JSAPITreeSet::Clear(const JSThread *thread, const JSHandle &set) { - int cap = set->GetSize(); + int cap = set->GetSize(thread); if (cap == 0) { return; } - JSTaggedValue fn = TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())->GetCompare(); + JSTaggedValue fn = TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())->GetCompare(thread); JSHandle compareFn = JSHandle(thread, fn); JSTaggedValue internal = TaggedTreeSet::Create(thread, cap); if (!compareFn->IsUndefined() && !compareFn->IsNull()) { @@ -87,12 +87,12 @@ void JSAPITreeSet::Clear(const JSThread *thread, const JSHandle &s JSTaggedValue JSAPITreeSet::PopFirst(JSThread *thread, const JSHandle &set) { - JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())); + JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())); int entry = setHandle->GetMinimum(setHandle->GetRootEntries()); if (entry < 0) { return JSTaggedValue::Undefined(); } - JSHandle value(thread, setHandle->GetKey(entry)); + JSHandle value(thread, setHandle->GetKey(thread, entry)); JSTaggedValue newSet = TaggedTreeSet::Delete(thread, setHandle, entry); set->SetTreeSet(thread, newSet); return value.GetTaggedValue(); @@ -100,12 +100,12 @@ JSTaggedValue JSAPITreeSet::PopFirst(JSThread *thread, const JSHandle &set) { - JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet().GetTaggedObject())); + JSHandle setHandle(thread, TaggedTreeSet::Cast(set->GetTreeSet(thread).GetTaggedObject())); int entry = setHandle->GetMaximum(setHandle->GetRootEntries()); if (entry < 0) { return JSTaggedValue::Undefined(); } - JSHandle value(thread, setHandle->GetKey(entry)); + JSHandle value(thread, setHandle->GetKey(thread, entry)); JSTaggedValue newSet = TaggedTreeSet::Delete(thread, setHandle, entry); set->SetTreeSet(thread, newSet); return value.GetTaggedValue(); diff --git a/ecmascript/js_api/js_api_tree_set.h b/ecmascript/js_api/js_api_tree_set.h index 7f799562b4..e1e46b8e92 100644 --- a/ecmascript/js_api/js_api_tree_set.h +++ b/ecmascript/js_api/js_api_tree_set.h @@ -42,9 +42,9 @@ public: static JSTaggedValue PopFirst(JSThread *thread, const JSHandle &set); static JSTaggedValue PopLast(JSThread *thread, const JSHandle &set); - int GetSize() const; + int GetSize(const JSThread *thread) const; - JSTaggedValue GetKey(int entry) const; + JSTaggedValue GetKey(JSThread *thread, int entry) const; JSTaggedValue GetValue(int entry) const; diff --git a/ecmascript/js_api/js_api_tree_set_iterator.cpp b/ecmascript/js_api/js_api_tree_set_iterator.cpp index e2ee848dd7..03ae4b4b6d 100644 --- a/ecmascript/js_api/js_api_tree_set_iterator.cpp +++ b/ecmascript/js_api/js_api_tree_set_iterator.cpp @@ -40,18 +40,18 @@ JSTaggedValue JSAPITreeSetIterator::Next(EcmaRuntimeCallInfo *argv) } JSHandle iter(input); // Let it be [[IteratedSet]]. - JSHandle iteratedSet(thread, iter->GetIteratedSet()); + JSHandle iteratedSet(thread, iter->GetIteratedSet(thread)); // If it is undefined, return undefinedIteratorResult. if (iteratedSet->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return env->GetUndefinedIteratorResult().GetTaggedValue(); } - JSHandle set(thread, JSHandle::Cast(iteratedSet)->GetTreeSet()); + JSHandle set(thread, JSHandle::Cast(iteratedSet)->GetTreeSet(thread)); uint32_t elements = static_cast(set->NumberOfElements()); - JSMutableHandle entries(thread, iter->GetEntries()); - if ((iter->GetEntries().IsHole()) || (elements != entries->GetLength())) { + JSMutableHandle entries(thread, iter->GetEntries(thread)); + if ((iter->GetEntries(thread).IsHole()) || (elements != entries->GetLength())) { entries.Update(TaggedTreeSet::GetArrayFromSet(thread, set).GetTaggedValue()); iter->SetEntries(thread, entries); } @@ -61,10 +61,10 @@ JSTaggedValue JSAPITreeSetIterator::Next(EcmaRuntimeCallInfo *argv) if (index < elements) { IterationKind itemKind = IterationKind(iter->GetIterationKind()); - int keyIndex = entries->Get(index).GetInt(); + int keyIndex = entries->Get(thread, index).GetInt(); iter->SetNextIndex(index + 1); - JSHandle key(thread, set->GetKey(keyIndex)); + JSHandle key(thread, set->GetKey(thread, keyIndex)); // If itemKind is key or value, let result be e.[[Key]]. if (itemKind == IterationKind::VALUE || itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); @@ -89,8 +89,8 @@ JSHandle JSAPITreeSetIterator::CreateTreeSetIterator(JSThread *th { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (!obj->IsJSAPITreeSet()) { - if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget().IsJSAPITreeSet()) { - obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget()); + if (obj->IsJSProxy() && JSHandle::Cast(obj)->GetTarget(thread).IsJSAPITreeSet()) { + obj = JSHandle(thread, JSHandle::Cast(obj)->GetTarget(thread)); } else { JSTaggedValue error = ContainerError::BusinessError(thread, ErrorFlag::BIND_ERROR, "The Symbol.iterator method cannot be bound"); diff --git a/ecmascript/js_api/js_api_vector.cpp b/ecmascript/js_api/js_api_vector.cpp index e732ff14eb..865e34c324 100644 --- a/ecmascript/js_api/js_api_vector.cpp +++ b/ecmascript/js_api/js_api_vector.cpp @@ -30,7 +30,7 @@ bool JSAPIVector::Add(JSThread *thread, const JSHandle &vector, con uint32_t length = vector->GetSize(); GrowCapacity(thread, vector, length + 1); - TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); elements->Set(thread, length, value); vector->SetLength(++length); @@ -47,10 +47,10 @@ 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(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); for (int32_t i = static_cast(length) - 1; i >= index; i--) { - elements->Set(thread, i + 1, elements->Get(i)); + elements->Set(thread, i + 1, elements->Get(thread, i)); } elements->Set(thread, index, value); @@ -66,9 +66,9 @@ void JSAPIVector::SetLength(JSThread *thread, const JSHandle &vecto vector->SetLength(newSize); } -uint32_t JSAPIVector::GetCapacity() +uint32_t JSAPIVector::GetCapacity(JSThread *thread) { - TaggedArray *elementData = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elementData = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); ASSERT(!elementData->IsDictionaryMode()); return elementData->GetLength(); } @@ -79,7 +79,7 @@ void JSAPIVector::IncreaseCapacityTo(JSThread *thread, const JSHandle elementData(thread, vector->GetElements()); + JSHandle elementData(thread, vector->GetElements(thread)); ASSERT(!elementData->IsDictionaryMode()); uint32_t oldCapacity = elementData->GetLength(); uint32_t tempCapacity = static_cast(newCapacity); @@ -99,7 +99,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(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); uint32_t length = vector->GetSize(); if (index < 0) { @@ -110,7 +110,7 @@ int32_t JSAPIVector::GetIndexFrom(JSThread *thread, const JSHandle JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (uint32_t i = static_cast(index); i < length; i++) { - value.Update(JSTaggedValue(elements->Get(i))); + value.Update(JSTaggedValue(elements->Get(thread, i))); if (JSTaggedValue::StrictEqual(thread, obj, value)) { return i; } @@ -123,15 +123,15 @@ bool JSAPIVector::IsEmpty() const return GetSize() == 0; } -JSTaggedValue JSAPIVector::GetLastElement() +JSTaggedValue JSAPIVector::GetLastElement(JSThread *thread) { uint32_t length = GetSize(); if (length == 0) { return JSTaggedValue::Undefined(); } - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); - return elements->Get(length - 1); + return elements->Get(thread, length - 1); } int32_t JSAPIVector::GetLastIndexOf(JSThread *thread, const JSHandle &vector, @@ -153,11 +153,11 @@ int32_t JSAPIVector::GetLastIndexFrom(JSThread *thread, const JSHandleGetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (int32_t i = index; i >= 0; i--) { - value.Update(elements->Get(i)); + value.Update(elements->Get(thread, i)); if (JSTaggedValue::StrictEqual(thread, obj, value)) { return i; } @@ -170,7 +170,7 @@ bool JSAPIVector::Remove(JSThread *thread, const JSHandle &vector, int32_t index = GetIndexOf(thread, vector, obj); uint32_t length = vector->GetSize(); if (index >= 0) { - JSHandle elements(thread, vector->GetElements()); + JSHandle elements(thread, vector->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); TaggedArray::RemoveElementByIndex(thread, elements, index, length); length--; @@ -186,12 +186,12 @@ JSTaggedValue JSAPIVector::RemoveByIndex(JSThread *thread, const JSHandle= static_cast(length)) { THROW_RANGE_ERROR_AND_RETURN(thread, "the index is out-of-bounds", JSTaggedValue::Exception()); } - TaggedArray *resElements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *resElements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); ASSERT(!resElements->IsDictionaryMode()); - JSTaggedValue oldValue = resElements->Get(index); + JSTaggedValue oldValue = resElements->Get(thread, index); if (index >= 0) { - JSHandle elements(thread, vector->GetElements()); + JSHandle elements(thread, vector->GetElements(thread)); ASSERT(!elements->IsDictionaryMode() && length > 0); TaggedArray::RemoveElementByIndex(thread, elements, index, length); vector->SetLength(length - 1); @@ -215,11 +215,11 @@ JSTaggedValue JSAPIVector::RemoveByRange(JSThread *thread, const JSHandle= length ? length : toIndex; - TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); int32_t numMoved = length - endIndex; for (int32_t i = 0; i < numMoved; i++) { - elements->Set(thread, fromIndex + i, elements->Get(endIndex + i)); + elements->Set(thread, fromIndex + i, elements->Get(thread, endIndex + i)); } int32_t newLength = length - (endIndex - fromIndex); @@ -244,11 +244,11 @@ JSHandle JSAPIVector::SubVector(JSThread *thread, const JSHandle(toIndex - fromIndex); JSHandle subVector = thread->GetEcmaVM()->GetFactory()->NewJSAPIVector(newLength); - TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); subVector->SetLength(newLength); for (uint32_t i = 0; i < newLength; i++) { - subVector->Set(thread, i, elements->Get(fromIndex + i)); + subVector->Set(thread, i, elements->Get(thread, fromIndex + i)); } return subVector; @@ -268,7 +268,7 @@ JSTaggedValue JSAPIVector::ToString(JSThread *thread, const JSHandleIsUndefined() && !element->IsNull()) { JSHandle nextStringHandle = JSTaggedValue::ToString(thread, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - nextStr = EcmaStringAccessor(nextStringHandle).ToU16String(); + nextStr = EcmaStringAccessor(nextStringHandle).ToU16String(thread); } if (k > 0) { concatStr.append(sepHandle); @@ -346,7 +346,7 @@ JSTaggedValue JSAPIVector::ReplaceAllElements(JSThread *thread, const JSHandle &vector, uint32_t minCapacity) { - JSHandle elementData(thread, vector->GetElements()); + JSHandle elementData(thread, vector->GetElements(thread)); ASSERT(!elementData->IsDictionaryMode()); uint32_t curCapacity = elementData->GetLength(); if (minCapacity > curCapacity) { @@ -374,27 +374,27 @@ JSTaggedValue JSAPIVector::Get(JSThread *thread, const JSHandle &ve THROW_RANGE_ERROR_AND_RETURN(thread, "the index is out-of-bounds", JSTaggedValue::Exception()); } - TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); - return elements->Get(index); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); + return elements->Get(thread, index); } JSTaggedValue JSAPIVector::Set(JSThread *thread, int32_t index, const JSTaggedValue &value) { - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); elements->Set(thread, index, value); return JSTaggedValue::Undefined(); } -bool JSAPIVector::Has(const JSTaggedValue &value) const +bool JSAPIVector::Has(JSThread *thread, const JSTaggedValue &value) const { - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); uint32_t length = GetSize(); if (length == 0) { return false; } for (uint32_t i = 0; i < length; i++) { - if (JSTaggedValue::SameValue(elements->Get(i), value)) { + if (JSTaggedValue::SameValue(thread, elements->Get(thread, i), value)) { return true; } } @@ -415,7 +415,7 @@ bool JSAPIVector::GetOwnProperty(JSThread *thread, const JSHandle & const JSHandle &key) { uint32_t index = 0; - if (UNLIKELY(!JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { + if (UNLIKELY(!JSTaggedValue::ToElementIndex(thread, key.GetTaggedValue(), &index))) { THROW_TYPE_ERROR_AND_RETURN(thread, "Can not obtain attributes of no-number type", false); } @@ -432,8 +432,8 @@ bool JSAPIVector::GetOwnProperty(JSThread *thread, const JSHandle & void JSAPIVector::TrimToCurrentLength(JSThread *thread, const JSHandle &obj) { uint32_t length = obj->GetSize(); - uint32_t capacity = obj->GetCapacity(); - TaggedArray *elements = TaggedArray::Cast(obj->GetElements().GetTaggedObject()); + uint32_t capacity = obj->GetCapacity(thread); + TaggedArray *elements = TaggedArray::Cast(obj->GetElements(thread).GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); if (capacity > length) { elements->Trim(thread, length); @@ -443,7 +443,7 @@ void JSAPIVector::TrimToCurrentLength(JSThread *thread, const JSHandle &obj) { uint32_t length = obj->GetLength(); - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); ASSERT(!elements->IsDictionaryMode()); for (uint32_t i = 0; i < length; ++i) { elements->Set(thread, i, JSTaggedValue::Hole()); @@ -453,7 +453,7 @@ void JSAPIVector::Clear(JSThread *thread, const JSHandle &obj) JSHandle JSAPIVector::Clone(JSThread *thread, const JSHandle &obj) { - JSHandle srcElements(thread, obj->GetElements()); + JSHandle srcElements(thread, obj->GetElements(thread)); auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle newVector = factory->NewJSAPIVector(0); @@ -465,14 +465,14 @@ JSHandle JSAPIVector::Clone(JSThread *thread, const JSHandle &vector) +JSTaggedValue JSAPIVector::GetFirstElement(JSThread *thread, const JSHandle &vector) { uint32_t length = vector->GetSize(); if (length == 0) { return JSTaggedValue::Undefined(); } - TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); - return elements->Get(0); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements(thread).GetTaggedObject()); + return elements->Get(thread, 0); } JSTaggedValue JSAPIVector::GetIteratorObj(JSThread *thread, const JSHandle &obj) diff --git a/ecmascript/js_api/js_api_vector.h b/ecmascript/js_api/js_api_vector.h index 7bd3dde80f..a37685f8c6 100644 --- a/ecmascript/js_api/js_api_vector.h +++ b/ecmascript/js_api/js_api_vector.h @@ -36,7 +36,7 @@ public: static void SetLength(JSThread *thread, const JSHandle &vector, uint32_t newSize); - uint32_t GetCapacity(); + uint32_t GetCapacity(JSThread *thread); static void IncreaseCapacityTo(JSThread *thread, const JSHandle &vector, int32_t newCapacity); @@ -48,7 +48,7 @@ public: bool IsEmpty() const; - JSTaggedValue GetLastElement(); + JSTaggedValue GetLastElement(JSThread *thread); static int32_t GetLastIndexOf(JSThread *thread, const JSHandle &vector, const JSHandle &obj); @@ -80,7 +80,7 @@ public: JSTaggedValue PUBLIC_API Set(JSThread *thread, int32_t index, const JSTaggedValue &value); - bool Has(const JSTaggedValue &value) const; + bool Has(JSThread *thread, const JSTaggedValue &value) const; static JSHandle OwnKeys(JSThread *thread, const JSHandle &obj); static JSHandle OwnEnumKeys(JSThread *thread, const JSHandle &obj); @@ -92,7 +92,7 @@ public: static JSHandle Clone(JSThread *thread, const JSHandle &vector); - static JSTaggedValue GetFirstElement(const JSHandle &vector); + static JSTaggedValue GetFirstElement(JSThread *thread, const JSHandle &vector); static JSTaggedValue GetIteratorObj(JSThread *thread, const JSHandle &obj); diff --git a/ecmascript/js_api/js_api_vector_iterator.cpp b/ecmascript/js_api/js_api_vector_iterator.cpp index 321976de08..60001c668c 100644 --- a/ecmascript/js_api/js_api_vector_iterator.cpp +++ b/ecmascript/js_api/js_api_vector_iterator.cpp @@ -34,7 +34,7 @@ JSTaggedValue JSAPIVectorIterator::Next(EcmaRuntimeCallInfo *argv) } JSHandle iter(input); // Let a be O.[[IteratedVectorLike]]. - JSHandle vector(thread, iter->GetIteratedVector()); + JSHandle vector(thread, iter->GetIteratedVector(thread)); // If a is undefined, return an undefinedIteratorResult. if (vector->IsUndefined()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); diff --git a/ecmascript/js_arguments.cpp b/ecmascript/js_arguments.cpp index 7af154c9c6..29d467ddde 100644 --- a/ecmascript/js_arguments.cpp +++ b/ecmascript/js_arguments.cpp @@ -31,7 +31,7 @@ bool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle & // 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"); - if (desc.IsDataDescriptor() && JSTaggedValue::SameValue(key.GetTaggedValue(), caller.GetTaggedValue()) && + if (desc.IsDataDescriptor() && JSTaggedValue::SameValue(thread, key.GetTaggedValue(), caller.GetTaggedValue()) && desc.GetValue()->IsJSFunction()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Arguments GetOwnProperty: type error", false); } diff --git a/ecmascript/js_array.cpp b/ecmascript/js_array.cpp index 535fb20c3a..31f95d4fd5 100644 --- a/ecmascript/js_array.cpp +++ b/ecmascript/js_array.cpp @@ -119,15 +119,15 @@ JSHandle JSArray::ArrayCreate(JSThread *thread, JSTaggedNumber le return JSHandle(obj); } -JSTaggedValue JSArray::GetConstructorOrSpeciesInlinedProp(JSTaggedValue object, uint32_t inlinePropIndex) +JSTaggedValue JSArray::GetConstructorOrSpeciesInlinedProp(JSThread *thread, JSTaggedValue object, uint32_t inlinePropIndex) { JSHClass *hclass = JSObject::Cast(object)->GetJSHClass(); ASSERT(!hclass->IsDictionaryMode() && "object can't be dictionary"); - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(inlinePropIndex)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, inlinePropIndex)); ASSERT(attr.GetOffset() == inlinePropIndex && "offset of Attr must be inlinePropIndex"); ASSERT(attr.IsInlinedProps() && "attr must be inline prop"); - JSTaggedValue value = JSObject::Cast(object)->GetPropertyInlinedPropsWithRep(hclass, attr.GetOffset(), attr); + JSTaggedValue value = JSObject::Cast(object)->GetPropertyInlinedPropsWithRep(thread, hclass, attr.GetOffset(), attr); ASSERT(!value.IsHole() && "object must have inlinePropIndex"); return value; } @@ -159,12 +159,12 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandleIsJSArray() && !originalArray->GetJSHClass()->HasConstructor()) { - JSTaggedValue proto = JSObject::GetPrototype(originalArray); + JSTaggedValue proto = JSObject::GetPrototype(thread, originalArray); // fastpath: if the hclass of proto is the default Array Prototype hclass, // the constructor must in the inline properties. if LIKELY(proto.IsECMAObject() && JSObject::Cast(proto)->GetJSHClass() == thread->GetBuiltinPrototypeHClass(BuiltinTypeId::ARRAY)) { - constructor.Update(GetConstructorOrSpeciesInlinedProp(proto, CONSTRUCTOR_INLINE_PROPERTY_INDEX)); + constructor.Update(GetConstructorOrSpeciesInlinedProp(thread, proto, CONSTRUCTOR_INLINE_PROPERTY_INDEX)); } } @@ -185,7 +185,8 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandleGetBuiltinHClass(BuiltinTypeId::ARRAY)) { - JSTaggedValue species = GetConstructorOrSpeciesInlinedProp(taggedCtor, ARRAY_FUNCTION_SPECIES_INDEX); + JSTaggedValue species = GetConstructorOrSpeciesInlinedProp(thread, taggedCtor, + ARRAY_FUNCTION_SPECIES_INDEX); if (species == env->GetArraySpeciesAccessor().GetTaggedValue()) { // fast path: means using default constructor, do ArrayCreate directly. return ArrayCreate(thread, length).GetTaggedValue(); @@ -203,7 +204,7 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandleGetArrayFunction().GetTaggedValue(); // i. If SameValue(C, realmC.[[Intrinsics]].[[%Array%]]) is true, set C to undefined. - if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realmArrayConstructor)) { + if (JSTaggedValue::SameValue(thread, constructor.GetTaggedValue(), realmArrayConstructor)) { constructor.Update(globalConst->GetUndefined()); } } @@ -270,7 +271,7 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle &array, uint32_t oldLen, uint32_t newLen, bool isNew) { - TaggedArray *element = TaggedArray::Cast(array->GetElements().GetTaggedObject()); + TaggedArray *element = TaggedArray::Cast(array->GetElements(thread).GetTaggedObject()); if (element->IsDictionaryMode()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -282,12 +283,12 @@ void JSArray::SetCapacity(JSThread *thread, const JSHandle &array, JSHandle newArr = factory->NewTaggedArray(numOfElements); GetAllElementKeys(thread, array, 0, newArr); for (uint32_t i = numOfElements - 1; i >= newLen; i--) { - JSTaggedValue value = newArr->Get(i); + JSTaggedValue value = newArr->Get(thread, i); uint32_t output = 0; - JSTaggedValue::StringToElementIndex(value, &output); + JSTaggedValue::StringToElementIndex(thread, value, &output); JSTaggedValue key(static_cast(output)); - int entry = dictHandle->FindEntry(key); - auto attr = dictHandle->GetAttributes(entry).GetValue(); + int entry = dictHandle->FindEntry(thread, key); + auto attr = dictHandle->GetAttributes(thread, entry).GetValue(); PropertyAttributes propAttr(attr); if (propAttr.IsConfigurable()) { JSHandle newDict = NumberDictionary::Remove(thread, dictHandle, entry); @@ -327,7 +328,7 @@ void JSArray::TransformElementsKindAfterSetCapacity(JSThread *thread, const JSHa { // Update ElementsKind after reset array length. // Add this switch because we do not support ElementsKind for instance from new Array - if (!array->IsElementDict()) { + if (!array->IsElementDict(thread)) { ElementsKind oldKind = array->GetClass()->GetElementsKind(); if (Elements::IsGeneric(oldKind)) { return; @@ -352,7 +353,7 @@ void JSArray::TransformElementsKindAfterSetCapacity(JSThread *thread, const JSHa newKind = Elements::ToElementsKind(val, newKind); } // elements length might not be zero when newLen is zero - uint32_t oldElementsLength = ElementAccessor::GetElementsLength(array); + uint32_t oldElementsLength = ElementAccessor::GetElementsLength(thread, array); if (newKind == ElementsKind::NONE && oldElementsLength != 0) { JSHandle newTaggedArray = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(oldElementsLength); array->SetElements(thread, newTaggedArray); @@ -499,7 +500,7 @@ JSHandle JSArray::CreateArrayFromList(JSThread *thread, const JSHandle< auto env = thread->GetEcmaVM()->GetGlobalEnv(); // New JSObject by Constructor. - JSTaggedValue protoOrHClass = JSHandle::Cast(env->GetArrayFunction())->GetProtoOrHClass(); + JSTaggedValue protoOrHClass = JSHandle::Cast(env->GetArrayFunction())->GetProtoOrHClass(thread); JSHandle jsHClass = JSHandle(thread, reinterpret_cast(protoOrHClass.GetTaggedObject())); @@ -606,7 +607,7 @@ bool JSArray::TryFastCreateDataProperty(JSThread *thread, const JSHandleGetElements())->GetLength(); + uint32_t capacity = TaggedArray::Cast(obj->GetElements(thread))->GetLength(); uint32_t len = JSHandle::Cast(obj)->GetArrayLength(); if UNLIKELY(index > len) { // goto slowPath @@ -627,7 +628,7 @@ bool JSArray::TryFastCreateDataProperty(JSThread *thread, const JSHandle::Cast(obj)->SetArrayLength(thread, newLen); } if LIKELY(!thread->IsEnableMutantArray()) { - TaggedArray::Cast(obj->GetElements())->Set(thread, index, value); + TaggedArray::Cast(obj->GetElements(thread))->Set(thread, index, value); if LIKELY(thread->IsEnableElementsKind()) { JSHClass::TransitToElementsKind(thread, obj, value, ElementsKind::NONE); } @@ -652,7 +653,7 @@ JSTaggedValue JSArray::CopySortedListToReceiver(JSThread *thread, const JSHandle // b. Set j to j + 1. JSMutableHandle item(thread, JSTaggedValue::Undefined()); while (j < itemCount) { - item.Update(sortedList->Get(j)); + item.Update(sortedList->Get(thread, j)); JSArray::FastSetPropertyByValue(thread, obj, j, item); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); ++j; @@ -734,19 +735,19 @@ JSTaggedValue JSArray::FastConcatDictionaryArray(JSThread *thread, JSHandleGetJSHClass()->IsDictionaryElement()); JSHandle objVal(obj); int64_t len = base::ArrayHelper::GetArrayLength(thread, objVal); - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); uint32_t size = static_cast(elements->Size()); - JSMutableHandle dict(thread, newArrayHandle->GetElements()); + JSMutableHandle dict(thread, newArrayHandle->GetElements(thread)); auto attr = PropertyAttributes(PropertyAttributes::GetDefaultAttributes()); for (uint32_t hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = elements->GetKey(hashIndex); + JSTaggedValue key = elements->GetKey(thread, hashIndex); if (key.IsUndefined() || key.IsHole()) { continue; } ASSERT(key.IsInt()); uint32_t uintKey = static_cast(key.GetInt()); if (uintKey < len) { - JSTaggedValue value = elements->GetValue(hashIndex); + JSTaggedValue value = elements->GetValue(thread, hashIndex); toKey.Update(JSTaggedValue(static_cast(n + uintKey))); // guarantee the toKey IsInt fromValHandle.Update(value); JSHandle newDict = \ @@ -772,10 +773,10 @@ void JSArray::MergeSortedElements(JSThread *thread, const JSHandle JSHandle rightArray = factory->NewTaggedArray(rightLength); for (int64_t i = 0; i < leftLength; i++) { - leftArray->Set(thread, i, elements->Get(startIdx + i)); + leftArray->Set(thread, i, elements->Get(thread, startIdx + i)); } for (int64_t j = 0; j < rightLength; j++) { - rightArray->Set(thread, j, elements->Get(static_cast(middleIdx + 1 + j))); + rightArray->Set(thread, j, elements->Get(thread, static_cast(middleIdx + 1 + j))); } int64_t i = 0; @@ -784,28 +785,28 @@ void JSArray::MergeSortedElements(JSThread *thread, const JSHandle JSMutableHandle leftValue(thread, JSTaggedValue::Undefined()); JSMutableHandle rightValue(thread, JSTaggedValue::Undefined()); while (i < leftLength && j < rightLength) { - leftValue.Update(leftArray->Get(i)); - rightValue.Update(rightArray->Get(j)); + leftValue.Update(leftArray->Get(thread, i)); + rightValue.Update(rightArray->Get(thread, j)); int64_t compareRet = base::ArrayHelper::SortCompare(thread, fn, leftValue, rightValue); RETURN_IF_ABRUPT_COMPLETION(thread); if (compareRet <= 0) { - elements->Set(thread, k, leftArray->Get(i)); + elements->Set(thread, k, leftArray->Get(thread, i)); i++; } else { - elements->Set(thread, k, rightArray->Get(j)); + elements->Set(thread, k, rightArray->Get(thread, j)); j++; } k++; } while (i < leftLength) { - elements->Set(thread, k, leftArray->Get(i)); + elements->Set(thread, k, leftArray->Get(thread, i)); i++; k++; } while (j < rightLength) { - elements->Set(thread, k, rightArray->Get(j)); + elements->Set(thread, k, rightArray->Get(thread, j)); j++; k++; } @@ -823,10 +824,10 @@ void JSArray::SortElementsByInsertionSort(JSThread *thread, const JSHandleGet(i)); + presentValue.Update(elements->Get(thread, i)); while (beginIndex < endIndex) { uint32_t middleIndex = (beginIndex + endIndex) / 2; // 2 : half - middleValue.Update(elements->Get(middleIndex)); + middleValue.Update(elements->Get(thread, middleIndex)); double compareResult = base::ArrayHelper::SortCompare(thread, fn, middleValue, presentValue); RETURN_IF_ABRUPT_COMPLETION(thread); if (compareResult > 0) { @@ -838,7 +839,7 @@ void JSArray::SortElementsByInsertionSort(JSThread *thread, const JSHandle= 0 && endIndex < i) { for (uint32_t j = i; j > endIndex; j--) { - previousValue.Update(elements->Get(j - 1)); + previousValue.Update(elements->Get(thread, j - 1)); elements->Set(thread, j, previousValue); } elements->Set(thread, endIndex, presentValue); @@ -854,7 +855,7 @@ void JSArray::SortElementsByObject(JSThread *thread, const JSHandle &t JSMutableHandle presentValue(thread, JSTaggedValue::Undefined()); JSMutableHandle middleValue(thread, JSTaggedValue::Undefined()); JSMutableHandle previousValue(thread, JSTaggedValue::Undefined()); - uint32_t len = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t len = ElementAccessor::GetElementsLength(thread, thisObjHandle); for (uint32_t i = 1; i < len; i++) { uint32_t beginIndex = 0; uint32_t endIndex = i; @@ -885,7 +886,7 @@ void JSArray::CheckStableArrayAndSet(JSThread *thread, const JSHandle JSMutableHandle &value) { if (thisObjHandle.GetTaggedValue().IsStableJSArray(thread) && - index < ElementAccessor::GetElementsLength(thisObjHandle)) { + index < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { return ElementAccessor::Set(thread, thisObjHandle, index, value, false); } else { ObjectFastOperator::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), index, @@ -896,7 +897,7 @@ void JSArray::CheckStableArrayAndSet(JSThread *thread, const JSHandle JSTaggedValue JSArray::CheckStableArrayAndGet(JSThread *thread, const JSHandle &thisObjHandle, uint32_t index) { if (thisObjHandle.GetTaggedValue().IsStableJSArray(thread) && - index < ElementAccessor::GetElementsLength(thisObjHandle)) { + index < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { return ElementAccessor::Get(thread, thisObjHandle, index); } else { return ObjectFastOperator::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), index); @@ -945,7 +946,7 @@ JSHandle JSArray::ToTaggedArray(JSThread *thread, const JSHandle obj) { - JSHandle arr(thread, obj->GetElements()); + JSHandle arr(thread, obj->GetElements(thread)); // Check whether array is shared in the nonmovable space before set properties and elements. // If true, then really copy array in the semi space. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -954,7 +955,7 @@ void JSArray::CheckAndCopyArray(const JSThread *thread, JSHandle obj) JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE); obj->SetElements(thread, newArray.GetTaggedValue()); } - JSHandle prop(thread, obj->GetProperties()); + JSHandle prop(thread, obj->GetProperties(thread)); if (prop.GetTaggedValue().IsCOWArray()) { auto newProps = factory->CopyArray(prop, prop->GetLength(), prop->GetLength(), JSTaggedValue::Hole(), MemSpaceType::SEMI_SPACE); @@ -969,10 +970,10 @@ bool JSArray::IsProtoNotChangeJSArray(JSThread *thread, const JSHandle if (obj->GetJSHClass()->GetElementsKind() != ElementsKind::GENERIC) { return true; } - JSTaggedValue arrayProtoValue = JSObject::GetPrototype(obj); + JSTaggedValue arrayProtoValue = JSObject::GetPrototype(thread, obj); JSTaggedValue genericArrayHClass = thread->GetGlobalEnv()->GetTaggedElementHOLE_TAGGEDClass(); JSTaggedValue genericArrayProtoValue = \ - JSHClass::Cast(genericArrayHClass.GetTaggedObject())->GetProto(); + JSHClass::Cast(genericArrayHClass.GetTaggedObject())->GetProto(thread); return genericArrayProtoValue == arrayProtoValue; } return false; @@ -1041,7 +1042,7 @@ JSHandle JSArray::CreateJSArrayFunctionClass(const JSThread *thread, O void JSArray::UpdateTrackInfo(const JSThread *thread) { - JSTaggedValue trackInfoVal = GetTrackInfo(); + JSTaggedValue trackInfoVal = GetTrackInfo(thread); if (trackInfoVal.IsHeapObject() && trackInfoVal.IsWeak()) { TrackInfo *trackInfo = TrackInfo::Cast(trackInfoVal.GetWeakReferentUnChecked()); ElementsKind oldKind = trackInfo->GetElementsKind(); @@ -1066,7 +1067,7 @@ bool ArrayJoinStack::Push(const JSThread *thread, const JSHandle ASSERT(globalEnv->GetArrayJoinStack()->IsTaggedArray()); JSHandle joinStack = JSHandle::Cast(globalEnv->GetArrayJoinStack()); ASSERT(joinStack->GetLength() > 0); - if (joinStack->Get(0) == JSTaggedValue::Hole()) { + if (joinStack->Get(thread, 0) == JSTaggedValue::Hole()) { joinStack->Set(thread, 0, receiver.GetTaggedValue()); return true; } @@ -1074,7 +1075,7 @@ bool ArrayJoinStack::Push(const JSThread *thread, const JSHandle uint32_t length = joinStack->GetLength(); JSTaggedValue receiverValue = receiver.GetTaggedValue(); for (uint32_t i = 0; i < length; ++i) { - JSTaggedValue visitedObj = joinStack->Get(i); + JSTaggedValue visitedObj = joinStack->Get(thread, i); if (visitedObj == JSTaggedValue::Hole()) { joinStack->Set(thread, i, receiverValue); return true; @@ -1097,12 +1098,12 @@ void ArrayJoinStack::Pop(const JSThread *thread, const JSHandle r JSHandle globalEnv = vm->GetGlobalEnv(); JSHandle joinStack = JSHandle::Cast(globalEnv->GetArrayJoinStack()); uint32_t length = joinStack->GetLength(); - if (joinStack->Get(0) == receiver.GetTaggedValue() && length == MIN_JOIN_STACK_SIZE) { + if (joinStack->Get(thread, 0) == receiver.GetTaggedValue() && length == MIN_JOIN_STACK_SIZE) { joinStack->Set(thread, 0, JSTaggedValue::Hole()); return; } for (uint32_t i = 0; i < length; ++i) { - if (joinStack->Get(i) == receiver.GetTaggedValue()) { + if (joinStack->Get(thread, i) == receiver.GetTaggedValue()) { if (i == 0 && length > MIN_JOIN_STACK_SIZE) { JSHandle newJoinStack = vm->GetFactory()->NewTaggedArray(MIN_JOIN_STACK_SIZE); globalEnv->SetArrayJoinStack(thread, newJoinStack); diff --git a/ecmascript/js_array.h b/ecmascript/js_array.h index eccbd171b2..e7f1792b44 100644 --- a/ecmascript/js_array.h +++ b/ecmascript/js_array.h @@ -45,7 +45,7 @@ public: static JSHandle ArrayCreate(JSThread *thread, JSTaggedNumber length, const JSHandle &newTarget, ArrayMode mode = ArrayMode::UNDEFINED); - static JSTaggedValue GetConstructorOrSpeciesInlinedProp(JSTaggedValue object, uint32_t inlinePropIndex); + static JSTaggedValue GetConstructorOrSpeciesInlinedProp(JSThread *thread, JSTaggedValue object, uint32_t inlinePropIndex); static JSTaggedValue ArraySpeciesCreate(JSThread *thread, const JSHandle &originalArray, JSTaggedNumber length); static bool ArraySetLength(JSThread *thread, const JSHandle &array, const PropertyDescriptor &desc); @@ -76,9 +76,9 @@ public: SetLength(length); } - inline uint32_t GetHintLength() const + inline uint32_t GetHintLength(const JSThread *thread) const { - auto trackInfo = GetTrackInfo(); + auto trackInfo = GetTrackInfo(thread); if (trackInfo.IsInt()) { int hint = trackInfo.GetInt(); return hint > 0 ? hint : 0; diff --git a/ecmascript/js_array_iterator.cpp b/ecmascript/js_array_iterator.cpp index 219ed367b0..b403f5ccba 100644 --- a/ecmascript/js_array_iterator.cpp +++ b/ecmascript/js_array_iterator.cpp @@ -41,7 +41,7 @@ JSTaggedValue JSArrayIterator::NextInternal(JSThread *thread, JSHandle iter(thisObj); // 4.Let a be O.[[IteratedArrayLike]]. - JSHandle array(thread, iter->GetIteratedArray()); + JSHandle array(thread, iter->GetIteratedArray(thread)); JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); // 5.If a is undefined, return CreateIterResultObject(undefined, true). if (array->IsUndefined()) { diff --git a/ecmascript/js_arraybuffer.cpp b/ecmascript/js_arraybuffer.cpp index 4ceb3d13fa..e935d1401b 100644 --- a/ecmascript/js_arraybuffer.cpp +++ b/ecmascript/js_arraybuffer.cpp @@ -55,7 +55,7 @@ void JSArrayBuffer::Attach(JSThread *thread, uint32_t arrayBufferByteLength, void JSArrayBuffer::Detach(JSThread *thread, bool transferWithNativeAreaAllocator, bool isSerialize) { - JSTaggedValue arrayBufferData = GetArrayBufferData(); + JSTaggedValue arrayBufferData = GetArrayBufferData(thread); // already detached. if (arrayBufferData.IsNull()) { return; diff --git a/ecmascript/js_arraybuffer.h b/ecmascript/js_arraybuffer.h index 126259c9b6..a6da193e8a 100644 --- a/ecmascript/js_arraybuffer.h +++ b/ecmascript/js_arraybuffer.h @@ -31,9 +31,9 @@ public: bool transferWithNativeAreaAllocator = false); void Detach(JSThread *thread, bool transferWithNativeAreaAllocator = false, bool isSerialize = false); - bool IsDetach() + bool IsDetach(JSThread *thread) { - JSTaggedValue arrayBufferData = GetArrayBufferData(); + JSTaggedValue arrayBufferData = GetArrayBufferData(thread); return arrayBufferData.IsNull(); } diff --git a/ecmascript/js_async_from_sync_iterator.cpp b/ecmascript/js_async_from_sync_iterator.cpp index 5122234567..344d25292f 100644 --- a/ecmascript/js_async_from_sync_iterator.cpp +++ b/ecmascript/js_async_from_sync_iterator.cpp @@ -42,7 +42,7 @@ JSHandle JSAsyncFromSyncIterator::CreateAsyncFromSyncIterator(JST // 4.Let iteratorRecord be the Record {[[Iterator]]: asyncIterator, [[NextMethod]]: nextMethod, [[Done]]: false}. JSHandle iteratorRecord = factory->NewAsyncIteratorRecord(tmpAsyncIterator, nextMethod, false); - return JSHandle(thread, iteratorRecord->GetIterator()); + return JSHandle(thread, iteratorRecord->GetIterator(thread)); } JSTaggedValue JSAsyncFromSyncIterator::AsyncFromSyncIteratorContinuation(JSThread *thread, @@ -83,7 +83,7 @@ JSTaggedValue JSAsyncFromSyncIterator::AsyncFromSyncIteratorContinuation(JSThrea JSHandle::Cast(onFulfilled), onFulRejected, promiseCapability); // 12.Return promiseCapability.[[Promise]]. - return promiseCapability->GetPromise(); + return promiseCapability->GetPromise(thread); } JSTaggedValue JSAsyncFromSyncIterator::AsyncFromSyncIterUnwarpFunction(EcmaRuntimeCallInfo *argv) @@ -95,7 +95,7 @@ JSTaggedValue JSAsyncFromSyncIterator::AsyncFromSyncIterUnwarpFunction(EcmaRunti // 2.Return ! CreateIterResultObject(value, F.[[Done]]). JSHandle value = base::BuiltinsBase::GetCallArg(argv, 0); - bool done = unwarpFunction->GetDone().ToBoolean(); + bool done = unwarpFunction->GetDone(thread).ToBoolean(); return JSIterator::CreateIterResultObject(thread, value, done).GetTaggedValue(); } } // namespace panda::ecmascript diff --git a/ecmascript/js_async_function.cpp b/ecmascript/js_async_function.cpp index 918a298c51..04896de82f 100644 --- a/ecmascript/js_async_function.cpp +++ b/ecmascript/js_async_function.cpp @@ -36,7 +36,7 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandleGetEcmaVM(); ObjectFactory *factory = vm->GetFactory(); - JSHandle asyncCtxt(thread, asyncFuncObj->GetGeneratorContext()); + JSHandle asyncCtxt(thread, asyncFuncObj->GetGeneratorContext(thread)); // 2.Let promiseCapability be ! NewPromiseCapability(%Promise%). JSHandle env = vm->GetGlobalEnv(); @@ -46,7 +46,7 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle resolve(thread, pcap->GetResolve()); + JSHandle resolve(thread, pcap->GetResolve(thread)); JSHandle thisArg = globalConst->GetHandledUndefined(); JSHandle undefined = globalConst->GetHandledUndefined(); @@ -75,10 +75,10 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle tcap = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle(thread, tcap->GetPromise())->SetPromiseIsHandled(true); + JSHandle(thread, tcap->GetPromise(thread))->SetPromiseIsHandled(true); // 10.Perform ! PerformPromiseThen(promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability). - JSHandle promise(thread, pcap->GetPromise()); + JSHandle promise(thread, pcap->GetPromise(thread)); [[maybe_unused]] JSTaggedValue pres = BuiltinsPromise::PerformPromiseThen( thread, promise, JSHandle::Cast(fulFunc), JSHandle::Cast(rejFunc), tcap); @@ -101,12 +101,12 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle obj = JSTaggedValue::ToObject(thread, asyncFuncObj); RETURN_IF_ABRUPT_COMPLETION(thread); JSHandle asyncGen = JSHandle::Cast(obj); - asyncCtxt = JSHandle(thread, asyncGen->GetGeneratorContext()); + asyncCtxt = JSHandle(thread, asyncGen->GetGeneratorContext(thread)); } else { JSHandle obj = JSTaggedValue::ToObject(thread, asyncFuncObj); RETURN_IF_ABRUPT_COMPLETION(thread); JSHandle asyncFun = JSHandle::Cast(obj); - asyncCtxt = JSHandle(thread, asyncFun->GetGeneratorContext()); + asyncCtxt = JSHandle(thread, asyncFun->GetGeneratorContext(thread)); } // 2.Let promise be ? PromiseResolve(%Promise%, value). @@ -134,10 +134,10 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle tcap = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle(thread, tcap->GetPromise())->SetPromiseIsHandled(true); + JSHandle(thread, tcap->GetPromise(thread))->SetPromiseIsHandled(true); if (thread->GetEcmaVM()->GetJsDebuggerManager()->IsAsyncStackTrace()) { thread->GetEcmaVM()->GetAsyncStackTrace()->InsertAsyncTaskStacks( - JSHandle(thread, tcap->GetPromise()), "await"); + JSHandle(thread, tcap->GetPromise(thread)), "await"); } // 10.Perform ! PerformPromiseThen(promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability). @@ -158,9 +158,9 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitFulfilled( JSThread *thread, const JSHandle &func, const JSHandle &value) { // 1.Let asyncContext be F.[[AsyncContext]]. - JSHandle asyncCtxt(thread, func->GetAsyncContext()); + JSHandle asyncCtxt(thread, func->GetAsyncContext(thread)); - JSHandle tagVal(thread, asyncCtxt->GetGeneratorObject()); + JSHandle tagVal(thread, asyncCtxt->GetGeneratorObject(thread)); if (tagVal->IsAsyncGeneratorObject()) { AsyncGeneratorHelper::Next(thread, asyncCtxt, value.GetTaggedValue()); return JSHandle(thread, JSTaggedValue::Undefined()); @@ -183,9 +183,9 @@ JSHandle JSAsyncAwaitStatusFunction::AsyncFunctionAwaitRejected( JSThread *thread, const JSHandle &func, const JSHandle &reason) { // 1.Let asyncContext be F.[[AsyncContext]]. - JSHandle asyncCtxt(thread, func->GetAsyncContext()); + JSHandle asyncCtxt(thread, func->GetAsyncContext(thread)); - JSHandle tagVal(thread, asyncCtxt->GetGeneratorObject()); + JSHandle tagVal(thread, asyncCtxt->GetGeneratorObject(thread)); if (tagVal->IsAsyncGeneratorObject()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completionRecord = diff --git a/ecmascript/js_async_generator_object.cpp b/ecmascript/js_async_generator_object.cpp index 912942328f..e5e8fc1c27 100644 --- a/ecmascript/js_async_generator_object.cpp +++ b/ecmascript/js_async_generator_object.cpp @@ -38,7 +38,7 @@ void JSAsyncGeneratorObject::AsyncGeneratorValidate(JSThread *thread, const JSHa JSHandle obj = JSTaggedValue::ToObject(thread, gen); RETURN_IF_ABRUPT_COMPLETION(thread); JSHandle generator = JSHandle::Cast(obj); - if (!JSTaggedValue::SameValue(generator->GetGeneratorBrand(), val)) { + if (!JSTaggedValue::SameValue(thread, generator->GetGeneratorBrand(thread), val)) { THROW_TYPE_ERROR(thread, "Results are not equal"); } } @@ -50,20 +50,20 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResolve(JSThread *thread, // 1. Assert: generator is an AsyncGenerator instance. ASSERT(generator->IsAsyncGeneratorObject()); // 2. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, generator->GetAsyncGeneratorQueue()); + JSHandle queue(thread, generator->GetAsyncGeneratorQueue(thread)); // 3. Assert: queue is not an empty List. - ASSERT(!(queue->Empty())); + ASSERT(!(queue->Empty(thread))); // 4. Let next be the first element of queue. - JSHandle next(thread, queue->Front()); + JSHandle next(thread, queue->Front(thread)); // 5. Remove the first element from queue. queue->Pop(thread); // 6. Let promiseCapability be next.[[Capability]]. - JSHandle capability(thread, next->GetCapability()); + JSHandle capability(thread, next->GetCapability(thread)); // 7. Let iteratorResult be ! CreateIterResultObject(value, done). JSHandle iteratorResult = JSIterator::CreateIterResultObject(thread, value, done); // 8. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iteratorResult »). JSHandle its = JSHandle::Cast(iteratorResult); - JSHandle resolve(thread, capability->GetResolve()); + JSHandle resolve(thread, capability->GetResolve(thread)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo* info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1, StackCheck::NO); @@ -89,18 +89,18 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorReject(JSThread *thread, // 1. Assert: generator is an AsyncGenerator instance. ASSERT(generator->IsAsyncGeneratorObject()); // 2. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, generator->GetAsyncGeneratorQueue()); + JSHandle queue(thread, generator->GetAsyncGeneratorQueue(thread)); // 3. Assert: queue is not an empty List. - ASSERT(!(queue->Empty())); + ASSERT(!(queue->Empty(thread))); // 4. Let next be the first element of queue. - JSHandle val(thread, queue->Front()); + JSHandle val(thread, queue->Front(thread)); JSHandle next = JSHandle::Cast(val); // 5. Remove the first element from queue. queue->Pop(thread); // 6. Let promiseCapability be next.[[Capability]]. - JSHandle capability(thread, next->GetCapability()); + JSHandle capability(thread, next->GetCapability(thread)); // 7. Perform ! Call(promiseCapability.[[Reject]], undefined, ? exception ?). - JSHandle reject(thread, capability->GetReject()); + JSHandle reject(thread, capability->GetReject(thread)); const GlobalEnvConstants *constants = thread->GlobalConstants(); const JSHandle thisArg = constants->GetHandledUndefined(); const JSHandle undefined = constants->GetHandledUndefined(); @@ -130,17 +130,17 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThread *thread, return JSTaggedValue::Undefined(); } // 5. Let queue be generator.[[AsyncGeneratorQueue]]. - JSHandle queue(thread, generator->GetAsyncGeneratorQueue()); + JSHandle queue(thread, generator->GetAsyncGeneratorQueue(thread)); // 6. If queue is an empty List, return undefined. - if (queue->Empty()) { + if (queue->Empty(thread)) { return JSTaggedValue::Undefined(); } // 7. Let next be the value of the first element of queue. - JSHandle next(thread, queue->Front()); + JSHandle next(thread, queue->Front(thread)); // 8. Assert: next is an AsyncGeneratorRequest record. ASSERT(next->GetClass()->IsAsyncGeneratorRequest()); // 9. Let completion be next.[[Completion]]. - JSTaggedValue rcd = next->GetCompletion(); + JSTaggedValue rcd = next->GetCompletion(thread); JSHandle completion(thread, rcd); CompletionRecordType type = completion->GetType(); // 10. If completion is an abrupt completion, then @@ -160,7 +160,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThread *thread, generator->SetAsyncGeneratorState(JSAsyncGeneratorState::AWAITING_RETURN); // 2. Let promise be ? PromiseResolve(%Promise%, completion.[[Value]]). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle val(thread, completion->GetValue()); + JSHandle val(thread, completion->GetValue(thread)); JSTaggedValue promise = PromiseResolve(thread, JSHandle::Cast(env->GetPromiseFunction()), val); JSHandle handPromise(thread, promise); @@ -197,7 +197,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThread *thread, // 1. Assert: completion.[[Type]] is throw. ASSERT(completion->GetType() == CompletionRecordType::THROW); // 2. Perform ! AsyncGeneratorReject(generator, completion.[[Value]]). - JSHandle comVal(thread, completion->GetValue()); + JSHandle comVal(thread, completion->GetValue(thread)); AsyncGeneratorReject(thread, generator, comVal); // 3. Return undefined. return JSTaggedValue::Undefined(); @@ -212,7 +212,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThread *thread, ASSERT((state == JSAsyncGeneratorState::SUSPENDED_START) || (state == JSAsyncGeneratorState::SUSPENDED_YIELD)); // 13. Let genContext be generator.[[AsyncGeneratorContext]]. - JSTaggedValue val = generator->GetGeneratorContext(); + JSTaggedValue val = generator->GetGeneratorContext(thread); JSHandle genContext(thread, val); // 14. Let callerContext be the running execution context. @@ -228,7 +228,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThread *thread, generator->SetAsyncGeneratorState(JSAsyncGeneratorState::EXECUTING); if (completion->GetType() == CompletionRecordType::NORMAL) { - AsyncGeneratorHelper::Next(thread, genContext, completion->GetValue()); + AsyncGeneratorHelper::Next(thread, genContext, completion->GetValue(thread)); } if (completion->GetType() == CompletionRecordType::RETURN) { AsyncGeneratorHelper::Return(thread, genContext, completion); @@ -259,7 +259,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorEnqueue(JSThread *thread, co // b. Perform ! Call(promiseCapability.[[Reject]], undefined, « badGeneratorError »). const GlobalEnvConstants *constants = thread->GlobalConstants(); JSHandle rstErr = JSHandle::Cast(resolutionError); - JSHandle reject(thread, pcap->GetReject()); + JSHandle reject(thread, pcap->GetReject(thread)); JSHandle thisArg = constants->GetHandledUndefined(); JSHandle undefined = constants->GetHandledUndefined(); EcmaRuntimeCallInfo* info = @@ -270,14 +270,14 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorEnqueue(JSThread *thread, co RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Return promiseCapability.[[Promise]]. - JSHandle promise(thread, pcap->GetPromise()); + JSHandle promise(thread, pcap->GetPromise(thread)); return promise.GetTaggedValue(); } // 4. Let queue be generator.[[AsyncGeneratorQueue]]. JSHandle obj = JSTaggedValue::ToObject(thread, gen); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle generator = JSHandle::Cast(obj); - JSHandle queue(thread, generator->GetAsyncGeneratorQueue()); + JSHandle queue(thread, generator->GetAsyncGeneratorQueue(thread)); // 5. Let request be AsyncGeneratorRequest { [[Completion]]: completion, [[Capability]]: promiseCapability }. ObjectFactory *fty = thread->GetEcmaVM()->GetFactory(); JSHandle asyncGeneratorRst = fty->NewAsyncGeneratorRequest(); @@ -297,7 +297,7 @@ JSTaggedValue JSAsyncGeneratorObject::AsyncGeneratorEnqueue(JSThread *thread, co AsyncGeneratorResumeNext(thread, generator); } // 9. Return promiseCapability.[[Promise]]. - JSHandle promise(thread, pcap->GetPromise()); + JSHandle promise(thread, pcap->GetPromise(thread)); return promise.GetTaggedValue(); } @@ -310,13 +310,13 @@ JSTaggedValue JSAsyncGeneratorObject::PromiseResolve(JSThread *thread, const JSH JSHandle ctorKey(globalConst->GetHandledConstructorString()); JSHandle ctorValue = JSObject::GetProperty(thread, value, ctorKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::SameValue(ctorValue.GetTaggedValue(), promise.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, ctorValue.GetTaggedValue(), promise.GetTaggedValue())) { return value.GetTaggedValue(); } } JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, promise); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle resolve(thread, promiseCapability->GetResolve()); + JSHandle resolve(thread, promiseCapability->GetResolve(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); JSHandle thisArg = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo* info = @@ -326,7 +326,7 @@ JSTaggedValue JSAsyncGeneratorObject::PromiseResolve(JSThread *thread, const JSH [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle promiseObj(thread, promiseCapability->GetPromise()); + JSHandle promiseObj(thread, promiseCapability->GetPromise(thread)); return promiseObj.GetTaggedValue(); } @@ -336,7 +336,7 @@ JSTaggedValue JSAsyncGeneratorObject::ProcessorFulfilledFunc(EcmaRuntimeCallInfo JSThread *thread = argv->GetThread(); JSHandle asyncResNextRtnPro = JSHandle::Cast(base::BuiltinsBase::GetConstructor(argv)); - JSHandle asyncGen(thread, asyncResNextRtnPro->GetAsyncGeneratorObject()); + JSHandle asyncGen(thread, asyncResNextRtnPro->GetAsyncGeneratorObject(thread)); // 2. Set F.[[Generator]].[[AsyncGeneratorState]] to completed. asyncGen->SetAsyncGeneratorState(JSAsyncGeneratorState::COMPLETED); @@ -352,7 +352,7 @@ JSTaggedValue JSAsyncGeneratorObject::ProcessorRejectedFunc(EcmaRuntimeCallInfo JSThread *thread = argv->GetThread(); JSHandle asyncResNextRtnPro = JSHandle::Cast(base::BuiltinsBase::GetConstructor(argv)); - JSHandle asyncGen(thread, asyncResNextRtnPro->GetAsyncGeneratorObject()); + JSHandle asyncGen(thread, asyncResNextRtnPro->GetAsyncGeneratorObject(thread)); // 2. Set F.[[Generator]].[[AsyncGeneratorState]] to completed. asyncGen->SetAsyncGeneratorState(JSAsyncGeneratorState::COMPLETED); // 3. Return ! AsyncGeneratorReject(F.[[Generator]], reason). diff --git a/ecmascript/js_bigint.h b/ecmascript/js_bigint.h index f560bcc60b..d92cbd9a67 100644 --- a/ecmascript/js_bigint.h +++ b/ecmascript/js_bigint.h @@ -151,7 +151,7 @@ public: inline uint32_t GetDigit(uint32_t index) const { ASSERT(index < GetLength()); - return Barriers::GetValue(GetData(), sizeof(uint32_t) * index); + return Barriers::GetPrimitive(GetData(), sizeof(uint32_t) * index); } inline void SetDigit(uint32_t index, uint32_t digit) diff --git a/ecmascript/js_collator.cpp b/ecmascript/js_collator.cpp index b02d233de5..1b57d84bc8 100644 --- a/ecmascript/js_collator.cpp +++ b/ecmascript/js_collator.cpp @@ -89,7 +89,7 @@ void JSCollator::SetIcuCollator(JSThread *thread, const JSHandle &co ObjectFactory *factory = ecmaVm->GetFactory(); ASSERT(icuCollator != nullptr); - JSTaggedValue data = collator->GetIcuField(); + JSTaggedValue data = collator->GetIcuField(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuCollator); @@ -149,7 +149,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, std::string collationStr; if (!collation->IsUndefined()) { JSHandle collationEcmaStr = JSHandle::Cast(collation); - collationStr = intl::LocaleHelper::ConvertToStdString(collationEcmaStr); + collationStr = intl::LocaleHelper::ConvertToStdString(thread, collationEcmaStr); if (!JSLocale::IsWellAlphaNumList(collationStr)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid collation", collator); } @@ -332,7 +332,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, if (forIcuCache) { std::string cacheEntry = - locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(thread); ecmaVm->GetIntlCache().SetIcuFormatterToCache(IcuFormatterType::COLLATOR, cacheEntry, icuCollator.release(), JSCollator::FreeIcuCollator); } else { @@ -345,7 +345,7 @@ JSHandle JSCollator::InitializeCollator(JSThread *thread, icu::Collator *JSCollator::GetCachedIcuCollator(JSThread *thread, const JSTaggedValue &locales) { - std::string cacheEntry = locales.IsUndefined() ? "" : EcmaStringAccessor(locales).ToStdString(); + std::string cacheEntry = locales.IsUndefined() ? "" : EcmaStringAccessor(locales).ToStdString(thread); void *cachedCollator = thread->GetEcmaVM()->GetIntlCache().GetIcuFormatterFromCache(IcuFormatterType::COLLATOR, cacheEntry); if (cachedCollator != nullptr) { @@ -449,7 +449,7 @@ JSHandle JSCollator::ResolvedOptions(JSThread *thread, const JSHandle< // [[Locale]] JSHandle property = globalConst->GetHandledLocaleString(); - JSHandle locale(thread, collator->GetLocale()); + JSHandle locale(thread, collator->GetLocale(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); @@ -469,9 +469,9 @@ JSHandle JSCollator::ResolvedOptions(JSThread *thread, const JSHandle< ignorePunctuationValue); // [[Collation]] - JSMutableHandle collationValue(thread, collator->GetCollation()); + JSMutableHandle collationValue(thread, collator->GetCollation(thread)); UErrorCode status = U_ZERO_ERROR; - icu::Collator *icuCollator = collator->GetIcuCollator(); + icu::Collator *icuCollator = collator->GetIcuCollator(thread); icu::Locale icu_locale(icuCollator->getLocale(ULOC_VALID_LOCALE, status)); std::string collation_value = icu_locale.getUnicodeKeywordValue("co", status); @@ -522,7 +522,7 @@ CompareStringsOption JSCollator::CompareStringsOptionFor(JSThread* thread, } JSHandle localesString = JSHandle::Cast(locales); - CString localesStr = ConvertToString(*localesString, StringConvertedUsage::LOGICOPERATION); + CString localesStr = ConvertToString(thread, *localesString, StringConvertedUsage::LOGICOPERATION); for (const char *fastLocale : FAST_LOCALE) { if (strcmp(fastLocale, localesStr.c_str()) == 0) { return CompareStringsOption::TRY_FAST_PATH; @@ -631,41 +631,42 @@ bool FastCompareFlatString(const T1* lhs, const T2* rhs, int length, FastCompare return true; } -bool FastCompareStringFlatContent(EcmaString* string1, EcmaString* string2, +bool FastCompareStringFlatContent(JSThread *thread, + EcmaString* string1, EcmaString* string2, int length, FastCompareStringsData& fastCompareData) { EcmaStringAccessor string1Acc(string1); EcmaStringAccessor string2Acc(string2); if (string1Acc.IsUtf8()) { - auto l = EcmaStringAccessor::GetNonTreeUtf8Data(string1); + auto l = EcmaStringAccessor::GetNonTreeUtf8Data(thread, string1); if (string2Acc.IsUtf8()) { - auto r = EcmaStringAccessor::GetNonTreeUtf8Data(string2); + auto r = EcmaStringAccessor::GetNonTreeUtf8Data(thread, string2); return FastCompareFlatString(l, r, length, fastCompareData); } else { - auto r = EcmaStringAccessor::GetNonTreeUtf16Data(string2); + auto r = EcmaStringAccessor::GetNonTreeUtf16Data(thread, string2); return FastCompareFlatString(l, r, length, fastCompareData); } } else { - auto l = EcmaStringAccessor::GetNonTreeUtf16Data(string1); + auto l = EcmaStringAccessor::GetNonTreeUtf16Data(thread, string1); if (string2Acc.IsUtf8()) { - auto r = EcmaStringAccessor::GetNonTreeUtf8Data(string2); + auto r = EcmaStringAccessor::GetNonTreeUtf8Data(thread, string2); return FastCompareFlatString(l, r, length, fastCompareData); } else { - auto r = EcmaStringAccessor::GetNonTreeUtf16Data(string2); + auto r = EcmaStringAccessor::GetNonTreeUtf16Data(thread, string2); return FastCompareFlatString(l, r, length, fastCompareData); } } UNREACHABLE(); } -bool CharIsAsciiOrOutOfBounds(EcmaString* string, int stringLength, int index) +bool CharIsAsciiOrOutOfBounds(JSThread *thread, EcmaString* string, int stringLength, int index) { - return index >= stringLength || EcmaStringAccessor::IsASCIICharacter(EcmaStringAccessor(string).Get(index)); + return index >= stringLength || EcmaStringAccessor::IsASCIICharacter(EcmaStringAccessor(string).Get(thread, index)); } -bool CharCanFastCompareOrOutOfBounds(EcmaString* string, int stringLength, int index) +bool CharCanFastCompareOrOutOfBounds(JSThread *thread, EcmaString* string, int stringLength, int index) { - return index >= stringLength || CanFastCompare(EcmaStringAccessor(string).Get(index)); + return index >= stringLength || CanFastCompare(EcmaStringAccessor(string).Get(thread, index)); } // Pseudo-code for simplified multi-pass algorithm is: @@ -678,7 +679,8 @@ bool CharCanFastCompareOrOutOfBounds(EcmaString* string, int stringLength, int i // 5. If all equal, return equal. // 6. Once some chars cannot be fastcompared, use icu. -std::optional TryFastCompareStrings(EcmaString* string1, EcmaString* string2, +std::optional TryFastCompareStrings(JSThread *thread, + EcmaString* string1, EcmaString* string2, int& processedUntilOut) { processedUntilOut = 0; @@ -688,13 +690,13 @@ std::optional TryFastCompareStrings(EcmaString* string1, EcmaS int commonLength = std::min(length1, length2); FastCompareStringsData fastCompareData; - if (!FastCompareStringFlatContent(string1, string2, commonLength, fastCompareData)) { + if (!FastCompareStringFlatContent(thread, string1, string2, commonLength, fastCompareData)) { return fastCompareData.FastCompareFailed(processedUntilOut); } // The result is only valid if the last processed character is not followed // by a unicode combining character. - if (!CharIsAsciiOrOutOfBounds(string1, length1, fastCompareData.processedUntil + 1) || - !CharIsAsciiOrOutOfBounds(string2, length2, fastCompareData.processedUntil + 1)) { + if (!CharIsAsciiOrOutOfBounds(thread, string1, length1, fastCompareData.processedUntil + 1) || + !CharIsAsciiOrOutOfBounds(thread, string2, length2, fastCompareData.processedUntil + 1)) { return fastCompareData.FastCompareFailed(processedUntilOut); } if (fastCompareData.l1Result != UCollationResult::UCOL_EQUAL) { @@ -705,8 +707,8 @@ std::optional TryFastCompareStrings(EcmaString* string1, EcmaS if (lengthResult != UCollationResult::UCOL_EQUAL) { // Strings of different lengths may still compare as equal if the longer // string has a fully ignored suffix, e.g. "a" vs. "a\u{1}". - if (!CharCanFastCompareOrOutOfBounds(string1, length1, commonLength) || - !CharCanFastCompareOrOutOfBounds(string2, length2, commonLength)) { + if (!CharCanFastCompareOrOutOfBounds(thread, string1, length1, commonLength) || + !CharCanFastCompareOrOutOfBounds(thread, string2, length2, commonLength)) { return fastCompareData.FastCompareFailed(processedUntilOut); } return lengthResult; @@ -717,17 +719,17 @@ std::optional TryFastCompareStrings(EcmaString* string1, EcmaS } // namespace //StringPiece is similar to std::string_view -icu::StringPiece ToICUStringPiece(EcmaString* string, int offset = 0) +icu::StringPiece ToICUStringPiece(JSThread *thread, EcmaString* string, int offset = 0) { EcmaStringAccessor stringAcc(string); ASSERT(stringAcc.IsUtf8()); ASSERT(!stringAcc.IsTreeString()); - return icu::StringPiece(reinterpret_cast(EcmaStringAccessor::GetNonTreeUtf8Data(string)) + offset, + return icu::StringPiece(reinterpret_cast(EcmaStringAccessor::GetNonTreeUtf8Data(thread, string)) + offset, static_cast(stringAcc.GetLength()) - offset); } // Convert to a UTF16 string and partially convert to ICUUnicodeString -icu::UnicodeString ToICUUnicodeString(EcmaString* string, int offset = 0) +icu::UnicodeString ToICUUnicodeString(JSThread *thread, EcmaString* string, int offset = 0) { EcmaStringAccessor stringAcc(string); ASSERT(!stringAcc.IsTreeString()); @@ -739,18 +741,19 @@ icu::UnicodeString ToICUUnicodeString(EcmaString* string, int offset = 0) // short string on stack UChar shortStringBuffer[shortStringLength]; // utf8 is within ascii, std::copy_n from utf8 to utf16 is OK - std::copy_n(EcmaStringAccessor::GetNonTreeUtf8Data(string) + offset, partialLength, shortStringBuffer); + std::copy_n(EcmaStringAccessor::GetNonTreeUtf8Data(thread, string) + offset, partialLength, shortStringBuffer); return icu::UnicodeString(shortStringBuffer, partialLength); } CVector ucharBuffer(partialLength); - std::copy_n(EcmaStringAccessor::GetNonTreeUtf8Data(string) + offset, partialLength, ucharBuffer.begin()); + std::copy_n(EcmaStringAccessor::GetNonTreeUtf8Data(thread, string) + offset, partialLength, ucharBuffer.begin()); return icu::UnicodeString(ucharBuffer.data(), partialLength); } else { - return icu::UnicodeString(EcmaStringAccessor::GetNonTreeUtf16Data(string) + offset, partialLength); + return icu::UnicodeString(EcmaStringAccessor::GetNonTreeUtf16Data(thread, string) + offset, partialLength); } } -JSTaggedValue JSCollator::SlowCompareStrings(const icu::Collator *icuCollator, +JSTaggedValue JSCollator::SlowCompareStrings(JSThread *thread, + const icu::Collator *icuCollator, EcmaString* flatString1, EcmaString* flatString2, int processedUntil) @@ -758,9 +761,9 @@ JSTaggedValue JSCollator::SlowCompareStrings(const icu::Collator *icuCollator, UCollationResult result; UErrorCode status = U_ZERO_ERROR; if (EcmaStringAccessor(flatString1).IsUtf8() && EcmaStringAccessor(flatString2).IsUtf8()) { - auto string1Piece = ToICUStringPiece(flatString1, processedUntil); + auto string1Piece = ToICUStringPiece(thread, flatString1, processedUntil); if (!string1Piece.empty()) { - auto string2Piece = ToICUStringPiece(flatString2, processedUntil); + auto string2Piece = ToICUStringPiece(thread, flatString2, processedUntil); if (!string2Piece.empty()) { result = icuCollator->compareUTF8(string1Piece, string2Piece, status); return JSTaggedValue(result); @@ -768,8 +771,8 @@ JSTaggedValue JSCollator::SlowCompareStrings(const icu::Collator *icuCollator, } } - auto uString1 = ToICUUnicodeString(flatString1, processedUntil); - auto uString2 = ToICUUnicodeString(flatString2, processedUntil); + auto uString1 = ToICUUnicodeString(thread, flatString1, processedUntil); + auto uString2 = ToICUUnicodeString(thread, flatString2, processedUntil); result = icuCollator->compare(uString1, uString2, status); ASSERT(U_SUCCESS(status)); return JSTaggedValue(result); @@ -790,12 +793,12 @@ JSTaggedValue JSCollator::CompareStrings(JSThread *thread, const icu::Collator * int processedUntil = 0; if (csOption == CompareStringsOption::TRY_FAST_PATH) { - auto maybeResult = TryFastCompareStrings(*flatString1, *flatString2, processedUntil); + auto maybeResult = TryFastCompareStrings(thread, *flatString1, *flatString2, processedUntil); if (maybeResult.has_value()) { return JSTaggedValue(maybeResult.value()); } } - return SlowCompareStrings(icuCollator, *flatString1, *flatString2, processedUntil); + return SlowCompareStrings(thread, icuCollator, *flatString1, *flatString2, processedUntil); } JSTaggedValue JSCollator::FastCachedCompareStrings(JSThread *thread, JSHandle locales, @@ -814,7 +817,7 @@ JSTaggedValue JSCollator::FastCachedCompareStrings(JSThread *thread, JSHandleGetExternalPointer(); return reinterpret_cast(result); } @@ -127,7 +127,8 @@ public: const JSHandle &string2, CompareStringsOption csOption = CompareStringsOption::NONE); - static JSTaggedValue SlowCompareStrings(const icu::Collator *icuCollator, + static JSTaggedValue SlowCompareStrings(JSThread *thread, + const icu::Collator *icuCollator, EcmaString* flatString1, EcmaString* flatString2, int processedUntil); diff --git a/ecmascript/js_date.cpp b/ecmascript/js_date.cpp index 05958566cc..a8dfbc3719 100644 --- a/ecmascript/js_date.cpp +++ b/ecmascript/js_date.cpp @@ -242,7 +242,7 @@ int64_t JSDate::GetLocalOffsetInMin(const JSThread *thread, int64_t timeMs, bool if (!isLocal) { return 0; } - double localOffset = this->GetLocalOffset().GetDouble(); + double localOffset = this->GetLocalOffset(thread).GetDouble(); if (localOffset == MAX_DOUBLE) { localOffset = static_cast(GetLocalOffsetFromOS(timeMs, isLocal)); SetLocalOffset(thread, JSTaggedValue(localOffset)); @@ -502,7 +502,7 @@ JSTaggedValue JSDate::Parse(EcmaRuntimeCallInfo *argv) return JSTaggedValue(base::NAN_VALUE); } int len = static_cast(strAccessor.GetLength()); - auto data = reinterpret_cast(strAccessor.GetUtf8DataFlat(*ecmaStr, tmpBuf)); + auto data = reinterpret_cast(strAccessor.GetUtf8DataFlat(thread, *ecmaStr, tmpBuf)); return GetTimeFromString(data, len); } @@ -593,9 +593,9 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) } // 20.4.4.10 -JSTaggedValue JSDate::GetTime() const +JSTaggedValue JSDate::GetTime(const JSThread *thread) const { - return GetTimeValue(); + return GetTimeValue(thread); } // static @@ -647,7 +647,7 @@ void JSDate::AppendStrToTargetLength(const CString &str, int length, CString &ta bool JSDate::GetThisDateValues(JSThread *thread, std::array *date, bool isLocal) const { - double timeMs = this->GetTimeValue().GetDouble(); + double timeMs = this->GetTimeValue(thread).GetDouble(); if (std::isnan(timeMs)) { return false; } @@ -757,7 +757,7 @@ JSTaggedValue JSDate::ToString(JSThread *thread) const return JSTaggedValue(base::NAN_VALUE); } CString localTime; - localMin = GetLocalOffsetFromOS(static_cast(this->GetTimeValue().GetDouble()), true); + localMin = GetLocalOffsetFromOS(static_cast(this->GetTimeValue(thread).GetDouble()), true); if (localMin >= 0) { localTime += PLUS; } else { @@ -796,7 +796,7 @@ JSTaggedValue JSDate::ToTimeString(JSThread *thread) const return JSTaggedValue(base::NAN_VALUE); } CString localTime; - localMin = GetLocalOffsetFromOS(static_cast(this->GetTimeValue().GetDouble()), true); + localMin = GetLocalOffsetFromOS(static_cast(this->GetTimeValue(thread).GetDouble()), true); if (localMin >= 0) { localTime += PLUS; } else { @@ -847,9 +847,9 @@ JSTaggedValue JSDate::ToUTCString(JSThread *thread) const } // 20.4.4.44 -JSTaggedValue JSDate::ValueOf() const +JSTaggedValue JSDate::ValueOf(const JSThread *thread) const { - return this->GetTimeValue(); + return this->GetTimeValue(thread); } // static @@ -891,8 +891,9 @@ JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, boo count = argc; } + JSThread *thread = argv->GetThread(); // get date values. - double timeMs = this->GetTimeValue().GetDouble(); + double timeMs = this->GetTimeValue(thread).GetDouble(); std::array date = {0}; bool isSelectLocal = isLocal; // setUTCFullYear, setFullYear @@ -900,7 +901,6 @@ JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, boo timeMs = 0.0; isSelectLocal = false; } - JSThread *thread = argv->GetThread(); if (!std::isnan(timeMs)) { GetDateValues(thread, timeMs, &date, isSelectLocal); } diff --git a/ecmascript/js_date.h b/ecmascript/js_date.h index 736dc98188..1c8eb7dcc2 100644 --- a/ecmascript/js_date.h +++ b/ecmascript/js_date.h @@ -129,7 +129,7 @@ public: static JSTaggedValue UTC(EcmaRuntimeCallInfo *argv); // 20.4.4.10 - JSTaggedValue GetTime() const; + JSTaggedValue GetTime(const JSThread *thread) const; // 20.4.4.19 JSTaggedValue GetUTCSeconds(); @@ -151,7 +151,7 @@ public: JSTaggedValue ToUTCString(JSThread *thread) const; // 20.4.4.44 - JSTaggedValue ValueOf() const; + JSTaggedValue ValueOf(const JSThread *thread) const; JSTaggedValue SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, bool isLocal) const; double GetDateValue(JSThread *thread, double timeMs, uint8_t code, bool isLocal) const; diff --git a/ecmascript/js_date_time_format.cpp b/ecmascript/js_date_time_format.cpp index 02f0fdcc4a..eef6dd3cb1 100644 --- a/ecmascript/js_date_time_format.cpp +++ b/ecmascript/js_date_time_format.cpp @@ -96,10 +96,10 @@ const std::map TO_HOUR_CYCLE_MAP = { const std::set RELEVANT_EXTENSION_KEYS = {"nu", "ca", "hc"}; } -icu::Locale *JSDateTimeFormat::GetIcuLocale() const +icu::Locale *JSDateTimeFormat::GetIcuLocale(const JSThread *thread) const { - ASSERT(GetLocaleIcu().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetLocaleIcu().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetLocaleIcu(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetLocaleIcu(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -111,7 +111,7 @@ void JSDateTimeFormat::SetIcuLocale(JSThread *thread, JSHandle ObjectFactory *factory = ecmaVm->GetFactory(); icu::Locale *icuPointer = ecmaVm->GetNativeAreaAllocator()->New(icuLocale); ASSERT(icuPointer != nullptr); - JSTaggedValue data = obj->GetLocaleIcu(); + JSTaggedValue data = obj->GetLocaleIcu(thread); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuPointer); @@ -133,10 +133,10 @@ void JSDateTimeFormat::FreeIcuLocale([[maybe_unused]] void *env, void *pointer, } } -icu::SimpleDateFormat *JSDateTimeFormat::GetIcuSimpleDateFormat() const +icu::SimpleDateFormat *JSDateTimeFormat::GetIcuSimpleDateFormat(const JSThread *thread) const { - ASSERT(GetSimpleDateTimeFormatIcu().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetSimpleDateTimeFormatIcu().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetSimpleDateTimeFormatIcu(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetSimpleDateTimeFormatIcu(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -149,7 +149,7 @@ void JSDateTimeFormat::SetIcuSimpleDateFormat(JSThread *thread, JSHandleGetNativeAreaAllocator()->New(icuSimpleDateTimeFormat); ASSERT(icuPointer != nullptr); - JSTaggedValue data = obj->GetSimpleDateTimeFormatIcu(); + JSTaggedValue data = obj->GetSimpleDateTimeFormatIcu(thread); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuPointer); @@ -367,7 +367,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * std::string calendarStr; if (!calendar->IsUndefined()) { JSHandle calendarEcmaStr = JSHandle::Cast(calendar); - calendarStr = intl::LocaleHelper::ConvertToStdString(calendarEcmaStr); + calendarStr = intl::LocaleHelper::ConvertToStdString(thread, calendarEcmaStr); if (!JSLocale::IsNormativeCalendar(calendarStr)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid calendar", dateTimeFormat); } @@ -386,7 +386,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * std::string nsStr; if (!numberingSystem->IsUndefined()) { JSHandle nsEcmaStr = JSHandle::Cast(numberingSystem); - nsStr = intl::LocaleHelper::ConvertToStdString(nsEcmaStr); + nsStr = intl::LocaleHelper::ConvertToStdString(thread, nsEcmaStr); if (!JSLocale::IsNormativeNumberingSystem(nsStr)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", dateTimeFormat); } @@ -456,7 +456,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * if (!operationResult.GetValue()->IsUndefined()) { JSHandle timezone = JSTaggedValue::ToString(thread, operationResult.GetValue()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSDateTimeFormat, thread); - icuTimeZone = ConstructTimeZone(intl::LocaleHelper::ConvertToStdString(timezone)); + icuTimeZone = ConstructTimeZone(intl::LocaleHelper::ConvertToStdString(thread, timezone)); if (icuTimeZone == nullptr) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid timeZone", dateTimeFormat); } @@ -493,7 +493,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * // d. If hour12 is not undefined, then if (!hour12->IsUndefined()) { // i. If hour12 is true, then - if (JSTaggedValue::SameValue(hour12.GetTaggedValue(), JSTaggedValue::True())) { + if (JSTaggedValue::SameValue(thread, hour12.GetTaggedValue(), JSTaggedValue::True())) { // 1. If hcDefault is "h11" or "h23", then if (hcDefault == HourCycleOption::H11 || hcDefault == HourCycleOption::H23) { // a. Set hc to "h11". @@ -635,7 +635,7 @@ JSHandle JSDateTimeFormat::InitializeDateTimeFormat(JSThread * simpleDateFormatIcu->adoptCalendar(calendarPtr.release()); if (type != IcuCacheType::NOT_CACHE) { std::string cacheEntry = - locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(thread); auto& intlCache = ecmaVm->GetIntlCache(); switch (type) { case IcuCacheType::DEFAULT: @@ -684,7 +684,7 @@ icu::SimpleDateFormat *JSDateTimeFormat::GetCachedIcuSimpleDateFormat(JSThread * const JSHandle &locales, IcuFormatterType type) { - std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(thread); void *cachedSimpleDateFormat = thread->GetEcmaVM()->GetIntlCache().GetIcuFormatterFromCache(type, cacheEntry); if (cachedSimpleDateFormat != nullptr) { return reinterpret_cast(cachedSimpleDateFormat); @@ -847,7 +847,7 @@ void JSDateTimeFormat::ToDateTimeSkeleton(JSThread *thread, const std::vectorGetLength(); for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); - std::string result = EcmaStringAccessor(key.GetTaggedValue()).ToStdString(); + std::string result = EcmaStringAccessor(key.GetTaggedValue()).ToStdString(thread); auto it = std::find(options.begin(), options.end(), result); if (it != options.end()) { needDefaults = false; @@ -872,7 +872,7 @@ void JSDateTimeFormat::ToDateTimeSkeleton(JSThread *thread, const std::vectorGetLength(); for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); - std::string result = EcmaStringAccessor(key.GetTaggedValue()).ToStdString(); + std::string result = EcmaStringAccessor(key.GetTaggedValue()).ToStdString(thread); auto it = std::find(options.begin(), options.end(), result); if (it != options.end()) { needDefaults = false; @@ -914,7 +914,7 @@ void JSDateTimeFormat::ToDateTimeSkeleton(JSThread *thread, const std::vector JSDateTimeFormat::FormatDateTime(JSThread *thread, const JSHandle &dateTimeFormat, double x) { - icu::SimpleDateFormat *simpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(); + icu::SimpleDateFormat *simpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(thread); JSHandle res = FormatDateTime(thread, simpleDateFormat, x); RETURN_HANDLE_IF_ABRUPT_COMPLETION(EcmaString, thread); return res; @@ -946,7 +946,7 @@ JSHandle JSDateTimeFormat::FormatDateTime(JSThread *thread, JSHandle JSDateTimeFormat::FormatDateTimeToParts(JSThread *thread, const JSHandle &dateTimeFormat, double x) { - icu::SimpleDateFormat *simpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(); + icu::SimpleDateFormat *simpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(thread); ASSERT(simpleDateFormat != nullptr); UErrorCode status = U_ZERO_ERROR; icu::FieldPositionIterator fieldPositionIter; @@ -1025,7 +1025,7 @@ JSHandle JSDateTimeFormat::UnwrapDateTimeFormat(JSThread *thread, bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), dateTimeFormat); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, dateTimeFormat); if (!dateTimeFormat->IsJSDateTimeFormat() && isInstanceOf) { - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol(thread)); OperationResult operationResult = JSTaggedValue::GetProperty(thread, dateTimeFormat, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, dateTimeFormat); return operationResult.GetValue(); @@ -1115,17 +1115,17 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle locale(thread, dateTimeFormat->GetLocale()); + JSHandle locale(thread, dateTimeFormat->GetLocale(thread)); JSHandle property = globalConst->GetHandledLocaleString(); JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); RETURN_IF_ABRUPT_COMPLETION(thread); // [[Calendar]] - JSMutableHandle calendarValue(thread, dateTimeFormat->GetCalendar()); - icu::SimpleDateFormat *icuSimpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(); + JSMutableHandle calendarValue(thread, dateTimeFormat->GetCalendar(thread)); + icu::SimpleDateFormat *icuSimpleDateFormat = dateTimeFormat->GetIcuSimpleDateFormat(thread); const icu::Calendar *calendar = icuSimpleDateFormat->getCalendar(); std::string icuCalendar = calendar->getType(); if (icuCalendar == "gregorian") { - if (dateTimeFormat->GetIso8601().IsTrue()) { + if (dateTimeFormat->GetIso8601(thread).IsTrue()) { calendarValue.Update(globalConst->GetHandledIso8601String().GetTaggedValue()); } else { calendarValue.Update(globalConst->GetHandledGregoryString().GetTaggedValue()); @@ -1139,7 +1139,7 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle numberingSystem(thread, dateTimeFormat->GetNumberingSystem()); + JSHandle numberingSystem(thread, dateTimeFormat->GetNumberingSystem(thread)); if (numberingSystem->IsUndefined()) { numberingSystem = globalConst->GetHandledLatnString(); } @@ -1147,7 +1147,7 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle timezoneValue(thread, dateTimeFormat->GetTimeZone()); + JSMutableHandle timezoneValue(thread, dateTimeFormat->GetTimeZone(thread)); const icu::TimeZone &icuTZ = calendar->getTimeZone(); icu::UnicodeString timezone; icuTZ.getID(timezone); @@ -1235,7 +1235,7 @@ void JSDateTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &dtf, double x, double y) { - std::unique_ptr dateIntervalFormat(ConstructDateIntervalFormat(dtf)); + std::unique_ptr dateIntervalFormat(ConstructDateIntervalFormat(thread, dtf)); if (dateIntervalFormat == nullptr) { icu::FormattedDateInterval emptyValue; THROW_TYPE_ERROR_AND_RETURN(thread, "create dateIntervalFormat failed", emptyValue); @@ -1797,10 +1797,10 @@ JSHandle JSDateTimeFormat::ConvertFieldIdToDateType(JSThread *thr } std::unique_ptr JSDateTimeFormat::ConstructDateIntervalFormat( - const JSHandle &dtf) + const JSThread *thread, const JSHandle &dtf) { - icu::SimpleDateFormat *icuSimpleDateFormat = dtf->GetIcuSimpleDateFormat(); - icu::Locale locale = *(dtf->GetIcuLocale()); + icu::SimpleDateFormat *icuSimpleDateFormat = dtf->GetIcuSimpleDateFormat(thread); + icu::Locale locale = *(dtf->GetIcuLocale(thread)); std::string hcString = ToHourCycleString(dtf->GetHourCycle()); UErrorCode status = U_ZERO_ERROR; // Sets the Unicode value for a Unicode keyword. diff --git a/ecmascript/js_date_time_format.h b/ecmascript/js_date_time_format.h index 0f0b87b2c7..eb670d2d3c 100644 --- a/ecmascript/js_date_time_format.h +++ b/ecmascript/js_date_time_format.h @@ -120,12 +120,12 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() - icu::Locale *GetIcuLocale() const; + icu::Locale *GetIcuLocale(const JSThread *thread) const; static void SetIcuLocale(JSThread *thread, JSHandle obj, const icu::Locale &icuLocale, const NativePointerCallback &callback); static void FreeIcuLocale(void *env, void *pointer, void *data); - icu::SimpleDateFormat *GetIcuSimpleDateFormat() const; + icu::SimpleDateFormat *GetIcuSimpleDateFormat(const JSThread *thread) const; static void SetIcuSimpleDateFormat(JSThread *thread, JSHandle obj, const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const NativePointerCallback &callback); static void FreeSimpleDateFormat(void *env, void *pointer, void *data); @@ -189,7 +189,7 @@ private: static std::string ToTitleCaseTimezonePosition(const std::string &input); - static std::unique_ptr ConstructDateIntervalFormat(const JSHandle &dtf); + static std::unique_ptr ConstructDateIntervalFormat(const JSThread *thread, const JSHandle &dtf); static std::string ConstructGMTTimeZoneID(const std::string &input); diff --git a/ecmascript/js_displaynames.cpp b/ecmascript/js_displaynames.cpp index c47a37f3bc..e614d85e99 100644 --- a/ecmascript/js_displaynames.cpp +++ b/ecmascript/js_displaynames.cpp @@ -69,10 +69,10 @@ const std::vector JSDisplayNames::LANGUAGE_DISPLAY_OPTION_NAME = { "dialect", "standard" }; -icu::LocaleDisplayNames *JSDisplayNames::GetIcuLocaleDisplayNames() const +icu::LocaleDisplayNames *JSDisplayNames::GetIcuLocaleDisplayNames(JSThread *thread) const { - ASSERT(GetIcuLDN().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuLDN().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuLDN(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuLDN(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -93,7 +93,7 @@ void JSDisplayNames::SetIcuLocaleDisplayNames(JSThread *thread, const JSHandleGetFactory(); ASSERT(iculocaledisplaynames != nullptr); - JSTaggedValue data = displayNames->GetIcuLDN(); + JSTaggedValue data = displayNames->GetIcuLDN(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, iculocaledisplaynames); @@ -273,7 +273,7 @@ JSHandle JSDisplayNames::CanonicalCodeForDisplayNames(JSThread *thre if (typeOpt == TypednsOption::LANGUAGE) { // a. If code does not match the unicode_language_id production, throw a RangeError exception. UErrorCode status = U_ZERO_ERROR; - std::string codeSt = intl::LocaleHelper::ConvertToStdString(code); + std::string codeSt = intl::LocaleHelper::ConvertToStdString(thread, code); icu::Locale loc = icu::Locale(icu::Locale::forLanguageTag(codeSt, status).getBaseName()); std::string checked = loc.toLanguageTag(status); if (checked.size() == 0) { @@ -285,47 +285,47 @@ JSHandle JSDisplayNames::CanonicalCodeForDisplayNames(JSThread *thre // b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception. // c. Set code to CanonicalizeUnicodeLocaleId(code). // d. Return code. - if (!intl::LocaleHelper::IsStructurallyValidLanguageTag(code)) { + if (!intl::LocaleHelper::IsStructurallyValidLanguageTag(thread, code)) { THROW_TYPE_ERROR_AND_RETURN(thread, "not a structurally valid", code); } JSHandle codeStr = intl::LocaleHelper::CanonicalizeUnicodeLocaleId(thread, code); RETURN_HANDLE_IF_ABRUPT_COMPLETION(EcmaString, thread); - icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); icu::UnicodeString result; - std::string codeString = intl::LocaleHelper::ConvertToStdString(codeStr); + std::string codeString = intl::LocaleHelper::ConvertToStdString(thread, codeStr); icuLocaldisplaynames->languageDisplayName(codeString.c_str(), result); JSHandle codeResult = intl::LocaleHelper::UStringToString(thread, result); return codeResult; } else if (typeOpt == TypednsOption::REGION) { // a. If code does not match the unicode_region_subtag production, throw a RangeError exception. - std::string regionCode = intl::LocaleHelper::ConvertToStdString(code); + std::string regionCode = intl::LocaleHelper::ConvertToStdString(thread, code); if (!IsUnicodeRegionSubtag(regionCode)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid region", code); } // b. Let code be the result of mapping code to upper case as described in 6.1. // c. Return code. - icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); icu::UnicodeString result; icuLocaldisplaynames->regionDisplayName(regionCode.c_str(), result); JSHandle codeResult = intl::LocaleHelper::UStringToString(thread, result); return codeResult; } else if (typeOpt == TypednsOption::SCRIPT) { - std::string scriptCode = intl::LocaleHelper::ConvertToStdString(code); + std::string scriptCode = intl::LocaleHelper::ConvertToStdString(thread, code); if (!IsUnicodeScriptSubtag(scriptCode)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid script", code); } - icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); icu::UnicodeString result; icuLocaldisplaynames->scriptDisplayName(scriptCode.c_str(), result); JSHandle codeResult = intl::LocaleHelper::UStringToString(thread, result); return codeResult; } else if (typeOpt == TypednsOption::CALENDAR) { - std::string calendarCode = intl::LocaleHelper::ConvertToStdString(code); + std::string calendarCode = intl::LocaleHelper::ConvertToStdString(thread, code); if (!JSLocale::IsWellFormedCalendarCode(calendarCode)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid calendar", code); } - icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); icu::UnicodeString result; std::string calendarStrCode = std::strcmp(calendarCode.c_str(), "gregory") == 0 ? "gregorian" @@ -352,14 +352,14 @@ JSHandle JSDisplayNames::CanonicalCodeForDisplayNames(JSThread *thre LOG_ECMA(FATAL) << "this branch is unreachable"; UNREACHABLE(); } - std::string datetimeCode = intl::LocaleHelper::ConvertToStdString(code); + std::string datetimeCode = intl::LocaleHelper::ConvertToStdString(thread, code); UDateTimePatternField field = StringToUDateTimePatternField(datetimeCode.c_str()); if (field == UDATPG_FIELD_COUNT) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid datetimefield", code); } UErrorCode status = U_ZERO_ERROR; - icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); icu::Locale locales = icuLocaldisplaynames->getLocale(); std::unique_ptr generator( icu::DateTimePatternGenerator::createInstance(locales, status)); @@ -369,11 +369,11 @@ JSHandle JSDisplayNames::CanonicalCodeForDisplayNames(JSThread *thre // 4. 4. Assert: type is "currency". // 5. If ! IsWellFormedCurrencyCode(code) is false, throw a RangeError exception. ASSERT(typeOpt == TypednsOption::CURRENCY); - std::string cCode = intl::LocaleHelper::ConvertToStdString(code); + std::string cCode = intl::LocaleHelper::ConvertToStdString(thread, code); if (!JSLocale::IsWellFormedCurrencyCode(cCode)) { THROW_RANGE_ERROR_AND_RETURN(thread, "not a wellformed currency code", code); } - icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *icuLocaldisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); icu::UnicodeString result; icuLocaldisplaynames->keyValueDisplayName("currency", cCode.c_str(), result); JSHandle codeResult = intl::LocaleHelper::UStringToString(thread, result); @@ -515,7 +515,7 @@ void JSDisplayNames::ResolvedOptions(JSThread *thread, const JSHandle propertyKey = globalConst->GetHandledLocaleString(); - JSHandle locale(thread, displayNames->GetLocale()); + JSHandle locale(thread, displayNames->GetLocale(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale); RETURN_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/js_displaynames.h b/ecmascript/js_displaynames.h index 196c6bc6c6..7f542bdd93 100644 --- a/ecmascript/js_displaynames.h +++ b/ecmascript/js_displaynames.h @@ -98,7 +98,7 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() - icu::LocaleDisplayNames *GetIcuLocaleDisplayNames() const; + icu::LocaleDisplayNames *GetIcuLocaleDisplayNames(JSThread *thread) const; static void FreeIcuLocaleDisplayNames(void *env, void *pointer, void* hint); diff --git a/ecmascript/js_finalization_registry.cpp b/ecmascript/js_finalization_registry.cpp index 7e7be31d06..c018b9250e 100644 --- a/ecmascript/js_finalization_registry.cpp +++ b/ecmascript/js_finalization_registry.cpp @@ -30,13 +30,13 @@ JSHandle CellRecordVector::Append(const JSThread *thread, cons return JSHandle(newVector); } -bool CellRecordVector::IsEmpty() +bool CellRecordVector::IsEmpty(const JSThread *thread) { if (Empty()) { return true; } for (uint32_t i = 0; i < GetEnd(); i++) { - JSTaggedValue value = Get(i); + JSTaggedValue value = Get(thread, i); if (!value.IsHole()) { return false; } @@ -57,7 +57,7 @@ void JSFinalizationRegistry::Register(JSThread *thread, JSHandle // If unregisterToken is undefined, we use vector to store // otherwise we use hash map to store to facilitate subsequent delete operations if (!unregisterToken->IsUndefined()) { - JSHandle maybeUnregister(thread, obj->GetMaybeUnregister()); + JSHandle maybeUnregister(thread, obj->GetMaybeUnregister(thread)); JSHandle array(thread, JSTaggedValue::Undefined()); if (maybeUnregister->Has(thread, unregisterToken.GetTaggedValue())) { array = JSHandle(thread, maybeUnregister->Get(thread, unregisterToken.GetTaggedValue())); @@ -69,7 +69,7 @@ void JSFinalizationRegistry::Register(JSThread *thread, JSHandle maybeUnregister = LinkedHashMap::SetWeakRef(thread, maybeUnregister, unregisterToken, arrayValue); obj->SetMaybeUnregister(thread, maybeUnregister); } else { - JSHandle noUnregister(thread, obj->GetNoUnregister()); + JSHandle noUnregister(thread, obj->GetNoUnregister(thread)); noUnregister = CellRecordVector::Append(thread, noUnregister, cell); obj->SetNoUnregister(thread, noUnregister); } @@ -81,7 +81,7 @@ bool JSFinalizationRegistry::Unregister(JSThread *thread, JSHandle maybeUnregister(thread, obj->GetMaybeUnregister()); + JSHandle maybeUnregister(thread, obj->GetMaybeUnregister(thread)); int entry = maybeUnregister->FindElement(thread, UnregisterToken.GetTaggedValue()); if (entry == -1) { return false; @@ -95,19 +95,19 @@ bool JSFinalizationRegistry::Unregister(JSThread *thread, JSHandle obj) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - if (obj->GetPrev().IsNull() && obj->GetNext().IsNull()) { + if (obj->GetPrev(thread).IsNull() && obj->GetNext(thread).IsNull()) { env->SetFinRegLists(thread, JSTaggedValue::Undefined()); return; } - if (!obj->GetPrev().IsNull()) { - JSHandle prev(thread, obj->GetPrev()); - prev->SetNext(thread, obj->GetNext()); + if (!obj->GetPrev(thread).IsNull()) { + JSHandle prev(thread, obj->GetPrev(thread)); + prev->SetNext(thread, obj->GetNext(thread)); } - if (!obj->GetNext().IsNull()) { - JSHandle next(thread, obj->GetNext()); - next->SetPrev(thread, obj->GetPrev()); + if (!obj->GetNext(thread).IsNull()) { + JSHandle next(thread, obj->GetNext(thread)); + next->SetPrev(thread, obj->GetPrev(thread)); } else { - env->SetFinRegLists(thread, obj->GetPrev()); + env->SetFinRegLists(thread, obj->GetPrev(thread)); } obj->SetPrev(thread, JSTaggedValue::Null()); obj->SetNext(thread, JSTaggedValue::Null()); @@ -134,7 +134,7 @@ void JSFinalizationRegistry::CheckAndCall(JSThread *thread) JSMutableHandle jsFinalizationRegistry(thread, current.GetTaggedValue()); while (!current->IsNull()) { jsFinalizationRegistry.Update(current.GetTaggedValue()); - current.Update(jsFinalizationRegistry->GetPrev()); + current.Update(jsFinalizationRegistry->GetPrev(thread)); if (CleanupFinalizationRegistry(thread, jsFinalizationRegistry)) { // If the objects registered on the current JSFinalizationRegistry object have all been gc, // then we clean up this JSFinalizationRegistry object from the FinRegLists @@ -149,15 +149,15 @@ void DealCallBackOfMap(JSThread *thread, JSHandle &cellVect, if (!cellVect->Empty()) { uint32_t cellVectLen = cellVect->GetEnd(); for (uint32_t i = 0; i < cellVectLen; ++i) { - JSTaggedValue value = cellVect->Get(i); + JSTaggedValue value = cellVect->Get(thread, i); if (value.IsHole()) { continue; } JSHandle cellRecord(thread, value); // if WeakRefTarget have been gc, set callback to job and delete - if (cellRecord->GetFromWeakRefTarget().IsUndefined()) { + if (cellRecord->GetFromWeakRefTarget(thread).IsUndefined()) { JSHandle argv = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(1); - argv->Set(thread, 0, cellRecord->GetHeldValue()); + argv->Set(thread, 0, cellRecord->GetHeldValue(thread)); job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, func, argv); cellVect->Delete(thread, i); } @@ -179,31 +179,31 @@ bool JSFinalizationRegistry::CleanupFinalizationRegistry(JSThread *thread, JSHan auto ecmaVm = thread->GetEcmaVM(); JSHandle job = ecmaVm->GetMicroJobQueue(); ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle func(thread, obj->GetCleanupCallback()); - JSHandle noUnregister(thread, obj->GetNoUnregister()); + JSHandle func(thread, obj->GetCleanupCallback(thread)); + JSHandle noUnregister(thread, obj->GetNoUnregister(thread)); if (!noUnregister->Empty()) { uint32_t noUnregisterLen = noUnregister->GetEnd(); for (uint32_t i = 0; i < noUnregisterLen; ++i) { - JSTaggedValue value = noUnregister->Get(i); + JSTaggedValue value = noUnregister->Get(thread, i); if (value.IsHole()) { continue; } JSHandle cellRecord(thread, value); // if WeakRefTarget have been gc, set callback to job and delete - if (cellRecord->GetFromWeakRefTarget().IsUndefined()) { + if (cellRecord->GetFromWeakRefTarget(thread).IsUndefined()) { JSHandle argv = factory->NewTaggedArray(1); - argv->Set(thread, 0, cellRecord->GetHeldValue()); + argv->Set(thread, 0, cellRecord->GetHeldValue(thread)); job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, func, argv); noUnregister->Delete(thread, i); } } } - JSMutableHandle maybeUnregister(thread, obj->GetMaybeUnregister()); + JSMutableHandle maybeUnregister(thread, obj->GetMaybeUnregister(thread)); int index = 0; int totalElements = maybeUnregister->NumberOfElements() + maybeUnregister->NumberOfDeletedElements(); while (index < totalElements) { - if (!maybeUnregister->GetKey(index++).IsHole()) { - JSHandle cellVect(thread, maybeUnregister->GetValue(index - 1)); + if (!maybeUnregister->GetKey(thread, index++).IsHole()) { + JSHandle cellVect(thread, maybeUnregister->GetValue(thread, index - 1)); DealCallBackOfMap(thread, cellVect, job, func); if (!cellVect->Empty()) { continue; @@ -216,7 +216,7 @@ bool JSFinalizationRegistry::CleanupFinalizationRegistry(JSThread *thread, JSHan // Determine whether the objects registered on the current JSFinalizationRegistry object // have all been gc int remainSize = newMap->NumberOfElements() + newMap->NumberOfDeletedElements(); - if (noUnregister->IsEmpty() && remainSize == 0) { + if (noUnregister->IsEmpty(thread) && remainSize == 0) { return true; } return false; @@ -226,7 +226,7 @@ void JSFinalizationRegistry::AddFinRegLists(JSThread *thread, JSHandleGetPrev().IsNull() || !next->GetNext().IsNull()) { + if (!next->GetPrev(thread).IsNull() || !next->GetNext(thread).IsNull()) { return; } JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -235,7 +235,7 @@ void JSFinalizationRegistry::AddFinRegLists(JSThread *thread, JSHandle prev(lists); // Prevent the same object from being connected end to end, // which should not happen and will lead to an infinite loop - if (JSTaggedValue::SameValue(next.GetTaggedValue(), prev.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, next.GetTaggedValue(), prev.GetTaggedValue())) { return; } prev->SetNext(thread, next); diff --git a/ecmascript/js_finalization_registry.h b/ecmascript/js_finalization_registry.h index 964121d58b..76755df9d5 100644 --- a/ecmascript/js_finalization_registry.h +++ b/ecmascript/js_finalization_registry.h @@ -46,9 +46,9 @@ public: SetWeakRefTarget(thread, weakObj); } - JSTaggedValue GetFromWeakRefTarget() const + JSTaggedValue GetFromWeakRefTarget(const JSThread *thread) const { - JSTaggedValue weakObj = GetWeakRefTarget(); + JSTaggedValue weakObj = GetWeakRefTarget(thread); if (!weakObj.IsUndefined()) { return JSTaggedValue(weakObj.GetWeakReferent()); } @@ -70,7 +70,7 @@ public: } static JSHandle Append(const JSThread *thread, const JSHandle &vector, const JSHandle &value); - bool IsEmpty(); + bool IsEmpty(const JSThread *thread); }; class JSFinalizationRegistry : public JSObject { diff --git a/ecmascript/js_for_in_iterator.cpp b/ecmascript/js_for_in_iterator.cpp index b6e0a5b1fd..9d741cf8a1 100644 --- a/ecmascript/js_for_in_iterator.cpp +++ b/ecmascript/js_for_in_iterator.cpp @@ -23,7 +23,8 @@ namespace panda::ecmascript { using BuiltinsBase = base::BuiltinsBase; -bool JSForInIterator::IsEnumCacheValid(JSTaggedValue receiver, JSTaggedValue cachedHClass, EnumCacheKind kind) +bool JSForInIterator::IsEnumCacheValid(const JSThread *thread, JSTaggedValue receiver, JSTaggedValue cachedHClass, + EnumCacheKind kind) { DISALLOW_GARBAGE_COLLECTION; JSHClass *hclass = receiver.GetTaggedObject()->GetClass(); @@ -37,13 +38,13 @@ bool JSForInIterator::IsEnumCacheValid(JSTaggedValue receiver, JSTaggedValue cac return false; } ASSERT(kind == EnumCacheKind::PROTOCHAIN); - JSTaggedValue proto = hclass->GetPrototype(); + JSTaggedValue proto = hclass->GetPrototype(thread); if (!proto.IsHeapObject()) { return true; } - JSTaggedValue enumCache = proto.GetTaggedObject()->GetClass()->GetEnumCache(); + JSTaggedValue enumCache = proto.GetTaggedObject()->GetClass()->GetEnumCache(thread); if (enumCache.IsEnumCache()) { - JSTaggedValue enumCacheAll = EnumCache::Cast(enumCache.GetTaggedObject())->GetEnumCacheAll(); + JSTaggedValue enumCacheAll = EnumCache::Cast(enumCache.GetTaggedObject())->GetEnumCacheAll(thread); if (enumCacheAll != JSTaggedValue::Null()) { return true; } @@ -51,7 +52,7 @@ bool JSForInIterator::IsEnumCacheValid(JSTaggedValue receiver, JSTaggedValue cac return false; } -bool JSForInIterator::NeedCheckProperty(JSTaggedValue receiver) +bool JSForInIterator::NeedCheckProperty(const JSThread *thread, JSTaggedValue receiver) { DISALLOW_GARBAGE_COLLECTION; JSTaggedValue current = receiver; @@ -59,7 +60,7 @@ bool JSForInIterator::NeedCheckProperty(JSTaggedValue receiver) if (!current.IsJSObject() || current.GetTaggedObject()->GetClass()->HasDeleteProperty()) { return true; } - current = JSObject::GetPrototype(current); + current = JSObject::GetPrototype(thread, current); } return false; } @@ -87,19 +88,19 @@ JSTaggedValue JSForInIterator::NextInternal(JSThread *thread, const JSHandle= length) { return JSTaggedValue::Undefined(); } - JSTaggedValue taggedKeys = it->GetKeys(); - JSTaggedValue receiver = it->GetObject(); + JSTaggedValue taggedKeys = it->GetKeys(thread); + JSTaggedValue receiver = it->GetObject(thread); EnumCacheKind kind = static_cast(it->GetCacheKind()); TaggedArray *keys = TaggedArray::Cast(taggedKeys.GetTaggedObject()); - if (IsEnumCacheValid(receiver, it->GetCachedHClass(), kind)) { - JSTaggedValue key = keys->Get(index); + if (IsEnumCacheValid(thread, receiver, it->GetCachedHClass(thread), kind)) { + JSTaggedValue key = keys->Get(thread, index); index++; it->SetIndex(index); return key; } - if (!NeedCheckProperty(receiver)) { - JSTaggedValue key = keys->Get(index); + if (!NeedCheckProperty(thread, receiver)) { + JSTaggedValue key = keys->Get(thread, index); index++; it->SetIndex(index); return key; @@ -115,12 +116,12 @@ JSTaggedValue JSForInIterator::NextInternalSlowpath(JSThread *thread, const JSHa if (index >= length) { return JSTaggedValue::Undefined(); } - JSHandle keysHandle(thread, it->GetKeys()); - JSHandle receiverHandle(thread, it->GetObject()); + JSHandle keysHandle(thread, it->GetKeys(thread)); + JSHandle receiverHandle(thread, it->GetObject(thread)); JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); bool has = false; while (index < length) { - keyHandle.Update(keysHandle->Get(index)); + keyHandle.Update(keysHandle->Get(thread, index)); if (keyHandle->IsUndefined()) { has = false; break; @@ -137,7 +138,7 @@ JSTaggedValue JSForInIterator::NextInternalSlowpath(JSThread *thread, const JSHa return JSTaggedValue::Undefined(); } - JSTaggedValue key = keysHandle->Get(index); + JSTaggedValue key = keysHandle->Get(thread, index); index++; it->SetIndex(index); return key; diff --git a/ecmascript/js_for_in_iterator.h b/ecmascript/js_for_in_iterator.h index 171cce149c..4a6ab2895a 100644 --- a/ecmascript/js_for_in_iterator.h +++ b/ecmascript/js_for_in_iterator.h @@ -46,8 +46,9 @@ public: DECL_DUMP() private: - static bool IsEnumCacheValid(JSTaggedValue receiver, JSTaggedValue cachedHClass, EnumCacheKind kind); - static bool NeedCheckProperty(JSTaggedValue receiver); + static bool IsEnumCacheValid(const JSThread *thread, JSTaggedValue receiver, JSTaggedValue cachedHClass, + EnumCacheKind kind); + static bool NeedCheckProperty(const JSThread *thread, JSTaggedValue receiver); static bool HasProperty(JSThread *thread, JSHandle receiver, JSHandle key); }; } // namespace panda::ecmascript diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index 62e4b6a5d3..0890555a11 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -151,21 +151,21 @@ JSHandle JSFunction::NewJSFunctionPrototype(JSThread *thread, const JS JSHClass *JSFunction::GetOrCreateInitialJSHClass(JSThread *thread, const JSHandle &fun) { - JSTaggedValue protoOrHClass(fun->GetProtoOrHClass()); + JSTaggedValue protoOrHClass(fun->GetProtoOrHClass(thread)); if (protoOrHClass.IsJSHClass()) { return reinterpret_cast(protoOrHClass.GetTaggedObject()); } JSHandle proto; bool needProfileTransition = false; - if (!fun->HasFunctionPrototype()) { + if (!fun->HasFunctionPrototype(thread)) { proto = JSHandle::Cast(NewJSFunctionPrototype(thread, fun)); if (thread->GetEcmaVM()->IsEnablePGOProfiler()) { thread->GetEcmaVM()->GetPGOProfiler()->ProfileClassRootHClass(fun.GetTaggedType(), JSTaggedType(proto->GetTaggedObject()->GetClass()), pgo::ProfileType::Kind::PrototypeId); } } else { - proto = JSHandle(thread, fun->GetProtoOrHClass()); + proto = JSHandle(thread, fun->GetProtoOrHClass(thread)); needProfileTransition = proto->IsECMAObject(); } @@ -173,7 +173,7 @@ JSHClass *JSFunction::GetOrCreateInitialJSHClass(JSThread *thread, const JSHandl JSHandle hclass; if (thread->GetEcmaVM()->GetJSOptions().IsEnableInlinePropertyOptimization()) { bool isStartObjSizeTracking = true; - uint32_t expectedOfProperties = JSFunction::CalcuExpotedOfProperties(fun, &isStartObjSizeTracking); + uint32_t expectedOfProperties = JSFunction::CalcuExpotedOfProperties(thread, fun, &isStartObjSizeTracking); hclass = factory->NewEcmaHClass(JSObject::SIZE, expectedOfProperties, JSType::JS_OBJECT, proto); if (isStartObjSizeTracking) { hclass->StartObjSizeTracking(); @@ -192,14 +192,15 @@ JSHClass *JSFunction::GetOrCreateInitialJSHClass(JSThread *thread, const JSHandl return *hclass; } -uint32_t JSFunction::CalcuExpotedOfProperties(const JSHandle &fun, bool *isStartObjSizeTracking) +uint32_t JSFunction::CalcuExpotedOfProperties(JSThread *thread, const JSHandle &fun, + bool *isStartObjSizeTracking) { JSTaggedValue prototype = fun.GetTaggedValue(); uint32_t expectedPropertyCount = 0; while (prototype.IsJSFunction()) { - JSTaggedValue method = JSFunction::Cast(prototype.GetTaggedObject())->GetMethod(); + JSTaggedValue method = JSFunction::Cast(prototype.GetTaggedObject())->GetMethod(thread); uint32_t count = Method::Cast(method.GetTaggedObject())->GetExpectedPropertyCount(); - prototype = JSObject::GetPrototype(prototype); + prototype = JSObject::GetPrototype(thread, prototype); // if equal MAX_EXPECTED_PROPERTY_COUNT means none expectedProperty in method if (count == MethodLiteral::MAX_EXPECTED_PROPERTY_COUNT) { continue; @@ -221,30 +222,30 @@ uint32_t JSFunction::CalcuExpotedOfProperties(const JSHandle &fun, b JSTaggedValue JSFunction::PrototypeGetter(JSThread *thread, const JSHandle &self) { JSHandle func = JSHandle::Cast(self); - if (!func->HasFunctionPrototype()) { + if (!func->HasFunctionPrototype(thread)) { JSHandle proto = JSHandle::Cast(NewJSFunctionPrototype(thread, func)); if (thread->GetEcmaVM()->IsEnablePGOProfiler()) { thread->GetEcmaVM()->GetPGOProfiler()->ProfileClassRootHClass(func.GetTaggedType(), JSTaggedType(proto->GetTaggedObject()->GetClass()), pgo::ProfileType::Kind::PrototypeId); } } - return JSFunction::Cast(*self)->GetFunctionPrototype(); + return JSFunction::Cast(*self)->GetFunctionPrototype(thread); } bool JSFunction::PrototypeSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, [[maybe_unused]] bool mayThrow) { JSHandle func(self); - JSTaggedValue protoOrHClass = func->GetProtoOrHClass(); + JSTaggedValue protoOrHClass = func->GetProtoOrHClass(thread); if (protoOrHClass.IsJSHClass()) { // need transition JSHandle hclass(thread, JSHClass::Cast(protoOrHClass.GetTaggedObject())); - hclass->CompleteObjSizeTracking(); + hclass->CompleteObjSizeTracking(thread); JSHandle newClass = JSHClass::SetPrototypeWithNotification(thread, hclass, value); func->SetProtoOrHClass(thread, newClass); // Forbide to profile for changing the function prototype after an instance of the function has been created if (!hclass->IsAOT() && thread->GetEcmaVM()->IsEnablePGOProfiler()) { - EntityId ctorMethodId = Method::Cast(func->GetMethod().GetTaggedObject())->GetMethodId(); + EntityId ctorMethodId = Method::Cast(func->GetMethod(thread).GetTaggedObject())->GetMethodId(); thread->GetEcmaVM()->GetPGOProfiler()->InsertSkipCtorMethodIdSafe(ctorMethodId); } } else { @@ -254,7 +255,7 @@ bool JSFunction::PrototypeSetter(JSThread *thread, const JSHandle &sel } bool enablePgo = thread->GetEcmaVM()->IsEnablePGOProfiler(); - JSMutableHandle oldPrototype(thread, func->GetProtoOrHClass()); + JSMutableHandle oldPrototype(thread, func->GetProtoOrHClass(thread)); // For pgo, we need the oldPrototype to record the old ihc and phc. if (enablePgo && oldPrototype->IsHole()) { oldPrototype.Update(JSHandle::Cast(NewJSFunctionPrototype(thread, func))); @@ -276,20 +277,20 @@ void JSFunction::SetFunctionPrototypeOrInstanceHClass(const JSThread *thread, co fun->SetProtoOrHClass(thread, protoHandle.GetTaggedValue()); if (protoHandle->IsJSHClass()) { protoHandle = JSHandle(thread, - JSHClass::Cast(protoHandle->GetTaggedObject())->GetPrototype()); + JSHClass::Cast(protoHandle->GetTaggedObject())->GetPrototype(thread)); } if (protoHandle->IsECMAObject()) { JSHClass::OptimizePrototypeForIC(thread, thread->GetGlobalEnv(), protoHandle); } } -EcmaString* JSFunction::GetFunctionNameString(ObjectFactory *factory, JSHandle concatString, +EcmaString* JSFunction::GetFunctionNameString(const JSThread *thread, ObjectFactory *factory, JSHandle concatString, JSHandle target) { if (target->IsJSFunction()) { - JSTaggedValue method = JSHandle::Cast(target)->GetMethod(); + JSTaggedValue method = JSHandle::Cast(target)->GetMethod(thread); if (!method.IsUndefined()) { - std::string funcName = Method::Cast(method.GetTaggedObject())->ParseFunctionName(); + std::string funcName = Method::Cast(method.GetTaggedObject())->ParseFunctionName(thread); if (!funcName.empty()) { return *factory->ConcatFromString(concatString, factory->NewFromStdString(funcName)); } @@ -304,7 +305,7 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle boundFunction(self); - JSHandle target(thread, boundFunction->GetBoundTarget()); + JSHandle target(thread, boundFunction->GetBoundTarget(thread)); JSHandle nameKey = globalConst->GetHandledNameString(); JSHandle boundName = thread->GlobalConstants()->GetHandledBoundString(); @@ -317,7 +318,7 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle EcmaString *newString; if (!targetName->IsString()) { - newString = GetFunctionNameString(factory, concatString, target); + newString = GetFunctionNameString(thread, factory, concatString, target); } else { JSHandle functionName = JSHandle::Cast(targetName); newString = *factory->ConcatFromString(concatString, functionName); @@ -326,7 +327,7 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle return JSTaggedValue(newString); } - JSTaggedValue method = JSHandle::Cast(self)->GetMethod(); + JSTaggedValue method = JSHandle::Cast(self)->GetMethod(thread); if (method.IsUndefined()) { return JSTaggedValue::Undefined(); } @@ -334,17 +335,17 @@ JSTaggedValue JSFunction::NameGetter(JSThread *thread, const JSHandle if (target->IsNativeWithCallField()) { return JSTaggedValue::Undefined(); } - auto [funcName, isASCII] = target->ParseFunctionNameView(); + auto [funcName, isASCII] = target->ParseFunctionNameView(thread); if (funcName.empty()) { return thread->GlobalConstants()->GetEmptyString(); } ObjectFactory* factory = thread->GetEcmaVM()->GetFactory(); const JSHandle nameHdl = factory->NewFromUtf8(funcName, isASCII); - if (JSHandle::Cast(self)->GetFunctionKind() == FunctionKind::GETTER_FUNCTION) { + if (JSHandle::Cast(self)->GetFunctionKind(thread) == FunctionKind::GETTER_FUNCTION) { return factory->ConcatFromString( JSHandle(thread->GlobalConstants()->GetHandledGetWithSpaceString()), nameHdl).GetTaggedValue(); } - if (JSHandle::Cast(self)->GetFunctionKind() == FunctionKind::SETTER_FUNCTION) { + if (JSHandle::Cast(self)->GetFunctionKind(thread) == FunctionKind::SETTER_FUNCTION) { return factory->ConcatFromString( JSHandle(thread->GlobalConstants()->GetHandledSetWithSpaceString()), nameHdl).GetTaggedValue(); } @@ -356,14 +357,14 @@ JSTaggedValue JSFunction::LengthGetter(JSThread *thread, const JSHandleIsBoundFunction()) { JSMutableHandle boundFunction(thread, self.GetTaggedValue()); - JSHandle arguments(thread, boundFunction->GetBoundArguments()); + JSHandle arguments(thread, boundFunction->GetBoundArguments(thread)); uint32_t argsLength = TaggedArray::Cast(arguments->GetTaggedObject())->GetLength(); - while (boundFunction->GetBoundTarget().IsBoundFunction()) { - boundFunction.Update(boundFunction->GetBoundTarget()); - argsLength += TaggedArray::Cast(boundFunction->GetBoundArguments())->GetLength(); + while (boundFunction->GetBoundTarget(thread).IsBoundFunction()) { + boundFunction.Update(boundFunction->GetBoundTarget(thread)); + argsLength += TaggedArray::Cast(boundFunction->GetBoundArguments(thread))->GetLength(); } - JSHandle target(thread, boundFunction->GetBoundTarget()); + JSHandle target(thread, boundFunction->GetBoundTarget(thread)); JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); bool targetHasLength = @@ -401,7 +402,7 @@ bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandleIsBoundFunction()) { STACK_LIMIT_CHECK(thread, false); JSHandle boundFunction(thread, JSBoundFunction::Cast(constructor->GetTaggedObject())); - JSTaggedValue boundTarget = boundFunction->GetBoundTarget(); + JSTaggedValue boundTarget = boundFunction->GetBoundTarget(thread); return JSObject::InstanceOf(thread, obj, JSHandle(thread, boundTarget)); } // 3. If Type(O) is not Object, return false @@ -415,12 +416,12 @@ bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandle constructorPrototype(thread, JSTaggedValue::Undefined()); if (constructor->IsJSFunction()) { JSHandle ctor(thread, constructor->GetTaggedObject()); - JSHandle ctorProtoOrHclass(thread, ctor->GetProtoOrHClass()); + JSHandle ctorProtoOrHclass(thread, ctor->GetProtoOrHClass(thread)); if (!ctorProtoOrHclass->IsHole()) { if (!ctorProtoOrHclass->IsJSHClass()) { constructorPrototype.Update(ctorProtoOrHclass); } else { - JSTaggedValue ctorProto = JSHClass::Cast(ctorProtoOrHclass->GetTaggedObject())->GetProto(); + JSTaggedValue ctorProto = JSHClass::Cast(ctorProtoOrHclass->GetTaggedObject())->GetProto(thread); constructorPrototype.Update(ctorProto); } } else { @@ -446,7 +447,7 @@ bool JSFunction::OrdinaryHasInstance(JSThread *thread, const JSHandle object(thread, obj.GetTaggedValue()); while (!object->IsNull()) { - if (JSTaggedValue::SameValue(object, constructorPrototype)) { + if (JSTaggedValue::SameValue(thread, object, constructorPrototype)) { return true; } object.Update(JSTaggedValue::GetPrototype(thread, object)); @@ -464,7 +465,7 @@ bool JSFunction::MakeConstructor(JSThread *thread, const JSHandle &f const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle constructorKey = globalConst->GetHandledConstructorString(); - ASSERT_PRINT(func->GetProtoOrHClass().IsHole() && func->IsExtensible(), + ASSERT_PRINT(func->GetProtoOrHClass(thread).IsHole() && func->IsExtensible(), "function doesn't has proto_type property and is extensible object"); ASSERT_PRINT(JSObject::HasProperty(thread, JSHandle(func), constructorKey), "function must have constructor"); @@ -573,7 +574,7 @@ JSTaggedValue JSFunction::InvokeOptimizedEntrypoint(JSThread *thread, JSHandleGetException(); } - Method *method = mainFunc->GetCallTarget(); + Method *method = mainFunc->GetCallTarget(thread); size_t actualNumArgs = method->GetNumArgs(); const JSTaggedType *prevFp = thread->GetLastLeaveFrame(); JSTaggedValue res; @@ -583,10 +584,10 @@ JSTaggedValue JSFunction::InvokeOptimizedEntrypoint(JSThread *thread, JSHandleIsCompiledFastCall()) { // entry of aot - args = JSFunction::GetArgsData(true, thisArg, mainFunc, cjsInfo); + args = JSFunction::GetArgsData(thread, true, thisArg, mainFunc, cjsInfo); res = thread->GetEcmaVM()->FastCallAot(actualNumArgs, args.data(), prevFp); } else { - args = JSFunction::GetArgsData(false, thisArg, mainFunc, cjsInfo); + args = JSFunction::GetArgsData(thread, false, thisArg, mainFunc, cjsInfo); // entry of aot res = thread->GetEcmaVM()->ExecuteAot(actualNumArgs, args.data(), prevFp, false); } @@ -599,12 +600,12 @@ JSTaggedValue JSFunction::InvokeOptimizedEntrypoint(JSThread *thread, JSHandle JSFunction::GetArgsData(bool isFastCall, JSHandle &thisArg, +std::vector JSFunction::GetArgsData(JSThread *thread, bool isFastCall, JSHandle &thisArg, JSHandle mainFunc, CJSInfo* cjsInfo) { size_t argsNum; uint32_t mandatoryNum; - Method *method = mainFunc->GetCallTarget(); + Method *method = mainFunc->GetCallTarget(thread); size_t actualNumArgs = method->GetNumArgs(); if (isFastCall) { argsNum = actualNumArgs + NUM_MANDATORY_JSFUNC_ARGS - 1; @@ -634,7 +635,7 @@ JSTaggedValue JSFunction::InvokeOptimizedEntrypoint(JSThread *thread, JSHandleIsInManagedState()); - Method *method = func->GetCallTarget(); + Method *method = func->GetCallTarget(thread); JSTaggedValue resultValue; size_t numArgs = method->GetNumArgsWithCallField(); bool needPushArgv = numArgs > info->GetArgsNumber(); @@ -675,7 +676,7 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) } JSHandle obj(thread, JSTaggedValue::Undefined()); - if (func->IsBase()) { + if (func->IsBase(thread)) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); obj = JSHandle(factory->NewJSObjectByConstructor(func, newTarget)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -697,11 +698,11 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) if (resultValue.IsECMAObject()) { return resultValue; } - if (func->IsBase()) { + if (func->IsBase(thread)) { return obj.GetTaggedValue(); } // derived ctor(sub class) return the obj which created by base ctor(parent class) - if (func->IsDerivedConstructor()) { + if (func->IsDerivedConstructor(thread)) { if (!resultValue.IsECMAObject() && !resultValue.IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "derived class constructor must return an object or undefined", JSTaggedValue::Exception()); @@ -740,7 +741,7 @@ bool JSFunctionBase::SetFunctionName(JSThread *thread, const JSHandle functionName; if (name->IsSymbol()) { - JSTaggedValue description = JSHandle::Cast(name)->GetDescription(); + JSTaggedValue description = JSHandle::Cast(name)->GetDescription(thread); JSHandle descriptionHandle(thread, description); if (description.IsUndefined()) { functionName = factory->GetEmptyString(); @@ -797,17 +798,17 @@ JSTaggedValue JSBoundFunction::ConstructInternal(EcmaRuntimeCallInfo *info) { JSThread *thread = info->GetThread(); JSHandle func(info->GetFunction()); - JSHandle target(thread, func->GetBoundTarget()); + JSHandle target(thread, func->GetBoundTarget(thread)); if (!target->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception()); } JSHandle newTarget = info->GetNewTarget(); JSMutableHandle newTargetMutable(thread, newTarget.GetTaggedValue()); - if (JSTaggedValue::SameValue(func.GetTaggedValue(), newTarget.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, func.GetTaggedValue(), newTarget.GetTaggedValue())) { newTargetMutable.Update(target.GetTaggedValue()); } - JSHandle boundArgs(thread, func->GetBoundArguments()); + JSHandle boundArgs(thread, func->GetBoundArguments(thread)); const uint32_t boundLength = boundArgs->GetLength(); const uint32_t argsLength = info->GetArgsNumber() + boundLength; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); @@ -835,7 +836,7 @@ JSTaggedValue JSBoundFunction::ConstructInternal(EcmaRuntimeCallInfo *info) void JSProxyRevocFunction::ProxyRevocFunctions(const JSThread *thread, const JSHandle &revoker) { // 1.Let p be the value of F’s [[RevocableProxy]] internal slot. - JSTaggedValue proxy = revoker->GetRevocableProxy(); + JSTaggedValue proxy = revoker->GetRevocableProxy(thread); // 2.If p is null, return undefined. if (proxy.IsNull()) { return; @@ -879,14 +880,14 @@ void JSFunction::SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JST nameHandle.Update(name); } else { JSHandle nameBegin(thread, name); - JSTaggedValue description = JSSymbol::Cast(name.GetTaggedObject())->GetDescription(); + JSTaggedValue description = JSSymbol::Cast(name.GetTaggedObject())->GetDescription(thread); if (description.IsUndefined()) { nameHandle.Update(globalConst->GetEmptyString()); } else { JSHandle leftBrackets(globalConst->GetHandledLeftSquareBracketString()); JSHandle rightBrackets(globalConst->GetHandledRightSquareBracketString()); JSHandle concatName = factory->ConcatFromString(leftBrackets, - JSHandle(thread, JSSymbol::Cast(nameBegin->GetTaggedObject())->GetDescription())); + JSHandle(thread, JSSymbol::Cast(nameBegin->GetTaggedObject())->GetDescription(thread))); concatName = factory->ConcatFromString(concatName, rightBrackets); nameHandle.Update(concatName.GetTaggedValue()); } @@ -908,7 +909,7 @@ JSHandle JSFunction::GetInstanceJSHClass(JSThread *thread, JSHandleIsJSFunction()) { JSHandle newTargetFunc = JSHandle::Cast(newTarget); - if (newTargetFunc->IsDerivedConstructor()) { + if (newTargetFunc->IsDerivedConstructor(thread)) { JSMutableHandle mutableNewTarget(thread, newTarget.GetTaggedValue()); JSMutableHandle mutableNewTargetProto(thread, JSTaggedValue::Undefined()); while (!mutableNewTargetProto->IsNull()) { @@ -926,7 +927,7 @@ JSHandle JSFunction::GetInstanceJSHClass(JSThread *thread, JSHandle prototype(thread, JSTaggedValue::Undefined()); if (newTarget->IsJSFunction()) { JSHandle newTargetFunc = JSHandle::Cast(newTarget); - FunctionKind kind = newTargetFunc->GetFunctionKind(); + FunctionKind kind = newTargetFunc->GetFunctionKind(thread); if (HasPrototype(kind)) { prototype.Update(PrototypeGetter(thread, JSHandle::Cast(newTargetFunc))); } @@ -942,7 +943,7 @@ JSHandle JSFunction::GetInstanceJSHClass(JSThread *thread, JSHandleIsECMAObject()) { - prototype.Update(constructor->GetFunctionPrototype()); + prototype.Update(constructor->GetFunctionPrototype(thread)); } JSHandle newJSHClass = JSHClass::Clone(thread, ctorInitialJSHClass); @@ -955,7 +956,7 @@ JSHandle JSFunction::GetInstanceJSHClass(JSThread *thread, JSHandle JSFunction::GetOrCreateDerivedJSHClass(JSThread *thread, JSHandle derived, JSHandle ctorInitialJSHClass) { - JSTaggedValue protoOrHClass(derived->GetProtoOrHClass()); + JSTaggedValue protoOrHClass(derived->GetProtoOrHClass(thread)); // has cached JSHClass, return directly if (protoOrHClass.IsJSHClass()) { return JSHandle(thread, protoOrHClass); @@ -963,7 +964,7 @@ JSHandle JSFunction::GetOrCreateDerivedJSHClass(JSThread *thread, JSHa JSHandle newJSHClass; if (thread->GetEcmaVM()->GetJSOptions().IsEnableInlinePropertyOptimization()) { bool isStartObjSizeTracking = true; - uint32_t expectedOfProperties = CalcuExpotedOfProperties(derived, &isStartObjSizeTracking); + uint32_t expectedOfProperties = CalcuExpotedOfProperties(thread, derived, &isStartObjSizeTracking); if (isStartObjSizeTracking) { newJSHClass = JSHClass::CloneAndIncInlinedProperties(thread, ctorInitialJSHClass, expectedOfProperties); newJSHClass->StartObjSizeTracking(); @@ -975,7 +976,7 @@ JSHandle JSFunction::GetOrCreateDerivedJSHClass(JSThread *thread, JSHa } newJSHClass->SetElementsKind(ElementsKind::GENERIC); // guarante derived has function prototype - JSHandle prototype(thread, derived->GetProtoOrHClass()); + JSHandle prototype(thread, derived->GetProtoOrHClass(thread)); ASSERT(!prototype->IsHole()); newJSHClass->SetPrototype(thread, prototype); derived->SetProtoOrHClass(thread, newJSHClass); @@ -988,14 +989,14 @@ JSHandle JSFunction::GetOrCreateDerivedJSHClass(JSThread *thread, JSHa return newJSHClass; } -CString JSFunction::GetRecordName() const +CString JSFunction::GetRecordName(const JSThread *thread) const { - JSTaggedValue module = GetModule(); + JSTaggedValue module = GetModule(thread); if (module.IsSourceTextModule()) { return SourceTextModule::GetModuleName(module); } if (module.IsString()) { - return ConvertToString(module); + return ConvertToString(thread, module); } LOG_INTERPRETER(DEBUG) << "record name is undefined"; return ""; @@ -1011,7 +1012,7 @@ void JSFunction::InitializeJSFunction(JSThread *thread, [[maybe_unused]] const J bool JSFunction::NameSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, [[maybe_unused]] bool mayThrow) { - if (self->IsPropertiesDict()) { + if (self->IsPropertiesDict(thread)) { // replace setter with value JSHandle nameString = thread->GlobalConstants()->GetHandledNameString(); return self->UpdatePropertyInDictionary(thread, nameString.GetTaggedValue(), value.GetTaggedValue()); @@ -1023,7 +1024,7 @@ bool JSFunction::NameSetter(JSThread *thread, const JSHandle &self, co // NOTE: move to INL file? void JSFunction::SetFunctionLength(const JSThread *thread, JSTaggedValue length) { - ASSERT(!IsPropertiesDict()); + ASSERT(!IsPropertiesDict(thread)); SetPropertyInlinedProps(thread, LENGTH_INLINE_PROPERTY_INDEX, length); } @@ -1032,12 +1033,12 @@ void JSFunction::SetFunctionExtraInfo(JSThread *thread, const JSHandleGetEcmaVM(); JSHandle value(thread, JSTaggedValue(hashField)); JSHandle pointer = vm->GetFactory()->NewJSNativePointer(nativeFunc, deleter, data, false, nativeBindingsize, isConcurrent); - if (!func->HasHash()) { + if (!func->HasHash(thread)) { Barriers::SetObject(thread, *func, HASH_OFFSET, pointer.GetTaggedValue().GetRawData()); return; } @@ -1055,9 +1056,9 @@ void JSFunction::SetFunctionExtraInfo(JSThread *thread, const JSHandle newArray = vm->GetFactory()->NewTaggedArray(nativeFieldCount + RESOLVED_MAX_SIZE); newArray->SetExtraLength(nativeFieldCount); for (uint32_t i = 0; i < nativeFieldCount; i++) { - newArray->Set(thread, i, array->Get(i)); + newArray->Set(thread, i, array->Get(thread, i)); } - newArray->Set(thread, nativeFieldCount + HASH_INDEX, array->Get(nativeFieldCount + HASH_INDEX)); + newArray->Set(thread, nativeFieldCount + HASH_INDEX, array->Get(thread, nativeFieldCount + HASH_INDEX)); newArray->Set(thread, nativeFieldCount + FUNCTION_EXTRA_INDEX, pointer); Barriers::SetObject(thread, *func, HASH_OFFSET, newArray.GetTaggedValue().GetRawData()); } @@ -1074,12 +1075,12 @@ void JSFunction::SetFunctionExtraInfo(JSThread *thread, const JSHandle &func, void *nativeFunc, const NativePointerCallback &deleter, void *data, size_t nativeBindingsize) { - JSTaggedType hashField = Barriers::GetTaggedValue(*func, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, *func, HASH_OFFSET); EcmaVM *vm = thread->GetEcmaVM(); JSHandle value(thread, JSTaggedValue(hashField)); JSHandle pointer = vm->GetFactory()->NewSJSNativePointer(nativeFunc, deleter, data, false, nativeBindingsize); - if (!func->HasHash()) { + if (!func->HasHash(thread)) { Barriers::SetObject(thread, *func, HASH_OFFSET, pointer.GetTaggedValue().GetRawData()); return; } @@ -1098,9 +1099,9 @@ void JSFunction::SetSFunctionExtraInfo(JSThread *thread, const JSHandleGetFactory()->NewSTaggedArrayWithoutInit(nativeFieldCount + RESOLVED_MAX_SIZE); newArray->SetExtraLength(nativeFieldCount); for (uint32_t i = 0; i < nativeFieldCount; i++) { - newArray->Set(thread, i, array->Get(i)); + newArray->Set(thread, i, array->Get(thread, i)); } - newArray->Set(thread, nativeFieldCount + HASH_INDEX, array->Get(nativeFieldCount + HASH_INDEX)); + newArray->Set(thread, nativeFieldCount + HASH_INDEX, array->Get(thread, nativeFieldCount + HASH_INDEX)); newArray->Set(thread, nativeFieldCount + FUNCTION_EXTRA_INDEX, pointer); Barriers::SetObject(thread, *func, HASH_OFFSET, newArray.GetTaggedValue().GetRawData()); } @@ -1116,7 +1117,7 @@ void JSFunction::SetSFunctionExtraInfo(JSThread *thread, const JSHandle &func, const JSHandle &value, BarrierMode mode) { - JSHandle handleRaw(thread, func->GetRawProfileTypeInfo()); + JSHandle handleRaw(thread, func->GetRawProfileTypeInfo(thread)); if (handleRaw->IsEmptyProfileTypeInfoCell(thread)) { JSHandle handleProfileTypeInfoCell = thread->GetEcmaVM()->GetFactory()->NewProfileTypeInfoCell(value); @@ -1129,7 +1130,7 @@ void JSFunction::SetProfileTypeInfo(const JSThread *thread, const JSHandle literalFunc, JSHandle targetFunc) { - auto profileTypeInfoCellVal = literalFunc->GetRawProfileTypeInfo(); + auto profileTypeInfoCellVal = literalFunc->GetRawProfileTypeInfo(thread); ASSERT(profileTypeInfoCellVal.IsProfileTypeInfoCell()); auto profileTypeInfoCell = ProfileTypeInfoCell::Cast(profileTypeInfoCellVal); if (profileTypeInfoCell->IsEmptyProfileTypeInfoCell(thread)) { @@ -1146,14 +1147,14 @@ void JSFunction::UpdateProfileTypeInfoCell(JSThread *thread, JSHandle &machineCode) { - JSHandle handleRaw(thread, GetRawProfileTypeInfo()); + JSHandle handleRaw(thread, GetRawProfileTypeInfo(thread)); ASSERT(!handleRaw->IsEmptyProfileTypeInfoCell(thread)); handleRaw->SetMachineCode(thread, machineCode.GetTaggedValue().CreateAndGetWeakRef(), WRITE_BARRIER); } void JSFunction::SetBaselineJitCodeCache(const JSThread *thread, const JSHandle &machineCode) { - JSHandle handleRaw(thread, GetRawProfileTypeInfo()); + JSHandle handleRaw(thread, GetRawProfileTypeInfo(thread)); if (handleRaw->IsEmptyProfileTypeInfoCell(thread)) { LOG_BASELINEJIT(ERROR) << "skip set baselinejit cache, as profileTypeInfoCell is empty."; return; @@ -1161,16 +1162,16 @@ void JSFunction::SetBaselineJitCodeCache(const JSThread *thread, const JSHandle< handleRaw->SetBaselineCode(thread, machineCode.GetTaggedValue().CreateAndGetWeakRef(), WRITE_BARRIER); } -JSTaggedValue JSFunctionBase::GetFunctionExtraInfo() const +JSTaggedValue JSFunctionBase::GetFunctionExtraInfo(const JSThread *thread) const { - JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, this, HASH_OFFSET); JSTaggedValue value(hashField); if (value.IsHeapObject()) { if (value.IsTaggedArray()) { TaggedArray *array = TaggedArray::Cast(value.GetTaggedObject()); uint32_t nativeFieldCount = array->GetExtraLength(); if (array->GetLength() >= nativeFieldCount + RESOLVED_MAX_SIZE) { - return array->Get(nativeFieldCount + FUNCTION_EXTRA_INDEX); + return array->Get(thread, nativeFieldCount + FUNCTION_EXTRA_INDEX); } } if (value.IsJSNativePointer()) { @@ -1185,9 +1186,9 @@ JSTaggedValue JSFunctionBase::GetFunctionExtraInfo() const return JSTaggedValue::Undefined(); } -JSTaggedValue JSFunction::GetNativeFunctionExtraInfo() const +JSTaggedValue JSFunction::GetNativeFunctionExtraInfo(const JSThread *thread) const { - JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, this, HASH_OFFSET); JSTaggedValue value(hashField); if (value.CheckIsJSNativePointer()) { return value; @@ -1197,18 +1198,18 @@ JSTaggedValue JSFunction::GetNativeFunctionExtraInfo() const void JSFunction::InitializeForConcurrentFunction(JSThread *thread, JSHandle &func) { - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); JSMutableHandle sendableEnv(thread, JSTaggedValue::Undefined()); - if (func->IsSharedFunction() && !func->GetModule().IsUndefined()) { - sendableEnv.Update(SourceTextModule::Cast(func->GetModule())->GetSendableEnv()); + if (func->IsSharedFunction() && !func->GetModule(thread).IsUndefined()) { + sendableEnv.Update(SourceTextModule::Cast(func->GetModule(thread))->GetSendableEnv(thread)); } - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); if (jsPandaFile == nullptr) { LOG_ECMA(ERROR) << "JSPandaFile is nullptr"; return; } ecmascript::CString moduleName = jsPandaFile->GetJSPandaFileDesc(); - ecmascript::CString recordName = method->GetRecordNameStr(); + ecmascript::CString recordName = method->GetRecordNameStr(thread); // check ESM or CJS ecmascript::JSRecordInfo *recordInfo = jsPandaFile->CheckAndGetRecordInfo(recordName); @@ -1246,10 +1247,10 @@ void JSFunction::InitializeForConcurrentFunction(JSThread *thread, JSHandleLoadModuleEvent(moduleName, recordName); } -bool JSFunction::IsSendableOrConcurrentFunction() const +bool JSFunction::IsSendableOrConcurrentFunction(JSThread *thread) const { if (this->GetClass()->IsJSSharedFunction() || this->GetClass()->IsJSSharedAsyncFunction() || - this->GetFunctionKind() == ecmascript::FunctionKind::CONCURRENT_FUNCTION) { + this->GetFunctionKind(thread) == ecmascript::FunctionKind::CONCURRENT_FUNCTION) { return true; } return false; @@ -1280,18 +1281,18 @@ void JSFunction::SetJitCompiledFuncEntry(JSThread *thread, JSHandle SetCompiledFuncEntry(codeEntry, isFastCall); } -void JSFunction::SetJitHotnessCnt(uint16_t cnt) +void JSFunction::SetJitHotnessCnt(const JSThread *thread, uint16_t cnt) { - JSTaggedValue profileTypeInfoVal = GetProfileTypeInfo(); + JSTaggedValue profileTypeInfoVal = GetProfileTypeInfo(thread); if (!profileTypeInfoVal.IsUndefined()) { ProfileTypeInfo *profileTypeInfo = ProfileTypeInfo::Cast(profileTypeInfoVal.GetTaggedObject()); profileTypeInfo->SetJitHotnessCnt(cnt); } } -uint16_t JSFunction::GetJitHotnessCnt() const +uint16_t JSFunction::GetJitHotnessCnt(const JSThread *thread) const { - JSTaggedValue profileTypeInfoVal = GetProfileTypeInfo(); + JSTaggedValue profileTypeInfoVal = GetProfileTypeInfo(thread); if (!profileTypeInfoVal.IsUndefined()) { ProfileTypeInfo *profileTypeInfo = ProfileTypeInfo::Cast(profileTypeInfoVal.GetTaggedObject()); return profileTypeInfo->GetJitHotnessCnt(); diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index a867352f03..36b2ebed25 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -53,9 +53,9 @@ public: return IsCallNapiBit::Decode(bitField); } - FunctionKind GetFunctionKind() const + FunctionKind GetFunctionKind(const JSThread *thread) const { - JSTaggedValue method = GetMethod(); + JSTaggedValue method = GetMethod(thread); return Method::ConstCast(method.GetTaggedObject())->GetFunctionKind(); } @@ -74,26 +74,26 @@ public: return IsFastCallBit::Decode(bitField); } - static bool IsCompiledCodeFromCallTarget(JSTaggedValue callTarget) + static bool IsCompiledCodeFromCallTarget(const JSThread *thread, JSTaggedValue callTarget) { if (callTarget.IsJSFunction()) { return Cast(callTarget.GetTaggedObject())->IsCompiledCode(); } else { ECMAObject *target = reinterpret_cast(callTarget.GetTaggedObject()); ASSERT(target != nullptr); - Method *method = target->GetCallTarget(); + Method *method = target->GetCallTarget(thread); return method->IsAotWithCallField(); } } - static bool IsFastCallFromCallTarget(JSTaggedValue callTarget) + static bool IsFastCallFromCallTarget(const JSThread *thread, JSTaggedValue callTarget) { if (callTarget.IsJSFunction()) { return Cast(callTarget.GetTaggedObject())->IsCompiledFastCall(); } else { ECMAObject *target = reinterpret_cast(callTarget.GetTaggedObject()); ASSERT(target != nullptr); - Method *method = target->GetCallTarget(); + Method *method = target->GetCallTarget(thread); return method->IsFastCall(); } } @@ -172,7 +172,7 @@ public: SetCodeEntryOrNativePointer(ToUintPtr(nativePointer)); } - JSTaggedValue GetFunctionExtraInfo() const; + JSTaggedValue GetFunctionExtraInfo(const JSThread *thread) const; /* compiled code flag field */ using IsCompiledCodeBit = BitField; // offset 0 @@ -247,12 +247,12 @@ public: static bool NameSetter(JSThread *thread, const JSHandle &self, const JSHandle &value, bool mayThrow); static void SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JSTaggedValue name); - inline JSTaggedValue GetFunctionPrototype() const + inline JSTaggedValue GetFunctionPrototype(const JSThread *thread) const { - ASSERT(HasFunctionPrototype()); - JSTaggedValue protoOrHClass = GetProtoOrHClass(); + ASSERT(HasFunctionPrototype(thread)); + JSTaggedValue protoOrHClass = GetProtoOrHClass(thread); if (protoOrHClass.IsJSHClass()) { - return JSHClass::Cast(protoOrHClass.GetTaggedObject())->GetPrototype(); + return JSHClass::Cast(protoOrHClass.GetTaggedObject())->GetPrototype(thread); } return protoOrHClass; @@ -261,44 +261,44 @@ public: static void SetFunctionPrototypeOrInstanceHClass(const JSThread *thread, const JSHandle &fun, JSTaggedValue protoOrHClass); - static EcmaString* GetFunctionNameString(ObjectFactory *factory, JSHandle concatString, + static EcmaString* GetFunctionNameString(const JSThread *thread, ObjectFactory *factory, JSHandle concatString, JSHandle target); - inline bool HasInitialClass() const + inline bool HasInitialClass(const JSThread *thread) const { - JSTaggedValue protoOrHClass = GetProtoOrHClass(); + JSTaggedValue protoOrHClass = GetProtoOrHClass(thread); return protoOrHClass.IsJSHClass(); } - inline bool HasFunctionPrototype() const + inline bool HasFunctionPrototype(const JSThread *thread) const { - JSTaggedValue protoOrHClass = GetProtoOrHClass(); + JSTaggedValue protoOrHClass = GetProtoOrHClass(thread); return !protoOrHClass.IsHole(); } void SetFunctionLength(const JSThread *thread, JSTaggedValue length); - inline bool IsGetterOrSetter() const + inline bool IsGetterOrSetter(const JSThread *thread) const { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind == FunctionKind::GETTER_FUNCTION || kind == FunctionKind::SETTER_FUNCTION; } - inline bool IsGetter() const + inline bool IsGetter(const JSThread *thread) const { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind == FunctionKind::GETTER_FUNCTION; } - inline bool IsBase() const + inline bool IsBase(const JSThread *thread) const { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind <= FunctionKind::CLASS_CONSTRUCTOR; } - inline bool IsDerivedConstructor() const + inline bool IsDerivedConstructor(const JSThread *thread) const { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind == FunctionKind::DERIVED_CONSTRUCTOR; } @@ -317,9 +317,9 @@ public: return (kind >= FunctionKind::BASE_CONSTRUCTOR) && (kind <= FunctionKind::DERIVED_CONSTRUCTOR); } - inline bool IsBuiltinConstructor() + inline bool IsBuiltinConstructor(const JSThread *thread) { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind >= FunctionKind::BUILTIN_PROXY_CONSTRUCTOR && kind <= FunctionKind::BUILTIN_CONSTRUCTOR; } @@ -354,11 +354,11 @@ public: GetClass()->SetClassConstructor(flag); } - inline bool HasProfileTypeInfo(JSThread *thread) const + inline bool HasProfileTypeInfo(const JSThread *thread) const { - return GetRawProfileTypeInfo().IsProfileTypeInfoCell() && - !ProfileTypeInfoCell::Cast(GetRawProfileTypeInfo())->IsEmptyProfileTypeInfoCell(thread) && - !ProfileTypeInfoCell::Cast(GetRawProfileTypeInfo())->GetValue().IsUndefined(); + return GetRawProfileTypeInfo(thread).IsProfileTypeInfoCell() && + !ProfileTypeInfoCell::Cast(GetRawProfileTypeInfo(thread))->IsEmptyProfileTypeInfoCell(thread) && + !ProfileTypeInfoCell::Cast(GetRawProfileTypeInfo(thread))->GetValue(thread).IsUndefined(); } static void SetFunctionExtraInfo(JSThread *thread, const JSHandle &func, void *nativeFunc, @@ -374,24 +374,25 @@ public: void SetBaselineJitCodeCache(const JSThread *thread, const JSHandle &machineCode); void ClearMachineCode(const JSThread *thread); - JSTaggedValue GetNativeFunctionExtraInfo() const; - CString GetRecordName() const; - JSTaggedValue GetProfileTypeInfo() const + JSTaggedValue GetNativeFunctionExtraInfo(const JSThread *thread) const; + CString GetRecordName(const JSThread *thread) const; + JSTaggedValue GetProfileTypeInfo(const JSThread *thread) const { - JSTaggedValue raw = GetRawProfileTypeInfo(); - return ProfileTypeInfoCell::Cast(raw.GetTaggedObject())->GetValue(); + JSTaggedValue raw = GetRawProfileTypeInfo(thread); + return ProfileTypeInfoCell::Cast(raw.GetTaggedObject())->GetValue(thread); } void SetJitCompiledFuncEntry(JSThread *thread, JSHandle &machineCode, bool isFastCall); - void SetJitHotnessCnt(uint16_t cnt); - uint16_t GetJitHotnessCnt() const; + void SetJitHotnessCnt(const JSThread *thread, uint16_t cnt); + uint16_t GetJitHotnessCnt(const JSThread *thread) const; static void InitializeForConcurrentFunction(JSThread *thread, JSHandle &func); - bool IsSendableOrConcurrentFunction() const; + bool IsSendableOrConcurrentFunction(JSThread *thread) const; bool IsSharedFunction() const; - static uint32_t CalcuExpotedOfProperties(const JSHandle &fun, bool *isStartSlackTracking); + static uint32_t CalcuExpotedOfProperties(JSThread *thread, const JSHandle &fun, + bool *isStartSlackTracking); static void InitializeJSFunctionCommon(JSThread *thread, const JSHandle &func, FunctionKind kind); static void InitializeJSFunction(JSThread *thread, const JSHandle &func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION); @@ -431,7 +432,7 @@ public: private: static JSHandle GetOrCreateDerivedJSHClass(JSThread *thread, JSHandle derived, JSHandle ctorInitialClass); - static std::vector GetArgsData(bool isFastCall, JSHandle &thisArg, + static std::vector GetArgsData(JSThread *thread, bool isFastCall, JSHandle &thisArg, JSHandle mainFunc, CJSInfo* cjsInfo); }; @@ -656,21 +657,21 @@ public: class FunctionTemplate : public TaggedObject { public: - FunctionKind GetFunctionKind() const + FunctionKind GetFunctionKind(const JSThread *thread) const { - JSTaggedValue method = GetMethod(); + JSTaggedValue method = GetMethod(thread); return Method::ConstCast(method.GetTaggedObject())->GetFunctionKind(); } - inline bool IsGetterOrSetter() const + inline bool IsGetterOrSetter(const JSThread *thread) const { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind == FunctionKind::GETTER_FUNCTION || kind == FunctionKind::SETTER_FUNCTION; } - inline bool IsGetter() const + inline bool IsGetter(const JSThread *thread) const { - FunctionKind kind = GetFunctionKind(); + FunctionKind kind = GetFunctionKind(thread); return kind == FunctionKind::GETTER_FUNCTION; } diff --git a/ecmascript/js_generator_object.cpp b/ecmascript/js_generator_object.cpp index bbc98bea0c..b757b2c641 100644 --- a/ecmascript/js_generator_object.cpp +++ b/ecmascript/js_generator_object.cpp @@ -64,7 +64,7 @@ JSHandle JSGeneratorObject::GeneratorResume(JSThread *thread, const JS "state is neither suspendedStart nor suspendedYield"); // 4.Let genContext be generator.[[GeneratorContext]]. - JSHandle genContext(thread, generator->GetGeneratorContext()); + JSHandle genContext(thread, generator->GetGeneratorContext(thread)); // 5.Let methodContext be the running execution context. // 6.Suspend methodContext. @@ -106,7 +106,7 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, // i.Return CreateIterResultObject(abruptCompletion.[[Value]], true). // b.Return Completion(abruptCompletion). if (state == JSGeneratorState::COMPLETED) { - JSHandle valueHandle(thread, abruptCompletion->GetValue()); + JSHandle valueHandle(thread, abruptCompletion->GetValue(thread)); JSHandle result = JSIterator::CreateIterResultObject(thread, valueHandle, true); if (abruptCompletion->GetType() == CompletionRecordType::RETURN) { return result; @@ -118,7 +118,7 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, ASSERT_PRINT(state == JSGeneratorState::SUSPENDED_YIELD, "state is not suspendedYield"); // 5.Let genContext be generator.[[GeneratorContext]]. - JSHandle genContext(thread, generator->GetGeneratorContext()); + JSHandle genContext(thread, generator->GetGeneratorContext(thread)); // 6.Let methodContext be the running execution context. // 7.Suspend methodContext. @@ -134,9 +134,9 @@ JSHandle JSGeneratorObject::GeneratorResumeAbrupt(JSThread *thread, // 12.Return Completion(result). JSHandle result; if (abruptCompletion->GetType() == CompletionRecordType::RETURN) { - result = GeneratorHelper::Return(thread, genContext, abruptCompletion->GetValue()); + result = GeneratorHelper::Return(thread, genContext, abruptCompletion->GetValue(thread)); } else { - result = GeneratorHelper::Throw(thread, genContext, abruptCompletion->GetValue()); + result = GeneratorHelper::Throw(thread, genContext, abruptCompletion->GetValue(thread)); } return result; } diff --git a/ecmascript/js_handle.h b/ecmascript/js_handle.h index 0d9b6a5819..e9b0e1e722 100644 --- a/ecmascript/js_handle.h +++ b/ecmascript/js_handle.h @@ -176,9 +176,9 @@ public: } } - void Dump() const DUMP_API_ATTR + void Dump(const JSThread *thread) const DUMP_API_ATTR { - GetTaggedValue().D(); + GetTaggedValue().D(thread); } template @@ -207,14 +207,12 @@ private: template <> inline JSTaggedValue *JSHandle::operator->() const { - Barriers::UpdateSlot(reinterpret_cast(GetAddress()), 0); return reinterpret_cast(GetAddress()); } template <> inline JSTaggedValue *JSHandle::operator*() const { - Barriers::UpdateSlot(reinterpret_cast(GetAddress()), 0); return reinterpret_cast(GetAddress()); } diff --git a/ecmascript/js_hclass-inl.h b/ecmascript/js_hclass-inl.h index d65f17eb99..d00b32133c 100644 --- a/ecmascript/js_hclass-inl.h +++ b/ecmascript/js_hclass-inl.h @@ -32,7 +32,7 @@ void JSHClass::AddTransitions(const JSThread *thread, const JSHandle & const JSHandle &key, PropertyAttributes attributes) { UpdateRootHClass(thread, parent, child); - JSTaggedValue transitions = parent->GetTransitions(); + JSTaggedValue transitions = parent->GetTransitions(thread); if (transitions.IsUndefined()) { NotifyLeafHClassChanged(const_cast(thread), parent); JSTaggedValue weakChild = JSTaggedValue(child.GetTaggedValue().CreateAndGetWeakRef()); @@ -45,10 +45,10 @@ void JSHClass::AddTransitions(const JSThread *thread, const JSHandle & auto cachedHClass = JSHClass::Cast(transitions.GetTaggedWeakRef()); if (cachedHClass->HasProps()) { uint32_t last = cachedHClass->LastPropIndex(); - LayoutInfo* layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); + LayoutInfo* layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout(thread).GetTaggedObject()); auto metaData = JSHandle(thread, - JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); - auto lastKey = JSHandle(thread, layoutInfo->GetKey(last)); + JSTaggedValue(layoutInfo->GetAttr(thread, last).GetPropertyMetaData())); + auto lastKey = JSHandle(thread, layoutInfo->GetKey(thread, last)); auto lastHClass = JSHandle(thread, cachedHClass); dict.Update(TransitionsDictionary::Create(thread)); transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, @@ -75,7 +75,7 @@ void JSHClass::AddProtoTransitions(const JSThread *thread, const JSHandleGetTransitions(); + JSTaggedValue transitions = parent->GetTransitions(thread); JSMutableHandle dict(thread, JSTaggedValue::Undefined()); if (transitions.IsUndefined()) { NotifyLeafHClassChanged(const_cast(thread), parent); @@ -84,10 +84,10 @@ void JSHClass::AddProtoTransitions(const JSThread *thread, const JSHandleHasProps()) { uint32_t last = cachedHClass->LastPropIndex(); - LayoutInfo* layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); + LayoutInfo* layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout(thread).GetTaggedObject()); auto metaData = JSHandle(thread, - JSTaggedValue(layoutInfo->GetAttr(last).GetPropertyMetaData())); - auto lastKey = JSHandle(thread, layoutInfo->GetKey(last)); + JSTaggedValue(layoutInfo->GetAttr(thread, last).GetPropertyMetaData())); + auto lastKey = JSHandle(thread, layoutInfo->GetKey(thread, last)); auto lastHClass = JSHandle(thread, cachedHClass); dict.Update(TransitionsDictionary::Create(thread)); transitions = TransitionsDictionary::PutIfAbsent(thread, dict, lastKey, lastHClass, @@ -101,11 +101,11 @@ void JSHClass::AddProtoTransitions(const JSThread *thread, const JSHandleSetTransitions(thread, transitions); } -inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTaggedValue &metaData, - const Representation &rep) +inline JSHClass *JSHClass::FindTransitions(const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &metaData, const Representation &rep) { DISALLOW_GARBAGE_COLLECTION; - JSTaggedValue transitions = GetTransitions(); + JSTaggedValue transitions = GetTransitions(thread); if (transitions.IsUndefined()) { return nullptr; } @@ -115,46 +115,47 @@ inline JSHClass *JSHClass::FindTransitions(const JSTaggedValue &key, const JSTag return nullptr; } int last = static_cast(cachedHClass->LastPropIndex()); - LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout().GetTaggedObject()); - auto lastMetaData = layoutInfo->GetAttr(last).GetPropertyMetaData(); - auto lastKey = layoutInfo->GetKey(last); + LayoutInfo *layoutInfo = LayoutInfo::Cast(cachedHClass->GetLayout(thread).GetTaggedObject()); + auto lastMetaData = layoutInfo->GetAttr(thread, last).GetPropertyMetaData(); + auto lastKey = layoutInfo->GetKey(thread, last); if (lastMetaData == metaData.GetInt() && key == lastKey) { - return CheckHClassForRep(cachedHClass, rep); + return CheckHClassForRep(thread, cachedHClass, rep); } return nullptr; } ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - auto entry = dict->FindEntry(key, metaData); + auto entry = dict->FindEntry(thread, key, metaData); if (entry == -1) { return nullptr; } - JSTaggedValue ret = dict->GetValue(entry); + JSTaggedValue ret = dict->GetValue(thread, entry); if (ret.IsUndefined()) { return nullptr; } - return CheckHClassForRep(JSHClass::Cast(ret.GetTaggedWeakRef()), rep); + return CheckHClassForRep(thread, JSHClass::Cast(ret.GetTaggedWeakRef()), rep); } -inline JSHClass *JSHClass::FindProtoTransitions(const JSTaggedValue &key, const JSTaggedValue &proto) +inline JSHClass *JSHClass::FindProtoTransitions(const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &proto) { DISALLOW_GARBAGE_COLLECTION; - JSTaggedValue transitions = GetTransitions(); + JSTaggedValue transitions = GetTransitions(thread); if (transitions.IsWeak() || !transitions.IsTaggedArray()) { ASSERT(transitions.IsUndefined() || transitions.IsWeak()); return nullptr; } ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - auto entry = dict->FindEntry(key, proto); + auto entry = dict->FindEntry(thread, key, proto); if (entry == -1) { return nullptr; } - JSTaggedValue ret = dict->GetValue(entry); + JSTaggedValue ret = dict->GetValue(thread, entry); if (ret.IsUndefined()) { return nullptr; } @@ -167,7 +168,7 @@ inline void JSHClass::RestoreElementsKindToGeneric(JSHClass *newJsHClass) newJsHClass->SetElementsKind(ElementsKind::GENERIC); } -inline JSHClass *JSHClass::CheckHClassForRep(JSHClass *hclass, const Representation &rep) +inline JSHClass *JSHClass::CheckHClassForRep(const JSThread *thread, JSHClass *hclass, const Representation &rep) { if (!hclass->IsAOT()) { return hclass; @@ -177,8 +178,8 @@ inline JSHClass *JSHClass::CheckHClassForRep(JSHClass *hclass, const Representat } int last = static_cast(hclass->LastPropIndex()); - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - auto lastRep = layoutInfo->GetAttr(last).GetRepresentation(); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + auto lastRep = layoutInfo->GetAttr(thread, last).GetRepresentation(); auto result = hclass; if (lastRep == Representation::INT) { if (rep != Representation::INT) { @@ -196,8 +197,8 @@ inline void JSHClass::UpdatePropertyMetaData(const JSThread *thread, [[maybe_unu const PropertyAttributes &metaData) { DISALLOW_GARBAGE_COLLECTION; - ASSERT(!GetLayout().IsNull()); - LayoutInfo *layoutInfo = LayoutInfo::Cast(GetLayout().GetTaggedObject()); + ASSERT(!GetLayout(thread).IsNull()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(GetLayout(thread).GetTaggedObject()); ASSERT(layoutInfo->GetLength() != 0); uint32_t entry = metaData.GetOffset(); @@ -278,17 +279,17 @@ inline void JSHClass::Copy(const JSThread *thread, const JSHClass *jshclass) DISALLOW_GARBAGE_COLLECTION; // copy jshclass - SetPrototype(thread, jshclass->GetPrototype()); + SetPrototype(thread, jshclass->GetPrototype(thread)); SetBitField(jshclass->GetBitField()); SetIsAllTaggedProp(jshclass->IsAllTaggedProp()); SetNumberOfProps(jshclass->NumberOfProps()); } -inline JSHClass *JSHClass::FindRootHClass(JSHClass *hclass) +inline JSHClass *JSHClass::FindRootHClass(const JSThread *thread, JSHClass *hclass) { auto root = hclass; while (!ProfileType(root->GetProfileType()).IsRootType()) { - auto parent = root->GetParent(); + auto parent = root->GetParent(thread); if (!parent.IsJSHClass()) { break; } @@ -297,9 +298,9 @@ inline JSHClass *JSHClass::FindRootHClass(JSHClass *hclass) return root; } -inline JSTaggedValue JSHClass::FindProtoHClass(JSHClass *hclass) +inline JSTaggedValue JSHClass::FindProtoHClass(const JSThread *thread, JSHClass *hclass) { - auto proto = hclass->GetProto(); + auto proto = hclass->GetProto(thread); if (proto.IsJSObject()) { auto prototypeObj = JSObject::Cast(proto); return JSTaggedValue(prototypeObj->GetClass()); @@ -307,13 +308,13 @@ inline JSTaggedValue JSHClass::FindProtoHClass(JSHClass *hclass) return JSTaggedValue::Undefined(); } -inline JSTaggedValue JSHClass::FindProtoRootHClass(JSHClass *hclass) +inline JSTaggedValue JSHClass::FindProtoRootHClass(const JSThread *thread, JSHClass *hclass) { - auto proto = hclass->GetProto(); + auto proto = hclass->GetProto(thread); if (proto.IsJSObject()) { auto prototypeObj = JSObject::Cast(proto); auto prototypeHClass = prototypeObj->GetClass(); - return JSTaggedValue(JSHClass::FindRootHClass(prototypeHClass)); + return JSTaggedValue(JSHClass::FindRootHClass(thread, prototypeHClass)); } return JSTaggedValue::Undefined(); } @@ -329,26 +330,26 @@ inline void JSHClass::UpdateRootHClass(const JSThread *thread, const JSHandleGetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); uint32_t propsNumber = hclass->NumberOfProps(); int entry = layout->FindElementWithCache(thread, hclass, key, propsNumber); return entry; } -inline void JSHClass::CompleteObjSizeTracking() +inline void JSHClass::CompleteObjSizeTracking(const JSThread *thread) { if (!IsObjSizeTrackingInProgress()) { return; } - uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(this); + uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(thread, this); if (finalInObjPropsNum < GetInlinedProperties()) { // UpdateObjSize with finalInObjPropsNum - JSHClass::VisitTransitionAndUpdateObjSize(this, finalInObjPropsNum); + JSHClass::VisitTransitionAndUpdateObjSize(thread, this, finalInObjPropsNum); } SetConstructionCounter(0); // fini ObjSizeTracking } -inline void JSHClass::ObjSizeTrackingStep() +inline void JSHClass::ObjSizeTrackingStep(const JSThread *thread) { if (!IsObjSizeTrackingInProgress()) { return; @@ -357,10 +358,10 @@ inline void JSHClass::ObjSizeTrackingStep() ASSERT(constructionCounter != 0); SetConstructionCounter(--constructionCounter); if (constructionCounter == 0) { - uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(this); + uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(thread, this); if (finalInObjPropsNum < GetInlinedProperties()) { // UpdateObjSize with finalInObjPropsNum - JSHClass::VisitTransitionAndUpdateObjSize(this, finalInObjPropsNum); + JSHClass::VisitTransitionAndUpdateObjSize(thread, this, finalInObjPropsNum); } } } @@ -370,8 +371,8 @@ void JSHClass::MarkProtoChanged(const JSThread *thread, const JSHandle { DISALLOW_GARBAGE_COLLECTION; ASSERT(jshclass->IsPrototype()); - JSTaggedValue enumCache = jshclass->GetEnumCache(); - JSTaggedValue markerValue = jshclass->GetProtoChangeMarker(); + JSTaggedValue enumCache = jshclass->GetEnumCache(thread); + JSTaggedValue markerValue = jshclass->GetProtoChangeMarker(thread); // Used in for-in. if (enumCache.IsEnumCache()) { EnumCache::Cast(enumCache)->SetInvalidState(thread); @@ -392,20 +393,20 @@ void JSHClass::NoticeThroughChain(const JSThread *thread, const JSHandle(thread, jshclass); - JSTaggedValue protoDetailsValue = jshclass->GetProtoChangeDetails(); + JSTaggedValue protoDetailsValue = jshclass->GetProtoChangeDetails(thread); if (!protoDetailsValue.IsProtoChangeDetails()) { return; } - JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(thread); if (!listenersValue.IsTaggedArray()) { return; } ChangeListener *listeners = ChangeListener::Cast(listenersValue.GetTaggedObject()); for (uint32_t i = 0; i < listeners->GetEnd(); i++) { - JSTaggedValue temp = listeners->Get(i); + JSTaggedValue temp = listeners->Get(thread, i); if (temp.IsJSHClass()) { NoticeThroughChain(thread, - JSHandle(thread, listeners->Get(i).GetTaggedObject()), addedKey); + JSHandle(thread, listeners->Get(thread, i).GetTaggedObject()), addedKey); } } } @@ -424,7 +425,7 @@ void JSHClass::AddPropertyToNewHClass(const JSThread *thread, JSHandle newJsHClass->IncNumberOfProps(); { - JSMutableHandle layoutInfoHandle(thread, newJsHClass->GetLayout()); + JSMutableHandle layoutInfoHandle(thread, newJsHClass->GetLayout(thread)); if (layoutInfoHandle->NumberOfElements() != static_cast(offset)) { layoutInfoHandle.Update(factory->CopyAndReSort(layoutInfoHandle, offset, offset + 1)); @@ -451,10 +452,10 @@ JSHandle JSHClass::SetPropertyOfObjHClass(const JSThread *thread, JSHa const PropertyAttributes &attr, const Representation &rep, bool specificInlinedProps, uint32_t specificNumInlinedProps) { - JSHClass *newClass = jshclass->FindTransitions( + JSHClass *newClass = jshclass->FindTransitions(thread, key.GetTaggedValue(), JSTaggedValue(attr.GetPropertyMetaData()), rep); if (newClass != nullptr) { - newClass->SetPrototype(thread, jshclass->GetPrototype()); + newClass->SetPrototype(thread, jshclass->GetPrototype(thread)); return JSHandle(thread, newClass); } diff --git a/ecmascript/js_hclass.cpp b/ecmascript/js_hclass.cpp index b996782d0b..f85ffb1f20 100644 --- a/ecmascript/js_hclass.cpp +++ b/ecmascript/js_hclass.cpp @@ -34,12 +34,12 @@ JSHandle TransitionsDictionary::PutIfAbsent(const JSThrea const JSHandle &value, const JSHandle &metaData) { - uint32_t hash = static_cast(TransitionsDictionary::Hash(key.GetTaggedValue(), metaData.GetTaggedValue())); + uint32_t hash = static_cast(TransitionsDictionary::Hash(thread, key.GetTaggedValue(), metaData.GetTaggedValue())); /* no need to add key if exist */ - int entry = dictionary->FindEntry(key.GetTaggedValue(), metaData.GetTaggedValue()); + int entry = dictionary->FindEntry(thread, key.GetTaggedValue(), metaData.GetTaggedValue()); if (entry != -1) { - if (dictionary->GetValue(entry).IsUndefined()) { + if (dictionary->GetValue(thread, entry).IsUndefined()) { JSTaggedValue weakValue = JSTaggedValue(value->CreateAndGetWeakRef()); dictionary->SetValue(thread, entry, weakValue); } @@ -49,7 +49,7 @@ JSHandle TransitionsDictionary::PutIfAbsent(const JSThrea // Check whether the dictionary should be extended. JSHandle newDictionary(HashTableT::GrowHashTable(thread, dictionary)); // Compute the key object. - entry = newDictionary->FindInsertIndex(hash); + entry = newDictionary->FindInsertIndex(thread, hash); JSTaggedValue val = value.GetTaggedValue(); newDictionary->SetEntry(thread, entry, key.GetTaggedValue(), val, metaData.GetTaggedValue()); @@ -57,14 +57,14 @@ JSHandle TransitionsDictionary::PutIfAbsent(const JSThrea return newDictionary; } -int TransitionsDictionary::FindEntry(const JSTaggedValue &key, const JSTaggedValue &metaData) +int TransitionsDictionary::FindEntry(const JSThread *thread, const JSTaggedValue &key, const JSTaggedValue &metaData) { size_t size = static_cast(Size()); uint32_t count = 1; - int32_t hash = TransitionsDictionary::Hash(key, metaData); + int32_t hash = TransitionsDictionary::Hash(thread, key, metaData); // GrowHashTable will guarantee the hash table is never full. for (uint32_t entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { - JSTaggedValue element = GetKey(entry); + JSTaggedValue element = GetKey(thread, entry); if (element.IsHole()) { continue; } @@ -72,7 +72,7 @@ int TransitionsDictionary::FindEntry(const JSTaggedValue &key, const JSTaggedVal return -1; } - if (TransitionsDictionary::IsMatch(key, metaData, element, GetAttributes(entry).GetWeakRawValue())) { + if (TransitionsDictionary::IsMatch(key, metaData, element, GetAttributes(thread, entry).GetWeakRawValue())) { return static_cast(entry); } } @@ -84,7 +84,7 @@ JSHandle TransitionsDictionary::Remove(const JSThread *th const JSHandle &key, const JSTaggedValue &metaData) { - int entry = table->FindEntry(key.GetTaggedValue(), metaData); + int entry = table->FindEntry(thread, key.GetTaggedValue(), metaData); if (entry == -1) { return table; } @@ -104,15 +104,15 @@ void TransitionsDictionary::Rehash(const JSThread *thread, TransitionsDictionary int entryCount = 0; for (int i = 0; i < size; i++) { int fromIndex = GetEntryIndex(i); - JSTaggedValue k = this->GetKey(i); - JSTaggedValue v = this->GetValue(i); + JSTaggedValue k = this->GetKey(thread, i); + JSTaggedValue v = this->GetValue(thread, i); if (IsKey(k) && TransitionsDictionary::CheckWeakExist(v)) { - uint32_t hash = static_cast(TransitionsDictionary::Hash(k, this->GetAttributes(i))); - int insertionIndex = GetEntryIndex(newTable->FindInsertIndex(hash)); - JSTaggedValue tv = Get(fromIndex); + uint32_t hash = static_cast(TransitionsDictionary::Hash(thread, k, this->GetAttributes(thread, i))); + int insertionIndex = GetEntryIndex(newTable->FindInsertIndex(thread, hash)); + JSTaggedValue tv = Get(thread, fromIndex); newTable->Set(thread, insertionIndex, tv); for (int j = 1; j < TransitionsDictionary::ENTRY_SIZE; j++) { - tv = Get(fromIndex + j); + tv = Get(thread, fromIndex + j); newTable->Set(thread, insertionIndex + j, tv); } entryCount++; @@ -238,7 +238,7 @@ JSHandle JSHClass::Clone(const JSThread *thread, const JSHandleSetProtoChangeDetails(thread, JSTaggedValue::Null()); newJsHClass->SetEnumCache(thread, JSTaggedValue::Null()); // reuse Attributes first. - newJsHClass->SetLayout(thread, jshclass->GetLayout()); + newJsHClass->SetLayout(thread, jshclass->GetLayout(thread)); if (jshclass->IsAOT()) { newJsHClass->SetAOT(false); @@ -319,11 +319,11 @@ void JSHClass::AddProperty(const JSThread *thread, const JSHandle &obj { JSHandle jshclass(thread, obj->GetJSHClass()); auto metadata = JSTaggedValue(attr.GetPropertyMetaData()); - JSHClass *newClass = jshclass->FindTransitions(key.GetTaggedValue(), metadata, rep); + JSHClass *newClass = jshclass->FindTransitions(thread, key.GetTaggedValue(), metadata, rep); if (newClass != nullptr) { // The transition hclass from AOT, which does not have a prototype, needs to be reset here. if (newClass->IsAOT()) { - newClass->SetPrototype(thread, jshclass->GetPrototype()); + newClass->SetPrototype(thread, jshclass->GetPrototype(thread)); } // Because we currently only supports Fast ElementsKind RestoreElementsKindToGeneric(newClass); @@ -335,7 +335,7 @@ void JSHClass::AddProperty(const JSThread *thread, const JSHandle &obj JSHClass::ProcessAotHClassTransition(thread, jshclass, newHClass, key.GetTaggedValue()); } else { if (newClass->IsPrototype()) { - newHClass->SetProtoChangeDetails(thread, jshclass->GetProtoChangeDetails()); + newHClass->SetProtoChangeDetails(thread, jshclass->GetProtoChangeDetails(thread)); } JSHClass::NotifyHclassChanged(thread, jshclass, newHClass, key.GetTaggedValue()); } @@ -357,9 +357,9 @@ JSHandle JSHClass::TransitionExtension(const JSThread *thread, const J { JSHandle key(thread->GlobalConstants()->GetHandledPreventExtensionsString()); { - auto *newClass = jshclass->FindTransitions(key.GetTaggedValue(), JSTaggedValue(0), Representation::NONE); + auto *newClass = jshclass->FindTransitions(thread, key.GetTaggedValue(), JSTaggedValue(0), Representation::NONE); if (newClass != nullptr) { - newClass->SetPrototype(thread, jshclass->GetPrototype()); + newClass->SetPrototype(thread, jshclass->GetPrototype(thread)); return JSHandle(thread, newClass); } } @@ -368,7 +368,7 @@ JSHandle JSHClass::TransitionExtension(const JSThread *thread, const J JSHandle newJsHClass = JSHClass::Clone(thread, jshclass); newJsHClass->SetExtensible(false); - JSTaggedValue attrs = newJsHClass->GetLayout(); + JSTaggedValue attrs = newJsHClass->GetLayout(thread); { JSMutableHandle layoutInfoHandle(thread, attrs); layoutInfoHandle.Update(factory->CopyLayoutInfo(layoutInfoHandle).GetTaggedValue()); @@ -387,7 +387,7 @@ JSHandle JSHClass::TransitionProto(const JSThread *thread, const JSHan JSHandle key(thread->GlobalConstants()->GetHandledPrototypeString()); { - auto *newClass = jshclass->FindProtoTransitions(key.GetTaggedValue(), proto.GetTaggedValue()); + auto *newClass = jshclass->FindProtoTransitions(thread, key.GetTaggedValue(), proto.GetTaggedValue()); if (newClass != nullptr) { return JSHandle(thread, newClass); } @@ -402,7 +402,7 @@ JSHandle JSHClass::TransitionProto(const JSThread *thread, const JSHan JSHandle newJsHClass = JSHClass::Clone(thread, jshclass); newJsHClass->SetPrototype(thread, proto.GetTaggedValue(), isChangeProto); - JSTaggedValue layout = newJsHClass->GetLayout(); + JSTaggedValue layout = newJsHClass->GetLayout(thread); { JSMutableHandle layoutInfoHandle(thread, layout); layoutInfoHandle.Update(factory->CopyLayoutInfo(layoutInfoHandle).GetTaggedValue()); @@ -456,9 +456,9 @@ void JSHClass::ReBuildFunctionInheritanceRelationship(const JSThread *thread, proto->GetTaggedObject()->SynchronizedTransitionClass(thread, JSHClass::Cast(transPhc->GetTaggedObject())); ASSERT(JSHClass::Cast(transPhc->GetTaggedObject())->IsPrototype()); // update the prototype of new phc - JSHClass::Cast(transPhc->GetTaggedObject())->SetPrototype(thread, oldPhc->GetPrototype()); + JSHClass::Cast(transPhc->GetTaggedObject())->SetPrototype(thread, oldPhc->GetPrototype(thread)); // enable prototype change marker - JSTaggedValue phcPrototype = JSHClass::Cast(transPhc->GetTaggedObject())->GetPrototype(); + JSTaggedValue phcPrototype = JSHClass::Cast(transPhc->GetTaggedObject())->GetPrototype(thread); JSHandle parentPrototype(thread, phcPrototype); ASSERT(parentPrototype->IsECMAObject()); JSHClass::EnablePHCProtoChangeMarker(thread, @@ -502,7 +502,7 @@ JSHandle JSHClass::TransProtoWithoutLayout(const JSThread *thread, con JSHandle key(thread->GlobalConstants()->GetHandledPrototypeString()); { - auto *newClass = jshclass->FindProtoTransitions(key.GetTaggedValue(), proto.GetTaggedValue()); + auto *newClass = jshclass->FindProtoTransitions(thread, key.GetTaggedValue(), proto.GetTaggedValue()); if (newClass != nullptr) { return JSHandle(thread, newClass); } @@ -597,7 +597,7 @@ void JSHClass::OptimizePrototypeForIC(const JSThread *thread, const JSHandleGetLayout(); + JSTaggedValue layout = newProtoClass->GetLayout(thread); // If the type of object is JSObject, the layout info value is initialized to the default value, // if the value is not JSObject, the layout info value is initialized to null. if (!layout.IsNull()) { @@ -655,14 +655,14 @@ void JSHClass::OptimizeAsFastProperties(const JSThread *thread, const JSHandle properties(thread, obj->GetProperties()); + JSHandle properties(thread, obj->GetProperties(thread)); int numberOfProperties = properties->EntriesCount(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle layoutInfoHandle = factory->CreateLayoutInfo(numberOfProperties); int numberOfInlinedProps = static_cast(newJsHClass->GetInlinedProperties()); for (int i = 0; i < numberOfProperties; i++) { - JSTaggedValue key = properties->GetKey(indexOrder[i]); - PropertyAttributes attributes = properties->GetAttributes(indexOrder[i]); + JSTaggedValue key = properties->GetKey(thread, indexOrder[i]); + PropertyAttributes attributes = properties->GetAttributes(thread, indexOrder[i]); if (i < numberOfInlinedProps) { attributes.SetIsInlinedProps(true); } else { @@ -700,7 +700,7 @@ void JSHClass::TransitionForRepChange(const JSThread *thread, const JSHandle newHClass = JSHClass::Clone(thread, oldHClass); RestoreElementsKindToGeneric(*newHClass); - JSHandle oldLayout(thread, newHClass->GetLayout()); + JSHandle oldLayout(thread, newHClass->GetLayout(thread)); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle newLayout(factory->CopyLayoutInfo(oldLayout)); newHClass->SetLayout(thread, newLayout); @@ -749,7 +749,7 @@ bool JSHClass::TransitToElementsKindUncheck(const JSThread *thread, const JSHand void JSHClass::TransitToElementsKind(const JSThread *thread, const JSHandle &array, ElementsKind newKind) { - JSTaggedValue elements = array->GetElements(); + JSTaggedValue elements = array->GetElements(thread); if (!elements.IsTaggedArray()) { return; } @@ -794,7 +794,7 @@ bool JSHClass::TransitToElementsKind(const JSThread *thread, const JSHandleIsPGOProfilerEnable()) { return true; } - JSTaggedValue trackInfoVal = JSHandle(object)->GetTrackInfo(); + JSTaggedValue trackInfoVal = JSHandle(object)->GetTrackInfo(thread); if (trackInfoVal.IsHeapObject() && trackInfoVal.IsWeak()) { TrackInfo *trackInfo = TrackInfo::Cast(trackInfoVal.GetWeakReferentUnChecked()); thread->GetEcmaVM()->GetPGOProfiler()->UpdateTrackInfo(JSTaggedValue(trackInfo)); @@ -802,14 +802,14 @@ bool JSHClass::TransitToElementsKind(const JSThread *thread, const JSHandleGetParent(); + parent = curHClass->GetParent(thread); } return curHClass; } -void JSHClass::VisitAndUpdateLayout(JSHClass *ownHClass, const PropertyAttributes &attr) +void JSHClass::VisitAndUpdateLayout(const JSThread *thread, JSHClass *ownHClass, const PropertyAttributes &attr) { uint32_t offset = attr.GetOffset(); auto targetTrackType = attr.GetTrackType(); @@ -835,12 +835,12 @@ void JSHClass::VisitAndUpdateLayout(JSHClass *ownHClass, const PropertyAttribute JSHClass *current = backHClass.front(); backHClass.pop(); - auto layout = LayoutInfo::Cast(current->GetLayout().GetTaggedObject()); - if (layout->GetAttr(offset).GetTrackType() != targetTrackType) { - layout->UpdateTrackTypeAttr(offset, attr); + auto layout = LayoutInfo::Cast(current->GetLayout(thread).GetTaggedObject()); + if (layout->GetAttr(thread, offset).GetTrackType() != targetTrackType) { + layout->UpdateTrackTypeAttr(thread, offset, attr); } - auto transitions = current->GetTransitions(); + auto transitions = current->GetTransitions(thread); if (transitions.IsUndefined()) { continue; } @@ -852,13 +852,13 @@ void JSHClass::VisitAndUpdateLayout(JSHClass *ownHClass, const PropertyAttribute ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - dict->IterateEntryValue([&backHClass] (JSHClass *cache) { + dict->IterateEntryValue(thread, [&backHClass] (JSHClass *cache) { backHClass.push(JSHClass::Cast(cache)); }); } } -void JSHClass::VisitTransitionAndUpdateObjSize(JSHClass *ownHClass, uint32_t finalInObjPropsNum) +void JSHClass::VisitTransitionAndUpdateObjSize(const JSThread *thread, JSHClass *ownHClass, uint32_t finalInObjPropsNum) { uint32_t size = ownHClass->GetInlinedPropsStartSize(); uint32_t objectSize = size + finalInObjPropsNum * JSTaggedValue::TaggedTypeSize(); @@ -868,7 +868,7 @@ void JSHClass::VisitTransitionAndUpdateObjSize(JSHClass *ownHClass, uint32_t fin JSHClass *current = backHClass.front(); backHClass.pop(); current->SetObjectSize(objectSize); - auto transitions = current->GetTransitions(); + auto transitions = current->GetTransitions(thread); if (transitions.IsUndefined()) { continue; } @@ -880,13 +880,13 @@ void JSHClass::VisitTransitionAndUpdateObjSize(JSHClass *ownHClass, uint32_t fin ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - dict->IterateEntryValue([&backHClass] (JSHClass *cache) { + dict->IterateEntryValue(thread, [&backHClass] (JSHClass *cache) { backHClass.push(JSHClass::Cast(cache)); }); } } -uint32_t JSHClass::VisitTransitionAndFindMaxNumOfProps(JSHClass *ownHClass) +uint32_t JSHClass::VisitTransitionAndFindMaxNumOfProps(const JSThread *thread, JSHClass *ownHClass) { std::queue backHClass; backHClass.push(ownHClass); @@ -899,7 +899,7 @@ uint32_t JSHClass::VisitTransitionAndFindMaxNumOfProps(JSHClass *ownHClass) } backHClass.pop(); - auto transitions = current->GetTransitions(); + auto transitions = current->GetTransitions(thread); if (transitions.IsUndefined()) { continue; } @@ -911,7 +911,7 @@ uint32_t JSHClass::VisitTransitionAndFindMaxNumOfProps(JSHClass *ownHClass) ASSERT(transitions.IsTaggedArray()); TransitionsDictionary *dict = TransitionsDictionary::Cast(transitions.GetTaggedObject()); - dict->IterateEntryValue([&backHClass] (JSHClass *cache) { + dict->IterateEntryValue(thread, [&backHClass] (JSHClass *cache) { backHClass.push(JSHClass::Cast(cache)); }); } @@ -923,10 +923,10 @@ TransitionResult JSHClass::ConvertOrTransitionWithRep(const JSThread *thread, PropertyAttributes &attr) { auto hclass = receiver->GetJSHClass(); - auto layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - attr = layout->GetAttr(attr.GetOffset()); + auto layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + attr = layout->GetAttr(thread, attr.GetOffset()); if (thread->IsPGOProfilerEnable() && !hclass->IsJSShared() && attr.UpdateTrackType(value.GetTaggedValue())) { - UpdateFieldType(hclass, attr); + UpdateFieldType(thread, hclass, attr); } Representation oldRep = attr.GetRepresentation(); @@ -959,12 +959,12 @@ TransitionResult JSHClass::ConvertOrTransitionWithRep(const JSThread *thread, void JSHClass::MergeRepresentation(const JSThread *thread, JSHClass *oldJsHClass, JSHClass *newJsHClass) { - JSHandle oldLayout(thread, oldJsHClass->GetLayout()); - JSHandle newLayout(thread, newJsHClass->GetLayout()); + JSHandle oldLayout(thread, oldJsHClass->GetLayout(thread)); + JSHandle newLayout(thread, newJsHClass->GetLayout(thread)); int numberOfProps = static_cast(oldJsHClass->NumberOfProps()); for (int i = 0; i < numberOfProps; i++) { - PropertyAttributes oldAttr = oldLayout->GetAttr(i); - PropertyAttributes newAttr = newLayout->GetAttr(i); + PropertyAttributes oldAttr = oldLayout->GetAttr(thread, i); + PropertyAttributes newAttr = newLayout->GetAttr(thread, i); ASSERT(oldAttr.IsInlinedProps()); if (oldAttr.GetRepresentation() == newAttr.GetRepresentation()) { continue; @@ -980,7 +980,7 @@ void JSHClass::NotifyLeafHClassChanged(JSThread *thread, const JSHandleSetIsStable(false); - JSTaggedValue infos = jsHClass->GetDependentInfos(); + JSTaggedValue infos = jsHClass->GetDependentInfos(thread); if (!infos.IsHeapObject()) { return; } @@ -991,7 +991,7 @@ void JSHClass::NotifyLeafHClassChanged(JSThread *thread, const JSHandle JSHClass::EnableProtoChangeMarker(const JSThread *thread, const JSHandle &jshclass) { - JSTaggedValue proto = jshclass->GetPrototype(); + JSTaggedValue proto = jshclass->GetPrototype(thread); if (!proto.IsECMAObject()) { // Return JSTaggedValue directly. No proto check is needed. LOG_ECMA(INFO) << "proto is not ecmaobject: " << proto.GetRawData(); @@ -1005,7 +1005,7 @@ JSHandle JSHClass::EnableProtoChangeMarker(const JSThread *thread // PHC's Listener to ensure that it can be notified. RegisterOnProtoChain(thread, protoClass); - JSTaggedValue protoChangeMarker = protoClass->GetProtoChangeMarker(); + JSTaggedValue protoChangeMarker = protoClass->GetProtoChangeMarker(thread); if (protoChangeMarker.IsProtoChangeMarker()) { JSHandle markerHandle(thread, ProtoChangeMarker::Cast(protoChangeMarker.GetTaggedObject())); if (!markerHandle->GetHasChanged()) { @@ -1027,7 +1027,7 @@ JSHandle JSHClass::EnablePHCProtoChangeMarker(const JSThread *thr { RegisterOnProtoChain(thread, protoClass); - JSTaggedValue protoChangeMarker = protoClass->GetProtoChangeMarker(); + JSTaggedValue protoChangeMarker = protoClass->GetProtoChangeMarker(thread); if (protoChangeMarker.IsProtoChangeMarker()) { JSHandle markerHandle(thread, ProtoChangeMarker::Cast(protoChangeMarker.GetTaggedObject())); if (!markerHandle->GetHasChanged()) { @@ -1105,26 +1105,26 @@ void JSHClass::NotifyAccessorChanged(const JSThread *thread, JSHandle void JSHClass::NotifyAccessorChangedThroughChain(const JSThread *thread, JSHandle hclass) { DISALLOW_GARBAGE_COLLECTION; - JSTaggedValue markerValue = hclass->GetProtoChangeMarker(); + JSTaggedValue markerValue = hclass->GetProtoChangeMarker(thread); if (markerValue.IsProtoChangeMarker()) { ProtoChangeMarker *protoChangeMarker = ProtoChangeMarker::Cast(markerValue.GetTaggedObject()); protoChangeMarker->SetAccessorHasChanged(true); } - JSTaggedValue protoDetailsValue = hclass->GetProtoChangeDetails(); + JSTaggedValue protoDetailsValue = hclass->GetProtoChangeDetails(thread); if (!protoDetailsValue.IsProtoChangeDetails()) { return; } - JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(thread); if (!listenersValue.IsTaggedArray()) { return; } ChangeListener *listeners = ChangeListener::Cast(listenersValue.GetTaggedObject()); JSMutableHandle hclassTemp(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < listeners->GetEnd(); i++) { - JSTaggedValue temp = listeners->Get(i); + JSTaggedValue temp = listeners->Get(thread, i); if (temp.IsJSHClass()) { - hclassTemp.Update(listeners->Get(i)); + hclassTemp.Update(listeners->Get(thread, i)); NotifyAccessorChangedThroughChain(thread, hclassTemp); } } @@ -1145,7 +1145,7 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandleGetPrototype(); + JSTaggedValue proto = user->GetPrototype(thread); if (!proto.IsHeapObject()) { return; } @@ -1160,7 +1160,7 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandle protoHandle(thread, proto); JSHandle protoDetails = GetProtoChangeDetails(thread, JSHandle(thread, protoHandle->GetJSHClass())); - JSTaggedValue listeners = protoDetails->GetChangeListener(); + JSTaggedValue listeners = protoDetails->GetChangeListener(thread); JSHandle listenersHandle; if (listeners.IsUndefined()) { listenersHandle = JSHandle(ChangeListener::Create(thread)); @@ -1179,12 +1179,12 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandle &jshclass) { ASSERT(jshclass->IsPrototype()); - if (!jshclass->GetProtoChangeDetails().IsProtoChangeDetails()) { + if (!jshclass->GetProtoChangeDetails(thread).IsProtoChangeDetails()) { return false; } - if (!jshclass->GetPrototype().IsECMAObject()) { + if (!jshclass->GetPrototype(thread).IsECMAObject()) { JSTaggedValue listeners = - ProtoChangeDetails::Cast(jshclass->GetProtoChangeDetails().GetTaggedObject())->GetChangeListener(); + ProtoChangeDetails::Cast(jshclass->GetProtoChangeDetails(thread).GetTaggedObject())->GetChangeListener(thread); return !listeners.IsUndefined(); } JSHandle currentDetails = GetProtoChangeDetails(thread, jshclass); @@ -1192,24 +1192,24 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandle(ProtoChangeDetails::UNREGISTERED)) { return false; } - JSTaggedValue proto = jshclass->GetPrototype(); + JSTaggedValue proto = jshclass->GetPrototype(thread); ASSERT(proto.IsECMAObject()); - JSTaggedValue protoDetailsValue = JSObject::Cast(proto.GetTaggedObject())->GetJSHClass()->GetProtoChangeDetails(); + JSTaggedValue protoDetailsValue = JSObject::Cast(proto.GetTaggedObject())->GetJSHClass()->GetProtoChangeDetails(thread); if (protoDetailsValue.IsUndefined() || protoDetailsValue.IsNull()) { return false; } ASSERT(protoDetailsValue.IsProtoChangeDetails()); - JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetailsValue.GetTaggedObject())->GetChangeListener(thread); ASSERT(!listenersValue.IsUndefined()); JSHandle listeners(thread, listenersValue.GetTaggedObject()); - ASSERT(listeners->Get(index) == jshclass.GetTaggedValue()); + ASSERT(listeners->Get(thread, index) == jshclass.GetTaggedValue()); listeners->Delete(thread, index); return true; } JSHandle JSHClass::GetProtoChangeDetails(const JSThread *thread, const JSHandle &jshclass) { - JSTaggedValue protoDetails = jshclass->GetProtoChangeDetails(); + JSTaggedValue protoDetails = jshclass->GetProtoChangeDetails(thread); if (protoDetails.IsProtoChangeDetails()) { return JSHandle(thread, protoDetails); } @@ -1226,7 +1226,7 @@ JSHandle JSHClass::GetProtoChangeDetails(const JSThread *thr JSHandle JSHClass::GetEnumCacheOwnWithOutCheck(const JSThread *thread, const JSHandle &jshclass) { - return JSHandle(thread, EnumCache::Cast(jshclass->GetEnumCache())->GetEnumCacheOwn()); + return JSHandle(thread, EnumCache::Cast(jshclass->GetEnumCache(thread))->GetEnumCacheOwn(thread)); } void JSHClass::RefreshUsers(const JSThread *thread, const JSHandle &oldHclass, @@ -1237,14 +1237,14 @@ void JSHClass::RefreshUsers(const JSThread *thread, const JSHandle &ol bool onceRegistered = UnregisterOnProtoChain(thread, oldHclass); // oldHclass is already marked. Only update newHclass.protoChangeDetails if it doesn't exist for further use. - if (!newHclass->GetProtoChangeDetails().IsProtoChangeDetails()) { - newHclass->SetProtoChangeDetails(thread, oldHclass->GetProtoChangeDetails()); + if (!newHclass->GetProtoChangeDetails(thread).IsProtoChangeDetails()) { + newHclass->SetProtoChangeDetails(thread, oldHclass->GetProtoChangeDetails(thread)); } if (onceRegistered) { - ProtoChangeDetails::Cast(oldHclass->GetProtoChangeDetails().GetTaggedObject()) + ProtoChangeDetails::Cast(oldHclass->GetProtoChangeDetails(thread).GetTaggedObject()) ->SetRegisterIndex(ProtoChangeDetails::UNREGISTERED); - if (newHclass->GetProtoChangeDetails().IsProtoChangeDetails()) { - ProtoChangeDetails::Cast(newHclass->GetProtoChangeDetails().GetTaggedObject()) + if (newHclass->GetProtoChangeDetails(thread).IsProtoChangeDetails()) { + ProtoChangeDetails::Cast(newHclass->GetProtoChangeDetails(thread).GetTaggedObject()) ->SetRegisterIndex(ProtoChangeDetails::UNREGISTERED); } RegisterOnProtoChain(thread, newHclass); @@ -1268,7 +1268,7 @@ PropertyLookupResult JSHClass::LookupPropertyInAotHClass(const JSThread *thread, if (entry != -1) { result.SetIsFound(true); result.SetIsLocal(true); - PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject())->GetAttr(entry); + PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject())->GetAttr(thread, entry); if (attr.IsInlinedProps()) { result.SetIsInlinedProps(true); result.SetOffset(hclass->GetInlinedPropertiesOffset(entry)); @@ -1307,7 +1307,7 @@ PropertyLookupResult JSHClass::LookupPropertyInPGOHClass(const JSThread *thread, if (entry != -1) { result.SetIsFound(true); result.SetIsLocal(true); - PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject())->GetAttr(entry); + PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject())->GetAttr(thread, entry); if (attr.IsInlinedProps()) { result.SetIsInlinedProps(true); result.SetOffset(hclass->GetInlinedPropertiesOffset(entry)); @@ -1355,7 +1355,7 @@ PropertyLookupResult JSHClass::LookupPropertyInBuiltinPrototypeHClass(const JSTh result.SetIsFound(true); result.SetIsLocal(true); - PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject())->GetAttr(entry); + PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject())->GetAttr(thread, entry); if (attr.IsInlinedProps()) { result.SetIsInlinedProps(true); result.SetOffset(hclass->GetInlinedPropertiesOffset(entry)); @@ -1477,7 +1477,7 @@ JSHandle JSHClass::CreateChildHClassFromPGO(const JSThread* thread, ASSERT(newJsHClass->GetInlinedProperties() >= (numOfProps + 1)); uint32_t offset = numOfProps; { - JSMutableHandle layoutInfoHandle(thread, newJsHClass->GetLayout()); + JSMutableHandle layoutInfoHandle(thread, newJsHClass->GetLayout(thread)); if (layoutInfoHandle->NumberOfElements() != static_cast(offset)) { layoutInfoHandle.Update(factory->CopyAndReSort(layoutInfoHandle, offset, offset + 1)); newJsHClass->SetLayout(thread, layoutInfoHandle); @@ -1502,22 +1502,22 @@ JSHandle JSHClass::CreateChildHClassFromPGO(const JSThread* thread, return newJsHClass; } -bool JSHClass::DumpRootHClassByPGO(const JSHClass* hclass, HClassLayoutDesc* desc) +bool JSHClass::DumpRootHClassByPGO(const JSThread *thread, const JSHClass* hclass, HClassLayoutDesc* desc) { DISALLOW_GARBAGE_COLLECTION; if (hclass->IsDictionaryMode()) { return false; } - LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); int element = static_cast(hclass->NumberOfProps()); for (int i = 0; i < element; i++) { - layout->DumpFieldIndexByPGO(i, desc); + layout->DumpFieldIndexByPGO(thread, i, desc); } return true; } -bool JSHClass::DumpChildHClassByPGO(const JSHClass* hclass, HClassLayoutDesc* desc) +bool JSHClass::DumpChildHClassByPGO(const JSThread *thread, const JSHClass* hclass, HClassLayoutDesc* desc) { DISALLOW_GARBAGE_COLLECTION; if (hclass->IsDictionaryMode()) { @@ -1527,12 +1527,12 @@ bool JSHClass::DumpChildHClassByPGO(const JSHClass* hclass, HClassLayoutDesc* de return false; } uint32_t last = hclass->LastPropIndex(); - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - layoutInfo->DumpFieldIndexByPGO(last, desc); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + layoutInfo->DumpFieldIndexByPGO(thread, last, desc); return true; } -bool JSHClass::UpdateChildLayoutDescByPGO(const JSHClass* hclass, HClassLayoutDesc* childDesc) +bool JSHClass::UpdateChildLayoutDescByPGO(const JSThread* thread, const JSHClass* hclass, HClassLayoutDesc* childDesc) { DISALLOW_GARBAGE_COLLECTION; if (hclass->IsDictionaryMode()) { @@ -1542,11 +1542,11 @@ bool JSHClass::UpdateChildLayoutDescByPGO(const JSHClass* hclass, HClassLayoutDe return false; } uint32_t last = hclass->LastPropIndex(); - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - return layoutInfo->UpdateFieldIndexByPGO(last, childDesc); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + return layoutInfo->UpdateFieldIndexByPGO(thread, last, childDesc); } -bool JSHClass::UpdateRootLayoutDescByPGO(const JSHClass* hclass, HClassLayoutDesc* desc) +bool JSHClass::UpdateRootLayoutDescByPGO(const JSThread* thread, const JSHClass* hclass, HClassLayoutDesc* desc) { DISALLOW_GARBAGE_COLLECTION; if (hclass->IsDictionaryMode()) { @@ -1555,14 +1555,14 @@ bool JSHClass::UpdateRootLayoutDescByPGO(const JSHClass* hclass, HClassLayoutDes auto rootDesc = reinterpret_cast(desc); int rootPropLen = static_cast(rootDesc->NumOfProps()); - LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); for (int i = 0; i < rootPropLen; i++) { - layout->UpdateFieldIndexByPGO(i, desc); + layout->UpdateFieldIndexByPGO(thread, i, desc); } return true; } -std::pair JSHClass::DumpToString(JSTaggedType hclassVal) +std::pair JSHClass::DumpToString(const JSThread *thread, JSTaggedType hclassVal) { DISALLOW_GARBAGE_COLLECTION; auto hclass = JSHClass::Cast(JSTaggedValue(hclassVal).GetTaggedObject()); @@ -1572,14 +1572,14 @@ std::pair JSHClass::DumpToString(JSTaggedType hclassVal) } CString result; - LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); int element = static_cast(hclass->NumberOfProps()); for (int i = 0; i < element; i++) { - auto key = layout->GetKey(i); + auto key = layout->GetKey(thread, i); if (key.IsString()) { - uint64_t value = EcmaStringAccessor(key).GetHashcode(); + uint64_t value = EcmaStringAccessor(key).GetHashcode(thread); value <<= sizeof(uint32_t) * BITS_PER_BYTE; - auto attr = layout->GetAttr(i); + auto attr = layout->GetAttr(thread, i); auto defaultAttr = PropertyAttributes(attr.GetPropertyMetaData()); defaultAttr.SetTrackType(attr.GetTrackType()); value += defaultAttr.GetValue(); @@ -1588,7 +1588,7 @@ std::pair JSHClass::DumpToString(JSTaggedType hclassVal) auto symbol = JSSymbol::Cast(key); if (symbol->HasId()) { result += JSSymbol::Cast(key)->GetPrivateId(); - auto attr = layout->GetAttr(i); + auto attr = layout->GetAttr(thread, i); result += static_cast(attr.GetTrackType()); result += attr.GetPropertyMetaData(); } else { @@ -1619,7 +1619,7 @@ PropertyLookupResult JSHClass::LookupPropertyInBuiltinHClass(const JSThread *thr if (entry != -1) { result.SetIsFound(true); result.SetIsLocal(true); - PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject())->GetAttr(entry); + PropertyAttributes attr = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject())->GetAttr(thread, entry); if (attr.IsInlinedProps()) { result.SetIsInlinedProps(true); result.SetOffset(hclass->GetInlinedPropertiesOffset(entry)); @@ -1657,7 +1657,7 @@ JSHandle JSHClass::CreateSHClass(JSThread *thread, if (parentHClass) { if (parentHClass->IsDictionaryMode()) { - auto dict = reinterpret_cast(parentHClass->GetLayout().GetTaggedObject()); + auto dict = reinterpret_cast(parentHClass->GetLayout(thread).GetTaggedObject()); length += static_cast(dict->EntriesCount()); } else { length += parentHClass->NumberOfProps(); @@ -1724,16 +1724,16 @@ void JSHClass::CreateSInlinedLayout(JSThread *thread, auto index = length; if (parentHClass) { - JSHandle old(thread, parentHClass->GetLayout()); + JSHandle old(thread, parentHClass->GetLayout(thread)); for (uint32_t i = 0; i < parentLength; i++) { - key.Update(old->GetKey(i)); + key.Update(old->GetKey(thread, i)); auto entry = layout->FindElementWithCache(thread, *hclass, key.GetTaggedValue(), index); if (entry != -1) { continue; } - auto attr = PropertyAttributes(old->GetAttr(i)); + auto attr = PropertyAttributes(old->GetAttr(thread, i)); attr.SetOffset(index); - layout->AddKey(thread, index, old->GetKey(i), attr); + layout->AddKey(thread, index, old->GetKey(thread, i), attr); ++index; } } @@ -1756,7 +1756,7 @@ void JSHClass::CreateSDictLayout(JSThread *thread, if (parentHClass) { if (parentHClass->IsDictionaryMode()) { parentLength = static_cast( - reinterpret_cast(parentHClass->GetLayout().GetTaggedObject())->EntriesCount()); + reinterpret_cast(parentHClass->GetLayout(thread).GetTaggedObject())->EntriesCount()); } else { parentLength = parentHClass->NumberOfProps(); } @@ -1781,20 +1781,20 @@ void JSHClass::CreateSDictLayout(JSThread *thread, if (parentHClass) { if (parentHClass->IsDictionaryMode()) { - JSHandle old(thread, parentHClass->GetLayout()); - std::vector indexOrder = old->GetEnumerationOrder(); + JSHandle old(thread, parentHClass->GetLayout(thread)); + std::vector indexOrder = old->GetEnumerationOrder(thread); for (uint32_t i = 0; i < parentLength; i++) { - key.Update(old->GetKey(indexOrder[i])); + key.Update(old->GetKey(thread, indexOrder[i])); JSHandle newDict = NameDictionary::Put( - thread, dict, key, value, PropertyAttributes(old->GetAttributes(indexOrder[i]))); + thread, dict, key, value, PropertyAttributes(old->GetAttributes(thread, indexOrder[i]))); dict.Update(newDict); } } else { - JSHandle old(thread, parentHClass->GetLayout()); + JSHandle old(thread, parentHClass->GetLayout(thread)); for (uint32_t i = 0; i < parentLength; i++) { - key.Update(old->GetKey(i)); + key.Update(old->GetKey(thread, i)); JSHandle newDict = - NameDictionary::Put(thread, dict, key, value, PropertyAttributes(old->GetAttr(i))); + NameDictionary::Put(thread, dict, key, value, PropertyAttributes(old->GetAttr(thread, i))); dict.Update(newDict); } } @@ -1808,13 +1808,13 @@ void JSHClass::CreateSDictLayout(JSThread *thread, bool JSHClass::IsNeedNotifyHclassChangedForAotTransition(const JSThread *thread, const JSHandle &hclass, JSTaggedValue key) { - JSMutableHandle protoHandle(thread, hclass->GetPrototype()); + JSMutableHandle protoHandle(thread, hclass->GetPrototype(thread)); while (protoHandle.GetTaggedValue().IsHeapObject()) { JSHClass *protoHclass = protoHandle->GetJSHClass(); if (JSHClass::FindPropertyEntry(thread, protoHclass, key) != -1) { return true; } - protoHandle.Update(protoHclass->GetPrototype()); + protoHandle.Update(protoHclass->GetPrototype(thread)); } return false; } diff --git a/ecmascript/js_hclass.h b/ecmascript/js_hclass.h index d59d760c7b..ac3f4adf5e 100644 --- a/ecmascript/js_hclass.h +++ b/ecmascript/js_hclass.h @@ -482,11 +482,12 @@ public: PropertyAttributes &attr); static void PUBLIC_API MergeRepresentation(const JSThread *thread, JSHClass *oldJsHClass, JSHClass *newJsHClass); - static void UpdateFieldType(JSHClass *hclass, const PropertyAttributes &attr); - static JSHClass *FindFieldOwnHClass(JSHClass *hclass, const PropertyAttributes &attr); - static void VisitAndUpdateLayout(JSHClass *ownHClass, const PropertyAttributes &attr); - static void VisitTransitionAndUpdateObjSize(JSHClass *ownHClass, uint32_t finalInObjPropsNum); - static uint32_t VisitTransitionAndFindMaxNumOfProps(JSHClass *ownHClass); + static void UpdateFieldType(const JSThread *thread, JSHClass *hclass, const PropertyAttributes &attr); + static JSHClass *FindFieldOwnHClass(const JSThread *thread, JSHClass *hclass, const PropertyAttributes &attr); + static void VisitAndUpdateLayout(const JSThread *thread, JSHClass *ownHClass, const PropertyAttributes &attr); + static void VisitTransitionAndUpdateObjSize(const JSThread *thread, JSHClass *ownHClass, + uint32_t finalInObjPropsNum); + static uint32_t VisitTransitionAndFindMaxNumOfProps(const JSThread *thread, JSHClass *ownHClass); static void NotifyLeafHClassChanged(JSThread *thread, const JSHandle &jsHClass); static JSHandle PUBLIC_API EnableProtoChangeMarker( @@ -788,9 +789,9 @@ public: return (IsSpecialContainer() || IsModuleNamespace() || IsBigInt64Array()); } - inline bool HasDependentInfos() const + inline bool HasDependentInfos(const JSThread *thread) const { - return GetDependentInfos() != JSTaggedValue::Undefined(); + return GetDependentInfos(thread) != JSTaggedValue::Undefined(); } inline bool IsJSTypedArray() const @@ -2047,13 +2048,13 @@ public: SetConstructionCounter(SLACK_TRACKING_COUNT); } - inline void CompleteObjSizeTracking(); + inline void CompleteObjSizeTracking(const JSThread *thread); - inline void ObjSizeTrackingStep(); + inline void ObjSizeTrackingStep(const JSThread *thread); - inline static JSHClass *FindRootHClass(JSHClass *hclass); - inline static JSTaggedValue FindProtoHClass(JSHClass *hclass); - inline static JSTaggedValue FindProtoRootHClass(JSHClass *hclass); + inline static JSHClass *FindRootHClass(const JSThread *thread, JSHClass *hclass); + inline static JSTaggedValue FindProtoHClass(const JSThread *thread, JSHClass *hclass); + inline static JSTaggedValue FindProtoRootHClass(const JSThread *thread, JSHClass *hclass); inline static void UpdateRootHClass(const JSThread *thread, const JSHandle &parent, const JSHandle &child); @@ -2098,15 +2099,16 @@ public: static void OptimizePrototypeForIC(const JSThread *thread, const JSHandle &env, const JSHandle &proto, bool isChangeProto = false); - inline JSTaggedValue GetPrototype() const + inline JSTaggedValue GetPrototype(const JSThread *thread) const { - return GetProto(); + return GetProto(thread); } - inline JSHClass *FindTransitions(const JSTaggedValue &key, + inline JSHClass *FindTransitions(const JSThread *thread, + const JSTaggedValue &key, const JSTaggedValue &metaData, const Representation &rep); - inline JSHClass *CheckHClassForRep(JSHClass *hclass, const Representation &rep); + inline JSHClass *CheckHClassForRep(const JSThread *thread, JSHClass *hclass, const Representation &rep); DECL_DUMP() @@ -2122,17 +2124,18 @@ public: static JSHandle CreateChildHClassFromPGO(const JSThread* thread, const JSHandle& parent, const HClassLayoutDesc* desc); - static bool DumpRootHClassByPGO(const JSHClass* hclass, HClassLayoutDesc* desc); - static bool DumpChildHClassByPGO(const JSHClass* hclass, HClassLayoutDesc* desc); - static bool UpdateRootLayoutDescByPGO(const JSHClass* hclass, HClassLayoutDesc* rootDesc); - static bool UpdateChildLayoutDescByPGO(const JSHClass* hclass, HClassLayoutDesc* childDesc); - static std::pair DumpToString(JSTaggedType hclassVal); + static bool DumpRootHClassByPGO(const JSThread *thread, const JSHClass* hclass, HClassLayoutDesc* desc); + static bool DumpChildHClassByPGO(const JSThread *thread, const JSHClass* hclass, HClassLayoutDesc* desc); + static bool UpdateRootLayoutDescByPGO(const JSThread* thread, const JSHClass* hclass, HClassLayoutDesc* rootDesc); + static bool UpdateChildLayoutDescByPGO(const JSThread* thread, const JSHClass* hclass, HClassLayoutDesc* childDesc); + static std::pair DumpToString(const JSThread *thread, JSTaggedType hclassVal); DECL_VISIT_OBJECT(PROTOTYPE_OFFSET, PROFILE_TYPE_OFFSET); - inline JSHClass *FindProtoTransitions(const JSTaggedValue &key, const JSTaggedValue &proto); - inline bool HasTransitions() const + inline JSHClass *FindProtoTransitions(const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &proto); + inline bool HasTransitions(const JSThread *thread) const { - return !GetTransitions().IsUndefined(); + return !GetTransitions(thread).IsUndefined(); } static JSHandle CreateSHClass(JSThread *thread, diff --git a/ecmascript/js_iterator.cpp b/ecmascript/js_iterator.cpp index 5cf7aa7ae8..1f37e82fd5 100644 --- a/ecmascript/js_iterator.cpp +++ b/ecmascript/js_iterator.cpp @@ -30,7 +30,7 @@ JSTaggedValue JSIterator::IteratorCloseAndReturn(JSThread *thread, const JSHandl JSHandle result = JSIterator::IteratorClose(thread, iter, record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (result->IsCompletionRecord()) { - return CompletionRecord::Cast(result->GetTaggedObject())->GetValue(); + return CompletionRecord::Cast(result->GetTaggedObject())->GetValue(thread); } return result.GetTaggedValue(); } @@ -156,8 +156,8 @@ JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandl { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 2.Let result be Invoke(iterator, "next", «‍value»). - JSHandle iterator(thread, iter->GetIterator()); - JSHandle next(thread, iter->GetNextMethod()); + JSHandle iterator(thread, iter->GetIterator(thread)); + JSHandle next(thread, iter->GetNextMethod(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iterator, undefined, 1); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, undefined); @@ -177,8 +177,8 @@ JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandl { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 2.Let result be Invoke(iterator, "next", «‍value»). - JSHandle iterator(thread, iter->GetIterator()); - JSHandle next(thread, iter->GetNextMethod()); + JSHandle iterator(thread, iter->GetIterator(thread)); + JSHandle next(thread, iter->GetNextMethod(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iterator, undefined, 0); JSTaggedValue ret = JSFunction::Call(info); diff --git a/ecmascript/js_list_format.cpp b/ecmascript/js_list_format.cpp index c830e1f795..17a2a8ca70 100644 --- a/ecmascript/js_list_format.cpp +++ b/ecmascript/js_list_format.cpp @@ -23,10 +23,10 @@ namespace panda::ecmascript { -icu::ListFormatter *JSListFormat::GetIcuListFormatter() const +icu::ListFormatter *JSListFormat::GetIcuListFormatter(JSThread *thread) const { - ASSERT(GetIcuLF().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuLF().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuLF(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuLF(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -46,7 +46,7 @@ void JSListFormat::SetIcuListFormatter(JSThread *thread, const JSHandleGetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory(); ASSERT(icuListFormatter != nullptr); - JSTaggedValue data = listFormat->GetIcuLF(); + JSTaggedValue data = listFormat->GetIcuLF(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuListFormatter); @@ -260,7 +260,7 @@ namespace { JSHandle kValue = JSArray::FastGetPropertyByValue(thread, listArray, k); ASSERT(kValue->IsString()); JSHandle kValueString = JSTaggedValue::ToString(thread, kValue); - std::string stdString = intl::LocaleHelper::ConvertToStdString(kValueString); + std::string stdString = intl::LocaleHelper::ConvertToStdString(thread, kValueString); icu::StringPiece sp(stdString); icu::UnicodeString uString = icu::UnicodeString::fromUTF8(sp); result.push_back(uString); @@ -271,7 +271,7 @@ namespace { icu::FormattedList GetIcuFormatted(JSThread *thread, const JSHandle &listFormat, const JSHandle &listArray) { - icu::ListFormatter *icuListFormat = listFormat->GetIcuListFormatter(); + icu::ListFormatter *icuListFormat = listFormat->GetIcuListFormatter(thread); ASSERT(icuListFormat != nullptr); std::vector usArray = ToUnicodeStringArray(thread, listArray); UErrorCode status = U_ZERO_ERROR; @@ -399,7 +399,7 @@ void JSListFormat::ResolvedOptions(JSThread *thread, const JSHandle propertyKey = globalConst->GetHandledLocaleString(); - JSHandle locale(thread, listFormat->GetLocale()); + JSHandle locale(thread, listFormat->GetLocale(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale); RETURN_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/js_list_format.h b/ecmascript/js_list_format.h index dc6e1210d3..806b70ef1d 100644 --- a/ecmascript/js_list_format.h +++ b/ecmascript/js_list_format.h @@ -59,7 +59,7 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() - icu::ListFormatter *GetIcuListFormatter() const; + icu::ListFormatter *GetIcuListFormatter(JSThread *thread) const; static void FreeIcuListFormatter(void *env, void *pointer, [[maybe_unused]] void* hint); diff --git a/ecmascript/js_locale.cpp b/ecmascript/js_locale.cpp index b395f00339..3d7d028c0b 100644 --- a/ecmascript/js_locale.cpp +++ b/ecmascript/js_locale.cpp @@ -82,7 +82,7 @@ JSHandle JSLocale::LookupMatcher(JSThread *thread, const JSHandleGet(thread, i)); // 2. a. Let noExtensionsLocale be the String value that is locale // with all Unicode locale extension sequences removed. - intl::LocaleHelper::ParsedLocale parsedResult = intl::LocaleHelper::HandleLocale(locale); + intl::LocaleHelper::ParsedLocale parsedResult = intl::LocaleHelper::HandleLocale(thread, locale); // 2. b. Let availableLocale be BestAvailableLocale(availableLocales, noExtensionsLocale). std::string availableLocale = intl::LocaleHelper::BestAvailableLocale(availableStringLocales, parsedResult.base); @@ -125,7 +125,7 @@ icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, uint32_t *availableLengt JSMutableHandle item(thread, JSTaggedValue::Undefined()); for (*availableLength = 0; *availableLength < length; ++(*availableLength)) { item.Update(availableLocales->Get(thread, *availableLength)); - std::string itemStr = intl::LocaleHelper::ConvertToStdString(item); + std::string itemStr = intl::LocaleHelper::ConvertToStdString(thread, item); icu::Locale localeForLanguageTag = icu::Locale::forLanguageTag(itemStr, *status); if (U_SUCCESS(*status) != 0) { builder.addSupportedLocale(localeForLanguageTag); @@ -148,7 +148,7 @@ JSHandle JSLocale::BestFitMatcher(JSThread *thread, const JSHandleGetLength(); - JSIntlIterator iter(requestedLocales, requestedLocalesLength); + JSIntlIterator iter(thread, requestedLocales, requestedLocalesLength); auto bestFit = matcher.getBestMatch(iter, status)->toLanguageTag(status); if (U_FAILURE(status) != 0) { @@ -177,7 +177,7 @@ JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const J indexAvailableLocales.reserve(length); for (uint32_t i = 0; i < length; ++i) { item.Update(requestedLocales->Get(thread, i)); - convertedLocales.push_back(intl::LocaleHelper::ConvertToStdString(item)); + convertedLocales.push_back(intl::LocaleHelper::ConvertToStdString(thread, item)); } // 1. For each element locale of requestedLocales in List order, do // a. Let noExtensionsLocale be the String value that is locale with all Unicode locale extension sequences @@ -227,7 +227,7 @@ JSHandle JSLocale::BestFitSupportedLocales(JSThread *thread, const result->Set(thread, index++, locale.GetTaggedValue()); } else { status = U_ZERO_ERROR; - std::string localeStr = intl::LocaleHelper::ConvertToStdString(locale); + std::string localeStr = intl::LocaleHelper::ConvertToStdString(thread, locale); icu::Locale desired = icu::Locale::forLanguageTag(localeStr, status); auto bestFit = matcher.getBestMatch(desired, status)->toLanguageTag(status); if ((U_SUCCESS(status) != 0) && @@ -308,7 +308,7 @@ JSHandle JSLocale::GetOption(JSThread *thread, const JSHandle valuesArray = JSHandle::Cast(values); uint32_t length = valuesArray->GetLength(); for (uint32_t i = 0; i < length; i++) { - if (JSTaggedValue::SameValue(valuesArray->Get(thread, i), value.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, valuesArray->Get(thread, i), value.GetTaggedValue())) { isExist = true; } } @@ -343,7 +343,7 @@ bool JSLocale::GetOptionOfString(JSThread *thread, const JSHandle &opt if (EcmaStringAccessor(valueEStr).IsUtf16()) { THROW_RANGE_ERROR_AND_RETURN(thread, "Value out of range for locale options property", false); } - *optionValue = intl::LocaleHelper::ConvertToStdString(valueEStr); + *optionValue = intl::LocaleHelper::ConvertToStdString(thread, valueEStr); if (values.empty()) { return true; } @@ -481,12 +481,12 @@ ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle tag = intl::LocaleHelper::ToLanguageTag(thread, foundLocaleData); - result.locale = intl::LocaleHelper::ConvertToStdString(tag); + result.locale = intl::LocaleHelper::ConvertToStdString(thread, tag); std::string supportedExtension = "-u"; icu::LocaleBuilder localeBuilder; localeBuilder.setLocale(foundLocaleData).clearExtensions(); @@ -597,12 +597,12 @@ ResolvedLocale JSLocale::ResolveLocale(JSThread *thread, const JSHandle &t return false; } // 2. If intl::LocaleHelper::IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception. - if (!intl::LocaleHelper::IsStructurallyValidLanguageTag(tag)) { + if (!intl::LocaleHelper::IsStructurallyValidLanguageTag(thread, tag)) { return false; } @@ -787,7 +787,7 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t // a. If language does not match the unicode_language_subtag production, throw a RangeError exception. if (!tagElements.language->IsUndefined()) { std::string languageStr = - intl::LocaleHelper::ConvertToStdString(JSHandle::Cast(tagElements.language)); + intl::LocaleHelper::ConvertToStdString(thread, JSHandle::Cast(tagElements.language)); if (languageStr[INTL_INDEX_ZERO] == '\0' || IsAlpha(languageStr, INTL_INDEX_FOUR, INTL_INDEX_FOUR)) { return false; @@ -804,7 +804,7 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t // a. If script does not match the unicode_script_subtag production, throw a RangeError exception. if (!tagElements.script->IsUndefined()) { std::string scriptStr = - intl::LocaleHelper::ConvertToStdString((JSHandle::Cast(tagElements.script))); + intl::LocaleHelper::ConvertToStdString(thread, (JSHandle::Cast(tagElements.script))); if (scriptStr[INTL_INDEX_ZERO] == '\0') { return false; } @@ -819,7 +819,7 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (!tagElements.region->IsUndefined()) { - std::string regionStr = intl::LocaleHelper::ConvertToStdString(JSHandle::Cast(tagElements.region)); + std::string regionStr = intl::LocaleHelper::ConvertToStdString(thread, JSHandle::Cast(tagElements.region)); if (regionStr[INTL_INDEX_ZERO] == '\0') { return false; } @@ -827,10 +827,10 @@ bool JSLocale::ApplyOptionsToTag(JSThread *thread, const JSHandle &t return true; } -bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *builder, JSHandle language, +bool BuildOptionsTags(JSThread *thread, const JSHandle &tag, icu::LocaleBuilder *builder, JSHandle language, JSHandle script, JSHandle region) { - std::string tagStr = intl::LocaleHelper::ConvertToStdString(tag); + std::string tagStr = intl::LocaleHelper::ConvertToStdString(thread, tag); int32_t len = static_cast(tagStr.length()); ASSERT(len > 0); builder->setLanguageTag({ tagStr.c_str(), len }); @@ -843,7 +843,7 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build builder->setLocale(locale); if (!language->IsUndefined()) { - std::string languageStr = intl::LocaleHelper::ConvertToStdString(JSHandle::Cast(language)); + std::string languageStr = intl::LocaleHelper::ConvertToStdString(thread, JSHandle::Cast(language)); builder->setLanguage(languageStr); builder->build(status); if ((U_FAILURE(status) != 0)) { @@ -852,7 +852,7 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build } if (!script->IsUndefined()) { - std::string scriptStr = intl::LocaleHelper::ConvertToStdString((JSHandle::Cast(script))); + std::string scriptStr = intl::LocaleHelper::ConvertToStdString(thread, (JSHandle::Cast(script))); builder->setScript(scriptStr); builder->build(status); if ((U_FAILURE(status) != 0)) { @@ -861,7 +861,7 @@ bool BuildOptionsTags(const JSHandle &tag, icu::LocaleBuilder *build } if (!region->IsUndefined()) { - std::string regionStr = intl::LocaleHelper::ConvertToStdString(JSHandle::Cast(region)); + std::string regionStr = intl::LocaleHelper::ConvertToStdString(thread, JSHandle::Cast(region)); builder->setRegion(regionStr); builder->build(status); if ((U_FAILURE(status) != 0)) { @@ -956,7 +956,7 @@ JSHandle JSLocale::InitializeLocale(JSThread *thread, const JSHandle &locale, const std::string &key) { - icu::Locale *icuLocale = locale->GetIcuLocale(); + icu::Locale *icuLocale = locale->GetIcuLocale(thread); UErrorCode status = U_ZERO_ERROR; auto value = icuLocale->getUnicodeKeywordValue(key, status); @@ -1012,7 +1012,7 @@ JSTaggedValue JSLocale::NormalizeKeywordValue(JSThread *thread, const JSHandle JSLocale::ToString(JSThread *thread, const JSHandle &locale) { - icu::Locale *icuLocale = locale->GetIcuLocale(); + icu::Locale *icuLocale = locale->GetIcuLocale(thread); if (icuLocale == nullptr) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); return factory->GetEmptyString(); @@ -1030,7 +1030,7 @@ std::vector JSLocale::GetAvailableStringLocales(JSThread *thread, uint32_t availablecalesLength = availableLocales->GetLength(); for (uint32_t i = 0; i < availablecalesLength; i++) { availableItem.Update(availableLocales->Get(thread, i)); - availableStringLocales.emplace_back(intl::LocaleHelper::ConvertToStdString(availableItem)); + availableStringLocales.emplace_back(intl::LocaleHelper::ConvertToStdString(thread, availableItem)); } return availableStringLocales; } diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index 6f7f2e8ea9..57cc8ca7c4 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -82,11 +82,11 @@ constexpr uint8_t INTL_INDEX_EIGHT = 8; class JSIntlIterator : public icu::Locale::Iterator { public: - JSIntlIterator(const JSHandle &data, uint32_t length) : length_(length), curIdx_(0) + JSIntlIterator(const JSThread *thread, const JSHandle &data, uint32_t length) : length_(length), curIdx_(0) { for (uint32_t idx = 0; idx < length; idx++) { - auto itor = data->Get(idx); - std::string str = EcmaStringAccessor(itor).ToStdString(); + auto itor = data->Get(thread, idx); + std::string str = EcmaStringAccessor(itor).ToStdString(thread); data_.emplace_back(str); } } @@ -174,10 +174,10 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ICU_FIELD_OFFSET, SIZE) DECL_DUMP() - icu::Locale *GetIcuLocale() const + icu::Locale *GetIcuLocale(const JSThread *thread) const { - ASSERT(GetIcuField().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuField().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuField(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuField(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -250,7 +250,7 @@ public: // i. If values does not contain an element equal to value, throw a RangeError exception. JSHandle valueEStr = JSTaggedValue::ToString(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, T::EXCEPTION); - std::string valueStr = std::string(ConvertToString(*valueEStr, StringConvertedUsage::LOGICOPERATION)); + std::string valueStr = std::string(ConvertToString(thread, *valueEStr, StringConvertedUsage::LOGICOPERATION)); int existIdx = -1; if (!enumValues.empty()) { size_t strValuesSize = strValues.size(); diff --git a/ecmascript/js_map.cpp b/ecmascript/js_map.cpp index 511c70e6bd..0987edc6ba 100644 --- a/ecmascript/js_map.cpp +++ b/ecmascript/js_map.cpp @@ -24,7 +24,7 @@ void JSMap::Set(JSThread *thread, const JSHandle &map, const JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); JSHandle newMap = LinkedHashMap::Set(thread, mapHandle, key, value); map->SetLinkedMap(thread, newMap); @@ -32,7 +32,7 @@ void JSMap::Set(JSThread *thread, const JSHandle &map, const JSHandle &map, const JSHandle &key) { - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); int entry = mapHandle->FindElement(thread, key.GetTaggedValue()); if (entry == -1) { return false; @@ -43,36 +43,36 @@ bool JSMap::Delete(const JSThread *thread, const JSHandle &map, const JSH void JSMap::Clear(const JSThread *thread, const JSHandle &map) { - LinkedHashMap *linkedMap = LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject()); - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + LinkedHashMap *linkedMap = LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject()); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); JSHandle newMap = linkedMap->Clear(thread, mapHandle); map->SetLinkedMap(thread, newMap); } bool JSMap::Has(JSThread *thread, JSTaggedValue key) const { - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->Has(thread, key); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->Has(thread, key); } JSTaggedValue JSMap::Get(JSThread *thread, JSTaggedValue key) const { - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->Get(thread, key); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->Get(thread, key); } -uint32_t JSMap::GetSize() const +uint32_t JSMap::GetSize(JSThread *thread) const { - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->NumberOfElements(); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->NumberOfElements(); } -JSTaggedValue JSMap::GetKey(uint32_t entry) const +JSTaggedValue JSMap::GetKey(JSThread *thread, uint32_t entry) const { - ASSERT_PRINT(entry >= 0 && entry < GetSize(), "entry must be non-negative integer less than capacity"); - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->GetKey(entry); + ASSERT_PRINT(entry >= 0 && entry < GetSize(thread), "entry must be non-negative integer less than capacity"); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->GetKey(thread, entry); } -JSTaggedValue JSMap::GetValue(uint32_t entry) const +JSTaggedValue JSMap::GetValue(JSThread *thread, uint32_t entry) const { - ASSERT_PRINT(entry >= 0 && entry < GetSize(), "entry must be non-negative integer less than capacity"); - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->GetValue(entry); + ASSERT_PRINT(entry >= 0 && entry < GetSize(thread), "entry must be non-negative integer less than capacity"); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->GetValue(thread, entry); } } // namespace panda::ecmascript diff --git a/ecmascript/js_map.h b/ecmascript/js_map.h index 4f6b225444..fb7eb2298a 100644 --- a/ecmascript/js_map.h +++ b/ecmascript/js_map.h @@ -34,11 +34,11 @@ public: JSTaggedValue Get(JSThread *thread, JSTaggedValue key) const; - uint32_t GetSize() const; + uint32_t GetSize(JSThread *thread) const; - JSTaggedValue GetKey(uint32_t entry) const; + JSTaggedValue GetKey(JSThread *thread, uint32_t entry) const; - JSTaggedValue GetValue(uint32_t entry) const; + JSTaggedValue GetValue(JSThread *thread, uint32_t entry) const; static constexpr size_t LINKED_MAP_OFFSET = JSObject::SIZE; ACCESSORS(LinkedMap, LINKED_MAP_OFFSET, SIZE) diff --git a/ecmascript/js_map_iterator.cpp b/ecmascript/js_map_iterator.cpp index 7a689fddfa..7ab1c0416c 100644 --- a/ecmascript/js_map_iterator.cpp +++ b/ecmascript/js_map_iterator.cpp @@ -43,7 +43,7 @@ JSTaggedValue JSMapIterator::NextInternal(JSThread *thread, JSHandleUpdate(thread); JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); // 4.Let m be O.[[IteratedMap]]. - JSHandle iteratedMap(thread, iter->GetIteratedMap()); + JSHandle iteratedMap(thread, iter->GetIteratedMap(thread)); // 5.Let index be O.[[MapNextIndex]]. int index = static_cast(iter->GetNextIndex()); @@ -57,7 +57,7 @@ JSTaggedValue JSMapIterator::NextInternal(JSThread *thread, JSHandle keyHandle(thread, JSTaggedValue::Undefined()); while (index < totalElements) { - JSTaggedValue key = map->GetKey(index); + JSTaggedValue key = map->GetKey(thread, index); if (!key.IsHole()) { iter->SetNextIndex(index + 1); keyHandle.Update(key); @@ -65,7 +65,7 @@ JSTaggedValue JSMapIterator::NextInternal(JSThread *thread, JSHandle value(thread, map->GetValue(index)); + JSHandle value(thread, map->GetValue(thread, index)); // Else if itemKind is value, let result be e.[[Value]]. if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); @@ -88,20 +88,20 @@ JSTaggedValue JSMapIterator::NextInternal(JSThread *thread, JSHandleGetNextTable().IsHole()) { + if (map->GetNextTable(thread).IsHole()) { return; } int index = static_cast(GetNextIndex()); - JSTaggedValue nextTable = map->GetNextTable(); + JSTaggedValue nextTable = map->GetNextTable(thread); while (!nextTable.IsHole()) { - index -= map->GetDeletedElementsAt(index); + index -= map->GetDeletedElementsAt(thread, index); map = LinkedHashMap::Cast(nextTable.GetTaggedObject()); - nextTable = map->GetNextTable(); + nextTable = map->GetNextTable(thread); } SetIteratedMap(thread, JSTaggedValue(map)); SetNextIndex(index); @@ -125,7 +125,7 @@ JSTaggedValue JSMapIterator::MapIteratorToList(JSThread *thread, JSHandle newArrayHandle(thread, newArray); JSHandle iter(iterator); - JSHandle iteratedMap(thread, iter->GetIteratedMap()); + JSHandle iteratedMap(thread, iter->GetIteratedMap(thread)); if (iteratedMap->IsUndefined()) { return newArrayHandle.GetTaggedValue(); } @@ -138,14 +138,14 @@ JSTaggedValue JSMapIterator::MapIteratorToList(JSThread *thread, JSHandle keyHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle oldElements(thread, newArrayHandle->GetElements()); + JSHandle oldElements(thread, newArrayHandle->GetElements(thread)); JSHandle elements = factory->ExtendArray(oldElements, totalElements); newArrayHandle->SetElements(thread, elements); while (index < totalElements) { - JSTaggedValue key = map->GetKey(index); + JSTaggedValue key = map->GetKey(thread, index); if (!key.IsHole()) { keyHandle.Update(key); - valueHandle.Update(map->GetValue(index)); + valueHandle.Update(map->GetValue(thread, index)); if (itemKind == IterationKind::KEY) { ElementAccessor::Set(thread, newArrayHandle, k, keyHandle, true); } else if (itemKind == IterationKind::VALUE) { diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index 6772f45f18..ae5a5fb622 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -347,7 +347,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, if (EcmaStringAccessor(currencyStr).IsUtf16()) { THROW_RANGE_ERROR_AND_RETURN(thread, "not a utf-8", fractionDigitsOption); } - std::string currencyCStr = intl::LocaleHelper::ConvertToStdString(currencyStr); + std::string currencyCStr = intl::LocaleHelper::ConvertToStdString(thread, currencyStr); if (!JSLocale::IsWellFormedCurrencyCode(currencyCStr)) { THROW_RANGE_ERROR_AND_RETURN(thread, "not a wellformed code", fractionDigitsOption); } @@ -393,7 +393,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, if (EcmaStringAccessor(unitStr).IsUtf16()) { THROW_RANGE_ERROR_AND_RETURN(thread, "Unit input is illegal", fractionDigitsOption); } - std::string str = intl::LocaleHelper::ConvertToStdString(unitStr); + std::string str = intl::LocaleHelper::ConvertToStdString(thread, unitStr); if (!IsWellFormedUnitIdentifier(str, icuUnit, icuPerUnit)) { THROW_RANGE_ERROR_AND_RETURN(thread, "Unit input is illegal", fractionDigitsOption); } @@ -422,7 +422,7 @@ FractionDigitsOption SetNumberFormatUnitOptions(JSThread *thread, UErrorCode status = U_ZERO_ERROR; if (style == StyleOption::CURRENCY) { JSHandle currencyStr = JSHandle::Cast(currency); - std::string currencyCStr = intl::LocaleHelper::ConvertToStdString(currencyStr); + std::string currencyCStr = intl::LocaleHelper::ConvertToStdString(thread, currencyStr); std::transform(currencyCStr.begin(), currencyCStr.end(), currencyCStr.begin(), toupper); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle currencyValue = JSHandle::Cast(factory->NewFromStdString(currencyCStr)); @@ -542,7 +542,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle::Cast(optionsObject), mnfdDefault, mxfdDefault, notation); RETURN_IF_ABRUPT_COMPLETION(thread); - icuNumberFormatter = SetICUFormatterDigitOptions(icuNumberFormatter, numberFormat); + icuNumberFormatter = SetICUFormatterDigitOptions(thread, icuNumberFormatter, numberFormat); // 22. Let compactDisplay be ? GetOptionOfString(options, "compactDisplay", "string", « "short", "long" », "short"). property = globalConst->GetHandledCompactDisplayString(); @@ -737,7 +737,7 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandleIsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(thread); auto formatterPointer = new icu::number::LocalizedNumberFormatter(icuNumberFormatter); ecmaVm->GetIntlCache().SetIcuFormatterToCache(IcuFormatterType::NUMBER_FORMATTER, cacheEntry, formatterPointer, JSNumberFormat::FreeIcuNumberformat); @@ -766,7 +766,7 @@ int32_t JSNumberFormat::CurrencyDigits(const icu::UnicodeString ¤cy) icu::number::LocalizedNumberFormatter *JSNumberFormat::GetCachedIcuNumberFormatter(JSThread *thread, const JSHandle &locales) { - std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(); + std::string cacheEntry = locales->IsUndefined() ? "" : EcmaStringAccessor(locales.GetTaggedValue()).ToStdString(thread); void *cachedNumberFormatter = thread->GetEcmaVM()->GetIntlCache().GetIcuFormatterFromCache( IcuFormatterType::NUMBER_FORMATTER, cacheEntry); if (cachedNumberFormatter) { @@ -779,7 +779,7 @@ icu::number::LocalizedNumberFormatter *JSNumberFormat::GetCachedIcuNumberFormatt JSHandle JSNumberFormat::FormatNumeric(JSThread *thread, const JSHandle &numberFormat, JSTaggedValue x) { - icu::number::LocalizedNumberFormatter *icuNumberFormat = numberFormat->GetIcuCallTarget(); + icu::number::LocalizedNumberFormatter *icuNumberFormat = numberFormat->GetIcuCallTarget(thread); ASSERT(icuNumberFormat != nullptr); JSHandle res = FormatNumeric(thread, icuNumberFormat, x); return res; @@ -794,7 +794,7 @@ JSHandle JSNumberFormat::FormatNumeric(JSThread *thread, if (x.IsBigInt()) { JSHandle bigint(thread, x); JSHandle bigintStr = BigInt::ToString(thread, bigint); - std::string stdString = EcmaStringAccessor(bigintStr).ToStdString(); + std::string stdString = EcmaStringAccessor(bigintStr).ToStdString(thread); formattedNumber = icuNumberFormat->formatDecimal(icu::StringPiece(stdString), status); } else { double number = x.GetNumber(); @@ -916,7 +916,7 @@ JSHandle JSNumberFormat::FormatNumericToParts(JSThread *thread, const J JSTaggedValue x) { ASSERT(x.IsNumber() || x.IsBigInt()); - icu::number::LocalizedNumberFormatter *icuNumberFormatter = numberFormat->GetIcuCallTarget(); + icu::number::LocalizedNumberFormatter *icuNumberFormatter = numberFormat->GetIcuCallTarget(thread); ASSERT(icuNumberFormatter != nullptr); UErrorCode status = U_ZERO_ERROR; @@ -924,7 +924,7 @@ JSHandle JSNumberFormat::FormatNumericToParts(JSThread *thread, const J if (x.IsBigInt()) { JSHandle bigint(thread, x); JSHandle bigintStr = BigInt::ToString(thread, bigint); - std::string stdString = EcmaStringAccessor(bigintStr).ToStdString(); + std::string stdString = EcmaStringAccessor(bigintStr).ToStdString(thread); formattedNumber = icuNumberFormatter->formatDecimal(icu::StringPiece(stdString), status); } else { double number = x.GetNumber(); @@ -961,7 +961,7 @@ JSHandle JSNumberFormat::UnwrapNumberFormat(JSThread *thread, con // InstanceofOperator(nf, %NumberFormat%) is true, then // a. Let nf be ? Get(nf, %Intl%.[[FallbackSymbol]]). if (!isJSNumberFormat && hasInstance) { - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol(thread)); OperationResult operationResult = JSTaggedValue::GetProperty(thread, nf, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Undefined())); return operationResult.GetValue(); @@ -1014,12 +1014,12 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGlobalConstants(); JSHandle property = globalConst->GetHandledLocaleString(); - JSHandle locale(thread, numberFormat->GetLocale()); + JSHandle locale(thread, numberFormat->GetLocale(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, locale); RETURN_IF_ABRUPT_COMPLETION(thread); // [[NumberingSystem]] - JSHandle numberingSystem(thread, numberFormat->GetNumberingSystem()); + JSHandle numberingSystem(thread, numberFormat->GetNumberingSystem(thread)); if (numberingSystem->IsUndefined()) { numberingSystem = globalConst->GetHandledLatnString(); } @@ -1038,7 +1038,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandle currency(thread, JSTaggedValue::Undefined()); // If style is not currency the currency should be undefined if (style == StyleOption::CURRENCY) { - currency = JSHandle(thread, numberFormat->GetCurrency()); + currency = JSHandle(thread, numberFormat->GetCurrency(thread)); } if (!currency->IsUndefined()) { // NOLINT(readability-implicit-bool-conversion) property = globalConst->GetHandledCurrencyString(); @@ -1061,7 +1061,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandle unit(thread, numberFormat->GetUnit()); + JSHandle unit(thread, numberFormat->GetUnit(thread)); if (!unit->IsUndefined()) { // [[Unit]] property = globalConst->GetHandledUnitString(); @@ -1077,7 +1077,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledMinimumIntegerDigitsString(); - JSHandle minimumIntegerDigits(thread, numberFormat->GetMinimumIntegerDigits()); + JSHandle minimumIntegerDigits(thread, numberFormat->GetMinimumIntegerDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumIntegerDigits); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -1085,23 +1085,23 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledMinimumSignificantDigitsString(); - JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits()); + JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumSignificantDigits); RETURN_IF_ABRUPT_COMPLETION(thread); // [[MaximumSignificantDigits]] property = globalConst->GetHandledMaximumSignificantDigitsString(); - JSHandle maximumSignificantDigits(thread, numberFormat->GetMaximumSignificantDigits()); + JSHandle maximumSignificantDigits(thread, numberFormat->GetMaximumSignificantDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumSignificantDigits); RETURN_IF_ABRUPT_COMPLETION(thread); } else { // [[MinimumFractionDigits]] property = globalConst->GetHandledMinimumFractionDigitsString(); - JSHandle minimumFractionDigits(thread, numberFormat->GetMinimumFractionDigits()); + JSHandle minimumFractionDigits(thread, numberFormat->GetMinimumFractionDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumFractionDigits); RETURN_IF_ABRUPT_COMPLETION(thread); // [[MaximumFractionDigits]] property = globalConst->GetHandledMaximumFractionDigitsString(); - JSHandle maximumFractionDigits(thread, numberFormat->GetMaximumFractionDigits()); + JSHandle maximumFractionDigits(thread, numberFormat->GetMaximumFractionDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumFractionDigits); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -1109,12 +1109,12 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledMinimumSignificantDigitsString(); - JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits()); + JSHandle minimumSignificantDigits(thread, numberFormat->GetMinimumSignificantDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumSignificantDigits); RETURN_IF_ABRUPT_COMPLETION(thread); // [[MaximumSignificantDigits]] property = globalConst->GetHandledMaximumSignificantDigitsString(); - JSHandle maximumSignificantDigits(thread, numberFormat->GetMaximumSignificantDigits()); + JSHandle maximumSignificantDigits(thread, numberFormat->GetMaximumSignificantDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumSignificantDigits); RETURN_IF_ABRUPT_COMPLETION(thread); } @@ -1123,7 +1123,7 @@ void JSNumberFormat::ResolvedOptions(JSThread *thread, const JSHandleGetHandledUserGroupingString(); JSObject::CreateDataPropertyOrThrow(thread, options, property, - JSHandle(thread, numberFormat->GetUseGrouping())); + JSHandle(thread, numberFormat->GetUseGrouping(thread))); RETURN_IF_ABRUPT_COMPLETION(thread); // [[Notation]] diff --git a/ecmascript/js_number_format.h b/ecmascript/js_number_format.h index a7cce3eb49..d1e06f6182 100644 --- a/ecmascript/js_number_format.h +++ b/ecmascript/js_number_format.h @@ -108,10 +108,10 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() - icu::number::LocalizedNumberFormatter *GetIcuCallTarget() const + icu::number::LocalizedNumberFormatter *GetIcuCallTarget(JSThread *thread) const { - ASSERT(GetIcuField().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuField().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuField(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuField(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -159,18 +159,18 @@ public: const JSHandle &options); template - static icu::number::LocalizedNumberFormatter SetICUFormatterDigitOptions( + static icu::number::LocalizedNumberFormatter SetICUFormatterDigitOptions(JSThread *thread, icu::number::LocalizedNumberFormatter &icuNumberformatter, const JSHandle &formatter) { - int minimumIntegerDigits = formatter->GetMinimumIntegerDigits().GetInt(); + int minimumIntegerDigits = formatter->GetMinimumIntegerDigits(thread).GetInt(); // Set ICU formatter IntegerWidth to MinimumIntegerDigits icuNumberformatter = icuNumberformatter.integerWidth(icu::number::IntegerWidth::zeroFillTo(minimumIntegerDigits)); - int minimumSignificantDigits = formatter->GetMinimumSignificantDigits().GetInt(); - int maximumSignificantDigits = formatter->GetMaximumSignificantDigits().GetInt(); - int minimumFractionDigits = formatter->GetMinimumFractionDigits().GetInt(); - int maximumFractionDigits = formatter->GetMaximumFractionDigits().GetInt(); + int minimumSignificantDigits = formatter->GetMinimumSignificantDigits(thread).GetInt(); + int maximumSignificantDigits = formatter->GetMaximumSignificantDigits(thread).GetInt(); + int minimumFractionDigits = formatter->GetMinimumFractionDigits(thread).GetInt(); + int maximumFractionDigits = formatter->GetMaximumFractionDigits(thread).GetInt(); // If roundingtype is "compact-rounding" return ICU formatter RoundingType roundingType = formatter->GetRoundingType(); diff --git a/ecmascript/js_object-inl.h b/ecmascript/js_object-inl.h index 18ff1eb1c5..95e4861c11 100644 --- a/ecmascript/js_object-inl.h +++ b/ecmascript/js_object-inl.h @@ -229,14 +229,14 @@ inline bool JSObject::IsJSPrimitiveRef() const return GetJSHClass()->IsJsPrimitiveRef(); } -inline bool JSObject::IsElementDict() const +inline bool JSObject::IsElementDict(const JSThread *thread) const { - return TaggedArray::Cast(GetElements().GetTaggedObject())->IsDictionaryMode(); + return TaggedArray::Cast(GetElements(thread).GetTaggedObject())->IsDictionaryMode(); } -inline bool JSObject::IsPropertiesDict() const +inline bool JSObject::IsPropertiesDict(const JSThread *thread) const { - return TaggedArray::Cast(GetProperties().GetTaggedObject())->IsDictionaryMode(); + return TaggedArray::Cast(GetProperties(thread).GetTaggedObject())->IsDictionaryMode(); } inline bool JSObject::IsTypedArray() const @@ -273,8 +273,8 @@ std::pair JSObject::ConvertValueWithRep(PropertyAttributes void JSObject::SetPropertyInlinedPropsWithRep(const JSThread *thread, uint32_t index, JSTaggedValue value) { - auto layout = LayoutInfo::Cast(GetJSHClass()->GetLayout().GetTaggedObject()); - auto attr = layout->GetAttr(index); + auto layout = LayoutInfo::Cast(GetJSHClass()->GetLayout(thread).GetTaggedObject()); + auto attr = layout->GetAttr(thread, index); if (attr.IsTaggedRep()) { SetPropertyInlinedProps(thread, index, value); } else { @@ -299,15 +299,15 @@ void JSObject::SetPropertyInlinedProps(const JSThread *thread, uint32_t index, J SetPropertyInlinedProps(thread, GetJSHClass(), index, value); } -JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(uint32_t index, PropertyAttributes attr) const +JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(const JSThread* thread, uint32_t index, PropertyAttributes attr) const { - return GetPropertyInlinedPropsWithRep(GetJSHClass(), index, attr); + return GetPropertyInlinedPropsWithRep(thread, GetJSHClass(), index, attr); } -JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(const JSHClass *hclass, uint32_t index, +JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(const JSThread* thread, const JSHClass *hclass, uint32_t index, PropertyAttributes attr) const { - auto value = GetPropertyInlinedProps(hclass, index); + auto value = GetPropertyInlinedProps(thread, hclass, index); if (attr.IsDoubleRep()) { value = JSTaggedValue(bit_cast(value.GetRawData())); } else if (attr.IsIntRep()) { @@ -317,15 +317,15 @@ JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(const JSHClass *hclass, u } template -JSTaggedValue JSObject::GetPropertyInlinedPropsWithSize() const +JSTaggedValue JSObject::GetPropertyInlinedPropsWithSize(const JSThread* thread) const { constexpr uint32_t offset = static_cast(objectSize + index * JSTaggedValue::TaggedTypeSize()); - return JSTaggedValue(GET_VALUE(this, offset)); + return JSTaggedValue(GET_VALUE(thread, this, offset)); } -JSTaggedValue JSObject::GetPropertyInlinedProps(uint32_t index) const +JSTaggedValue JSObject::GetPropertyInlinedProps(const JSThread* thread, uint32_t index) const { - return GetPropertyInlinedProps(GetJSHClass(), index); + return GetPropertyInlinedProps(thread, GetJSHClass(), index); } template @@ -341,19 +341,19 @@ void JSObject::SetPropertyInlinedProps(const JSThread *thread, const JSHClass *h } } -JSTaggedValue JSObject::GetPropertyInlinedProps(const JSHClass *hclass, uint32_t index) const +JSTaggedValue JSObject::GetPropertyInlinedProps(const JSThread* thread, const JSHClass *hclass, uint32_t index) const { uint32_t offset = hclass->GetInlinedPropertiesOffset(index); - return JSTaggedValue(GET_VALUE(this, offset)); + return JSTaggedValue(GET_VALUE(thread, this, offset)); } -JSTaggedValue JSObject::GetProperty(const JSHClass *hclass, PropertyAttributes attr) const +JSTaggedValue JSObject::GetProperty(const JSThread* thread, const JSHClass *hclass, PropertyAttributes attr) const { if (attr.IsInlinedProps()) { - return GetPropertyInlinedPropsWithRep(hclass, attr.GetOffset(), attr); + return GetPropertyInlinedPropsWithRep(thread, hclass, attr.GetOffset(), attr); } - TaggedArray *array = TaggedArray::Cast(GetProperties().GetTaggedObject()); - return array->Get(attr.GetOffset() - hclass->GetInlinedProperties()); + TaggedArray *array = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); + return array->Get(thread, attr.GetOffset() - hclass->GetInlinedProperties()); } template @@ -362,7 +362,7 @@ void JSObject::SetProperty(const JSThread *thread, const JSHClass *hclass, Prope if (attr.IsInlinedProps()) { SetPropertyInlinedProps(thread, hclass, attr.GetOffset(), value); } else { - TaggedArray *array = TaggedArray::Cast(GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); array->Set(thread, attr.GetOffset() - hclass->GetInlinedProperties(), value); } } @@ -489,7 +489,7 @@ inline JSTaggedValue JSObject::ShouldGetValueFromBox(ObjectOperator *op) { JSTaggedValue result = op->GetValue(); if (result.IsPropertyBox()) { - result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(); + result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(op->GetThread()); } return result; } @@ -515,10 +515,10 @@ inline uint32_t JSObject::SetValuesOrEntries(JSThread *thread, const JSHandleGetClass(); - return hclass->GetPrototype(); + return hclass->GetPrototype(thread); } inline bool JSObject::IsDepulicateKeys(JSThread *thread, JSHandle keys, int32_t lastLength, @@ -529,16 +529,16 @@ inline bool JSObject::IsDepulicateKeys(JSThread *thread, JSHandle k } JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (int32_t i = 0; i < lastLength; i++) { - value.Update(keys->Get(i)); + value.Update(keys->Get(thread, i)); bool has = JSTaggedValue::Equal(thread, value, key); if (has) { return true; } } - uint32_t shadowSize = shadowQueue->Size(); + uint32_t shadowSize = shadowQueue->Size(thread); for (uint32_t i = 0; i < shadowSize; i++) { - value.Update(shadowQueue->Get(i)); + value.Update(shadowQueue->Get(thread, i)); bool has = JSTaggedValue::Equal(thread, value, key); if (has) { return true; @@ -558,7 +558,7 @@ inline std::pair, JSHandle> JSObject::GetOwnE JSThread *thread, const JSHandle &obj, uint32_t *copyLengthOfKeys, uint32_t *copyLengthOfElements) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::pair numOfKeys = obj->GetNumberOfEnumKeys(); + std::pair numOfKeys = obj->GetNumberOfEnumKeys(thread); uint32_t numOfEnumKeys = numOfKeys.first; uint32_t numOfElements = obj->GetNumberOfElements(thread); JSHandle elementArray = numOfElements > 0 ? JSObject::GetEnumElementKeys( @@ -568,9 +568,9 @@ inline std::pair, JSHandle> JSObject::GetOwnE return std::make_pair(keyArray, elementArray); } -inline bool JSObject::HasMutantTaggedArrayElements(const JSHandle &obj) +inline bool JSObject::HasMutantTaggedArrayElements(const JSThread *thread, const JSHandle &obj) { - return obj->GetElements().IsMutantTaggedArray(); + return obj->GetElements(thread).IsMutantTaggedArray(); } } // namespace panda::ecmascript #endif // ECMASCRIPT_JSOBJECT_INL_H diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index e4bb79d419..4059de3d73 100644 --- a/ecmascript/js_object.cpp +++ b/ecmascript/js_object.cpp @@ -60,23 +60,23 @@ void ThroughputJSObjectResizingStrategy::UpdateGrowStep(JSThread *thread, uint32 step)); } -Method *ECMAObject::GetCallTarget() const +Method *ECMAObject::GetCallTarget(const JSThread *thread) const { const TaggedObject *obj = this; ASSERT(JSTaggedValue(obj).IsJSFunctionBase() || JSTaggedValue(obj).IsJSProxy()); JSTaggedValue value; if (JSTaggedValue(obj).IsJSFunctionBase()) { - value = JSFunctionBase::ConstCast(obj)->GetMethod(); + value = JSFunctionBase::ConstCast(obj)->GetMethod(thread); } else { - value = JSProxy::ConstCast(obj)->GetMethod(); + value = JSProxy::ConstCast(obj)->GetMethod(thread); } return reinterpret_cast(value.GetTaggedObject()); } -void *ECMAObject::GetNativePointer() const +void *ECMAObject::GetNativePointer(const JSThread *thread) const { - Method *method = GetCallTarget(); + Method *method = GetCallTarget(thread); ASSERT(method->IsNativeWithCallField()); const TaggedObject *obj = this; if (JSTaggedValue(obj).IsJSFunctionBase()) { @@ -91,11 +91,11 @@ JSHandle JSObject::GrowElementsCapacity(const JSThread *thread, con { uint32_t newCapacity = 0; if (obj->IsJSArray()) { - uint32_t hint = JSHandle(obj)->GetHintLength(); + uint32_t hint = JSHandle(obj)->GetHintLength(thread); newCapacity = ComputeElementCapacityWithHint(capacity, hint); } if (obj->IsJSSArray()) { - uint32_t hint = JSHandle(obj)->GetHintLength(); + uint32_t hint = JSHandle(obj)->GetHintLength(thread); newCapacity = ComputeElementCapacityWithHint(capacity, hint); } if (newCapacity == 0) { @@ -103,7 +103,7 @@ JSHandle JSObject::GrowElementsCapacity(const JSThread *thread, con ComputeElementCapacity(capacity, isNew); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle oldElements(thread, obj->GetElements()); + JSHandle oldElements(thread, obj->GetElements(thread)); uint32_t oldLength = oldElements->GetLength(); ElementsKind kind = obj->GetClass()->GetElementsKind(); @@ -112,7 +112,7 @@ JSHandle JSObject::GrowElementsCapacity(const JSThread *thread, con obj->IsJSShared() ? MemSpaceType::SHARED_OLD_SPACE : MemSpaceType::SEMI_SPACE, kind); obj->SetElements(thread, newElements); if (thread->IsPGOProfilerEnable() && obj->IsJSArray()) { - auto trackInfo = JSHandle(obj)->GetTrackInfo(); + auto trackInfo = JSHandle(obj)->GetTrackInfo(thread); thread->GetEcmaVM()->GetPGOProfiler()->UpdateTrackArrayLength(trackInfo, newCapacity); } return newElements; @@ -179,38 +179,38 @@ bool JSObject::IsRegExp(JSThread *thread, const JSHandle &argumen JSHandle JSObject::TransitionToDictionary(const JSThread *thread, const JSHandle &receiver) { - JSHandle array(thread, receiver->GetProperties()); + JSHandle array(thread, receiver->GetProperties(thread)); JSHandle jshclass(thread, receiver->GetJSHClass()); ASSERT(!jshclass->IsDictionaryMode()); uint32_t propNumber = jshclass->NumberOfProps(); - ASSERT(!jshclass->GetLayout().IsNull()); + ASSERT(!jshclass->GetLayout(thread).IsNull()); if (jshclass->IsJSShared()) { THROW_TYPE_ERROR_AND_RETURN(const_cast(thread), "shared obj does not support changing or deleting attributes", JSHandle()); } - JSHandle layoutInfoHandle(thread, jshclass->GetLayout()); + JSHandle layoutInfoHandle(thread, jshclass->GetLayout(thread)); JSMutableHandle dict( thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(propNumber))); JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); uint32_t numberInlinedProps = jshclass->GetInlinedProperties(); for (uint32_t i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfoHandle->GetKey(i); - PropertyAttributes attr = layoutInfoHandle->GetAttr(i); + JSTaggedValue key = layoutInfoHandle->GetKey(thread, i); + PropertyAttributes attr = layoutInfoHandle->GetAttr(thread, i); ASSERT(i == attr.GetOffset()); JSTaggedValue value; if (i < numberInlinedProps) { - value = receiver->GetPropertyInlinedPropsWithRep(i, attr); + value = receiver->GetPropertyInlinedPropsWithRep(thread, i, attr); // If delete a property in hclass which has subtyping info and not prototype, only set value as hole and // not remove. When transition to dictionary, exclude it. if (value.IsHole()) { continue; } } else { - value = array->Get(i - numberInlinedProps); + value = array->Get(thread, i - numberInlinedProps); } attr.SetBoxType(PropertyBoxType::UNDEFINED); @@ -241,7 +241,7 @@ JSHandle JSObject::TransitionToDictionary(const JSThread *thread void JSObject::ElementsToDictionary(const JSThread *thread, JSHandle obj) { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); ASSERT(!obj->GetJSHClass()->IsDictionaryElement()); uint32_t length = elements->GetLength(); if (obj->IsJSShared()) { @@ -272,14 +272,14 @@ void JSObject::ElementsToDictionary(const JSThread *thread, JSHandle o bool JSObject::AttributesUnchanged(const JSThread *thread, const JSHandle &obj) { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); uint32_t size = static_cast(elements->Size()); for (uint32_t hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = elements->GetKey(hashIndex); + JSTaggedValue key = elements->GetKey(thread, hashIndex); if (key.IsUndefined() || key.IsHole()) { continue; } - PropertyAttributes attr = elements->GetAttributes(hashIndex); + PropertyAttributes attr = elements->GetAttributes(thread, hashIndex); if (!attr.IsDefaultAttributes()) { return false; } @@ -292,13 +292,13 @@ void JSObject::TryOptimizeAsFastElements(const JSThread *thread, JSHandleGetJSHClass()->IsDictionaryElement() && obj->IsJSArray()); if (AttributesUnchanged(thread, obj)) { uint32_t length = JSArray::Cast(*obj)->GetLength(); - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); uint32_t size = static_cast(elements->Size()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle array = factory->NewTaggedArray(length); for (uint32_t hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = elements->GetKey(hashIndex); - JSTaggedValue value = elements->GetValue(hashIndex); + JSTaggedValue key = elements->GetKey(thread, hashIndex); + JSTaggedValue value = elements->GetValue(thread, hashIndex); if (key.IsUndefined() || key.IsHole()) { continue; } @@ -317,7 +317,7 @@ void JSObject::OptimizeAsFastProperties(const JSThread *thread, JSHandleGetJSHClass()->IsDictionaryMode()); // 1. Get NameDictionary properties - JSHandle properties(thread, obj->GetProperties()); + JSHandle properties(thread, obj->GetProperties(thread)); int numberOfProperties = properties->EntriesCount(); // Make sure we preserve enough capacity @@ -326,7 +326,7 @@ void JSObject::OptimizeAsFastProperties(const JSThread *thread, JSHandle indexOrder = properties->GetEnumerationOrder(); + std::vector indexOrder = properties->GetEnumerationOrder(thread); ASSERT(static_cast(indexOrder.size()) == numberOfProperties); // 3. Change Hclass @@ -340,7 +340,7 @@ void JSObject::OptimizeAsFastProperties(const JSThread *thread, JSHandleGetValue(indexOrder[i]); + JSTaggedValue value = properties->GetValue(thread, indexOrder[i]); if (i < numberOfInlinedProps) { obj->SetPropertyInlinedPropsWithRep(thread, i, value); } else { @@ -386,8 +386,8 @@ bool JSObject::IsArrayLengthWritable(JSThread *thread, const JSHandle { auto *hclass = receiver->GetJSHClass(); if (!hclass->IsDictionaryMode()) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, JSArray::LENGTH_INLINE_PROPERTY_INDEX)); return attr.IsWritable(); } JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); @@ -442,7 +442,7 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &re if (receiver->GetJSHClass()->IsDictionaryElement() && receiver->IsJSArray()) { JSArray *arr = JSArray::Cast(*receiver); uint32_t capacity = arr->GetArrayLength(); - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread).GetTaggedObject()); ASSERT(elements->IsDictionaryMode()); if (ShouldTransToFastElements(thread, elements, capacity, index)) { JSObject::TryOptimizeAsFastElements(thread, receiver); @@ -450,7 +450,7 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &re } bool isDictionary = receiver->GetJSHClass()->IsDictionaryElement(); - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread).GetTaggedObject()); if (isDictionary) { ASSERT(elements->IsDictionaryMode()); JSHandle keyHandle(thread, JSTaggedValue(static_cast(index))); @@ -466,7 +466,7 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &re JSObject::ElementsToDictionary(thread, receiver); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); JSHandle keyHandle(thread, JSTaggedValue(static_cast(index))); - JSHandle dict(thread, receiver->GetElements()); + JSHandle dict(thread, receiver->GetElements(thread)); JSHandle newKey = NumberDictionary::Put(thread, dict, keyHandle, value, attr); receiver->SetElements(thread, newKey); return true; @@ -484,11 +484,11 @@ bool JSObject::AddElementInternal(JSThread *thread, const JSHandle &re void JSObject::DeletePropertyInternal(JSThread *thread, const JSHandle &obj, const JSHandle &key, uint32_t index) { - JSHandle array(thread, obj->GetProperties()); + JSHandle array(thread, obj->GetProperties(thread)); if (obj->IsJSGlobalObject()) { - JSHandle dictHandle(thread, obj->GetProperties()); - PropertyBox* box = dictHandle->GetBox(index); + JSHandle dictHandle(thread, obj->GetProperties(thread)); + PropertyBox* box = dictHandle->GetBox(thread, index); box->Clear(thread); JSHandle newDict = GlobalDictionary::Remove(thread, dictHandle, index); obj->SetProperties(thread, newDict); @@ -498,7 +498,7 @@ void JSObject::DeletePropertyInternal(JSThread *thread, const JSHandle if (!array->IsDictionaryMode()) { JSHandle dictHandle(TransitionToDictionary(thread, obj)); RETURN_IF_ABRUPT_COMPLETION(thread); - int entry = dictHandle->FindEntry(key.GetTaggedValue()); + int entry = dictHandle->FindEntry(thread, key.GetTaggedValue()); ASSERT(entry != -1); JSHandle newDict = NameDictionary::Remove(thread, dictHandle, entry); obj->SetProperties(thread, newDict); @@ -514,11 +514,11 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, const JSHandle &keyArray) { - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { int end = static_cast(obj->GetJSHClass()->NumberOfProps()); if (end > 0) { - LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject()) + LayoutInfo::Cast(obj->GetJSHClass()->GetLayout(thread).GetTaggedObject()) ->GetAllKeys(thread, end, offset, *keyArray); } return; @@ -529,7 +529,7 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, return dict->GetAllKeys(thread, offset, *keyArray); } - NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); + NameDictionary *dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetAllKeys(thread, offset, *keyArray); } @@ -538,11 +538,11 @@ void JSObject::GetAllKeysByFilter(const JSThread *thread, const JSHandle &keyArray, uint32_t filter) { - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { uint32_t numberOfProps = obj->GetJSHClass()->NumberOfProps(); if (numberOfProps > 0) { - LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())-> + LayoutInfo::Cast(obj->GetJSHClass()->GetLayout(thread).GetTaggedObject())-> GetAllKeysByFilter(thread, numberOfProps, keyArrayEffectivelength, *keyArray, filter); } return; @@ -553,49 +553,49 @@ void JSObject::GetAllKeysByFilter(const JSThread *thread, const JSHandleGetAllKeysByFilter(thread, keyArrayEffectivelength, *keyArray, filter); } - NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); + NameDictionary *dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetAllKeysByFilter(thread, keyArrayEffectivelength, *keyArray, filter); } // For Serialization use. Does not support JSGlobalObject -void JSObject::GetAllKeysForSerialization(const JSHandle &obj, std::vector &keyVector) +void JSObject::GetAllKeysForSerialization(const JSThread *thread, const JSHandle &obj, std::vector &keyVector) { DISALLOW_GARBAGE_COLLECTION; ASSERT_PRINT(!obj->IsJSGlobalObject(), "Do not support get key of JSGlobal Object"); - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { int end = static_cast(obj->GetJSHClass()->NumberOfProps()); if (end > 0) { - LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())->GetAllKeysForSerialization(end, - keyVector); + LayoutInfo::Cast(obj->GetJSHClass()->GetLayout(thread).GetTaggedObject())->GetAllKeysForSerialization( + thread, end, keyVector); } } else { - NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); - dict->GetAllKeysIntoVector(keyVector); + NameDictionary *dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); + dict->GetAllKeysIntoVector(thread, keyVector); } } // static JSHandle JSObject::GetOrCreateEnumCache(JSThread *thread, JSHandle jsHClass) { - if (!jsHClass->GetEnumCache().IsEnumCache()) { + if (!jsHClass->GetEnumCache(thread).IsEnumCache()) { JSHandle enumCache = thread->GetEcmaVM()->GetFactory()->NewEnumCache(); jsHClass->SetEnumCache(thread, enumCache.GetTaggedValue()); return enumCache; } - JSHandle enumCacheHandle(thread, jsHClass->GetEnumCache()); + JSHandle enumCacheHandle(thread, jsHClass->GetEnumCache(thread)); return JSHandle::Cast(enumCacheHandle); } // static JSHandle JSObject::GetOrCreateDependentInfos(JSThread *thread, JSHandle jsHClass) { - if (!jsHClass->HasDependentInfos()) { + if (!jsHClass->HasDependentInfos(thread)) { JSHandle dependentInfos = thread->GetEcmaVM()->GetFactory()->NewDependentInfos(0); jsHClass->SetDependentInfos(thread, dependentInfos.GetTaggedValue()); return JSHandle::Cast(dependentInfos); } - JSHandle dependentInfos(thread, jsHClass->GetDependentInfos()); + JSHandle dependentInfos(thread, jsHClass->GetDependentInfos(thread)); return JSHandle::Cast(dependentInfos); } @@ -605,18 +605,18 @@ JSHandle JSObject::GetAllEnumKeys(JSThread *thread, const JSHandle< ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (obj->IsJSGlobalObject()) { JSHandle keyArray = factory->NewTaggedArray(numOfKeys); - GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties().GetTaggedObject()); + GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetEnumAllKeys(thread, 0, *keyArray, keys); return keyArray; } - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { JSHandle jsHclass(thread, obj->GetJSHClass()); if (!jsHclass.GetTaggedValue().IsInSharedHeap()) { JSHandle enumCache = GetOrCreateEnumCache(thread, jsHclass); - if (enumCache->IsEnumCacheOwnValid()) { - JSHandle cacheArray = JSHandle(thread, enumCache->GetEnumCacheOwn()); + if (enumCache->IsEnumCacheOwnValid(thread)) { + JSHandle cacheArray = JSHandle(thread, enumCache->GetEnumCacheOwn(thread)); JSHandle keyArray = factory->CopyFromKeyArray(cacheArray); *keys = keyArray->GetLength(); return keyArray; @@ -624,7 +624,7 @@ JSHandle JSObject::GetAllEnumKeys(JSThread *thread, const JSHandle< if (numOfKeys > 0) { int end = static_cast(jsHclass->NumberOfProps()); JSHandle keyArray = factory->NewTaggedArray(numOfKeys); - LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()) + LayoutInfo::Cast(jsHclass->GetLayout(thread).GetTaggedObject()) ->GetAllEnumKeys(thread, end, 0, keyArray, keys); enumCache->SetEnumCacheOwn(thread, keyArray.GetTaggedValue()); JSHandle newkeyArray = factory->CopyFromKeyArray(keyArray); @@ -634,7 +634,7 @@ JSHandle JSObject::GetAllEnumKeys(JSThread *thread, const JSHandle< if (numOfKeys > 0) { int end = static_cast(jsHclass->NumberOfProps()); JSHandle keyArray = factory->NewTaggedArray(numOfKeys); - LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()) + LayoutInfo::Cast(jsHclass->GetLayout(thread).GetTaggedObject()) ->GetAllEnumKeys(thread, end, 0, keyArray, keys); JSHandle newkeyArray = factory->CopyFromKeyArray(keyArray); return newkeyArray; @@ -645,7 +645,7 @@ JSHandle JSObject::GetAllEnumKeys(JSThread *thread, const JSHandle< } JSHandle keyArray = factory->NewTaggedArray(numOfKeys); - NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); + NameDictionary *dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetAllEnumKeys(thread, 0, keyArray, keys); return keyArray; } @@ -653,24 +653,24 @@ JSHandle JSObject::GetAllEnumKeys(JSThread *thread, const JSHandle< uint32_t JSObject::GetAllEnumKeys(JSThread *thread, const JSHandle &obj, int offset, const JSHandle &keyArray) { - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); uint32_t keys = 0; if (!array->IsDictionaryMode()) { JSHClass *jsHclass = obj->GetJSHClass(); int end = static_cast(jsHclass->NumberOfProps()); if (end > 0) { - LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()) + LayoutInfo::Cast(jsHclass->GetLayout(thread).GetTaggedObject()) ->GetAllEnumKeys(thread, end, offset, keyArray, &keys); } return keys; } if (obj->IsJSGlobalObject()) { - GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties().GetTaggedObject()); + GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetEnumAllKeys(thread, offset, *keyArray, &keys); return keys; } - NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); + NameDictionary *dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetAllEnumKeys(thread, offset, keyArray, &keys); return keys; } @@ -679,16 +679,16 @@ void JSObject::GetAllElementKeys(JSThread *thread, const JSHandle &obj const JSHandle &keyArray) { uint32_t elementIndex = 0; - if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength() + static_cast(offset); + if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString(thread)) { + elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength(thread) + static_cast(offset); for (uint32_t i = static_cast(offset); i < elementIndex; ++i) { auto key = base::NumberHelper::IntToEcmaString(thread, i); keyArray->Set(thread, i, key); } } - if (!ElementAccessor::IsDictionaryMode(obj)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + if (!ElementAccessor::IsDictionaryMode(thread, obj)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread, obj); for (uint32_t i = 0, j = elementIndex; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread, obj, i).IsHole()) { auto key = base::NumberHelper::IntToEcmaString(thread, i); @@ -696,7 +696,7 @@ void JSObject::GetAllElementKeys(JSThread *thread, const JSHandle &obj } } } else { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); NumberDictionary::GetAllKeys(thread, JSHandle(elements), elementIndex, keyArray); } } @@ -711,8 +711,8 @@ void JSObject::GetAllElementKeysByFilter(JSThread *thread, uint32_t elementIndex = 0; // For strings attributes, only enumerable is true - if ((filter & NATIVE_ENUMERABLE) && obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength(); + if ((filter & NATIVE_ENUMERABLE) && obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString(thread)) { + elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength(thread); for (uint32_t i = 0; i < elementIndex; ++i) { keyArray->Set(thread, keyArrayEffectiveLength, JSTaggedValue(i)); keyArrayEffectiveLength++; @@ -721,8 +721,8 @@ void JSObject::GetAllElementKeysByFilter(JSThread *thread, JSHandle objValue(obj); - if (!ElementAccessor::IsDictionaryMode(obj)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + if (!ElementAccessor::IsDictionaryMode(thread, obj)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread, obj); for (uint32_t i = 0; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread, obj, i).IsHole()) { ObjectOperator op(thread, objValue, i, OperatorType::OWN); @@ -735,7 +735,7 @@ void JSObject::GetAllElementKeysByFilter(JSThread *thread, } } } else { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); NumberDictionary::GetAllKeysByFilter(thread, JSHandle(elements), keyArrayEffectiveLength, keyArray, filter); } @@ -744,17 +744,17 @@ void JSObject::GetAllElementKeysByFilter(JSThread *thread, void JSObject::GetALLElementKeysIntoVector(const JSThread *thread, const JSHandle &obj, std::vector &keyVector) { - if (!ElementAccessor::IsDictionaryMode(obj)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + if (!ElementAccessor::IsDictionaryMode(thread, obj)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread, obj); for (uint32_t i = 0; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread, obj, i).IsHole()) { keyVector.emplace_back(JSTaggedValue(i)); } } } else { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); JSHandle dict = JSHandle::Cast(elements); - dict->GetAllKeysIntoVector(keyVector); + dict->GetAllKeysIntoVector(thread, keyVector); } } @@ -773,8 +773,8 @@ void JSObject::CollectEnumElements(JSThread *thread, const JSHandle &o uint32_t elementIndex = static_cast(offset); JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); - if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - uint32_t strLen = JSPrimitiveRef::Cast(*obj)->GetStringLength(); + if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString(thread)) { + uint32_t strLen = JSPrimitiveRef::Cast(*obj)->GetStringLength(thread); for (uint32_t i = 0; i < strLen; ++i) { keyHandle.Update(base::NumberHelper::IntToEcmaString(thread, i)); elementArray->Set(thread, elementIndex, keyHandle); @@ -783,9 +783,9 @@ void JSObject::CollectEnumElements(JSThread *thread, const JSHandle &o *keys += strLen; } - if (!ElementAccessor::IsDictionaryMode(obj)) { + if (!ElementAccessor::IsDictionaryMode(thread, obj)) { JSHandle emptyQueue = thread->GetEcmaVM()->GetFactory()->GetEmptyTaggedQueue(); - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread, obj); uint32_t preElementIndex = elementIndex; for (uint32_t i = 0; i < elementsLen; ++i) { if (ElementAccessor::Get(thread, obj, i).IsHole()) { @@ -801,7 +801,7 @@ void JSObject::CollectEnumElements(JSThread *thread, const JSHandle &o } *keys += (elementIndex - preElementIndex); } else { - JSHandle arr(thread, obj->GetElements()); + JSHandle arr(thread, obj->GetElements(thread)); NumberDictionary::GetAllEnumKeys( thread, JSHandle(arr), elementIndex, elementArray, keys, lastLength); } @@ -811,16 +811,16 @@ void JSObject::GetEnumElementKeys(JSThread *thread, const JSHandle &ob const JSHandle &keyArray) { uint32_t elementIndex = 0; - if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString()) { - elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength() + static_cast(offset); + if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(*obj)->IsString(thread)) { + elementIndex = JSPrimitiveRef::Cast(*obj)->GetStringLength(thread) + static_cast(offset); for (uint32_t i = static_cast(offset); i < elementIndex; ++i) { auto key = base::NumberHelper::IntToEcmaString(thread, i); keyArray->Set(thread, i, key); } } - if (!ElementAccessor::IsDictionaryMode(obj)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(obj); + if (!ElementAccessor::IsDictionaryMode(thread, obj)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread, obj); for (uint32_t i = 0, j = elementIndex; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread, obj, i).IsHole()) { auto key = base::NumberHelper::IntToEcmaString(thread, i); @@ -828,37 +828,37 @@ void JSObject::GetEnumElementKeys(JSThread *thread, const JSHandle &ob } } } else { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); uint32_t keys = 0; NumberDictionary::GetAllEnumKeys(thread, JSHandle(elements), elementIndex, keyArray, &keys); } } -std::pair JSObject::GetNumberOfEnumKeys() const +std::pair JSObject::GetNumberOfEnumKeys(const JSThread *thread) const { DISALLOW_GARBAGE_COLLECTION; - TaggedArray *array = TaggedArray::Cast(GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { int end = static_cast(GetJSHClass()->NumberOfProps()); if (end > 0) { - LayoutInfo *layout = LayoutInfo::Cast(GetJSHClass()->GetLayout().GetTaggedObject()); - return layout->GetNumOfEnumKeys(end); + LayoutInfo *layout = LayoutInfo::Cast(GetJSHClass()->GetLayout(thread).GetTaggedObject()); + return layout->GetNumOfEnumKeys(thread, end); } return std::make_pair(0, 0); } if (IsJSGlobalObject()) { GlobalDictionary *dict = GlobalDictionary::Cast(array); - return dict->GetNumOfEnumKeys(); + return dict->GetNumOfEnumKeys(thread); } - NameDictionary *dict = NameDictionary::Cast(GetProperties().GetTaggedObject()); - return dict->GetNumOfEnumKeys(); + NameDictionary *dict = NameDictionary::Cast(GetProperties(thread).GetTaggedObject()); + return dict->GetNumOfEnumKeys(thread); } -uint32_t JSObject::GetNumberOfKeys() +uint32_t JSObject::GetNumberOfKeys(const JSThread *thread) { DISALLOW_GARBAGE_COLLECTION; - TaggedArray *array = TaggedArray::Cast(GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { return GetJSHClass()->NumberOfProps(); @@ -884,19 +884,19 @@ uint32_t JSObject::GetNumberOfElements(JSThread *thread) { DISALLOW_GARBAGE_COLLECTION; uint32_t numOfElements = 0; - if (IsJSPrimitiveRef() && JSPrimitiveRef::Cast(this)->IsString()) { - numOfElements = JSPrimitiveRef::Cast(this)->GetStringLength(); + if (IsJSPrimitiveRef() && JSPrimitiveRef::Cast(this)->IsString(thread)) { + numOfElements = JSPrimitiveRef::Cast(this)->GetStringLength(thread); } - if (!ElementAccessor::IsDictionaryMode(this)) { - uint32_t elementsLen = ElementAccessor::GetElementsLength(this); + if (!ElementAccessor::IsDictionaryMode(thread, this)) { + uint32_t elementsLen = ElementAccessor::GetElementsLength(thread, this); for (uint32_t i = 0; i < elementsLen; ++i) { if (!ElementAccessor::Get(thread, this, i).IsHole()) { numOfElements++; } } } else { - TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements(thread).GetTaggedObject()); numOfElements += static_cast(NumberDictionary::Cast(elements)->EntriesCount()); } @@ -1156,7 +1156,7 @@ bool JSObject::CallSetter(JSThread *thread, const AccessorData &accessor, const if (UNLIKELY(accessor.IsInternal())) { return accessor.CallInternalSet(thread, JSHandle::Cast(receiver), value, mayThrow); } - JSTaggedValue setter = accessor.GetSetter(); + JSTaggedValue setter = accessor.GetSetter(thread); // 8. If setter is undefined, return false. if (setter.IsUndefined()) { if (mayThrow) { @@ -1181,7 +1181,7 @@ bool JSObject::CallSetter(JSThread *thread, const AccessorData &accessor, const JSTaggedValue JSObject::CallGetter(JSThread *thread, const AccessorData *accessor, const JSHandle &receiver) { - JSTaggedValue getter = accessor->GetGetter(); + JSTaggedValue getter = accessor->GetGetter(thread); // 7. If getter is undefined, return undefined. if (getter.IsUndefined()) { return JSTaggedValue::Undefined(); @@ -1244,22 +1244,22 @@ OperationResult JSObject::GetPropertyFromGlobal(JSThread *thread, const JSHandle return OperationResult(thread, GetProperty(thread, &op), PropertyMetaData(op.IsFound())); } -PropertyBox* JSObject::GetGlobalPropertyBox(JSTaggedValue key) +PropertyBox* JSObject::GetGlobalPropertyBox(const JSThread *thread, JSTaggedValue key) { ASSERT(IsJSGlobalObject()); - auto dict = GlobalDictionary::Cast(GetProperties().GetTaggedObject()); - auto entry = dict->FindEntry(key); + auto dict = GlobalDictionary::Cast(GetProperties(thread).GetTaggedObject()); + auto entry = dict->FindEntry(thread, key); if (entry == -1) { return nullptr; } - return dict->GetBox(entry); + return dict->GetBox(thread, entry); } -PropertyBox* JSObject::GetGlobalPropertyBox(JSThread *thread, const std::string& key) +PropertyBox* JSObject::GetGlobalPropertyBox(const JSThread *thread, const std::string& key) { auto factory = thread->GetEcmaVM()->GetFactory(); auto keyValue = factory->NewFromUtf8(key).GetTaggedValue(); - return GetGlobalPropertyBox(keyValue); + return GetGlobalPropertyBox(thread, keyValue); } JSTaggedValue JSObject::GetProperty(JSThread *thread, ObjectOperator *op) @@ -1267,8 +1267,8 @@ JSTaggedValue JSObject::GetProperty(JSThread *thread, ObjectOperator *op) JSHandle receiver = op->GetReceiver(); JSHandle holder = op->GetHolder(); if (receiver->IsNativeModuleFailureInfo()) { - JSTaggedValue failureInfo = JSHandle::Cast(receiver)->GetArkNativeModuleFailureInfo(); - THROW_REFERENCE_ERROR_AND_RETURN(thread, ConvertToString(failureInfo).c_str(), JSTaggedValue::Undefined()); + JSTaggedValue failureInfo = JSHandle::Cast(receiver)->GetArkNativeModuleFailureInfo(thread); + THROW_REFERENCE_ERROR_AND_RETURN(thread, ConvertToString(thread, failureInfo).c_str(), JSTaggedValue::Undefined()); } if (holder->IsJSProxy()) { if (op->IsElement()) { @@ -1346,7 +1346,7 @@ bool JSObject::GlobalGetOwnProperty(JSThread *thread, const JSHandle valueHandle(thread, cell->GetValue()); + JSHandle valueHandle(thread, cell->GetValue(thread)); desc.SetValue(valueHandle); } ASSERT(!desc.GetValue()->IsInternalAccessor()); @@ -1369,7 +1369,7 @@ bool JSObject::OrdinaryGetOwnProperty(JSThread *thread, const JSHandle JSTaggedValue val = desc.GetValue().GetTaggedValue(); if (val.IsPropertyBox()) { PropertyBox *cell = PropertyBox::Cast(val.GetTaggedObject()); - JSHandle valueHandle(thread, cell->GetValue()); + JSHandle valueHandle(thread, cell->GetValue(thread)); desc.SetValue(valueHandle); } } @@ -1444,7 +1444,7 @@ bool JSObject::ValidateDataDescriptorWhenConfigurable(ObjectOperator *op, const } // 8a ii. If the [[Writable]] field of current is false, then if (!current.IsWritable()) { - if (desc.HasValue() && !JSTaggedValue::SameValue(current.GetValue(), desc.GetValue())) { + if (desc.HasValue() && !JSTaggedValue::SameValue(op->GetThread(), current.GetValue(), desc.GetValue())) { return false; } } @@ -1506,14 +1506,15 @@ bool JSObject::ValidateAndApplyPropertyDescriptor(ObjectOperator *op, bool exten // 3. Return true, if every field in Desc is absent // 4. Return true, if every field in Desc also occurs in current and the value of every field in Desc is the // same value as the corresponding field in current when compared using the SameValue algorithm. + JSThread *thread = op->GetThread(); if ((!desc.HasEnumerable() || desc.IsEnumerable() == current.IsEnumerable()) && (!desc.HasConfigurable() || desc.IsConfigurable() == current.IsConfigurable()) && - (!desc.HasValue() || JSTaggedValue::SameValue(current.GetValue(), desc.GetValue())) && + (!desc.HasValue() || JSTaggedValue::SameValue(thread, current.GetValue(), desc.GetValue())) && (!desc.HasWritable() || (current.IsWritable() == desc.IsWritable())) && (!desc.HasGetter() || - (current.HasGetter() && JSTaggedValue::SameValue(current.GetGetter(), desc.GetGetter()))) && + (current.HasGetter() && JSTaggedValue::SameValue(thread, current.GetGetter(), desc.GetGetter()))) && (!desc.HasSetter() || - (current.HasSetter() && JSTaggedValue::SameValue(current.GetSetter(), desc.GetSetter())))) { + (current.HasSetter() && JSTaggedValue::SameValue(thread, current.GetSetter(), desc.GetSetter())))) { return true; } @@ -1560,12 +1561,12 @@ bool JSObject::ValidateAndApplyPropertyDescriptor(ObjectOperator *op, bool exten if (!current.IsConfigurable()) { // i. Return false, if the [[Set]] field of Desc is present and SameValue(Desc.[[Set]], current.[[Set]]) // is false. - if (desc.HasSetter() && !JSTaggedValue::SameValue(current.GetSetter(), desc.GetSetter())) { + if (desc.HasSetter() && !JSTaggedValue::SameValue(thread, current.GetSetter(), desc.GetSetter())) { return false; } // ii. Return false, if the [[Get]] field of Desc is present and SameValue(Desc.[[Get]], // current.[[Get]]) is false. - if (desc.HasGetter() && !JSTaggedValue::SameValue(current.GetGetter(), desc.GetGetter())) { + if (desc.HasGetter() && !JSTaggedValue::SameValue(thread, current.GetGetter(), desc.GetGetter())) { return false; } } @@ -1581,8 +1582,8 @@ bool JSObject::ValidateAndApplyPropertyDescriptor(ObjectOperator *op, bool exten PropertyDescriptor newDesc = desc; JSHandle valueHandle = current.GetValue(); if (valueHandle->IsPropertyBox()) { - JSTaggedValue value = PropertyBox::Cast(valueHandle->GetTaggedObject())->GetValue(); - valueHandle = JSHandle(op->GetThread(), value); + JSTaggedValue value = PropertyBox::Cast(valueHandle->GetTaggedObject())->GetValue(thread); + valueHandle = JSHandle(thread, value); } newDesc.SetValue(valueHandle); op->UpdateDetector(); @@ -1603,10 +1604,10 @@ bool JSObject::IsCompatiblePropertyDescriptor(bool extensible, const PropertyDes return ValidateAndApplyPropertyDescriptor(&op, extensible, desc, current); } -JSTaggedValue JSObject::GetPrototype(const JSHandle &obj) +JSTaggedValue JSObject::GetPrototype(const JSThread *thread, const JSHandle &obj) { JSHClass *hclass = obj->GetJSHClass(); - return hclass->GetPrototype(); + return hclass->GetPrototype(thread); } bool JSObject::SetPrototype(JSThread *thread, const JSHandle &obj, @@ -1614,7 +1615,7 @@ bool JSObject::SetPrototype(JSThread *thread, const JSHandle &obj, bool isChangeProto) { ASSERT_PRINT(proto->IsECMAObject() || proto->IsNull(), "proto must be object or null"); - JSTaggedValue current = JSObject::GetPrototype(obj); + JSTaggedValue current = JSObject::GetPrototype(thread, obj); if (current == proto.GetTaggedValue()) { return true; } @@ -1626,7 +1627,7 @@ bool JSObject::SetPrototype(JSThread *thread, const JSHandle &obj, while (!done) { if (tempProtoHandle->IsNull() || !tempProtoHandle->IsECMAObject()) { done = true; - } else if (JSTaggedValue::SameValue(tempProtoHandle.GetTaggedValue(), obj.GetTaggedValue())) { + } else if (JSTaggedValue::SameValue(thread, tempProtoHandle.GetTaggedValue(), obj.GetTaggedValue())) { return false; } else { if (tempProtoHandle->IsJSProxy()) { @@ -1692,7 +1693,7 @@ bool JSObject::PreventExtensions(JSThread *thread, const JSHandle &obj JSHandle JSObject::GetOwnPropertyKeys(JSThread *thread, const JSHandle &obj) { uint32_t numOfElements = obj->GetNumberOfElements(thread); - uint32_t keyLen = numOfElements + obj->GetNumberOfKeys(); + uint32_t keyLen = numOfElements + obj->GetNumberOfKeys(thread); JSHandle keyArray = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(keyLen); @@ -1709,7 +1710,7 @@ JSHandle JSObject::GetAllPropertyKeys(JSThread *thread, const JSHan JSMutableHandle currentObjValue(thread, currentObj); uint32_t curObjNumberOfElements = currentObj->GetNumberOfElements(thread); - uint32_t curObjNumberOfKeys = currentObj->GetNumberOfKeys(); + uint32_t curObjNumberOfKeys = currentObj->GetNumberOfKeys(thread); uint32_t curObjectKeysLength = curObjNumberOfElements + curObjNumberOfKeys; uint32_t retArrayLength = curObjectKeysLength; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -1718,7 +1719,7 @@ JSHandle JSObject::GetAllPropertyKeys(JSThread *thread, const JSHan do { curObjNumberOfElements = currentObj->GetNumberOfElements(thread); - curObjNumberOfKeys = currentObj->GetNumberOfKeys(); + curObjNumberOfKeys = currentObj->GetNumberOfKeys(thread); curObjectKeysLength = curObjNumberOfElements + curObjNumberOfKeys; uint32_t minRequireLength = curObjectKeysLength + retArrayEffectivelength; if (retArrayLength < minRequireLength) { @@ -1738,7 +1739,7 @@ JSHandle JSObject::GetAllPropertyKeys(JSThread *thread, const JSHan if (!isInculdePrototypes) { break; } - currentObj.Update(GetPrototype(currentObj)); + currentObj.Update(GetPrototype(thread, currentObj)); currentObjValue.Update(currentObj); } while (currentObjValue->IsHeapObject()); @@ -1748,7 +1749,7 @@ JSHandle JSObject::GetAllPropertyKeys(JSThread *thread, const JSHan JSMutableHandle element(thread, JSTaggedValue::Undefined()); if (filter & NATIVE_KEY_NUMBERS_TO_STRINGS) { for (uint32_t i = 0; i < retArrayEffectivelength; i++) { - element.Update(retArray->Get(i)); + element.Update(retArray->Get(thread, i)); if (element->IsNumber()) { retArray->Set(thread, i, base::NumberHelper::NumberToString(thread, JSTaggedValue(element->GetNumber()))); @@ -1758,7 +1759,7 @@ JSHandle JSObject::GetAllPropertyKeys(JSThread *thread, const JSHan uint32_t elementIndex = 0; if (filter & NATIVE_KEY_SKIP_STRINGS) { while ((retArrayEffectivelength > 0) && (elementIndex < retArrayEffectivelength)) { - if (retArray->Get(elementIndex).IsString()) { + if (retArray->Get(thread, elementIndex).IsString()) { TaggedArray::RemoveElementByIndex(thread, retArray, elementIndex, retArrayEffectivelength); retArrayEffectivelength--; } else { @@ -1778,17 +1779,17 @@ void JSObject::CollectEnumKeys(JSThread *thread, const JSHandle &obj, { ASSERT(!obj->IsJSGlobalObject()); - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); if (!array->IsDictionaryMode()) { JSHClass *jsHclass = obj->GetJSHClass(); int end = static_cast(jsHclass->NumberOfProps()); if (end > 0) { - LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()) + LayoutInfo::Cast(jsHclass->GetLayout(thread).GetTaggedObject()) ->GetAllEnumKeys(thread, end, *keys, keyArray, keys, shadowQueue, lastLength); } return; } - NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); + NameDictionary *dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->GetAllEnumKeys(thread, *keys, keyArray, keys, shadowQueue, lastLength); } @@ -1807,7 +1808,7 @@ void JSObject::AppendOwnEnumPropertyKeys(JSThread *thread, const JSHandle JSObject::GetOwnEnumPropertyKeys(JSThread *thread, const JSHandle &obj) { uint32_t numOfElements = obj->GetNumberOfElements(thread); - uint32_t keyLen = numOfElements + obj->GetNumberOfKeys(); + uint32_t keyLen = numOfElements + obj->GetNumberOfKeys(thread); JSHandle keyArray = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(keyLen); @@ -1956,10 +1957,10 @@ bool JSObject::SetIntegrityLevel(JSThread *thread, const JSHandle &obj if (length == 0) { return true; } - auto key = jshandleKeys->Get(0); + auto key = jshandleKeys->Get(thread, 0); JSMutableHandle handleKey(thread, key); for (uint32_t i = 0; i < length; i++) { - auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); + auto taggedKey = JSTaggedValue(jshandleKeys->Get(thread, i)); handleKey.Update(taggedKey); [[maybe_unused]] bool success = JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(obj), handleKey, descNoConf); @@ -1970,10 +1971,10 @@ bool JSObject::SetIntegrityLevel(JSThread *thread, const JSHandle &obj if (length == 0) { return true; } - auto key = jshandleKeys->Get(0); + auto key = jshandleKeys->Get(thread, 0); JSMutableHandle handleKey(thread, key); for (uint32_t i = 0; i < length; i++) { - auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); + auto taggedKey = JSTaggedValue(jshandleKeys->Get(thread, i)); handleKey.Update(taggedKey); PropertyDescriptor currentDesc(thread); bool curDescStatus = @@ -2005,18 +2006,18 @@ bool JSObject::FreezeSharedObject(JSThread *thread, const JSHandle &ob auto newClass = JSHClass::Clone(thread, hclass); if (!hclass->IsDictionaryMode()) { uint32_t propNumber = hclass->NumberOfProps(); - JSHandle layoutInfo(thread, hclass->GetLayout()); + JSHandle layoutInfo(thread, hclass->GetLayout(thread)); JSHandle newLayoutInfo = factory->CreateSLayoutInfo(propNumber); for (uint32_t i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); - PropertyAttributes attr = layoutInfo->GetAttr(i); + JSTaggedValue key = layoutInfo->GetKey(thread, i); + PropertyAttributes attr = layoutInfo->GetAttr(thread, i); attr.SetWritable(false); newLayoutInfo->AddKey(thread, i, key, attr); } newClass->SetLayout(thread, newLayoutInfo); obj->SynchronizedTransitionClass(thread, *newClass); } else { - auto dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); + auto dict = NameDictionary::Cast(obj->GetProperties(thread).GetTaggedObject()); dict->UpdateAllAttributesToNoWitable(thread); } return true; @@ -2042,10 +2043,10 @@ bool JSObject::TestIntegrityLevel(JSThread *thread, const JSHandle &ob if (length == 0) { return true; } - auto key = jshandleKeys->Get(0); + auto key = jshandleKeys->Get(thread, 0); JSMutableHandle handleKey(thread, key); for (uint32_t i = 0; i < length; i++) { - auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); + auto taggedKey = JSTaggedValue(jshandleKeys->Get(thread, i)); handleKey.Update(taggedKey); PropertyDescriptor currentDesc(thread); bool curDescStatus = @@ -2106,7 +2107,7 @@ JSHandle JSObject::EnumerableOwnNames(JSThread *thread, const JSHan JSHandle names = factory->NewTaggedArray(length); JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i++) { - keyHandle.Update(keys->Get(i)); + keyHandle.Update(keys->Get(thread, i)); if (keyHandle->IsString()) { PropertyDescriptor desc(thread); bool status = JSTaggedValue::GetOwnProperty(thread, JSHandle(obj), @@ -2247,19 +2248,19 @@ JSHandle JSObject::GetFunctionRealm(JSThread *thread, const JSHandle< // 3. If obj is a Bound Function exotic object, then if (object->IsBoundFunction()) { // a. Let target be obj’s [[BoundTargetFunction]] internal slot. - JSHandle target(thread, JSHandle(object)->GetBoundTarget()); + JSHandle target(thread, JSHandle(object)->GetBoundTarget(thread)); // b. Return GetFunctionRealm(target). return GetFunctionRealm(thread, target); } // 4. If obj is a Proxy exotic object, then if (object->IsJSProxy()) { // a. If the value of the [[ProxyHandler]] internal slot of obj is null, throw a TypeError exception. - if (JSHandle(object)->GetHandler().IsNull()) { + if (JSHandle(object)->GetHandler(thread).IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSObject::GetFunctionRealm: handler is null", JSHandle(thread, JSTaggedValue::Exception())); } // b. Let proxyTarget be the value of obj’s [[ProxyTarget]] internal slot. - JSHandle proxyTarget(thread, JSHandle(object)->GetTarget()); + JSHandle proxyTarget(thread, JSHandle(object)->GetTarget(thread)); return GetFunctionRealm(thread, proxyTarget); } @@ -2268,10 +2269,10 @@ JSHandle JSObject::GetFunctionRealm(JSThread *thread, const JSHandle< return thread->GetGlobalEnv(); } - JSTaggedValue functionEnv = JSHandle(object)->GetLexicalEnv(); + JSTaggedValue functionEnv = JSHandle(object)->GetLexicalEnv(thread); // currentEnv is LexicalEnv/GlobalEnv for normal function, and is SFunctionEnv/Undefined for SharedFunction. if (functionEnv.IsHeapObject()) { - return JSHandle(thread, BaseEnv::Cast(functionEnv.GetTaggedObject())->GetGlobalEnv()); + return JSHandle(thread, BaseEnv::Cast(functionEnv.GetTaggedObject())->GetGlobalEnv(thread)); } return thread->GetGlobalEnv(); } @@ -2383,22 +2384,22 @@ bool JSObject::ToPropertyDescriptorFast(JSThread *thread, const JSHandleGetEcmaVM()->GetGlobalEnv(); auto globalConst = thread->GlobalConstants(); - if (hclass->GetPrototype() != env->GetObjectFunctionPrototype().GetTaggedValue()) { + if (hclass->GetPrototype(thread) != env->GetObjectFunctionPrototype().GetTaggedValue()) { return false; } - if (JSObject::Cast(hclass->GetPrototype().GetTaggedObject())->GetClass() != + if (JSObject::Cast(hclass->GetPrototype(thread).GetTaggedObject())->GetClass() != env->GetObjectFunctionPrototypeClass().GetObject()) { return false; } - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); uint32_t propsNumber = hclass->NumberOfProps(); for (uint32_t i = 0; i < propsNumber; i++) { - auto attr = layoutInfo->GetAttr(i); + auto attr = layoutInfo->GetAttr(thread, i); if (attr.IsAccessor()) { return false; } - auto key = layoutInfo->GetKey(i); - auto value = JSObject::Cast(obj->GetTaggedObject())->GetProperty(hclass, attr); + auto key = layoutInfo->GetKey(thread, i); + auto value = JSObject::Cast(obj->GetTaggedObject())->GetProperty(thread, hclass, attr); if (key == globalConst->GetEnumerableString()) { bool enumerable = value.ToBoolean(); desc.SetEnumerable(enumerable); @@ -2536,15 +2537,15 @@ const CString JSObject::ExtractConstructorAndRecordName(JSThread *thread, Tagged } JSFunctionBase *func = JSFunctionBase::Cast(objConstructor.GetTaggedObject()); - Method *method = Method::Cast(func->GetMethod().GetTaggedObject()); - MethodLiteral *methodLiteral = method->GetMethodLiteral(); + Method *method = Method::Cast(func->GetMethod(thread).GetTaggedObject()); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); if (methodLiteral == nullptr) { return "JSObject"; } - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); panda_file::File::EntityId methodId = methodLiteral->GetMethodId(); const CString &nameStr = MethodLiteral::ParseFunctionNameToCString(jsPandaFile, methodId); - const CString &moduleStr = method->GetRecordNameStr(); + const CString &moduleStr = method->GetRecordNameStr(thread); DebugInfoExtractor *debugExtractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(jsPandaFile); if (debugExtractor == nullptr) { @@ -2702,7 +2703,7 @@ bool JSObject::IsSimpleEnumCacheValid(JSThread *thread, JSTaggedValue receiver) return false; } - JSTaggedValue current = JSObject::GetPrototype(receiver); + JSTaggedValue current = JSObject::GetPrototype(thread, receiver); // Since current isn't a heapObject, the receiver's proto chain has no keys. if (!current.IsHeapObject()) { return true; @@ -2710,8 +2711,8 @@ bool JSObject::IsSimpleEnumCacheValid(JSThread *thread, JSTaggedValue receiver) // Check protoChainInfoEnumCache of receiver's proto == JSTaggedValue::Undefined. JSHClass *hclass = current.GetTaggedObject()->GetClass(); - JSTaggedValue enumCache = hclass->GetEnumCache(); - if (!enumCache.IsEnumCacheProtoInfoUndefined()) { + JSTaggedValue enumCache = hclass->GetEnumCache(thread); + if (!enumCache.IsEnumCacheProtoInfoUndefined(thread)) { return false; } @@ -2722,7 +2723,7 @@ bool JSObject::IsSimpleEnumCacheValid(JSThread *thread, JSTaggedValue receiver) if (numOfCurrentElements > 0) { return false; } - current = JSObject::GetPrototype(current); + current = JSObject::GetPrototype(thread, current); } return true; } @@ -2740,15 +2741,15 @@ bool JSObject::IsProtoChainCacheValid(JSThread *thread, JSTaggedValue receiver) return false; } - JSTaggedValue current = JSObject::GetPrototype(receiver); + JSTaggedValue current = JSObject::GetPrototype(thread, receiver); if (!current.IsHeapObject()) { return false; } // Check receiver.proto.EnumCacheAll == receiver.ProtoChainInfoEnumCache. - JSTaggedValue enumCacheOwn = receiver.GetTaggedObject()->GetClass()->GetEnumCache(); - JSTaggedValue enumCacheProto = current.GetTaggedObject()->GetClass()->GetEnumCache(); - if (!EnumCache::CheckSelfAndProtoEnumCache(enumCacheOwn, enumCacheProto)) { + JSTaggedValue enumCacheOwn = receiver.GetTaggedObject()->GetClass()->GetEnumCache(thread); + JSTaggedValue enumCacheProto = current.GetTaggedObject()->GetClass()->GetEnumCache(thread); + if (!EnumCache::CheckSelfAndProtoEnumCache(thread, enumCacheOwn, enumCacheProto)) { return false; } @@ -2759,7 +2760,7 @@ bool JSObject::IsProtoChainCacheValid(JSThread *thread, JSTaggedValue receiver) if (numOfCurrentElements > 0) { return false; } - current = JSObject::GetPrototype(current); + current = JSObject::GetPrototype(thread, current); } return true; } @@ -2769,19 +2770,19 @@ JSTaggedValue JSObject::TryGetEnumCache(JSThread *thread, JSTaggedValue obj) if (obj.IsSlowKeysObject() || obj.GetTaggedObject()->GetClass()->IsDictionaryMode()) { return JSTaggedValue::Undefined(); } - JSTaggedValue enumCacheValue = obj.GetTaggedObject()->GetClass()->GetEnumCache(); + JSTaggedValue enumCacheValue = obj.GetTaggedObject()->GetClass()->GetEnumCache(thread); if (enumCacheValue.IsEnumCache()) { EnumCacheKind kind = JSObject::GetEnumCacheKind(enumCacheValue); EnumCache* enumCache = EnumCache::Cast(enumCacheValue.GetTaggedObject()); switch (kind) { case EnumCacheKind::SIMPLE: if (IsSimpleEnumCacheValid(thread, obj)) { - return enumCache->GetEnumCacheAll(); + return enumCache->GetEnumCacheAll(thread); } break; case EnumCacheKind::PROTOCHAIN: if (IsProtoChainCacheValid(thread, obj)) { - return enumCache->GetEnumCacheAll(); + return enumCache->GetEnumCacheAll(thread); } break; default: @@ -2814,7 +2815,7 @@ JSHandle JSObject::EnumerateObjectProperties(JSThread *thread, keys.Update(TryGetEnumCache(thread, object.GetTaggedValue())); if (!keys->IsUndefined()) { cachedHclass.Update(JSTaggedValue(JSHandle::Cast(object)->GetJSHClass())); - JSTaggedValue enumCache = JSHandle::Cast(object)->GetJSHClass()->GetEnumCache(); + JSTaggedValue enumCache = JSHandle::Cast(object)->GetJSHClass()->GetEnumCache(thread); uint32_t enumCacheKind = EnumCache::Cast(enumCache)->GetEnumCacheKind(); return thread->GetEcmaVM()->GetFactory()->NewJSForinIterator(object, keys, cachedHclass, enumCacheKind); } @@ -2859,7 +2860,7 @@ void JSObject::DefinePropertyByLiteral(JSThread *thread, const JSHandle JSObject::CreateObjectFromProperties(const JSThread *thread, size_t length = properties->GetLength(); uint32_t propsLen = 0; for (size_t i = 0; i < length; i += 2) { // 2: skip a pair of key and value - if (properties->Get(i).IsHole()) { + if (properties->Get(thread, i).IsHole()) { break; } propsLen++; @@ -2909,7 +2910,7 @@ JSHandle JSObject::CreateObjectFromProperties(const JSThread *thread, isLiteral = true; } if (hclass->IsAOT()) { - if (CheckPropertiesForRep(properties, propsLen, hclass)) { + if (CheckPropertiesForRep(thread, properties, propsLen, hclass)) { return CreateObjectFromPropertiesByIHClass(thread, properties, propsLen, hclass, TrackTypeUpdateMode::DISABLE); } else if (!isLiteral) { @@ -2934,9 +2935,9 @@ JSHandle JSObject::CreateObjectFromProperties(const JSThread *thread, for (size_t i = 0; i < propsLen; i++) { PropertyAttributes attr = PropertyAttributes::Default(); // 2: literal contains a pair of key-value - valueHandle.Update(properties->Get(i * 2 + 1)); + valueHandle.Update(properties->Get(thread, i * 2 + 1)); // 2: literal contains a pair of key-value - keyHandle.Update(properties->Get(i * 2)); + keyHandle.Update(properties->Get(thread, i * 2)); JSHandle newDict = NameDictionary::PutIfAbsent(thread, dict, keyHandle, valueHandle, attr); dict.Update(newDict); } @@ -2957,10 +2958,10 @@ JSHandle JSObject::CreateObjectFromPropertiesByIHClass(const JSThread bool needTrack = (trackMode == TrackTypeUpdateMode::ENABLE) && thread->IsPGOProfilerEnable(); JSHClass *layoutHClass = obj->GetJSHClass(); bool isShared = layoutHClass->IsJSShared(); - LayoutInfo *layoutInfo = LayoutInfo::Cast(layoutHClass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(layoutHClass->GetLayout(thread).GetTaggedObject()); for (size_t i = 0; i < propsLen; i++) { - auto attr = layoutInfo->GetAttr(i); - auto value = properties->Get(i * JSObject::PAIR_SIZE + JSObject::VALUE_OFFSET); + auto attr = layoutInfo->GetAttr(thread, i); + auto value = properties->Get(thread, i * JSObject::PAIR_SIZE + JSObject::VALUE_OFFSET); if (needTrack && attr.UpdateTrackType(value) && !isShared) { layoutInfo->SetNormalAttr(thread, i, attr); } @@ -2971,13 +2972,13 @@ JSHandle JSObject::CreateObjectFromPropertiesByIHClass(const JSThread return obj; } -bool JSObject::CheckPropertiesForRep( +bool JSObject::CheckPropertiesForRep(const JSThread *thread, const JSHandle &properties, uint32_t propsLen, const JSHandle &ihc) { - auto layout = LayoutInfo::Cast(ihc->GetLayout().GetTaggedObject()); + auto layout = LayoutInfo::Cast(ihc->GetLayout(thread).GetTaggedObject()); for (size_t i = 0; i < propsLen; i++) { - auto attr = layout->GetAttr(i); - auto value = JSObject::ConvertValueWithRep(attr, properties->Get(i * 2 + 1)); + auto attr = layout->GetAttr(thread, i); + auto value = JSObject::ConvertValueWithRep(attr, properties->Get(thread, i * 2 + 1)); // If value.first is false, indicating that value cannot be converted to the expected value of // representation. For example, the representation is INT, but the value type is string. if (!value.first) { @@ -3001,8 +3002,8 @@ void JSObject::AddAccessor(JSThread *thread, const JSHandle &obj, bool JSObject::UpdatePropertyInDictionary(const JSThread *thread, JSTaggedValue key, JSTaggedValue value) { DISALLOW_GARBAGE_COLLECTION; - NameDictionary *dict = NameDictionary::Cast(GetProperties().GetTaggedObject()); - int entry = dict->FindEntry(key); + NameDictionary *dict = NameDictionary::Cast(GetProperties(thread).GetTaggedObject()); + int entry = dict->FindEntry(thread, key); if (entry == -1) { return false; } @@ -3031,7 +3032,7 @@ void JSObject::TrimInlinePropsSpace(const JSThread *thread, const JSHandle &obj) { - JSTaggedType hashField = Barriers::GetTaggedValue(*obj, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, *obj, HASH_OFFSET); JSTaggedValue value(hashField); if (value.IsHeapObject()) { // Hash position reserve in advance. @@ -3055,14 +3056,14 @@ void ECMAObject::SetHash(const JSThread *thread, int32_t hash, const JSHandleGet(array->GetExtraLength() + HASH_INDEX).GetInt(); + return array->Get(thread, array->GetExtraLength() + HASH_INDEX).GetInt(); } else { // Default is 0 return 0; @@ -3071,9 +3072,9 @@ int32_t ECMAObject::GetHash() const return value.GetInt(); } -bool ECMAObject::HasHash() const +bool ECMAObject::HasHash(const JSThread *thread) const { - JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, this, HASH_OFFSET); JSTaggedValue value(hashField); if (value.IsInt() && value.GetInt() == 0) { return false; @@ -3081,14 +3082,14 @@ bool ECMAObject::HasHash() const return true; } -void *ECMAObject::GetNativePointerField(int32_t index) const +void *ECMAObject::GetNativePointerField(const JSThread *thread, int32_t index) const { - JSTaggedType hashField = Barriers::GetTaggedValue(this, HASH_OFFSET); + JSTaggedType hashField = Barriers::GetTaggedValue(thread, this, HASH_OFFSET); JSTaggedValue value(hashField); if (value.IsTaggedArray()) { auto array = TaggedArray::Cast(value); if (static_cast(array->GetExtraLength()) > index) { - auto jsValue = array->Get(index); + auto jsValue = array->Get(thread, index); if (UNLIKELY(!jsValue.IsJSNativePointer())) { LOG_FULL(ERROR) << "jsValue is not js native pointer"; return nullptr; @@ -3105,7 +3106,7 @@ void ECMAObject::SetNativePointerField(const JSThread *thread, const JSHandle array(thread, value); @@ -3129,10 +3130,10 @@ void ECMAObject::SetNativePointerField(const JSThread *thread, const JSHandle value(thread, JSTaggedValue(hashField)); JSHandle object(obj); bool isShared = object->IsJSShared(); @@ -3160,8 +3161,8 @@ void ECMAObject::SetNativePointerFieldCount(const JSThread *thread, const JSHand isShared ? thread->GetEcmaVM()->GetFactory()->NewSTaggedArray(count + RESOLVED_MAX_SIZE) : thread->GetEcmaVM()->GetFactory()->NewTaggedArray(count + RESOLVED_MAX_SIZE); newArray->SetExtraLength(count); - newArray->Set(thread, count + HASH_INDEX, array->Get(HASH_INDEX)); - newArray->Set(thread, count + FUNCTION_EXTRA_INDEX, array->Get(FUNCTION_EXTRA_INDEX)); + newArray->Set(thread, count + HASH_INDEX, array->Get(thread, HASH_INDEX)); + newArray->Set(thread, count + FUNCTION_EXTRA_INDEX, array->Get(thread, FUNCTION_EXTRA_INDEX)); Barriers::SetObject(thread, *obj, HASH_OFFSET, newArray.GetTaggedValue().GetRawData()); } } else if (value->IsJSNativePointer()) { @@ -3185,10 +3186,10 @@ void ECMAObject::SetNativePointerFieldCount(const JSThread *thread, const JSHand } } -bool JSObject::ElementsAndPropertiesIsEmpty() const +bool JSObject::ElementsAndPropertiesIsEmpty(JSThread *thread) const { - if (TaggedArray::Cast(GetElements().GetTaggedObject())->GetLength() == 0 && - TaggedArray::Cast(GetProperties().GetTaggedObject())->GetLength() == 0) { + if (TaggedArray::Cast(GetElements(thread).GetTaggedObject())->GetLength() == 0 && + TaggedArray::Cast(GetProperties(thread).GetTaggedObject())->GetLength() == 0) { return true; } return false; @@ -3197,7 +3198,7 @@ bool JSObject::ElementsAndPropertiesIsEmpty() const void JSObject::TryMigrateToGenericKindForJSObject(const JSThread *thread, const JSHandle &obj, const ElementsKind oldKind) { - if (obj->IsJSArray() && HasMutantTaggedArrayElements(obj)) { + if (obj->IsJSArray() && HasMutantTaggedArrayElements(thread, obj)) { Elements::MigrateArrayWithKind(thread, obj, oldKind, ElementsKind::GENERIC); } } diff --git a/ecmascript/js_object.h b/ecmascript/js_object.h index 71b1aff4f3..55151019fc 100644 --- a/ecmascript/js_object.h +++ b/ecmascript/js_object.h @@ -338,7 +338,7 @@ public: { if (value_->IsPropertyBox()) { return JSHandle(thread_, - PropertyBox::Cast(value_.GetTaggedValue().GetTaggedObject())->GetValue()); + PropertyBox::Cast(value_.GetTaggedValue().GetTaggedObject())->GetValue(thread_)); } return value_; } @@ -373,26 +373,26 @@ public: void SetCallable(bool flag); bool IsCallable() const; - Method *GetCallTarget() const; - void *GetNativePointer() const; + Method *GetCallTarget(const JSThread *thread) const; + void *GetNativePointer(const JSThread *thread) const; static constexpr size_t HASH_OFFSET = TaggedObjectSize(); static constexpr size_t SIZE = HASH_OFFSET + sizeof(JSTaggedType); static void SetHash(const JSThread *thread, int32_t hash, const JSHandle &obj); - int32_t GetHash() const; - bool HasHash() const; + int32_t GetHash(const JSThread *thread) const; + bool HasHash(const JSThread *thread) const; void InitializeHash() { Barriers::SetPrimitive(this, ECMAObject::HASH_OFFSET, JSTaggedValue(0).GetRawData()); } - void* GetNativePointerField(int32_t index) const; + void* GetNativePointerField(const JSThread *thread, int32_t index) const; static void SetNativePointerField(const JSThread *thread, const JSHandle &obj, int32_t index, void *nativePointer, const NativePointerCallback &callBack, void *data, size_t nativeBindingsize = 0, Concurrent isConcurrent = Concurrent::NO); - int32_t GetNativePointerFieldCount() const; + int32_t GetNativePointerFieldCount(const JSThread *thread) const; static void SetNativePointerFieldCount(const JSThread *thread, const JSHandle &obj, int32_t count); DECL_VISIT_OBJECT(HASH_OFFSET, SIZE); @@ -484,9 +484,9 @@ public: // ecma6 9.1 // [[GetPrototypeOf]] - static JSTaggedValue GetPrototype(const JSHandle &obj); + static JSTaggedValue GetPrototype(const JSThread *thread, const JSHandle &obj); - static JSTaggedValue GetPrototype(JSTaggedValue obj); + static JSTaggedValue GetPrototype(const JSThread *thread, JSTaggedValue obj); // [[SetPrototypeOf]] static bool SetPrototype(JSThread *thread, const JSHandle &obj, @@ -652,11 +652,11 @@ public: bool IsJSAPILinkedListIterator() const; bool IsJSAPIListIterator() const; bool IsJSPrimitiveRef() const; - bool IsElementDict() const; - bool IsPropertiesDict() const; + bool IsElementDict(const JSThread *thread) const; + bool IsPropertiesDict(const JSThread *thread) const; bool IsTypedArray() const; bool IsSharedTypedArray() const; - bool PUBLIC_API ElementsAndPropertiesIsEmpty() const; + bool PUBLIC_API ElementsAndPropertiesIsEmpty(JSThread *thread) const; static PUBLIC_API void DefinePropertyByLiteral(JSThread *thread, const JSHandle &obj, const JSHandle &key, @@ -674,11 +674,12 @@ public: uint32_t propsLen, const JSHandle &ihc, TrackTypeUpdateMode trackMode); - static bool CheckPropertiesForRep( + static bool CheckPropertiesForRep(const JSThread *thread, const JSHandle &properties, uint32_t propsLen, const JSHandle &ihc); static void GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, const JSHandle &keyArray); - static void GetAllKeysForSerialization(const JSHandle &obj, std::vector &keyVector); + static void GetAllKeysForSerialization(const JSThread *thread, const JSHandle &obj, + std::vector &keyVector); static void GetAllKeysByFilter(const JSThread *thread, const JSHandle &obj, uint32_t &keyArrayEffectivelength, @@ -694,8 +695,8 @@ public: static void GetALLElementKeysIntoVector(const JSThread *thread, const JSHandle &obj, std::vector &keyVector); - std::pair GetNumberOfEnumKeys() const; - uint32_t GetNumberOfKeys(); + std::pair GetNumberOfEnumKeys(const JSThread *thread) const; + uint32_t GetNumberOfKeys(const JSThread *thread); uint32_t GetNumberOfElements(JSThread *thread); static JSHandle GetEnumElementKeys(JSThread *thread, const JSHandle &obj, int offset, @@ -720,12 +721,12 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(ECMAObject, PROPERTIES_OFFSET, SIZE) - void Dump(std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; - void Dump() const DUMP_API_ATTR + void Dump(const JSThread *thread, std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; + void Dump(const JSThread *thread) const DUMP_API_ATTR { - Dump(std::cout); + Dump(thread, std::cout); } - void DumpForSnapshot(std::vector &vec) const; + void DumpForSnapshot(const JSThread *thread, std::vector &vec) const; static const CString ExtractConstructorAndRecordName(JSThread *thread, TaggedObject *obj, bool noAllocate = false, bool *isCallGetter = nullptr); @@ -745,15 +746,15 @@ public: template inline void SetPropertyInlinedProps(const JSThread *thread, const JSHClass *hclass, uint32_t index, JSTaggedValue value); - inline JSTaggedValue GetPropertyInlinedPropsWithRep(uint32_t index, PropertyAttributes attr) const; - inline JSTaggedValue GetPropertyInlinedPropsWithRep(const JSHClass *hclass, uint32_t index, + inline JSTaggedValue GetPropertyInlinedPropsWithRep(const JSThread* thread, uint32_t index, PropertyAttributes attr) const; + inline JSTaggedValue GetPropertyInlinedPropsWithRep(const JSThread* thread, const JSHClass *hclass, uint32_t index, PropertyAttributes attr) const; template - inline JSTaggedValue GetPropertyInlinedPropsWithSize() const; - inline JSTaggedValue GetPropertyInlinedProps(uint32_t index) const; - inline JSTaggedValue GetPropertyInlinedProps(const JSHClass *hclass, uint32_t index) const; - inline JSTaggedValue GetProperty(const JSHClass *hclass, PropertyAttributes attr) const; - PropertyBox* GetGlobalPropertyBox(JSThread *thread, const std::string& key); + inline JSTaggedValue GetPropertyInlinedPropsWithSize(const JSThread* thread) const; + inline JSTaggedValue GetPropertyInlinedProps(const JSThread* thread, uint32_t index) const; + inline JSTaggedValue GetPropertyInlinedProps(const JSThread* thread, const JSHClass *hclass, uint32_t index) const; + inline JSTaggedValue GetProperty(const JSThread* thread, const JSHClass *hclass, PropertyAttributes attr) const; + PropertyBox* GetGlobalPropertyBox(const JSThread *thread, const std::string& key); template inline void SetProperty(const JSThread *thread, const JSHClass *hclass, PropertyAttributes attr, JSTaggedValue value); @@ -812,8 +813,8 @@ private: friend class JSSharedArray; friend class builtins::BuiltinsArkTools; - static bool HasMutantTaggedArrayElements(const JSHandle &obj); - PropertyBox* GetGlobalPropertyBox(JSTaggedValue key); + static bool HasMutantTaggedArrayElements(const JSThread *thread, const JSHandle &obj); + PropertyBox* GetGlobalPropertyBox(const JSThread *thread, JSTaggedValue key); static bool CheckAndUpdateArrayLength(JSThread *thread, const JSHandle &receiver, uint32_t index, ElementsKind &kind); static bool PUBLIC_API AddElementInternal( diff --git a/ecmascript/js_plural_rules.cpp b/ecmascript/js_plural_rules.cpp index 2eaeb79856..4c51f9260e 100644 --- a/ecmascript/js_plural_rules.cpp +++ b/ecmascript/js_plural_rules.cpp @@ -22,10 +22,10 @@ namespace panda::ecmascript { constexpr int32_t STRING_SEPARATOR_LENGTH = 4; -icu::number::LocalizedNumberFormatter *JSPluralRules::GetIcuNumberFormatter() const +icu::number::LocalizedNumberFormatter *JSPluralRules::GetIcuNumberFormatter(JSThread *thread) const { - ASSERT(GetIcuNF().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuNF().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuNF(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuNF(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -50,7 +50,7 @@ void JSPluralRules::SetIcuNumberFormatter(JSThread *thread, const JSHandleGetNativeAreaAllocator()->New(icuNF); ASSERT(icuPointer != nullptr); - JSTaggedValue data = pluralRules->GetIcuNF(); + JSTaggedValue data = pluralRules->GetIcuNF(thread); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuPointer); @@ -60,10 +60,10 @@ void JSPluralRules::SetIcuNumberFormatter(JSThread *thread, const JSHandleSetIcuNF(thread, pointer.GetTaggedValue()); } -icu::PluralRules *JSPluralRules::GetIcuPluralRules() const +icu::PluralRules *JSPluralRules::GetIcuPluralRules(JSThread *thread) const { - ASSERT(GetIcuPR().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuPR().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuPR(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuPR(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -88,7 +88,7 @@ void JSPluralRules::SetIcuPluralRules(JSThread *thread, const JSHandleGetNativeAreaAllocator()->New(icuPR); ASSERT(icuPointer != nullptr); - JSTaggedValue data = pluralRules->GetIcuPR(); + JSTaggedValue data = pluralRules->GetIcuPR(thread); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuPointer); @@ -248,7 +248,7 @@ JSHandle JSPluralRules::InitializePluralRules(JSThread *thread, JSLocale::SetNumberFormatDigitOptions(thread, pluralRules, JSHandle::Cast(prOptions), MNFD_DEFAULT, MXFD_DEFAULT, NotationOption::STANDARD); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSPluralRules, thread); - icuNumberFormatter = JSNumberFormat::SetICUFormatterDigitOptions(icuNumberFormatter, pluralRules); + icuNumberFormatter = JSNumberFormat::SetICUFormatterDigitOptions(thread, icuNumberFormatter, pluralRules); // Set pluralRules.[[IcuPluralRules]] to icuPluralRules SetIcuPluralRules(thread, pluralRules, *icuPluralRules, JSPluralRules::FreeIcuPluralRules); @@ -289,8 +289,8 @@ JSHandle FormatNumericToString(JSThread *thread, const icu::number:: JSHandle JSPluralRules::ResolvePlural(JSThread *thread, const JSHandle &pluralRules, double n) { - icu::PluralRules *icuPluralRules = pluralRules->GetIcuPluralRules(); - icu::number::LocalizedNumberFormatter *icuFormatter = pluralRules->GetIcuNumberFormatter(); + icu::PluralRules *icuPluralRules = pluralRules->GetIcuPluralRules(thread); + icu::number::LocalizedNumberFormatter *icuFormatter = pluralRules->GetIcuNumberFormatter(thread); if (icuPluralRules == nullptr || icuFormatter == nullptr) { return JSHandle(thread, JSTaggedValue::Undefined()); } @@ -309,7 +309,7 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandle property = JSHandle::Cast(globalConst->GetHandledLocaleString()); - JSHandle locale(thread, pluralRules->GetLocale()); + JSHandle locale(thread, pluralRules->GetLocale(thread)); PropertyDescriptor localeDesc(thread, JSHandle::Cast(locale), true, true, true); JSObject::DefineOwnProperty(thread, options, property, localeDesc); @@ -326,7 +326,7 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandle::Cast(globalConst->GetHandledMinimumIntegerDigitsString()); - JSHandle minimumIntegerDigits(thread, pluralRules->GetMinimumIntegerDigits()); + JSHandle minimumIntegerDigits(thread, pluralRules->GetMinimumIntegerDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumIntegerDigits); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -334,23 +334,23 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandleGetHandledMinimumSignificantDigitsString(); - JSHandle minimumSignificantDigits(thread, pluralRules->GetMinimumSignificantDigits()); + JSHandle minimumSignificantDigits(thread, pluralRules->GetMinimumSignificantDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumSignificantDigits); RETURN_IF_ABRUPT_COMPLETION(thread); // [[MaximumSignificantDigits]] property = globalConst->GetHandledMaximumSignificantDigitsString(); - JSHandle maximumSignificantDigits(thread, pluralRules->GetMaximumSignificantDigits()); + JSHandle maximumSignificantDigits(thread, pluralRules->GetMaximumSignificantDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumSignificantDigits); RETURN_IF_ABRUPT_COMPLETION(thread); } else { // [[MinimumFractionDigits]] property = globalConst->GetHandledMinimumFractionDigitsString(); - JSHandle minimumFractionDigits(thread, pluralRules->GetMinimumFractionDigits()); + JSHandle minimumFractionDigits(thread, pluralRules->GetMinimumFractionDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, minimumFractionDigits); RETURN_IF_ABRUPT_COMPLETION(thread); // [[MaximumFractionDigits]] property = globalConst->GetHandledMaximumFractionDigitsString(); - JSHandle maximumFractionDigits(thread, pluralRules->GetMaximumFractionDigits()); + JSHandle maximumFractionDigits(thread, pluralRules->GetMaximumFractionDigits(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, property, maximumFractionDigits); RETURN_IF_ABRUPT_COMPLETION(thread); } @@ -360,7 +360,7 @@ void JSPluralRules::ResolvedOptions(JSThread *thread, const JSHandleGetIcuPluralRules(); + icu::PluralRules *icuPluralRules = pluralRules->GetIcuPluralRules(thread); ASSERT(icuPluralRules != nullptr); std::unique_ptr categories(icuPluralRules->getKeywords(status)); int32_t count = categories->count(status); diff --git a/ecmascript/js_plural_rules.h b/ecmascript/js_plural_rules.h index f22e2dd1c2..544feb5618 100644 --- a/ecmascript/js_plural_rules.h +++ b/ecmascript/js_plural_rules.h @@ -52,14 +52,14 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LOCALE_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() - icu::number::LocalizedNumberFormatter *GetIcuNumberFormatter() const; + icu::number::LocalizedNumberFormatter *GetIcuNumberFormatter(JSThread *thread) const; static void SetIcuNumberFormatter(JSThread *thread, const JSHandle &pluralRules, const icu::number::LocalizedNumberFormatter &icuNF, const NativePointerCallback &callback); static void FreeIcuNumberFormatter(void *env, void *pointer, void* hint = nullptr); - icu::PluralRules *GetIcuPluralRules() const; + icu::PluralRules *GetIcuPluralRules(JSThread *thread) const; static void SetIcuPluralRules(JSThread *thread, const JSHandle &pluralRules, const icu::PluralRules &icuPR, const NativePointerCallback &callback); diff --git a/ecmascript/js_primitive_ref.cpp b/ecmascript/js_primitive_ref.cpp index 0766e46b57..3ff301f1b3 100644 --- a/ecmascript/js_primitive_ref.cpp +++ b/ecmascript/js_primitive_ref.cpp @@ -51,14 +51,14 @@ bool JSPrimitiveRef::StringGetIndexProperty(const JSThread *thread, const JSHand { uint16_t tmpChar = 0; { - JSHandle strHandle(thread, EcmaString::Cast(JSPrimitiveRef::Cast(*obj)->GetValue())); + JSHandle strHandle(thread, EcmaString::Cast(JSPrimitiveRef::Cast(*obj)->GetValue(thread))); JSHandle strFlat(thread, EcmaStringAccessor::Flatten(thread->GetEcmaVM(), strHandle)); if (EcmaStringAccessor(strFlat).GetLength() <= index) { return false; } // 10. Let resultStr be a String value of length 1, containing one code unit from str, specifically the code // unit at index index - tmpChar = EcmaStringAccessor(strFlat).Get(index); + tmpChar = EcmaStringAccessor(strFlat).Get(thread, index); } JSHandle value(thread->GetEcmaVM()->GetFactory()->NewFromUtf16(&tmpChar, 1)); // 11. Return a PropertyDescriptor{ [[Value]]: resultStr, [[Enumerable]]: true, [[Writable]]: false, diff --git a/ecmascript/js_primitive_ref.h b/ecmascript/js_primitive_ref.h index 83de86f531..73be0e4433 100644 --- a/ecmascript/js_primitive_ref.h +++ b/ecmascript/js_primitive_ref.h @@ -37,40 +37,40 @@ public: JSPrimitiveRef() = delete; - bool IsNumber() const + bool IsNumber(const JSThread *thread) const { - return GetValue().IsNumber(); + return GetValue(thread).IsNumber(); } - bool IsBigInt() const + bool IsBigInt(const JSThread *thread) const { - return GetValue().IsBigInt(); + return GetValue(thread).IsBigInt(); } - bool IsInt() const + bool IsInt(const JSThread *thread) const { - return GetValue().IsInt(); + return GetValue(thread).IsInt(); } - bool IsBoolean() const + bool IsBoolean(const JSThread *thread) const { - return GetValue().IsBoolean(); + return GetValue(thread).IsBoolean(); } - bool IsString() const + bool IsString(const JSThread *thread) const { - return GetValue().IsString(); + return GetValue(thread).IsString(); } - bool IsSymbol() const + bool IsSymbol(const JSThread *thread) const { - return GetValue().IsSymbol(); + return GetValue(thread).IsSymbol(); } - uint32_t GetStringLength() const + uint32_t GetStringLength(const JSThread *thread) const { - ASSERT(IsString()); - return EcmaStringAccessor(GetValue()).GetLength(); + ASSERT(IsString(thread)); + return EcmaStringAccessor(GetValue(thread)).GetLength(); } // ES6 9.4.3 String Exotic Objects diff --git a/ecmascript/js_promise.cpp b/ecmascript/js_promise.cpp index fa9de1a313..7cb6ec9487 100644 --- a/ecmascript/js_promise.cpp +++ b/ecmascript/js_promise.cpp @@ -65,7 +65,7 @@ JSTaggedValue JSPromise::FulfillPromise(JSThread *thread, const JSHandleGetPromiseState() == PromiseState::PENDING, "FulfillPromise: state must be pending"); // 2. Let reactions be the value of promise's [[PromiseFulfillReactions]] internal slot. - JSHandle reactions(thread, promise->GetPromiseFulfillReactions()); + JSHandle reactions(thread, promise->GetPromiseFulfillReactions(thread)); // 3. Set the value of promise's [[PromiseResult]] internal slot to value. promise->SetPromiseResult(thread, value); // 4. Set the value of promise's [[PromiseFulfillReactions]] internal slot to undefined. @@ -96,8 +96,8 @@ JSHandle JSPromise::NewPromiseCapability(JSThread *thread, co JSHandle promise = factory->NewJSPromise(); JSHandle resolvingFunctions = JSPromise::CreateResolvingFunctions(thread, promise); promiseCapability->SetPromise(thread, promise); - auto resolveFunc = resolvingFunctions->GetResolveFunction(); - auto rejectFunc = resolvingFunctions->GetRejectFunction(); + auto resolveFunc = resolvingFunctions->GetResolveFunction(thread); + auto rejectFunc = resolvingFunctions->GetRejectFunction(thread); promiseCapability->SetResolve(thread, resolveFunc); promiseCapability->SetReject(thread, rejectFunc); return promiseCapability; @@ -117,12 +117,12 @@ JSHandle JSPromise::NewPromiseCapability(JSThread *thread, co JSHandle promise(thread, result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, factory->NewPromiseCapability()); // 8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception. - if (!promiseCapability->GetResolve().IsCallable()) { + if (!promiseCapability->GetResolve(thread).IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "NewPromiseCapability: resolve is not a callable function!", factory->NewPromiseCapability()); } // 9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception. - if (!promiseCapability->GetReject().IsCallable()) { + if (!promiseCapability->GetReject(thread).IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "NewPromiseCapability: reject is not a callable function!", factory->NewPromiseCapability()); } @@ -156,7 +156,7 @@ JSTaggedValue JSPromise::RejectPromise(JSThread *thread, const JSHandleGetPromiseState() == PromiseState::PENDING, "RejectPromise: state must be pending"); // 2. Let reactions be the value of promise's [[PromiseRejectReactions]] internal slot. - JSHandle reactions(thread, TaggedQueue::Cast(promise->GetPromiseRejectReactions().GetTaggedObject())); + JSHandle reactions(thread, TaggedQueue::Cast(promise->GetPromiseRejectReactions(thread).GetTaggedObject())); // 3. Set the value of promise's [[PromiseResult]] internal slot to reason. promise->SetPromiseResult(thread, reason); // 4. Set the value of promise's [[PromiseFulfillReactions]] internal slot to undefined. @@ -184,7 +184,7 @@ JSTaggedValue JSPromise::TriggerPromiseReactions(JSThread *thread, const JSHandl ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle promiseReactionsJob(globalEnv->GetPromiseReactionJob()); JSMutableHandle reaction(thread, JSTaggedValue::Undefined()); - while (!reactions->Empty()) { + while (!reactions->Empty(thread)) { reaction.Update(reactions->Pop(thread)); JSHandle arguments = factory->NewTaggedArray(2); // 2 means the length of new array arguments->Set(thread, 0, reaction); diff --git a/ecmascript/js_proxy.cpp b/ecmascript/js_proxy.cpp index c866097542..1bf8e7308d 100644 --- a/ecmascript/js_proxy.cpp +++ b/ecmascript/js_proxy.cpp @@ -50,7 +50,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle &p STACK_LIMIT_CHECK(thread, JSTaggedValue::Exception()); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. - JSHandle handler(thread, proxy->GetHandler()); + JSHandle handler(thread, proxy->GetHandler(thread)); // 2. If handler is null, throw a TypeError exception. if (handler->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetPrototype: handler is null", JSTaggedValue::Exception()); @@ -58,7 +58,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle &p // 3. Assert: Type(handler) is Object. ASSERT(handler->IsECMAObject()); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); // 5. Let trap be GetMethod(handler, "getPrototypeOf"). JSHandle name(globalConst->GetHandledGetPrototypeOfString()); JSHandle trap = JSObject::GetMethod(thread, handler, name); @@ -96,7 +96,7 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle &p // 15. ReturnIfAbrupt(targetProto). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. If SameValue(handlerProto, targetProto) is false, throw a TypeError exception. - if (!JSTaggedValue::SameValue(handlerProto.GetTaggedValue(), targetProto)) { + if (!JSTaggedValue::SameValue(thread, handlerProto.GetTaggedValue(), targetProto)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetPrototype: SameValue(handlerProto, targetProto) is false", JSTaggedValue::Exception()); } @@ -112,7 +112,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con // 1. Assert: Either Type(V) is Object or Type(V) is Null. ASSERT(proto->IsECMAObject() || proto->IsNull()); // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); // 3. If handler is null, throw a TypeError exception. if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetPrototype: handler is null", false); @@ -120,7 +120,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con // 4. Assert: Type(handler) is Object. ASSERT(handler.IsECMAObject()); // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); // 6. Let trap be GetMethod(handler, "setPrototypeOf"). JSHandle name = globalConst->GetHandledSetPrototypeOfString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); @@ -131,7 +131,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con if (trap->IsUndefined()) { return JSTaggedValue::SetPrototype(thread, targetHandle, proto); } - JSHandle handlerTag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 2; // 2: target and proto JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); @@ -160,7 +160,7 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); // 16. If booleanTrapResult is true and SameValue(V, targetProto) is false, throw a TypeError exception. - if (booleanTrapResult && !JSTaggedValue::SameValue(proto.GetTaggedValue(), targetProto)) { + if (booleanTrapResult && !JSTaggedValue::SameValue(thread, proto.GetTaggedValue(), targetProto)) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetPrototype: TypeError of targetProto and Result", false); } // 17. Return handlerProto. @@ -173,7 +173,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) STACK_LIMIT_CHECK(thread, false); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); // 2. If handler is null, throw a TypeError exception. if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::IsExtensible: handler is null", false); @@ -181,7 +181,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) // 3. Assert: Type(handler) is Object. ASSERT(handler.IsECMAObject()); // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); // 5. Let trap be GetMethod(handler, "isExtensible"). JSHandle name = globalConst->GetHandledIsExtensibleString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); @@ -194,7 +194,7 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) } // 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). JSHandle newTgt(thread, JSTaggedValue::Undefined()); - JSHandle handlerTag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -231,12 +231,12 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle &proxy // a. Return target.[[PreventExtensions]](). // 8. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target»)). // 9. ReturnIfAbrupt(booleanTrapResult). - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::PreventExtensions: handler is null", false); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledPreventExtensionsString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 6. ReturnIfAbrupt(trap). @@ -245,7 +245,7 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle &proxy if (trap->IsUndefined()) { return JSTaggedValue::PreventExtensions(thread, targetHandle); } - JSHandle handlerTag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -285,12 +285,12 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle &proxy, c // 9. Let trapResultObj be Call(trap, handler, «target, P»). // 10. ReturnIfAbrupt(trapResultObj). // 11. If Type(trapResultObj) is neither Object nor Undefined, throw a TypeError exception - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetOwnProperty: handler is null", false); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledGetOwnPropertyDescriptorString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). @@ -299,7 +299,7 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle &proxy, c if (trap->IsUndefined()) { return JSTaggedValue::GetOwnProperty(thread, targetHandle, key, desc); } - JSHandle handlerTag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 2; // 2: target and key JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); @@ -378,12 +378,12 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle &proxy const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DefineOwnProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledDefinePropertyString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). @@ -394,7 +394,7 @@ 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()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 3; // 3: target, key and desc JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); @@ -461,12 +461,12 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle &proxy, cons const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::HasProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledHasString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). @@ -476,7 +476,7 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle &proxy, cons } // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). - JSHandle handlerTag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 2; // 2: target and key JSHandle undefined = globalConst->GetHandledUndefined(); @@ -531,7 +531,7 @@ OperationResult JSProxy::CheckGetTrapResult(JSThread *thread, const JSHandle & const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); JSHandle exceptionHandle(thread, JSTaggedValue::Exception()); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::GetProperty: handler is Null", OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledGetString(); JSHandle trap(JSObject::FastGetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). @@ -579,7 +579,7 @@ OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle & return JSTaggedValue::GetProperty(thread, targetHandle, key, receiver); } // 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). - JSHandle handlerTag(thread, proxy->GetHandler()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 3; // 3: «target, P, Receiver» JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); @@ -609,7 +609,7 @@ bool JSProxy::CheckSetTrapResult(JSThread *thread, const JSHandle // false, then if (targetDesc.IsDataDescriptor() && !targetDesc.IsConfigurable() && !targetDesc.IsWritable()) { // i. If SameValue(trapResult, targetDesc.[[Value]]) is false, throw a TypeError exception. - if (!JSTaggedValue::SameValue(value, targetDesc.GetValue())) { + if (!JSTaggedValue::SameValue(thread, value, targetDesc.GetValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetProperty: TypeError of trapResult", false); } } @@ -631,12 +631,12 @@ bool JSProxy::SetProperty(JSThread *thread, const JSHandle &proxy, cons const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 10 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::SetProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledSetString(); JSHandle trap(JSObject::FastGetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). @@ -646,7 +646,7 @@ 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()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 4; // 4: «target, P, V, Receiver» JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); @@ -674,12 +674,12 @@ bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle &proxy, c const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 13 are almost same as GetOwnProperty ASSERT(JSTaggedValue::IsPropertyKey(key)); - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::DeleteProperty: handler is Null", false); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle name = globalConst->GetHandledDeletePropertyString(); JSHandle trap(JSObject::GetMethod(thread, JSHandle(thread, handler), name)); // 7. ReturnIfAbrupt(trap). @@ -690,7 +690,7 @@ 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()); + JSHandle handlerTag(thread, proxy->GetHandler(thread)); const uint32_t argsLength = 2; // 2: target and key JSHandle undefined = globalConst->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); @@ -728,14 +728,14 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< STACK_LIMIT_CHECK(thread, JSHandle(thread, JSTaggedValue::Exception())); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 4 get ProxyHandler and ProxyTarget - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: handler is null", JSHandle(thread, JSTaggedValue::Exception())); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); // 5.Let trap be GetMethod(handler, "ownKeys"). JSHandle key = globalConst->GetHandledOwnKeysString(); @@ -768,7 +768,7 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< JSObject::CreateListFromArrayLike(thread, trapResArr)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - if (trapRes->HasDuplicateEntry()) { + if (trapRes->HasDuplicateEntry(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: contains duplicate entries", JSHandle(thread, JSTaggedValue::Exception())); } @@ -802,7 +802,7 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< uint32_t cfigLength = 0; uint32_t noCfigLength = 0; for (uint32_t i = 0; i < length; i++) { - JSHandle targetKey(thread, targetKeys->Get(i)); + JSHandle targetKey(thread, targetKeys->Get(thread, i)); ASSERT(targetKey->IsStringOrSymbol()); PropertyDescriptor desc(thread); @@ -833,7 +833,7 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // a.If key is not an element of uncheckedResultKeys, throw a TypeError exception. // b.Remove key from uncheckedResultKeys for (uint32_t i = 0; i < noCfigLength; i++) { - uint32_t idx = uncheckFesKeys->GetIdx(tgtNoCfigKeys->Get(i)); + uint32_t idx = uncheckFesKeys->GetIdx(thread, tgtNoCfigKeys->Get(thread, i)); if (idx == TaggedArray::MAX_ARRAY_INDEX) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: key is not an element of uncheckedResultKeys", JSHandle(thread, JSTaggedValue::Exception())); @@ -851,7 +851,7 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // a.If key is not an element of uncheckedResultKeys, throw a TypeError exception. // b.Remove key from uncheckedResultKeys for (uint32_t i = 0; i < cfigLength; i++) { - uint32_t idx = uncheckFesKeys->GetIdx(tgtCfigKeys->Get(i)); + uint32_t idx = uncheckFesKeys->GetIdx(thread, tgtCfigKeys->Get(thread, i)); if (idx == TaggedArray::MAX_ARRAY_INDEX) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: key is not an element of uncheckedResultKeys", JSHandle(thread, JSTaggedValue::Exception())); @@ -874,14 +874,14 @@ JSHandle JSProxy::GetAllPropertyKeys(JSThread *thread, const JSHand { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSTaggedValue handler = proxy->GetHandler(); + JSTaggedValue handler = proxy->GetHandler(thread); if (handler.IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: handler is null", JSHandle(thread, JSTaggedValue::Exception())); } ASSERT(handler.IsECMAObject()); - JSHandle targetHandle(thread, proxy->GetTarget()); + JSHandle targetHandle(thread, proxy->GetTarget(thread)); JSHandle key = globalConst->GetHandledOwnKeysString(); JSHandle handlerHandle(thread, handler); @@ -916,8 +916,8 @@ JSHandle JSProxy::GetAllPropertyKeys(JSThread *thread, const JSHand uint32_t elementIndex = 0; if (filter & NATIVE_KEY_SKIP_SYMBOLS) { for (uint32_t index = 0; index < reciveArrayLength; index++) { - if (!ownKeys->Get(index).IsSymbol()) { - resArray->Set(thread, elementIndex, reciveArray->Get(index)); + if (!ownKeys->Get(thread, index).IsSymbol()) { + resArray->Set(thread, elementIndex, reciveArray->Get(thread, index)); elementIndex++; } } @@ -925,12 +925,12 @@ JSHandle JSProxy::GetAllPropertyKeys(JSThread *thread, const JSHand } for (uint32_t i = 0; i < trapResLength; i++) { - resArray->Set(thread, i, trapRes->Get(i)); + resArray->Set(thread, i, trapRes->Get(thread, i)); } uint32_t index = ownKeysLength; for (uint32_t j = 0; j < reciveArrayLength - ownKeysLength; j++) { - resArray->Set(thread, trapResLength + j, reciveArray->Get(index)); + resArray->Set(thread, trapResLength + j, reciveArray->Get(thread, index)); index++; } return resArray; @@ -947,12 +947,12 @@ JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info) const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle proxy(info->GetFunction()); // step 1 ~ 4 get ProxyHandler and ProxyTarget - JSHandle handler(thread, proxy->GetHandler()); + JSHandle handler(thread, proxy->GetHandler(thread)); if (handler->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Call: handler is null", JSTaggedValue::Exception()); } ASSERT(handler->IsECMAObject()); - JSHandle target(thread, proxy->GetTarget()); + JSHandle target(thread, proxy->GetTarget(thread)); // 5.Let trap be GetMethod(handler, "apply"). JSHandle key(globalConst->GetHandledApplyString()); @@ -1004,12 +1004,12 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info) const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // step 1 ~ 4 get ProxyHandler and ProxyTarget JSHandle proxy(info->GetFunction()); - JSHandle handler(thread, proxy->GetHandler()); + JSHandle handler(thread, proxy->GetHandler(thread)); if (handler->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor: handler is null", JSTaggedValue::Exception()); } ASSERT(handler->IsECMAObject()); - JSHandle target(thread, proxy->GetTarget()); + JSHandle target(thread, proxy->GetTarget(thread)); // 5.Let trap be GetMethod(handler, "construct"). JSHandle key(globalConst->GetHandledProxyConstructString()); @@ -1070,19 +1070,19 @@ bool JSProxy::IsArray(JSThread *thread) const if (thread->DoStackLimitCheck()) { return false; } - if (GetHandler().IsNull()) { + if (GetHandler(thread).IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "JSProxy::IsArray: handler is null", false); } - return GetTarget().IsArray(thread); + return GetTarget(thread).IsArray(thread); } JSHandle JSProxy::GetSourceTarget(JSThread *thread) const { JSMutableHandle proxy(thread, JSTaggedValue(this)); - JSMutableHandle target(thread, proxy->GetTarget()); + JSMutableHandle target(thread, proxy->GetTarget(thread)); while (target->IsJSProxy()) { proxy.Update(target.GetTaggedValue()); - target.Update(proxy->GetTarget()); + target.Update(proxy->GetTarget(thread)); } return target; } diff --git a/ecmascript/js_regexp_iterator.cpp b/ecmascript/js_regexp_iterator.cpp index 4811b28f90..e907e0a5ab 100644 --- a/ecmascript/js_regexp_iterator.cpp +++ b/ecmascript/js_regexp_iterator.cpp @@ -49,8 +49,8 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) // 6. Let S be O.[[IteratedString]]. // 7. Let global be O.[[Global]]. // 8. Let fullUnicode be O.[[Unicode]]. - JSHandle regexp(thread, jsIterator->GetIteratingRegExp()); - JSHandle inputStr(thread, jsIterator->GetIteratedString()); + JSHandle regexp(thread, jsIterator->GetIteratingRegExp(thread)); + JSHandle inputStr(thread, jsIterator->GetIteratedString(thread)); bool global = jsIterator->GetGlobal(); bool fullUnicode = jsIterator->GetUnicode(); @@ -94,7 +94,7 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) uint32_t lastIndex = static_cast(BuiltinsRegExp::GetLastIndex(thread, regexp, isFastPath)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t nextIndex = static_cast( - BuiltinsRegExp::AdvanceStringIndex(inputStr, lastIndex, fullUnicode)); + BuiltinsRegExp::AdvanceStringIndex(thread, inputStr, lastIndex, fullUnicode)); BuiltinsRegExp::SetLastIndex(thread, regexp, JSTaggedValue(nextIndex), isFastPath); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } diff --git a/ecmascript/js_relative_time_format.cpp b/ecmascript/js_relative_time_format.cpp index 4c5dd59735..3d02118422 100644 --- a/ecmascript/js_relative_time_format.cpp +++ b/ecmascript/js_relative_time_format.cpp @@ -61,7 +61,7 @@ JSHandle JSRelativeTimeFormat::InitializeRelativeTimeForma if (EcmaStringAccessor(numberingSystemString).IsUtf16()) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", relativeTimeFormat); } - numberingSystemStdStr = intl::LocaleHelper::ConvertToStdString(numberingSystemString); + numberingSystemStdStr = intl::LocaleHelper::ConvertToStdString(thread, numberingSystemString); if (!JSLocale::IsNormativeNumberingSystem(numberingSystemStdStr)) { THROW_RANGE_ERROR_AND_RETURN(thread, "invalid numberingSystem", relativeTimeFormat); } @@ -201,29 +201,29 @@ bool SingularUnitToIcuUnit(JSThread *thread, const JSHandle &unit, U JSHandle quarters = JSHandle::Cast(globalConst->GetHandledQuartersString()); JSHandle years = JSHandle::Cast(globalConst->GetHandledYearsString()); - if (EcmaStringAccessor::StringsAreEqual(*second, *unit) || - EcmaStringAccessor::StringsAreEqual(*seconds, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *second, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *seconds, *unit)) { *unitEnum = UDAT_REL_UNIT_SECOND; - } else if (EcmaStringAccessor::StringsAreEqual(*minute, *unit) || - EcmaStringAccessor::StringsAreEqual(*minutes, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *minute, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *minutes, *unit)) { *unitEnum = UDAT_REL_UNIT_MINUTE; - } else if (EcmaStringAccessor::StringsAreEqual(*hour, *unit) || - EcmaStringAccessor::StringsAreEqual(*hours, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *hour, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *hours, *unit)) { *unitEnum = UDAT_REL_UNIT_HOUR; - } else if (EcmaStringAccessor::StringsAreEqual(*day, *unit) || - EcmaStringAccessor::StringsAreEqual(*days, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *day, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *days, *unit)) { *unitEnum = UDAT_REL_UNIT_DAY; - } else if (EcmaStringAccessor::StringsAreEqual(*week, *unit) || - EcmaStringAccessor::StringsAreEqual(*weeks, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *week, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *weeks, *unit)) { *unitEnum = UDAT_REL_UNIT_WEEK; - } else if (EcmaStringAccessor::StringsAreEqual(*month, *unit) || - EcmaStringAccessor::StringsAreEqual(*months, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *month, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *months, *unit)) { *unitEnum = UDAT_REL_UNIT_MONTH; - } else if (EcmaStringAccessor::StringsAreEqual(*quarter, *unit) || - EcmaStringAccessor::StringsAreEqual(*quarters, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *quarter, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *quarters, *unit)) { *unitEnum = UDAT_REL_UNIT_QUARTER; - } else if (EcmaStringAccessor::StringsAreEqual(*year, *unit) || - EcmaStringAccessor::StringsAreEqual(*years, *unit)) { + } else if (EcmaStringAccessor::StringsAreEqual(thread, *year, *unit) || + EcmaStringAccessor::StringsAreEqual(thread, *years, *unit)) { *unitEnum = UDAT_REL_UNIT_YEAR; } else { return false; @@ -242,7 +242,7 @@ JSHandle JSRelativeTimeFormat::UnwrapRelativeTimeFormat(JSThread bool isInstanceOf = JSFunction::InstanceOf(thread, rtf, env->GetRelativeTimeFormatFunction()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, rtf); if (!rtf->IsJSRelativeTimeFormat() && isInstanceOf) { - JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); + JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol(thread)); OperationResult operationResult = JSTaggedValue::GetProperty(thread, rtf, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, rtf); return operationResult.GetValue(); @@ -260,7 +260,7 @@ icu::FormattedRelativeDateTime GetIcuFormatted(JSThread *thread, const JSHandle &relativeTimeFormat, double value, const JSHandle &unit) { - icu::RelativeDateTimeFormatter *formatter = relativeTimeFormat->GetIcuRTFFormatter(); + icu::RelativeDateTimeFormatter *formatter = relativeTimeFormat->GetIcuRTFFormatter(thread); ASSERT_PRINT(formatter != nullptr, "rtfFormatter is null"); // If isFinite(value) is false, then throw a RangeError exception. @@ -316,35 +316,35 @@ JSHandle SingularUnitString(JSThread *thread, const JSHandle years = JSHandle::Cast(globalConst->GetHandledYearsString()); // 2. If unit is "seconds" or "second", return "second". - if (EcmaStringAccessor::StringsAreEqual(*second, *unit) || EcmaStringAccessor::StringsAreEqual(*seconds, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *second, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *seconds, *unit)) { return second; } // 3. If unit is "minutes" or "minute", return "minute". - if (EcmaStringAccessor::StringsAreEqual(*minute, *unit) || EcmaStringAccessor::StringsAreEqual(*minutes, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *minute, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *minutes, *unit)) { return minute; } // 4. If unit is "hours" or "hour", return "hour". - if (EcmaStringAccessor::StringsAreEqual(*hour, *unit) || EcmaStringAccessor::StringsAreEqual(*hours, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *hour, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *hours, *unit)) { return hour; } // 5. If unit is "days" or "day", return "day". - if (EcmaStringAccessor::StringsAreEqual(*day, *unit) || EcmaStringAccessor::StringsAreEqual(*days, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *day, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *days, *unit)) { return day; } // 6. If unit is "weeks" or "week", return "week". - if (EcmaStringAccessor::StringsAreEqual(*week, *unit) || EcmaStringAccessor::StringsAreEqual(*weeks, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *week, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *weeks, *unit)) { return week; } // 7. If unit is "months" or "month", return "month". - if (EcmaStringAccessor::StringsAreEqual(*month, *unit) || EcmaStringAccessor::StringsAreEqual(*months, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *month, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *months, *unit)) { return month; } // 8. If unit is "quarters" or "quarter", return "quarter". - if (EcmaStringAccessor::StringsAreEqual(*quarter, *unit) || EcmaStringAccessor::StringsAreEqual(*quarters, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *quarter, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *quarters, *unit)) { return quarter; } // 9. If unit is "years" or "year", return "year". - if (EcmaStringAccessor::StringsAreEqual(*year, *unit) || EcmaStringAccessor::StringsAreEqual(*years, *unit)) { + if (EcmaStringAccessor::StringsAreEqual(thread, *year, *unit) || EcmaStringAccessor::StringsAreEqual(thread, *years, *unit)) { return year; } @@ -487,8 +487,8 @@ JSHandle JSRelativeTimeFormat::FormatToParts(JSThread *thread, double v void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle &relativeTimeFormat, const JSHandle &options) { - if (relativeTimeFormat->GetIcuRTFFormatter() != nullptr) { - [[maybe_unused]] icu::RelativeDateTimeFormatter *formatter = relativeTimeFormat->GetIcuRTFFormatter(); + if (relativeTimeFormat->GetIcuRTFFormatter(thread) != nullptr) { + [[maybe_unused]] icu::RelativeDateTimeFormatter *formatter = relativeTimeFormat->GetIcuRTFFormatter(thread); } else { THROW_ERROR(thread, ErrorType::RANGE_ERROR, "rtf is not initialized"); } @@ -496,7 +496,7 @@ void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandleGlobalConstants(); // [[locale]] JSHandle property = globalConst->GetHandledLocaleString(); - JSHandle locale(thread, relativeTimeFormat->GetLocale()); + JSHandle locale(thread, relativeTimeFormat->GetLocale(thread)); PropertyDescriptor localeDesc(thread, JSHandle::Cast(locale), true, true, true); JSObject::DefineOwnProperty(thread, options, property, localeDesc); @@ -530,7 +530,7 @@ void JSRelativeTimeFormat::ResolvedOptions(JSThread *thread, const JSHandle::Cast(globalConst->GetHandledNumberingSystemString()); - JSHandle numberingSystem(thread, relativeTimeFormat->GetNumberingSystem()); + JSHandle numberingSystem(thread, relativeTimeFormat->GetNumberingSystem(thread)); PropertyDescriptor numberingSystemDesc(thread, numberingSystem, true, true, true); JSObject::DefineOwnProperty(thread, options, property, numberingSystemDesc); } diff --git a/ecmascript/js_relative_time_format.h b/ecmascript/js_relative_time_format.h index b23deb1c47..5164dab749 100644 --- a/ecmascript/js_relative_time_format.h +++ b/ecmascript/js_relative_time_format.h @@ -67,10 +67,10 @@ public: static JSHandle UnwrapRelativeTimeFormat(JSThread *thread, const JSHandle &rtf); // Get icu formatter from icu field - icu::RelativeDateTimeFormatter *GetIcuRTFFormatter() const + icu::RelativeDateTimeFormatter *GetIcuRTFFormatter(JSThread *thread) const { - ASSERT(GetIcuField().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuField().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuField(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuField(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } diff --git a/ecmascript/js_segment_iterator.cpp b/ecmascript/js_segment_iterator.cpp index d01e877b78..acd9c7b511 100644 --- a/ecmascript/js_segment_iterator.cpp +++ b/ecmascript/js_segment_iterator.cpp @@ -29,7 +29,7 @@ void JSSegmentIterator::SetIcuBreakIterator(JSThread *thread, const JSHandleGetFactory(); ASSERT(icuBreakIterator != nullptr); - JSTaggedValue data = iterator->GetIcuField(); + JSTaggedValue data = iterator->GetIcuField(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuBreakIterator); @@ -46,7 +46,7 @@ void JSSegmentIterator::SetUString(JSThread *thread, const JSHandleGetFactory(); ASSERT(icuUnicodeString != nullptr); - JSTaggedValue data = iterator->GetUnicodeString(); + JSTaggedValue data = iterator->GetUnicodeString(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuUnicodeString); @@ -83,7 +83,7 @@ JSHandle JSSegmentIterator::CreateSegmentIterator(JSThread *t JSTaggedValue JSSegmentIterator::Next(JSThread *thread, const JSHandle &iterator) { - icu::BreakIterator* icuBreakIterator = iterator->GetIcuBreakIterator(); + icu::BreakIterator* icuBreakIterator = iterator->GetIcuBreakIterator(thread); // 5. Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]]. int32_t startIndex = icuBreakIterator->current(); // 6. Let endIndex be ! FindBoundary(segmenter, string, startIndex, after). @@ -100,7 +100,7 @@ JSTaggedValue JSSegmentIterator::Next(JSThread *thread, const JSHandlegetText().getText(unicodeString); JSHandle segmentData = JSSegments::CreateSegmentDataObject(thread, iterator->GetGranularity(), - icuBreakIterator, JSHandle(thread, iterator->GetIteratedString()), + icuBreakIterator, JSHandle(thread, iterator->GetIteratedString(thread)), unicodeString, startIndex, endIndex); // 10. Return CreateIterResultObject(segmentData, false). diff --git a/ecmascript/js_segment_iterator.h b/ecmascript/js_segment_iterator.h index d94de50148..f0971ba03a 100644 --- a/ecmascript/js_segment_iterator.h +++ b/ecmascript/js_segment_iterator.h @@ -58,10 +58,10 @@ public: static JSTaggedValue Next(JSThread *thread, const JSHandle &iterator); // Get icu break iterator from icu field - icu::BreakIterator *GetIcuBreakIterator() const + icu::BreakIterator *GetIcuBreakIterator(JSThread *thread) const { - ASSERT(GetIcuField().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuField().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuField(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuField(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -89,10 +89,10 @@ public: static void SetUString(JSThread *thread, const JSHandle &iterator, icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback); - icu::UnicodeString *GetUString() const + icu::UnicodeString *GetUString(JSThread *thread) const { - ASSERT(GetUnicodeString().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetUnicodeString().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetUnicodeString(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetUnicodeString(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } }; diff --git a/ecmascript/js_segmenter.cpp b/ecmascript/js_segmenter.cpp index 966df3ed27..9e693c053a 100644 --- a/ecmascript/js_segmenter.cpp +++ b/ecmascript/js_segmenter.cpp @@ -28,7 +28,7 @@ void JSSegmenter::SetIcuBreakIterator(JSThread *thread, const JSHandleGetFactory(); ASSERT(icuBreakIterator != nullptr); - JSTaggedValue data = segmenter->GetIcuField(); + JSTaggedValue data = segmenter->GetIcuField(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuBreakIterator); @@ -171,7 +171,7 @@ void JSSegmenter::ResolvedOptions(JSThread *thread, const JSHandle // [[Locale]] JSHandle propertyKey = globalConst->GetHandledLocaleString(); - JSHandle locale(thread, segmenter->GetLocale()); + JSHandle locale(thread, segmenter->GetLocale(thread)); JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale); RETURN_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/js_segmenter.h b/ecmascript/js_segmenter.h index bb0bb828c6..c37d9904e5 100644 --- a/ecmascript/js_segmenter.h +++ b/ecmascript/js_segmenter.h @@ -59,10 +59,10 @@ public: const JSHandle &locales, const JSHandle &options); // Get icu break iterator from icu field - icu::BreakIterator *GetIcuBreakIterator() const + icu::BreakIterator *GetIcuBreakIterator(JSThread *thread) const { - ASSERT(GetIcuField().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuField().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuField(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuField(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } diff --git a/ecmascript/js_segments.cpp b/ecmascript/js_segments.cpp index dfa0c641c8..cb167d0f0e 100644 --- a/ecmascript/js_segments.cpp +++ b/ecmascript/js_segments.cpp @@ -29,7 +29,7 @@ void JSSegments::SetIcuBreakIterator(JSThread *thread, const JSHandleGetFactory(); ASSERT(icuBreakIterator != nullptr); - JSTaggedValue data = segments->GetIcuField(); + JSTaggedValue data = segments->GetIcuField(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuBreakIterator); @@ -46,7 +46,7 @@ void JSSegments::SetUString(JSThread *thread, const JSHandle &segmen ObjectFactory *factory = ecmaVm->GetFactory(); ASSERT(icuUnicodeString != nullptr); - JSTaggedValue data = segments->GetUnicodeString(); + JSTaggedValue data = segments->GetUnicodeString(thread); if (data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread, icuUnicodeString); @@ -59,7 +59,7 @@ void JSSegments::SetUString(JSThread *thread, const JSHandle &segmen void SetTextToBreakIterator(JSThread *thread, const JSHandle &segments, JSHandle text, icu::BreakIterator* breakIterator) { - std::u16string u16str = EcmaStringAccessor(text).ToU16String(); + std::u16string u16str = EcmaStringAccessor(text).ToU16String(thread); icu::UnicodeString src(u16str.data(), u16str.size()); icu::UnicodeString* uText = static_cast(src.clone()); breakIterator->setText(*uText); @@ -77,7 +77,7 @@ JSHandle JSSegments::CreateSegmentsObject(JSThread *thread, JSHandle segmentsCtor(env->GetSegmentsFunction()); JSHandle segments(factory->NewJSObjectByConstructor(segmentsCtor)); // 3. Set segments.[[SegmentsSegmenter]] to segmenter. - icu::BreakIterator* icuBreakIterator = segmenter->GetIcuBreakIterator()->clone(); + icu::BreakIterator* icuBreakIterator = segmenter->GetIcuBreakIterator(thread)->clone(); SetIcuBreakIterator(thread, segments, icuBreakIterator, JSSegments::FreeIcuBreakIterator); segments->SetGranularity(segmenter->GetGranularity()); // 4. Set segments.[[SegmentsString]] to string. @@ -88,7 +88,7 @@ JSHandle JSSegments::CreateSegmentsObject(JSThread *thread, JSTaggedValue JSSegments::Containing(JSThread *thread, const JSHandle &segments, double index) { - icu::UnicodeString* unicodeString = segments->GetUString(); + icu::UnicodeString* unicodeString = segments->GetUString(thread); // 5. Let len be the length of string. int32_t len = unicodeString->length(); // 7. If n < 0 or n ≥ len, return undefined. @@ -98,14 +98,14 @@ JSTaggedValue JSSegments::Containing(JSThread *thread, const JSHandle(index); // n may point to the surrogate tail- adjust it back to the lead. n = unicodeString->getChar32Start(n); - icu::BreakIterator* breakIterator = segments->GetIcuBreakIterator(); + icu::BreakIterator* breakIterator = segments->GetIcuBreakIterator(thread); // 8. Let startIndex be ! FindBoundary(segmenter, string, n, before). int32_t startIndex = breakIterator->isBoundary(n) ? n : breakIterator->preceding(n); // 9. Let endIndex be ! FindBoundary(segmenter, string, n, after). int32_t endIndex = breakIterator->following(n); // 10. Return ! CreateSegmentDataObject(segmenter, string, startIndex, endIndex). return CreateSegmentDataObject(thread, segments->GetGranularity(), breakIterator, - JSHandle(thread, segments->GetSegmentsString()), + JSHandle(thread, segments->GetSegmentsString(thread)), *unicodeString, startIndex, endIndex).GetTaggedValue(); } diff --git a/ecmascript/js_segments.h b/ecmascript/js_segments.h index afbbdf750f..84c85a9f55 100644 --- a/ecmascript/js_segments.h +++ b/ecmascript/js_segments.h @@ -54,10 +54,10 @@ public: const JSHandle &segmenter, const JSHandle &string); // Get icu break iterator from icu field - icu::BreakIterator *GetIcuBreakIterator() const + icu::BreakIterator *GetIcuBreakIterator(JSThread *thread) const { - ASSERT(GetIcuField().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetIcuField().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetIcuField(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetIcuField(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } @@ -85,10 +85,10 @@ public: static void SetUString(JSThread *thread, const JSHandle &segments, icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback); - icu::UnicodeString *GetUString() const + icu::UnicodeString *GetUString(JSThread *thread) const { - ASSERT(GetUnicodeString().IsJSNativePointer()); - auto result = JSNativePointer::Cast(GetUnicodeString().GetTaggedObject())->GetExternalPointer(); + ASSERT(GetUnicodeString(thread).IsJSNativePointer()); + auto result = JSNativePointer::Cast(GetUnicodeString(thread).GetTaggedObject())->GetExternalPointer(); return reinterpret_cast(result); } diff --git a/ecmascript/js_set.cpp b/ecmascript/js_set.cpp index d1867946d5..73843b8173 100644 --- a/ecmascript/js_set.cpp +++ b/ecmascript/js_set.cpp @@ -23,7 +23,7 @@ void JSSet::Add(JSThread *thread, const JSHandle &set, const JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())); JSHandle newSet = LinkedHashSet::Add(thread, setHandle, value); set->SetLinkedSet(thread, newSet); @@ -31,7 +31,7 @@ void JSSet::Add(JSThread *thread, const JSHandle &set, const JSHandle &set, const JSHandle &value) { - JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())); int entry = setHandle->FindElement(thread, value.GetTaggedValue()); if (entry == -1) { return false; @@ -42,26 +42,26 @@ bool JSSet::Delete(const JSThread *thread, const JSHandle &set, const JSH void JSSet::Clear(const JSThread *thread, const JSHandle &set) { - LinkedHashSet *linkedSet = LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject()); - JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + LinkedHashSet *linkedSet = LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject()); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())); JSHandle newSet = linkedSet->Clear(thread, setHandle); set->SetLinkedSet(thread, newSet); } bool JSSet::Has(const JSThread *thread, JSTaggedValue value) const { - return LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject())->Has(thread, value); + return LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject())->Has(thread, value); } -uint32_t JSSet::GetSize() const +uint32_t JSSet::GetSize(const JSThread *thread) const { - return LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject())->NumberOfElements(); + return LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject())->NumberOfElements(); } -JSTaggedValue JSSet::GetValue(int entry) const +JSTaggedValue JSSet::GetValue(const JSThread *thread, int entry) const { - ASSERT_PRINT(entry >= 0 && static_cast(entry) < GetSize(), + ASSERT_PRINT(entry >= 0 && static_cast(entry) < GetSize(thread), "entry must be non-negative integer less than capacity"); - return LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject())->GetValue(entry); + return LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject())->GetValue(thread, entry); } } // namespace panda::ecmascript diff --git a/ecmascript/js_set.h b/ecmascript/js_set.h index 757389fbbb..595f54b15f 100644 --- a/ecmascript/js_set.h +++ b/ecmascript/js_set.h @@ -32,9 +32,9 @@ public: bool Has(const JSThread *thread, JSTaggedValue value) const; - uint32_t GetSize() const; + uint32_t GetSize(const JSThread *thread) const; - JSTaggedValue GetValue(int entry) const; + JSTaggedValue GetValue(const JSThread *thread, int entry) const; static constexpr size_t LINKED_SET_OFFSET = JSObject::SIZE; ACCESSORS(LinkedSet, LINKED_SET_OFFSET, SIZE) diff --git a/ecmascript/js_set_iterator.cpp b/ecmascript/js_set_iterator.cpp index 6fcc51ed15..7fa6fb7e1a 100644 --- a/ecmascript/js_set_iterator.cpp +++ b/ecmascript/js_set_iterator.cpp @@ -42,7 +42,7 @@ JSTaggedValue JSSetIterator::NextInternal(JSThread *thread, JSHandleUpdate(thread); JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); // 4.Let s be O.[[IteratedSet]]. - JSHandle iteratedSet(thread, iter->GetIteratedSet()); + JSHandle iteratedSet(thread, iter->GetIteratedSet(thread)); // 5.Let index be O.[[SetNextIndex]]. int index = static_cast(iter->GetNextIndex()); @@ -55,9 +55,9 @@ JSTaggedValue JSSetIterator::NextInternal(JSThread *thread, JSHandleNumberOfElements() + set->NumberOfDeletedElements(); while (index < totalElements) { - if (!set->GetKey(index).IsHole()) { + if (!set->GetKey(thread, index).IsHole()) { iter->SetNextIndex(index + 1); - JSHandle key(thread, set->GetKey(index)); + JSHandle key(thread, set->GetKey(thread, index)); // If itemKind is value if (itemKind == IterationKind::VALUE || itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); @@ -80,20 +80,20 @@ JSTaggedValue JSSetIterator::NextInternal(JSThread *thread, JSHandleGetNextTable().IsHole()) { + if (set->GetNextTable(thread).IsHole()) { return; } int index = static_cast(GetNextIndex()); - JSTaggedValue nextTable = set->GetNextTable(); + JSTaggedValue nextTable = set->GetNextTable(thread); while (!nextTable.IsHole()) { - index -= set->GetDeletedElementsAt(index); + index -= set->GetDeletedElementsAt(thread, index); set = LinkedHashSet::Cast(nextTable.GetTaggedObject()); - nextTable = set->GetNextTable(); + nextTable = set->GetNextTable(thread); } SetIteratedSet(thread, JSTaggedValue(set)); SetNextIndex(index); diff --git a/ecmascript/js_stable_array.cpp b/ecmascript/js_stable_array.cpp index 64ddc79d84..9159c0011c 100644 --- a/ecmascript/js_stable_array.cpp +++ b/ecmascript/js_stable_array.cpp @@ -34,7 +34,7 @@ JSTaggedValue JSStableArray::Push(JSHandle receiver, EcmaRuntimeC uint32_t newLength = argc + oldLength; JSHandle thisObjHandle(receiver); - if (newLength > ElementAccessor::GetElementsLength(thisObjHandle)) { + if (newLength > ElementAccessor::GetElementsLength(thread, thisObjHandle)) { JSObject::GrowElementsCapacity(thread, JSHandle::Cast(receiver), newLength, true); } bool needTransition = true; @@ -55,7 +55,7 @@ JSTaggedValue JSStableArray::Push(JSHandle receiver, EcmaRuntimeCallInf uint32_t newLength = argc + oldLength; JSHandle thisObjHandle(receiver); - if (newLength > ElementAccessor::GetElementsLength(thisObjHandle)) { + if (newLength > ElementAccessor::GetElementsLength(thread, thisObjHandle)) { JSObject::GrowElementsCapacity(thread, JSHandle::Cast(receiver), newLength, true); } bool needTransition = true; @@ -78,7 +78,7 @@ JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCa JSHandle holeHandle(thread, JSTaggedValue::Hole()); JSSharedArray::CheckAndCopyArray(thread, receiver); JSHandle obj(receiver); - uint32_t capacity = ElementAccessor::GetElementsLength(obj); + uint32_t capacity = ElementAccessor::GetElementsLength(thread, obj); uint32_t index = length - 1; JSMutableHandle result(thread, JSTaggedValue::Hole()); if (index < capacity) { @@ -86,7 +86,7 @@ JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCa } if (!result->IsHole()) { if (TaggedArray::ShouldTrim(capacity, index)) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread).GetTaggedObject()); elements->Trim(thread, index); } else { ElementAccessor::Set(thread, obj, index, holeHandle, false); @@ -109,7 +109,7 @@ JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCallInfo JSHandle holeHandle(thread, JSTaggedValue::Hole()); JSArray::CheckAndCopyArray(thread, receiver); JSHandle obj(receiver); - uint32_t capacity = ElementAccessor::GetElementsLength(obj); + uint32_t capacity = ElementAccessor::GetElementsLength(thread, obj); uint32_t index = length - 1; JSMutableHandle result(thread, JSTaggedValue::Hole()); if (index < capacity) { @@ -117,7 +117,7 @@ JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCallInfo } if (!result->IsHole()) { if (TaggedArray::ShouldTrim(capacity, index)) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread).GetTaggedObject()); elements->Trim(thread, index); } else { ElementAccessor::Set(thread, obj, index, holeHandle, false); @@ -134,13 +134,13 @@ void JSStableArray::HandleArray(JSHandle &newArrayHandle, uint32_t &ac JSThread *thread, uint32_t &start, JSHandle &thisObjHandle, JSHandle &holeHandle) { - TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject()); - if (actualDeleteCount > ElementAccessor::GetElementsLength(newArrayHandle)) { + TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements(thread).GetTaggedObject()); + if (actualDeleteCount > ElementAccessor::GetElementsLength(thread, newArrayHandle)) { destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, actualDeleteCount); } for (uint32_t idx = 0; idx < actualDeleteCount; idx++) { - if ((start + idx) >= ElementAccessor::GetElementsLength(thisObjHandle)) { + if ((start + idx) >= ElementAccessor::GetElementsLength(thread, thisObjHandle)) { ElementAccessor::Set(thread, newArrayHandle, idx, holeHandle, true); } else { JSHandle valueHandle(thread, ElementAccessor::Get(thread, thisObjHandle, start + idx)); @@ -158,10 +158,10 @@ JSTaggedValue JSStableArray::UpdateArrayCapacity(JSHandle &thisObjHand EcmaRuntimeCallInfo *argv, JSHandle &thisObjVal, JSHandle &lengthKey) { - uint32_t oldCapacity = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t oldCapacity = ElementAccessor::GetElementsLength(thread, thisObjHandle); ASSERT(len + insertCount >= actualDeleteCount); uint32_t newCapacity = len - actualDeleteCount + insertCount; - TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); JSMutableHandle srcElementsHandle(thread, srcElements); uint32_t argc = argv->GetArgsNumber(); if (newCapacity > oldCapacity) { @@ -169,13 +169,13 @@ JSTaggedValue JSStableArray::UpdateArrayCapacity(JSHandle &thisObjHand } if (insertCount < actualDeleteCount) { JSArray::CheckAndCopyArray(thread, receiver); - srcElementsHandle.Update(receiver->GetElements()); + srcElementsHandle.Update(receiver->GetElements(thread)); for (uint32_t idx = start; idx < len - actualDeleteCount; idx++) { JSMutableHandle element(thread, JSTaggedValue::Hole()); - if ((idx + actualDeleteCount) < ElementAccessor::GetElementsLength(thisObjHandle)) { + if ((idx + actualDeleteCount) < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { element.Update(ElementAccessor::Get(thread, thisObjHandle, idx + actualDeleteCount)); } - if ((idx + insertCount) < ElementAccessor::GetElementsLength(thisObjHandle)) { + if ((idx + insertCount) < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { ElementAccessor::Set(thread, thisObjHandle, idx + insertCount, element, needTransition); } } @@ -184,7 +184,7 @@ JSTaggedValue JSStableArray::UpdateArrayCapacity(JSHandle &thisObjHand srcElementsHandle->Trim(thread, newCapacity); } else { for (uint32_t idx = newCapacity; idx < len; idx++) { - if (idx < ElementAccessor::GetElementsLength(thisObjHandle)) { + if (idx < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { ElementAccessor::Set(thread, thisObjHandle, idx, holeHandle, needTransition); } } @@ -268,17 +268,17 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntim JSHandle thisObjVal(thisObjHandle); JSSharedArray::CheckAndCopyArray(thread, receiver); JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements(thread).GetTaggedObject()); JSMutableHandle srcElementsHandle(thread, srcElements); bool needTransition = true; if (newArrayHandle.GetTaggedValue().IsStableJSArray(thread)) { - TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject()); - if (actualDeleteCount > ElementAccessor::GetElementsLength(newArrayHandle)) { + TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements(thread).GetTaggedObject()); + if (actualDeleteCount > ElementAccessor::GetElementsLength(thread, newArrayHandle)) { destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, actualDeleteCount); } for (uint32_t idx = 0; idx < actualDeleteCount; idx++) { - if ((start + idx) >= ElementAccessor::GetElementsLength(thisObjHandle)) { + if ((start + idx) >= ElementAccessor::GetElementsLength(thread, thisObjHandle)) { ElementAccessor::Set(thread, newArrayHandle, idx, holeHandle, needTransition); } else { JSHandle valueHandle(thread, ElementAccessor::Get(thread, thisObjHandle, start + idx)); @@ -314,7 +314,7 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntim true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - uint32_t oldCapacity = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t oldCapacity = ElementAccessor::GetElementsLength(thread, thisObjHandle); ASSERT(len + insertCount >= actualDeleteCount); uint32_t newCapacity = len - actualDeleteCount + insertCount; if (newCapacity > oldCapacity) { @@ -322,13 +322,13 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntim } if (insertCount < actualDeleteCount) { JSSharedArray::CheckAndCopyArray(thread, receiver); - srcElementsHandle.Update(receiver->GetElements()); + srcElementsHandle.Update(receiver->GetElements(thread)); for (uint32_t idx = start; idx < len - actualDeleteCount; idx++) { JSMutableHandle element(thread, JSTaggedValue::Hole()); - if ((idx + actualDeleteCount) < ElementAccessor::GetElementsLength(thisObjHandle)) { + if ((idx + actualDeleteCount) < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { element.Update(ElementAccessor::Get(thread, thisObjHandle, idx + actualDeleteCount)); } - if ((idx + insertCount) < ElementAccessor::GetElementsLength(thisObjHandle)) { + if ((idx + insertCount) < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { ElementAccessor::Set(thread, thisObjHandle, idx + insertCount, element, needTransition); } } @@ -337,7 +337,7 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntim srcElementsHandle->Trim(thread, newCapacity); } else { for (uint32_t idx = newCapacity; idx < len; idx++) { - if (idx < ElementAccessor::GetElementsLength(thisObjHandle)) { + if (idx < ElementAccessor::GetElementsLength(thread, thisObjHandle)) { ElementAccessor::Set(thread, thisObjHandle, idx, holeHandle, needTransition); } } @@ -371,14 +371,14 @@ JSTaggedValue JSStableArray::Shift(JSHandle receiver, EcmaRuntime return JSTaggedValue::Undefined(); } JSSharedArray::CheckAndCopyArray(thread, receiver); - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread).GetTaggedObject()); JSHandle result(thread, ElementAccessor::Get(thread, thisObjHandle, 0)); bool needTransition = false; for (uint32_t k = 1; k < length; k++) { JSHandle kValue(thread, ElementAccessor::Get(thread, thisObjHandle, k)); ElementAccessor::Set(thread, thisObjHandle, k - 1, kValue, needTransition); } - uint32_t capacity = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t capacity = ElementAccessor::GetElementsLength(thread, thisObjHandle); uint32_t index = length - 1; if (TaggedArray::ShouldTrim(capacity, index)) { elements->Trim(thread, index); @@ -399,14 +399,14 @@ JSTaggedValue JSStableArray::Shift(JSHandle receiver, EcmaRuntimeCallIn return JSTaggedValue::Undefined(); } JSArray::CheckAndCopyArray(thread, receiver); - JSHandle elements(thread, TaggedArray::Cast(receiver->GetElements().GetTaggedObject())); + JSHandle elements(thread, TaggedArray::Cast(receiver->GetElements(thread).GetTaggedObject())); JSHandle result(thread, ElementAccessor::Get(thread, thisObjHandle, 0)); bool needTransition = false; for (uint32_t k = 1; k < length; k++) { JSHandle kValue(thread, ElementAccessor::Get(thread, thisObjHandle, k)); ElementAccessor::Set(thread, thisObjHandle, k - 1, kValue, needTransition); } - uint32_t capacity = ElementAccessor::GetElementsLength(thisObjHandle); + uint32_t capacity = ElementAccessor::GetElementsLength(thread, thisObjHandle); uint32_t index = length - 1; if (TaggedArray::ShouldTrim(capacity, index)) { elements->Trim(thread, index); @@ -476,7 +476,7 @@ void JSStableArray::ProcessElements(JSThread *thread, JSHandle re JSTaggedValue element = JSTaggedValue::Undefined(); for (uint32_t k = 0; k < len; k++) { if (receiverValue->IsStableJSArray(thread) || receiverValue->IsJSSharedArray()) { - element = k < ElementAccessor::GetElementsLength(obj) ? + element = k < ElementAccessor::GetElementsLength(thread, obj) ? ElementAccessor::Get(thread, obj, k) : JSTaggedValue::Hole(); } else { element = JSArray::FastGetPropertyByValue(thread, receiverValue, k).GetTaggedValue(); @@ -532,7 +532,7 @@ JSTaggedValue JSStableArray::DoStableArrayJoin(JSThread *thread, JSHandle(sep)); } else if (sepLength > 1) { - EcmaStringAccessor::ReadData(newString, *sepStringHandle, current, + EcmaStringAccessor::ReadData(thread, newString, *sepStringHandle, current, allocateLength - static_cast(current), sepLength); } current += static_cast(sepLength); @@ -542,8 +542,8 @@ JSTaggedValue JSStableArray::DoStableArrayJoin(JSThread *thread, JSHandle(EcmaStringAccessor(nextStr).GetLength()); - EcmaStringAccessor::ReadData(newString, *nextStr, current, allocateLength - static_cast(current), - nextLength); + EcmaStringAccessor::ReadData(thread, newString, *nextStr, current, + allocateLength - static_cast(current), nextLength); current += nextLength; } } @@ -581,7 +581,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiverValue, EcmaRun RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); sepLength = EcmaStringAccessor(sepStringHandle).GetLength(); if (sepLength == 1) { - sep = EcmaStringAccessor(sepStringHandle).Get(0); + sep = EcmaStringAccessor(sepStringHandle).Get(thread, 0); } } @@ -611,11 +611,11 @@ JSTaggedValue JSStableArray::Join(JSHandle receiverValue, EcmaRun #endif #if !ENABLE_NEXT_OPTIMIZATION -void JSStableArray::SetSepValue(JSHandle sepStringHandle, int &sep, uint32_t &sepLength) +void JSStableArray::SetSepValue(JSThread *thread, JSHandle sepStringHandle, int &sep, uint32_t &sepLength) { if (EcmaStringAccessor(sepStringHandle).IsUtf8() && EcmaStringAccessor(sepStringHandle).GetLength() == 1) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - sep = EcmaStringAccessor(sepStringHandle).Get(0); + sep = EcmaStringAccessor(sepStringHandle).Get(thread, 0); } else if (EcmaStringAccessor(sepStringHandle).GetLength() == 0) { sep = JSStableArray::SeparatorFlag::MINUS_TWO; sepLength = 0; @@ -688,7 +688,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiverValue, EcmaRun sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - SetSepValue(sepStringHandle, sep, sepLength); + SetSepValue(thread, sepStringHandle, sep, sepLength); } if (length == 0 || !ArrayJoinStack::Push(thread, receiverValue)) { return globalConst->GetEmptyString(); @@ -697,7 +697,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiverValue, EcmaRun uint64_t allocateLength = 0; bool isOneByte = (sep != JSStableArray::SeparatorFlag::MINUS_ONE) || EcmaStringAccessor(sepStringHandle).IsUtf8(); JSMutableHandle elementHandle(thread, JSTaggedValue::Undefined()); - uint32_t elementsLength = ElementAccessor::GetElementsLength(obj); + uint32_t elementsLength = ElementAccessor::GetElementsLength(thread, obj); uint32_t len = elementsLength > length ? length : elementsLength; if (elementsLength == 0 && length != 0) { len = length; @@ -711,7 +711,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiverValue, EcmaRun JSTaggedValue element = JSTaggedValue::Hole(); for (uint32_t k = 0; k < len; k++) { if (receiverValue->IsStableJSArray(thread)) { - element = k < ElementAccessor::GetElementsLength(obj) ? + element = k < ElementAccessor::GetElementsLength(thread, obj) ? ElementAccessor::Get(thread, obj, k) : JSTaggedValue::Hole(); } else { element = JSArray::FastGetPropertyByValue(thread, receiverValue, k).GetTaggedValue(); @@ -752,15 +752,15 @@ JSTaggedValue JSStableArray::Join(JSHandle receiverValue, EcmaRun if (sep >= 0) { EcmaStringAccessor(newString).Set(current, static_cast(sep)); } else if (sep != JSStableArray::SeparatorFlag::MINUS_TWO) { - EcmaStringAccessor::ReadData(newString, *sepStringHandle, current, + EcmaStringAccessor::ReadData(thread, newString, *sepStringHandle, current, allocateLength - static_cast(current), sepLength); } current += static_cast(sepLength); } JSHandle nextStr = vec[k]; int nextLength = static_cast(EcmaStringAccessor(nextStr).GetLength()); - EcmaStringAccessor::ReadData(newString, *nextStr, current, allocateLength - static_cast(current), - nextLength); + EcmaStringAccessor::ReadData(thread, newString, *nextStr, current, + allocateLength - static_cast(current), nextLength); current += nextLength; } } @@ -805,8 +805,8 @@ JSTaggedValue JSStableArray::HandleFindIndexOfStable(JSThread *thread, JSHandle< if (callResult.ToBoolean()) { return callResult; } - if (ElementAccessor::GetElementsLength(thisObjHandle) < len) { - len = ElementAccessor::GetElementsLength(thisObjHandle); + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) < len) { + len = ElementAccessor::GetElementsLength(thread, thisObjHandle); } k++; if (!thisObjVal->IsStableJSArray(thread)) { @@ -880,8 +880,8 @@ JSTaggedValue JSStableArray::HandleEveryOfStable(JSThread *thread, JSHandleSetCallArg(kValue.GetTaggedValue(), JSTaggedValue(k), thisObjVal.GetTaggedValue()); callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (ElementAccessor::GetElementsLength(thisObjHandle) < len) { - len = ElementAccessor::GetElementsLength(thisObjHandle); + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) < len) { + len = ElementAccessor::GetElementsLength(thread, thisObjHandle); } } else if (JSTaggedValue::HasProperty(thread, thisObjVal, k)) { JSHandle kValue1 = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); @@ -935,8 +935,8 @@ JSTaggedValue JSStableArray::HandleSomeOfStable(JSThread *thread, JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); const int32_t argsLength = 3; // 3: ?kValue, k, O? JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); - if (ElementAccessor::GetElementsLength(thisObjHandle) <= k) { + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) <= k) { return base::BuiltinsBase::GetTaggedBoolean(false); } while (k < len) { @@ -972,8 +972,8 @@ JSTaggedValue JSStableArray::HandleforEachOfStable(JSThread *thread, JSHandleSetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); - if (ElementAccessor::GetElementsLength(thisObjHandle) < len) { - len = ElementAccessor::GetElementsLength(thisObjHandle); + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) < len) { + len = ElementAccessor::GetElementsLength(thread, thisObjHandle); } } else if (JSTaggedValue::HasProperty(thread, thisObjVal, k)) { key.Update(JSTaggedValue(k)); @@ -995,19 +995,19 @@ JSTaggedValue JSStableArray::HandleforEachOfStable(JSThread *thread, JSHandle -const JSTaggedType* JSStableArray::IndexOfElements(Span elements, IndexOfOptions options, - Predicate predicate) +const JSTaggedType* JSStableArray::IndexOfElements(JSThread *thread, Span elements, + IndexOfOptions options, Predicate predicate) { static_assert(std::is_invocable_r_v, "Invalid call signature."); if (options.reversedOrder) { for (auto cur = elements.end() - 1; cur >= elements.begin(); --cur) { - if (UNLIKELY(std::invoke(predicate, Barriers::GetTaggedValue(ToUintPtr(cur))))) { + if (UNLIKELY(std::invoke(predicate, Barriers::GetTaggedValue(thread, ToUintPtr(cur))))) { return cur; } } } else { for (auto cur = elements.begin(); cur < elements.end(); ++cur) { - if (UNLIKELY(std::invoke(predicate, Barriers::GetTaggedValue(ToUintPtr(cur))))) { + if (UNLIKELY(std::invoke(predicate, Barriers::GetTaggedValue(thread, ToUintPtr(cur))))) { return cur; } } @@ -1015,39 +1015,41 @@ const JSTaggedType* JSStableArray::IndexOfElements(Span elem return nullptr; } -const JSTaggedType* JSStableArray::IndexOfUndefined(Span elements, IndexOfOptions options, - bool isMutant) +const JSTaggedType* JSStableArray::IndexOfUndefined(JSThread *thread, Span elements, + IndexOfOptions options, bool isMutant) { // For mutant arrays, only raw int32, raw double and SPECIAL_HOLE may exist. if (isMutant) { if (!options.holeAsUndefined) { return nullptr; } - return IndexOfElements(elements, options, [](JSTaggedType rawValue) { + return IndexOfElements(thread, elements, options, [](JSTaggedType rawValue) { return rawValue == base::SPECIAL_HOLE; }); } // For non-mutant arrays, taggedValue can never be SPECIAL_HOLE. if (!options.holeAsUndefined) { - return IndexOfElements(elements, options, [](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [](JSTaggedType taggedValue) { return JSTaggedValue(taggedValue).IsUndefined(); }); } - return IndexOfElements(elements, options, [](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [](JSTaggedType taggedValue) { return JSTaggedValue(taggedValue).IsHole() || JSTaggedValue(taggedValue).IsUndefined(); }); } -const JSTaggedType* JSStableArray::IndexOfTaggedZero(Span elements, IndexOfOptions options) +const JSTaggedType* JSStableArray::IndexOfTaggedZero(JSThread *thread, Span elements, + IndexOfOptions options) { - return IndexOfElements(elements, options, [](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [](JSTaggedType taggedValue) { return JSTaggedValue(taggedValue).IsExactlyZero(); }); } // Raw int32 array (isMutant = true), or tagged array (isMutant = false) -const JSTaggedType* JSStableArray::IndexOfInt(Span elements, JSTaggedValue searchElement, - IndexOfOptions options, bool isMutantInt32Array) +const JSTaggedType* JSStableArray::IndexOfInt(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options, + bool isMutantInt32Array) { ASSERT(!searchElement.IsUndefined()); int32_t searchValue; @@ -1060,24 +1062,25 @@ const JSTaggedType* JSStableArray::IndexOfInt(Span elements, } if (isMutantInt32Array) { // For ElementsKind::INT: convertedValue = JSTaggedValue(static_cast(rawValue)) - return IndexOfElements(elements, options, [searchValue](JSTaggedType rawValue) { + return IndexOfElements(thread, elements, options, [searchValue](JSTaggedType rawValue) { return rawValue != base::SPECIAL_HOLE && searchValue == static_cast(rawValue); }); } if (searchValue == 0) { - return IndexOfTaggedZero(elements, options); + return IndexOfTaggedZero(thread, elements, options); } JSTaggedType taggedInt32 = JSTaggedValue(searchValue).GetRawData(); JSTaggedType taggedDouble = JSTaggedValue(static_cast(searchValue)).GetRawData(); // Always false if taggedValue is not number - return IndexOfElements(elements, options, [taggedInt32, taggedDouble](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [taggedInt32, taggedDouble](JSTaggedType taggedValue) { return taggedValue == taggedInt32 || taggedValue == taggedDouble; }); } // Raw double array (isMutant = true), or tagged array (isMutant = false) -const JSTaggedType* JSStableArray::IndexOfDouble(Span elements, JSTaggedValue searchElement, - IndexOfOptions options, bool isMutantDoubleArray) +const JSTaggedType* JSStableArray::IndexOfDouble(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options, + bool isMutantDoubleArray) { ASSERT(!searchElement.IsUndefined()); if (!searchElement.IsNumber()) { @@ -1090,44 +1093,44 @@ const JSTaggedType* JSStableArray::IndexOfDouble(Span elemen } if (isMutantDoubleArray) { // For ElementsKind::NUMBER: convertedValue = JSTaggedValue(base::bit_cast(rawValue)) - return IndexOfElements(elements, options, [](JSTaggedType rawValue) { + return IndexOfElements(thread, elements, options, [](JSTaggedType rawValue) { return rawValue != base::SPECIAL_HOLE && std::isnan(base::bit_cast(rawValue)); }); } - return IndexOfElements(elements, options, [](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [](JSTaggedType taggedValue) { return JSTaggedValue(taggedValue).IsNaN(); }); } if (isMutantDoubleArray) { // Including the cases of +inf, -inf, +0.0 and -0.0 // We assume that bit representation of searchValue can never be SPECIAL_HOLE (which is NaN) - return IndexOfElements(elements, options, [searchValue](JSTaggedType rawValue) { + return IndexOfElements(thread, elements, options, [searchValue](JSTaggedType rawValue) { return searchValue == base::bit_cast(rawValue); }); } if (searchValue == 0.0) { - return IndexOfTaggedZero(elements, options); + return IndexOfTaggedZero(thread, elements, options); } JSTaggedType taggedDouble = JSTaggedValue(searchValue).GetRawData(); if (JSTaggedValue(taggedDouble).WithinInt32()) { JSTaggedType taggedInt32 = JSTaggedValue(static_cast(searchValue)).GetRawData(); - return IndexOfElements(elements, options, [taggedDouble, taggedInt32](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [taggedDouble, taggedInt32](JSTaggedType taggedValue) { return taggedValue == taggedDouble || taggedValue == taggedInt32; }); } - return IndexOfElements(elements, options, [taggedDouble](JSTaggedType taggedValue) { + return IndexOfElements(thread, elements, options, [taggedDouble](JSTaggedType taggedValue) { return taggedValue == taggedDouble; }); } -const JSTaggedType* JSStableArray::IndexOfString(Span elements, JSTaggedValue searchElement, - IndexOfOptions options) +const JSTaggedType* JSStableArray::IndexOfString(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options) { ASSERT(!searchElement.IsUndefined()); if (!searchElement.IsString()) { return nullptr; } - return IndexOfElements(elements, options, [searchElement](JSTaggedType cur) { + return IndexOfElements(thread, elements, options, [searchElement, thread](JSTaggedType cur) { if (searchElement.GetRawData() == cur) { return true; } @@ -1135,17 +1138,17 @@ const JSTaggedType* JSStableArray::IndexOfString(Span elemen if (!curValue.IsString()) { return false; } - return JSTaggedValue::StringCompare( + return JSTaggedValue::StringCompare(thread, EcmaString::Cast(curValue.GetTaggedObject()), EcmaString::Cast(searchElement.GetTaggedObject())); }); } -const JSTaggedType* JSStableArray::IndexOfBigInt(Span elements, JSTaggedValue searchElement, - IndexOfOptions options) +const JSTaggedType* JSStableArray::IndexOfBigInt(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options) { ASSERT(searchElement.IsBigInt()); - return IndexOfElements(elements, options, [searchElement](JSTaggedType cur) { + return IndexOfElements(thread, elements, options, [searchElement](JSTaggedType cur) { if (searchElement.GetRawData() == cur) { return true; } @@ -1157,13 +1160,13 @@ const JSTaggedType* JSStableArray::IndexOfBigInt(Span elemen }); } -const JSTaggedType* JSStableArray::IndexOfObjectAddress(Span elements, JSTaggedValue searchElement, - IndexOfOptions options) +const JSTaggedType* JSStableArray::IndexOfObjectAddress(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options) { // Note: searchElement may be true, false or null ASSERT(searchElement.IsObject()); JSTaggedType targetAddress = searchElement.GetRawData(); - return IndexOfElements(elements, options, [targetAddress](JSTaggedType cur) { + return IndexOfElements(thread, elements, options, [targetAddress](JSTaggedType cur) { return cur == targetAddress; }); } @@ -1175,7 +1178,7 @@ JSTaggedValue JSStableArray::IndexOfDispatch(JSThread *thread, JSHandle::Cast(receiver)->GetElements(); + JSTaggedValue elementsValue = JSHandle::Cast(receiver)->GetElements(thread); bool isMutant = elementsValue.IsMutantTaggedArray(); if (isMutant) { JSHandle elements(thread, elementsValue); @@ -1195,25 +1198,25 @@ JSTaggedValue JSStableArray::IndexOfDispatch(JSThread *thread, JSHandle(foundPos - data)); @@ -1286,8 +1289,8 @@ JSTaggedValue JSStableArray::Filter(JSHandle newArrayHandle, JSHandle< info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); JSTaggedValue callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (ElementAccessor::GetElementsLength(thisObjHandle) < len) { - len = ElementAccessor::GetElementsLength(thisObjHandle); + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) < len) { + len = ElementAccessor::GetElementsLength(thread, thisObjHandle); } bool boolResult = callResult.ToBoolean(); if (boolResult) { @@ -1336,8 +1339,8 @@ JSTaggedValue JSStableArray::Map(JSHandle newArrayHandle, JSHandle thisOb JSArray::CheckAndCopyArray(thread, JSHandle::Cast(thisObjHandle)); } ElementsKind kind = thisObjHandle->GetClass()->GetElementsKind(); - JSHandle elements(thread, thisObjHandle->GetElements()); + JSHandle elements(thread, thisObjHandle->GetElements(thread)); if (thread->IsEnableMutantArray()) { if (kind == ElementsKind::INT || kind == ElementsKind::HOLE_INT) { return FastReverse(thread, elements, lower, len, ElementsKind::INT); @@ -1378,8 +1381,8 @@ JSTaggedValue JSStableArray::FastReverse(JSThread *thread, JSHandle break; } int64_t upper = static_cast(len) - lower - 1; - lowerValueHandle.Update(ElementAccessor::FastGet(elements, lower, kind)); - upperValueHandle.Update(ElementAccessor::FastGet(elements, upper, kind)); + lowerValueHandle.Update(ElementAccessor::FastGet(thread, elements, lower, kind)); + upperValueHandle.Update(ElementAccessor::FastGet(thread, elements, upper, kind)); ElementAccessor::FastSet(thread, elements, lower, upperValueHandle, kind); ElementAccessor::FastSet(thread, elements, upper, lowerValueHandle, kind); lower++; @@ -1395,7 +1398,7 @@ JSTaggedValue JSStableArray::Concat(JSThread *thread, JSHandle newArra RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); while (k < thisLen) { - if (ElementAccessor::GetElementsLength(thisObjHandle) != thisLen) { + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) != thisLen) { break; } toKey.Update(JSTaggedValue(n)); @@ -1422,9 +1425,9 @@ JSTaggedValue JSStableArray::FastCopyFromArrayToTypedArray(JSThread *thread, JSH DataViewType targetType, uint64_t targetOffset, uint32_t srcLength, JSHandle &obj) { - JSHandle targetBuffer(thread, targetArray->GetViewedArrayBufferOrByteArray()); + JSHandle targetBuffer(thread, targetArray->GetViewedArrayBufferOrByteArray(thread)); // If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. - if (BuiltinsArrayBufferType::Type::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsArrayBufferType::Type::IsDetachedBuffer(thread, targetBuffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -1437,7 +1440,7 @@ JSTaggedValue JSStableArray::FastCopyFromArrayToTypedArray(JSThread *thread, JSH } uint32_t targetByteIndex = static_cast(targetOffset * targetElementSize + targetByteOffset); ContentType contentType = targetArray->GetContentType(); - uint32_t elemLen = ElementAccessor::GetElementsLength(obj); + uint32_t elemLen = ElementAccessor::GetElementsLength(thread, obj); if (contentType == ContentType::BigInt) { JSMutableHandle kValue(thread, JSTaggedValue::Hole()); JSMutableHandle elem(thread, JSTaggedValue::Hole()); @@ -1543,9 +1546,9 @@ JSTaggedValue JSStableArray::With(JSThread *thread, JSHandle receiver, JSHandle newArrayHandle(newArray); JSHandle thisObjVal(thisObjHandle); - TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject()); + TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements(thread).GetTaggedObject()); - if (insertCount > ElementAccessor::GetElementsLength(newArrayHandle)) { + if (insertCount > ElementAccessor::GetElementsLength(thread, newArrayHandle)) { destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, insertCount); } ASSERT(!newArrayHandle->GetJSHClass()->IsDictionaryMode()); @@ -1578,9 +1581,9 @@ JSTaggedValue JSStableArray::ToSpliced(JSHandle receiver, EcmaRuntimeCa JSHandle newArrayHandle(newArray); JSHandle thisObjVal(thisObjHandle); - TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject()); + TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements(thread).GetTaggedObject()); - if (insertCount > ElementAccessor::GetElementsLength(newArrayHandle)) { + if (insertCount > ElementAccessor::GetElementsLength(thread, newArrayHandle)) { destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, insertCount); } ASSERT(!newArrayHandle->GetJSHClass()->IsDictionaryMode()); @@ -1628,9 +1631,9 @@ JSTaggedValue JSStableArray::ToReversed(JSThread *thread, JSHandle rece JSHandle newArrayHandle(newArray); JSHandle thisObjVal(thisObjHandle); - TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements().GetTaggedObject()); + TaggedArray *destElements = TaggedArray::Cast(newArrayHandle->GetElements(thread).GetTaggedObject()); - if (insertCount > ElementAccessor::GetElementsLength(newArrayHandle)) { + if (insertCount > ElementAccessor::GetElementsLength(thread, newArrayHandle)) { destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, insertCount); } ASSERT(!newArrayHandle->GetJSHClass()->IsDictionaryMode()); @@ -1668,8 +1671,8 @@ JSTaggedValue JSStableArray::Reduce(JSThread *thread, JSHandle thisObj thisObjVal.GetTaggedValue()); callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (ElementAccessor::GetElementsLength(thisObjHandle) < len) { - len = ElementAccessor::GetElementsLength(thisObjHandle); + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) < len) { + len = ElementAccessor::GetElementsLength(thread, thisObjHandle); } accumulator.Update(callResult); } @@ -1686,7 +1689,7 @@ JSTaggedValue JSStableArray::Slice(JSThread *thread, JSHandle thisObjH { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle thisObjVal(thisObjHandle); - int64_t len = static_cast(ElementAccessor::GetElementsLength(thisObjHandle)); + int64_t len = static_cast(ElementAccessor::GetElementsLength(thread, thisObjHandle)); int64_t oldLen; if (len > k + count) { oldLen = count; @@ -1710,7 +1713,7 @@ JSHandle JSStableArray::SortIndexedProperties(JSThread *thread, con base::HolesType holes) { JSHandle thisObj(thread, thisObjVal.GetTaggedValue()); - JSHandle elements(thread, thisObj->GetElements()); + JSHandle elements(thread, thisObj->GetElements(thread)); ElementsKind kind = thisObj->GetClass()->GetElementsKind(); if (!elements->GetClass()->IsMutantTaggedArray()) { kind = ElementsKind::GENERIC; @@ -1720,7 +1723,7 @@ JSHandle JSStableArray::SortIndexedProperties(JSThread *thread, con bool kRead = false; int64_t tmp = 0; for (int k = 0; k < len; k++) { - JSTaggedValue kValue = ElementAccessor::FastGet(elements, k, kind); + JSTaggedValue kValue = ElementAccessor::FastGet(thread, elements, k, kind); if (holes == base::HolesType::SKIP_HOLES) { kRead = (kValue != JSTaggedValue::Hole()); } else { @@ -1754,8 +1757,8 @@ JSTaggedValue JSStableArray::CopySortedListToReceiver(JSThread *thread, const JS // grow elements if len > newLength. JSHandle thisObj(thisObjVal); uint32_t newLength = std::max(JSHandle::Cast(thisObjVal)->GetArrayLength(), itemCount); - TaggedArray *elements = TaggedArray::Cast(thisObj->GetElements().GetTaggedObject()); - if (newLength > ElementAccessor::GetElementsLength(thisObj)) { + TaggedArray *elements = TaggedArray::Cast(thisObj->GetElements(thread).GetTaggedObject()); + if (newLength > ElementAccessor::GetElementsLength(thread, thisObj)) { elements = *JSObject::GrowElementsCapacity(thread, thisObj, newLength, true); } @@ -1766,7 +1769,7 @@ JSTaggedValue JSStableArray::CopySortedListToReceiver(JSThread *thread, const JS // a. Perform ! Set(obj, ! ToString((j)), sortedList[j], true). // b. Set j to j + 1. for (uint32_t j = 0; j < itemCount; j++) { - valueHandle.Update(sortedList->Get(j)); + valueHandle.Update(sortedList->Get(thread, j)); ElementAccessor::Set(thread, thisObj, j, valueHandle, needTransition); } // 9. NOTE: The call to SortIndexedProperties in step 5 uses SKIP-HOLES.The remaining indices are deleted to @@ -1814,7 +1817,7 @@ JSTaggedValue JSStableArray::Fill(JSThread *thread, const JSHandle &th int64_t end) { JSArray::CheckAndCopyArray(thread, JSHandle::Cast(thisObj)); - uint32_t length = ElementAccessor::GetElementsLength(thisObj); + uint32_t length = ElementAccessor::GetElementsLength(thread, thisObj); ElementsKind oldKind = thisObj->GetClass()->GetElementsKind(); if (start == 0 && end == length) { if (oldKind != ElementsKind::GENERIC) { @@ -1825,16 +1828,16 @@ JSTaggedValue JSStableArray::Fill(JSThread *thread, const JSHandle &th Elements::MigrateArrayWithKind(thread, thisObj, oldKind, newKind); } if (length >= end) { - if (thisObj->GetElements().IsMutantTaggedArray()) { + if (thisObj->GetElements(thread).IsMutantTaggedArray()) { ElementsKind kind = thisObj->GetClass()->GetElementsKind(); - TaggedArray *elements = TaggedArray::Cast(thisObj->GetElements()); + TaggedArray *elements = TaggedArray::Cast(thisObj->GetElements(thread)); JSTaggedValue migratedValue = JSTaggedValue(ElementAccessor::ConvertTaggedValueWithElementsKind( value.GetTaggedValue(), kind)); for (int64_t idx = start; idx < end; idx++) { elements->Set(thread, idx, migratedValue); } } else { - TaggedArray *elements = TaggedArray::Cast(thisObj->GetElements()); + TaggedArray *elements = TaggedArray::Cast(thisObj->GetElements(thread)); for (int64_t idx = start; idx < end; idx++) { elements->Set(thread, idx, value); } @@ -1879,8 +1882,8 @@ JSTaggedValue JSStableArray::HandleFindLastOfStable(JSThread *thread, JSHandle 0); - if (ElementAccessor::GetElementsLength(thisObjHandle) - 1 < k) { + ASSERT(ElementAccessor::GetElementsLength(thread, thisObjHandle) > 0); + if (ElementAccessor::GetElementsLength(thread, thisObjHandle) - 1 < k) { break; } if (!thisObjVal->IsStableJSArray(thread)) { diff --git a/ecmascript/js_stable_array.h b/ecmascript/js_stable_array.h index fc9d9a5fbe..db313b1d17 100644 --- a/ecmascript/js_stable_array.h +++ b/ecmascript/js_stable_array.h @@ -129,21 +129,22 @@ public: private: template - static const JSTaggedType* IndexOfElements(Span rawElements, IndexOfOptions options, - Predicate predicate); - static const JSTaggedType* IndexOfUndefined(Span elements, IndexOfOptions options, - bool isMutant); - static const JSTaggedType* IndexOfTaggedZero(Span taggedElements, IndexOfOptions options); - static const JSTaggedType* IndexOfInt(Span elements, JSTaggedValue searchElement, - IndexOfOptions options, bool isMutantInt32Array); - static const JSTaggedType* IndexOfDouble(Span elements, JSTaggedValue searchElement, - IndexOfOptions options, bool isMutantDoubleArray); - static const JSTaggedType* IndexOfObjectAddress(Span elements, JSTaggedValue searchElement, - IndexOfOptions options); - static const JSTaggedType* IndexOfString(Span elements, JSTaggedValue searchElement, - IndexOfOptions options); - static const JSTaggedType* IndexOfBigInt(Span elements, JSTaggedValue searchElement, - IndexOfOptions options); + static const JSTaggedType* IndexOfElements(JSThread *thread, Span rawElements, + IndexOfOptions options, Predicate predicate); + static const JSTaggedType* IndexOfUndefined(JSThread *thread, Span elements, + IndexOfOptions options, bool isMutant); + static const JSTaggedType* IndexOfTaggedZero(JSThread *thread, Span taggedElements, + IndexOfOptions options); + static const JSTaggedType* IndexOfInt(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options, bool isMutantInt32Array); + static const JSTaggedType* IndexOfDouble(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options, bool isMutantDoubleArray); + static const JSTaggedType* IndexOfObjectAddress(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options); + static const JSTaggedType* IndexOfString(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options); + static const JSTaggedType* IndexOfBigInt(JSThread *thread, Span elements, + JSTaggedValue searchElement, IndexOfOptions options); static JSTaggedValue IndexOfDispatch(JSThread *thread, JSHandle receiver, JSHandle searchElementHandle, uint32_t from, uint32_t len, IndexOfOptions options); @@ -160,7 +161,7 @@ private: JSHandle &holeHandle); #if !ENABLE_NEXT_OPTIMIZATION - static void SetSepValue(JSHandle sepStringHandle, int &sep, uint32_t &sepLength); + static void SetSepValue(JSThread *thread, JSHandle sepStringHandle, int &sep, uint32_t &sepLength); static JSTaggedValue JoinUseTreeString(const JSThread *thread, const JSHandle receiverValue, const JSHandle sepStringHandle, const int sep, diff --git a/ecmascript/js_symbol.h b/ecmascript/js_symbol.h index e601ad3986..ad6ab0747c 100644 --- a/ecmascript/js_symbol.h +++ b/ecmascript/js_symbol.h @@ -117,14 +117,14 @@ public: SetFlags(GetFlags() | IS_PRIVATE_NAME); } - static bool Equal(const JSSymbol &src, const JSSymbol &dst) + static bool Equal(JSThread *thread, const JSSymbol &src, const JSSymbol &dst) { if (src.GetFlags() != dst.GetFlags()) { return false; } - EcmaString *srcString = EcmaString::Cast(src.GetDescription().GetTaggedObject()); - EcmaString *dstString = EcmaString::Cast(dst.GetDescription().GetTaggedObject()); - return EcmaStringAccessor::StringsAreEqual(srcString, dstString); + EcmaString *srcString = EcmaString::Cast(src.GetDescription(thread).GetTaggedObject()); + EcmaString *dstString = EcmaString::Cast(dst.GetDescription(thread).GetTaggedObject()); + return EcmaStringAccessor::StringsAreEqual(thread, srcString, dstString); } uint64_t GetPrivateId() diff --git a/ecmascript/js_tagged_value-inl.h b/ecmascript/js_tagged_value-inl.h index 85862ae181..f8f6174826 100644 --- a/ecmascript/js_tagged_value-inl.h +++ b/ecmascript/js_tagged_value-inl.h @@ -79,7 +79,7 @@ inline bool JSTaggedValue::IsPropertyKey(const JSHandle &key) return key->IsStringOrSymbol() || key->IsNumber(); } -inline bool JSTaggedValue::SameValue(const JSTaggedValue &x, const JSTaggedValue &y) +inline bool JSTaggedValue::SameValue(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) { // same object or special type must be same value if (x == y) { @@ -93,7 +93,7 @@ inline bool JSTaggedValue::SameValue(const JSTaggedValue &x, const JSTaggedValue return SameValueNumberic(x, y); } if (x.IsString() && y.IsString()) { - return StringCompare(EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject())); + return StringCompare(const_cast(thread), EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject())); } if (x.IsBigInt() && y.IsBigInt()) { return BigInt::SameValue(x, y); @@ -101,23 +101,24 @@ inline bool JSTaggedValue::SameValue(const JSTaggedValue &x, const JSTaggedValue return false; } -inline bool JSTaggedValue::SameValue(const JSHandle &xHandle, const JSHandle &yHandle) +inline bool JSTaggedValue::SameValue(const JSThread *thread, const JSHandle &xHandle, const JSHandle &yHandle) { - return SameValue(xHandle.GetTaggedValue(), yHandle.GetTaggedValue()); + return SameValue(thread, xHandle.GetTaggedValue(), yHandle.GetTaggedValue()); } -inline bool JSTaggedValue::SameValueString(const JSHandle &xHandle, +inline bool JSTaggedValue::SameValueString(const JSThread *thread, + const JSHandle &xHandle, const JSHandle &yHandle) { - return SameValueString(xHandle.GetTaggedValue(), yHandle.GetTaggedValue()); + return SameValueString(thread, xHandle.GetTaggedValue(), yHandle.GetTaggedValue()); } -inline bool JSTaggedValue::SameValueString(const JSTaggedValue &x, const JSTaggedValue &y) +inline bool JSTaggedValue::SameValueString(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) { - return StringCompare(EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject())); + return StringCompare(thread, EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject())); } -inline bool JSTaggedValue::SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y) +inline bool JSTaggedValue::SameValueZero(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) { if (x == y) { return true; @@ -133,7 +134,7 @@ inline bool JSTaggedValue::SameValueZero(const JSTaggedValue &x, const JSTaggedV if (x.IsString() && y.IsString()) { auto xStr = static_cast(x.GetTaggedObject()); auto yStr = static_cast(y.GetTaggedObject()); - return EcmaStringAccessor::StringsAreEqual(xStr, yStr); + return EcmaStringAccessor::StringsAreEqual(thread, xStr, yStr); } if (x.IsBigInt() && y.IsBigInt()) { return BigInt::SameValueZero(x, y); @@ -173,13 +174,13 @@ inline bool JSTaggedValue::StrictIntEquals(int x, int y) return x == y; } -inline bool JSTaggedValue::StrictEqual([[maybe_unused]] const JSThread *thread, const JSHandle &x, +inline bool JSTaggedValue::StrictEqual(const JSThread *thread, const JSHandle &x, const JSHandle &y) { - return StrictEqual(x.GetTaggedValue(), y.GetTaggedValue()); + return StrictEqual(thread, x.GetTaggedValue(), y.GetTaggedValue()); } -inline bool JSTaggedValue::StrictEqual(const JSTaggedValue &x, const JSTaggedValue &y) +inline bool JSTaggedValue::StrictEqual(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y) { if (x.IsInt() && y.IsInt()) { return StrictIntEquals(x.GetInt(), y.GetInt()); @@ -193,7 +194,8 @@ inline bool JSTaggedValue::StrictEqual(const JSTaggedValue &x, const JSTaggedVal return true; } if (x.IsString() && y.IsString()) { - return StringCompare(EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject())); + return StringCompare(const_cast(thread), + EcmaString::Cast(x.GetTaggedObject()), EcmaString::Cast(y.GetTaggedObject())); } if (x.IsBigInt() && y.IsBigInt()) { return BigInt::Equal(x, y); @@ -224,22 +226,22 @@ inline bool JSTaggedValue::IsInSharedSweepableSpace() const return false; } -inline bool JSTaggedValue::IsEnumCacheAllValid() const +inline bool JSTaggedValue::IsEnumCacheAllValid(const JSThread *thread) const { return IsEnumCache() && - EnumCache::Cast(GetTaggedObject())->IsEnumCacheAllValid(); + EnumCache::Cast(GetTaggedObject())->IsEnumCacheAllValid(thread); } -inline bool JSTaggedValue::IsEnumCacheOwnValid() const +inline bool JSTaggedValue::IsEnumCacheOwnValid(const JSThread *thread) const { return IsEnumCache() && - EnumCache::Cast(GetTaggedObject())->IsEnumCacheOwnValid(); + EnumCache::Cast(GetTaggedObject())->IsEnumCacheOwnValid(thread); } -inline bool JSTaggedValue::IsEnumCacheProtoInfoUndefined() const +inline bool JSTaggedValue::IsEnumCacheProtoInfoUndefined(const JSThread *thread) const { return IsEnumCache() && - EnumCache::Cast(GetTaggedObject())->IsEnumCacheProtoInfoUndefined(); + EnumCache::Cast(GetTaggedObject())->IsEnumCacheProtoInfoUndefined(thread); } inline bool JSTaggedValue::IsNumber() const @@ -1383,7 +1385,7 @@ inline uint32_t JSTaggedValue::GetArrayLength() const UNREACHABLE(); } -inline bool JSTaggedValue::ToElementIndex(JSTaggedValue key, uint32_t *output) +inline bool JSTaggedValue::ToElementIndex(JSThread *thread, JSTaggedValue key, uint32_t *output) { if (key.IsInt()) { int index = key.GetInt(); @@ -1399,30 +1401,30 @@ inline bool JSTaggedValue::ToElementIndex(JSTaggedValue key, uint32_t *output) return true; } } else if (key.IsString()) { - return StringToElementIndex(key, output); + return StringToElementIndex(thread, key, output); } return false; } -inline bool JSTaggedValue::StringToElementIndex(JSTaggedValue key, uint32_t *output) +inline bool JSTaggedValue::StringToElementIndex(JSThread *thread, JSTaggedValue key, uint32_t *output) { ASSERT(key.IsString()); auto strObj = static_cast(key.GetTaggedObject()); - return EcmaStringAccessor(strObj).ToElementIndex(output); + return EcmaStringAccessor(strObj).ToElementIndex(thread, output); } -inline uint32_t JSTaggedValue::GetKeyHashCode() const +inline uint32_t JSTaggedValue::GetKeyHashCode(const JSThread *thread) const { ASSERT(IsStringOrSymbol()); if (IsString()) { - return EcmaStringAccessor(GetTaggedObject()).GetHashcode(); + return EcmaStringAccessor(GetTaggedObject()).GetHashcode(thread); } return JSSymbol::Cast(GetTaggedObject())->GetHashField(); } -inline JSTaggedNumber JSTaggedValue::StringToDouble(JSTaggedValue tagged) +inline JSTaggedNumber JSTaggedValue::StringToDouble(JSThread *thread, JSTaggedValue tagged) { auto strObj = static_cast(tagged.GetTaggedObject()); size_t strLen = EcmaStringAccessor(strObj).GetLength(); @@ -1430,18 +1432,18 @@ inline JSTaggedNumber JSTaggedValue::StringToDouble(JSTaggedValue tagged) return JSTaggedNumber(0); } CVector buf; - Span str = EcmaStringAccessor(strObj).ToUtf8Span(buf); + Span str = EcmaStringAccessor(strObj).ToUtf8Span(thread, buf); double d = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::ALLOW_BINARY + base::ALLOW_OCTAL + base::ALLOW_HEX); return JSTaggedNumber(d); } -inline bool JSTaggedValue::StringCompare(EcmaString *xStr, EcmaString *yStr) +inline bool JSTaggedValue::StringCompare(const JSThread *thread, EcmaString *xStr, EcmaString *yStr) { if (EcmaStringAccessor(xStr).IsInternString() && EcmaStringAccessor(yStr).IsInternString()) { return xStr == yStr; } - return EcmaStringAccessor::StringsAreEqual(xStr, yStr); + return EcmaStringAccessor::StringsAreEqual(thread, xStr, yStr); } inline JSTaggedValue JSTaggedValue::TryCastDoubleToInt32(double d) @@ -1452,13 +1454,13 @@ inline JSTaggedValue JSTaggedValue::TryCastDoubleToInt32(double d) return JSTaggedValue(static_cast(d)); } -inline bool JSTaggedValue::IsPureString(JSTaggedValue key) +inline bool JSTaggedValue::IsPureString(JSThread *thread, JSTaggedValue key) { if (!key.IsString()) { return false; } uint32_t idx; - return !StringToElementIndex(key, &idx); + return !StringToElementIndex(thread, key, &idx); } inline JSHandle JSTaggedValue::PublishSharedValue(JSThread *thread, JSHandle value) diff --git a/ecmascript/js_tagged_value.cpp b/ecmascript/js_tagged_value.cpp index c3f3f7ff2c..92111ed13a 100644 --- a/ecmascript/js_tagged_value.cpp +++ b/ecmascript/js_tagged_value.cpp @@ -104,7 +104,7 @@ JSTaggedNumber JSTaggedValue::ToNumber(JSThread *thread, JSTaggedValue tagged) } } if (tagged.IsString()) { - return StringToNumber(tagged); + return StringToNumber(thread, tagged); } } if (tagged.IsECMAObject()) { @@ -378,10 +378,10 @@ bool JSTaggedValue::IsInteger() const return true; } -bool JSTaggedValue::IsJSCOWArray() const +bool JSTaggedValue::IsJSCOWArray(const JSThread *thread) const { // Elements of JSArray are shared and properties are not yet. - return IsJSArray() && JSArray::Cast(GetTaggedObject())->GetElements().IsCOWArray(); + return IsJSArray() && JSArray::Cast(GetTaggedObject())->GetElements(thread).IsCOWArray(); } bool JSTaggedValue::IsStableJSArray(JSThread *thread) const @@ -705,8 +705,8 @@ ComparisonResult JSTaggedValue::Compare(JSThread *thread, const JSHandle &y) { if (x->IsDate() && y->IsDate()) { - double timeX = JSDate::Cast(x->GetTaggedObject())->GetTimeValue().GetDouble(); - double timeY = JSDate::Cast(y->GetTaggedObject())->GetTimeValue().GetDouble(); + double timeX = JSDate::Cast(x->GetTaggedObject())->GetTimeValue(thread).GetDouble(); + double timeY = JSDate::Cast(y->GetTaggedObject())->GetTimeValue(thread).GetDouble(); return StrictNumberCompare(timeX, timeY); } JSHandle primX(thread, ToPrimitive(thread, x)); @@ -893,7 +893,7 @@ std::string JSTaggedValue::ExceptionToString(JSThread *thread, const JSHandle JSTaggedValue::ToString(JSThread *thread, const JSHandle &tagged) @@ -972,7 +972,7 @@ JSTaggedValue JSTaggedValue::CanonicalNumericIndexString(JSThread *thread, const } JSHandle tmp(thread, ToNumber(thread, tagged)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (SameValue(ToString(thread, tmp).GetTaggedValue(), tagged.GetTaggedValue())) { + if (SameValue(thread, ToString(thread, tmp).GetTaggedValue(), tagged.GetTaggedValue())) { return tmp.GetTaggedValue(); } } @@ -1029,8 +1029,8 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &key, SCheckMode sCheckMode) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { - std::string keyStr = EcmaStringAccessor(ToString(thread, key)).ToStdString(); - std::string objStr = EcmaStringAccessor(ToString(thread, obj)).ToStdString(); + std::string keyStr = EcmaStringAccessor(ToString(thread, key)).ToStdString(thread); + std::string objStr = EcmaStringAccessor(ToString(thread, obj)).ToStdString(thread); std::string message = "Cannot read property "; message.append(keyStr).append(" of ").append(objStr); THROW_TYPE_ERROR_AND_RETURN(thread, message.c_str(), @@ -1058,7 +1058,7 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &obj, uint32_t key) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { - std::string objStr = EcmaStringAccessor(ToString(thread, obj)).ToStdString(); + std::string objStr = EcmaStringAccessor(ToString(thread, obj)).ToStdString(thread); std::string message = "Cannot read property "; message.append(ToCString(key)).append(" of ").append(objStr); THROW_TYPE_ERROR_AND_RETURN(thread, message.c_str(), @@ -1086,8 +1086,8 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &key, const JSHandle &receiver) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { - std::string keyStr = EcmaStringAccessor(ToString(thread, key)).ToStdString(); - std::string objStr = EcmaStringAccessor(ToString(thread, obj)).ToStdString(); + std::string keyStr = EcmaStringAccessor(ToString(thread, key)).ToStdString(thread); + std::string objStr = EcmaStringAccessor(ToString(thread, obj)).ToStdString(thread); std::string message = "Cannot read property "; message.append(keyStr).append(" of ").append(objStr); THROW_TYPE_ERROR_AND_RETURN(thread, message.c_str(), @@ -1328,10 +1328,10 @@ bool JSTaggedValue::SetPrototype(JSThread *thread, const JSHandle } if (obj->IsJSFunction() && proto->IsJSFunction()) { JSHandle objFunc = JSHandle::Cast(obj); - JSTaggedValue objProtoOrHClass(objFunc->GetProtoOrHClass()); - if (objProtoOrHClass.IsJSHClass() && objFunc->IsDerivedConstructor()) { + JSTaggedValue objProtoOrHClass(objFunc->GetProtoOrHClass(thread)); + if (objProtoOrHClass.IsJSHClass() && objFunc->IsDerivedConstructor(thread)) { JSHandle cachedJSHClass = JSHandle(thread, objProtoOrHClass); - objFunc->SetProtoOrHClass(thread, cachedJSHClass->GetPrototype()); + objFunc->SetProtoOrHClass(thread, cachedJSHClass->GetPrototype(thread)); } } @@ -1347,7 +1347,7 @@ JSTaggedValue JSTaggedValue::GetPrototype(JSThread *thread, const JSHandleIsJSProxy()) { return JSProxy::GetPrototype(thread, JSHandle(obj)); } - return JSObject::GetPrototype(JSHandle(obj)); + return JSObject::GetPrototype(thread, JSHandle(obj)); } bool JSTaggedValue::PreventExtensions(JSThread *thread, const JSHandle &obj) @@ -1477,7 +1477,7 @@ bool JSTaggedValue::CanBeHeldWeakly(JSThread *thread, const JSHandleIsSymbol()) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); auto *table = env->GetRegisterSymbols().GetObject(); - JSTaggedValue key = table->FindSymbol(tagged.GetTaggedValue()); + JSTaggedValue key = table->FindSymbol(thread, tagged.GetTaggedValue()); if (key.IsUndefined()) { return true; } @@ -1539,23 +1539,23 @@ JSHandle JSTaggedValue::ToPrototypeOrObj(JSThread *thread, const JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); if (obj->IsNumber()) { return JSHandle(thread, - env->GetNumberFunction().GetObject()->GetFunctionPrototype()); + env->GetNumberFunction().GetObject()->GetFunctionPrototype(thread)); } if (obj->IsBoolean()) { return JSHandle(thread, - env->GetBooleanFunction().GetObject()->GetFunctionPrototype()); + env->GetBooleanFunction().GetObject()->GetFunctionPrototype(thread)); } if (obj->IsString()) { return JSHandle(thread, - env->GetStringFunction().GetObject()->GetFunctionPrototype()); + env->GetStringFunction().GetObject()->GetFunctionPrototype(thread)); } if (obj->IsSymbol()) { return JSHandle(thread, - env->GetSymbolFunction().GetObject()->GetFunctionPrototype()); + env->GetSymbolFunction().GetObject()->GetFunctionPrototype(thread)); } if (obj->IsBigInt()) { return JSHandle(thread, - env->GetBigIntFunction().GetObject()->GetFunctionPrototype()); + env->GetBigIntFunction().GetObject()->GetFunctionPrototype(thread)); } return obj; } @@ -1577,27 +1577,27 @@ bool JSTaggedValue::HasContainerProperty(JSThread *thread, const JSHandleGetObjectType(); switch (jsType) { case JSType::JS_API_ARRAY_LIST: { - return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); + return JSHandle::Cast(obj)->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_QUEUE: { - return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); + return JSHandle::Cast(obj)->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_PLAIN_ARRAY: { return JSObject::HasProperty(thread, JSHandle(obj), key); } case JSType::JS_API_DEQUE: { - return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); + return JSHandle::Cast(obj)->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_STACK: { - return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); + return JSHandle::Cast(obj)->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_LIST: { JSHandle list = JSHandle::Cast(obj); - return list->Has(key.GetTaggedValue()); + return list->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_LINKED_LIST: { JSHandle linkedList = JSHandle::Cast(obj); - return linkedList->Has(key.GetTaggedValue()); + return linkedList->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_HASH_MAP: case JSType::JS_API_HASH_SET: @@ -1608,10 +1608,10 @@ bool JSTaggedValue::HasContainerProperty(JSThread *thread, const JSHandle(obj), key); } case JSType::JS_API_VECTOR: { - return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); + return JSHandle::Cast(obj)->Has(thread, key.GetTaggedValue()); } case JSType::JS_API_BITVECTOR: { - return JSHandle::Cast(obj)->Has(key.GetTaggedValue()); + return JSHandle::Cast(obj)->Has(thread, key.GetTaggedValue()); } default: { LOG_ECMA(FATAL) << "this branch is unreachable"; @@ -1751,7 +1751,7 @@ bool JSTaggedValue::GetContainerProperty(JSThread *thread, const JSHandle buf; - Span str = strAccessor.ToUtf8Span(buf); + Span str = strAccessor.ToUtf8Span(thread, buf); if (strAccessor.GetLength() == 0) { return JSTaggedNumber(0); } @@ -1770,7 +1770,7 @@ JSTaggedNumber JSTaggedValue::StringToNumber(JSTaggedValue tagged) } } CVector buf; - Span str = strAccessor.ToUtf8Span(buf); + Span str = strAccessor.ToUtf8Span(thread, buf); double d = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::ALLOW_BINARY + base::ALLOW_OCTAL + base::ALLOW_HEX); return JSTaggedNumber(d); @@ -1891,14 +1891,14 @@ bool JSTaggedValue::SetJSAPIProperty(JSThread *thread, const JSHandle &obj) { if (thread->GetEcmaVM()->GetJSOptions().EnableExceptionBacktrace()) { - DesensitizedDump(obj); + DesensitizedDump(thread, obj); } } -void JSTaggedValue::DesensitizedDump(const JSHandle &obj) +void JSTaggedValue::DesensitizedDump(const JSThread *thread, const JSHandle &obj) { std::ostringstream oss; - obj->Dump(oss, true); + obj->Dump(thread, oss, true); std::regex reg("0x[0-9a-fA-F]+"); std::string sensitiveStr = std::regex_replace(oss.str(), reg, ""); LOG_ECMA(ERROR) << "DumpExceptionObject: " << sensitiveStr; @@ -1913,9 +1913,9 @@ JSHandle JSTaggedValue::PublishSharedValueSlow(JSThread *thread, return JSHandle(thread, JSTaggedValue(flatStr)); } -uint32_t JSTaggedValue::GetStringKeyHashCode() const +uint32_t JSTaggedValue::GetStringKeyHashCode(const JSThread *thread) const { ASSERT(IsString()); - return EcmaStringAccessor(GetTaggedObject()).GetHashcode(); + return EcmaStringAccessor(GetTaggedObject()).GetHashcode(thread); } } // namespace panda::ecmascript diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index f15025946a..2e7c9f29de 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -402,13 +402,13 @@ public: static JSTaggedNumber ToLength(JSThread *thread, const JSHandle &tagged); static JSTaggedValue CanonicalNumericIndexString(JSThread *thread, const JSHandle &tagged); static JSTaggedNumber ToIndex(JSThread *thread, const JSHandle &tagged); - static JSTaggedNumber StringToDouble(JSTaggedValue tagged); - static JSTaggedNumber StringToNumber(JSTaggedValue tagged); + static JSTaggedNumber StringToDouble(JSThread *thread, JSTaggedValue tagged); + static JSTaggedNumber StringToNumber(JSThread *thread, JSTaggedValue tagged); static bool ToArrayLength(JSThread *thread, const JSHandle &tagged, uint32_t *output); - static bool ToElementIndex(JSTaggedValue key, uint32_t *output); - static bool StringToElementIndex(JSTaggedValue key, uint32_t *output); - static bool IsPureString(JSTaggedValue key); + static bool ToElementIndex(JSThread *thread, JSTaggedValue key, uint32_t *output); + static bool StringToElementIndex(JSThread *thread, JSTaggedValue key, uint32_t *output); + static bool IsPureString(JSThread *thread, JSTaggedValue key); uint32_t GetArrayLength() const; // ecma6 7.2 Testing and Comparison Operations @@ -422,15 +422,17 @@ public: static bool IsPropertyKey(const JSHandle &key); static JSHandle RequireObjectCoercible(JSThread *thread, const JSHandle &tagged, const char *message = "RequireObjectCoercible throw Error"); - static bool SameValue(const JSTaggedValue &x, const JSTaggedValue &y); - static bool SameValue(const JSHandle &xHandle, const JSHandle &yHandle); - static bool SameValueString(const JSTaggedValue &x, const JSTaggedValue &y); - static bool SameValueString(const JSHandle &xHandle, const JSHandle &yHandle); - static bool SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y); + static bool SameValue(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y); + static bool SameValue(const JSThread *thread, const JSHandle &xHandle, + const JSHandle &yHandle); + static bool SameValueString(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y); + static bool SameValueString(const JSThread *thread, const JSHandle &xHandle, + const JSHandle &yHandle); + static bool SameValueZero(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y); static bool Less(JSThread *thread, const JSHandle &x, const JSHandle &y); static bool Equal(JSThread *thread, const JSHandle &x, const JSHandle &y); static bool StrictEqual(const JSThread *thread, const JSHandle &x, const JSHandle &y); - static bool StrictEqual(const JSTaggedValue &x, const JSTaggedValue &y); + static bool StrictEqual(const JSThread *thread, const JSTaggedValue &x, const JSTaggedValue &y); static bool SameValueNumberic(const JSTaggedValue &x, const JSTaggedValue &y); // ES6 7.4 Operations on Iterator Objects @@ -529,7 +531,7 @@ public: bool IsMutantTaggedArray() const; bool IsJSArray() const; bool IsJSSharedArray() const; - bool PUBLIC_API IsJSCOWArray() const; + bool PUBLIC_API IsJSCOWArray(const JSThread *thread) const; bool IsStableJSArray(JSThread *thread) const; bool IsStableJSArguments(JSThread *thread) const; bool IsTypedArray() const; @@ -717,9 +719,9 @@ public: bool PUBLIC_API IsInSharedHeap() const; bool IsInSharedSweepableSpace() const; - bool IsEnumCacheAllValid() const; - bool IsEnumCacheOwnValid() const; - bool IsEnumCacheProtoInfoUndefined() const; + bool IsEnumCacheAllValid(const JSThread *thread) const; + bool IsEnumCacheOwnValid(const JSThread *thread) const; + bool IsEnumCacheProtoInfoUndefined(const JSThread *thread) const; static bool IsSameTypeOrHClass(JSTaggedValue x, JSTaggedValue y); static ComparisonResult Compare(JSThread *thread, const JSHandle &x, @@ -729,25 +731,25 @@ public: static ComparisonResult StrictNumberCompare(double x, double y); static bool StrictNumberEquals(double x, double y); static bool StrictIntEquals(int x, int y); - static bool StringCompare(EcmaString *xStr, EcmaString *yStr); + static bool StringCompare(const JSThread *thread, EcmaString *xStr, EcmaString *yStr); static JSHandle ToPrototypeOrObj(JSThread *thread, const JSHandle &obj); - inline uint32_t GetKeyHashCode() const; - uint32_t GetStringKeyHashCode() const; + inline uint32_t GetKeyHashCode(const JSThread *thread) const; + uint32_t GetStringKeyHashCode(const JSThread *thread) const; static JSTaggedValue GetSuperBase(JSThread *thread, const JSHandle &obj); static JSTaggedValue TryCastDoubleToInt32(double d); - void DumpTaggedValue(std::ostream &os) const DUMP_API_ATTR; + void DumpTaggedValue(const JSThread *thread, std::ostream &os) const DUMP_API_ATTR; void DumpTaggedValueType(std::ostream &os) const DUMP_API_ATTR; - void Dump(std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; - void DumpHeapObjAddress(std::ostream &os) const DUMP_API_ATTR; - void D() const DUMP_API_ATTR; - void DumpForSnapshot(std::vector &vec, bool isVmMode = true) const; - static void DesensitizedDump(const JSHandle &obj); - static void DV(JSTaggedType val) DUMP_API_ATTR; + void Dump(const JSThread *thread, std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; + void DumpHeapObjAddress(const JSThread *thread, std::ostream &os) const DUMP_API_ATTR; + void D(const JSThread *thread) const DUMP_API_ATTR; + void DumpForSnapshot(const JSThread *thread, std::vector &vec, bool isVmMode = true) const; + static void DesensitizedDump(const JSThread *thread, const JSHandle &obj); + static void DV(const JSThread *thread, JSTaggedType val) DUMP_API_ATTR; friend std::ostream& operator<<(std::ostream& os, const JSTaggedValue& value) { - value.Dump(os); + value.Dump(THREAD_ARG_PLACEHOLDER, os); // Dump() will handle nullptr as current thread return os; } @@ -757,7 +759,7 @@ private: inline double ExtractNumber() const; void DumpSpecialValue(std::ostream &os) const; - void DumpHeapObjectType(std::ostream &os) const; + void DumpHeapObjectType(const JSThread *thread, std::ostream &os) const; // non ECMA standard jsapis static bool HasContainerProperty(JSThread *thread, const JSHandle &obj, diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index ed67b2d22a..cc6a8b718c 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -325,7 +325,7 @@ void JSThread::HandleUncaughtException(JSTaggedValue exception) return; } JSHandle result = JSTaggedValue::ToString(this, exceptionHandle); - LOG_NO_TAG(ERROR) << ConvertToString(*result); + LOG_NO_TAG(ERROR) << ConvertToString(this, *result); } void JSThread::HandleUncaughtException() @@ -339,13 +339,13 @@ void JSThread::HandleUncaughtException() JSTaggedValue JSThread::GetCurrentLexenv() const { - FrameHandler frameHandler(this); + FrameHandler frameHandler(const_cast(this)); return frameHandler.GetEnv(); } JSTaggedValue JSThread::GetCurrentFunction() const { - FrameHandler frameHandler(this); + FrameHandler frameHandler(const_cast(this)); return frameHandler.GetFunction(); } @@ -368,7 +368,7 @@ void JSThread::SetCurrentFrame(JSTaggedType *sp) const JSTaggedType *JSThread::GetCurrentInterpretedFrame() const { if (IsAsmInterpreter()) { - auto frameHandler = FrameHandler(this); + auto frameHandler = FrameHandler(const_cast(this)); return frameHandler.GetSp(); } return GetCurrentSPFrame(); @@ -1179,7 +1179,7 @@ void JSThread::InitializeBuiltinObject(const JSHandle& env, const std } auto& entry = glueData_.builtinEntries_.builtin_[index]; entry.box_ = JSTaggedValue::Cast(box); - auto builtin = JSHandle(this, box->GetValue()); + auto builtin = JSHandle(this, box->GetValue(this)); auto hclass = builtin->GetJSHClass(); entry.hClass_ = JSTaggedValue::Cast(hclass); } diff --git a/ecmascript/js_typed_array.cpp b/ecmascript/js_typed_array.cpp index 4b936e1599..fea0aa5d81 100644 --- a/ecmascript/js_typed_array.cpp +++ b/ecmascript/js_typed_array.cpp @@ -91,8 +91,8 @@ bool JSTypedArray::HasProperty(JSThread *thread, const JSHandle & JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(thread, key); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (!numericIndex.IsUndefined()) { - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); - if (IsArrayBufferDetached(buffer)) { + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); + if (IsArrayBufferDetached(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); } if (!numericIndex.IsInteger()) { @@ -209,7 +209,7 @@ OperationResult JSTypedArray::GetProperty(JSThread *thread, const JSHandleIsString() || key->IsNumber()) && JSTaggedValue::SameValue(typedarray, receiver)) { + if ((key->IsString() || key->IsNumber()) && JSTaggedValue::SameValue(thread, typedarray, receiver)) { // a. Let numericIndex be CanonicalNumericIndexString (P). // b. Assert: numericIndex is not an abrupt completion. // c. If numericIndex is not undefined, then @@ -235,7 +235,7 @@ bool JSTypedArray::SetProperty(JSThread *thread, const JSHandle & // 1. Assert : IsPropertyKey(P) is true. ASSERT(JSTaggedValue::IsPropertyKey(key)); // 2. If Type(P) is String and if SameValue(O, Receiver) is true, then - if ((key->IsString() || key->IsNumber()) && JSTaggedValue::SameValue(typedarray, receiver)) { + if ((key->IsString() || key->IsNumber()) && JSTaggedValue::SameValue(thread, typedarray, receiver)) { // a. Let numericIndex be CanonicalNumericIndexString (P). // b. Assert: numericIndex is not an abrupt completion. // c. If numericIndex is not undefined, then @@ -265,7 +265,7 @@ bool JSTypedArray::DeleteProperty(JSThread *thread, const JSHandleIsString() || key->IsNumber()) { JSTaggedValue numericIndex = JSTaggedValue::CanonicalNumericIndexString(thread, key); if (!numericIndex.IsUndefined()) { - if (!IsValidIntegerIndex(typedarray, numericIndex)) { + if (!IsValidIntegerIndex(thread, typedarray, numericIndex)) { return true; } return false; @@ -306,7 +306,7 @@ JSHandle JSTypedArray::OwnPropertyKeys(JSThread *thread, const JSHa // property creation order // a. Add P as the last element of keys. for (uint32_t i = 0; i < objKeysLen; i++) { - JSTaggedValue key = objKeys->Get(i); + JSTaggedValue key = objKeys->Get(thread, i); if (JSTaggedValue(key).IsString()) { nameList->Set(thread, copyLength, key); copyLength++; @@ -316,7 +316,7 @@ JSHandle JSTypedArray::OwnPropertyKeys(JSThread *thread, const JSHa // 6. For each own property key P of O such that Type(P) is Symbol, in property creation order // a. Add P as the last element of keys. for (uint32_t i = 0; i < objKeysLen; i++) { - JSTaggedValue key = objKeys->Get(i); + JSTaggedValue key = objKeys->Get(thread, i); if (JSTaggedValue(key).IsSymbol()) { nameList->Set(thread, copyLength, key); copyLength++; @@ -354,7 +354,7 @@ JSHandle JSTypedArray::OwnEnumPropertyKeys(JSThread *thread, const // property creation order // a. Add P as the last element of keys. for (uint32_t i = 0; i < objKeysLen; i++) { - JSTaggedValue key = objKeys->Get(i); + JSTaggedValue key = objKeys->Get(thread, i); nameList->Set(thread, copyLength, key); copyLength++; } @@ -376,16 +376,16 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J ASSERT(typedarray->IsTypedArray() || typedarray->IsSharedTypedArray()); // 3. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSHandle typedarrayObj(typedarray); - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (!buffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (!buffer.IsSendableArrayBuffer() && BuiltinsArrayBuffer::IsDetachedBuffer(thread, buffer)) { if (index == JSTaggedValue(0)) { return OperationResult(thread, JSTaggedValue::Undefined(), PropertyMetaData(true)); } THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } - if (buffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(buffer)) { + if (buffer.IsSendableArrayBuffer() && BuiltinsSendableArrayBuffer::IsDetachedBuffer(thread, buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } @@ -432,14 +432,14 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J } // s12 10.4.5.9 IsValidIntegerIndex ( O, index ) -bool JSTypedArray::IsValidIntegerIndex(const JSHandle &typedArray, JSTaggedValue index) +bool JSTypedArray::IsValidIntegerIndex(JSThread *thread, const JSHandle &typedArray, JSTaggedValue index) { // 1. Assert: O is an Integer-Indexed exotic object. ASSERT(typedArray->IsTypedArray() || typedArray->IsSharedTypedArray()); // 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. JSHandle typedarrayObj(typedArray); - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); - if (IsArrayBufferDetached(buffer)) { + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); + if (IsArrayBufferDetached(thread, buffer)) { return false; } // 3. If ! IsIntegralNumber(index) is false, return false. @@ -464,44 +464,44 @@ bool JSTypedArray::IsValidIntegerIndex(const JSHandle &typedArray DataViewType JSTypedArray::GetTypeFromName(JSThread *thread, const JSHandle &typeName) { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedInt8ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledInt8ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedInt8ArrayString())) { return DataViewType::INT8; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedUint8ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledUint8ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedUint8ArrayString())) { return DataViewType::UINT8; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ClampedArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedUint8ClampedArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledUint8ClampedArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedUint8ClampedArrayString())) { return DataViewType::UINT8_CLAMPED; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt16ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedInt16ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledInt16ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedInt16ArrayString())) { return DataViewType::INT16; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint16ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedUint16ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledUint16ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedUint16ArrayString())) { return DataViewType::UINT16; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt32ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedInt32ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledInt32ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedInt32ArrayString())) { return DataViewType::INT32; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint32ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedUint32ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledUint32ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedUint32ArrayString())) { return DataViewType::UINT32; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat32ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedFloat32ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledFloat32ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedFloat32ArrayString())) { return DataViewType::FLOAT32; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat64ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedFloat64ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledFloat64ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedFloat64ArrayString())) { return DataViewType::FLOAT64; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledBigInt64ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledSharedBigInt64ArrayString())) { + if (JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledBigInt64ArrayString()) || + JSTaggedValue::SameValue(thread, typeName, globalConst->GetHandledSharedBigInt64ArrayString())) { return DataViewType::BIGINT64; } return DataViewType::BIGUINT64; @@ -518,8 +518,8 @@ bool JSTypedArray::FastCopyElementToArray(JSThread *thread, const JSHandle typedarrayObj(typedArray); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. JSHandle bufferHandle = - JSHandle(thread, typedarrayObj->GetViewedArrayBufferOrByteArray()); - if (IsArrayBufferDetached(bufferHandle.GetTaggedValue())) { + JSHandle(thread, typedarrayObj->GetViewedArrayBufferOrByteArray(thread)); + if (IsArrayBufferDetached(thread, bufferHandle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); } @@ -553,10 +553,10 @@ OperationResult JSTypedArray::FastElementGet(JSThread *thread, const JSHandleIsTypedArray() || typedarray->IsSharedTypedArray()); // 3. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSHandle typedarrayObj(typedarray); - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); // 10.4.5.15 TypedArrayGetElement ( O, index ) // 1. If IsValidIntegerIndex(O, index) is false, return undefined. - if (IsArrayBufferDetached(buffer)) { + if (IsArrayBufferDetached(thread, buffer)) { return OperationResult(thread, JSTaggedValue::Undefined(), PropertyMetaData(true)); } @@ -600,10 +600,10 @@ bool JSTypedArray::IntegerIndexedElementSet(JSThread *thread, const JSHandle typedarrayObj(typedarray); - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); JSHandle indexHandle(thread, index); // 5. If ! IsValidIntegerIndex(O, index) is true, then - if (IsValidIntegerIndex(typedarray, index)) { + if (IsValidIntegerIndex(thread, typedarray, index)) { // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. uint32_t offset = typedarrayObj->GetByteOffset(); // 7. Let arrayTypeName be the String value of O’s [[TypedArrayName]] internal slot. @@ -632,7 +632,7 @@ JSTaggedNumber JSTypedArray::NonEcmaObjectToNumber(JSThread *thread, const JSTag return JSTaggedNumber(tagged); } if (tagged.IsString()) { - return JSTaggedValue::StringToDouble(tagged); + return JSTaggedValue::StringToDouble(thread, tagged); } switch (tagged.GetRawData()) { case JSTaggedValue::VALUE_UNDEFINED: @@ -667,8 +667,8 @@ JSTaggedValue JSTypedArray::FastGetPropertyByIndex(JSThread *thread, const JSTag ASSERT(typedarray.IsTypedArray() || typedarray.IsSharedTypedArray()); // Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTypedArray *typedarrayObj = JSTypedArray::Cast(typedarray.GetTaggedObject()); - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); - if (IsArrayBufferDetached(buffer)) { + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); + if (IsArrayBufferDetached(thread, buffer)) { return JSTaggedValue::Undefined(); } @@ -706,7 +706,7 @@ JSTaggedValue JSTypedArray::FastSetPropertyByIndex(JSThread *thread, const JSTag RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); DISALLOW_GARBAGE_COLLECTION; - JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray(thread); // If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return false. uint32_t arrLen = typedarrayObj->GetArrayLength(); @@ -730,7 +730,7 @@ JSTaggedValue JSTypedArray::FastSetPropertyByIndex(JSThread *thread, const JSTag JSTaggedValue JSTypedArray::GetOffHeapBuffer(JSThread *thread, JSHandle &typedArray) { - JSTaggedValue arrBuf = typedArray->GetViewedArrayBufferOrByteArray(); + JSTaggedValue arrBuf = typedArray->GetViewedArrayBufferOrByteArray(thread); if (arrBuf.IsArrayBuffer() || arrBuf.IsSharedArrayBuffer()) { return arrBuf; } @@ -741,14 +741,14 @@ JSTaggedValue JSTypedArray::GetOffHeapBuffer(JSThread *thread, JSHandle 0) { void *fromBuf = reinterpret_cast(ToUintPtr( - ByteArray::Cast(typedArray->GetViewedArrayBufferOrByteArray().GetTaggedObject())->GetData())); - JSTaggedValue data = arrayBuffer->GetArrayBufferData(); + ByteArray::Cast(typedArray->GetViewedArrayBufferOrByteArray(thread).GetTaggedObject())->GetData())); + JSTaggedValue data = arrayBuffer->GetArrayBufferData(thread); void *toBuf = reinterpret_cast( ToUintPtr(JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer())); JSArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, 0, length); } typedArray->SetViewedArrayBufferOrByteArray(thread, arrayBuffer.GetTaggedValue()); - JSHandle typeName(thread, typedArray->GetTypedArrayName()); + JSHandle typeName(thread, typedArray->GetTypedArrayName(thread)); DataViewType arrayType = JSTypedArray::GetTypeFromName(thread, typeName); JSHandle notOnHeapHclass = TypedArrayHelper::GetNotOnHeapHclassFromType( thread, typedArray, arrayType); @@ -762,7 +762,7 @@ JSTaggedValue JSTypedArray::GetOffHeapBuffer(JSThread *thread, JSHandle typedArray) { - JSTaggedValue arrBuf = typedArray->GetViewedArrayBufferOrByteArray(); + JSTaggedValue arrBuf = typedArray->GetViewedArrayBufferOrByteArray(thread); if (arrBuf.IsSendableArrayBuffer()) { return arrBuf; } @@ -773,14 +773,14 @@ JSTaggedValue JSSharedTypedArray::GetSharedOffHeapBuffer(JSThread *thread, JSHan if (length > 0) { void *fromBuf = reinterpret_cast(ToUintPtr( - ByteArray::Cast(typedArray->GetViewedArrayBufferOrByteArray().GetTaggedObject())->GetData())); - JSTaggedValue data = arrayBuffer->GetArrayBufferData(); + ByteArray::Cast(typedArray->GetViewedArrayBufferOrByteArray(thread).GetTaggedObject())->GetData())); + JSTaggedValue data = arrayBuffer->GetArrayBufferData(thread); void *toBuf = reinterpret_cast( ToUintPtr(JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer())); JSSendableArrayBuffer::CopyDataPointBytes(toBuf, fromBuf, 0, length); } typedArray->SetViewedArrayBufferOrByteArray(thread, arrayBuffer.GetTaggedValue()); - JSHandle typeName(thread, typedArray->GetTypedArrayName()); + JSHandle typeName(thread, typedArray->GetTypedArrayName(thread)); DataViewType arrayType = JSTypedArray::GetTypeFromName(thread, typeName); JSHandle notOnHeapHclass = TypedArrayHelper::GetSharedNotOnHeapHclassFromType( thread, typedArray, arrayType); @@ -806,7 +806,7 @@ bool JSTypedArray::FastTypedArrayFill(JSThread *thread, const JSHandleGetViewedArrayBufferOrByteArray(); + JSTaggedValue buffer = typedArrayObj->GetViewedArrayBufferOrByteArray(thread); // If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return false. uint32_t arrLen = typedArrayObj->GetArrayLength(); // Let offset be the value of O’s [[ByteOffset]] internal slot. @@ -826,12 +826,12 @@ bool JSTypedArray::FastTypedArrayFill(JSThread *thread, const JSHandle &typedarray, JSTaggedValue index, const JSHandle &value); // s12 10.4.5.9 IsValidIntegerIndex ( O, index ) - static bool IsValidIntegerIndex(const JSHandle &typedArray, JSTaggedValue index); + static bool IsValidIntegerIndex(JSThread *thread, const JSHandle &typedArray, JSTaggedValue index); static JSTaggedValue FastGetPropertyByIndex(JSThread *thread, const JSTaggedValue typedarray, uint32_t index, JSType jsType); static JSTaggedValue PUBLIC_API FastSetPropertyByIndex(JSThread *thread, const JSTaggedValue typedarray, @@ -117,7 +117,7 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, VIEWED_ARRAY_BUFFER_OFFSET, BYTE_LENGTH_OFFSET) private: - static inline bool IsArrayBufferDetached(JSTaggedValue buffer); + static inline bool IsArrayBufferDetached(JSThread *thread, JSTaggedValue buffer); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JS_TYPED_ARRAY_H diff --git a/ecmascript/js_weak_container.cpp b/ecmascript/js_weak_container.cpp index 8f95db261a..4fab9bee8f 100644 --- a/ecmascript/js_weak_container.cpp +++ b/ecmascript/js_weak_container.cpp @@ -26,7 +26,7 @@ void JSWeakMap::Set(JSThread *thread, const JSHandle &map, const JSHa if (!LinkedHashMap::IsKey(JSTaggedValue(key.GetTaggedValue().CreateAndGetWeakRef()))) { THROW_TYPE_ERROR(thread, "the value must be Key of JSWeakMap"); } - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); JSHandle newMap = LinkedHashMap::SetWeakRef(thread, mapHandle, key, value); map->SetLinkedMap(thread, newMap); @@ -34,7 +34,7 @@ void JSWeakMap::Set(JSThread *thread, const JSHandle &map, const JSHa bool JSWeakMap::Delete(JSThread *thread, const JSHandle &map, const JSHandle &key) { - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); int entry = mapHandle->FindElement(thread, key.GetTaggedValue()); if (entry == -1) { return false; @@ -48,29 +48,29 @@ bool JSWeakMap::Delete(JSThread *thread, const JSHandle &map, const J bool JSWeakMap::Has(JSThread *thread, JSTaggedValue key) const { - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->Has(thread, key); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->Has(thread, key); } JSTaggedValue JSWeakMap::Get(JSThread *thread, JSTaggedValue key) const { - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->Get(thread, key); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->Get(thread, key); } -int JSWeakMap::GetSize() const +int JSWeakMap::GetSize(const JSThread *thread) const { - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->NumberOfElements(); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->NumberOfElements(); } -JSTaggedValue JSWeakMap::GetKey(int entry) const +JSTaggedValue JSWeakMap::GetKey(const JSThread *thread, int entry) const { - ASSERT_PRINT(entry >= 0 && entry < GetSize(), "entry must be non-negative integer less than capacity"); - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->GetKey(entry); + ASSERT_PRINT(entry >= 0 && entry < GetSize(thread), "entry must be non-negative integer less than capacity"); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->GetKey(thread, entry); } -JSTaggedValue JSWeakMap::GetValue(int entry) const +JSTaggedValue JSWeakMap::GetValue(const JSThread *thread, int entry) const { - ASSERT_PRINT(entry >= 0 && entry < GetSize(), "entry must be non-negative integer less than capacity"); - return LinkedHashMap::Cast(GetLinkedMap().GetTaggedObject())->GetValue(entry); + ASSERT_PRINT(entry >= 0 && entry < GetSize(thread), "entry must be non-negative integer less than capacity"); + return LinkedHashMap::Cast(GetLinkedMap(thread).GetTaggedObject())->GetValue(thread, entry); } void JSWeakSet::Add(JSThread *thread, const JSHandle &weakSet, const JSHandle &value) @@ -78,7 +78,7 @@ void JSWeakSet::Add(JSThread *thread, const JSHandle &weakSet, const if (!LinkedHashSet::IsKey(value.GetTaggedValue())) { THROW_TYPE_ERROR(thread, "the value must be Key of JSWeakSet"); } - JSHandle weakSetHandle(thread, LinkedHashSet::Cast(weakSet->GetLinkedSet().GetTaggedObject())); + JSHandle weakSetHandle(thread, LinkedHashSet::Cast(weakSet->GetLinkedSet(thread).GetTaggedObject())); JSHandle newSet = LinkedHashSet::AddWeakRef(thread, weakSetHandle, value); weakSet->SetLinkedSet(thread, newSet); @@ -86,7 +86,7 @@ void JSWeakSet::Add(JSThread *thread, const JSHandle &weakSet, const bool JSWeakSet::Delete(JSThread *thread, const JSHandle &weakSet, const JSHandle &value) { - JSHandle weakSetHandle(thread, LinkedHashSet::Cast(weakSet->GetLinkedSet().GetTaggedObject())); + JSHandle weakSetHandle(thread, LinkedHashSet::Cast(weakSet->GetLinkedSet(thread).GetTaggedObject())); int entry = weakSetHandle->FindElement(thread, value.GetTaggedValue()); if (entry == -1) { return false; @@ -99,17 +99,17 @@ bool JSWeakSet::Delete(JSThread *thread, const JSHandle &weakSet, con bool JSWeakSet::Has(JSThread *thread, JSTaggedValue value) const { - return LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject())->Has(thread, value); + return LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject())->Has(thread, value); } -int JSWeakSet::GetSize() const +int JSWeakSet::GetSize(const JSThread *thread) const { - return LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject())->NumberOfElements(); + return LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject())->NumberOfElements(); } -JSTaggedValue JSWeakSet::GetValue(int entry) const +JSTaggedValue JSWeakSet::GetValue(const JSThread *thread, int entry) const { - ASSERT_PRINT(entry >= 0 && entry < GetSize(), "entry must be non-negative integer less than capacity"); - return LinkedHashSet::Cast(GetLinkedSet().GetTaggedObject())->GetValue(entry); + ASSERT_PRINT(entry >= 0 && entry < GetSize(thread), "entry must be non-negative integer less than capacity"); + return LinkedHashSet::Cast(GetLinkedSet(thread).GetTaggedObject())->GetValue(thread, entry); } } // namespace panda::ecmascript diff --git a/ecmascript/js_weak_container.h b/ecmascript/js_weak_container.h index e4146eac07..57c1e071a9 100644 --- a/ecmascript/js_weak_container.h +++ b/ecmascript/js_weak_container.h @@ -36,11 +36,11 @@ public: JSTaggedValue Get(JSThread *thread, JSTaggedValue key) const; - int GetSize() const; + int GetSize(const JSThread *thread) const; - JSTaggedValue GetKey(int entry) const; + JSTaggedValue GetKey(const JSThread *thread, int entry) const; - JSTaggedValue GetValue(int entry) const; + JSTaggedValue GetValue(const JSThread *thread, int entry) const; static constexpr size_t LINKED_MAP_OFFSET = JSObject::SIZE; ACCESSORS(LinkedMap, LINKED_MAP_OFFSET, SIZE) @@ -62,9 +62,9 @@ public: bool Has(JSThread *thread, JSTaggedValue value) const; - int GetSize() const; + int GetSize(const JSThread *thread) const; - JSTaggedValue GetValue(int entry) const; + JSTaggedValue GetValue(const JSThread *thread, int entry) const; static constexpr size_t LINKED_SET_OFFSET = JSObject::SIZE; ACCESSORS(LinkedSet, LINKED_SET_OFFSET, SIZE) diff --git a/ecmascript/js_weak_ref.h b/ecmascript/js_weak_ref.h index daa8dd8f41..0905386d65 100644 --- a/ecmascript/js_weak_ref.h +++ b/ecmascript/js_weak_ref.h @@ -36,7 +36,7 @@ public: // a. Perform ! AddToKeptObjects(target). // b. Return target. // 3. Return undefined. - JSHandle target(thread, weakRef->GetFromWeak()); + JSHandle target(thread, weakRef->GetFromWeak(thread)); if (!target->IsUndefined()) { EcmaVM::AddToKeptObjects(thread, target); } @@ -51,9 +51,9 @@ public: SetWeakObject(thread, weakObj); } - JSTaggedValue GetFromWeak() const + JSTaggedValue GetFromWeak(JSThread *thread) const { - JSTaggedValue weakObj = GetWeakObject(); + JSTaggedValue weakObj = GetWeakObject(thread); if (!weakObj.IsUndefined()) { return JSTaggedValue(weakObj.GetWeakReferent()); } diff --git a/ecmascript/jspandafile/class_info_extractor.cpp b/ecmascript/jspandafile/class_info_extractor.cpp index 36ef9a9f26..a4a8bd8d04 100644 --- a/ecmascript/jspandafile/class_info_extractor.cpp +++ b/ecmascript/jspandafile/class_info_extractor.cpp @@ -53,9 +53,9 @@ void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JS } nonStaticKeys->Set(thread, CONSTRUCTOR_INDEX, globalConst->GetConstructorString()); - Method *method = Method::Cast(extractor->GetConstructorMethod().GetTaggedObject()); - MethodLiteral *methodLiteral = method->GetMethodLiteral(); - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + Method *method = Method::Cast(extractor->GetConstructorMethod(thread).GetTaggedObject()); + MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); EntityId methodId = method->GetMethodId(); if (nonStaticNum) { ExtractContentsDetail nonStaticDetail {0, nonStaticNum * 2, NON_STATIC_RESERVED_LENGTH, nullptr}; @@ -145,12 +145,12 @@ bool ClassInfoExtractor::ExtractAndReturnWhetherWithElements(JSThread *thread, c JSMutableHandle firstValue(thread, JSTaggedValue::Undefined()); JSMutableHandle secondValue(thread, JSTaggedValue::Undefined()); for (uint32_t index = detail.extractBegin; index < detail.extractEnd; index += 2) { // 2: key-value pair - firstValue.Update(literal->Get(index)); - secondValue.Update(literal->Get(index + 1)); + firstValue.Update(literal->Get(thread, index)); + secondValue.Update(literal->Get(thread, index + 1)); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(firstValue), "Key is not a property key"); if (LIKELY(firstValue->IsString())) { - if (isStaticFlag && !keysHasNameFlag && JSTaggedValue::SameValue(firstValue, nameString)) { + if (isStaticFlag && !keysHasNameFlag && JSTaggedValue::SameValue(thread, firstValue, nameString)) { properties->Set(thread, NAME_INDEX, secondValue); keysHasNameFlag = true; continue; @@ -158,7 +158,7 @@ bool ClassInfoExtractor::ExtractAndReturnWhetherWithElements(JSThread *thread, c // front-end can do better: write index in class literal directly. uint32_t elementIndex = 0; - if (JSTaggedValue::StringToElementIndex(firstValue.GetTaggedValue(), &elementIndex)) { + if (JSTaggedValue::StringToElementIndex(thread, firstValue.GetTaggedValue(), &elementIndex)) { ASSERT(elementIndex < JSObject::MAX_ELEMENT_INDEX); uint32_t elementsLength = elements->GetLength(); elements = @@ -212,11 +212,11 @@ JSHandle ClassInfoExtractor::CreatePrototypeHClass(JSThread *thread, JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSHandle layout = factory->CreateLayoutInfo(length, MemSpaceType::OLD_SPACE, GrowMode::KEEP); for (uint32_t index = 0; index < length; ++index) { - key.Update(keys->Get(index)); + key.Update(keys->Get(thread, index)); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes = PropertyAttributes::Default(true, false, true); // non-enumerable - if (UNLIKELY(properties->Get(index).IsAccessor())) { + if (UNLIKELY(properties->Get(thread, index).IsAccessor())) { attributes.SetIsAccessor(true); } @@ -252,7 +252,7 @@ JSHandle ClassInfoExtractor::CreateConstructorHClass(JSThread *thread, if (!thread->GetEcmaVM()->IsEnablePGOProfiler()) { // The class constructor of AOT is not shared, and PGO collect cannot be shared. if (length == ClassInfoExtractor::STATIC_RESERVED_LENGTH && base->IsHole() && - properties->Get(NAME_INDEX).IsString()) { + properties->Get(thread, NAME_INDEX).IsString()) { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); return JSHandle(globalConst->GetHandledClassConstructorClass()); } @@ -262,7 +262,7 @@ JSHandle ClassInfoExtractor::CreateConstructorHClass(JSThread *thread, JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSHandle layout = factory->CreateLayoutInfo(length, MemSpaceType::OLD_SPACE, GrowMode::KEEP); for (uint32_t index = 0; index < length; ++index) { - key.Update(keys->Get(index)); + key.Update(keys->Get(thread, index)); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes; switch (index) { @@ -270,10 +270,10 @@ JSHandle ClassInfoExtractor::CreateConstructorHClass(JSThread *thread, attributes = PropertyAttributes::Default(false, false, true); break; case NAME_INDEX: - if (LIKELY(properties->Get(NAME_INDEX).IsString())) { + if (LIKELY(properties->Get(thread, NAME_INDEX).IsString())) { attributes = PropertyAttributes::Default(false, false, true); } else { - ASSERT(properties->Get(NAME_INDEX).IsFunctionTemplate()); + ASSERT(properties->Get(thread, NAME_INDEX).IsFunctionTemplate()); attributes = PropertyAttributes::Default(true, false, true); } break; @@ -285,7 +285,7 @@ JSHandle ClassInfoExtractor::CreateConstructorHClass(JSThread *thread, break; } - if (UNLIKELY(properties->Get(index).IsAccessor())) { + if (UNLIKELY(properties->Get(thread, index).IsAccessor())) { attributes.SetIsAccessor(true); } @@ -319,22 +319,22 @@ void ClassInfoExtractor::CorrectConstructorHClass(JSThread *thread, if (constructorHClass->IsDictionaryMode()) { return; } - JSHandle layout(thread, constructorHClass->GetLayout()); + JSHandle layout(thread, constructorHClass->GetLayout(thread)); for (uint32_t index = 0; index < ClassInfoExtractor::STATIC_RESERVED_LENGTH; ++index) { if (index == NAME_INDEX) { - if (UNLIKELY(properties->Get(NAME_INDEX).IsFunctionTemplate())) { - PropertyAttributes attr = layout->GetAttr(index); + if (UNLIKELY(properties->Get(thread, NAME_INDEX).IsFunctionTemplate())) { + PropertyAttributes attr = layout->GetAttr(thread, index); attr.SetWritable(true); layout->SetNormalAttr(thread, index, attr); } - if (UNLIKELY(properties->Get(index).IsAccessor())) { - PropertyAttributes attr = layout->GetAttr(index); + if (UNLIKELY(properties->Get(thread, index).IsAccessor())) { + PropertyAttributes attr = layout->GetAttr(thread, index); attr.SetIsAccessor(true); layout->SetNormalAttr(thread, index, attr); } } else { - if (UNLIKELY(properties->Get(index).IsAccessor())) { - PropertyAttributes attr = layout->GetAttr(index); + if (UNLIKELY(properties->Get(thread, index).IsAccessor())) { + PropertyAttributes attr = layout->GetAttr(thread, index); attr.SetIsAccessor(true); layout->SetNormalAttr(thread, index, attr); } @@ -354,10 +354,10 @@ JSHandle ClassInfoExtractor::CreateSendableHClass(JSThread *thread, JS JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSHandle layout = factory->CreateSLayoutInfo(length + extraLength); for (uint32_t index = 0; index < length; ++index) { - key.Update(keys->Get(index)); + key.Update(keys->Get(thread, index)); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes = PropertyAttributes::Default(false, false, false); - if (UNLIKELY(properties->Get(index).IsAccessor())) { + if (UNLIKELY(properties->Get(thread, index).IsAccessor())) { attributes.SetIsAccessor(true); } attributes.SetIsInlinedProps(true); @@ -391,16 +391,16 @@ JSHandle ClassHelper::DefineClassFromExtractor(JSThread *thread, con const JSHandle &lexenv) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle staticKeys(thread, extractor->GetStaticKeys()); - JSHandle staticProperties(thread, extractor->GetStaticProperties()); + JSHandle staticKeys(thread, extractor->GetStaticKeys(thread)); + JSHandle staticProperties(thread, extractor->GetStaticProperties(thread)); - JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys()); - JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties()); + JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys(thread)); + JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties(thread)); JSHandle prototypeHClass = ClassInfoExtractor::CreatePrototypeHClass(thread, nonStaticKeys, nonStaticProperties); JSHandle prototype = factory->NewOldSpaceJSObject(prototypeHClass); - JSHandle method(thread, Method::Cast(extractor->GetConstructorMethod().GetTaggedObject())); + JSHandle method(thread, Method::Cast(extractor->GetConstructorMethod(thread).GetTaggedObject())); JSHandle constructorHClass = ClassInfoExtractor::CreateConstructorHClass(thread, base, staticKeys, staticProperties); // Allocate to non-movable space for PGO @@ -415,7 +415,7 @@ JSHandle ClassHelper::DefineClassFromExtractor(JSThread *thread, con if (LIKELY(!prototypeHClass->IsDictionaryMode())) { for (uint32_t index = 0; index < nonStaticLength; ++index) { - propValue.Update(nonStaticProperties->Get(index)); + propValue.Update(nonStaticProperties->Get(thread, index)); if (propValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(propValue); propValue.Update(CreateJSFunctionFromTemplate(thread, literalFunc, prototype, lexenv)); @@ -430,7 +430,7 @@ JSHandle ClassHelper::DefineClassFromExtractor(JSThread *thread, con // non-static elements if (UNLIKELY(extractor->GetNonStaticWithElements())) { - JSHandle nonStaticElements(thread, extractor->GetNonStaticElements()); + JSHandle nonStaticElements(thread, extractor->GetNonStaticElements(thread)); ClassHelper::HandleElementsProperties(thread, prototype, lexenv, nonStaticElements); } @@ -439,7 +439,7 @@ JSHandle ClassHelper::DefineClassFromExtractor(JSThread *thread, con if (LIKELY(!constructorHClass->IsDictionaryMode())) { for (uint32_t index = 0; index < staticLength; ++index) { - propValue.Update(staticProperties->Get(index)); + propValue.Update(staticProperties->Get(thread, index)); if (propValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(propValue); propValue.Update( @@ -455,7 +455,7 @@ JSHandle ClassHelper::DefineClassFromExtractor(JSThread *thread, con // static elements if (UNLIKELY(extractor->GetStaticWithElements())) { - JSHandle staticElements(thread, extractor->GetStaticElements()); + JSHandle staticElements(thread, extractor->GetStaticElements(thread)); ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), lexenv, staticElements); } @@ -479,8 +479,8 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const const JSHandle &constructorHClassVal) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle staticKeys(thread, extractor->GetStaticKeys()); - JSHandle staticProperties(thread, extractor->GetStaticProperties()); + JSHandle staticKeys(thread, extractor->GetStaticKeys(thread)); + JSHandle staticProperties(thread, extractor->GetStaticProperties(thread)); JSHandle constructorHClass; // When constructorHClassVal is undefined, it means that AOT has not generated the corresponding hclass (chc), // then chc will be created through the interpreter. @@ -491,8 +491,8 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const ClassInfoExtractor::CorrectConstructorHClass(thread, staticProperties, *constructorHClass); } - JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys()); - JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties()); + JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys(thread)); + JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties(thread)); JSHandle prototype; JSHandle prototypeOrHClass = prototypeOrHClassVal; // When prototypeOrHClassVal is undefined, it means that AOT has not generated the corresponding hclass or @@ -504,12 +504,12 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const prototypeOrHClass = JSHandle(prototype); } else if (prototypeOrHClassVal->IsJSHClass()) { JSHandle ihclass(prototypeOrHClassVal); - prototype = JSHandle(thread, ihclass->GetProto()); + prototype = JSHandle(thread, ihclass->GetProto(thread)); } else { prototype = JSHandle(prototypeOrHClassVal); } - JSHandle method(thread, Method::Cast(extractor->GetConstructorMethod().GetTaggedObject())); + JSHandle method(thread, Method::Cast(extractor->GetConstructorMethod(thread).GetTaggedObject())); JSHandle constructor = factory->NewJSFunctionByHClass(method, constructorHClass, MemSpaceType::NON_MOVABLE); @@ -521,7 +521,7 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const if (LIKELY(!prototype->GetJSHClass()->IsDictionaryMode())) { for (uint32_t index = 0; index < nonStaticLength; ++index) { - propValue.Update(nonStaticProperties->Get(index)); + propValue.Update(nonStaticProperties->Get(thread, index)); if (propValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(propValue); propValue.Update(CreateJSFunctionFromTemplate(thread, literalFunc, prototype, lexenv)); @@ -536,7 +536,7 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const // non-static elements if (UNLIKELY(extractor->GetNonStaticWithElements())) { - JSHandle nonStaticElements(thread, extractor->GetNonStaticElements()); + JSHandle nonStaticElements(thread, extractor->GetNonStaticElements(thread)); ClassHelper::HandleElementsProperties(thread, prototype, lexenv, nonStaticElements); } @@ -546,7 +546,7 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const int correntIndex = 0; if (LIKELY(!constructorHClass->IsDictionaryMode())) { for (uint32_t index = 0; index < staticLength; ++index) { - propValue.Update(staticProperties->Get(index)); + propValue.Update(staticProperties->Get(thread, index)); if (propValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(propValue); propValue.Update( @@ -554,7 +554,7 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const } bool needCorrentIndex = index >= ClassInfoExtractor::STATIC_RESERVED_LENGTH; if (needCorrentIndex) { - key.Update(staticKeys->Get(index)); + key.Update(staticKeys->Get(thread, index)); correntIndex = JSHClass::FindPropertyEntry(thread, *constructorHClass, key.GetTaggedValue()); } JSHandle::Cast(constructor)->SetPropertyInlinedProps(thread, @@ -568,7 +568,7 @@ JSHandle ClassHelper::DefineClassWithIHClass(JSThread *thread, const // static elements if (UNLIKELY(extractor->GetStaticWithElements())) { - JSHandle staticElements(thread, extractor->GetStaticElements()); + JSHandle staticElements(thread, extractor->GetStaticElements(thread)); ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), lexenv, staticElements); } @@ -621,10 +621,10 @@ JSHandle ClassHelper::BuildDictionaryProperties(JSThread *thread attributes = PropertyAttributes::Default(false, false, true); break; case ClassInfoExtractor::NAME_INDEX: - if (LIKELY(properties->Get(ClassInfoExtractor::NAME_INDEX).IsString())) { + if (LIKELY(properties->Get(thread, ClassInfoExtractor::NAME_INDEX).IsString())) { attributes = PropertyAttributes::Default(false, false, true); } else { - ASSERT(properties->Get(ClassInfoExtractor::NAME_INDEX).IsFunctionTemplate()); + ASSERT(properties->Get(thread, ClassInfoExtractor::NAME_INDEX).IsFunctionTemplate()); attributes = PropertyAttributes::Default(true, false, true); } break; @@ -638,8 +638,8 @@ JSHandle ClassHelper::BuildDictionaryProperties(JSThread *thread } else { attributes = PropertyAttributes::Default(true, false, true); // non-enumerable } - propKey.Update(keys->Get(index)); - propValue.Update(properties->Get(index)); + propKey.Update(keys->Get(thread, index)); + propValue.Update(properties->Get(thread, index)); if (propValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(propValue); propValue.Update(CreateJSFunctionFromTemplate(thread, literalFunc, object, lexenv)); @@ -720,8 +720,8 @@ void ClassHelper::HandleElementsProperties(JSThread *thread, const JSHandle elementsKey(thread, JSTaggedValue::Undefined()); JSMutableHandle elementsValue(thread, JSTaggedValue::Undefined()); for (uint32_t index = 0; index < elements->GetLength(); index += 2) { // 2: key-value pair - elementsKey.Update(elements->Get(index)); - elementsValue.Update(elements->Get(index + 1)); + elementsKey.Update(elements->Get(thread, index)); + elementsValue.Update(elements->Get(thread, index + 1)); if (elementsValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(elementsValue); elementsValue.Update(CreateJSFunctionFromTemplate(thread, literalFunc, object, lexenv)); @@ -736,12 +736,12 @@ JSHandle SendableClassDefiner::DefineSendableClassFromExtractor(JSTh JSHandle &extractor, const JSHandle &staticFieldArray) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle staticKeys(thread, extractor->GetStaticKeys()); - JSHandle staticProperties(thread, extractor->GetStaticProperties()); + JSHandle staticKeys(thread, extractor->GetStaticKeys(thread)); + JSHandle staticProperties(thread, extractor->GetStaticProperties(thread)); SendableClassDefiner::FilterDuplicatedKeys(thread, staticKeys, staticProperties); - JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys()); - JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties()); + JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys(thread)); + JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties(thread)); SendableClassDefiner::FilterDuplicatedKeys(thread, nonStaticKeys, nonStaticProperties); JSHandle prototypeHClass = ClassInfoExtractor::CreateSendableHClass(thread, nonStaticKeys, nonStaticProperties, true); @@ -750,7 +750,7 @@ JSHandle SendableClassDefiner::DefineSendableClassFromExtractor(JSTh uint32_t staticFields = length / 2; // 2: key-type JSHandle constructorHClass = ClassInfoExtractor::CreateSendableHClass(thread, staticKeys, staticProperties, false, staticFields); - JSHandle method(thread, Method::Cast(extractor->GetConstructorMethod().GetTaggedObject())); + JSHandle method(thread, Method::Cast(extractor->GetConstructorMethod(thread).GetTaggedObject())); /* * Method::SetFunctionKind can't be called here, because method will set kind when set inheritance relationship, * so there is a multi-threading problem with multi-threads define sendable DERIVED class at the same time. @@ -765,7 +765,7 @@ JSHandle SendableClassDefiner::DefineSendableClassFromExtractor(JSTh JSHandle elementsDic = NumberDictionary::CreateInSharedHeap(thread); bool hasElement = false; if (!constructorHClass->IsDictionaryMode() && staticFields > 0) { - auto layout = JSHandle(thread, constructorHClass->GetLayout()); + auto layout = JSHandle(thread, constructorHClass->GetLayout(thread)); AddFieldTypeToHClass( thread, staticFieldArray, length, layout, constructorHClass, elementsDic, hasElement, ~0U); } @@ -780,7 +780,7 @@ JSHandle SendableClassDefiner::DefineSendableClassFromExtractor(JSTh if (LIKELY(!prototypeHClass->IsDictionaryMode())) { for (uint32_t index = 0; index < nonStaticLength; ++index) { - propValue.Update(nonStaticProperties->Get(index)); + propValue.Update(nonStaticProperties->Get(thread, index)); // constructor don't need to clone if (propValue->IsFunctionTemplate() && index != ClassInfoExtractor::CONSTRUCTOR_INDEX) { auto literalFunc = JSHandle::Cast(propValue); @@ -807,7 +807,7 @@ JSHandle SendableClassDefiner::DefineSendableClassFromExtractor(JSTh uint32_t staticLength = staticProperties->GetLength(); if (LIKELY(!constructorHClass->IsDictionaryMode())) { for (uint32_t index = 0; index < staticLength; ++index) { - propValue.Update(staticProperties->Get(index)); + propValue.Update(staticProperties->Get(thread, index)); if (propValue->IsFunctionTemplate()) { auto literalFunc = JSHandle::Cast(propValue); propValue.Update(CreateSFunctionFromTemplate( @@ -862,9 +862,9 @@ void SendableClassDefiner::FilterDuplicatedKeys(JSThread *thread, const JSHandle JSMutableHandle existValue(thread, JSTaggedValue::Undefined()); JSMutableHandle index(thread, JSTaggedValue::Undefined()); for (; right < length; right++) { - key.Update(keys->Get(right)); - value.Update(properties->Get(right)); - int entry = dict->FindEntry(key.GetTaggedValue()); + key.Update(keys->Get(thread, right)); + value.Update(properties->Get(thread, right)); + int entry = dict->FindEntry(thread, key.GetTaggedValue()); if (entry == -1) { TryUpdateValue(thread, value); index.Update(JSTaggedValue(left)); @@ -878,8 +878,8 @@ void SendableClassDefiner::FilterDuplicatedKeys(JSThread *thread, const JSHandle left++; continue; } - auto existIndex = static_cast(dict->GetValue(entry).GetNumber()); - existValue.Update(properties->Get(existIndex)); + auto existIndex = static_cast(dict->GetValue(thread, entry).GetNumber()); + existValue.Update(properties->Get(thread, existIndex)); bool needUpdateValue = TryUpdateExistValue(thread, existValue, value); if (needUpdateValue) { properties->Set(thread, existIndex, value); @@ -904,11 +904,11 @@ JSHandle SendableClassDefiner::BuildSendableDictionaryProperties JSMutableHandle propValue(thread, JSTaggedValue::Undefined()); for (uint32_t index = 0; index < length; index++) { PropertyAttributes attributes = PropertyAttributes::Default(false, false, false); - if (UNLIKELY(properties->Get(index).IsAccessor())) { + if (UNLIKELY(properties->Get(thread, index).IsAccessor())) { attributes.SetIsAccessor(true); } - propKey.Update(keys->Get(index)); - propValue.Update(properties->Get(index)); + propKey.Update(keys->Get(thread, index)); + propValue.Update(properties->Get(thread, index)); // constructor don't need to clone if (index == ClassInfoExtractor::CONSTRUCTOR_INDEX && type == ClassPropertyType::NON_STATIC) { JSHandle newDict = @@ -958,12 +958,12 @@ void SendableClassDefiner::AddFieldTypeToDict(JSThread *thread, const JSHandle eleIndexKey(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i += 2) { // 2: key-value pair; - key.Update(fieldTypeArray->Get(i)); + key.Update(fieldTypeArray->Get(thread, i)); ASSERT(key->IsString()); - SharedFieldType type = FromFieldType(FieldType(fieldTypeArray->Get(i + 1).GetInt())); + SharedFieldType type = FromFieldType(FieldType(fieldTypeArray->Get(thread, i + 1).GetInt())); attributes.SetSharedFieldType(type); attributes.SetBoxType(PropertyBoxType::UNDEFINED); - int64_t eleIndex = ObjectFastOperator::TryToElementsIndex(key.GetTaggedValue()); + int64_t eleIndex = ObjectFastOperator::TryToElementsIndex(thread, key.GetTaggedValue()); if (eleIndex >= 0) { eleIndexKey.Update(JSTaggedValue(eleIndex)); JSHandle newElementsDic = NumberDictionary::Put( @@ -995,12 +995,12 @@ void SendableClassDefiner::AddFieldTypeToHClass(JSThread *thread, const JSHandle JSMutableHandle eleIndexKey(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i += 2) { // 2: key-value pair; PropertyAttributes attributes = PropertyAttributes::Default(true, true, false); - key.Update(fieldTypeArray->Get(i)); + key.Update(fieldTypeArray->Get(thread, i)); ASSERT(key->IsString()); - SharedFieldType type = FromFieldType(FieldType(fieldTypeArray->Get(i + 1).GetInt())); + SharedFieldType type = FromFieldType(FieldType(fieldTypeArray->Get(thread, i + 1).GetInt())); int entry = layout->FindElementWithCache(thread, *hclass, key.GetTaggedValue(), index); if (entry != -1) { - attributes = layout->GetAttr(entry); + attributes = layout->GetAttr(thread, entry); attributes.SetSharedFieldType(type); layout->SetNormalAttr(thread, entry, attributes); if (start != ~0U && propertyList.size() > 0) { @@ -1008,7 +1008,7 @@ void SendableClassDefiner::AddFieldTypeToHClass(JSThread *thread, const JSHandle propertyList[start + (static_cast(entry) << 1) + 1] = propertyList[start + i + 1]; } } else { - int64_t eleIndex = ObjectFastOperator::TryToElementsIndex(key.GetTaggedValue()); + int64_t eleIndex = ObjectFastOperator::TryToElementsIndex(thread, key.GetTaggedValue()); if (eleIndex < 0 && start != ~0U && propertyList.size() > 0) { propertyList[start + (index << 1)] = propertyList[start + i]; propertyList[start + (index << 1) + 1] = propertyList[start + i + 1]; @@ -1060,7 +1060,7 @@ void SendableClassDefiner::DefineSendableInstanceHClass(JSThread *thread, const uint32_t length, const JSHandle &ctor, const JSHandle &base) { ASSERT(ctor->GetClass()->IsJSSharedFunction()); - JSHandle clsPrototype(thread, JSHandle(ctor)->GetFunctionPrototype()); + JSHandle clsPrototype(thread, JSHandle(ctor)->GetFunctionPrototype(thread)); ASSERT(clsPrototype->GetClass()->IsJSSharedObject()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); ASSERT(length <= fieldTypeArray->GetLength()); @@ -1084,13 +1084,13 @@ void SendableClassDefiner::DefineSendableInstanceHClass(JSThread *thread, const } else { ASSERT(base->IsJSSharedFunction()); JSHandle baseCtor = JSHandle::Cast(base); - JSHandle baseIHClass(thread, baseCtor->GetProtoOrHClass()); + JSHandle baseIHClass(thread, baseCtor->GetProtoOrHClass(thread)); ASSERT(baseIHClass->IsJSShared()); JSType baseType = baseIHClass->GetObjectType(); const auto [baseSize, baseMaxInlineSize] = GetSizeAndMaxInlineByType(baseType); if (LIKELY(!baseIHClass->IsDictionaryMode())) { auto baseLength = baseIHClass->NumberOfProps(); - JSHandle baseLayout(thread, baseIHClass->GetLayout()); + JSHandle baseLayout(thread, baseIHClass->GetLayout(thread)); auto newLength = baseLength + fieldNum; if (newLength == 0) { iHClass = factory->NewSEcmaHClass(baseSize, baseType, 0); @@ -1106,8 +1106,8 @@ void SendableClassDefiner::DefineSendableInstanceHClass(JSThread *thread, const JSHandle value = globalConst->GetHandledUndefined(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < baseLength; i++) { - key.Update(baseLayout->GetKey(i)); - PropertyAttributes attr = baseLayout->GetAttr(i); + key.Update(baseLayout->GetKey(thread, i)); + PropertyAttributes attr = baseLayout->GetAttr(thread, i); attr.SetIsInlinedProps(false); attr.SetBoxType(PropertyBoxType::UNDEFINED); dict = NameDictionary::Put(thread, dict, key, value, attr); @@ -1115,7 +1115,7 @@ void SendableClassDefiner::DefineSendableInstanceHClass(JSThread *thread, const AddFieldTypeToHClass(thread, fieldTypeArray, length, dict, iHClass, elementsDic, hasElement); } } else { - JSHandle baseDict(thread, baseIHClass->GetLayout()); + JSHandle baseDict(thread, baseIHClass->GetLayout(thread)); auto baseLength = baseDict->EntriesCount(); auto newLength = fieldNum + static_cast(baseLength); JSHandle dict = @@ -1142,7 +1142,7 @@ JSHandle SendableClassDefiner::ExtractStaticFieldTypeArray(JSThread ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t arrayLength = fieldTypeArray->GetLength(); ASSERT(arrayLength > 0); - auto instanceFieldNums = static_cast(fieldTypeArray->Get(arrayLength - 1).GetInt()); + auto instanceFieldNums = static_cast(fieldTypeArray->Get(thread, arrayLength - 1).GetInt()); uint32_t staticFieldBegin = instanceFieldNums * 2; // 2: key-type if (staticFieldBegin >= arrayLength) { LOG_ECMA(ERROR) << "ExtractStaticFieldTypeArray Failed, staticFieldBegin:" << staticFieldBegin @@ -1152,8 +1152,8 @@ JSHandle SendableClassDefiner::ExtractStaticFieldTypeArray(JSThread uint32_t staticFieldLength = arrayLength - staticFieldBegin - 1; JSHandle staticFieldArray = factory->NewTaggedArray(staticFieldLength); for (uint32_t i = 0; i < staticFieldLength; i += 2) { // 2: key-type - staticFieldArray->Set(thread, i, fieldTypeArray->Get(staticFieldBegin + i)); - staticFieldArray->Set(thread, i + 1, fieldTypeArray->Get(staticFieldBegin + i + 1)); + staticFieldArray->Set(thread, i, fieldTypeArray->Get(thread, staticFieldBegin + i)); + staticFieldArray->Set(thread, i + 1, fieldTypeArray->Get(thread, staticFieldBegin + i + 1)); } return staticFieldArray; } @@ -1163,14 +1163,14 @@ void SendableClassDefiner::UpdateAccessorFunction(JSThread *thread, const JSMuta { ASSERT(value->IsAccessorData()); JSHandle accessor(value); - auto getter = accessor->GetGetter(); + auto getter = accessor->GetGetter(thread); if (getter.IsFunctionTemplate()) { auto funcTemp = JSHandle(thread, getter); auto propFunc = CreateSFunctionFromTemplate( thread, funcTemp, JSHandle(homeObject), ctor); accessor->SetGetter(thread, propFunc); } - auto setter = accessor->GetSetter(); + auto setter = accessor->GetSetter(thread); if (setter.IsFunctionTemplate()) { auto funcTemp = JSHandle(thread, setter); auto propFunc = CreateSFunctionFromTemplate( @@ -1184,13 +1184,13 @@ bool SendableClassDefiner::TryUpdateExistValue(JSThread *thread, JSMutableHandle { bool needUpdateValue = true; if (existValue->IsAccessorData()) { - if (value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter()) { + if (value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter(thread)) { JSHandle accessor(existValue); UpdateValueToAccessor(thread, value, accessor); needUpdateValue = false; } } else { - if (value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter()) { + if (value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter(thread)) { JSHandle accessor = thread->GetEcmaVM()->GetFactory()->NewSAccessorData(); UpdateValueToAccessor(thread, value, accessor); } @@ -1200,7 +1200,7 @@ bool SendableClassDefiner::TryUpdateExistValue(JSThread *thread, JSMutableHandle void SendableClassDefiner::TryUpdateValue(JSThread *thread, JSMutableHandle &value) { - if (value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter()) { + if (value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter(thread)) { JSHandle accessor = thread->GetEcmaVM()->GetFactory()->NewSAccessorData(); UpdateValueToAccessor(thread, value, accessor); } @@ -1209,8 +1209,8 @@ void SendableClassDefiner::TryUpdateValue(JSThread *thread, JSMutableHandle &value, JSHandle &accessor) { - ASSERT(value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter()); - if (JSHandle(value)->IsGetter()) { + ASSERT(value->IsFunctionTemplate() && JSHandle(value)->IsGetterOrSetter(thread)); + if (JSHandle(value)->IsGetter(thread)) { accessor->SetGetter(thread, value); } else { accessor->SetSetter(thread, value); diff --git a/ecmascript/jspandafile/literal_data_extractor.cpp b/ecmascript/jspandafile/literal_data_extractor.cpp index 0bc9086683..251d3b72b1 100644 --- a/ecmascript/jspandafile/literal_data_extractor.cpp +++ b/ecmascript/jspandafile/literal_data_extractor.cpp @@ -64,7 +64,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE); jt = JSTaggedValue(str); uint32_t elementIndex = 0; - if (JSTaggedValue::ToElementIndex(jt, &elementIndex) && ppos % pairSize == 0) { + if (JSTaggedValue::ToElementIndex(thread, jt, &elementIndex) && ppos % pairSize == 0) { flag = true; } break; @@ -441,7 +441,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE); jt = JSTaggedValue(str); uint32_t elementIndex = 0; - if (JSTaggedValue::ToElementIndex(jt, &elementIndex) && ppos % pairSize == 0) { + if (JSTaggedValue::ToElementIndex(thread, jt, &elementIndex) && ppos % pairSize == 0) { flag = true; } break; @@ -478,7 +478,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil int entryIndex = 0; bool needSetAotFlag = (isLoadedAOT && (epos % pairSize == 0) && !flag); if (needSetAotFlag) { - entryIndex = entryIndexes->GetObjectFromCache(pos++).GetInt(); + entryIndex = entryIndexes->GetObjectFromCache(thread, pos++).GetInt(); // -1 : this jsfunction is a large function if (entryIndex == -1) { needSetAotFlag = false; @@ -611,7 +611,7 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, int entryIndex = 0; bool needSetAotFlag = isLoadedAOT; if (isLoadedAOT) { - entryIndex = entryIndexes->GetObjectFromCache(index++).GetInt(); + entryIndex = entryIndexes->GetObjectFromCache(thread, index++).GetInt(); if (entryIndex == -1) { needSetAotFlag = false; } diff --git a/ecmascript/jspandafile/panda_file_translator.cpp b/ecmascript/jspandafile/panda_file_translator.cpp index f068583228..b76422ea41 100644 --- a/ecmascript/jspandafile/panda_file_translator.cpp +++ b/ecmascript/jspandafile/panda_file_translator.cpp @@ -231,11 +231,11 @@ std::pair, JSHandle> PandaFileTranslator::P JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); size_t elementsLen = elements->GetLength(); for (size_t i = 0; i < elementsLen; i += 2) { // 2: Each literal buffer contains a pair of key-value. - key.Update(elements->Get(i)); + key.Update(elements->Get(thread, i)); if (key->IsHole()) { break; } - valueHandle.Update(elements->Get(i + 1)); + valueHandle.Update(elements->Get(thread, i + 1)); JSObject::DefinePropertyByLiteral(thread, obj, key, valueHandle); } constpool->SetObjectToCache(thread, value.GetConstpoolIndex(), obj.GetTaggedValue()); @@ -303,11 +303,11 @@ void PandaFileTranslator::ParseFuncAndLiteralConstPool(EcmaVM *vm, const JSPanda JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); size_t elementsLen = elements->GetLength(); for (size_t i = 0; i < elementsLen; i += 2) { // 2: Each literal buffer contains a pair of key-value. - key.Update(elements->Get(i)); + key.Update(elements->Get(thread, i)); if (key->IsHole()) { break; } - valueHandle.Update(elements->Get(i + 1)); + valueHandle.Update(elements->Get(thread, i + 1)); JSObject::DefinePropertyByLiteral(thread, obj, key, valueHandle); } constpool->SetObjectToCache(thread, value.GetConstpoolIndex(), obj.GetTaggedValue()); diff --git a/ecmascript/jspandafile/program_object.cpp b/ecmascript/jspandafile/program_object.cpp index 17e58803b0..aea07aeb72 100644 --- a/ecmascript/jspandafile/program_object.cpp +++ b/ecmascript/jspandafile/program_object.cpp @@ -23,7 +23,7 @@ JSTaggedValue ConstantPool::GetClassLiteralFromCache(JSThread *thread, JSHandle< [[maybe_unused]] EcmaHandleScope handleScope(thread); // Do not use cache when sendable for get wrong obj from cache, // shall be fix or refactor during shared object implements - JSTaggedValue val = constpool->GetObjectFromCache(literal); + JSTaggedValue val = constpool->GetObjectFromCache(thread, literal); JSPandaFile *jsPandaFile = constpool->GetJSPandaFile(); // For AOT @@ -76,7 +76,7 @@ JSTaggedValue ConstantPool::GetStringFromCacheForJit(JSThread *thread, JSTaggedV bool allowAlloc) { const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); - auto val = taggedPool->Get(index); + auto val = taggedPool->Get(thread, index); if (!allowAlloc && val.IsHole()) { return JSTaggedValue::Undefined(); } @@ -96,12 +96,12 @@ JSTaggedValue ConstantPool::GetStringFromCacheForJit(JSThread *thread, JSTaggedV JSTaggedValue ConstantPool::GetStringFromCache(JSThread *thread, JSTaggedValue constpool, uint32_t index) { const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); - auto val = taggedPool->Get(index); + auto val = taggedPool->Get(thread, index); if (val.IsHole()) { if (!taggedPool->GetJSPandaFile()->IsNewVersion()) { JSTaggedValue unsharedCp = thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpool); taggedPool = ConstantPool::Cast(unsharedCp.GetTaggedObject()); - return taggedPool->Get(index); + return taggedPool->Get(thread, index); } [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -135,8 +135,9 @@ void ConstantPool::MergeObjectLiteralHClassCache(EcmaVM *vm, const JSHandleIsHole()) { return; } + JSThread *thread = vm->GetJSThread(); JSHandle pool(constpool); - auto aotHCInfo = pool->GetAotHClassInfo(); + auto aotHCInfo = pool->GetAotHClassInfo(thread); if (!aotHCInfo.IsTaggedArray()) { return; } @@ -144,7 +145,7 @@ void ConstantPool::MergeObjectLiteralHClassCache(EcmaVM *vm, const JSHandleGetLength() <= 0) { return; } - auto last = aotHCInfoArray->Get(aotHCInfoArray->GetLength() - 1); + auto last = aotHCInfoArray->Get(thread, aotHCInfoArray->GetLength() - 1); if (!last.IsTaggedArray()) { return; } @@ -152,10 +153,9 @@ void ConstantPool::MergeObjectLiteralHClassCache(EcmaVM *vm, const JSHandleGetGlobalEnv()->GetObjectLiteralHClassCache(); auto length = snapshotCachedArray->GetLength(); auto prototype = vm->GetGlobalEnv()->GetObjectFunctionPrototype(); - JSThread *thread = vm->GetJSThread(); if (curCached->IsHole()) { for (uint32_t i = 0; i < length; i++) { - auto newValue = snapshotCachedArray->Get(i); + auto newValue = snapshotCachedArray->Get(thread, i); if (newValue.IsJSHClass()) { JSHClass::Cast(newValue.GetTaggedObject())->SetPrototype(thread, prototype); } @@ -165,11 +165,11 @@ void ConstantPool::MergeObjectLiteralHClassCache(EcmaVM *vm, const JSHandleGet(i); + auto newValue = snapshotCachedArray->Get(thread, i); if (newValue.IsHole()) { continue; } - auto curValue = curCachedArray->Get(i); + auto curValue = curCachedArray->Get(thread, i); // If already merged, stop to merge. if (curValue.IsJSHClass() && JSHClass::Cast(curValue.GetTaggedObject())->IsAOT()) { break; @@ -179,10 +179,10 @@ void ConstantPool::MergeObjectLiteralHClassCache(EcmaVM *vm, const JSHandleGetObjectFromCache(index); + auto val = taggedPool->GetObjectFromCache(thread, index); JSPandaFile *jsPandaFile = taggedPool->GetJSPandaFile(); if (IsLoadingAOTMethodInfo(jsPandaFile, val)) { @@ -201,7 +201,7 @@ bool ConstantPool::IsAotMethodLiteralInfo(JSTaggedValue literalInfo) JSTaggedValue ConstantPool::GetIhcFromAOTLiteralInfo(JSTaggedValue constpool, uint32_t index) { ASSERT(constpool.IsConstantPool()); - auto val = ConstantPool::Cast(constpool.GetTaggedObject())->Get(index); + auto val = ConstantPool::Cast(constpool.GetTaggedObject())->GetPrimitive(index); if (val.IsHeapObject() && val.IsAOTLiteralInfo()) { return AOTLiteralInfo::Cast(val.GetTaggedObject())->GetIhc(); } @@ -210,9 +210,10 @@ JSTaggedValue ConstantPool::GetIhcFromAOTLiteralInfo(JSTaggedValue constpool, ui void ConstantPool::UpdateConstpoolWhenDeserialAI(EcmaVM *vm, JSHandle aiCP, JSHandle sharedCP, JSHandle unsharedCP) { + JSThread *thread = vm->GetJSThread(); uint32_t constpoolLen = aiCP->GetCacheLength(); auto aiCPLength = aiCP->GetLength(); - JSMutableHandle valHandle(vm->GetJSThread(), JSTaggedValue::Undefined()); + JSMutableHandle valHandle(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < constpoolLen; i++) { // We need preserve unshared constantPool index and shared constantPool id instead of fetching from ai. // Because framework abc's ai does not contain those infos. @@ -220,8 +221,7 @@ void ConstantPool::UpdateConstpoolWhenDeserialAI(EcmaVM *vm, JSHandleGetJSThread(); - JSTaggedValue val = aiCP->GetObjectFromCache(i); + JSTaggedValue val = aiCP->GetObjectFromCache(thread, i); valHandle.Update(val); if (IsAotMethodLiteralInfo(valHandle.GetTaggedValue())) { JSHandle value(thread, val); diff --git a/ecmascript/jspandafile/program_object.h b/ecmascript/jspandafile/program_object.h index 71795d4e43..ba73aab46c 100644 --- a/ecmascript/jspandafile/program_object.h +++ b/ecmascript/jspandafile/program_object.h @@ -210,7 +210,7 @@ public: } JSThread *thread = vm->GetJSThread(); for (uint32_t i = 0; i < capacity; i++) { - JSTaggedValue val = constpool->GetObjectFromCache(i); + JSTaggedValue val = constpool->GetObjectFromCache(thread, i); if (val.IsString()) { sconstpool->SetObjectToCache(thread, i, val); } else if (IsAotMethodLiteralInfo(val)) { @@ -239,12 +239,13 @@ public: static JSHandle CopySharedMethodAOTLiteralInfo(EcmaVM *vm, JSHandle src) { + JSThread *thread = vm->GetJSThread(); ObjectFactory *factory = vm->GetFactory(); JSHandle dst = factory->NewSAOTLiteralInfo(1); for (uint32_t i = 0; i < src->GetCacheLength(); i++) { - JSTaggedValue val = src->GetObjectFromCache(i); + JSTaggedValue val = src->GetObjectFromCache(thread, i); ASSERT(!val.IsHeapObject() || val.IsJSShared()); - dst->SetObjectToCache(vm->GetJSThread(), i, val); + dst->SetObjectToCache(thread, i, val); } dst->SetLiteralType(JSTaggedValue(src->GetLiteralType())); return dst; @@ -266,7 +267,7 @@ public: inline int32_t GetUnsharedConstpoolIndex() const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetUnsharedConstpoolIndexOffset())).GetInt(); + return Barriers::GetPrimitive(GetData(), GetUnsharedConstpoolIndexOffset()).GetInt(); } inline void SetSharedConstpoolId(const JSTaggedValue index) @@ -276,7 +277,7 @@ public: inline JSTaggedValue GetSharedConstpoolId() const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetSharedConstpoolIdOffset())); + return JSTaggedValue(Barriers::GetPrimitive(GetData(), GetSharedConstpoolIdOffset())); } panda_file::File::EntityId GetEntityId(uint32_t index) const @@ -308,7 +309,7 @@ public: inline panda_file::File::IndexHeader *GetIndexHeader() const { - return Barriers::GetValue(GetData(), GetIndexHeaderOffset()); + return Barriers::GetPrimitive(GetData(), GetIndexHeaderOffset()); } static size_t ComputeSize(uint32_t cacheSize) @@ -356,16 +357,16 @@ public: inline JSPandaFile *GetJSPandaFile() const { - return Barriers::GetValue(GetData(), GetJSPandaFileOffset()); + return Barriers::GetPrimitive(GetData(), GetJSPandaFileOffset()); } inline void InitConstantPoolTail(const JSThread *thread, JSHandle constPool) { - SetAotArrayInfo(thread, constPool->GetAotArrayInfo()); - SetAotHClassInfo(thread, constPool->GetAotHClassInfo()); - SetConstantIndexInfo(thread, constPool->GetConstantIndexInfo()); - SetAotSymbolInfo(thread, constPool->GetAotSymbolInfo()); - SetProtoTransTableInfo(thread, constPool->GetProtoTransTableInfo()); + SetAotArrayInfo(thread, constPool->GetAotArrayInfo(thread)); + SetAotHClassInfo(thread, constPool->GetAotHClassInfo(thread)); + SetConstantIndexInfo(thread, constPool->GetConstantIndexInfo(thread)); + SetAotSymbolInfo(thread, constPool->GetAotSymbolInfo(thread)); + SetProtoTransTableInfo(thread, constPool->GetProtoTransTableInfo(thread)); } inline void SetConstantIndexInfo(const JSThread *thread, JSTaggedValue info) @@ -373,9 +374,9 @@ public: Set(thread, (GetLength() - CONSTANT_INDEX_INFO_INDEX), info); } - inline JSTaggedValue GetConstantIndexInfo() const + inline JSTaggedValue GetConstantIndexInfo(const JSThread *thread) const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetConstantIndexInfoOffset())); + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), GetConstantIndexInfoOffset())); } inline void SetAotArrayInfo(const JSThread *thread, JSTaggedValue info) @@ -383,43 +384,43 @@ public: Set(thread, (GetLength() - AOT_ARRAY_INFO_INDEX), info); } - inline JSTaggedValue GetAotArrayInfo() const + inline JSTaggedValue GetAotArrayInfo(const JSThread *thread) const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetAotArrayInfoOffset())); + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), GetAotArrayInfoOffset())); } - inline JSTaggedValue GetAotSymbolInfo() const + inline JSTaggedValue GetAotSymbolInfo(const JSThread *thread) const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetAotSymbolInfoOffset())); + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), GetAotSymbolInfoOffset())); } - inline JSTaggedValue GetProtoTransTableInfo() const + inline JSTaggedValue GetProtoTransTableInfo(const JSThread *thread) const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetProtoTransTableInfoOffset())); + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), GetProtoTransTableInfoOffset())); } - static JSTaggedValue GetSymbolFromSymbolInfo(JSHandle symbolInfoHandler, uint64_t id) + static JSTaggedValue GetSymbolFromSymbolInfo(const JSThread *thread, JSHandle symbolInfoHandler, uint64_t id) { uint32_t len = symbolInfoHandler->GetLength(); for (uint32_t j = 0; j < len; j += 2) { // 2: symbolId, symbol ASSERT(j + 1 < len); - uint64_t symbolId = symbolInfoHandler->Get(j).GetRawData(); + uint64_t symbolId = symbolInfoHandler->Get(thread, j).GetRawData(); if (symbolId == id) { - return symbolInfoHandler->Get(j + 1); + return symbolInfoHandler->Get(thread, j + 1); } } return JSTaggedValue::Hole(); } - static JSTaggedValue GetSymbolFromSymbolInfo(JSTaggedValue symbolInfo, uint64_t id) + static JSTaggedValue GetSymbolFromSymbolInfo(const JSThread *thread, JSTaggedValue symbolInfo, uint64_t id) { TaggedArray* info = TaggedArray::Cast(symbolInfo.GetTaggedObject()); uint32_t len = info->GetLength(); for (uint32_t j = 0; j < len; j += 2) { // 2: symbolId, symbol ASSERT(j + 1 < len); - uint64_t symbolId = info->Get(j).GetRawData(); + uint64_t symbolId = info->Get(thread, j).GetRawData(); if (symbolId == id) { - return info->Get(j + 1); + return info->Get(thread, j + 1); } } return JSTaggedValue::Hole(); @@ -430,9 +431,9 @@ public: Set(thread, (GetLength() - AOT_HCLASS_INFO_INDEX), info); } - inline JSTaggedValue GetAotHClassInfo() const + inline JSTaggedValue GetAotHClassInfo(const JSThread *thread) const { - return JSTaggedValue(Barriers::GetTaggedValue(GetData(), GetAotHClassInfoOffset())); + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), GetAotHClassInfoOffset())); } inline void SetAotSymbolInfo(const JSThread *thread, JSTaggedValue info) @@ -457,7 +458,7 @@ public: JSHandle constpoolHandle(thread, constpool); std::atomic *atomicVal = reinterpret_cast *>( reinterpret_cast(taggedPool) + DATA_OFFSET + index * JSTaggedValue::TaggedTypeSize()); - JSTaggedValue tempVal = taggedPool->GetObjectFromCache(index); + JSTaggedValue tempVal = taggedPool->GetObjectFromCache(thread, index); JSTaggedValue expected = IsLoadingAOTMethodInfo(taggedPool->GetJSPandaFile(), tempVal) ? tempVal : JSTaggedValue::Hole(); JSTaggedValue desired = value; @@ -468,15 +469,15 @@ public: } } - inline JSTaggedValue GetObjectFromCache(uint32_t index) const + inline JSTaggedValue GetObjectFromCache(const JSThread *thread, uint32_t index) const { - return Get(index); + return Get(thread, index); } - static JSTaggedValue GetMethodFromCache(JSThread *thread, JSTaggedValue constpool, uint32_t index) + static JSTaggedValue PUBLIC_API GetMethodFromCache(JSThread *thread, JSTaggedValue constpool, uint32_t index) { const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); - auto val = taggedPool->GetObjectFromCache(index); + auto val = taggedPool->GetObjectFromCache(thread, index); JSPandaFile *jsPandaFile = taggedPool->GetJSPandaFile(); // For AOT @@ -490,7 +491,7 @@ public: entryIndexVal = val.GetInt(); } else { JSHandle entryIndexes(thread, val); - entryIndexVal = entryIndexes->GetObjectFromCache(0).GetInt(); // 0: only one method + entryIndexVal = entryIndexes->GetObjectFromCache(thread, 0).GetInt(); // 0: only one method } if (entryIndexVal != static_cast(AOTLiteralInfo::NO_FUNC_ENTRY_VALUE)) { hasEntryIndex = true; @@ -506,7 +507,7 @@ public: if (!taggedPool->GetJSPandaFile()->IsNewVersion()) { JSTaggedValue unsharedCp = thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpool); taggedPool = ConstantPool::Cast(unsharedCp.GetTaggedObject()); - return taggedPool->Get(index); + return taggedPool->Get(thread, index); } [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -526,7 +527,7 @@ public: return method.GetTaggedValue(); } - static JSTaggedValue PUBLIC_API GetMethodFromCache(JSTaggedValue constpool, uint32_t index); + static JSTaggedValue PUBLIC_API GetMethodFromCache(JSTaggedValue constpool, uint32_t index, JSThread *thread); static void PUBLIC_API UpdateConstpoolWhenDeserialAI(EcmaVM *vm, JSHandle aiCP, JSHandle sharedCP, JSHandle unsharedCP); @@ -547,7 +548,7 @@ public: static_assert(type == ConstPoolType::OBJECT_LITERAL || type == ConstPoolType::ARRAY_LITERAL); [[maybe_unused]] EcmaHandleScope handleScope(thread); const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); - auto val = taggedPool->GetObjectFromCache(index); + auto val = taggedPool->GetObjectFromCache(thread, index); JSPandaFile *jsPandaFile = taggedPool->GetJSPandaFile(); // For AOT @@ -588,11 +589,11 @@ public: JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); size_t elementsLen = elements->GetLength(); for (size_t i = 0; i < elementsLen; i += 2) { // 2: Each literal buffer has a pair of key-value. - key.Update(elements->Get(i)); + key.Update(elements->Get(thread, i)); if (key->IsHole()) { break; } - valueHandle.Update(elements->Get(i + 1)); + valueHandle.Update(elements->Get(thread, i + 1)); JSObject::DefinePropertyByLiteral(thread, obj, key, valueHandle); } val = obj.GetTaggedValue(); @@ -642,11 +643,19 @@ public: return val; } + static panda_file::File::EntityId GetIdFromCache(JSTaggedValue constpool, uint32_t index) + { + const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); + panda_file::File::EntityId id = taggedPool->GetEntityId(index); + return id; + } + template - static JSTaggedValue GetLiteralFromCache(JSTaggedValue constpool, uint32_t index, [[maybe_unused]] CString entry) + static JSTaggedValue GetLiteralFromCacheNoScope(JSThread *thread, JSTaggedValue constpool, + uint32_t index, [[maybe_unused]] CString entry) { const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); - auto val = taggedPool->GetObjectFromCache(index); + auto val = taggedPool->GetObjectFromCache(thread, index); JSPandaFile *jsPandaFile = taggedPool->GetJSPandaFile(); bool isLoadedAOT = jsPandaFile->IsLoadedAOT(); @@ -656,18 +665,11 @@ public: return val.IsHole() ? JSTaggedValue::Undefined() : val; } - static panda_file::File::EntityId GetIdFromCache(JSTaggedValue constpool, uint32_t index) - { - const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject()); - panda_file::File::EntityId id = taggedPool->GetEntityId(index); - return id; - } - template static JSTaggedValue GetLiteralFromCache(JSThread *thread, JSTaggedValue constpool, uint32_t index, JSTaggedValue module) { - CString entry = ModuleManager::GetRecordName(module); + CString entry = ModuleManager::GetRecordName(thread, module); return GetLiteralFromCache(thread, constpool, index, entry); } diff --git a/ecmascript/jspandafile/scope_info_extractor.cpp b/ecmascript/jspandafile/scope_info_extractor.cpp index b00712fa68..92ab8d7e3b 100644 --- a/ecmascript/jspandafile/scope_info_extractor.cpp +++ b/ecmascript/jspandafile/scope_info_extractor.cpp @@ -27,9 +27,9 @@ JSTaggedValue ScopeInfoExtractor::GenerateScopeInfo(JSThread *thread, uint16_t s [[maybe_unused]] EcmaHandleScope handleScope(thread); Method *method = FrameHandler(thread).GetMethod(); - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); ASSERT(jsPandaFile != nullptr); - JSHandle constpool(thread, method->GetConstantPool()); + JSHandle constpool(thread, method->GetConstantPool(thread)); JSHandle elementsLiteral; if (jsPandaFile->IsNewVersion()) { @@ -48,10 +48,10 @@ JSTaggedValue ScopeInfoExtractor::GenerateScopeInfo(JSThread *thread, uint16_t s size_t length = elementsLiteral->GetLength(); for (size_t i = 1; i < length; i += 2) { // 2: Each literal buffer contains a pair of key-value. - JSTaggedValue val = elementsLiteral->Get(i); + JSTaggedValue val = elementsLiteral->Get(thread, i); ASSERT(val.IsString()); - CString name = ConvertToString(EcmaString::Cast(val.GetTaggedObject())); - int32_t slot = elementsLiteral->Get(i + 1).GetInt(); + CString name = ConvertToString(thread, EcmaString::Cast(val.GetTaggedObject())); + int32_t slot = elementsLiteral->Get(thread, i + 1).GetInt(); scopeDebugInfo->scopeInfo.emplace(name, slot); } diff --git a/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp b/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp index ca5fed991a..592f6f64b8 100644 --- a/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp +++ b/ecmascript/jspandafile/tests/js_pandafile_manager_test.cpp @@ -288,9 +288,9 @@ HWTEST_F_L0(JSPandaFileManagerTest, GenerateProgram) pfManager->AddJSPandaFile(pf); JSHandle program = pfManager->GenerateProgram(vm, pf.get(), JSPandaFile::ENTRY_FUNCTION_NAME); - JSHandle mainFunc(thread, program->GetMainFunction()); + JSHandle mainFunc(thread, program->GetMainFunction(thread)); JSHandle funcName = JSFunction::GetFunctionName(thread, JSHandle(mainFunc)); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(funcName)).ToCString().c_str(), "foo"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(funcName)).ToCString(thread).c_str(), "foo"); pfManager->RemoveJSPandaFile(pf.get()); } diff --git a/ecmascript/jspandafile/tests/panda_file_translator_test.cpp b/ecmascript/jspandafile/tests/panda_file_translator_test.cpp index 0520fde220..d8edae1b32 100644 --- a/ecmascript/jspandafile/tests/panda_file_translator_test.cpp +++ b/ecmascript/jspandafile/tests/panda_file_translator_test.cpp @@ -87,15 +87,15 @@ HWTEST_F_L0(PandaFileTranslatorTest, GenerateProgram) pfManager->AddJSPandaFile(pf); JSHandle program1 = pfManager->GenerateProgram(vm, pf.get(), std::string_view("func")); - JSHandle mainFunc1(thread, program1->GetMainFunction()); + JSHandle mainFunc1(thread, program1->GetMainFunction(thread)); JSHandle funcName1 = JSFunction::GetFunctionName(thread, JSHandle(mainFunc1)); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(funcName1)).ToCString().c_str(), "func"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(funcName1)).ToCString(thread).c_str(), "func"); pf->UpdateMainMethodIndex(methodId[1].GetOffset()); JSHandle program2 = pfManager->GenerateProgram(vm, pf.get(), JSPandaFile::ENTRY_FUNCTION_NAME); - JSHandle mainFunc2(thread, program2->GetMainFunction()); + JSHandle mainFunc2(thread, program2->GetMainFunction(thread)); JSHandle funcName2 = JSFunction::GetFunctionName(thread, JSHandle(mainFunc2)); - EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(funcName2)).ToCString().c_str(), "func_main_0"); + EXPECT_STREQ(EcmaStringAccessor(JSHandle::Cast(funcName2)).ToCString(thread).c_str(), "func_main_0"); pfManager->RemoveJSPandaFile(pf.get()); } diff --git a/ecmascript/layout_info-inl.h b/ecmascript/layout_info-inl.h index 09802829e8..bca8528294 100644 --- a/ecmascript/layout_info-inl.h +++ b/ecmascript/layout_info-inl.h @@ -67,38 +67,38 @@ inline void LayoutInfo::SetPropertyInit(const JSThread *thread, int index, const inline void LayoutInfo::SetNormalAttr(const JSThread *thread, int index, const PropertyAttributes &attr) { uint32_t fixedIdx = GetAttrIndex(index); - PropertyAttributes oldAttr(TaggedArray::Get(fixedIdx)); + PropertyAttributes oldAttr(TaggedArray::Get(thread, fixedIdx)); oldAttr.SetNormalAttr(attr.GetNormalAttr()); TaggedArray::Set(thread, fixedIdx, oldAttr.GetTaggedValue()); } -inline JSTaggedValue LayoutInfo::GetKey(int index) const +inline JSTaggedValue LayoutInfo::GetKey(const JSThread *thread, int index) const { uint32_t fixedIdx = GetKeyIndex(index); - return TaggedArray::Get(fixedIdx); + return TaggedArray::Get(thread, fixedIdx); } -inline PropertyAttributes LayoutInfo::GetAttr(int index) const +inline PropertyAttributes LayoutInfo::GetAttr(const JSThread *thread, int index) const { uint32_t fixedIdx = GetAttrIndex(index); - return PropertyAttributes(TaggedArray::Get(fixedIdx)); + return PropertyAttributes(TaggedArray::Get(thread, fixedIdx)); } -inline JSTaggedValue LayoutInfo::GetSortedKey(int index) const +inline JSTaggedValue LayoutInfo::GetSortedKey(const JSThread *thread, int index) const { - uint32_t fixedIdx = GetSortedIndex(index); - return GetKey(fixedIdx); + uint32_t fixedIdx = GetSortedIndex(thread, index); + return GetKey(thread, fixedIdx); } -inline uint32_t LayoutInfo::GetSortedIndex(int index) const +inline uint32_t LayoutInfo::GetSortedIndex(const JSThread *thread, int index) const { - return GetAttr(index).GetSortedIndex(); + return GetAttr(thread, index).GetSortedIndex(); } inline void LayoutInfo::SetSortedIndex(const JSThread *thread, int index, int sortedIndex) { uint32_t fixedIdx = GetAttrIndex(index); - PropertyAttributes attr(TaggedArray::Get(fixedIdx)); + PropertyAttributes attr(TaggedArray::Get(thread, fixedIdx)); attr.SetSortedIndex(sortedIndex); TaggedArray::Set(thread, fixedIdx, attr.GetTaggedValue()); } @@ -112,7 +112,8 @@ inline int LayoutInfo::FindElementWithCache(const JSThread *thread, JSHClass *cl void *properties = reinterpret_cast(GetProperties()); size_t keyOffset = 0; for (int i = 0; i < propertiesNumber; i++) { - JSTaggedValue propKey(Barriers::GetTaggedValue(ToUintPtr(properties) + i * sizeof(Properties) + keyOffset)); + JSTaggedValue propKey(Barriers::GetTaggedValue(thread, + ToUintPtr(properties) + i * sizeof(Properties) + keyOffset)); if (propKey == key) { return i; } @@ -122,50 +123,50 @@ inline int LayoutInfo::FindElementWithCache(const JSThread *thread, JSHClass *cl // jit compile thread not use cache if (thread->IsJitThread()) { - return BinarySearch(key, propertiesNumber); + return BinarySearch(thread, key, propertiesNumber); } PropertiesCache *cache = thread->GetPropertiesCache(); - int index = cache->Get(cls, key); + int index = cache->Get(thread, cls, key); if (index == PropertiesCache::NOT_FOUND) { - index = BinarySearch(key, propertiesNumber); + index = BinarySearch(thread, key, propertiesNumber); if (index != -1) { - cache->Set(cls, key, index); + cache->Set(thread, cls, key, index); } } return index; } -inline int LayoutInfo::BinarySearch(JSTaggedValue key, int propertiesNumber) +inline int LayoutInfo::BinarySearch(const JSThread *thread, JSTaggedValue key, int propertiesNumber) { ASSERT(NumberOfElements() >= propertiesNumber); int low = 0; int elements = NumberOfElements(); int high = elements - 1; - uint32_t keyHash = key.GetKeyHashCode(); + uint32_t keyHash = key.GetKeyHashCode(thread); ASSERT(low <= high); while (low <= high) { int mid = low + (high - low) / 2; // 2: half - JSTaggedValue midKey = GetSortedKey(mid); - uint32_t midHash = midKey.GetKeyHashCode(); + JSTaggedValue midKey = GetSortedKey(thread, mid); + uint32_t midHash = midKey.GetKeyHashCode(thread); if (midHash > keyHash) { high = mid - 1; } else if (midHash < keyHash) { low = mid + 1; } else { - int sortIndex = static_cast(GetSortedIndex(mid)); - JSTaggedValue currentKey = GetKey(sortIndex); + int sortIndex = static_cast(GetSortedIndex(thread, mid)); + JSTaggedValue currentKey = GetKey(thread, sortIndex); if (currentKey == key) { return sortIndex < propertiesNumber ? sortIndex : -1; } int midLeft = mid; int midRight = mid; while (midLeft - 1 >= 0) { - sortIndex = static_cast(GetSortedIndex(--midLeft)); - currentKey = GetKey(sortIndex); - if (currentKey.GetKeyHashCode() == keyHash) { + sortIndex = static_cast(GetSortedIndex(thread, --midLeft)); + currentKey = GetKey(thread, sortIndex); + if (currentKey.GetKeyHashCode(thread) == keyHash) { if (currentKey == key) { return sortIndex < propertiesNumber ? sortIndex : -1; } @@ -174,9 +175,9 @@ inline int LayoutInfo::BinarySearch(JSTaggedValue key, int propertiesNumber) } } while (midRight + 1 < elements) { - sortIndex = static_cast(GetSortedIndex(++midRight)); - currentKey = GetKey(sortIndex); - if (currentKey.GetKeyHashCode() == keyHash) { + sortIndex = static_cast(GetSortedIndex(thread, ++midRight)); + currentKey = GetKey(thread, sortIndex); + if (currentKey.GetKeyHashCode(thread) == keyHash) { if (currentKey == key) { return sortIndex < propertiesNumber ? sortIndex : -1; } @@ -193,24 +194,24 @@ inline int LayoutInfo::BinarySearch(JSTaggedValue key, int propertiesNumber) inline void LayoutInfo::SetIsNotHole(const JSThread *thread, int index) { uint32_t fixedIdx = GetAttrIndex(index); - PropertyAttributes attr(TaggedArray::Get(fixedIdx)); + PropertyAttributes attr(TaggedArray::Get(thread, fixedIdx)); attr.SetIsNotHole(true); TaggedArray::Set(thread, fixedIdx, attr.GetTaggedValue()); } -inline void LayoutInfo::UpdateTrackTypeAttr(int index, const PropertyAttributes &attr) +inline void LayoutInfo::UpdateTrackTypeAttr(const JSThread *thread, int index, const PropertyAttributes &attr) { uint32_t fixedIdx = GetAttrIndex(index); - PropertyAttributes oldAttr(TaggedArray::Get(fixedIdx)); + PropertyAttributes oldAttr(TaggedArray::Get(thread, fixedIdx)); oldAttr.SetNormalAttr(attr.GetNormalAttr()); oldAttr.SetIsPGODumped(false); SetWithoutBarrier(fixedIdx, oldAttr.GetTaggedValue()); } -inline void LayoutInfo::SetIsPGODumped(int index) +inline void LayoutInfo::SetIsPGODumped(const JSThread *thread, int index) { uint32_t fixedIdx = GetAttrIndex(index); - PropertyAttributes attr(TaggedArray::Get(fixedIdx)); + PropertyAttributes attr(TaggedArray::Get(thread, fixedIdx)); attr.SetIsPGODumped(true); SetWithoutBarrier(fixedIdx, attr.GetTaggedValue()); } @@ -226,20 +227,20 @@ void LayoutInfo::AddKey(const JSThread *thread, [[maybe_unused]] int index, cons SetNumberOfElements(thread, number + 1); SetPropertyInit(thread, number, key, attr); - uint32_t keyHash = key.GetKeyHashCode(); + uint32_t keyHash = key.GetKeyHashCode(thread); int insertIndex = number; for (; insertIndex > 0; --insertIndex) { - JSTaggedValue prevKey = GetSortedKey(insertIndex - 1); - if (prevKey.GetKeyHashCode() <= keyHash) { + JSTaggedValue prevKey = GetSortedKey(thread, insertIndex - 1); + if (prevKey.GetKeyHashCode(thread) <= keyHash) { break; } - SetSortedIndex(thread, insertIndex, GetSortedIndex(insertIndex - 1)); + SetSortedIndex(thread, insertIndex, GetSortedIndex(thread, insertIndex - 1)); } SetSortedIndex(thread, insertIndex, number); if constexpr (checkDuplicateKeys) { while (insertIndex > 0) { - JSTaggedValue prevKey = GetSortedKey(--insertIndex); - if (prevKey.GetKeyHashCode() < keyHash) { + JSTaggedValue prevKey = GetSortedKey(thread, --insertIndex); + if (prevKey.GetKeyHashCode(thread) < keyHash) { return; } if (prevKey == key) { diff --git a/ecmascript/layout_info.cpp b/ecmascript/layout_info.cpp index 5f3efce21c..ba92ade943 100644 --- a/ecmascript/layout_info.cpp +++ b/ecmascript/layout_info.cpp @@ -37,7 +37,7 @@ void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedA DISALLOW_GARBAGE_COLLECTION; int enumKeys = 0; for (int i = 0; i < end; i++) { - JSTaggedValue key = GetKey(i); + JSTaggedValue key = GetKey(thread, i); if (key.IsString()) { keyArray->Set(thread, enumKeys + offset, key); enumKeys++; @@ -46,7 +46,7 @@ void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedA if (enumKeys < end) { for (int i = 0; i < end; i++) { - JSTaggedValue key = GetKey(i); + JSTaggedValue key = GetKey(thread, i); if (key.IsSymbol()) { keyArray->Set(thread, enumKeys + offset, key); enumKeys++; @@ -64,9 +64,9 @@ void LayoutInfo::GetAllKeysByFilter(const JSThread *thread, uint32_t numberOfPro DISALLOW_GARBAGE_COLLECTION; uint32_t enumKeys = 0; for (uint32_t i = 0; i < numberOfProps; i++) { - JSTaggedValue key = GetKey(static_cast(i)); + JSTaggedValue key = GetKey(thread, static_cast(i)); if (key.IsString() && !(filter & NATIVE_KEY_SKIP_STRINGS)) { - PropertyAttributes attr = GetAttr(static_cast(i)); + PropertyAttributes attr = GetAttr(thread, static_cast(i)); bool bIgnore = FilterHelper::IgnoreKeyByFilter(attr, filter); if (bIgnore) { continue; @@ -79,9 +79,9 @@ void LayoutInfo::GetAllKeysByFilter(const JSThread *thread, uint32_t numberOfPro if (enumKeys < numberOfProps) { for (uint32_t i = 0; i < numberOfProps; i++) { - JSTaggedValue key = GetKey(static_cast(i)); + JSTaggedValue key = GetKey(thread, static_cast(i)); if (key.IsSymbol() && !(filter & NATIVE_KEY_SKIP_SYMBOLS)) { - PropertyAttributes attr = GetAttr(static_cast(i)); + PropertyAttributes attr = GetAttr(thread, static_cast(i)); bool bIgnore = FilterHelper::IgnoreKeyByFilter(attr, filter); if (bIgnore) { continue; @@ -93,28 +93,28 @@ void LayoutInfo::GetAllKeysByFilter(const JSThread *thread, uint32_t numberOfPro } } -void LayoutInfo::GetAllKeysForSerialization(int end, std::vector &keyVector) +void LayoutInfo::GetAllKeysForSerialization(const JSThread *thread, int end, std::vector &keyVector) { ASSERT(end <= NumberOfElements()); for (int i = 0; i < end; i++) { - JSTaggedValue key = GetKey(i); + JSTaggedValue key = GetKey(thread, i); if (key.IsString() || key.IsSymbol()) { keyVector.emplace_back(key); } } } -std::pair LayoutInfo::GetNumOfEnumKeys(int end) const +std::pair LayoutInfo::GetNumOfEnumKeys(const JSThread *thread, int end) const { ASSERT(end <= NumberOfElements()); uint32_t enumKeys = 0; uint32_t shadowKeys = 0; for (int i = 0; i < end; i++) { - JSTaggedValue key = GetKey(i); + JSTaggedValue key = GetKey(thread, i); if (!key.IsString()) { continue; } - if (GetAttr(i).IsEnumerable()) { + if (GetAttr(thread, i).IsEnumerable()) { enumKeys++; } else { shadowKeys++; @@ -132,11 +132,11 @@ void LayoutInfo::GetAllEnumKeys(JSThread *thread, int end, int offset, JSHandle< JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); int enumKeys = 0; for (int i = 0; i < end; i++) { - keyHandle.Update(GetKey(i)); + keyHandle.Update(GetKey(thread, i)); if (!keyHandle->IsString()) { continue; } - if (GetAttr(i).IsEnumerable()) { + if (GetAttr(thread, i).IsEnumerable()) { bool isDuplicated = JSObject::IsDepulicateKeys(thread, keyArray, lastLength, shadowQueue, keyHandle); if (isDuplicated) { continue; @@ -158,8 +158,8 @@ void LayoutInfo::GetAllEnumKeys(JSThread *thread, int end, int offset, JSHandle< JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); int enumKeys = 0; for (int i = 0; i < end; i++) { - keyHandle.Update(GetKey(i)); - if (keyHandle->IsString() && GetAttr(i).IsEnumerable()) { + keyHandle.Update(GetKey(thread, i)); + if (keyHandle->IsString() && GetAttr(thread, i).IsEnumerable()) { keyArray->Set(thread, enumKeys + offset, keyHandle); enumKeys++; } @@ -167,39 +167,39 @@ void LayoutInfo::GetAllEnumKeys(JSThread *thread, int end, int offset, JSHandle< *keys += enumKeys; } -CString LayoutInfo::GetSymbolKeyString(JSTaggedValue key) +CString LayoutInfo::GetSymbolKeyString(const JSThread *thread, JSTaggedValue key) { auto symbol = JSSymbol::Cast(key); if (!symbol->HasId()) { return ""; } auto id = symbol->GetPrivateId(); - auto symbolDesc = symbol->GetDescription(); + auto symbolDesc = symbol->GetDescription(thread); if (symbolDesc.IsUndefined()) { return ToCString(id); } if (!symbolDesc.IsString()) { return ""; } - CString str = EcmaStringAccessor(symbolDesc).ToCString(); + CString str = EcmaStringAccessor(symbolDesc).ToCString(thread); if (str != "method") { return ""; } return str.append("_").append(ToCString(id)); } -void LayoutInfo::DumpFieldIndexByPGO(int index, pgo::HClassLayoutDesc* desc) +void LayoutInfo::DumpFieldIndexByPGO(const JSThread *thread, int index, pgo::HClassLayoutDesc* desc) { - auto key = GetKey(index); - auto attr = GetAttr(index); - SetIsPGODumped(index); + auto key = GetKey(thread, index); + auto attr = GetAttr(thread, index); + SetIsPGODumped(thread, index); TrackType type = attr.GetTrackType(); int propertyMeta = attr.GetPropertyMetaData(); if (key.IsString()) { - auto keyString = EcmaStringAccessor(key).ToCString(); + auto keyString = EcmaStringAccessor(key).ToCString(thread); desc->InsertKeyAndDesc(keyString, PGOHandler(type, propertyMeta, false)); } else if (key.IsSymbol()) { - auto keyString = GetSymbolKeyString(key); + auto keyString = GetSymbolKeyString(thread, key); if (keyString.empty()) { return; } @@ -207,21 +207,21 @@ void LayoutInfo::DumpFieldIndexByPGO(int index, pgo::HClassLayoutDesc* desc) } } -bool LayoutInfo::UpdateFieldIndexByPGO(int index, pgo::HClassLayoutDesc* desc) +bool LayoutInfo::UpdateFieldIndexByPGO(const JSThread *thread, int index, pgo::HClassLayoutDesc* desc) { - auto key = GetKey(index); - auto attr = GetAttr(index); + auto key = GetKey(thread, index); + auto attr = GetAttr(thread, index); if (attr.IsPGODumped()) { return true; } - SetIsPGODumped(index); + SetIsPGODumped(thread, index); TrackType type = attr.GetTrackType(); int propertyMeta = attr.GetPropertyMetaData(); if (key.IsString()) { - auto keyString = EcmaStringAccessor(key).ToCString(); + auto keyString = EcmaStringAccessor(key).ToCString(thread); return desc->UpdateKeyAndDesc(keyString, PGOHandler(type, propertyMeta, false)); } else if (key.IsSymbol()) { - auto keyString = GetSymbolKeyString(key); + auto keyString = GetSymbolKeyString(thread, key); if (keyString.empty()) { return false; } diff --git a/ecmascript/layout_info.h b/ecmascript/layout_info.h index 6f15e78e30..e72d18b155 100644 --- a/ecmascript/layout_info.h +++ b/ecmascript/layout_info.h @@ -45,9 +45,9 @@ public: return reinterpret_cast(obj); } - static LayoutInfo* GetLayoutInfoFromHClass(const JSHClass* hclass) + static LayoutInfo* GetLayoutInfoFromHClass(const JSThread *thread, const JSHClass* hclass) { - return LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + return LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); } void Initialize(const JSThread *thread, int num = 0); @@ -60,16 +60,16 @@ public: void SetPropertyInit(const JSThread *thread, int index, const JSTaggedValue &key, const PropertyAttributes &attr); void SetKey(const JSThread *thread, int index, const JSTaggedValue &key); void SetNormalAttr(const JSThread *thread, int index, const PropertyAttributes &attr); - JSTaggedValue GetKey(int index) const; - PropertyAttributes GetAttr(int index) const; - JSTaggedValue GetSortedKey(int index) const; - uint32_t GetSortedIndex(int index) const; + JSTaggedValue GetKey(const JSThread *thread, int index) const; + PropertyAttributes GetAttr(const JSThread *thread, int index) const; + JSTaggedValue GetSortedKey(const JSThread *thread, int index) const; + uint32_t GetSortedIndex(const JSThread *thread, int index) const; void SetSortedIndex(const JSThread *thread, int index, int sortedIndex); template void AddKey(const JSThread *thread, int index, const JSTaggedValue &key, const PropertyAttributes &attr); void SetIsNotHole(const JSThread *thread, int index); - void UpdateTrackTypeAttr(int index, const PropertyAttributes &attr); - void SetIsPGODumped(int index); + void UpdateTrackTypeAttr(const JSThread *thread, int index, const PropertyAttributes &attr); + void SetIsPGODumped(const JSThread *thread, int index); inline uint32_t GetLength() const { @@ -93,19 +93,19 @@ public: } int FindElementWithCache(const JSThread *thread, JSHClass *cls, JSTaggedValue key, int propertiesNumber); - int BinarySearch(JSTaggedValue key, int propertiesNumber); + int BinarySearch(const JSThread *thread, JSTaggedValue key, int propertiesNumber); void GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray); - void GetAllKeysForSerialization(int end, std::vector &keyVector); + void GetAllKeysForSerialization(const JSThread *thread, int end, std::vector &keyVector); void GetAllKeysByFilter(const JSThread *thread, uint32_t numberOfProps, uint32_t &keyArrayEffectivelength, TaggedArray *keyArray, uint32_t filter); - std::pair GetNumOfEnumKeys(int end) const; + std::pair GetNumOfEnumKeys(const JSThread *thread, int end) const; void GetAllEnumKeys(JSThread *thread, int end, int offset, JSHandle keyArray, uint32_t *keys, JSHandle shadowQueue, int32_t lastLength); void GetAllEnumKeys(JSThread *thread, int end, int offset, JSHandle keyArray, uint32_t *keys); - void DumpFieldIndexByPGO(int index, pgo::HClassLayoutDesc* desc); - bool UpdateFieldIndexByPGO(int index, pgo::HClassLayoutDesc* desc); - CString GetSymbolKeyString(JSTaggedValue key); + void DumpFieldIndexByPGO(const JSThread *thread, int index, pgo::HClassLayoutDesc* desc); + bool UpdateFieldIndexByPGO(const JSThread *thread, int index, pgo::HClassLayoutDesc* desc); + CString GetSymbolKeyString(const JSThread *thread, JSTaggedValue key); DECL_DUMP() }; } // namespace panda::ecmascript diff --git a/ecmascript/lexical_env.h b/ecmascript/lexical_env.h index b0e230b161..63e9f097b9 100644 --- a/ecmascript/lexical_env.h +++ b/ecmascript/lexical_env.h @@ -42,14 +42,14 @@ public: Set(thread, PARENT_ENV_INDEX, value); } - JSTaggedValue GetParentEnv() const + JSTaggedValue GetParentEnv(const JSThread *thread) const { - return Get(PARENT_ENV_INDEX); + return Get(thread, PARENT_ENV_INDEX); } - JSTaggedValue GetProperties(uint32_t index) const + JSTaggedValue GetProperties(const JSThread *thread, uint32_t index) const { - return Get(index + RESERVED_ENV_LENGTH); + return Get(thread, index + RESERVED_ENV_LENGTH); } void SetProperties(JSThread *thread, uint32_t index, JSTaggedValue value) @@ -57,9 +57,9 @@ public: Set(thread, index + RESERVED_ENV_LENGTH, value); } - JSTaggedValue GetScopeInfo() const + JSTaggedValue GetScopeInfo(const JSThread *thread) const { - return Get(SCOPE_INFO_INDEX); + return Get(thread, SCOPE_INFO_INDEX); } void SetScopeInfo(JSThread *thread, JSTaggedValue value) @@ -92,9 +92,9 @@ public: Set(thread, CONSTRUCTOR_INDEX, value); } - JSTaggedValue GetConstructor() const + JSTaggedValue GetConstructor(const JSThread *thread) const { - return Get(CONSTRUCTOR_INDEX); + return Get(thread, CONSTRUCTOR_INDEX); } DECL_DUMP() diff --git a/ecmascript/linked_hash_table.cpp b/ecmascript/linked_hash_table.cpp index e7478435ed..8db5ba248b 100644 --- a/ecmascript/linked_hash_table.cpp +++ b/ecmascript/linked_hash_table.cpp @@ -166,7 +166,7 @@ JSTaggedValue LinkedHashMap::Get(const JSThread *thread, JSTaggedValue key) cons if (entry == -1) { return JSTaggedValue::Undefined(); } - return GetValue(entry); + return GetValue(thread, entry); } bool LinkedHashMap::Has(const JSThread *thread, JSTaggedValue key) const @@ -264,10 +264,10 @@ int LinkedHash::Hash(const JSThread *thread, JSTaggedValue key) } if (key.IsString()) { auto keyString = reinterpret_cast(key.GetTaggedObject()); - return EcmaStringAccessor(keyString).GetHashcode(); + return EcmaStringAccessor(keyString).GetHashcode(thread); } if (key.IsECMAObject()) { - int32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(); + int32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(thread); if (hash == 0) { hash = base::RandomGenerator::GenerateIdentityHash(); JSHandle ecmaObj(thread, key); diff --git a/ecmascript/linked_hash_table.h b/ecmascript/linked_hash_table.h index 66da179dcb..e4fcbf8537 100644 --- a/ecmascript/linked_hash_table.h +++ b/ecmascript/linked_hash_table.h @@ -93,16 +93,16 @@ public: } int hash = LinkedHash::Hash(thread, key); uint32_t bucket = HashToBucket(hash); - for (JSTaggedValue entry = GetElement(BucketToIndex(bucket)); !entry.IsHole(); - entry = GetNextEntry(entry.GetInt())) { - JSTaggedValue element = GetKey(entry.GetInt()); + for (JSTaggedValue entry = GetElement(thread, BucketToIndex(bucket)); !entry.IsHole(); + entry = GetNextEntry(thread, entry.GetInt())) { + JSTaggedValue element = GetKey(thread, entry.GetInt()); if (element.IsHole()) { continue; } if (element.IsWeak()) { element.RemoveWeakTag(); } - if (HashObject::IsMatch(key, element)) { + if (HashObject::IsMatch(thread, key, element)) { return entry.GetInt(); } } @@ -148,29 +148,29 @@ public: inline int NumberOfElements() const { - return Get(NUMBER_OF_ELEMENTS_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_ELEMENTS_INDEX).GetInt(); } inline int NumberOfDeletedElements() const { - return Get(NUMBER_OF_DELETED_ELEMENTS_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_DELETED_ELEMENTS_INDEX).GetInt(); } inline int Capacity() const { - return JSTaggedValue(Get(CAPACITY_INDEX)).GetInt(); + return JSTaggedValue(GetPrimitive(CAPACITY_INDEX)).GetInt(); } - inline JSTaggedValue GetKey(int entry) const + inline JSTaggedValue GetKey(const JSThread *thread, int entry) const { int index = static_cast(EntryToIndex(entry)); - return GetElement(index); + return GetElement(thread, index); } - inline JSTaggedValue GetValue(int entry) const + inline JSTaggedValue GetValue(const JSThread *thread, int entry) const { int index = static_cast(EntryToIndex(entry)) + HashObject::ENTRY_VALUE_INDEX; - return GetElement(index); + return GetElement(thread, index); } inline static bool IsKey(JSTaggedValue key) @@ -193,9 +193,9 @@ public: Set(thread, CAPACITY_INDEX, JSTaggedValue(capacity)); } - inline JSTaggedValue GetNextTable() const + inline JSTaggedValue GetNextTable(const JSThread *thread) const { - return JSTaggedValue(Get(NEXT_TABLE_INDEX)); + return JSTaggedValue(Get(thread, NEXT_TABLE_INDEX)); } inline void SetNextTable(const JSThread *thread, JSTaggedValue nextTable) @@ -203,16 +203,16 @@ public: Set(thread, NEXT_TABLE_INDEX, nextTable); } - inline int GetDeletedElementsAt(int entry) const + inline int GetDeletedElementsAt(const JSThread *thread, int entry) const { - ASSERT_PRINT(!GetNextTable().IsUndefined(), "function only execute after rehash"); + ASSERT_PRINT(!GetNextTable(thread).IsUndefined(), "function only execute after rehash"); int currentEntry = entry - 1; if (NumberOfDeletedElements() == -1) { return entry; } while (currentEntry >= 0) { - if (GetKey(currentEntry).IsHole()) { - return GetDeletedNum(currentEntry); + if (GetKey(thread, currentEntry).IsHole()) { + return GetDeletedNum(thread, currentEntry); } currentEntry--; } @@ -229,7 +229,7 @@ public: SetNextTable(thread, JSTaggedValue(newTable)); for (int i = 0; i < numberOfAllElements; i++) { int fromIndex = static_cast(EntryToIndex(i)); - JSTaggedValue key = GetElement(fromIndex); + JSTaggedValue key = GetElement(thread, fromIndex); if (key.IsHole()) { // store num_of_deleted_element before entry i; it will be used when iterator update. currentDeletedElements++; @@ -246,7 +246,7 @@ public: 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)); + newTable->SetElement(thread, desIndex + j, GetElement(thread, fromIndex + j)); } desEntry++; } @@ -255,10 +255,10 @@ public: } protected: - inline JSTaggedValue GetElement(int index) const + inline JSTaggedValue GetElement(const JSThread *thread, int index) const { ASSERT(index >= 0 && index < static_cast(GetLength())); - return Get(index); + return Get(thread, index); } inline void SetElement(const JSThread *thread, int index, JSTaggedValue element) @@ -279,10 +279,10 @@ protected: SetElement(thread, index, value); } - inline JSTaggedValue GetNextEntry(int entry) const + inline JSTaggedValue GetNextEntry(const JSThread *thread, int entry) const { int index = static_cast(EntryToIndex(entry)) + HashObject::ENTRY_SIZE; - return GetElement(index); + return GetElement(thread, index); } inline void SetNextEntry(const JSThread *thread, int entry, JSTaggedValue nextEntry) @@ -310,20 +310,20 @@ protected: inline void InsertNewEntry(const JSThread *thread, int bucket, int entry) { int bucketIndex = static_cast(BucketToIndex(bucket)); - JSTaggedValue previousEntry = GetElement(bucketIndex); + JSTaggedValue previousEntry = GetElement(thread, bucketIndex); SetNextEntry(thread, entry, previousEntry); SetElement(thread, bucketIndex, JSTaggedValue(entry)); } - inline int GetDeletedNum(int entry) const + inline int GetDeletedNum(const JSThread *thread, int entry) const { - ASSERT_PRINT(!GetNextTable().IsUndefined(), "function only execute after rehash"); - return GetNextEntry(entry).GetInt(); + ASSERT_PRINT(!GetNextTable(thread).IsUndefined(), "function only execute after rehash"); + return GetNextEntry(thread, entry).GetInt(); } inline void SetDeletedNum(const JSThread *thread, int entry, JSTaggedValue num) { - ASSERT_PRINT(!GetNextTable().IsUndefined(), "function only execute after rehash"); + ASSERT_PRINT(!GetNextTable(thread).IsUndefined(), "function only execute after rehash"); SetNextEntry(thread, entry, num); } }; @@ -331,9 +331,9 @@ protected: class LinkedHashMapObject { public: // key must be string now for other object has no 'equals' method - static inline bool IsMatch(JSTaggedValue key, JSTaggedValue other) + static inline bool IsMatch(const JSThread *thread, JSTaggedValue key, JSTaggedValue other) { - return JSTaggedValue::SameValueZero(key, other); + return JSTaggedValue::SameValueZero(thread, key, other); } static const int ENTRY_SIZE = 2; @@ -372,9 +372,9 @@ public: class LinkedHashSetObject { public: // key must be string now for other object has no 'equals' method - static inline bool IsMatch(JSTaggedValue key, JSTaggedValue other) + static inline bool IsMatch(const JSThread *thread, JSTaggedValue key, JSTaggedValue other) { - return JSTaggedValue::SameValueZero(key, other); + return JSTaggedValue::SameValueZero(thread, key, other); } static const int ENTRY_SIZE = 1; diff --git a/ecmascript/mem/barriers-inl.h b/ecmascript/mem/barriers-inl.h index e82c4f09c1..835ded451f 100644 --- a/ecmascript/mem/barriers-inl.h +++ b/ecmascript/mem/barriers-inl.h @@ -131,7 +131,8 @@ inline void Barriers::SynchronizedSetObject(const JSThread *thread, void *obj, s } template -static inline void CopyBackward(JSTaggedValue* dst, const JSTaggedValue* src, size_t count) +static inline void CopyBackward([[maybe_unused]]const JSThread *thread, JSTaggedValue* dst, const JSTaggedValue* src, + size_t count) { if constexpr (needReadBarrier == false) { std::copy_backward(src, src + count, dst + count); @@ -139,13 +140,14 @@ static inline void CopyBackward(JSTaggedValue* dst, const JSTaggedValue* src, si } for (size_t i = count; i > 0; i--) { - JSTaggedType valueToRef = Barriers::GetTaggedValue(src, (i - 1) * sizeof(JSTaggedType)); + JSTaggedType valueToRef = Barriers::GetTaggedValue(thread, src, (i - 1) * sizeof(JSTaggedType)); Barriers::SetObject(nullptr, dst, (i - 1) * sizeof(JSTaggedType), valueToRef); } } template -static inline void CopyForward(JSTaggedValue* dst, const JSTaggedValue* src, size_t count) +static inline void CopyForward([[maybe_unused]]const JSThread *thread, JSTaggedValue* dst, const JSTaggedValue* src, + size_t count) { if constexpr (needReadBarrier == false) { std::copy_n(src, count, dst); @@ -153,7 +155,7 @@ static inline void CopyForward(JSTaggedValue* dst, const JSTaggedValue* src, siz } for (size_t i = 0; i < count; i++) { - JSTaggedType valueToRef = Barriers::GetTaggedValue(src, i * sizeof(JSTaggedType)); + JSTaggedType valueToRef = Barriers::GetTaggedValue(thread, src, i * sizeof(JSTaggedType)); Barriers::SetObject(nullptr, dst, i * sizeof(JSTaggedType), valueToRef); } } @@ -172,13 +174,13 @@ void Barriers::CopyObject(const JSThread *thread, const TaggedObject *dstObj, JS // step 1. copy from src to dst directly. #ifdef USE_READ_BARRIER if (thread->IsCMCGCConcurrentCopying()) { - CopyObjectPrimitive(dstAddr, srcAddr, count); + CopyObjectPrimitive(thread, dstAddr, srcAddr, count); return; } else { - CopyObjectPrimitive(dstAddr, srcAddr, count); + CopyObjectPrimitive(thread, dstAddr, srcAddr, count); } #else - CopyObjectPrimitive(dstAddr, srcAddr, count); + CopyObjectPrimitive(thread, dstAddr, srcAddr, count); #endif if constexpr (!needWriteBarrier) { @@ -232,18 +234,19 @@ void Barriers::CopyObject(const JSThread *thread, const TaggedObject *dstObj, JS } template -inline void Barriers::CopyObjectPrimitive(JSTaggedValue* dst, const JSTaggedValue* src, size_t count) +inline void Barriers::CopyObjectPrimitive(const JSThread *thread, JSTaggedValue* dst, const JSTaggedValue* src, + size_t count) { // Copy Primitive value don't need thread. ASSERT((ToUintPtr(dst) % static_cast(MemAlignment::MEM_ALIGN_OBJECT)) == 0); if constexpr (maybeOverlap == false) { - CopyForward(dst, src, count); + CopyForward(thread, dst, src, count); return; } if (dst > src && dst < src + count) { - CopyBackward(dst, src, count); + CopyBackward(thread, dst, src, count); } else { - CopyForward(dst, src, count); + CopyForward(thread, dst, src, count); } } } // namespace panda::ecmascript diff --git a/ecmascript/mem/barriers.h b/ecmascript/mem/barriers.h index cb2c3c812a..e1b6cc8062 100644 --- a/ecmascript/mem/barriers.h +++ b/ecmascript/mem/barriers.h @@ -78,23 +78,25 @@ public: // // Note: dstObj is the object address for dstAddr, it must point to the head of an object. template - static void CopyObjectPrimitive(JSTaggedValue* dst, const JSTaggedValue* src, size_t count); + static void CopyObjectPrimitive(const JSThread *thread, JSTaggedValue* dst, const JSTaggedValue* src, + size_t count); static void SynchronizedSetObject(const JSThread *thread, void *obj, size_t offset, JSTaggedType value, bool isPrimitive = false); template - static inline T GetValue(const void *obj, size_t offset) + static inline T GetPrimitive(const void *obj, size_t offset) { auto *addr = reinterpret_cast(ToUintPtr(obj) + offset); return *addr; } - static inline ARK_INLINE TaggedObject* GetTaggedObject(const void* obj, size_t offset) + static inline ARK_INLINE TaggedObject* GetTaggedObject(const JSThread *thread, + const void* obj, size_t offset) { - return JSTaggedValue(GetTaggedValue(obj, offset)).GetTaggedObject(); + return JSTaggedValue(GetTaggedValue(thread, obj, offset)).GetTaggedObject(); } - static inline JSTaggedType GetTaggedValue(const void *obj, size_t offset) + static inline JSTaggedType GetTaggedValue([[maybe_unused]]const JSThread *thread, const void *obj, size_t offset) { #ifdef USE_READ_BARRIER JSTaggedValue value = *reinterpret_cast(ToUintPtr(obj) + offset); @@ -110,7 +112,7 @@ public: #endif } - static inline JSTaggedType GetTaggedValue(uintptr_t slotAddress) + static inline JSTaggedType GetTaggedValue([[maybe_unused]]const JSThread *thread, uintptr_t slotAddress) { #ifdef USE_READ_BARRIER JSTaggedValue value = *reinterpret_cast(slotAddress); @@ -125,7 +127,8 @@ public: #endif } - static inline JSTaggedType GetTaggedValueAtomic(const void *obj, size_t offset) + static inline JSTaggedType GetTaggedValueAtomic([[maybe_unused]]const JSThread *thread, const void *obj, + size_t offset) { #ifdef USE_READ_BARRIER JSTaggedValue value = reinterpret_cast *>(ToUintPtr(obj) + @@ -144,9 +147,9 @@ public: #endif } - static inline JSTaggedType UpdateSlot(void *obj, size_t offset) + static inline JSTaggedType UpdateSlot(const JSThread *thread, void *obj, size_t offset) { - JSTaggedType value = GetTaggedValue(obj, offset); + JSTaggedType value = GetTaggedValue(thread, obj, offset); *reinterpret_cast(ToUintPtr(obj) + offset) = value; return value; } diff --git a/ecmascript/mem/c_string.cpp b/ecmascript/mem/c_string.cpp index ae29c2f4f5..6b14c004b5 100644 --- a/ecmascript/mem/c_string.cpp +++ b/ecmascript/mem/c_string.cpp @@ -83,19 +83,19 @@ CString ConvertToString(T sp) return res; } -CString ConvertToString(JSTaggedValue key) +CString ConvertToString(const JSThread *thread, JSTaggedValue key) { ASSERT(key.IsStringOrSymbol()); if (key.IsString()) { - return ConvertToString(EcmaString::ConstCast(key.GetTaggedObject())); + return ConvertToString(thread, EcmaString::ConstCast(key.GetTaggedObject())); } - ecmascript::JSTaggedValue desc = JSSymbol::Cast(key.GetTaggedObject())->GetDescription(); + ecmascript::JSTaggedValue desc = JSSymbol::Cast(key.GetTaggedObject())->GetDescription(thread); if (desc.IsUndefined()) { return CString("Symbol()"); } - return ConvertToString(EcmaString::ConstCast(desc.GetTaggedObject())); + return ConvertToString(thread, EcmaString::ConstCast(desc.GetTaggedObject())); } // NB! the following function need additional mem allocation, don't use when unnecessary! @@ -109,12 +109,12 @@ CString ConvertToString(const std::string &str) return res; } -CString ConvertToString(const EcmaString *s, StringConvertedUsage usage, bool cesu8) +CString ConvertToString(const JSThread *thread, const EcmaString *s, StringConvertedUsage usage, bool cesu8) { if (s == nullptr) { return CString(""); } - return EcmaStringAccessor(const_cast(s)).ToCString(usage, cesu8); + return EcmaStringAccessor(const_cast(s)).ToCString(thread, usage, cesu8); } std::string ConvertToStdString(const CString &str) @@ -253,30 +253,30 @@ void ConvertNumberToCStringAndAppend(DstType &str, JSTaggedValue num) template void ConvertNumberToCStringAndAppend(CString &str, JSTaggedValue num); template void ConvertNumberToCStringAndAppend(C16String &str, JSTaggedValue num); -void ConvertQuotedAndAppendToCString(CString &str, const EcmaString *s) +void ConvertQuotedAndAppendToCString(const JSThread *thread, CString &str, const EcmaString *s) { ASSERT(s != nullptr); uint32_t strLen = EcmaStringAccessor(const_cast(s)).GetLength(); CVector buf; - const uint8_t *data = EcmaStringAccessor::GetUtf8DataFlat(s, buf); + const uint8_t *data = EcmaStringAccessor::GetUtf8DataFlat(thread, s, buf); const Span dataSpan(data, strLen); base::JsonHelper::AppendValueToQuotedString(dataSpan, str); } -void ConvertQuotedAndAppendToC16String(C16String &str, const EcmaString *s) +void ConvertQuotedAndAppendToC16String(const JSThread *thread, C16String &str, const EcmaString *s) { ASSERT(s != nullptr); uint32_t strLen = EcmaStringAccessor(const_cast(s)).GetLength(); if (EcmaStringAccessor(const_cast(s)).IsUtf8()) { CVector buf; - const uint8_t *data = EcmaStringAccessor::GetUtf8DataFlat(s, buf); + const uint8_t *data = EcmaStringAccessor::GetUtf8DataFlat(thread, s, buf); const Span dataSpan(data, strLen); base::JsonHelper::AppendValueToQuotedString(dataSpan, str); } else { CVector buf; - const uint16_t *data = EcmaStringAccessor::GetUtf16DataFlat(s, buf); + const uint16_t *data = EcmaStringAccessor::GetUtf16DataFlat(thread, s, buf); const Span dataSpan(data, strLen); base::JsonHelper::AppendValueToQuotedString(dataSpan, str); } diff --git a/ecmascript/mem/c_string.h b/ecmascript/mem/c_string.h index 84304ca928..85e341b060 100644 --- a/ecmascript/mem/c_string.h +++ b/ecmascript/mem/c_string.h @@ -57,7 +57,7 @@ std::string PUBLIC_API ConvertToStdString(const CString &str); // '\u0000' is skip according to holdZero // cesu8 means non-BMP1 codepoints should encode as 1 utf8 string -CString PUBLIC_API ConvertToString(const ecmascript::EcmaString *s, +CString PUBLIC_API ConvertToString(const JSThread *thread, const ecmascript::EcmaString *s, StringConvertedUsage usage = StringConvertedUsage::PRINT, bool cesu8 = false); #if ENABLE_NEXT_OPTIMIZATION @@ -69,11 +69,11 @@ template void AppendIntToCString(DstType &str, int number); template void ConvertNumberToCStringAndAppend(DstType &str, JSTaggedValue num); -void ConvertQuotedAndAppendToCString(CString &str, const EcmaString *s); -void ConvertQuotedAndAppendToC16String(C16String &str, const EcmaString *s); +void ConvertQuotedAndAppendToCString(const JSThread *thread, CString &str, const EcmaString *s); +void ConvertQuotedAndAppendToC16String(const JSThread *thread, C16String &str, const EcmaString *s); #endif -CString ConvertToString(ecmascript::JSTaggedValue key); +CString ConvertToString(const JSThread *thread, ecmascript::JSTaggedValue key); // append char to CString to C16String. // char16_t to CString needs to be converted, which is time-consuming. So this way is not allowed. diff --git a/ecmascript/mem/dynamic_object_operator.h b/ecmascript/mem/dynamic_object_operator.h index 977384255e..942a2994fd 100644 --- a/ecmascript/mem/dynamic_object_operator.h +++ b/ecmascript/mem/dynamic_object_operator.h @@ -43,15 +43,15 @@ class RefFieldObjectVisitor final : public BaseObjectVisitorSynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); - - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + auto thread = JSThread::GetCurrent(); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(thread).GetTaggedObject()); ObjectSlot realEnd = start; start += layout->GetPropertiesCapacity(); // only += operator is supported end = std::min(end, realEnd); int index = 0; for (ObjectSlot slot = start; slot < end; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { cb(slot); } diff --git a/ecmascript/mem/full_gc-inl.h b/ecmascript/mem/full_gc-inl.h index c529775612..75dd5c97d2 100644 --- a/ecmascript/mem/full_gc-inl.h +++ b/ecmascript/mem/full_gc-inl.h @@ -59,16 +59,17 @@ void FullGCRunner::HandleMarkingSlot(ObjectSlot slot) template void FullGCRunner::VisitBodyInObj(BaseObject *root, uintptr_t start, uintptr_t endAddr, Callback &&cb) { + JSThread *thread = heap_->GetJSThread(); JSHClass *hclass = TaggedObject::Cast(root)->SynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(thread).GetTaggedObject()); ObjectSlot realEnd(start); realEnd += layout->GetPropertiesCapacity(); ObjectSlot end(endAddr); end = end > realEnd ? realEnd : end; for (ObjectSlot slot(start); slot < end; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { cb(slot); } diff --git a/ecmascript/mem/machine_code.cpp b/ecmascript/mem/machine_code.cpp index c330e20ab6..7d2d74685a 100644 --- a/ecmascript/mem/machine_code.cpp +++ b/ecmascript/mem/machine_code.cpp @@ -117,11 +117,12 @@ bool MachineCode::SetNonText(const MachineCodeDesc &desc, EntityId methodId) return true; } -bool MachineCode::SetData(const MachineCodeDesc &desc, JSHandle &method, size_t dataSize, RelocMap &relocInfo) +bool MachineCode::SetData(JSThread *thread, const MachineCodeDesc &desc, JSHandle &method, + size_t dataSize, RelocMap &relocInfo) { DISALLOW_GARBAGE_COLLECTION; if (desc.codeType == MachineCodeType::BASELINE_CODE) { - return SetBaselineCodeData(desc, method, dataSize, relocInfo); + return SetBaselineCodeData(thread, desc, method, dataSize, relocInfo); } SetOSROffset(MachineCode::INVALID_OSR_OFFSET); @@ -154,7 +155,7 @@ bool MachineCode::SetData(const MachineCodeDesc &desc, JSHandle &method, uint8_t *stackmapAddr = GetStackMapOrOffsetTableAddress(); uint8_t *textStart = reinterpret_cast(GetText()); - CString methodName = method->GetRecordNameStr() + "." + CString(method->GetMethodName()); + CString methodName = method->GetRecordNameStr(thread) + "." + CString(method->GetMethodName(thread)); LOG_JIT(DEBUG) << "Fast JIT MachineCode :" << methodName << ", " << " text addr:" << reinterpret_cast(GetText()) << ", size:" << instrSize << ", stackMap addr:" << reinterpret_cast(stackmapAddr) << @@ -167,7 +168,7 @@ bool MachineCode::SetData(const MachineCodeDesc &desc, JSHandle &method, return true; } -bool MachineCode::SetBaselineCodeData(const MachineCodeDesc &desc, +bool MachineCode::SetBaselineCodeData(JSThread *thread, const MachineCodeDesc &desc, JSHandle &method, size_t dataSize, RelocMap &relocInfo) { DISALLOW_GARBAGE_COLLECTION; @@ -220,7 +221,7 @@ bool MachineCode::SetBaselineCodeData(const MachineCodeDesc &desc, SetFuncAddr(reinterpret_cast(textStart)); - CString methodName = method->GetRecordNameStr() + "." + CString(method->GetMethodName()); + CString methodName = method->GetRecordNameStr(thread) + "." + CString(method->GetMethodName(thread)); LOG_BASELINEJIT(DEBUG) << "BaselineCode :" << methodName << ", " << " text addr:" << reinterpret_cast(GetText()) << ", size:" << instrSizeAlign << ", stackMap addr: 0, size: 0"; diff --git a/ecmascript/mem/machine_code.h b/ecmascript/mem/machine_code.h index 5053a932ab..638c496679 100644 --- a/ecmascript/mem/machine_code.h +++ b/ecmascript/mem/machine_code.h @@ -238,7 +238,7 @@ public: int32_t GetCalleeReg2OffsetArray(int32_t calleeRegIndex) const { DASSERT_PRINT(calleeRegIndex < CalleeReg2OffsetArraySize, "Array index out of bounds."); - return Barriers::GetValue(this, CALLEE_R2O_OFFSET + calleeRegIndex * INT32_SIZE); + return Barriers::GetPrimitive(this, CALLEE_R2O_OFFSET + calleeRegIndex * INT32_SIZE); } // define BitField @@ -261,7 +261,8 @@ public: return GetInstructionsSize(); } - bool SetData(const MachineCodeDesc &desc, JSHandle &method, size_t dataSize, RelocMap &relocInfo); + bool SetData(JSThread *thread, const MachineCodeDesc &desc, JSHandle &method, + size_t dataSize, RelocMap &relocInfo); bool SetText(const MachineCodeDesc &desc); bool SetNonText(const MachineCodeDesc &desc, EntityId methodId); @@ -300,7 +301,7 @@ public: void SetOsrDeoptFlag(bool isDeopt) { - uint16_t flag = Barriers::GetValue(this, OSRMASK_OFFSET); + uint16_t flag = Barriers::GetPrimitive(this, OSRMASK_OFFSET); if (isDeopt) { flag |= OSR_DEOPT_FLAG; } else { @@ -314,7 +315,7 @@ public: Barriers::SetPrimitive(this, OSR_EXECUTE_CNT_OFFSET, count); } private: - bool SetBaselineCodeData(const MachineCodeDesc &desc, JSHandle &method, + bool SetBaselineCodeData(JSThread *thread, const MachineCodeDesc &desc, JSHandle &method, size_t dataSize, RelocMap &relocInfo); }; } // namespace panda::ecmascript diff --git a/ecmascript/mem/old_gc_visitor-inl.h b/ecmascript/mem/old_gc_visitor-inl.h index b16bde712f..ff3686fb84 100644 --- a/ecmascript/mem/old_gc_visitor-inl.h +++ b/ecmascript/mem/old_gc_visitor-inl.h @@ -77,18 +77,19 @@ void OldGCMarkObjectVisitor::VisitObjectRangeImpl(BaseObject *rootObject, uintpt ObjectSlot startSlot(start); ObjectSlot endSlot(end); auto root = TaggedObject::Cast(rootObject); + JSThread *thread = workNodeHolder_->GetJSThread(); Region *rootRegion = Region::ObjectAddressToRange(root); bool rootNeedEvacuate = rootRegion->InYoungSpaceOrCSet(); if (UNLIKELY(area == VisitObjectArea::IN_OBJECT)) { JSHClass *hclass = root->SynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(thread).GetTaggedObject()); ObjectSlot realEnd(start); realEnd += layout->GetPropertiesCapacity(); endSlot = endSlot > realEnd ? realEnd : endSlot; for (ObjectSlot slot = startSlot; slot < endSlot; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { HandleSlot(slot, rootRegion, rootNeedEvacuate); } diff --git a/ecmascript/mem/parallel_evacuator-inl.h b/ecmascript/mem/parallel_evacuator-inl.h index 5ca803cf81..b642e19922 100644 --- a/ecmascript/mem/parallel_evacuator-inl.h +++ b/ecmascript/mem/parallel_evacuator-inl.h @@ -257,6 +257,7 @@ ParallelEvacuator::SetObjectFieldRSetVisitor::SetObjectFieldRSetVisitor(Parallel void ParallelEvacuator::SetObjectFieldRSetVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t startAddr, uintptr_t endAddr, VisitObjectArea area) { + JSThread *thread = evacuator_->heap_->GetJSThread(); Region *rootRegion = Region::ObjectAddressToRange(root); ObjectSlot start(startAddr); ObjectSlot end(endAddr); @@ -264,13 +265,13 @@ void ParallelEvacuator::SetObjectFieldRSetVisitor::VisitObjectRangeImpl(BaseObje JSHClass *hclass = TaggedObject::Cast(root)->GetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - TaggedObject *dst = hclass->GetLayout().GetTaggedObject(); + TaggedObject *dst = hclass->GetLayout(thread).GetTaggedObject(); LayoutInfo *layout = LayoutInfo::UncheckCast(dst); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - auto attr = layout->GetAttr(index++); + auto attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { evacuator_->SetObjectRSet(slot, rootRegion); } diff --git a/ecmascript/mem/parallel_evacuator.cpp b/ecmascript/mem/parallel_evacuator.cpp index 8ded843302..3774676a9d 100644 --- a/ecmascript/mem/parallel_evacuator.cpp +++ b/ecmascript/mem/parallel_evacuator.cpp @@ -189,8 +189,9 @@ void ParallelEvacuator::EvacuateRegion(TlabAllocator *allocator, Region *region, bool pgoEnabled = heap_->GetJSThread()->IsPGOProfilerEnable(); bool inHeapProfiler = heap_->InHeapProfiler(); size_t promotedSize = 0; + auto thread = heap_->GetJSThread(); region->IterateAllMarkedBits([this, ®ion, &isInOldGen, &isBelowAgeMark, &pgoEnabled, - &promotedSize, &allocator, &trackSet, inHeapProfiler](void *mem) { + &promotedSize, &allocator, &trackSet, inHeapProfiler, &thread](void *mem) { ASSERT(region->InRange(ToUintPtr(mem))); auto header = reinterpret_cast(mem); auto klass = header->GetClass(); @@ -224,7 +225,7 @@ void ParallelEvacuator::EvacuateRegion(TlabAllocator *allocator, Region *region, } if (pgoEnabled) { if (actualPromoted && klass->IsJSArray()) { - auto trackInfo = JSArray::Cast(header)->GetTrackInfo(); + auto trackInfo = JSArray::Cast(header)->GetTrackInfo(thread); trackSet.emplace(trackInfo.GetRawData()); } } @@ -468,16 +469,17 @@ void ParallelEvacuator::UpdateNewObjectFieldVisitorheap_->GetJSThread(); JSHClass *hclass = root->GetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - TaggedObject *dst = hclass->GetLayout().GetTaggedObject(); + TaggedObject *dst = hclass->GetLayout(thread).GetTaggedObject(); LayoutInfo *layout = LayoutInfo::UncheckCast(dst); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - auto attr = layout->GetAttr(index++); + auto attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { evacuator_->UpdateNewObjectSlot(slot); } diff --git a/ecmascript/mem/parallel_evacuator_visitor-inl.h b/ecmascript/mem/parallel_evacuator_visitor-inl.h index 55a21aa418..16ff17ce92 100644 --- a/ecmascript/mem/parallel_evacuator_visitor-inl.h +++ b/ecmascript/mem/parallel_evacuator_visitor-inl.h @@ -27,6 +27,7 @@ template void SlotUpdateRangeVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t startAddr, uintptr_t endAddr, VisitObjectArea area) { + JSThread *thread = evacuator_->heap_->GetJSThread(); Region *rootRegion = Region::ObjectAddressToRange(root); ObjectSlot start(startAddr); ObjectSlot end(endAddr); @@ -34,12 +35,12 @@ void SlotUpdateRangeVisitor::VisitObjectRangeImpl(BaseObject *root, uint JSHClass *hclass = TaggedObject::Cast(root)->SynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(thread).GetTaggedObject()); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { UpdateSlot(slot, rootRegion); } @@ -67,7 +68,7 @@ void SlotUpdateRangeVisitor::UpdateSlot(ObjectSlot slot, Region *rootReg template NewToOldEvacuationVisitor::NewToOldEvacuationVisitor(Heap *heap, std::unordered_set *set, - ParallelEvacuator *evacuator) : pgoEnabled_(heap->GetJSThread()->IsPGOProfilerEnable()), + ParallelEvacuator *evacuator) : pgoEnabled_(heap->GetJSThread()->IsPGOProfilerEnable()), thread_(heap->GetJSThread()), pgoProfiler_(heap->GetEcmaVM()->GetPGOProfiler()), trackSet_(set), slotUpdateRangeVisitor_(evacuator) {} template @@ -85,7 +86,7 @@ template void NewToOldEvacuationVisitor::UpdateTrackInfo(TaggedObject *header, JSHClass *klass) { if (klass->IsJSArray()) { - auto trackInfo = JSArray::Cast(header)->GetTrackInfo(); + auto trackInfo = JSArray::Cast(header)->GetTrackInfo(thread_); trackSet_->emplace(trackInfo.GetRawData()); } } diff --git a/ecmascript/mem/parallel_evacuator_visitor.h b/ecmascript/mem/parallel_evacuator_visitor.h index dda235af32..a23903e02d 100644 --- a/ecmascript/mem/parallel_evacuator_visitor.h +++ b/ecmascript/mem/parallel_evacuator_visitor.h @@ -49,6 +49,7 @@ public: private: bool pgoEnabled_ {false}; + JSThread *thread_ {nullptr}; std::shared_ptr pgoProfiler_; std::unordered_set *trackSet_ {nullptr}; SlotUpdateRangeVisitor slotUpdateRangeVisitor_; diff --git a/ecmascript/mem/shared_heap/shared_full_gc-inl.h b/ecmascript/mem/shared_heap/shared_full_gc-inl.h index 119369bcd9..44382847b4 100644 --- a/ecmascript/mem/shared_heap/shared_full_gc-inl.h +++ b/ecmascript/mem/shared_heap/shared_full_gc-inl.h @@ -69,12 +69,12 @@ void SharedFullGCMarkObjectVisitor::VisitObjectRangeImpl(BaseObject *rootObject, JSHClass *hclass = root->SynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(THREAD_ARG_PLACEHOLDER).GetTaggedObject()); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(THREAD_ARG_PLACEHOLDER, index++); if (attr.IsTaggedRep()) { marker_->MarkValue(threadId_, slot); } diff --git a/ecmascript/mem/shared_heap/shared_gc_evacuator.cpp b/ecmascript/mem/shared_heap/shared_gc_evacuator.cpp index 3c1798fc7c..dd09ba3760 100644 --- a/ecmascript/mem/shared_heap/shared_gc_evacuator.cpp +++ b/ecmascript/mem/shared_heap/shared_gc_evacuator.cpp @@ -169,13 +169,13 @@ void SharedGCEvacuator::ObjectFieldCSetVisitor::VisitObjectRangeImpl(BaseObject JSHClass *hclass = TaggedObject::Cast(root)->GetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - TaggedObject *dst = hclass->GetLayout().GetTaggedObject(); + TaggedObject *dst = hclass->GetLayout(THREAD_ARG_PLACEHOLDER).GetTaggedObject(); LayoutInfo *layout = LayoutInfo::UncheckCast(dst); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - auto attr = layout->GetAttr(index++); + auto attr = layout->GetAttr(THREAD_ARG_PLACEHOLDER, index++); if (attr.IsTaggedRep()) { evacuator_->UpdateCrossRegionRSet(slot, rootRegion); } diff --git a/ecmascript/mem/shared_heap/shared_gc_visitor-inl.h b/ecmascript/mem/shared_heap/shared_gc_visitor-inl.h index 7a29869135..890c8ceb12 100644 --- a/ecmascript/mem/shared_heap/shared_gc_visitor-inl.h +++ b/ecmascript/mem/shared_heap/shared_gc_visitor-inl.h @@ -76,12 +76,12 @@ void SharedGCMarkObjectVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t JSHClass *hclass = TaggedObject::Cast(root)->SynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(THREAD_ARG_PLACEHOLDER).GetTaggedObject()); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(THREAD_ARG_PLACEHOLDER, index++); if (attr.IsTaggedRep()) { HandleSlot(slot, rootRegion); } diff --git a/ecmascript/mem/verification.h b/ecmascript/mem/verification.h index c370f92048..c8c0cef82e 100644 --- a/ecmascript/mem/verification.h +++ b/ecmascript/mem/verification.h @@ -178,7 +178,7 @@ private: template class VerifyVisitor final : public BaseObjectVisitor> { public: - explicit VerifyVisitor(Callback &cb) : cb_(cb) {} + explicit VerifyVisitor(Callback &cb) : thread_(JSThread::GetCurrent()), cb_(cb) {} ~VerifyVisitor() = default; void VisitObjectRangeImpl(BaseObject *root, uintptr_t startAddr, uintptr_t endAddr, VisitObjectArea area) override { @@ -189,8 +189,8 @@ public: ASSERT(!hclass->IsAllTaggedProp()); int index = 0; for (ObjectSlot slot = start; slot < end; slot++) { - auto layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - auto attr = layout->GetAttr(index++); + auto layout = LayoutInfo::Cast(hclass->GetLayout(thread_).GetTaggedObject()); + auto attr = layout->GetAttr(thread_, index++); if (attr.IsTaggedRep()) { cb_(slot, TaggedObject::Cast(root)); } @@ -202,6 +202,7 @@ public: } } private: + const JSThread *thread_; Callback &cb_; }; } // namespace panda::ecmascript diff --git a/ecmascript/mem/work_manager-inl.h b/ecmascript/mem/work_manager-inl.h index 94a066b88f..829758f3b1 100644 --- a/ecmascript/mem/work_manager-inl.h +++ b/ecmascript/mem/work_manager-inl.h @@ -139,6 +139,11 @@ TlabAllocator *WorkNodeHolder::GetTlabAllocator() const return allocator_; } +JSThread *WorkNodeHolder::GetJSThread() const +{ + return heap_->GetJSThread(); +} + WorkManagerBase::WorkManagerBase(NativeAreaAllocator *allocator) : spaceChunk_(allocator), workSpace_(0), spaceStart_(0), spaceEnd_(0) { diff --git a/ecmascript/mem/work_manager.h b/ecmascript/mem/work_manager.h index 47974487c7..31ed5be6c3 100644 --- a/ecmascript/mem/work_manager.h +++ b/ecmascript/mem/work_manager.h @@ -163,6 +163,8 @@ public: inline ProcessQueue *GetWeakReferenceQueue() const; inline TlabAllocator *GetTlabAllocator() const; + + inline JSThread *GetJSThread() const; private: Heap *heap_ {nullptr}; WorkManager *workManager_ {nullptr}; diff --git a/ecmascript/mem/young_gc_visitor-inl.h b/ecmascript/mem/young_gc_visitor-inl.h index ff397456ac..795f21d6bf 100644 --- a/ecmascript/mem/young_gc_visitor-inl.h +++ b/ecmascript/mem/young_gc_visitor-inl.h @@ -77,15 +77,16 @@ void YoungGCMarkObjectVisitor::VisitObjectRangeImpl(BaseObject *root, uintptr_t ObjectSlot start(startAddr); ObjectSlot end(endAddr); if (UNLIKELY(area == VisitObjectArea::IN_OBJECT)) { + JSThread *thread = workNodeHolder_->GetJSThread(); JSHClass *hclass = TaggedObject::Cast(root)->SynchronizedGetClass(); ASSERT(!hclass->IsAllTaggedProp()); int index = 0; - LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout().GetTaggedObject()); + LayoutInfo *layout = LayoutInfo::UncheckCast(hclass->GetLayout(thread).GetTaggedObject()); ObjectSlot realEnd = start; realEnd += layout->GetPropertiesCapacity(); end = end > realEnd ? realEnd : end; for (ObjectSlot slot = start; slot < end; slot++) { - PropertyAttributes attr = layout->GetAttr(index++); + PropertyAttributes attr = layout->GetAttr(thread, index++); if (attr.IsTaggedRep()) { HandleSlot(slot); } diff --git a/ecmascript/method.cpp b/ecmascript/method.cpp index 950fbc84af..b24dbd8ec8 100644 --- a/ecmascript/method.cpp +++ b/ecmascript/method.cpp @@ -18,21 +18,21 @@ #include "ecmascript/jspandafile/program_object.h" namespace panda::ecmascript { -std::string Method::ParseFunctionName() const +std::string Method::ParseFunctionName(const JSThread *thread) const { - const JSPandaFile *jsPandaFile = GetJSPandaFile(); + const JSPandaFile *jsPandaFile = GetJSPandaFile(thread); return MethodLiteral::ParseFunctionName(jsPandaFile, GetMethodId()); } -std::pair Method::ParseFunctionNameView() const +std::pair Method::ParseFunctionNameView(const JSThread *thread) const { - const JSPandaFile *jsPandaFile = GetJSPandaFile(); + const JSPandaFile *jsPandaFile = GetJSPandaFile(thread); return MethodLiteral::ParseFunctionNameView(jsPandaFile, GetMethodId()); } -const char *Method::GetMethodName() const +const char *Method::GetMethodName(const JSThread *thread) const { - const JSPandaFile *jsPandaFile = GetJSPandaFile(); + const JSPandaFile *jsPandaFile = GetJSPandaFile(thread); return MethodLiteral::GetMethodName(jsPandaFile, GetMethodId()); } @@ -41,21 +41,21 @@ const char *Method::GetMethodName(const JSPandaFile *file) const return MethodLiteral::GetMethodName(file, GetMethodId()); } -const CString Method::GetRecordNameStr() const +const CString Method::GetRecordNameStr(const JSThread *thread) const { - const JSPandaFile *jsPandaFile = GetJSPandaFile(); + const JSPandaFile *jsPandaFile = GetJSPandaFile(thread); return MethodLiteral::GetRecordName(jsPandaFile, GetMethodId()); } -uint32_t Method::GetCodeSize() const +uint32_t Method::GetCodeSize(const JSThread *thread) const { - const JSPandaFile *jsPandaFile = GetJSPandaFile(); + const JSPandaFile *jsPandaFile = GetJSPandaFile(thread); return MethodLiteral::GetCodeSize(jsPandaFile, GetMethodId()); } -const JSPandaFile *Method::GetJSPandaFile() const +const JSPandaFile *Method::GetJSPandaFile(const JSThread *thread) const { - JSTaggedValue constpool = GetConstantPool(); + JSTaggedValue constpool = GetConstantPool(thread); if (constpool.IsUndefined()) { return nullptr; } @@ -64,11 +64,11 @@ const JSPandaFile *Method::GetJSPandaFile() const return taggedPool->GetJSPandaFile(); } -MethodLiteral *Method::GetMethodLiteral() const +MethodLiteral *Method::GetMethodLiteral(const JSThread *thread) const { if (IsAotWithCallField() || IsDeoptimized()) { ASSERT(!IsNativeWithCallField()); - const JSPandaFile *jsPandaFile = GetJSPandaFile(); + const JSPandaFile *jsPandaFile = GetJSPandaFile(thread); ASSERT(jsPandaFile != nullptr); return jsPandaFile->FindMethodLiteral(GetMethodId().GetOffset()); } @@ -80,11 +80,11 @@ bool Method::IsDeoptimized() const return GetDeoptType() != kungfu::DeoptType::NONE; } -uint32_t Method::FindCatchBlock(uint32_t pc) const +uint32_t Method::FindCatchBlock(const JSThread *thread, uint32_t pc) const { ASSERT(!IsNativeWithCallField()); - ASSERT(GetJSPandaFile() != nullptr); - auto *pandaFile = GetJSPandaFile()->GetPandaFile(); + ASSERT(GetJSPandaFile(thread) != nullptr); + auto *pandaFile = GetJSPandaFile(thread)->GetPandaFile(); ASSERT(pandaFile != nullptr); panda_file::MethodDataAccessor mda(*pandaFile, GetMethodId()); panda_file::CodeDataAccessor cda(*pandaFile, mda.GetCodeId().value()); @@ -102,10 +102,10 @@ uint32_t Method::FindCatchBlock(uint32_t pc) const return pcOffset; } -bool Method::HasCatchBlock() const +bool Method::HasCatchBlock(const JSThread *thread) const { - ASSERT(GetJSPandaFile() != nullptr); - auto *pandaFile = GetJSPandaFile()->GetPandaFile(); + ASSERT(GetJSPandaFile(thread) != nullptr); + auto *pandaFile = GetJSPandaFile(thread)->GetPandaFile(); ASSERT(pandaFile != nullptr); panda_file::MethodDataAccessor mda(*pandaFile, GetMethodId()); panda_file::CodeDataAccessor cda(*pandaFile, mda.GetCodeId().value()); diff --git a/ecmascript/method.h b/ecmascript/method.h index 4c8d401eab..01a0ddb7f7 100644 --- a/ecmascript/method.h +++ b/ecmascript/method.h @@ -440,18 +440,18 @@ public: return sizeof(Method); } - const JSPandaFile *PUBLIC_API GetJSPandaFile() const; - uint32_t PUBLIC_API GetCodeSize() const; - MethodLiteral *PUBLIC_API GetMethodLiteral() const; + const JSPandaFile *PUBLIC_API GetJSPandaFile(const JSThread *thread) const; + uint32_t PUBLIC_API GetCodeSize(const JSThread *thread) const; + MethodLiteral *PUBLIC_API GetMethodLiteral(const JSThread *thread) const; - const char *PUBLIC_API GetMethodName() const; + const char *PUBLIC_API GetMethodName(const JSThread *thread) const; const char *PUBLIC_API GetMethodName(const JSPandaFile *file) const; - std::string PUBLIC_API ParseFunctionName() const; - std::pair PUBLIC_API ParseFunctionNameView() const; - const CString PUBLIC_API GetRecordNameStr() const; + std::string PUBLIC_API ParseFunctionName(const JSThread *thread) const; + std::pair PUBLIC_API ParseFunctionNameView(const JSThread *thread) const; + const CString PUBLIC_API GetRecordNameStr(const JSThread *thread) const; - uint32_t FindCatchBlock(uint32_t pc) const; - bool HasCatchBlock() const; + uint32_t FindCatchBlock(const JSThread *thread, uint32_t pc) const; + bool HasCatchBlock(const JSThread *thread) const; /* callfield */ static constexpr size_t VREGS_ARGS_NUM_BITS = 28; // 28: maximum 268,435,455 diff --git a/ecmascript/module/js_module_deregister.cpp b/ecmascript/module/js_module_deregister.cpp index 98040c5ffc..4bcdfe93a1 100644 --- a/ecmascript/module/js_module_deregister.cpp +++ b/ecmascript/module/js_module_deregister.cpp @@ -97,8 +97,8 @@ void ModuleDeregister::RemoveModule(JSThread *thread, JSHandle void ModuleDeregister::IncreaseRegisterCounts(JSThread *thread, JSHandle module, std::set &increaseModule) { - if (!module->GetRequestedModules().IsUndefined()) { - JSHandle requestedModules(thread, module->GetRequestedModules()); + if (!module->GetRequestedModules(thread).IsUndefined()) { + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); size_t requestedModulesLen = requestedModules->GetLength(); for (size_t idx = 0; idx < requestedModulesLen; idx++) { JSHandle requiredModule = @@ -134,8 +134,8 @@ void ModuleDeregister::IncreaseRegisterCounts(JSThread *thread, JSHandle module, std::set &decreaseModule) { - if (!module->GetRequestedModules().IsUndefined()) { - JSHandle requestedModules(thread, module->GetRequestedModules()); + if (!module->GetRequestedModules(thread).IsUndefined()) { + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); size_t requestedModulesLen = requestedModules->GetLength(); for (size_t idx = 0; idx < requestedModulesLen; idx++) { JSHandle requiredModule = diff --git a/ecmascript/module/js_module_deregister.h b/ecmascript/module/js_module_deregister.h index d2bdca1077..d9051638d7 100644 --- a/ecmascript/module/js_module_deregister.h +++ b/ecmascript/module/js_module_deregister.h @@ -37,7 +37,7 @@ public: static inline void ProcessModuleReference(JSThread *thread, const JSHandle &nameSpVal) { JSHandle nameSp = JSHandle::Cast(nameSpVal); - JSHandle moduleRecord(thread, nameSp->GetModule()); + JSHandle moduleRecord(thread, nameSp->GetModule(thread)); JSTaggedValue weakNameSp = JSTaggedValue(nameSpVal->CreateAndGetWeakRef()); moduleRecord->SetNamespace(thread, weakNameSp); } diff --git a/ecmascript/module/js_module_manager.cpp b/ecmascript/module/js_module_manager.cpp index 93d830c05b..3922062c2c 100644 --- a/ecmascript/module/js_module_manager.cpp +++ b/ecmascript/module/js_module_manager.cpp @@ -36,35 +36,36 @@ JSHandle ModuleManager::GenerateSendableFuncModule(const JSHandle return SendableClassModule::GenerateSendableFuncModule(vm_->GetJSThread(), module); } -bool ModuleManager::CheckModuleValueOutterResolved(int32_t index, JSFunction *jsFunc) +bool ModuleManager::CheckModuleValueOutterResolved(JSThread *thread, int32_t index, JSFunction *jsFunc) { // check module resolved, if resolved, load var from module directly for jit compiled code. ASSERT(jsFunc != nullptr); - JSTaggedValue currentModule = jsFunc->GetModule(); + JSTaggedValue currentModule = jsFunc->GetModule(thread); if (!currentModule.IsSourceTextModule()) { return false; } if (SourceTextModule::IsSendableFunctionModule(currentModule)) { return false; } - JSTaggedValue moduleEnv = reinterpret_cast(currentModule.GetTaggedObject())->GetEnvironment(); + JSTaggedValue moduleEnv = + reinterpret_cast(currentModule.GetTaggedObject())->GetEnvironment(thread); if (!moduleEnv.IsTaggedArray()) { return false; } - - JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnv.GetTaggedObject())->Get(index); + JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnv.GetTaggedObject())->Get(thread, index); if (!resolvedBinding.IsResolvedIndexBinding()) { return false; } ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject()); - SourceTextModule *resolvedModule = reinterpret_cast(binding->GetModule().GetTaggedObject()); + SourceTextModule *resolvedModule = reinterpret_cast( + binding->GetModule(thread).GetTaggedObject()); ModuleTypes moduleType = resolvedModule->GetTypes(); if (moduleType != ModuleTypes::ECMA_MODULE) { return false; } - JSTaggedValue resolvedModuleDict = resolvedModule->GetNameDictionary(); + JSTaggedValue resolvedModuleDict = resolvedModule->GetNameDictionary(thread); if (!resolvedModuleDict.IsTaggedArray()) { return false; } @@ -81,21 +82,21 @@ JSTaggedValue ModuleManager::GetExternalModuleVarFastPathForJIT(JSThread *thread return JSTaggedValue::Hole(); } - JSTaggedValue currentModule = jsFunc->GetModule(); + JSTaggedValue currentModule = jsFunc->GetModule(thread); ASSERT(currentModule.IsSourceTextModule()); JSTaggedValue moduleEnvironment = - reinterpret_cast(currentModule.GetTaggedObject())->GetEnvironment(); + reinterpret_cast(currentModule.GetTaggedObject())->GetEnvironment(thread); ASSERT(moduleEnvironment.IsTaggedArray()); - JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnvironment.GetTaggedObject())->Get(index); + JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnvironment.GetTaggedObject())->Get(thread, index); ASSERT(resolvedBinding.IsResolvedIndexBinding()); ResolvedIndexBinding *binding = ResolvedIndexBinding::Cast(resolvedBinding.GetTaggedObject()); - JSTaggedValue resolvedModule = binding->GetModule(); + JSTaggedValue resolvedModule = binding->GetModule(thread); int32_t bindingIndex = binding->GetIndex(); ASSERT(resolvedModule.IsSourceTextModule()); JSTaggedValue dictionary = - reinterpret_cast(resolvedModule.GetTaggedObject())->GetNameDictionary(); + reinterpret_cast(resolvedModule.GetTaggedObject())->GetNameDictionary(thread); TaggedArray *array = TaggedArray::Cast(dictionary.GetTaggedObject()); - return array->Get(bindingIndex); + return array->Get(thread, bindingIndex); } JSHandle ModuleManager::GetImportedModule(const CString &referencing) @@ -215,11 +216,11 @@ void ModuleManager::Iterate(RootVisitor &v) } } -CString ModuleManager::GetRecordName(JSTaggedValue module) +CString ModuleManager::GetRecordName(const JSThread *thread, JSTaggedValue module) { CString entry = ""; if (module.IsString()) { - entry = ModulePathHelper::Utf8ConvertToString(module); + entry = ModulePathHelper::Utf8ConvertToString(const_cast(thread), module); } if (module.IsSourceTextModule()) { SourceTextModule *sourceTextModule = SourceTextModule::Cast(module.GetTaggedObject()); @@ -235,7 +236,7 @@ int ModuleManager::GetExportObjectIndex(EcmaVM *vm, JSHandle e const CString &key) { JSThread *thread = vm->GetJSThread(); - if (ecmaModule->GetLocalExportEntries().IsUndefined()) { + if (ecmaModule->GetLocalExportEntries(thread).IsUndefined()) { CString msg = "No export named '" + key; if (!ecmaModule->GetEcmaModuleRecordNameString().empty()) { msg += "' which exported by '" + ecmaModule->GetEcmaModuleRecordNameString() + "'"; @@ -247,15 +248,15 @@ int ModuleManager::GetExportObjectIndex(EcmaVM *vm, JSHandle e StackCheck::NO).GetTaggedValue(); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, 0); } - JSHandle localExportEntries(thread, ecmaModule->GetLocalExportEntries()); + JSHandle localExportEntries(thread, ecmaModule->GetLocalExportEntries(thread)); size_t exportEntriesLen = localExportEntries->GetLength(); // 0: There's only one export value "default" int index = 0; JSMutableHandle ee(thread, thread->GlobalConstants()->GetUndefined()); if (exportEntriesLen > 1) { // 1: The number of export objects exceeds 1 for (size_t idx = 0; idx < exportEntriesLen; idx++) { - ee.Update(localExportEntries->Get(idx)); - if (EcmaStringAccessor(ee->GetExportName()).Utf8ConvertToString() == key) { + ee.Update(localExportEntries->Get(thread, idx)); + if (EcmaStringAccessor(ee->GetExportName(thread)).Utf8ConvertToString(thread) == key) { ASSERT(idx <= static_cast(INT_MAX)); index = static_cast(ee->GetLocalIndex()); break; diff --git a/ecmascript/module/js_module_manager.h b/ecmascript/module/js_module_manager.h index 0e6295b48e..9b0800deab 100644 --- a/ecmascript/module/js_module_manager.h +++ b/ecmascript/module/js_module_manager.h @@ -73,7 +73,7 @@ public: isExecuteBuffer_.store(mode, std::memory_order_release); } - static CString PUBLIC_API GetRecordName(JSTaggedValue module); + static CString PUBLIC_API GetRecordName(const JSThread *thread, JSTaggedValue module); static int GetExportObjectIndex(EcmaVM *vm, JSHandle ecmaModule, const CString &key); uint32_t NextModuleAsyncEvaluatingOrdinal() @@ -110,7 +110,7 @@ public: void SyncModuleExecuteMode(JSThread *thread); // fast path ldexternalmodulevar for jit - static bool CheckModuleValueOutterResolved(int32_t index, JSFunction *jsFunc); + static bool CheckModuleValueOutterResolved(JSThread *thread, int32_t index, JSFunction *jsFunc); static JSTaggedValue GetExternalModuleVarFastPathForJIT(JSThread *thread, int32_t index, JSFunction *jsFunc); private: diff --git a/ecmascript/module/js_module_namespace.cpp b/ecmascript/module/js_module_namespace.cpp index e5900ea8de..069a62bcab 100644 --- a/ecmascript/module/js_module_namespace.cpp +++ b/ecmascript/module/js_module_namespace.cpp @@ -88,7 +88,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandle moduleNamespace = JSHandle::Cast(obj); // 3. Let exports be O.[[Exports]]. - JSHandle exports(thread, moduleNamespace->GetExports()); + JSHandle exports(thread, moduleNamespace->GetExports(thread)); // 4. If P is not an element of exports, return undefined. if (exports->IsUndefined()) { return OperationResult(thread, thread->GlobalConstants()->GetUndefined(), PropertyMetaData(false)); @@ -100,7 +100,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandleGlobalConstants()->GetUndefined(), PropertyMetaData(false)); } // 5. Let m be O.[[Module]]. - JSHandle mm(thread, moduleNamespace->GetModule()); + JSHandle mm(thread, moduleNamespace->GetModule(thread)); // 6. Let binding be ! m.ResolveExport(P, « »). ResolvedMultiMap resolvedMap; JSHandle binding = SourceTextModule::ResolveExport(thread, mm, key, resolvedMap); @@ -111,7 +111,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandleIsNull() || binding->IsString()) { // LCOV_EXCL_BR_LINE CString requestMod = ModulePathHelper::ReformatPath(mm->GetEcmaModuleFilenameString()); LOG_FULL(FATAL) << "Module: '" << requestMod << SourceTextModule::GetResolveErrorReason(binding) << - ConvertToString(key.GetTaggedValue()) << "."; + ConvertToString(thread, key.GetTaggedValue()) << "."; } JSTaggedValue result; // 8. Let targetModule be binding.[[Module]]. @@ -119,7 +119,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandle resolvedBind = JSHandle::Cast(binding); - JSTaggedValue targetModule = resolvedBind->GetModule(); + JSTaggedValue targetModule = resolvedBind->GetModule(thread); // 9. Assert: targetModule is not undefined. ASSERT(!targetModule.IsUndefined()); JSHandle module(thread, targetModule); @@ -129,17 +129,18 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandleGetTypes(); if (UNLIKELY(SourceTextModule::IsNativeModule(moduleType))) { - result = ModuleValueAccessor::GetNativeOrCjsModuleValue(thread, module, resolvedBind->GetBindingName()); + result = ModuleValueAccessor::GetNativeOrCjsModuleValue(thread, module, + resolvedBind->GetBindingName(thread)); RETURN_VALUE_IF_ABRUPT_COMPLETION( thread, OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } else { - result = module->GetModuleValue(thread, resolvedBind->GetBindingName(), true); + result = module->GetModuleValue(thread, resolvedBind->GetBindingName(thread), true); } break; } case JSType::RESOLVEDINDEXBINDING_RECORD: { JSHandle resolvedBind = JSHandle::Cast(binding); - JSTaggedValue targetModule = resolvedBind->GetModule(); + JSTaggedValue targetModule = resolvedBind->GetModule(thread); // 9. Assert: targetModule is not undefined. ASSERT(!targetModule.IsUndefined()); JSHandle module(thread, targetModule); @@ -174,7 +175,7 @@ JSHandle ModuleNamespace::OwnPropertyKeys(JSThread *thread, const J ASSERT(obj->IsModuleNamespace()); // 1. Let exports be a copy of O.[[Exports]]. JSHandle moduleNamespace = JSHandle::Cast(obj); - JSHandle exports(thread, moduleNamespace->GetExports()); + JSHandle exports(thread, moduleNamespace->GetExports(thread)); JSHandle exportsArray = JSArray::ToTaggedArray(thread, exports); if (!ModuleNamespace::ValidateKeysAvailable(thread, moduleNamespace, exportsArray)) { return exportsArray; @@ -193,7 +194,7 @@ JSHandle ModuleNamespace::OwnEnumPropertyKeys(JSThread *thread, con ASSERT(obj->IsModuleNamespace()); // 1. Let exports be a copy of O.[[Exports]]. JSHandle moduleNamespace = JSHandle::Cast(obj); - JSHandle exports(thread, moduleNamespace->GetExports()); + JSHandle exports(thread, moduleNamespace->GetExports(thread)); JSHandle exportsArray = JSArray::ToTaggedArray(thread, exports); if (!ModuleNamespace::ValidateKeysAvailable(thread, moduleNamespace, exportsArray)) { return exportsArray; @@ -251,7 +252,7 @@ bool ModuleNamespace::DefineOwnProperty(JSThread *thread, if (desc.HasValue()) { JSHandle descValue = desc.GetValue(); JSHandle currentValue = current.GetValue(); - return JSTaggedValue::SameValue(descValue, currentValue); + return JSTaggedValue::SameValue(thread, descValue, currentValue); } // 9. Return true. @@ -268,7 +269,7 @@ bool ModuleNamespace::HasProperty(JSThread *thread, const JSHandle moduleNamespace = JSHandle::Cast(obj); - JSHandle exports(thread, moduleNamespace->GetExports()); + JSHandle exports(thread, moduleNamespace->GetExports(thread)); // 3. If P is an element of exports, return true. if (exports->IsUndefined()) { return false; @@ -298,7 +299,7 @@ bool ModuleNamespace::GetOwnProperty(JSThread *thread, const JSHandle moduleNamespace = JSHandle::Cast(obj); - JSHandle exports(thread, moduleNamespace->GetExports()); + JSHandle exports(thread, moduleNamespace->GetExports(thread)); // 3. If P is not an element of exports, return undefined. if (exports->IsUndefined()) { return false; @@ -339,7 +340,7 @@ bool ModuleNamespace::DeleteProperty(JSThread *thread, const JSHandle moduleNamespace = JSHandle::Cast(obj); - JSHandle exports(thread, moduleNamespace->GetExports()); + JSHandle exports(thread, moduleNamespace->GetExports(thread)); // 4. If P is an element of exports, return false. if (exports->IsUndefined()) { return true; @@ -354,10 +355,10 @@ bool ModuleNamespace::DeleteProperty(JSThread *thread, const JSHandle &moduleNamespace, const JSHandle &exports) { - JSHandle mm(thread, moduleNamespace->GetModule()); + JSHandle mm(thread, moduleNamespace->GetModule(thread)); uint32_t exportsLength = exports->GetLength(); for (uint32_t idx = 0; idx < exportsLength; idx++) { - JSHandle key(thread, exports->Get(idx)); + JSHandle key(thread, exports->Get(thread, idx)); ResolvedMultiMap resolvedMap; JSHandle binding = SourceTextModule::ResolveExport(thread, mm, key, resolvedMap); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -365,12 +366,12 @@ bool ModuleNamespace::ValidateKeysAvailable(JSThread *thread, const JSHandleIsResolvedBinding() || binding->IsResolvedIndexBinding()); JSTaggedValue targetModule = JSTaggedValue::Undefined(); if (binding->IsResolvedBinding()) { - targetModule = JSHandle::Cast(binding)->GetModule(); + targetModule = JSHandle::Cast(binding)->GetModule(thread); } else if (binding->IsResolvedIndexBinding()) { - targetModule = JSHandle::Cast(binding)->GetModule(); + targetModule = JSHandle::Cast(binding)->GetModule(thread); } ASSERT(!targetModule.IsUndefined()); - JSTaggedValue dictionary = SourceTextModule::Cast(targetModule.GetTaggedObject())->GetNameDictionary(); + JSTaggedValue dictionary = SourceTextModule::Cast(targetModule.GetTaggedObject())->GetNameDictionary(thread); if (dictionary.IsUndefined()) { THROW_REFERENCE_ERROR_AND_RETURN(thread, "module environment is undefined", false); } @@ -383,7 +384,7 @@ void ModuleNamespace::SetModuleDeregisterProcession(JSThread *thread, const JSHa { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle module(thread, nameSpace->GetModule()); + JSHandle module(thread, nameSpace->GetModule(thread)); CString moduleStr = SourceTextModule::GetModuleName(module.GetTaggedValue()); int srcLength = strlen(moduleStr.c_str()) + 1; auto moduleNameData = thread->GetEcmaVM()->GetNativeAreaAllocator()->AllocateBuffer(srcLength); @@ -393,7 +394,7 @@ void ModuleNamespace::SetModuleDeregisterProcession(JSThread *thread, const JSHa } char *tmpData = reinterpret_cast(moduleNameData); tmpData[srcLength - 1] = '\0'; - ASSERT(nameSpace->GetDeregisterProcession().IsUndefined()); + ASSERT(nameSpace->GetDeregisterProcession(thread).IsUndefined()); JSHandle registerPointer = factory->NewJSNativePointer( reinterpret_cast(moduleNameData), callback, reinterpret_cast(thread), false, srcLength); nameSpace->SetDeregisterProcession(thread, registerPointer.GetTaggedValue()); diff --git a/ecmascript/module/js_module_source_text.cpp b/ecmascript/module/js_module_source_text.cpp index e82877f2e5..bc9c13df17 100644 --- a/ecmascript/module/js_module_source_text.cpp +++ b/ecmascript/module/js_module_source_text.cpp @@ -41,7 +41,7 @@ CVector SourceTextModule::GetExportedNames(JSThread *thread, const CVector exportedNames; // 1. Let module be this Source Text Module Record. // 2. If exportStarSet contains module, then - if (exportStarSet->GetIdx(module.GetTaggedValue()) != TaggedArray::MAX_ARRAY_INDEX) { + if (exportStarSet->GetIdx(thread, module.GetTaggedValue()) != TaggedArray::MAX_ARRAY_INDEX) { // a. Assert: We've reached the starting point of an import * circularity. // b. Return a new empty List. return exportedNames; @@ -51,24 +51,24 @@ CVector SourceTextModule::GetExportedNames(JSThread *thread, const JSHandle newExportStarSet = TaggedArray::SetCapacity(thread, exportStarSet, len + 1); newExportStarSet->Set(thread, len, module.GetTaggedValue()); - JSTaggedValue entryValue = module->GetLocalExportEntries(); + JSTaggedValue entryValue = module->GetLocalExportEntries(thread); // 5. For each ExportEntry Record e in module.[[LocalExportEntries]], do AddExportName(thread, entryValue, exportedNames); // 6. For each ExportEntry Record e in module.[[IndirectExportEntries]], do - entryValue = module->GetIndirectExportEntries(); + entryValue = module->GetIndirectExportEntries(thread); AddExportName(thread, entryValue, exportedNames); - entryValue = module->GetStarExportEntries(); + entryValue = module->GetStarExportEntries(thread); auto globalConstants = thread->GlobalConstants(); if (!entryValue.IsUndefined()) { JSMutableHandle ee(thread, globalConstants->GetUndefined()); - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); // 7. For each ExportEntry Record e in module.[[StarExportEntries]], do JSHandle starExportEntries(thread, entryValue); size_t starExportEntriesLen = starExportEntries->GetLength(); for (size_t idx = 0; idx < starExportEntriesLen; idx++) { - ee.Update(starExportEntries->Get(idx)); + ee.Update(starExportEntries->Get(thread, idx)); // a. Let requestedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). JSHandle requestedModule = GetRequestedModuleFromCache(thread, requestedModules, ee->GetModuleRequestIndex()); @@ -80,7 +80,8 @@ CVector SourceTextModule::GetExportedNames(JSThread *thread, const return exportedNames; } -bool SourceTextModule::CheckCircularImport(const JSHandle &module, +bool SourceTextModule::CheckCircularImport(JSThread *thread, + const JSHandle &module, const JSHandle &exportName, ResolvedMultiMap &resolvedMap) { @@ -92,7 +93,7 @@ bool SourceTextModule::CheckCircularImport(const JSHandle &mod auto name = iter->second; // a. If module and r.[[Module]] are the same Module Record and // SameValue(exportName, r.[[ExportName]]) is true, then - if (JSTaggedValue::StringCompare(EcmaString::Cast(name.GetTaggedValue().GetTaggedObject()), + if (JSTaggedValue::StringCompare(thread, EcmaString::Cast(name.GetTaggedValue().GetTaggedObject()), EcmaString::Cast(exportName.GetTaggedValue().GetTaggedObject()))) { // i. Assert: This is a circular import request. // ii. Return true. @@ -112,7 +113,7 @@ JSHandle SourceTextModule::ResolveExportObject(JSThread *thread, ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // For CJS, if exports is not JSObject, means the CJS module use default output JSHandle defaultString = globalConstants->GetHandledDefaultString(); - if (JSTaggedValue::SameValueString(exportName, defaultString)) { + if (JSTaggedValue::SameValueString(thread, exportName, defaultString)) { // bind with a number return JSHandle::Cast(factory->NewResolvedIndexBindingRecord(module, -1)); } @@ -122,17 +123,17 @@ JSHandle SourceTextModule::ResolveExportObject(JSThread *thread, if (exports->IsJSObject()) { JSHandle resolution(thread, JSTaggedValue::Hole()); JSObject *exportObject = JSObject::Cast(exports.GetTaggedValue().GetTaggedObject()); - TaggedArray *properties = TaggedArray::Cast(exportObject->GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(exportObject->GetProperties(thread).GetTaggedObject()); if (!properties->IsDictionaryMode()) { JSHandle jsHclass(thread, exportObject->GetJSHClass()); // Get layoutInfo and compare the input and output names of files - LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout(thread).GetTaggedObject()); if (layoutInfo->NumberOfElements() != 0) { resolution = ResolveElementOfObject(thread, jsHclass, exportName, module); } } else { NameDictionary *dict = NameDictionary::Cast(properties); - int entry = dict->FindEntry(exportName.GetTaggedValue()); + int entry = dict->FindEntry(thread, exportName.GetTaggedValue()); if (entry != -1) { resolution = JSHandle::Cast(factory->NewResolvedIndexBindingRecord(module, entry)); } @@ -181,13 +182,13 @@ JSHandle SourceTextModule::ResolveExport(JSThread *thread, auto globalConstants = thread->GlobalConstants(); // Check if circular import request. // 2.For each Record { [[Module]], [[ExportName]] } r in resolvedMap, do - if (CheckCircularImport(module, exportName, resolvedMap)) { + if (CheckCircularImport(thread, module, exportName, resolvedMap)) { return globalConstants->GetHandledNull(); } // 3. Append the Record { [[Module]]: module, [[ExportName]]: exportName } to resolvedMap. resolvedMap.emplace(reinterpret_cast(GetModuleName(module)), exportName); // 4. For each ExportEntry Record e in module.[[LocalExportEntries]], do - JSHandle localExportEntriesTv(thread, module->GetLocalExportEntries()); + JSHandle localExportEntriesTv(thread, module->GetLocalExportEntries(thread)); if (!localExportEntriesTv->IsUndefined()) { JSHandle resolution = ResolveLocalExport(thread, localExportEntriesTv, exportName, module); if (!resolution->IsUndefined()) { @@ -195,7 +196,7 @@ JSHandle SourceTextModule::ResolveExport(JSThread *thread, } } // 5. For each ExportEntry Record e in module.[[IndirectExportEntries]], do - JSHandle indirectExportEntriesTv(thread, module->GetIndirectExportEntries()); + JSHandle indirectExportEntriesTv(thread, module->GetIndirectExportEntries(thread)); if (!indirectExportEntriesTv->IsUndefined()) { JSHandle resolution = ResolveIndirectExport(thread, indirectExportEntriesTv, exportName, module, resolvedMap); @@ -206,7 +207,7 @@ JSHandle SourceTextModule::ResolveExport(JSThread *thread, } // 6. If SameValue(exportName, "default") is true, then JSHandle defaultString = globalConstants->GetHandledDefaultString(); - if (JSTaggedValue::SameValueString(exportName, defaultString)) { + if (JSTaggedValue::SameValueString(thread, exportName, defaultString)) { // a. Assert: A default export was not explicitly defined by this module. // b. Return null. // c. NOTE: A default export cannot be provided by an export *. @@ -215,16 +216,16 @@ JSHandle SourceTextModule::ResolveExport(JSThread *thread, // 7. Let starResolution be null. JSMutableHandle starResolution(thread, globalConstants->GetNull()); // 8. For each ExportEntry Record e in module.[[StarExportEntries]], do - JSTaggedValue starExportEntriesTv = module->GetStarExportEntries(); + JSTaggedValue starExportEntriesTv = module->GetStarExportEntries(thread); if (starExportEntriesTv.IsUndefined()) { return starResolution; } JSMutableHandle ee(thread, globalConstants->GetUndefined()); - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); JSHandle starExportEntries(thread, starExportEntriesTv); size_t starExportEntriesLen = starExportEntries->GetLength(); for (size_t idx = 0; idx < starExportEntriesLen; idx++) { - ee.Update(starExportEntries->Get(idx)); + ee.Update(starExportEntries->Get(thread, idx)); // a. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). JSHandle requestedModule = GetRequestedModuleFromCache(thread, requestedModules, ee->GetModuleRequestIndex()); @@ -491,15 +492,16 @@ int SourceTextModule::Instantiate(JSThread *thread, const JSHandle> SourceTextModule::GetConcurrentRequestedModules(const JSHandle &method) +std::optional> SourceTextModule::GetConcurrentRequestedModules(JSThread *thread, + const JSHandle &method) { - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); - const MethodLiteral *methodLiteral = method->GetMethodLiteral(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); + const MethodLiteral *methodLiteral = method->GetMethodLiteral(thread); ASSERT(methodLiteral != nullptr); return methodLiteral->GetConcurrentRequestedModules(jsPandaFile); } -void SourceTextModule::DFSModuleInstantiation(JSHandle &module, +void SourceTextModule::DFSModuleInstantiation(JSThread *thread, JSHandle &module, CVector> &stack) { // 1. Assert: module occurs exactly once in stack. @@ -520,7 +522,7 @@ void SourceTextModule::DFSModuleInstantiation(JSHandle &module // iii. Set requiredModule.[[Status]] to "instantiated". requiredModule->SetStatus(ModuleStatus::INSTANTIATED); // iv. If requiredModule and module are the same Module Record, set done to true. - if (JSTaggedValue::SameValue(module.GetTaggedValue(), requiredModule.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, module.GetTaggedValue(), requiredModule.GetTaggedValue())) { done = true; } } @@ -543,14 +545,14 @@ bool SourceTextModule::PreModuleInstantiation(JSThread *thread, return true; } module->SetStatus(ModuleStatus::PREINSTANTIATING); - JSHandle moduleRequests(thread, module->GetModuleRequests()); + JSHandle moduleRequests(thread, module->GetModuleRequests(thread)); // 9. For each String required that is an element of module.[[RequestedModules]], do if (!moduleRequests.GetTaggedValue().IsUndefined()) { - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); size_t moduleRequestsLen = moduleRequests->GetLength(); JSMutableHandle required(thread, thread->GlobalConstants()->GetUndefined()); for (size_t idx = 0; idx < moduleRequestsLen; idx++) { - required.Update(moduleRequests->Get(idx)); + required.Update(moduleRequests->Get(thread, idx)); JSHandle requiredModule = ModuleResolver::HostResolveImportedModule(thread, module, required, executeType); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -595,8 +597,8 @@ int SourceTextModule::FinishModuleInstantiation(JSThread *thread, JSHandleGetRequestedModules().IsUndefined()) { - JSHandle requestedModules(thread, module->GetRequestedModules()); + if (!module->GetRequestedModules(thread).IsUndefined()) { + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); size_t requestedModulesLen = requestedModules->GetLength(); for (size_t idx = 0; idx < requestedModulesLen; idx++) { JSHandle moduleHdl = @@ -630,7 +632,7 @@ int SourceTextModule::FinishModuleInstantiation(JSThread *thread, JSHandle &module) { CheckResolvedBinding(thread, module); - if (module->GetImportEntries().IsUndefined()) { + if (module->GetImportEntries(thread).IsUndefined()) { return; } ASSERT(!SourceTextModule::IsSharedModule(module)); @@ -646,32 +648,32 @@ void SourceTextModule::ModuleDeclarationEnvironmentSetup(JSThread *thread, // 3. Let realm be module.[[Realm]]. // 4. Assert: realm is not undefined. // 5. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). - JSHandle importEntries(thread, module->GetImportEntries()); + JSHandle importEntries(thread, module->GetImportEntries(thread)); size_t importEntriesLen = importEntries->GetLength(); JSHandle map(NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(importEntriesLen))); // 6. Set module.[[Environment]] to env. module->SetEnvironment(thread, map); // 7. Let envRec be env's EnvironmentRecord. - JSMutableHandle envRec(thread, module->GetEnvironment()); + JSMutableHandle envRec(thread, module->GetEnvironment(thread)); ASSERT(!envRec->IsUndefined()); // 8. For each ImportEntry Record in in module.[[ImportEntries]], do - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); auto globalConstants = thread->GlobalConstants(); JSMutableHandle in(thread, globalConstants->GetUndefined()); JSMutableHandle importName(thread, globalConstants->GetUndefined()); JSMutableHandle localName(thread, globalConstants->GetUndefined()); for (size_t idx = 0; idx < importEntriesLen; idx++) { - in.Update(importEntries->Get(idx)); - localName.Update(in->GetLocalName()); - importName.Update(in->GetImportName()); + in.Update(importEntries->Get(thread, idx)); + localName.Update(in->GetLocalName(thread)); + importName.Update(in->GetImportName(thread)); // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). JSHandle importedModule = JSHandle::Cast( GetRequestedModuleFromCache(thread, requestedModules, in->GetModuleRequestIndex())); ASSERT(importedModule.GetTaggedValue().IsSourceTextModule()); // c. If in.[[ImportName]] is "*", then JSHandle starString = globalConstants->GetHandledStarString(); - if (JSTaggedValue::SameValueString(importName, starString)) { + if (JSTaggedValue::SameValueString(thread, importName, starString)) { // i. Let namespace be ? GetModuleNamespace(importedModule). JSHandle moduleNamespace = SourceTextModule::GetModuleNamespace(thread, importedModule); // ii. Perform ! envRec.CreateImmutableBinding(in.[[LocalName]], true). @@ -690,7 +692,7 @@ void SourceTextModule::ModuleDeclarationEnvironmentSetup(JSThread *thread, if (resolution->IsNull() || resolution->IsString()) { CString requestMod = ModulePathHelper::ReformatPath(GetModuleName(importedModule.GetTaggedValue())); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + - ConvertToString(importName.GetTaggedValue()); + ConvertToString(thread, importName.GetTaggedValue()); if (!module->GetEcmaModuleRecordNameString().empty()) { CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); msg += "' which imported by '" + recordStr + "'"; @@ -720,7 +722,7 @@ void SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(JSThread *thread, return; } CheckResolvedIndexBinding(thread, module); - if (module->GetImportEntries().IsUndefined()) { + if (module->GetImportEntries(thread).IsUndefined()) { return; } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -729,26 +731,26 @@ void SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(JSThread *thread, // 3. Let realm be module.[[Realm]]. // 4. Assert: realm is not undefined. // 5. Let env be NewModuleEnvironment(realm.[[GlobalEnv]]). - JSHandle importEntries(thread, module->GetImportEntries()); + JSHandle importEntries(thread, module->GetImportEntries(thread)); size_t importEntriesLen = importEntries->GetLength(); JSHandle arr = factory->NewTaggedArray(importEntriesLen); // 7. Let envRec be env's EnvironmentRecord. JSHandle envRec = arr; // 8. For each ImportEntry Record in in module.[[ImportEntries]], do - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); auto globalConstants = thread->GlobalConstants(); JSMutableHandle in(thread, globalConstants->GetUndefined()); JSMutableHandle importName(thread, globalConstants->GetUndefined()); for (size_t idx = 0; idx < importEntriesLen; idx++) { - in.Update(importEntries->Get(idx)); - importName.Update(in->GetImportName()); + in.Update(importEntries->Get(thread, idx)); + importName.Update(in->GetImportName(thread)); // a. Let importedModule be ! HostResolveImportedModule(module, in.[[ModuleRequest]]). JSHandle importedModule = GetRequestedModuleFromCache(thread, requestedModules, in->GetModuleRequestIndex()); ASSERT(importedModule.GetTaggedValue().IsSourceTextModule()); // c. If in.[[ImportName]] is "*", then JSHandle starString = globalConstants->GetHandledStarString(); - if (JSTaggedValue::SameValueString(importName, starString)) { + if (JSTaggedValue::SameValueString(thread, importName, starString)) { // need refactor envRec = JSSharedModule::CloneEnvForSModule(thread, module, envRec); module->SetEnvironment(thread, envRec); @@ -763,7 +765,7 @@ void SourceTextModule::ModuleDeclarationArrayEnvironmentSetup(JSThread *thread, if (resolution->IsNull() || resolution->IsString()) { CString requestMod = ModulePathHelper::ReformatPath(GetModuleName(importedModule.GetTaggedValue())); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + - ConvertToString(importName.GetTaggedValue()); + ConvertToString(thread, importName.GetTaggedValue()); if (!module->GetEcmaModuleRecordNameString().empty()) { CString recordStr = ModulePathHelper::ReformatPath( module->GetEcmaModuleRecordNameString()); @@ -789,7 +791,7 @@ JSHandle SourceTextModule::GetModuleNamespace(JSThread *thread, // 2. Assert: module.[[Status]] is not "uninstantiated". ASSERT(module->GetStatus() != ModuleStatus::UNINSTANTIATED); // 3. Let namespace be module.[[Namespace]]. - JSMutableHandle moduleNamespace(thread, module->GetNamespace().GetWeakRawValue()); + JSMutableHandle moduleNamespace(thread, module->GetNamespace(thread).GetWeakRawValue()); // If namespace is undefined, then if (moduleNamespace->IsUndefined()) { // a. Let exportedNames be ? module.GetExportedNames(« »). @@ -866,7 +868,7 @@ JSTaggedValue SourceTextModule::Evaluate(JSThread *thread, const JSHandleGetCycleRoot()); + module.Update(module->GetCycleRoot(thread)); } // 4. If module.[[TopLevelCapability]] is not EMPTY, then // a. Return module.[[TopLevelCapability]].[[Promise]]. @@ -939,8 +941,8 @@ int SourceTextModule::InnerModuleEvaluationUnsafe(JSThread *thread, JSHandleGetModuleLogger(); - if (!module->GetRequestedModules().IsUndefined()) { - JSHandle requestedModules(thread, module->GetRequestedModules()); + if (!module->GetRequestedModules(thread).IsUndefined()) { + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); size_t requestedModulesLen = requestedModules->GetLength(); JSHandle requiredModule; for (size_t idx = 0; idx < requestedModulesLen; idx++) { @@ -980,12 +982,12 @@ int SourceTextModule::InnerModuleEvaluationUnsafe(JSThread *thread, JSHandleGetDFSAncestorIndex(), requiredModule->GetDFSAncestorIndex()); module->SetDFSAncestorIndex(dfsAncIdx); } else { - requiredModule = JSHandle(thread, requiredModule->GetCycleRoot()); + requiredModule = JSHandle(thread, requiredModule->GetCycleRoot(thread)); requiredModuleStatus = requiredModule->GetStatus(); ASSERT(requiredModuleStatus >= ModuleStatus::EVALUATING_ASYNC); if (requiredModuleStatus == ModuleStatus::ERRORED) { errorStack.emplace_back(module); - SetExceptionToModule(thread, module, requiredModule->GetException()); + SetExceptionToModule(thread, module, requiredModule->GetException(thread)); ModuleMessageHelper::PrintAndThrowError(thread, module); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, index); return index; @@ -1040,7 +1042,7 @@ int SourceTextModule::InnerModuleEvaluationUnsafe(JSThread *thread, JSHandleSetStatus(ModuleStatus::EVALUATING_ASYNC); } // vi. If requiredModule and module are the same Module Record, set done to true. - if (JSTaggedValue::SameValue(module.GetTaggedValue(), requiredModule.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, module.GetTaggedValue(), requiredModule.GetTaggedValue())) { done = true; } // vii. Set requiredModule.[[CycleRoot]] to module. @@ -1131,11 +1133,11 @@ void SourceTextModule::HandleConcurrentEvaluateResult(JSThread *thread, JSHandle int SourceTextModule::ModuleEvaluation(JSThread *thread, const JSHandle &module, int index, const JSHandle &method) { - if (!module->GetRequestedModules().IsUndefined()) { - JSHandle requestedModules(thread, module->GetRequestedModules()); + if (!module->GetRequestedModules(thread).IsUndefined()) { + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); size_t requestedModulesLen = requestedModules->GetLength(); JSMutableHandle required(thread, thread->GlobalConstants()->GetUndefined()); - auto coRequestedModules = GetConcurrentRequestedModules(method); + auto coRequestedModules = GetConcurrentRequestedModules(thread, method); for (size_t idx = 0; idx < requestedModulesLen; idx++) { if (coRequestedModules.has_value() && coRequestedModules.value().count(idx) == 0) { // skip the unused module @@ -1201,7 +1203,7 @@ void SourceTextModule::AddImportEntry(JSThread *thread, const JSHandle &importEntry, size_t idx, uint32_t len) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSTaggedValue importEntries = module->GetImportEntries(); + JSTaggedValue importEntries = module->GetImportEntries(thread); if (importEntries.IsUndefined()) { JSHandle array = factory->NewTaggedArray(len); array->Set(thread, idx, importEntry.GetTaggedValue()); @@ -1222,7 +1224,7 @@ void SourceTextModule::AddLocalExportEntry(JSThread *thread, const JSHandle &exportEntry, size_t idx, uint32_t len) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSTaggedValue localExportEntries = module->GetLocalExportEntries(); + JSTaggedValue localExportEntries = module->GetLocalExportEntries(thread); if (localExportEntries.IsUndefined()) { JSHandle array = factory->NewTaggedArray(len); array->Set(thread, idx, exportEntry.GetTaggedValue()); @@ -1238,7 +1240,7 @@ void SourceTextModule::AddIndirectExportEntry(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); - JSTaggedValue indirectExportEntries = module->GetIndirectExportEntries(); + JSTaggedValue indirectExportEntries = module->GetIndirectExportEntries(thread); if (indirectExportEntries.IsUndefined()) { JSHandle array = factory->NewTaggedArray(len); array->Set(thread, idx, exportEntry.GetTaggedValue()); @@ -1253,7 +1255,7 @@ void SourceTextModule::AddStarExportEntry(JSThread *thread, const JSHandle &exportEntry, size_t idx, uint32_t len) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSTaggedValue starExportEntries = module->GetStarExportEntries(); + JSTaggedValue starExportEntries = module->GetStarExportEntries(thread); if (starExportEntries.IsUndefined()) { JSHandle array = factory->NewTaggedArray(len); array->Set(thread, idx, exportEntry.GetTaggedValue()); @@ -1266,7 +1268,7 @@ void SourceTextModule::AddStarExportEntry(JSThread *thread, const JSHandleCheckAndThrowModuleError(thread); @@ -1282,12 +1284,12 @@ JSTaggedValue SourceTextModule::GetModuleValue(JSThread *thread, int32_t index, } TaggedArray *array = TaggedArray::Cast(dictionary.GetTaggedObject()); - return array->Get(index); + return array->Get(thread, index); } JSTaggedValue SourceTextModule::GetModuleValue(JSThread *thread, JSTaggedValue key, bool isThrow) { - JSTaggedValue dictionary = GetNameDictionary(); + JSTaggedValue dictionary = GetNameDictionary(thread); if (dictionary.IsUndefined()) { // if module is Errored, throw origin jsError this->CheckAndThrowModuleError(thread); @@ -1303,15 +1305,15 @@ JSTaggedValue SourceTextModule::GetModuleValue(JSThread *thread, JSTaggedValue k } NameDictionary *dict = NameDictionary::Cast(dictionary.GetTaggedObject()); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { - return dict->GetValue(entry); + return dict->GetValue(thread, entry); } // when key is exportName, need to get localName - JSTaggedValue exportEntriesTv = GetLocalExportEntries(); + JSTaggedValue exportEntriesTv = GetLocalExportEntries(thread); if (!exportEntriesTv.IsUndefined()) { - JSTaggedValue resolution = FindByExport(exportEntriesTv, key, dictionary); + JSTaggedValue resolution = FindByExport(thread, exportEntriesTv, key, dictionary); if (!resolution.IsHole()) { return resolution; } @@ -1328,15 +1330,15 @@ JSTaggedValue SourceTextModule::GetValueFromExportObject(JSThread *thread, JSHan } JSTaggedValue value = JSTaggedValue::Hole(); JSObject *obj = JSObject::Cast(exportObject.GetTaggedValue()); - TaggedArray *properties = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(obj->GetProperties(thread).GetTaggedObject()); if (!properties->IsDictionaryMode()) { JSHClass *jsHclass = obj->GetJSHClass(); - LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr = layoutInfo->GetAttr(index); - value = obj->GetProperty(jsHclass, attr); + LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr = layoutInfo->GetAttr(thread, index); + value = obj->GetProperty(thread, jsHclass, attr); } else { NameDictionary *dict = NameDictionary::Cast(properties); - value = dict->GetValue(index); + value = dict->GetValue(thread, index); } if (UNLIKELY(value.IsAccessor())) { return FastRuntimeStub::CallGetter(thread, JSTaggedValue(obj), JSTaggedValue(obj), value); @@ -1344,7 +1346,8 @@ JSTaggedValue SourceTextModule::GetValueFromExportObject(JSThread *thread, JSHan return value; } -JSTaggedValue SourceTextModule::FindByExport(const JSTaggedValue &exportEntriesTv, const JSTaggedValue &key, +JSTaggedValue SourceTextModule::FindByExport(JSThread *thread, + const JSTaggedValue &exportEntriesTv, const JSTaggedValue &key, const JSTaggedValue &dictionary) { DISALLOW_GARBAGE_COLLECTION; @@ -1352,14 +1355,14 @@ JSTaggedValue SourceTextModule::FindByExport(const JSTaggedValue &exportEntriesT TaggedArray *exportEntries = TaggedArray::Cast(exportEntriesTv.GetTaggedObject()); size_t exportEntriesLen = exportEntries->GetLength(); for (size_t idx = 0; idx < exportEntriesLen; idx++) { - LocalExportEntry *ee = LocalExportEntry::Cast(exportEntries->Get(idx).GetTaggedObject()); - if (!JSTaggedValue::SameValue(ee->GetExportName(), key)) { + LocalExportEntry *ee = LocalExportEntry::Cast(exportEntries->Get(thread, idx).GetTaggedObject()); + if (!JSTaggedValue::SameValue(thread, ee->GetExportName(thread), key)) { continue; } - JSTaggedValue localName = ee->GetLocalName(); - int entry = dict->FindEntry(localName); + JSTaggedValue localName = ee->GetLocalName(thread); + int entry = dict->FindEntry(thread, localName); if (entry != -1) { - return dict->GetValue(entry); + return dict->GetValue(thread, entry); } } @@ -1375,10 +1378,10 @@ void SourceTextModule::StoreModuleValue(JSThread *thread, const JSHandleGetEcmaModuleRecordNameString(); THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str()); } - JSTaggedValue localExportEntries = module->GetLocalExportEntries(); + JSTaggedValue localExportEntries = module->GetLocalExportEntries(thread); ASSERT(localExportEntries.IsTaggedArray()); - JSHandle data(thread, module->GetNameDictionary()); + JSHandle data(thread, module->GetNameDictionary(thread)); if (data->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t size = TaggedArray::Cast(localExportEntries.GetTaggedObject())->GetLength(); @@ -1405,7 +1408,7 @@ void SourceTextModule::StoreModuleValue(JSThread *thread, const JSHandleGetEcmaModuleRecordNameString(); THROW_ERROR(thread, ErrorType::SYNTAX_ERROR, msg.c_str()); } - JSMutableHandle data(thread, module->GetNameDictionary()); + JSMutableHandle data(thread, module->GetNameDictionary(thread)); if (data->IsUndefined()) { data.Update(NameDictionary::Create(thread, DEFAULT_DICTIONART_CAPACITY)); } @@ -1475,15 +1478,15 @@ JSHandle SourceTextModule::GetStarResolution(JSThread *thread, if (resolution->IsResolvedBinding()) { JSHandle resolutionBd = JSHandle::Cast(resolution); JSHandle starResolutionBd = JSHandle::Cast(starResolution); - if ((!JSTaggedValue::SameValue(resolutionBd->GetModule(), starResolutionBd->GetModule())) || - (!JSTaggedValue::SameValue( - resolutionBd->GetBindingName(), starResolutionBd->GetBindingName()))) { + if ((!JSTaggedValue::SameValue(thread, resolutionBd->GetModule(thread), starResolutionBd->GetModule(thread))) || + (!JSTaggedValue::SameValue(thread, + resolutionBd->GetBindingName(thread), starResolutionBd->GetBindingName(thread)))) { return globalConstants->GetHandledAmbiguousString(); } } else { JSHandle resolutionBd = JSHandle::Cast(resolution); JSHandle starResolutionBd = JSHandle::Cast(starResolution); - if ((!JSTaggedValue::SameValue(resolutionBd->GetModule(), starResolutionBd->GetModule())) || + if ((!JSTaggedValue::SameValue(thread, resolutionBd->GetModule(thread), starResolutionBd->GetModule(thread))) || resolutionBd->GetIndex() != starResolutionBd->GetIndex()) { return globalConstants->GetHandledAmbiguousString(); } @@ -1501,10 +1504,10 @@ void SourceTextModule::AddExportName(JSThread *thread, const JSTaggedValue &expo JSHandle exportEntries(thread, exportEntry); size_t exportEntriesLen = exportEntries->GetLength(); for (size_t idx = 0; idx < exportEntriesLen; idx++) { - ee.Update(exportEntries->Get(idx)); + ee.Update(exportEntries->Get(thread, idx)); // a. Assert: module provides the direct binding for this export. // b. Append e.[[ExportName]] to exportedNames. - std::string exportName = EcmaStringAccessor(ee->GetExportName()).ToStdString(); + std::string exportName = EcmaStringAccessor(ee->GetExportName(thread)).ToStdString(thread); exportedNames.emplace_back(exportName); } } @@ -1535,7 +1538,7 @@ JSHandle SourceTextModule::ResolveLocalExport(JSThread *thread, JSHandle localExportEntries(exportEntry); size_t localExportEntriesLen = localExportEntries->GetLength(); for (size_t idx = 0; idx < localExportEntriesLen; idx++) { - ee.Update(localExportEntries->Get(idx)); + ee.Update(localExportEntries->Get(thread, idx)); // a. If SameValue(exportName, e.[[ExportName]]) is true, then // if module is type of CommonJS or native, export first, check after execution. auto moduleType = module->GetTypes(); @@ -1543,7 +1546,7 @@ JSHandle SourceTextModule::ResolveLocalExport(JSThread *thread, return JSHandle::Cast(factory->NewResolvedBindingRecord(module, exportName)); } - if ((JSTaggedValue::SameValueString(ee->GetExportName(), exportName.GetTaggedValue()))) { + if ((JSTaggedValue::SameValueString(thread, ee->GetExportName(thread), exportName.GetTaggedValue()))) { // Adapter new module if (module->GetIsNewBcVersion()) { return JSHandle::Cast(factory->NewResolvedIndexBindingRecord(module, @@ -1551,7 +1554,7 @@ JSHandle SourceTextModule::ResolveLocalExport(JSThread *thread, } // i. Assert: module provides the direct binding for this export. // ii. Return ResolvedBinding Record { [[Module]]: module, [[BindingName]]: e.[[LocalName]] }. - localName.Update(ee->GetLocalName()); + localName.Update(ee->GetLocalName(thread)); return JSHandle::Cast(factory->NewResolvedBindingRecord(module, localName)); } } @@ -1568,20 +1571,20 @@ JSHandle SourceTextModule::ResolveIndirectExport(JSThread *thread JSTaggedValue undefined = globalConstants->GetUndefined(); JSMutableHandle ee(thread, undefined); JSMutableHandle importName(thread, undefined); - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); JSHandle indirectExportEntries(exportEntry); size_t indirectExportEntriesLen = indirectExportEntries->GetLength(); for (size_t idx = 0; idx < indirectExportEntriesLen; idx++) { - ee.Update(indirectExportEntries->Get(idx)); + ee.Update(indirectExportEntries->Get(thread, idx)); // a. If SameValue(exportName, e.[[ExportName]]) is true, then - if (JSTaggedValue::SameValueString(exportName.GetTaggedValue(), ee->GetExportName())) { + if (JSTaggedValue::SameValueString(thread, exportName.GetTaggedValue(), ee->GetExportName(thread))) { // i. Assert: module imports a specific binding for this export. // ii. Let importedModule be ? HostResolveImportedModule(module, e.[[ModuleRequest]]). JSHandle requestedModule = GetRequestedModuleFromCache(thread, requestedModules, ee->GetModuleRequestIndex()); ASSERT(requestedModule.GetTaggedValue().IsSourceTextModule()); // iii. Return importedModule.ResolveExport(e.[[ImportName]], resolvedMap). - importName.Update(ee->GetImportName()); + importName.Update(ee->GetImportName(thread)); return SourceTextModule::ResolveExport(thread, requestedModule, importName, resolvedMap); } } @@ -1592,7 +1595,7 @@ void SourceTextModule::CheckResolvedBinding(JSThread *thread, const JSHandleGlobalConstants(); // 1. For each ExportEntry Record e in module.[[IndirectExportEntries]], do - JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(); + JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(thread); if (indirectExportEntriesTv.IsUndefined()) { return; } @@ -1602,20 +1605,20 @@ void SourceTextModule::CheckResolvedBinding(JSThread *thread, const JSHandle indirectExportEntries(thread, indirectExportEntriesTv); size_t indirectExportEntriesLen = indirectExportEntries->GetLength(); for (size_t idx = 0; idx < indirectExportEntriesLen; idx++) { - ee.Update(indirectExportEntries->Get(idx)); + ee.Update(indirectExportEntries->Get(thread, idx)); // a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « »). - exportName.Update(ee->GetExportName()); + exportName.Update(ee->GetExportName(thread)); ResolvedMultiMap resolvedMap; JSHandle resolution = SourceTextModule::ResolveExport(thread, module, exportName, resolvedMap); RETURN_IF_ABRUPT_COMPLETION(thread); // b. If resolution is null or "ambiguous", throw a SyntaxError exception. if (resolution->IsNull() || resolution->IsString()) { - TaggedArray *requestArray = TaggedArray::Cast(module->GetModuleRequests().GetTaggedObject()); - JSTaggedValue moduleRequest = requestArray->Get(ee->GetModuleRequestIndex()); - CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(moduleRequest)); + TaggedArray *requestArray = TaggedArray::Cast(module->GetModuleRequests(thread).GetTaggedObject()); + JSTaggedValue moduleRequest = requestArray->Get(thread, ee->GetModuleRequestIndex()); + CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(thread, moduleRequest)); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + - ConvertToString(exportName.GetTaggedValue()); + ConvertToString(thread, exportName.GetTaggedValue()); if (!module->GetEcmaModuleRecordNameString().empty()) { CString recordStr = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); msg += "' which exported by '" + recordStr + "'"; @@ -1633,7 +1636,7 @@ void SourceTextModule::CheckResolvedIndexBinding(JSThread *thread, const JSHandl { auto globalConstants = thread->GlobalConstants(); // 1. For each ExportEntry Record e in module.[[IndirectExportEntries]], do - JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(); + JSTaggedValue indirectExportEntriesTv = module->GetIndirectExportEntries(thread); if (indirectExportEntriesTv.IsUndefined()) { return; } @@ -1643,20 +1646,20 @@ void SourceTextModule::CheckResolvedIndexBinding(JSThread *thread, const JSHandl JSHandle indirectExportEntries(thread, indirectExportEntriesTv); size_t indirectExportEntriesLen = indirectExportEntries->GetLength(); for (size_t idx = 0; idx < indirectExportEntriesLen; idx++) { - ee.Update(indirectExportEntries->Get(idx)); + ee.Update(indirectExportEntries->Get(thread, idx)); // a. Let resolution be ? module.ResolveExport(e.[[ExportName]], « »). - exportName.Update(ee->GetExportName()); + exportName.Update(ee->GetExportName(thread)); ResolvedMultiMap resolvedMap; JSHandle resolution = SourceTextModule::ResolveExport(thread, module, exportName, resolvedMap); RETURN_IF_ABRUPT_COMPLETION(thread); // b. If resolution is null or "ambiguous", throw a SyntaxError exception. if (resolution->IsNull() || resolution->IsString()) { - TaggedArray *requestArray = TaggedArray::Cast(module->GetModuleRequests().GetTaggedObject()); - JSTaggedValue moduleRequest = requestArray->Get(ee->GetModuleRequestIndex()); - CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(moduleRequest)); + TaggedArray *requestArray = TaggedArray::Cast(module->GetModuleRequests(thread).GetTaggedObject()); + JSTaggedValue moduleRequest = requestArray->Get(thread, ee->GetModuleRequestIndex()); + CString requestMod = ModulePathHelper::ReformatPath(ConvertToString(thread, moduleRequest)); CString msg = "the requested module '" + requestMod + GetResolveErrorReason(resolution) + - ConvertToString(exportName.GetTaggedValue()); + ConvertToString(thread, exportName.GetTaggedValue()); if (!module->GetEcmaModuleRecordNameString().empty()) { CString record = ModulePathHelper::ReformatPath(module->GetEcmaModuleRecordNameString()); msg += "' which exported by '" + record + "'"; @@ -1692,7 +1695,7 @@ void SourceTextModule::AddAsyncParentModule(JSThread *thread, JSHandle &parent) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSTaggedValue asyncParentModules = module->GetAsyncParentModules(); + JSTaggedValue asyncParentModules = module->GetAsyncParentModules(thread); if (asyncParentModules.IsUndefined()) { JSHandle array = factory->NewTaggedArray(1); array->Set(thread, 0, parent.GetTaggedValue()); @@ -1772,7 +1775,7 @@ void SourceTextModule::GatherAvailableAncestors(JSThread *thread, const JSHandle AsyncParentCompletionSet &execList) { auto globalConstants = thread->GlobalConstants(); - JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(); + JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(thread); if (asyncParentModulesValue.IsUndefined()) { return; } @@ -1781,9 +1784,9 @@ void SourceTextModule::GatherAvailableAncestors(JSThread *thread, const JSHandle size_t asyncParentModulesLen = asyncParentModules->GetLength(); // 1. For each Cyclic Module Record m of module.[[AsyncParentModules]], do for (size_t idx = 0; idx < asyncParentModulesLen; idx++) { - JSHandle parentModule(thread, asyncParentModules->Get(idx)); + JSHandle parentModule(thread, asyncParentModules->Get(thread, idx)); // a. If execList does not contain m and m.[[CycleRoot]].[[EvaluationError]] is EMPTY, then - cycleRoot.Update(parentModule->GetCycleRoot()); + cycleRoot.Update(parentModule->GetCycleRoot(thread)); if (execList.find(parentModule) == execList.end() && cycleRoot->GetStatus() != ModuleStatus::ERRORED) { // i. Assert: m.[[Status]] is EVALUATING-ASYNC. @@ -1814,7 +1817,7 @@ void SourceTextModule::AsyncModuleExecutionFulfilled(JSThread *thread, const JSH // a. Assert: module.[[EvaluationError]] is not EMPTY. // b. Return UNUSED. if (module->GetStatus() == ModuleStatus::ERRORED) { - ASSERT(!module->GetException().IsHole()); + ASSERT(!module->GetException(thread).IsHole()); return; } // 2. Assert: module.[[Status]] is EVALUATING-ASYNC. @@ -1830,9 +1833,9 @@ void SourceTextModule::AsyncModuleExecutionFulfilled(JSThread *thread, const JSH // a. Assert: module.[[CycleRoot]] is module. // b. Perform ! Call(module.[[TopLevelCapability]].[[Resolve]], undefined, « undefined »). auto globalConstants = thread->GlobalConstants(); - JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(); + JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(thread); if (!topLevelCapabilityValue.IsUndefined()) { - ASSERT(JSTaggedValue::SameValue(module->GetCycleRoot(), module.GetTaggedValue())); + ASSERT(JSTaggedValue::SameValue(thread, module->GetCycleRoot(thread), module.GetTaggedValue())); JSHandle topLevelCapability(thread, JSPromise::Cast(topLevelCapabilityValue.GetTaggedObject())); JSHandle undefinedValue = globalConstants->GetHandledUndefined(); JSPromise::FulfillPromise(thread, topLevelCapability, undefinedValue); @@ -1871,9 +1874,9 @@ void SourceTextModule::AsyncModuleExecutionFulfilled(JSThread *thread, const JSH // 2. If m.[[TopLevelCapability]] is not EMPTY, then // a. Assert: m.[[CycleRoot]] is m. // b. Perform ! Call(m.[[TopLevelCapability]].[[Resolve]], undefined, « undefined »). - JSTaggedValue capabilityValue = m->GetTopLevelCapability(); + JSTaggedValue capabilityValue = m->GetTopLevelCapability(thread); if (!capabilityValue.IsUndefined()) { - ASSERT(JSTaggedValue::SameValue(m->GetCycleRoot(), m.GetTaggedValue())); + ASSERT(JSTaggedValue::SameValue(thread, m->GetCycleRoot(thread), m.GetTaggedValue())); JSHandle topLevelCapability(thread, JSPromise::Cast(topLevelCapabilityValue.GetTaggedObject())); JSHandle undefinedValue = globalConstants->GetHandledUndefined(); @@ -1892,7 +1895,7 @@ void SourceTextModule::AsyncModuleExecutionRejected(JSThread *thread, const JSHa // a. Assert: module.[[EvaluationError]] is not EMPTY. // b. Return UNUSED. if (module->GetStatus() == ModuleStatus::ERRORED) { - ASSERT(!module->GetException().IsHole()); + ASSERT(!module->GetException(thread).IsHole()); return; } // 2. Assert: module.[[Status]] is EVALUATING-ASYNC. @@ -1900,7 +1903,7 @@ void SourceTextModule::AsyncModuleExecutionRejected(JSThread *thread, const JSHa // 3. Assert: module.[[AsyncEvaluation]] is true. ASSERT(module->IsAsyncEvaluating()); // 4. Assert: module.[[EvaluationError]] is EMPTY. - ASSERT(module->GetException().IsHole()); + ASSERT(module->GetException(thread).IsHole()); // 5. Set module.[[EvaluationError]] to ThrowCompletion(error). module->SetStatus(ModuleStatus::ERRORED); // 6. Set module.[[Status]] to EVALUATED. @@ -1908,13 +1911,13 @@ void SourceTextModule::AsyncModuleExecutionRejected(JSThread *thread, const JSHa // 7. For each Cyclic Module Record m of module.[[AsyncParentModules]], do // a. Perform AsyncModuleExecutionRejected(m, error). auto globalConstants = thread->GlobalConstants(); - JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(); + JSTaggedValue asyncParentModulesValue = module->GetAsyncParentModules(thread); if (!asyncParentModulesValue.IsUndefined()) { JSMutableHandle parentModule(thread, globalConstants->GetUndefined()); JSHandle asyncParentModules(thread, asyncParentModulesValue); size_t asyncParentModulesLen = asyncParentModules->GetLength(); for (size_t idx = 0; idx < asyncParentModulesLen; idx++) { - parentModule.Update(asyncParentModules->Get(idx)); + parentModule.Update(asyncParentModules->Get(thread, idx)); AsyncModuleExecutionRejected(thread, parentModule, error); } } @@ -1922,14 +1925,14 @@ void SourceTextModule::AsyncModuleExecutionRejected(JSThread *thread, const JSHa // 8. If module.[[TopLevelCapability]] is not EMPTY, then // a. Assert: module.[[CycleRoot]] is module. // b. Perform ! Call(module.[[TopLevelCapability]].[[Reject]], undefined, « error »). - JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(); + JSTaggedValue topLevelCapabilityValue = module->GetTopLevelCapability(thread); if (!topLevelCapabilityValue.IsUndefined()) { JSHandle exceptionHandle(thread, error); // if caught exceptionHandle type is JSError if (exceptionHandle->IsJSError()) { thread->HandleUncaughtException(error); } - ASSERT(JSTaggedValue::SameValue(module->GetCycleRoot(), module.GetTaggedValue())); + ASSERT(JSTaggedValue::SameValue(thread, module->GetCycleRoot(thread), module.GetTaggedValue())); JSHandle topLevelCapability(thread, JSPromise::Cast(topLevelCapabilityValue.GetTaggedObject())); JSPromise::RejectPromise(thread, topLevelCapability, exceptionHandle); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -1943,7 +1946,7 @@ JSTaggedValue SourceTextModule::AsyncModuleFulfilledFunc(EcmaRuntimeCallInfo *ar [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle fulfilledFunc = JSHandle::Cast(base::BuiltinsBase::GetConstructor(argv)); - JSHandle module(thread, fulfilledFunc->GetModule()); + JSHandle module(thread, fulfilledFunc->GetModule(thread)); AsyncModuleExecutionFulfilled(thread, module); return JSTaggedValue::Undefined(); } @@ -1956,7 +1959,7 @@ JSTaggedValue SourceTextModule::AsyncModuleRejectedFunc(EcmaRuntimeCallInfo *arg [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle rejectedFunc = JSHandle::Cast(base::BuiltinsBase::GetConstructor(argv)); - JSHandle module(thread, rejectedFunc->GetModule()); + JSHandle module(thread, rejectedFunc->GetModule(thread)); [[maybe_unused]] JSHandle value = base::BuiltinsBase::GetCallArg(argv, 0); AsyncModuleExecutionRejected(thread, module, value.GetTaggedValue()); return JSTaggedValue::Undefined(); @@ -1984,16 +1987,16 @@ void SourceTextModule::SearchCircularImport(JSThread *thread, const CString &cir CList &referenceList, CString &requiredModuleName, bool printOtherCircular) { - if (module->GetModuleRequests().IsUndefined()) { + if (module->GetModuleRequests(thread).IsUndefined()) { return; } auto globalConstants = thread->GlobalConstants(); - JSHandle moduleRequests(thread, module->GetModuleRequests()); + JSHandle moduleRequests(thread, module->GetModuleRequests(thread)); size_t moduleRequestsLen = moduleRequests->GetLength(); JSMutableHandle required(thread, globalConstants->GetUndefined()); JSMutableHandle requiredModule(thread, globalConstants->GetUndefined()); for (size_t idx = 0; idx < moduleRequestsLen; idx++) { - required.Update(moduleRequests->Get(idx)); + required.Update(moduleRequests->Get(thread, idx)); requiredModule.Update(JSHandle::Cast( ModuleResolver::HostResolveImportedModule(thread, module, required))); RETURN_IF_ABRUPT_COMPLETION(thread); @@ -2091,14 +2094,14 @@ bool SourceTextModule::CheckAndThrowModuleError(JSThread *thread) { if (GetStatus() == ModuleStatus::ERRORED) { LOG_FULL(ERROR) << "Error found in module:" << GetEcmaModuleRecordNameString(); - JSHandle exceptionInfo(thread, GetException()); + JSHandle exceptionInfo(thread, GetException(thread)); if (exceptionInfo->IsJSError()) { base::ErrorHelper::PrintJSErrorInfo(thread, exceptionInfo); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, exceptionInfo.GetTaggedValue(), false); } JSHandle message = JSTaggedValue::ToString(thread, exceptionInfo); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - CString str = ConvertToString(*message); + CString str = ConvertToString(thread, *message); LOG_NO_TAG(ERROR) << str; THROW_NEW_ERROR_AND_RETURN_VALUE(thread, message.GetTaggedValue(), false); } @@ -2111,7 +2114,7 @@ void SourceTextModule::HandleEvaluateException(JSThread *thread, // a. For each module m in stack, do auto &options = const_cast(thread->GetEcmaVM())->GetJSOptions(); if (options.EnableModuleException()) { - JSTaggedValue::DesensitizedDump(exception); + JSTaggedValue::DesensitizedDump(thread, exception); } for (auto &mm : stack) { // i. Assert: m.[[Status]] is "evaluating". @@ -2143,14 +2146,14 @@ JSHandle SourceTextModule::GetRequestedModuleFromCache(JSThrea const JSHandle requestedModules, uint32_t idx) { - JSHandle request(thread, requestedModules->Get(idx)); + JSHandle request(thread, requestedModules->Get(thread, idx)); if (request->IsSourceTextModule()) { // current is normal module: directly get require SourceTextModule. return JSHandle::Cast(request); } // current is shared module: resolve or find request module by request string. ModuleManager *moduleManager = thread->GetModuleManager(); - CString requestStr = ModulePathHelper::Utf8ConvertToString(request.GetTaggedValue()); + CString requestStr = ModulePathHelper::Utf8ConvertToString(thread, request.GetTaggedValue()); return moduleManager->GetImportedModule(requestStr); } @@ -2158,7 +2161,7 @@ JSHandle SourceTextModule::GetModuleFromCacheOrResolveNewOne(J const JSHandle module, const JSHandle requestedModules, uint32_t idx) { JSHandle requireModule; - JSTaggedValue request = requestedModules->Get(idx); + JSTaggedValue request = requestedModules->Get(thread, idx); if (!request.IsHole()) { requireModule = GetRequestedModuleFromCache(thread, requestedModules, idx); } @@ -2176,8 +2179,8 @@ JSHandle SourceTextModule::GetModuleFromCacheOrResolveNewOne(J * Because [GetRequestedModuleFromCache] is a fastpath for resolvedModule, but B is not resolved in thread 2. * In this case, we need to add resolve new module process. */ - JSHandle moduleRequests(thread, module->GetModuleRequests()); - JSHandle required(thread, moduleRequests->Get(idx)); + JSHandle moduleRequests(thread, module->GetModuleRequests(thread)); + JSHandle required(thread, moduleRequests->Get(thread, idx)); return JSHandle::Cast( ModuleResolver::HostResolveImportedModule(thread, module, required)); } @@ -2185,7 +2188,7 @@ JSHandle SourceTextModule::GetModuleFromCacheOrResolveNewOne(J JSHandle SourceTextModule::GetRequestedModuleMayThrowError(JSThread *thread, const JSHandle requestedModules, uint32_t idx, JSHandle exception) { - JSHandle request(thread, requestedModules->Get(idx)); + JSHandle request(thread, requestedModules->Get(thread, idx)); if (UNLIKELY(request->IsHole())) { // requestModule is hole, means module resolve already have exception. // throw original error. diff --git a/ecmascript/module/js_module_source_text.h b/ecmascript/module/js_module_source_text.h index 25d1f3eb1b..cd7d03bd0b 100644 --- a/ecmascript/module/js_module_source_text.h +++ b/ecmascript/module/js_module_source_text.h @@ -375,7 +375,8 @@ public: static bool IsDynamicModule(LoadingTypes types); // taskpool - static std::optional> GetConcurrentRequestedModules(const JSHandle &method); + static std::optional> GetConcurrentRequestedModules(JSThread *thread, + const JSHandle &method); static int EvaluateForConcurrent(JSThread *thread, const JSHandle &module, const JSHandle &method); static int ModuleEvaluation(JSThread *thread, const JSHandle &module, @@ -419,12 +420,14 @@ private: const JSHandle &hclass, const JSHandle &exportName, const JSHandle &module); - static bool CheckCircularImport(const JSHandle &module, + static bool CheckCircularImport(JSThread *thread, + const JSHandle &module, const JSHandle &exportName, ResolvedMultiMap &resolvedMap); - static JSTaggedValue FindByExport(const JSTaggedValue &exportEntriesTv, const JSTaggedValue &key, + static JSTaggedValue FindByExport(JSThread *thread, const JSTaggedValue &exportEntriesTv, const JSTaggedValue &key, const JSTaggedValue &dictionary); - static void DFSModuleInstantiation(JSHandle &module, + static void DFSModuleInstantiation(JSThread *thread, + JSHandle &module, CVector> &stack); static int HandleInstantiateException(JSHandle &module, const CVector> &stack, int result); diff --git a/ecmascript/module/js_shared_module.cpp b/ecmascript/module/js_shared_module.cpp index 2664b2f786..b7af5330ac 100644 --- a/ecmascript/module/js_shared_module.cpp +++ b/ecmascript/module/js_shared_module.cpp @@ -33,7 +33,7 @@ JSHandle SendableClassModule::GenerateSendableFuncModule(JSThread } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle sModule = factory->NewSSourceTextModule(); - JSHandle currentEnvironment(thread, currentModule->GetEnvironment()); + JSHandle currentEnvironment(thread, currentModule->GetEnvironment(thread)); JSHandle sendableEnvironment = SendableClassModule::CloneModuleEnvironment(thread, currentEnvironment); sModule->SetSharedType(SharedTypes::SENDABLE_FUNCTION_MODULE); @@ -48,7 +48,7 @@ JSHandle SendableClassModule::CloneRecordIndexBinding(JSThread *t { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle binding(thread, indexBinding); - JSHandle resolvedModule(thread, binding->GetModule()); + JSHandle resolvedModule(thread, binding->GetModule(thread)); if (SourceTextModule::IsSharedModule((resolvedModule))) { return JSHandle::Cast( factory->NewSResolvedIndexBindingRecord(resolvedModule, binding->GetIndex())); @@ -65,16 +65,16 @@ JSHandle SendableClassModule::CloneRecordNameBinding(JSThread *th { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); ResolvedBinding *resolvedBinding = ResolvedBinding::Cast(binding.GetTaggedObject()); - JSHandle resolvedModule(thread, resolvedBinding->GetModule()); + JSHandle resolvedModule(thread, resolvedBinding->GetModule(thread)); if (SourceTextModule::IsSharedModule((resolvedModule))) { - JSHandle bindingName(thread, resolvedBinding->GetBindingName()); + JSHandle bindingName(thread, resolvedBinding->GetBindingName(thread)); return JSHandle::Cast( factory->NewSResolvedBindingRecord(resolvedModule, bindingName)); } CString moduleName = SourceTextModule::GetModuleName(resolvedModule.GetTaggedValue()); JSHandle record = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(moduleName); - JSHandle bindingName(thread, resolvedBinding->GetBindingName()); + JSHandle bindingName(thread, resolvedBinding->GetBindingName(thread)); return JSHandle::Cast(factory->NewSResolvedRecordBindingRecord(record, bindingName)); } @@ -89,7 +89,7 @@ JSHandle SendableClassModule::CloneModuleEnvironment(JSThread *thre int enumKeys = static_cast(currentEnvironment->GetLength()); JSHandle sendableEnvironment = factory->NewSDictionaryArray(enumKeys); for (int idx = 0; idx < enumKeys; idx++) { - JSTaggedValue key = currentEnvironment->Get(idx); + JSTaggedValue key = currentEnvironment->Get(thread, idx); if (key.IsRecord()) { JSType type = key.GetTaggedObject()->GetClass()->GetObjectType(); switch (type) { @@ -155,7 +155,7 @@ JSHandle JSSharedModule::GenerateSharedExports(JSThread *thread, co } JSHandle newArray = thread->GetEcmaVM()->GetFactory()->NewSTaggedArray(newLength); for (uint32_t i = 0; i < newLength; i++) { - JSTaggedValue value = oldExports->Get(i); + JSTaggedValue value = oldExports->Get(thread, i); ASSERT(value.IsString()); newArray->Set(thread, i, value); } diff --git a/ecmascript/module/module_logger.cpp b/ecmascript/module/module_logger.cpp index 68ccd22425..0f500b5a88 100644 --- a/ecmascript/module/module_logger.cpp +++ b/ecmascript/module/module_logger.cpp @@ -86,10 +86,10 @@ void ModuleLogger::InsertModuleLoadInfo(JSHandle currentModule if (index < 0) { exportNameStr = "*"; } else { - JSHandle importArray(thread, currentModule->GetImportEntries()); - JSHandle importEntry(thread, importArray->Get(index)); - JSHandle importName(thread, importEntry->GetImportName()); - exportNameStr = ModulePathHelper::Utf8ConvertToString(importName.GetTaggedValue()); + JSHandle importArray(thread, currentModule->GetImportEntries(thread)); + JSHandle importEntry(thread, importArray->Get(thread, index)); + JSHandle importName(thread, importEntry->GetImportName(thread)); + exportNameStr = ModulePathHelper::Utf8ConvertToString(thread, importName.GetTaggedValue()); } auto &upLevelInfo = sonModule->upLevel; auto ulModule = upLevelInfo.find(curName); diff --git a/ecmascript/module/module_message_helper.h b/ecmascript/module/module_message_helper.h index d04aecac8a..22bae3d65c 100644 --- a/ecmascript/module/module_message_helper.h +++ b/ecmascript/module/module_message_helper.h @@ -37,20 +37,20 @@ public: PrintErrorMessage(thread, module); auto &options = const_cast(thread->GetEcmaVM())->GetJSOptions(); if (options.EnableModuleException()) { - THROW_NEW_ERROR_AND_RETURN(thread, module->GetException()); + THROW_NEW_ERROR_AND_RETURN(thread, module->GetException(thread)); } } static void PrintErrorMessage(JSThread *thread, JSHandle module) { - JSHandle exceptionInfo(thread, module->GetException()); + JSHandle exceptionInfo(thread, module->GetException(thread)); if (exceptionInfo->IsJSError()) { base::ErrorHelper::PrintJSErrorInfo(thread, exceptionInfo); return; } JSHandle str = JSTaggedValue::ToString(thread, exceptionInfo); RETURN_IF_ABRUPT_COMPLETION(thread); - CString message = ConvertToString(*str); + CString message = ConvertToString(thread, *str); LOG_ECMA(ERROR) << "Error occurs:" << message; } }; diff --git a/ecmascript/module/module_path_helper.cpp b/ecmascript/module/module_path_helper.cpp index b2e8869d90..4129ed7185 100644 --- a/ecmascript/module/module_path_helper.cpp +++ b/ecmascript/module/module_path_helper.cpp @@ -1077,9 +1077,9 @@ CString ModulePathHelper::GetBundleNameWithRecordName(EcmaVM *vm, const CString } // this function convert for ESModule name string(Utf8) -CString ModulePathHelper::Utf8ConvertToString(JSTaggedValue str) +CString ModulePathHelper::Utf8ConvertToString(JSThread *thread, JSTaggedValue str) { - return EcmaStringAccessor(str).Utf8ConvertToString(); + return EcmaStringAccessor(str).Utf8ConvertToString(thread); } // check if input is ohmurl's ets/ts/js diff --git a/ecmascript/module/module_path_helper.h b/ecmascript/module/module_path_helper.h index 7767f3a0ce..9d7c2f9494 100644 --- a/ecmascript/module/module_path_helper.h +++ b/ecmascript/module/module_path_helper.h @@ -205,7 +205,7 @@ public: static CString ConcatNormalizedOhmurlWithData(const CVector &data, const CString &pkgName, CString &entryPath); static CString GetBundleNameWithRecordName(EcmaVM *vm, const CString &recordName); - static CString Utf8ConvertToString(JSTaggedValue str); + static CString Utf8ConvertToString(JSThread *thread, JSTaggedValue str); static CString ParseFileNameToVMAName(const CString &filename); static CString ConcatOtherNormalizedOhmurlWithFilePath(EcmaVM *vm, size_t filePathPos, const CString &moduleName, diff --git a/ecmascript/module/module_resolver.cpp b/ecmascript/module/module_resolver.cpp index 50601fbb87..6706efa085 100644 --- a/ecmascript/module/module_resolver.cpp +++ b/ecmascript/module/module_resolver.cpp @@ -80,7 +80,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleWithMerge(JSThr const JSHandle &moduleRequest, const ExecuteTypes &executeType) { - CString moduleRequestName = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue()); + CString moduleRequestName = ModulePathHelper::Utf8ConvertToString(thread, moduleRequest.GetTaggedValue()); ReplaceModuleThroughFeature(thread, moduleRequestName); CString baseFilename{}; @@ -126,7 +126,7 @@ JSHandle ModuleResolver::HostResolveImportedModuleBundlePack(JSTh const ExecuteTypes &executeType) { auto moduleManager = thread->GetModuleManager(); - CString moduleRequestStr = ModulePathHelper::Utf8ConvertToString(moduleRequest.GetTaggedValue()); + CString moduleRequestStr = ModulePathHelper::Utf8ConvertToString(thread, moduleRequest.GetTaggedValue()); if (moduleManager->IsLocalModuleLoaded(moduleRequestStr)) { return JSHandle(moduleManager->HostGetImportedModule(moduleRequestStr)); } diff --git a/ecmascript/module/module_value_accessor.cpp b/ecmascript/module/module_value_accessor.cpp index 56793b56f8..4e9aaefa2e 100644 --- a/ecmascript/module/module_value_accessor.cpp +++ b/ecmascript/module/module_value_accessor.cpp @@ -33,7 +33,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueInner(JSThread *thread, int32_t JSTaggedValue ModuleValueAccessor::GetModuleValueInner(JSThread *thread, int32_t index, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); if (currentModule.IsUndefined()) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed"; } @@ -51,7 +51,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueInner(JSThread *thread, int32_t JSTaggedValue ModuleValueAccessor::GetSendableModuleValueInner(JSThread* thread, int32_t index, JSTaggedValue jsFunc) { ModuleManager* moduleManager = thread->GetModuleManager(); - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); if (currentModule.IsUndefined()) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "GetSendableModuleValueInner currentModule is undefined"; } @@ -82,7 +82,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueOuter(JSThread* thread, int32_t JSTaggedValue ModuleValueAccessor::GetModuleValueOuter(JSThread* thread, int32_t index, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); return GetModuleValueOuterInternal(thread, index, currentModule, false); } @@ -94,20 +94,20 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueOuter(JSThread* thread, int32_t JSTaggedValue ModuleValueAccessor::GetLazyModuleValueOuter(JSThread* thread, int32_t index, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); return GetModuleValueOuterInternal(thread, index, currentModule, true); } JSTaggedValue ModuleValueAccessor::GetSendableModuleValueOuter(JSThread *thread, int32_t index, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); return GetSendableModuleValueOuterInternal(thread, index, currentModule, false); } JSTaggedValue ModuleValueAccessor::GetLazySendableModuleValueOuter(JSThread* thread, int32_t index, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); return GetSendableModuleValueOuterInternal(thread, index, currentModule, true); } @@ -119,7 +119,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleNamespace(JSThread *thread, int32_t JSTaggedValue ModuleValueAccessor::GetModuleNamespace(JSThread *thread, int32_t index, JSTaggedValue curFunc) { - JSTaggedValue currentModule = JSFunction::Cast(curFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(curFunc.GetTaggedObject())->GetModule(thread); return GetModuleNamespaceInternal(thread, index, currentModule); } JSTaggedValue ModuleValueAccessor::GetNativeOrCjsModuleValue(JSThread *thread, JSHandle module, @@ -134,7 +134,7 @@ JSTaggedValue ModuleValueAccessor::GetNativeOrCjsModuleValue(JSThread *thread, J { JSHandle exports = GetNativeOrCjsExports(thread, module.GetTaggedValue()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - if (UNLIKELY(JSTaggedValue::SameValue( + if (UNLIKELY(JSTaggedValue::SameValue(thread, bindingName, thread->GlobalConstants()->GetHandledDefaultString().GetTaggedValue()))) { return exports.GetTaggedValue(); } @@ -153,14 +153,14 @@ void ModuleValueAccessor::StoreModuleValue(JSThread *thread, int32_t index, JSTa void ModuleValueAccessor::StoreModuleValue(JSThread *thread, int32_t index, JSTaggedValue value, JSTaggedValue jsFunc) { - JSHandle currentModule(thread, JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule()); + JSHandle currentModule(thread, JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread)); StoreModuleValueInternal(thread, currentModule, index, value); } JSTaggedValue ModuleValueAccessor::GetCurrentModule(JSThread *thread) { FrameHandler frameHandler(thread); JSTaggedValue currentFunc = frameHandler.GetFunction(); - JSTaggedValue module = JSFunction::Cast(currentFunc.GetTaggedObject())->GetModule(); + JSTaggedValue module = JSFunction::Cast(currentFunc.GetTaggedObject())->GetModule(thread); if (SourceTextModule::IsSendableFunctionModule(module)) { CString recordNameStr = SourceTextModule::GetModuleName(module); return thread->GetModuleManager()->HostGetImportedModule(recordNameStr).GetTaggedValue(); @@ -183,12 +183,12 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueOuterInternal(JSThread *thread, UNREACHABLE(); } JSHandle currentModuleHdl(thread, curModule); - JSTaggedValue moduleEnvironment = currentModuleHdl->GetEnvironment(); + JSTaggedValue moduleEnvironment = currentModuleHdl->GetEnvironment(thread); if (moduleEnvironment.IsUndefined()) { return thread->GlobalConstants()->GetUndefined(); } ASSERT(moduleEnvironment.IsTaggedArray()); - JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnvironment.GetTaggedObject())->Get(index); + JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnvironment.GetTaggedObject())->Get(thread, index); GetModuleValueFromBindingInfo info { thread, currentModuleHdl, resolvedBinding, index, false, isLazy }; if (resolvedBinding.IsResolvedIndexBinding()) { return GetModuleValueFromIndexBinding(info); @@ -203,7 +203,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueOuterInternal(JSThread *thread, return GetModuleValueFromRecordBinding(info); } std::ostringstream oss; - curModule.Dump(oss); + curModule.Dump(thread, oss); LOG_ECMA(FATAL) << "Get module value failed, mistaken ResolvedBinding" << ", index: " << index << ", currentModule: " << oss.str(); UNREACHABLE(); @@ -216,12 +216,12 @@ JSTaggedValue ModuleValueAccessor::GetSendableModuleValueOuterInternal(JSThread UNREACHABLE(); } JSHandle module(thread, curModule.GetTaggedObject()); - JSTaggedValue moduleEnvironment = module->GetEnvironment(); + JSTaggedValue moduleEnvironment = module->GetEnvironment(thread); if (moduleEnvironment.IsUndefined()) { return thread->GlobalConstants()->GetUndefined(); } ASSERT(moduleEnvironment.IsTaggedArray()); - JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnvironment.GetTaggedObject())->Get(index); + JSTaggedValue resolvedBinding = TaggedArray::Cast(moduleEnvironment.GetTaggedObject())->Get(thread, index); GetModuleValueFromBindingInfo info { thread, module, resolvedBinding, index, true, isLazy }; if (resolvedBinding.IsResolvedRecordIndexBinding()) { return GetModuleValueFromRecordIndexBinding(info); @@ -242,7 +242,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleNamespaceInternal(JSThread *thread, UNREACHABLE(); } JSHandle module(thread, SourceTextModule::Cast(curModule)); - JSHandle requestedModules(thread, module->GetRequestedModules()); + JSHandle requestedModules(thread, module->GetRequestedModules(thread)); JSHandle requiredModule = SourceTextModule::GetRequestedModuleFromCache(thread, requestedModules, index); ASSERT(requiredModule.GetTaggedValue().IsSourceTextModule()); @@ -280,7 +280,7 @@ void ModuleValueAccessor::StoreModuleValueInternal(JSThread *thread, JSHandle binding(info.thread, info.resolvedBinding); - JSMutableHandle resolvedModule(info.thread, binding->GetModule()); + JSMutableHandle resolvedModule(info.thread, binding->GetModule(info.thread)); if (!info.isSendable && info.thread->GetStageOfHotReload() == StageOfHotReload::LOAD_END_EXECUTE_PATCHMAIN) { const JSHandle resolvedModuleOfHotReload = info.thread->GetEcmaVM()->FindPatchModule(resolvedModule->GetEcmaModuleRecordNameString()); @@ -301,11 +301,11 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueFromIndexBinding(const GetModul JSTaggedValue ModuleValueAccessor::GetModuleValueFromBinding(const GetModuleValueFromBindingInfo &info) { JSHandle binding(info.thread, info.resolvedBinding); - JSHandle resolvedModule(info.thread, binding->GetModule()); + JSHandle resolvedModule(info.thread, binding->GetModule(info.thread)); if (UNLIKELY(!SourceTextModule::IsNativeModule(resolvedModule->GetTypes()) && !SourceTextModule::IsCjsModule(resolvedModule->GetTypes()))) { std::ostringstream oss; - info.module.GetTaggedValue().Dump(oss); + info.module.GetTaggedValue().Dump(info.thread, oss); LOG_ECMA(FATAL) << "Get module value failed, mistaken ResolvedBinding" << ", index: " << info.index << ", currentModule: " << oss.str(); } @@ -313,7 +313,7 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueFromBinding(const GetModuleValu RETURN_VALUE_IF_ABRUPT_COMPLETION(info.thread, JSTaggedValue::Exception()); LogModuleLoadInfo(info.thread, info.module, resolvedModule, info.index, false); return UpdateBindingAndGetModuleValue(info.thread, info.module, resolvedModule, info.index, - binding->GetBindingName()); + binding->GetBindingName(info.thread)); } JSTaggedValue ModuleValueAccessor::GetModuleValueFromRecordIndexBinding(const GetModuleValueFromBindingInfo &info) @@ -333,14 +333,14 @@ JSTaggedValue ModuleValueAccessor::GetModuleValueFromRecordBinding(const GetModu GetResolvedModuleFromRecordBinding(info.thread, info.module, binding, info.isLazy); RETURN_VALUE_IF_ABRUPT_COMPLETION(info.thread, JSTaggedValue::Exception()); LogModuleLoadInfo(info.thread, info.module, resolvedModule, info.index, info.isSendable); - return GetNativeOrCjsModuleValue(info.thread, resolvedModule, binding->GetBindingName()); + return GetNativeOrCjsModuleValue(info.thread, resolvedModule, binding->GetBindingName(info.thread)); } JSTaggedValue ModuleValueAccessor::UpdateBindingAndGetModuleValue(JSThread *thread, JSHandle module, JSHandle requiredModule, int32_t index, JSTaggedValue bindingName) { // Get esm environment - JSHandle moduleEnvironment(thread, module->GetEnvironment()); + JSHandle moduleEnvironment(thread, module->GetEnvironment(thread)); ASSERT(!moduleEnvironment->IsUndefined()); JSHandle environment = JSHandle::Cast(moduleEnvironment); // rebinding here @@ -356,7 +356,7 @@ JSTaggedValue ModuleValueAccessor::UpdateBindingAndGetModuleValue(JSThread *thre CString recordStr = ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName( module.GetTaggedValue())); CString msg = "the requested module '" + requestMod + SourceTextModule::GetResolveErrorReason(resolution) + - ModulePathHelper::Utf8ConvertToString(bindingName) + + ModulePathHelper::Utf8ConvertToString(thread, bindingName) + "' which imported by '" + recordStr + "'"; THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE( thread, ErrorType::SYNTAX_ERROR, msg.c_str(), JSTaggedValue::Exception()); @@ -373,15 +373,15 @@ JSHandle ModuleValueAccessor::GetResolvedModuleFromRecordIndex JSHandle module, JSHandle binding, bool isLazy) { return GetResolvedModule(thread, module, - ModulePathHelper::Utf8ConvertToString(binding->GetAbcFileName()), - ModulePathHelper::Utf8ConvertToString(binding->GetModuleRecord()), isLazy); + ModulePathHelper::Utf8ConvertToString(thread, binding->GetAbcFileName(thread)), + ModulePathHelper::Utf8ConvertToString(thread, binding->GetModuleRecord(thread)), isLazy); } JSHandle ModuleValueAccessor::GetResolvedModuleFromRecordBinding(JSThread* thread, JSHandle module, JSHandle binding, bool isLazy) { return GetResolvedModule(thread, module, module->GetEcmaModuleFilenameString(), - ModulePathHelper::Utf8ConvertToString(binding->GetModuleRecord()), isLazy); + ModulePathHelper::Utf8ConvertToString(thread, binding->GetModuleRecord(thread)), isLazy); } void ModuleValueAccessor::EvaluateModuleIfNeeded(JSThread* thread, JSHandle module, bool isLazy) @@ -476,7 +476,7 @@ JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueInner(JSThread* threa JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueInner(JSThread* thread, JSTaggedValue key, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); if (currentModule.IsUndefined()) { // LCOV_EXCL_BR_LINE LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed"; UNREACHABLE(); @@ -493,7 +493,7 @@ JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueOuter(JSThread* threa JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueOuter(JSThread* thread, JSTaggedValue key, JSTaggedValue jsFunc) { - JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread); return GetModuleValueOuterInternal(thread, key, currentModule); } @@ -506,7 +506,7 @@ JSTaggedValue DeprecatedModuleValueAccessor::GetModuleNamespace(JSThread* thread JSTaggedValue DeprecatedModuleValueAccessor::GetModuleNamespace(JSThread* thread, JSTaggedValue localName, JSTaggedValue curFunc) { - JSTaggedValue currentModule = JSFunction::Cast(curFunc.GetTaggedObject())->GetModule(); + JSTaggedValue currentModule = JSFunction::Cast(curFunc.GetTaggedObject())->GetModule(thread); return GetModuleNamespaceInternal(thread, localName, currentModule); } void DeprecatedModuleValueAccessor::StoreModuleValue(JSThread* thread, JSTaggedValue key, JSTaggedValue value) @@ -518,7 +518,7 @@ void DeprecatedModuleValueAccessor::StoreModuleValue(JSThread* thread, JSTaggedV void DeprecatedModuleValueAccessor::StoreModuleValue(JSThread* thread, JSTaggedValue key, JSTaggedValue value, JSTaggedValue jsFunc) { - JSHandle currentModule(thread, JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule()); + JSHandle currentModule(thread, JSFunction::Cast(jsFunc.GetTaggedObject())->GetModule(thread)); StoreModuleValueInternal(thread, currentModule, key, value); } JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueOuterInternal(JSThread* thread, JSTaggedValue key, @@ -528,18 +528,18 @@ JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueOuterInternal(JSThrea LOG_FULL(FATAL) << "GetModuleValueOutter currentModule failed"; UNREACHABLE(); } - JSTaggedValue moduleEnvironment = SourceTextModule::Cast(curModule.GetTaggedObject())->GetEnvironment(); + JSTaggedValue moduleEnvironment = SourceTextModule::Cast(curModule.GetTaggedObject())->GetEnvironment(thread); if (moduleEnvironment.IsUndefined()) { return thread->GlobalConstants()->GetUndefined(); } - int entry = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->FindEntry(key); + int entry = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->FindEntry(thread, key); if (entry == -1) { return thread->GlobalConstants()->GetUndefined(); } - JSTaggedValue resolvedBinding = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->GetValue(entry); + JSTaggedValue resolvedBinding = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->GetValue(thread, entry); ASSERT(resolvedBinding.IsResolvedBinding()); ResolvedBinding *binding = ResolvedBinding::Cast(resolvedBinding.GetTaggedObject()); - JSTaggedValue resolvedModule = binding->GetModule(); + JSTaggedValue resolvedModule = binding->GetModule(thread); ASSERT(resolvedModule.IsSourceTextModule()); SourceTextModule *module = SourceTextModule::Cast(resolvedModule.GetTaggedObject()); if (module->GetTypes() == ModuleTypes::CJS_MODULE) { @@ -547,7 +547,7 @@ JSTaggedValue DeprecatedModuleValueAccessor::GetModuleValueOuterInternal(JSThrea JSHandle moduleNameHandle(thread->GetEcmaVM()->GetFactory()->NewFromUtf8(cjsModuleName)); return CjsModule::SearchFromModuleCache(thread, moduleNameHandle).GetTaggedValue(); } - return module->GetModuleValue(thread, binding->GetBindingName(), false); + return module->GetModuleValue(thread, binding->GetBindingName(thread), false); } JSTaggedValue DeprecatedModuleValueAccessor::GetModuleNamespaceInternal(JSThread* thread, JSTaggedValue localName, JSTaggedValue curModule) @@ -556,15 +556,15 @@ JSTaggedValue DeprecatedModuleValueAccessor::GetModuleNamespaceInternal(JSThread LOG_FULL(FATAL) << "GetModuleNamespace currentModule failed"; UNREACHABLE(); } - JSTaggedValue moduleEnvironment = SourceTextModule::Cast(curModule.GetTaggedObject())->GetEnvironment(); + JSTaggedValue moduleEnvironment = SourceTextModule::Cast(curModule.GetTaggedObject())->GetEnvironment(thread); if (moduleEnvironment.IsUndefined()) { return thread->GlobalConstants()->GetUndefined(); } - int entry = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->FindEntry(localName); + int entry = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->FindEntry(thread, localName); if (entry == -1) { return thread->GlobalConstants()->GetUndefined(); } - JSTaggedValue moduleNamespace = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->GetValue(entry); + JSTaggedValue moduleNamespace = NameDictionary::Cast(moduleEnvironment.GetTaggedObject())->GetValue(thread, entry); ASSERT(moduleNamespace.IsModuleNamespace()); return moduleNamespace; } diff --git a/ecmascript/module/tests/ecma_module_test.cpp b/ecmascript/module/tests/ecma_module_test.cpp index 39ee5c54aa..61f4905928 100644 --- a/ecmascript/module/tests/ecma_module_test.cpp +++ b/ecmascript/module/tests/ecma_module_test.cpp @@ -186,7 +186,7 @@ HWTEST_F_L0(EcmaModuleTest, AddImportEntry) SourceTextModule::AddImportEntry(thread, module, importEntry1, 0, 2); JSHandle importEntry2 = objectFactory->NewImportEntry(); SourceTextModule::AddImportEntry(thread, module, importEntry2, 1, 2); - JSHandle importEntries(thread, module->GetImportEntries()); + JSHandle importEntries(thread, module->GetImportEntries(thread)); EXPECT_TRUE(importEntries->GetLength() == 2U); } @@ -205,7 +205,7 @@ HWTEST_F_L0(EcmaModuleTest, AddLocalExportEntry) SourceTextModule::AddLocalExportEntry(thread, module, localExportEntry1, 0, 2); JSHandle localExportEntry2 = objectFactory->NewLocalExportEntry(); SourceTextModule::AddLocalExportEntry(thread, module, localExportEntry2, 1, 2); - JSHandle localExportEntries(thread, module->GetLocalExportEntries()); + JSHandle localExportEntries(thread, module->GetLocalExportEntries(thread)); EXPECT_TRUE(localExportEntries->GetLength() == 2U); } @@ -224,7 +224,7 @@ HWTEST_F_L0(EcmaModuleTest, AddIndirectExportEntry) SourceTextModule::AddIndirectExportEntry(thread, module, indirectExportEntry1, 0, 2); JSHandle indirectExportEntry2 = objectFactory->NewIndirectExportEntry(); SourceTextModule::AddIndirectExportEntry(thread, module, indirectExportEntry2, 1, 2); - JSHandle indirectExportEntries(thread, module->GetIndirectExportEntries()); + JSHandle indirectExportEntries(thread, module->GetIndirectExportEntries(thread)); EXPECT_TRUE(indirectExportEntries->GetLength() == 2U); } @@ -243,7 +243,7 @@ HWTEST_F_L0(EcmaModuleTest, AddStarExportEntry) SourceTextModule::AddStarExportEntry(thread, module, starExportEntry1, 0, 2); JSHandle starExportEntry2 = objectFactory->NewStarExportEntry(); SourceTextModule::AddStarExportEntry(thread, module, starExportEntry2, 1, 2); - JSHandle startExportEntries(thread, module->GetStarExportEntries()); + JSHandle startExportEntries(thread, module->GetStarExportEntries(thread)); EXPECT_TRUE(startExportEntries->GetLength() == 2U); } @@ -787,7 +787,7 @@ HWTEST_F_L0(EcmaModuleTest, PreventExtensions_IsExtensible) SourceTextModule::AddLocalExportEntry(thread, module, localExportEntry1, 0, 2); JSHandle localExportEntry2 = objectFactory->NewLocalExportEntry(); SourceTextModule::AddLocalExportEntry(thread, module, localExportEntry2, 1, 2); - JSHandle localExportEntries(thread, module->GetLocalExportEntries()); + JSHandle localExportEntries(thread, module->GetLocalExportEntries(thread)); CString baseFileName = "a.abc"; module->SetEcmaModuleFilenameString(baseFileName); ModuleManager *moduleManager = thread->GetModuleManager(); @@ -1721,7 +1721,7 @@ HWTEST_F_L0(EcmaModuleTest, GetCurrentModuleName) JSNApi::Execute(instance, baseFileName, "module_test_module_test_module"); Local res = JSNApi::GetExportObject(instance, "module_test_module_test_module", "moduleName"); JSHandle result = JSNApiHelper::ToJSHandle(res); - CString moduleName = ConvertToString(result.GetTaggedValue()); + CString moduleName = ConvertToString(thread, result.GetTaggedValue()); EXPECT_EQ(moduleName, ""); } @@ -1750,7 +1750,7 @@ HWTEST_F_L0(EcmaModuleTest, IncreaseRegisterCounts2) increaseModule.insert("b"); module->SetSharedType(SharedTypes::SHARED_MODULE); ModuleDeregister::IncreaseRegisterCounts(thread, module, increaseModule); - EXPECT_EQ(module->GetModuleRequests().IsUndefined(), false); + EXPECT_EQ(module->GetModuleRequests(thread).IsUndefined(), false); } HWTEST_F_L0(EcmaModuleTest, DecreaseRegisterCounts2) @@ -1766,7 +1766,7 @@ HWTEST_F_L0(EcmaModuleTest, DecreaseRegisterCounts2) decreaseModule.insert("b"); module->SetSharedType(SharedTypes::SHARED_MODULE); ModuleDeregister::DecreaseRegisterCounts(thread, module, decreaseModule); - EXPECT_EQ(module->GetModuleRequests().IsUndefined(), false); + EXPECT_EQ(module->GetModuleRequests(thread).IsUndefined(), false); } HWTEST_F_L0(EcmaModuleTest, GenerateSendableFuncModule) @@ -2808,15 +2808,15 @@ HWTEST_F_L0(EcmaModuleTest, IncreaseRegisterCounts) std::set increaseModule; ModuleDeregister::IncreaseRegisterCounts(thread, module, increaseModule); - EXPECT_EQ(module->GetModuleRequests().IsUndefined(), false); + EXPECT_EQ(module->GetModuleRequests(thread).IsUndefined(), false); module->SetRegisterCounts(INT8_MAX); ModuleDeregister::IncreaseRegisterCounts(thread, module, increaseModule); - EXPECT_EQ(module->GetModuleRequests().IsUndefined(), false); + EXPECT_EQ(module->GetModuleRequests(thread).IsUndefined(), false); module2->SetRegisterCounts(INT8_MAX); ModuleDeregister::IncreaseRegisterCounts(thread, module2, increaseModule); - EXPECT_EQ(module2->GetModuleRequests().IsUndefined(), true); + EXPECT_EQ(module2->GetModuleRequests(thread).IsUndefined(), true); module2->SetLoadingTypes(LoadingTypes::STABLE_MODULE); ModuleDeregister::IncreaseRegisterCounts(thread, module2, increaseModule); @@ -2842,7 +2842,7 @@ HWTEST_F_L0(EcmaModuleTest, DecreaseRegisterCounts) module->SetRegisterCounts(INT8_MAX); ModuleDeregister::DecreaseRegisterCounts(thread, module, decreaseModule); - EXPECT_EQ(module->GetModuleRequests().IsUndefined(), false); + EXPECT_EQ(module->GetModuleRequests(thread).IsUndefined(), false); module2->SetLoadingTypes(LoadingTypes::DYNAMITC_MODULE); ModuleDeregister::DecreaseRegisterCounts(thread, module2, decreaseModule); diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index c30c1884b8..5ed7036c43 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -230,7 +230,7 @@ Local RegExpRef::GetOriginalSource(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue source = regExp->GetOriginalSource(); + JSTaggedValue source = regExp->GetOriginalSource(thread); if (!source.IsString()) { auto constants = thread->GlobalConstants(); return JSNApiHelper::ToLocal(constants->GetHandledEmptyString()); @@ -242,9 +242,10 @@ Local RegExpRef::GetOriginalSource(const EcmaVM *vm) std::string RegExpRef::GetOriginalFlags([[maybe_unused]] const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, ""); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue regExpFlags = regExp->GetOriginalFlags(); + JSTaggedValue regExpFlags = regExp->GetOriginalFlags(thread); uint32_t regExpFlagsInt = static_cast(regExpFlags.GetInt()); std::string strFlags = ""; if (regExpFlagsInt & RegExpParser::FLAG_GLOBAL) { @@ -275,7 +276,7 @@ Local RegExpRef::IsGlobal(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue flags = regExp->GetOriginalFlags(); + JSTaggedValue flags = regExp->GetOriginalFlags(thread); bool result = flags.GetInt() & RegExpParser::FLAG_GLOBAL; Local jsValue = BooleanRef::New(vm, result); return jsValue; @@ -287,7 +288,7 @@ Local RegExpRef::IsIgnoreCase(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue flags = regExp->GetOriginalFlags(); + JSTaggedValue flags = regExp->GetOriginalFlags(thread); bool result = flags.GetInt() & RegExpParser::FLAG_IGNORECASE; Local jsValue = BooleanRef::New(vm, result); return jsValue; @@ -299,7 +300,7 @@ Local RegExpRef::IsMultiline(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue flags = regExp->GetOriginalFlags(); + JSTaggedValue flags = regExp->GetOriginalFlags(thread); bool result = flags.GetInt() & RegExpParser::FLAG_MULTILINE; Local jsValue = BooleanRef::New(vm, result); return jsValue; @@ -311,7 +312,7 @@ Local RegExpRef::IsDotAll(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue flags = regExp->GetOriginalFlags(); + JSTaggedValue flags = regExp->GetOriginalFlags(thread); bool result = flags.GetInt() & RegExpParser::FLAG_DOTALL; Local jsValue = BooleanRef::New(vm, result); return jsValue; @@ -323,7 +324,7 @@ Local RegExpRef::IsUtf16(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue flags = regExp->GetOriginalFlags(); + JSTaggedValue flags = regExp->GetOriginalFlags(thread); bool result = flags.GetInt() & RegExpParser::FLAG_UTF16; Local jsValue = BooleanRef::New(vm, result); return jsValue; @@ -335,7 +336,7 @@ Local RegExpRef::IsStick(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle regExp(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(regExp, FATAL); - JSTaggedValue flags = regExp->GetOriginalFlags(); + JSTaggedValue flags = regExp->GetOriginalFlags(thread); bool result = flags.GetInt() & RegExpParser::FLAG_STICKY; Local jsValue = BooleanRef::New(vm, result); return jsValue; @@ -367,8 +368,8 @@ Local GeneratorObjectRef::GetGeneratorFunction(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle jsGenerator(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(jsGenerator, FATAL); - JSHandle generatorContext(thread, jsGenerator->GetGeneratorContext()); - JSTaggedValue jsTagValue = generatorContext->GetMethod(); + JSHandle generatorContext(thread, jsGenerator->GetGeneratorContext(thread)); + JSTaggedValue jsTagValue = generatorContext->GetMethod(thread); return JSNApiHelper::ToLocal(JSHandle(thread, jsTagValue)); } @@ -378,8 +379,8 @@ Local GeneratorObjectRef::GetGeneratorReceiver(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle jsGenerator(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(jsGenerator, FATAL); - JSHandle generatorContext(thread, jsGenerator->GetGeneratorContext()); - JSTaggedValue jsTagValue = generatorContext->GetAcc(); + JSHandle generatorContext(thread, jsGenerator->GetGeneratorContext(thread)); + JSTaggedValue jsTagValue = generatorContext->GetAcc(thread); return JSNApiHelper::ToLocal(JSHandle(thread, jsTagValue)); } @@ -390,7 +391,7 @@ Local CollatorRef::GetCompareFunction(const EcmaVM *vm) #ifdef ARK_SUPPORT_INTL JSHandle jsCollator(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(jsCollator, FATAL); - JSTaggedValue jsTagValue = jsCollator->GetBoundCompare(); + JSTaggedValue jsTagValue = jsCollator->GetBoundCompare(thread); return JSNApiHelper::ToLocal(JSHandle(thread, jsTagValue)); #else LOG_ECMA(ERROR) << "Not support arkcompiler intl"; @@ -405,7 +406,7 @@ Local DataTimeFormatRef::GetFormatFunction(const EcmaVM *vm) #ifdef ARK_SUPPORT_INTL JSHandle jsDateTimeFormat(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(jsDateTimeFormat, FATAL); - JSTaggedValue jsTagValue = jsDateTimeFormat->GetBoundFormat(); + JSTaggedValue jsTagValue = jsDateTimeFormat->GetBoundFormat(thread); return JSNApiHelper::ToLocal(JSHandle(thread, jsTagValue)); #else LOG_ECMA(ERROR) << "Not support arkcompiler intl"; @@ -420,7 +421,7 @@ Local NumberFormatRef::GetFormatFunction(const EcmaVM *vm) #ifdef ARK_SUPPORT_INTL JSHandle jsNumberFormat(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(jsNumberFormat, FATAL); - JSTaggedValue jsTagValue = jsNumberFormat->GetBoundFormat(); + JSTaggedValue jsTagValue = jsNumberFormat->GetBoundFormat(thread); return JSNApiHelper::ToLocal(JSHandle(thread, jsTagValue)); #else LOG_ECMA(ERROR) << "Not support arkcompiler intl"; @@ -440,7 +441,7 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *ecmaRu } [[maybe_unused]] LocalScope scope(thread->GetEcmaVM()); JSHandle function(constructor); - JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo(); + JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo(thread); if (!extraInfoValue.IsJSNativePointer()) { return JSTaggedValue::False(); } diff --git a/ecmascript/napi/jsnapi_expo.cpp b/ecmascript/napi/jsnapi_expo.cpp index fd0820ff6c..e4af56d89a 100644 --- a/ecmascript/napi/jsnapi_expo.cpp +++ b/ecmascript/napi/jsnapi_expo.cpp @@ -839,42 +839,47 @@ bool JSValueRef::IsJSPrimitiveRef(const EcmaVM *vm) bool JSValueRef::IsJSPrimitiveNumber(const EcmaVM *vm) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(obj, FATAL); - return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsNumber() : false; + return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsNumber(thread) : false; } bool JSValueRef::IsJSPrimitiveInt(const EcmaVM *vm) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(obj, FATAL); - return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsInt() : false; + return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsInt(thread) : false; } bool JSValueRef::IsJSPrimitiveBoolean(const EcmaVM *vm) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(obj, FATAL); - return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsBoolean() : false; + return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsBoolean(thread) : false; } bool JSValueRef::IsJSPrimitiveString(const EcmaVM *vm) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(obj, FATAL); - return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsString() : false; + return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsString(thread) : false; } bool JSValueRef::IsJSPrimitiveSymbol(const EcmaVM *vm) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle obj = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(obj, FATAL); - return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsSymbol() : false; + return IsJSPrimitiveRef(vm) ? JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsSymbol(thread) : false; } bool JSValueRef::IsGeneratorObject(const EcmaVM *vm) @@ -969,10 +974,11 @@ bool JSValueRef::IsAsyncFunction(const EcmaVM *vm) bool JSValueRef::IsConcurrentFunction(const EcmaVM *vm) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle funcVal = JSNApiHelper::ToJSHandle(this); JSHandle transFunc = JSHandle::Cast(funcVal); - return transFunc->GetFunctionKind() == ecmascript::FunctionKind::CONCURRENT_FUNCTION; + return transFunc->GetFunctionKind(thread) == ecmascript::FunctionKind::CONCURRENT_FUNCTION; } bool JSValueRef::IsArgumentsObject(const EcmaVM *vm) @@ -1158,7 +1164,8 @@ void *JSValueRef::GetNativePointerValueImpl(const EcmaVM* vm, bool &isNativePoin bool JSValueRef::IsDetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer) { - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); // arraybuffer is not shared. Do not need to switch state if (!IsArrayBuffer(vm)) { isArrayBuffer = false; @@ -1166,7 +1173,7 @@ bool JSValueRef::IsDetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer) } isArrayBuffer = true; JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - return arrayBuffer->IsDetach(); + return arrayBuffer->IsDetach(thread); } void JSValueRef::DetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer) @@ -1175,14 +1182,14 @@ void JSValueRef::DetachedArraybuffer(const EcmaVM *vm, bool &isArrayBuffer) ecmascript::ThreadManagedScope managedScope(thread); if (IsArrayBuffer(vm)) { JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - if (arrayBuffer->IsDetach()) { + if (arrayBuffer->IsDetach(thread)) { return; } arrayBuffer->Detach(thread); isArrayBuffer = true; } else if (IsSendableArrayBuffer(vm)) { JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - if (arrayBuffer->IsDetach()) { + if (arrayBuffer->IsDetach(thread)) { return; } arrayBuffer->Detach(thread); @@ -1212,9 +1219,9 @@ void JSValueRef::GetDataViewInfo(const EcmaVM *vm, *byteLength = dataView->GetByteLength(); } if (data || arrayBuffer) { - JSHandle retArrayBuffer(thread, dataView->GetViewedArrayBuffer()); + JSHandle retArrayBuffer(thread, dataView->GetViewedArrayBuffer(thread)); if (data) { - JSTaggedValue bufferData = retArrayBuffer->GetArrayBufferData(); + JSTaggedValue bufferData = retArrayBuffer->GetArrayBufferData(thread); if (!bufferData.IsJSNativePointer()) { *data = nullptr; } @@ -1290,7 +1297,7 @@ Local DataViewRef::GetArrayBuffer(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle dataView(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(dataView, FATAL); - JSHandle arrayBuffer(thread, dataView->GetViewedArrayBuffer()); + JSHandle arrayBuffer(thread, dataView->GetViewedArrayBuffer(thread)); return JSNApiHelper::ToLocal(arrayBuffer); } // ---------------------------------- DataView ----------------------------------- @@ -1303,7 +1310,7 @@ Local PrimitiveRef::GetValue(const EcmaVM *vm) JSHandle obj = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(obj, ERROR); if (obj->IsJSPrimitiveRef()) { - JSTaggedValue primitiveValue = JSPrimitiveRef::Cast(obj->GetTaggedObject())->GetValue(); + JSTaggedValue primitiveValue = JSPrimitiveRef::Cast(obj->GetTaggedObject())->GetValue(thread); JSHandle value(thread, primitiveValue); return JSNApiHelper::ToLocal(value); } @@ -1450,18 +1457,20 @@ Local MapRef::New(const EcmaVM *vm) int32_t MapRef::GetSize(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle map(JSNApiHelper::ToJSHandle(this)); - return map->GetSize(); + return map->GetSize(thread); } int32_t MapRef::GetTotalElements(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle map(JSNApiHelper::ToJSHandle(this)); - return static_cast((map->GetSize())) + - LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->NumberOfDeletedElements(); + return static_cast((map->GetSize(thread))) + + LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->NumberOfDeletedElements(); } Local MapRef::GetKey(const EcmaVM *vm, int entry) @@ -1470,7 +1479,7 @@ Local MapRef::GetKey(const EcmaVM *vm, int entry) ecmascript::ThreadManagedScope managedScope(thread); JSHandle map(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(map, FATAL); - return JSNApiHelper::ToLocal(JSHandle(thread, map->GetKey(entry))); + return JSNApiHelper::ToLocal(JSHandle(thread, map->GetKey(thread, entry))); } Local MapRef::GetValue(const EcmaVM *vm, int entry) @@ -1479,7 +1488,7 @@ Local MapRef::GetValue(const EcmaVM *vm, int entry) ecmascript::ThreadManagedScope managedScope(thread); JSHandle map(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(map, FATAL); - return JSNApiHelper::ToLocal(JSHandle(thread, map->GetValue(entry))); + return JSNApiHelper::ToLocal(JSHandle(thread, map->GetValue(thread, entry))); } Local MapRef::GetEntries(const EcmaVM *vm) @@ -1622,7 +1631,7 @@ uint32_t SendableMapRef::GetTotalElements(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle map(JSNApiHelper::ToJSHandle(this)); return static_cast(ecmascript::JSSharedMap::GetSize(thread, map)) + - LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->NumberOfDeletedElements(); + LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->NumberOfDeletedElements(); } Local SendableMapRef::GetKey(const EcmaVM *vm, int entry) @@ -1713,7 +1722,7 @@ uint32_t SendableSetRef::GetTotalElements(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle set(JSNApiHelper::ToJSHandle(this)); return static_cast(ecmascript::JSSharedSet::GetSize(thread, set)) + - LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())->NumberOfDeletedElements(); + LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())->NumberOfDeletedElements(); } Local SendableSetRef::GetValue(const EcmaVM *vm, int entry) @@ -1785,7 +1794,7 @@ ecmascript::EcmaRuntimeCallInfo *MapIteratorRef::GetEcmaRuntimeCallInfo(const Ec CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, nullptr); ecmascript::ThreadManagedScope managedScope(thread); JSHandle jsMapIter(JSNApiHelper::ToJSHandle(this)); - JSHandle linkedHashMap(thread, jsMapIter->GetIteratedMap()); + JSHandle linkedHashMap(thread, jsMapIter->GetIteratedMap(thread)); uint32_t size = linkedHashMap->GetLength(); return ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(thread, JSTaggedValue::Undefined()), @@ -1873,7 +1882,7 @@ ecmascript::EcmaRuntimeCallInfo *SetIteratorRef::GetEcmaRuntimeCallInfo(const Ec CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, nullptr); ecmascript::ThreadManagedScope managedScope(thread); JSHandle jsSetIter(JSNApiHelper::ToJSHandle(this)); - JSHandle linkedHashSet(thread, jsSetIter->GetIteratedSet()); + JSHandle linkedHashSet(thread, jsSetIter->GetIteratedSet(thread)); uint32_t size = linkedHashSet->GetLength(); return ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(thread, JSTaggedValue::Undefined()), @@ -1950,7 +1959,7 @@ void *BufferRef::GetBuffer(const EcmaVM *vm) DCHECK_SPECIAL_VALUE_WITH_RETURN(this, nullptr); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(); + JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(vm->GetJSThread()); if (!bufferData.IsJSNativePointer()) { return nullptr; } @@ -1967,7 +1976,7 @@ JSTaggedValue BufferRef::BufferToStringCallback(ecmascript::EcmaRuntimeCallInfo JSHandle arrayBuffer(arrayBuff); uint32_t length = arrayBuffer->GetArrayBufferByteLength(); - JSTaggedValue data = arrayBuffer->GetArrayBufferData(); + JSTaggedValue data = arrayBuffer->GetArrayBufferData(thread); ecmascript::CVector valueTable; valueTable.reserve(length); @@ -2010,7 +2019,7 @@ Local PromiseCapabilityRef::GetPromise(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle capacity(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(capacity, FATAL); - return JSNApiHelper::ToLocal(JSHandle(thread, capacity->GetPromise())); + return JSNApiHelper::ToLocal(JSHandle(thread, capacity->GetPromise(thread))); } bool PromiseCapabilityRef::Resolve(const EcmaVM *vm, uintptr_t value) @@ -2025,7 +2034,7 @@ bool PromiseCapabilityRef::Resolve(const EcmaVM *vm, uintptr_t value) #endif JSHandle capacity(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(capacity, FATAL); - JSTaggedValue resolve = capacity->GetResolve(); + JSTaggedValue resolve = capacity->GetResolve(thread); JSTaggedValue undefined = constants->GetUndefined(); EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); @@ -2052,7 +2061,7 @@ bool PromiseCapabilityRef::Resolve(const EcmaVM *vm, Local value) #endif JSHandle capacity(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(capacity, FATAL); - JSHandle resolve(thread, capacity->GetResolve()); + JSHandle resolve(thread, capacity->GetResolve(thread)); JSHandle undefined(constants->GetHandledUndefined()); EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); @@ -2079,7 +2088,7 @@ bool PromiseCapabilityRef::Reject(const EcmaVM *vm, uintptr_t reason) #endif JSHandle capacity(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(capacity, FATAL); - JSTaggedValue reject = capacity->GetReject(); + JSTaggedValue reject = capacity->GetReject(thread); JSTaggedValue undefined = constants->GetUndefined(); EcmaRuntimeCallInfo *info = @@ -2107,7 +2116,7 @@ bool PromiseCapabilityRef::Reject(const EcmaVM *vm, Local reason) #endif JSHandle capacity(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(capacity, FATAL); - JSHandle reject(thread, capacity->GetReject()); + JSHandle reject(thread, capacity->GetReject(thread)); JSHandle undefined(constants->GetHandledUndefined()); EcmaRuntimeCallInfo *info = @@ -2144,7 +2153,7 @@ Local SymbolRef::GetDescription(const EcmaVM *vm) CROSS_THREAD_CHECK(vm); ecmascript::ThreadManagedScope managedScope(thread); JSTaggedValue description = JSSymbol::Cast( - JSNApiHelper::ToJSTaggedValue(this).GetTaggedObject())->GetDescription(); + JSNApiHelper::ToJSTaggedValue(this).GetTaggedObject())->GetDescription(thread); if (!description.IsString()) { auto constants = thread->GlobalConstants(); return JSNApiHelper::ToLocal(constants->GetHandledEmptyString()); @@ -2237,14 +2246,14 @@ std::string StringRef::ToString(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, ""); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); - return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)).ToStdString(); + return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)).ToStdString(vm->GetJSThread()); } std::string StringRef::DebuggerToString(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, ""); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); - return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)).DebuggerToStdString(); + return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)).DebuggerToStdString(vm->GetJSThread()); } uint32_t StringRef::Length(const EcmaVM *vm) @@ -2260,15 +2269,16 @@ size_t StringRef::Utf8Length(const EcmaVM *vm, bool isGetBufferSize) auto thread = vm->GetJSThread(); ecmascript::ThreadManagedScope managedScope(thread); JSHandle strHandle(thread, EcmaString::Cast(JSNApiHelper::ToJSTaggedValue(this))); - return EcmaStringAccessor(EcmaStringAccessor::Flatten(vm, strHandle)).GetUtf8Length(isGetBufferSize); + return EcmaStringAccessor(EcmaStringAccessor::Flatten(vm, strHandle)).GetUtf8Length(thread, isGetBufferSize); } uint32_t StringRef::WriteUtf8(const EcmaVM *vm, char *buffer, uint32_t length, bool isWriteBuffer) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)) - .WriteToFlatUtf8(reinterpret_cast(buffer), length, isWriteBuffer); + .WriteToFlatUtf8(thread, reinterpret_cast(buffer), length, isWriteBuffer); } uint32_t StringRef::WriteUtf16(const EcmaVM *vm, char16_t *buffer, uint32_t length) @@ -2276,7 +2286,7 @@ uint32_t StringRef::WriteUtf16(const EcmaVM *vm, char16_t *buffer, uint32_t leng DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)) - .WriteToUtf16(reinterpret_cast(buffer), length); + .WriteToUtf16(vm->GetJSThread(), reinterpret_cast(buffer), length); } uint32_t StringRef::WriteLatin1(const EcmaVM *vm, char *buffer, uint32_t length) @@ -2284,7 +2294,7 @@ uint32_t StringRef::WriteLatin1(const EcmaVM *vm, char *buffer, uint32_t length) DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); return EcmaStringAccessor(JSNApiHelper::ToJSTaggedValue(this)) - .WriteToOneByte(reinterpret_cast(buffer), length); + .WriteToOneByte(vm->GetJSThread(), reinterpret_cast(buffer), length); } Local StringRef::GetNapiWrapperString(const EcmaVM *vm) @@ -2310,12 +2320,12 @@ Local StringRef::EncodeIntoUint8Array(const EcmaVM *vm) JSHandle obj = TypedArrayHelper::FastCreateTypedArray(thread, thread->GlobalConstants()->GetHandledUint8ArrayString(), length - 1, DataViewType::UINT8); - JSHandle arrayBuffer(thread, JSTypedArray::Cast(*obj)->GetViewedArrayBufferOrByteArray()); - JSTaggedValue bufferData = JSHandle::Cast(arrayBuffer)->GetArrayBufferData(); + JSHandle arrayBuffer(thread, JSTypedArray::Cast(*obj)->GetViewedArrayBufferOrByteArray(thread)); + JSTaggedValue bufferData = JSHandle::Cast(arrayBuffer)->GetArrayBufferData(thread); void *buffer = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); JSHandle stringHandle = JSHandle::Cast(string); - EcmaStringAccessor(stringHandle).WriteToFlatUtf8(reinterpret_cast(buffer), length - 1, true); + EcmaStringAccessor(stringHandle).WriteToFlatUtf8(thread, reinterpret_cast(buffer), length - 1, true); JSHandle typedArrayTag = JSHandle::Cast(obj); return JSNApiHelper::ToLocal(typedArrayTag); } @@ -3060,7 +3070,7 @@ int32_t ObjectRef::GetNativePointerFieldCount(const EcmaVM *vm) DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle object(JSNApiHelper::ToJSHandle(this)); - return object->GetNativePointerFieldCount(); + return object->GetNativePointerFieldCount(vm->GetJSThread()); } void *ObjectRef::GetNativePointerField(const EcmaVM *vm, int32_t index) @@ -3070,7 +3080,7 @@ void *ObjectRef::GetNativePointerField(const EcmaVM *vm, int32_t index) DCHECK_SPECIAL_VALUE_WITH_RETURN(this, nullptr); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle object(JSNApiHelper::ToJSHandle(this)); - return object->GetNativePointerField(index); + return object->GetNativePointerField(vm->GetJSThread(), index); } void ObjectRef::SetNativePointerField(const EcmaVM *vm, int32_t index, void *nativePointer, @@ -3183,7 +3193,7 @@ void *ArrayBufferRef::GetBuffer(const EcmaVM *vm) DCHECK_SPECIAL_VALUE_WITH_RETURN(this, nullptr); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(); + JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(vm->GetJSThread()); if (!bufferData.IsJSNativePointer()) { return nullptr; } @@ -3202,9 +3212,10 @@ void ArrayBufferRef::Detach(const EcmaVM *vm) bool ArrayBufferRef::IsDetach(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, false); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - return arrayBuffer->IsDetach(); + return arrayBuffer->IsDetach(thread); } Local SendableArrayBufferRef::New(const EcmaVM *vm, int32_t length) @@ -3247,9 +3258,10 @@ void SendableArrayBufferRef::Detach(const EcmaVM *vm) bool SendableArrayBufferRef::IsDetach(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, false); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - return arrayBuffer->IsDetach(); + return arrayBuffer->IsDetach(thread); } void *SendableArrayBufferRef::GetBuffer(const EcmaVM *vm) @@ -3257,7 +3269,7 @@ void *SendableArrayBufferRef::GetBuffer(const EcmaVM *vm) DCHECK_SPECIAL_VALUE_WITH_RETURN(this, nullptr); ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(this)); - JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(); + JSTaggedValue bufferData = arrayBuffer->GetArrayBufferData(vm->GetJSThread()); if (!bufferData.IsJSNativePointer()) { return nullptr; } @@ -3300,7 +3312,7 @@ double DateRef::GetTime(const EcmaVM *vm) if (!date->IsDate()) { LOG_ECMA(ERROR) << "Not a Date Object"; } - return date->GetTime().GetDouble(); + return date->GetTime(vm->GetJSThread()).GetDouble(); } // ---------------------------------- TypedArray ----------------------------------- @@ -3651,7 +3663,7 @@ Local FunctionRef::NewSendableClassFunction(const EcmaVM *vm, JSHClass *parentIHClass{nullptr}; if (!parent->IsHole() && !parent->IsNull()) { JSHandle parentHandle(JSNApiHelper::ToJSHandle(parent)); - parentIHClass = reinterpret_cast(parentHandle->GetProtoOrHClass().GetTaggedObject()); + parentIHClass = reinterpret_cast(parentHandle->GetProtoOrHClass(thread).GetTaggedObject()); } JSHandle iHClass = JSHClass::CreateSHClass(thread, sendable.GetInstanceDescs(), parentIHClass); iHClass->SetPrototype(thread, JSHandle(prototype)); @@ -3837,7 +3849,7 @@ Local FunctionRef::GetFunctionPrototype(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle func = JSNApiHelper::ToJSHandle(this); LOG_IF_SPECIAL(func, FATAL); - JSHandle prototype(thread, JSHandle(func)->GetFunctionPrototype()); + JSHandle prototype(thread, JSHandle(func)->GetFunctionPrototype(thread)); return JSNApiHelper::ToLocal(prototype); } @@ -3888,13 +3900,13 @@ Local FunctionRef::GetSourceCode(const EcmaVM *vm, int lineNumber) ecmascript::ThreadManagedScope managedScope(thread); EscapeLocalScope scope(vm); JSHandle func(thread, JSNApiHelper::ToJSTaggedValue(this)); - JSHandle method(thread, func->GetMethod()); - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + JSHandle method(thread, func->GetMethod(thread)); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); DebugInfoExtractor *debugExtractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(jsPandaFile); ecmascript::CString entry = JSPandaFile::ENTRY_FUNCTION_NAME; if (!jsPandaFile->IsBundlePack()) { JSFunction *function = JSFunction::Cast(func.GetTaggedValue().GetTaggedObject()); - ecmascript::CString recordName = function->GetRecordName(); + ecmascript::CString recordName = function->GetRecordName(thread); ASSERT(!recordName.empty()); entry = recordName; } @@ -3924,7 +3936,7 @@ bool FunctionRef::IsNative(const EcmaVM *vm) CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, false); ecmascript::ThreadManagedScope managedScope(thread); JSHandle func(thread, JSNApiHelper::ToJSTaggedValue(this)); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); return method->IsNativeWithCallField(); } @@ -3947,7 +3959,7 @@ void* FunctionRef::GetData(const EcmaVM *vm) ecmascript::ThreadManagedScope managedScope(thread); JSHandle funcValue = JSNApiHelper::ToJSHandle(this); JSHandle function(funcValue); - JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo(); + JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo(thread); if (!extraInfoValue.IsNativePointer()) { return nullptr; } @@ -4157,7 +4169,7 @@ void *JsiRuntimeCallInfo::GetData() return nullptr; } JSHandle function(constructor); - JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo(); + JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo(thread_); if (!extraInfoValue.IsJSNativePointer()) { return nullptr; } @@ -4436,7 +4448,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local function, v [[maybe_unused]] LocalScope scope(vm); JSHandle funcVal = JSNApiHelper::ToJSHandle(function); JSHandle transFunc = JSHandle::Cast(funcVal); - if (transFunc->GetFunctionKind() != ecmascript::FunctionKind::CONCURRENT_FUNCTION) { + if (transFunc->GetFunctionKind(thread) != ecmascript::FunctionKind::CONCURRENT_FUNCTION) { LOG_ECMA(ERROR) << "Function is not concurrent"; return false; } @@ -4756,7 +4768,7 @@ void JSNApi::PrintExceptionInfo(const EcmaVM *vm) return; } JSHandle result = JSTaggedValue::ToString(thread, exceptionHandle); - ecmascript::CString string = ConvertToString(*result); + ecmascript::CString string = ConvertToString(thread, *result); LOG_ECMA(ERROR) << string; ThrowException(vm, exception); } @@ -6417,7 +6429,7 @@ Local PromiseRef::GetPromiseResult(const EcmaVM *vm) JSHandle promise(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(promise, ERROR); - return JSNApiHelper::ToLocal(JSHandle(thread, promise->GetPromiseResult())); + return JSNApiHelper::ToLocal(JSHandle(thread, promise->GetPromiseResult(thread))); } // ---------------------------------- ProxyRef ----------------------------------------- Local ProxyRef::GetHandler(const EcmaVM *vm) @@ -6425,7 +6437,7 @@ Local ProxyRef::GetHandler(const EcmaVM *vm) CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); ecmascript::ThreadManagedScope scope(thread); JSHandle jsProxy(JSNApiHelper::ToJSHandle(this)); - return JSNApiHelper::ToLocal(JSHandle(thread, jsProxy->GetHandler())); + return JSNApiHelper::ToLocal(JSHandle(thread, jsProxy->GetHandler(thread))); } Local ProxyRef::GetTarget(const EcmaVM *vm) @@ -6433,7 +6445,7 @@ Local ProxyRef::GetTarget(const EcmaVM *vm) CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); ecmascript::ThreadManagedScope scope(thread); JSHandle jsProxy(JSNApiHelper::ToJSHandle(this)); - return JSNApiHelper::ToLocal(JSHandle(thread, jsProxy->GetTarget())); + return JSNApiHelper::ToLocal(JSHandle(thread, jsProxy->GetTarget(thread))); } bool ProxyRef::IsRevoked() @@ -6447,18 +6459,20 @@ bool ProxyRef::IsRevoked() int32_t SetRef::GetSize(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle set(JSNApiHelper::ToJSHandle(this)); - return set->GetSize(); + return set->GetSize(thread); } int32_t SetRef::GetTotalElements(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle set(JSNApiHelper::ToJSHandle(this)); - return static_cast(set->GetSize()) + - LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())->NumberOfDeletedElements(); + return static_cast(set->GetSize(thread)) + + LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())->NumberOfDeletedElements(); } Local SetRef::GetValue(const EcmaVM *vm, int entry) @@ -6467,7 +6481,7 @@ Local SetRef::GetValue(const EcmaVM *vm, int entry) ecmascript::ThreadManagedScope managedScope(thread); JSHandle set(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(set, FATAL); - return JSNApiHelper::ToLocal(JSHandle(thread, set->GetValue(entry))); + return JSNApiHelper::ToLocal(JSHandle(thread, set->GetValue(thread, entry))); } Local SetRef::New(const EcmaVM *vm) @@ -6498,18 +6512,20 @@ void SetRef::Add(const EcmaVM *vm, Local value) int32_t WeakMapRef::GetSize(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle weakMap(JSNApiHelper::ToJSHandle(this)); - return weakMap->GetSize(); + return weakMap->GetSize(thread); } int32_t WeakMapRef::GetTotalElements(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle weakMap(JSNApiHelper::ToJSHandle(this)); - return weakMap->GetSize() + - LinkedHashMap::Cast(weakMap->GetLinkedMap().GetTaggedObject())->NumberOfDeletedElements(); + return weakMap->GetSize(thread) + + LinkedHashMap::Cast(weakMap->GetLinkedMap(thread).GetTaggedObject())->NumberOfDeletedElements(); } Local WeakMapRef::GetKey(const EcmaVM *vm, int entry) @@ -6518,7 +6534,7 @@ Local WeakMapRef::GetKey(const EcmaVM *vm, int entry) ecmascript::ThreadManagedScope managedScope(thread); JSHandle weakMap(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(weakMap, FATAL); - JSTaggedValue key = weakMap->GetKey(entry); + JSTaggedValue key = weakMap->GetKey(thread, entry); return JSNApiHelper::ToLocal(JSHandle(thread, key.GetWeakRawValue())); } @@ -6527,7 +6543,7 @@ Local WeakMapRef::GetValue(const EcmaVM *vm, int entry) CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm)); JSHandle weakMap(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(weakMap, FATAL); - return JSNApiHelper::ToLocal(JSHandle(thread, weakMap->GetValue(entry))); + return JSNApiHelper::ToLocal(JSHandle(thread, weakMap->GetValue(thread, entry))); } Local WeakMapRef::New(const EcmaVM *vm) @@ -6567,18 +6583,20 @@ bool WeakMapRef::Has(const EcmaVM *vm, Local key) int32_t WeakSetRef::GetSize(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle weakSet(JSNApiHelper::ToJSHandle(this)); - return weakSet->GetSize(); + return weakSet->GetSize(thread); } int32_t WeakSetRef::GetTotalElements(const EcmaVM *vm) { DCHECK_SPECIAL_VALUE_WITH_RETURN(this, 0); - ecmascript::ThreadManagedScope managedScope(vm->GetJSThread()); + JSThread *thread = vm->GetJSThread(); + ecmascript::ThreadManagedScope managedScope(thread); JSHandle weakSet(JSNApiHelper::ToJSHandle(this)); - return weakSet->GetSize() + - LinkedHashSet::Cast(weakSet->GetLinkedSet().GetTaggedObject())->NumberOfDeletedElements(); + return weakSet->GetSize(thread) + + LinkedHashSet::Cast(weakSet->GetLinkedSet(thread).GetTaggedObject())->NumberOfDeletedElements(); } Local WeakSetRef::GetValue(const EcmaVM *vm, int entry) @@ -6587,7 +6605,7 @@ Local WeakSetRef::GetValue(const EcmaVM *vm, int entry) ecmascript::ThreadManagedScope managedScope(thread); JSHandle weakSet(JSNApiHelper::ToJSHandle(this)); LOG_IF_SPECIAL(weakSet, FATAL); - JSTaggedValue value = weakSet->GetValue(entry); + JSTaggedValue value = weakSet->GetValue(thread, entry); return JSNApiHelper::ToLocal(JSHandle(thread, value.GetWeakRawValue())); } diff --git a/ecmascript/napi/test/ffi_workload.cpp b/ecmascript/napi/test/ffi_workload.cpp index 0085b291a4..a191cfa111 100644 --- a/ecmascript/napi/test/ffi_workload.cpp +++ b/ecmascript/napi/test/ffi_workload.cpp @@ -699,7 +699,7 @@ HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayList) JSHandle proto = globalEnv->GetFunctionPrototype(); JSHandle arrayListClass = factory->NewEcmaHClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto); JSHandle jsArrayList = JSHandle::Cast(factory->NewJSObjectWithInit(arrayListClass)); - jsArrayList->SetLength(thread, JSTaggedValue(0)); + jsArrayList->SetLength(0); JSHandle arryListTag = JSHandle::Cast(jsArrayList); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { diff --git a/ecmascript/napi/test/jsnapi_first_tests.cpp b/ecmascript/napi/test/jsnapi_first_tests.cpp index 1b1fb02687..fc1e525d29 100644 --- a/ecmascript/napi/test/jsnapi_first_tests.cpp +++ b/ecmascript/napi/test/jsnapi_first_tests.cpp @@ -1164,15 +1164,15 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_001) // new with Builtins::Map Prototype JSHandle map = env->GetBuiltinsMapFunction(); Local mapLocal = JSNApiHelper::ToLocal(map); - JSHandle setPrototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype()); - JSHandle mapPrototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype()); + JSHandle setPrototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype(thread_)); + JSHandle mapPrototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype(thread_)); JSHandle mapPrototypeProto(thread_, JSTaggedValue::GetPrototype(thread_, mapPrototype)); - bool same = JSTaggedValue::SameValue(setPrototype, mapPrototypeProto); + bool same = JSTaggedValue::SameValue(thread_, setPrototype, mapPrototypeProto); // before inherit, map.Prototype.__proto__ should be different from set.Prototype ASSERT_FALSE(same); // before inherit, map.__proto__ should be different from set JSHandle mapProto(thread_, JSTaggedValue::GetPrototype(thread_, map)); - bool same1 = JSTaggedValue::SameValue(set, mapProto); + bool same1 = JSTaggedValue::SameValue(thread_, set, mapProto); ASSERT_FALSE(same1); // Set property to Set Function @@ -1189,12 +1189,12 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_001) mapLocal->Inherit(vm_, setLocal); JSHandle sonHandle = JSNApiHelper::ToJSHandle(mapLocal); - JSHandle sonPrototype(thread_, JSHandle::Cast(sonHandle)->GetFunctionPrototype()); + JSHandle sonPrototype(thread_, JSHandle::Cast(sonHandle)->GetFunctionPrototype(thread_)); JSHandle sonPrototypeProto(thread_, JSTaggedValue::GetPrototype(thread_, sonPrototype)); - bool same2 = JSTaggedValue::SameValue(setPrototype, sonPrototypeProto); + bool same2 = JSTaggedValue::SameValue(thread_, setPrototype, sonPrototypeProto); ASSERT_TRUE(same2); JSHandle sonProto(thread_, JSTaggedValue::GetPrototype(thread_, map)); - bool same3 = JSTaggedValue::SameValue(set, sonProto); + bool same3 = JSTaggedValue::SameValue(thread_, set, sonProto); ASSERT_TRUE(same3); // son = new Son(), Son() inherit from Parent(), Test whether son.InstanceOf(Parent) is true @@ -1204,17 +1204,17 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_001) // Test whether son Function can access to property of parent Function OperationResult res = JSObject::GetProperty(thread_, JSHandle::Cast(sonHandle), defaultString); - bool same4 = JSTaggedValue::SameValue(defaultString, res.GetValue()); + bool same4 = JSTaggedValue::SameValue(thread_, defaultString, res.GetValue()); ASSERT_TRUE(same4); OperationResult res1 = JSObject::GetProperty(thread_, JSHandle::Cast(sonHandle), property1String); - bool same5 = JSTaggedValue::SameValue(func, res1.GetValue()); + bool same5 = JSTaggedValue::SameValue(thread_, func, res1.GetValue()); ASSERT_TRUE(same5); // new with empty Function Constructor Local son1 = FunctionRef::New(vm_, FunctionCallback, nullptr); son1->Inherit(vm_, mapLocal); JSHandle son1Handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(son1)); - ASSERT_TRUE(son1Handle->HasFunctionPrototype()); + ASSERT_TRUE(son1Handle->HasFunctionPrototype(thread_)); } HWTEST_F_L0(JSNApiTests, InheritPrototype_002) @@ -1248,7 +1248,7 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_002) JSHandle sonMethod = JSObject::GetMethod(thread_, JSHandle(sonObj), property1String); JSHandle fatherMethod = JSObject::GetMethod(thread_, JSHandle(fatherObj), property1String); - bool same = JSTaggedValue::SameValue(sonMethod, fatherMethod); + bool same = JSTaggedValue::SameValue(thread_, sonMethod, fatherMethod); ASSERT_TRUE(same); } @@ -1271,7 +1271,7 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_003) Local noProtoLocal = JSNApiHelper::ToLocal(JSHandle(noProtoFunc)); JSHandle sonHandle = JSHandle::Cast(JSNApiHelper::ToJSHandle(noProtoLocal)); - EXPECT_FALSE(sonHandle->HasFunctionPrototype()); + EXPECT_FALSE(sonHandle->HasFunctionPrototype(thread_)); JSHandle defaultString = thread_->GlobalConstants()->GetHandledDefaultString(); PropertyDescriptor desc = PropertyDescriptor(thread_, defaultString); @@ -1279,17 +1279,17 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_003) noProtoLocal->Inherit(vm_, protoLocal); JSHandle son1Handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(noProtoLocal)); - EXPECT_TRUE(son1Handle->HasFunctionPrototype()); + EXPECT_TRUE(son1Handle->HasFunctionPrototype(thread_)); OperationResult res = JSObject::GetProperty(thread_, JSHandle::Cast(son1Handle), defaultString); - EXPECT_EQ(JSTaggedValue::SameValue(defaultString, res.GetValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread_, defaultString, res.GetValue()), true); JSHandle propertyString(thread_, factory->NewFromASCII("property").GetTaggedValue()); JSHandle func = env->GetArrayFunction(); PropertyDescriptor desc1 = PropertyDescriptor(thread_, func); JSObject::DefineOwnProperty(thread_, JSHandle::Cast(protoFunc), propertyString, desc1); OperationResult res1 = JSObject::GetProperty(thread_, JSHandle::Cast(son1Handle), propertyString); - EXPECT_EQ(JSTaggedValue::SameValue(func, res1.GetValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread_, func, res1.GetValue()), true); } HWTEST_F_L0(JSNApiTests, InheritPrototype_004) @@ -1349,10 +1349,10 @@ HWTEST_F_L0(JSNApiTests, InheritPrototype_004) JSHandle sonHandle = JSHandle::Cast(JSNApiHelper::ToJSHandle(noProtoLocal)); OperationResult res = JSObject::GetProperty(thread_, JSHandle::Cast(sonHandle), deleteString); - EXPECT_EQ(JSTaggedValue::SameValue(deleteMethod, res.GetValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread_, deleteMethod, res.GetValue()), true); // test if the property value changed after inherit OperationResult res1 = JSObject::GetProperty(thread_, JSHandle::Cast(sonHandle), addString); - EXPECT_EQ(JSTaggedValue::SameValue(defaultString, res1.GetValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread_, defaultString, res1.GetValue()), true); } HWTEST_F_L0(JSNApiTests, ClassFunction) @@ -1364,10 +1364,10 @@ HWTEST_F_L0(JSNApiTests, ClassFunction) ASSERT_TRUE(clsObj->IsClassConstructor()); JSTaggedValue accessor = - JSHandle(clsObj)->GetPropertyInlinedProps(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX); + JSHandle(clsObj)->GetPropertyInlinedProps(thread_, JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX); ASSERT_TRUE(accessor.IsInternalAccessor()); - accessor = JSHandle(clsObj)->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX); + accessor = JSHandle(clsObj)->GetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX); ASSERT_TRUE(!accessor.IsUndefinedOrNull()); } @@ -1431,8 +1431,8 @@ HWTEST_F_L0(JSNApiTests, TriggerGC_OLD_GC) JSHandle taggedArray = factory->NewTaggedArray(arrayLength); taggedArray->Set(thread_, 0, objVal1); taggedArray->Set(thread_, 1, canBeGcValue); - EXPECT_EQ(taggedArray->GetIdx(objVal1.GetTaggedValue()), 0U); - EXPECT_EQ(taggedArray->GetIdx(canBeGcValue), 1U); + EXPECT_EQ(taggedArray->GetIdx(thread_, objVal1.GetTaggedValue()), 0U); + EXPECT_EQ(taggedArray->GetIdx(thread_, canBeGcValue), 1U); // trigger gc JSNApi::TRIGGER_GC_TYPE gcType = JSNApi::TRIGGER_GC_TYPE::OLD_GC; @@ -1442,8 +1442,8 @@ HWTEST_F_L0(JSNApiTests, TriggerGC_OLD_GC) gcType = JSNApi::TRIGGER_GC_TYPE::SHARED_FULL_GC; JSNApi::TriggerGC(vm_, gcType); - EXPECT_EQ(taggedArray->GetIdx(objVal1.GetTaggedValue()), 0U); - EXPECT_EQ(taggedArray->GetIdx(canBeGcValue), TaggedArray::MAX_ARRAY_INDEX); + EXPECT_EQ(taggedArray->GetIdx(thread_, objVal1.GetTaggedValue()), 0U); + EXPECT_EQ(taggedArray->GetIdx(thread_, canBeGcValue), TaggedArray::MAX_ARRAY_INDEX); ASSERT_EQ("1", origin->ToString(vm_)); vm_->SetEnableForceGC(true); @@ -2232,21 +2232,21 @@ HWTEST_F_L0(JSNApiTests, FunctionRef_New_GetFunctionPrototype) Local setLocal = JSNApiHelper::ToLocal(set); JSHandle map = env->GetBuiltinsMapFunction(); Local mapLocal = JSNApiHelper::ToLocal(map); - JSHandle setPrototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype()); - JSHandle mapPrototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype()); + JSHandle setPrototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype(thread_)); + JSHandle mapPrototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype(thread_)); JSHandle mapPrototypeProto(thread_, JSTaggedValue::GetPrototype(thread_, mapPrototype)); - bool same = JSTaggedValue::SameValue(setPrototype, mapPrototypeProto); + bool same = JSTaggedValue::SameValue(thread_, setPrototype, mapPrototypeProto); ASSERT_FALSE(same); mapLocal->Inherit(vm_, setLocal); JSHandle sonHandle = JSNApiHelper::ToJSHandle(mapLocal); - JSHandle sonPrototype(thread_, JSHandle::Cast(sonHandle)->GetFunctionPrototype()); + JSHandle sonPrototype(thread_, JSHandle::Cast(sonHandle)->GetFunctionPrototype(thread_)); JSHandle sonPrototypeProto(thread_, JSTaggedValue::GetPrototype(thread_, sonPrototype)); - bool same2 = JSTaggedValue::SameValue(setPrototype, sonPrototypeProto); + bool same2 = JSTaggedValue::SameValue(thread_, setPrototype, sonPrototypeProto); ASSERT_TRUE(same2); Local son1 = FunctionRef::New(vm_, FunctionCallback, nullptr); son1->Inherit(vm_, mapLocal); JSHandle son1Handle = JSHandle::Cast(JSNApiHelper::ToJSHandle(son1)); - ASSERT_TRUE(son1Handle->HasFunctionPrototype()); + ASSERT_TRUE(son1Handle->HasFunctionPrototype(thread_)); } /* diff --git a/ecmascript/napi/test/jsnapi_second_tests.cpp b/ecmascript/napi/test/jsnapi_second_tests.cpp index 65a330589b..63b74816e9 100644 --- a/ecmascript/napi/test/jsnapi_second_tests.cpp +++ b/ecmascript/napi/test/jsnapi_second_tests.cpp @@ -329,7 +329,7 @@ HWTEST_F_L0(JSNApiTests, GetKind_entries_values_keys) JSHandle jsMapIteratorTag = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY_AND_VALUE); JSHandle jsMapIterator(jsMapIteratorTag); - EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator->GetIteratedMap(), jsMap->GetLinkedMap()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsMapIterator->GetIteratedMap(thread), jsMap->GetLinkedMap(thread)), true); Local mapIterator = JSNApiHelper::ToLocal(jsMapIteratorTag); Local res = mapIterator->GetKind(vm_); EXPECT_EQ(expectedResult, res->ToString(vm_)->ToString(vm_)); @@ -368,7 +368,7 @@ HWTEST_F_L0(JSNApiTests, GetKind_001) JSHandle mapTag = JSHandle::Cast(jsMap); JSHandle jsMapIteratorTag1 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY); JSHandle jsMapIterator1(jsMapIteratorTag1); - EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator1->GetIteratedMap(), jsMap->GetLinkedMap()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsMapIterator1->GetIteratedMap(thread), jsMap->GetLinkedMap(thread)), true); Local mapIterator1 = JSNApiHelper::ToLocal(jsMapIteratorTag1); Local res1 = mapIterator1->GetKind(vm_); EXPECT_EQ(keysResult, res1->ToString(vm_)->ToString(vm_)); @@ -398,7 +398,7 @@ HWTEST_F_L0(JSNApiTests, GetKind_002) JSHandle mapTag = JSHandle::Cast(jsMap); JSHandle jsMapIteratorTag2 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::VALUE); JSHandle jsMapIterator2(jsMapIteratorTag2); - EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator2->GetIteratedMap(), jsMap->GetLinkedMap()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsMapIterator2->GetIteratedMap(thread), jsMap->GetLinkedMap(thread)), true); Local mapIterator2 = JSNApiHelper::ToLocal(jsMapIteratorTag2); Local res2 = mapIterator2->GetKind(vm_); EXPECT_EQ(valuesResult, res2->ToString(vm_)->ToString(vm_)); @@ -434,7 +434,7 @@ HWTEST_F_L0(JSNApiTests, GetKind_003) JSHandle jsMapIteratorTag = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY_AND_VALUE); JSHandle jsMapIterator(jsMapIteratorTag); - EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator->GetIteratedMap(), jsMap->GetLinkedMap()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsMapIterator->GetIteratedMap(thread), jsMap->GetLinkedMap(thread)), true); // 将jsMapIteratorTag转换为本地代码可以使用的MapIteratorRef类型 Local mapIterator = JSNApiHelper::ToLocal(jsMapIteratorTag); Local res = mapIterator->GetKind(vm_); @@ -480,7 +480,7 @@ HWTEST_F_L0(JSNApiTests, NewClassFunction) ASSERT_TRUE(obj->IsClassConstructor()); // GetPropertyInlinedProps方法获取内联属性的方法,CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX类原型的内联属性索引 JSTaggedValue res = - JSHandle(obj)->GetPropertyInlinedProps(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX); + JSHandle(obj)->GetPropertyInlinedProps(thread_, JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX); // 断言获取的属性是一个内部访问器 ASSERT_TRUE(res.IsInternalAccessor()); } @@ -1110,7 +1110,7 @@ HWTEST_F_L0(JSNApiTests, JSSetIterator_IsSetIterator_GetIndex_GetKind) JSHandle jsTagSetIterator = JSSetIterator::CreateSetIterator(thread, JSHandle(jsSet), IterationKind::KEY); JSHandle jsSetIterator1(jsTagSetIterator); - EXPECT_EQ(JSTaggedValue::SameValue(jsSetIterator1->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsSetIterator1->GetIteratedSet(thread), jsSet->GetLinkedSet(thread)), true); Local setIterator = JSNApiHelper::ToLocal(jsTagSetIterator); EXPECT_TRUE(setIterator->IsSetIterator(vm_)); EXPECT_EQ(setIterator->GetIndex(), 0U); @@ -1140,7 +1140,7 @@ HWTEST_F_L0(JSNApiTests, JSValueRef_IsMapIterator) JSHandle jsMapIteratorTag = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY_AND_VALUE); JSHandle jsMapIterator(jsMapIteratorTag); - EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator->GetIteratedMap(), jsMap->GetLinkedMap()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, jsMapIterator->GetIteratedMap(thread), jsMap->GetLinkedMap(thread)), true); Local mapIterator = JSNApiHelper::ToLocal(jsMapIteratorTag); EXPECT_TRUE(mapIterator->IsMapIterator(vm_)); } @@ -1161,7 +1161,7 @@ HWTEST_F_L0(JSNApiTests, JSValueRef_IsModuleNamespaceObject) SourceTextModule::AddLocalExportEntry(thread_, module, localExportEntry1, 0, 2); JSHandle localExportEntry2 = objectFactory->NewLocalExportEntry(); SourceTextModule::AddLocalExportEntry(thread_, module, localExportEntry2, 1, 2); - JSHandle localExportEntries(thread_, module->GetLocalExportEntries()); + JSHandle localExportEntries(thread_, module->GetLocalExportEntries(thread_)); CString baseFileName = "a.abc"; module->SetEcmaModuleFilenameString(baseFileName); ModuleManager *moduleManager = thread_->GetModuleManager(); diff --git a/ecmascript/napi/test/jsnapi_third_tests.cpp b/ecmascript/napi/test/jsnapi_third_tests.cpp index af9d3041ea..3ebf75a791 100644 --- a/ecmascript/napi/test/jsnapi_third_tests.cpp +++ b/ecmascript/napi/test/jsnapi_third_tests.cpp @@ -959,7 +959,7 @@ HWTEST_F_L0(JSNApiTests, NewObjectWithProperties) if (i + 1 > PropertyAttributes::MAX_FAST_PROPS_CAPACITY) { EXPECT_TRUE(propCount == 0); EXPECT_TRUE(obj->GetJSHClass()->IsDictionaryMode()); - JSHandle dict(thread_, obj->GetProperties()); + JSHandle dict(thread_, obj->GetProperties(thread_)); EXPECT_TRUE(dict->EntriesCount() == i + 1); } else { EXPECT_TRUE(propCount == i + 1); @@ -1041,7 +1041,7 @@ HWTEST_F_L0(JSNApiTests, NewObjectWithNamedProperties) if (i + 1 > PropertyAttributes::MAX_FAST_PROPS_CAPACITY) { EXPECT_TRUE(propCount == 0); EXPECT_TRUE(obj->GetJSHClass()->IsDictionaryMode()); - JSHandle dict(thread_, obj->GetProperties()); + JSHandle dict(thread_, obj->GetProperties(thread_)); EXPECT_TRUE(dict->EntriesCount() == i + 1); } else { EXPECT_TRUE(propCount == i + 1); diff --git a/ecmascript/object_factory-inl.h b/ecmascript/object_factory-inl.h index 48f4151785..848412a1c8 100644 --- a/ecmascript/object_factory-inl.h +++ b/ecmascript/object_factory-inl.h @@ -178,7 +178,7 @@ void ObjectFactory::NewJSIntlIcuData(const JSHandle &obj, const S &icu, const { S *icuPoint = vm_->GetNativeAreaAllocator()->New(icu); ASSERT(icuPoint != nullptr); - JSTaggedValue data = obj->GetIcuField(); + JSTaggedValue data = obj->GetIcuField(vm_->GetJSThread()); if (data.IsHeapObject() && data.IsJSNativePointer()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread_, icuPoint); diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 83fa51e38a..2ea94ab806 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -223,7 +223,7 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle &array, i return; } - JSTaggedValue data = array->GetArrayBufferData(); + JSTaggedValue data = array->GetArrayBufferData(thread_); size_t size = static_cast(length) * sizeof(uint8_t); if (!data.IsUndefined()) { auto *pointer = JSNativePointer::Cast(data.GetTaggedObject()); @@ -259,7 +259,7 @@ void ObjectFactory::NewJSSendableArrayBufferData(const JSHandleGetArrayBufferData(); + JSTaggedValue data = array->GetArrayBufferData(thread_); size_t size = static_cast(length) * sizeof(uint8_t); NativeAreaAllocator *nativeAreaAllocator = sHeap_->GetNativeAreaAllocator(); if (!data.IsUndefined()) { @@ -451,7 +451,7 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle ®exp, vo LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } - JSTaggedValue data = regexp->GetByteCodeBuffer(); + JSTaggedValue data = regexp->GetByteCodeBuffer(thread_); if (!data.IsUndefined()) { JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject()); native->ResetExternalPointer(thread_, newBuffer); @@ -513,7 +513,7 @@ JSHandle ObjectFactory::CloneProperties(const JSHandle JSHandle newArray(thread_, header); newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength, old->GetExtraLength()); for (uint32_t i = 0; i < newLength; i++) { - JSTaggedValue value = old->Get(i); + JSTaggedValue value = old->Get(thread_, i); newArray->Set(thread_, i, value); } return newArray; @@ -526,17 +526,17 @@ JSHandle ObjectFactory::CloneObjectLiteral(JSHandle object) JSHandle cloneObject = NewJSObject(klass); - JSHandle elements(thread_, object->GetElements()); + JSHandle elements(thread_, object->GetElements(thread_)); auto newElements = CloneProperties(elements); cloneObject->SetElements(thread_, newElements.GetTaggedValue()); - JSHandle properties(thread_, object->GetProperties()); + JSHandle properties(thread_, object->GetProperties(thread_)); auto newProperties = CloneProperties(properties); cloneObject->SetProperties(thread_, newProperties.GetTaggedValue()); uint32_t length = std::min(klass->GetInlinedProperties(), klass->NumberOfProps()); for (uint32_t i = 0; i < length; i++) { - cloneObject->SetPropertyInlinedPropsWithRep(thread_, i, object->GetPropertyInlinedProps(i)); + cloneObject->SetPropertyInlinedPropsWithRep(thread_, i, object->GetPropertyInlinedProps(thread_, i)); } return cloneObject; } @@ -550,7 +550,7 @@ JSHandle ObjectFactory::CloneArrayLiteral(JSHandle object) cloneObject->SetArrayLength(thread_, object->GetArrayLength()); cloneObject->SetTrackInfo(thread_, JSTaggedValue::Undefined()); - JSHandle elements(thread_, object->GetElements()); + JSHandle elements(thread_, object->GetElements(thread_)); static constexpr uint8_t MAX_READ_ONLY_ARRAY_LENGTH = 10; uint32_t elementsLength = elements->GetLength(); MemSpaceType type = elementsLength > MAX_READ_ONLY_ARRAY_LENGTH ? @@ -568,15 +568,15 @@ JSHandle ObjectFactory::CloneArrayLiteral(JSHandle object) cloneObject->SetElements(thread_, newElements.GetTaggedValue()); } - if (type == MemSpaceType::NON_MOVABLE && !object->GetElements().IsCOWArray()) { + if (type == MemSpaceType::NON_MOVABLE && !object->GetElements(thread_).IsCOWArray()) { #ifndef USE_CMC_GC - ASSERT(!Region::ObjectAddressToRange(object->GetElements().GetTaggedObject())->InNonMovableSpace()); + ASSERT(!Region::ObjectAddressToRange(object->GetElements(thread_).GetTaggedObject())->InNonMovableSpace()); #endif // Set the first shared elements into the old object. - object->SetElements(thread_, cloneObject->GetElements()); + object->SetElements(thread_, cloneObject->GetElements(thread_)); } - JSHandle properties(thread_, object->GetProperties()); + JSHandle properties(thread_, object->GetProperties(thread_)); uint32_t propertiesLength = properties->GetLength(); type = propertiesLength > MAX_READ_ONLY_ARRAY_LENGTH ? MemSpaceType::SEMI_SPACE : MemSpaceType::NON_MOVABLE; @@ -593,16 +593,16 @@ JSHandle ObjectFactory::CloneArrayLiteral(JSHandle object) cloneObject->SetProperties(thread_, newProperties.GetTaggedValue()); } - if (type == MemSpaceType::NON_MOVABLE && !object->GetProperties().IsCOWArray()) { + if (type == MemSpaceType::NON_MOVABLE && !object->GetProperties(thread_).IsCOWArray()) { #ifndef USE_CMC_GC - ASSERT(!Region::ObjectAddressToRange(object->GetProperties().GetTaggedObject())->InNonMovableSpace()); + ASSERT(!Region::ObjectAddressToRange(object->GetProperties(thread_).GetTaggedObject())->InNonMovableSpace()); #endif // Set the first shared properties into the old object. - object->SetProperties(thread_, cloneObject->GetProperties()); + object->SetProperties(thread_, cloneObject->GetProperties(thread_)); } for (uint32_t i = 0; i < klass->GetInlinedProperties(); i++) { - cloneObject->SetPropertyInlinedPropsWithRep(thread_, i, object->GetPropertyInlinedProps(i)); + cloneObject->SetPropertyInlinedPropsWithRep(thread_, i, object->GetPropertyInlinedProps(thread_, i)); } return cloneObject; } @@ -622,7 +622,7 @@ JSHandle ObjectFactory::CloneProperties(const JSHandle newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength, old->GetExtraLength()); for (uint32_t i = 0; i < newLength; i++) { - JSTaggedValue value = old->Get(i); + JSTaggedValue value = old->Get(thread_, i); if (!value.IsJSFunction()) { newArray->Set(thread_, i, value); } else { @@ -649,19 +649,19 @@ JSHandle ObjectFactory::CloneObjectLiteral(JSHandle object, JSHandle cloneObject = NewJSObject(klass); - JSHandle elements(thread_, object->GetElements()); + JSHandle elements(thread_, object->GetElements(thread_)); auto newElements = CloneProperties(elements, env, cloneObject); cloneObject->SetElements(thread_, newElements.GetTaggedValue()); - JSHandle properties(thread_, object->GetProperties()); + JSHandle properties(thread_, object->GetProperties(thread_)); auto newProperties = CloneProperties(properties, env, cloneObject); cloneObject->SetProperties(thread_, newProperties.GetTaggedValue()); uint32_t length = std::min(klass->GetInlinedProperties(), klass->NumberOfProps()); for (uint32_t i = 0; i < length; i++) { - auto layout = LayoutInfo::Cast(klass->GetLayout().GetTaggedObject()); - JSTaggedValue value = object->GetPropertyInlinedProps(i); - if (!layout->GetAttr(i).IsTaggedRep() || (!value.IsJSFunction() && !value.IsAccessorData())) { + auto layout = LayoutInfo::Cast(klass->GetLayout(thread_).GetTaggedObject()); + JSTaggedValue value = object->GetPropertyInlinedProps(thread_, i); + if (!layout->GetAttr(thread_, i).IsTaggedRep() || (!value.IsJSFunction() && !value.IsAccessorData())) { cloneObject->SetPropertyInlinedPropsWithRep(thread_, i, value); } else if (value.IsJSFunction()) { JSHandle valueHandle(thread_, value); @@ -683,13 +683,13 @@ JSHandle ObjectFactory::CloneObjectLiteral(JSHandle object, JSHandle ObjectFactory::CloneJSFunction(JSHandle func) { JSHandle jshclass(thread_, func->GetJSHClass()); - JSHandle method(thread_, func->GetMethod()); + JSHandle method(thread_, func->GetMethod(thread_)); JSHandle cloneFunc = NewJSFunctionByHClass(method, jshclass); - JSTaggedValue length = func->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX); + JSTaggedValue length = func->GetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX); cloneFunc->SetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length); cloneFunc->SetLength(func->GetLength()); - cloneFunc->SetModule(thread_, func->GetModule()); + cloneFunc->SetModule(thread_, func->GetModule(thread_)); return cloneFunc; } @@ -697,13 +697,13 @@ JSHandle ObjectFactory::CloneSFunction(JSHandle func) { ASSERT(func.GetTaggedValue().IsJSSharedFunction()); JSHandle jshclass(thread_, func->GetJSHClass()); - JSHandle method(thread_, func->GetMethod()); + JSHandle method(thread_, func->GetMethod(thread_)); JSHandle cloneFunc = NewSFunctionByHClass(method, jshclass); - JSTaggedValue length = func->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX); + JSTaggedValue length = func->GetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX); cloneFunc->SetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length); cloneFunc->SetLength(func->GetLength()); - cloneFunc->SetModule(thread_, func->GetModule()); + cloneFunc->SetModule(thread_, func->GetModule(thread_)); return cloneFunc; } @@ -711,7 +711,7 @@ JSHandle ObjectFactory::CreateJSFunctionFromTemplate(JSHandle env = vm_->GetGlobalEnv(); - auto kind = funcTemp->GetFunctionKind(); + auto kind = funcTemp->GetFunctionKind(thread_); JSHandle jshclass; if (kind == FunctionKind::NORMAL_FUNCTION || kind == FunctionKind::GETTER_FUNCTION || @@ -722,11 +722,11 @@ JSHandle ObjectFactory::CreateJSFunctionFromTemplate(JSHandle::Cast(env->GetGeneratorFunctionClass()); } - JSHandle method = JSHandle(thread_, funcTemp->GetMethod()); + JSHandle method = JSHandle(thread_, funcTemp->GetMethod(thread_)); JSHandle newFunc = NewJSFunctionByHClass(method, jshclass); newFunc->SetLength(funcTemp->GetLength()); - newFunc->SetModule(thread_, funcTemp->GetModule()); + newFunc->SetModule(thread_, funcTemp->GetModule(thread_)); return newFunc; } @@ -734,7 +734,7 @@ JSHandle ObjectFactory::CreateSFunctionFromTemplate(JSHandle env = vm_->GetGlobalEnv(); - auto kind = funcTemp->GetFunctionKind(); + auto kind = funcTemp->GetFunctionKind(thread_); JSHandle jshclass; if (kind == FunctionKind::NORMAL_FUNCTION || kind == FunctionKind::GETTER_FUNCTION || @@ -745,11 +745,11 @@ JSHandle ObjectFactory::CreateSFunctionFromTemplate(JSHandle::Cast(env->GetGeneratorFunctionClass()); } - JSHandle method(thread_, funcTemp->GetMethod()); + JSHandle method(thread_, funcTemp->GetMethod(thread_)); JSHandle newFunc = NewSFunctionByHClass(method, jshclass); newFunc->SetLength(funcTemp->GetLength()); - newFunc->SetModule(thread_, funcTemp->GetModule()); + newFunc->SetModule(thread_, funcTemp->GetModule(thread_)); return newFunc; } @@ -763,7 +763,7 @@ JSHandle ObjectFactory::CloneClassCtor(JSHandle ctor, co hclass = JSHClass::Clone(thread_, hclass); } - JSHandle method(thread_, ctor->GetMethod()); + JSHandle method(thread_, ctor->GetMethod(thread_)); ASSERT_PRINT(method->GetFunctionKind() == FunctionKind::CLASS_CONSTRUCTOR || method->GetFunctionKind() == FunctionKind::DERIVED_CONSTRUCTOR, "cloned function is not class"); @@ -771,9 +771,9 @@ JSHandle ObjectFactory::CloneClassCtor(JSHandle ctor, co uint32_t length = std::min(hclass->GetInlinedProperties(), hclass->NumberOfProps()); for (uint32_t i = 0; i < length; i++) { - auto layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - JSTaggedValue value = ctor->GetPropertyInlinedProps(i); - if (!layout->GetAttr(i).IsTaggedRep() || !value.IsJSFunction()) { + auto layout = LayoutInfo::Cast(hclass->GetLayout(thread_).GetTaggedObject()); + JSTaggedValue value = ctor->GetPropertyInlinedProps(thread_, i); + if (!layout->GetAttr(thread_, i).IsTaggedRep() || !value.IsJSFunction()) { cloneCtor->SetPropertyInlinedPropsWithRep(thread_, i, value); } else { JSHandle valueHandle(thread_, value); @@ -784,11 +784,11 @@ JSHandle ObjectFactory::CloneClassCtor(JSHandle ctor, co } } - JSHandle elements(thread_, ctor->GetElements()); + JSHandle elements(thread_, ctor->GetElements(thread_)); auto newElements = CloneProperties(elements, lexenv, JSHandle(cloneCtor)); cloneCtor->SetElements(thread_, newElements.GetTaggedValue()); - JSHandle properties(thread_, ctor->GetProperties()); + JSHandle properties(thread_, ctor->GetProperties(thread_)); auto newProperties = CloneProperties(properties, lexenv, JSHandle(cloneCtor)); cloneCtor->SetProperties(thread_, newProperties.GetTaggedValue()); @@ -1049,7 +1049,7 @@ JSHandle ObjectFactory::NewJSError(const JSHandle &env, con break; } JSHandle nativeFunc = JSHandle::Cast(nativeConstructor); - JSHandle nativePrototype(thread_, nativeFunc->GetFunctionPrototype()); + JSHandle nativePrototype(thread_, nativeFunc->GetFunctionPrototype(thread_)); JSHandle undefined = thread_->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, nativeConstructor, nativePrototype, undefined, 1, needCheckStack); @@ -1097,8 +1097,9 @@ JSHandle ObjectFactory::CreateNapiObject() JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandle &env, const JSHandle &constructor, uint32_t inlinedProps) { - if (!constructor->HasFunctionPrototype() || - (constructor->GetProtoOrHClass().IsHeapObject() && constructor->GetFunctionPrototype().IsECMAObject())) { + if (!constructor->HasFunctionPrototype(thread_) || + (constructor->GetProtoOrHClass(thread_).IsHeapObject() && + constructor->GetFunctionPrototype(thread_).IsECMAObject())) { JSHandle jshclass; if (LIKELY(inlinedProps == JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS)) { jshclass = JSHandle(thread_, JSFunction::GetOrCreateInitialJSHClass(thread_, constructor)); @@ -1110,7 +1111,7 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleIsJSShared()) { obj = NewSharedOldSpaceJSObject(jshclass); if (jshclass->IsDictionaryMode()) { - auto fieldLayout = jshclass->GetLayout(); + auto fieldLayout = jshclass->GetLayout(thread_); ASSERT(fieldLayout.IsDictionary()); auto dict = JSHandle(thread_, fieldLayout); auto properties = NewAndCopySNameDictionary(dict, dict->GetLength()); @@ -1118,7 +1119,7 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleIsClassConstructor()) { JSTaggedValue elementsDic = - constructor->GetPropertyInlinedProps(ClassInfoExtractor::SENDABLE_ELEMENTS_INDEX); + constructor->GetPropertyInlinedProps(thread_, ClassInfoExtractor::SENDABLE_ELEMENTS_INDEX); if (elementsDic.IsDictionary()) { JSHandle elementsDicHld(thread_, elementsDic); JSHandle elements = @@ -1156,8 +1157,9 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandle(thread_, JSTaggedValue::Undefined())); } JSHandle jshclass; - if (!constructor->HasFunctionPrototype() || - (constructor->GetProtoOrHClass().IsHeapObject() && constructor->GetFunctionPrototype().IsECMAObject())) { + if (!constructor->HasFunctionPrototype(thread_) || + (constructor->GetProtoOrHClass(thread_).IsHeapObject() && + constructor->GetFunctionPrototype(thread_).IsECMAObject())) { jshclass = JSFunction::GetInstanceJSHClass(thread_, constructor, newTarget); } else { JSHandle env = vm_->GetGlobalEnv(); @@ -1169,7 +1171,7 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleIsJSShared()) { obj = NewSharedOldSpaceJSObject(jshclass); if (jshclass->IsDictionaryMode()) { - auto fieldLayout = jshclass->GetLayout(); + auto fieldLayout = jshclass->GetLayout(thread_); ASSERT(fieldLayout.IsDictionary()); auto dict = JSHandle(thread_, fieldLayout); auto properties = NewAndCopySNameDictionary(dict, dict->GetLength()); @@ -1177,9 +1179,10 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleIsClassConstructor() && newTarget->IsClassConstructor()) { JSTaggedValue elementsDicOfCtor = - constructor->GetPropertyInlinedProps(ClassInfoExtractor::SENDABLE_ELEMENTS_INDEX); + constructor->GetPropertyInlinedProps(thread_, ClassInfoExtractor::SENDABLE_ELEMENTS_INDEX); JSTaggedValue elementsDicOfTrg = - JSHandle(newTarget)->GetPropertyInlinedProps(ClassInfoExtractor::SENDABLE_ELEMENTS_INDEX); + JSHandle(newTarget)->GetPropertyInlinedProps(thread_, + ClassInfoExtractor::SENDABLE_ELEMENTS_INDEX); if (elementsDicOfCtor.IsDictionary() && elementsDicOfTrg.IsDictionary()) { JSHandle elements; MergeSendableClassElementsDic(elements, JSHandle(thread_, elementsDicOfCtor), @@ -1212,12 +1215,12 @@ void ObjectFactory::MergeSendableClassElementsDic(JSHandle &element JSMutableHandle newElementsDicUpdate(thread_, elementsDicOfCtor); uint32_t headerSize = 4; for (uint32_t i = headerSize; i < elementsDicDicOfTrgHdl->GetLength(); i++) { - key.Update(elementsDicDicOfTrgHdl->Get(i)); + key.Update(elementsDicDicOfTrgHdl->Get(thread_, i)); if (key->IsInt()) { JSHandle elementsDicOfTrg(elementsDicOfTrgVal); - int entry = elementsDicOfTrg->FindEntry(key.GetTaggedValue()); - PropertyAttributes attributes = elementsDicOfTrg->GetAttributes(entry); + int entry = elementsDicOfTrg->FindEntry(thread_, key.GetTaggedValue()); + PropertyAttributes attributes = elementsDicOfTrg->GetAttributes(thread_, entry); JSHandle newElementsDic = NumberDictionary::Put(thread_, elementsDicOfCtor, key, undefinedVal, attributes); newElementsDicUpdate.Update(newElementsDic); @@ -1544,7 +1547,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa break; // non ECMA standard jsapi container case JSType::JS_API_ARRAY_LIST: { - JSAPIArrayList::Cast(*obj)->SetLength(thread_, JSTaggedValue(0)); + JSAPIArrayList::Cast(*obj)->SetLength(0); break; } case JSType::JS_API_HASH_MAP: { @@ -1838,7 +1841,7 @@ void ObjectFactory::InitializeExtraProperties(const JSHandle &hclass, *reinterpret_cast(paddr) = initVal; } if (inProgress) { - hclass->ObjSizeTrackingStep(); + hclass->ObjSizeTrackingStep(thread_); } } @@ -2029,7 +2032,7 @@ JSHandle ObjectFactory::CreateDefaultClassConstructorHClass(JSHClass * attributes.SetIsInlinedProps(true); attributes.SetRepresentation(Representation::TAGGED); attributes.SetOffset(index); - layout->AddKey(thread_, index, array->Get(index), attributes); + layout->AddKey(thread_, index, array->Get(thread_, index), attributes); } JSHandle defaultHClass = NewEcmaHClass(hclass, JSFunction::SIZE, JSType::JS_FUNCTION, size); @@ -2076,7 +2079,7 @@ void ObjectFactory::SetupJSFunctionByHClass(const JSHandle &function SetNativePointerToFunctionFromMethod(JSHandle::Cast(function), method); } else if (method->IsAotWithCallField()) { thread_->GetEcmaVM()->GetAOTFileManager()-> - SetAOTFuncEntry(method->GetJSPandaFile(), *function, *method); + SetAOTFuncEntry(method->GetJSPandaFile(thread_), *function, *method); } else { SetCodeEntryToFunctionFromMethod(function, method); } @@ -2399,7 +2402,7 @@ JSHandle ObjectFactory::NewJSAsyncAwaitStatusFunctio JSHandle ObjectFactory::NewJSGeneratorObject(JSHandle generatorFunction) { - JSHandle proto(thread_, JSHandle::Cast(generatorFunction)->GetProtoOrHClass()); + JSHandle proto(thread_, JSHandle::Cast(generatorFunction)->GetProtoOrHClass(thread_)); if (!proto->IsECMAObject()) { JSHandle realmHandle = JSObject::GetFunctionRealm(thread_, generatorFunction); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSGeneratorObject, thread_); @@ -2414,7 +2417,7 @@ JSHandle ObjectFactory::NewJSGeneratorObject(JSHandle ObjectFactory::NewJSAsyncGeneratorObject(JSHandle generatorFunction) { - JSHandle proto(thread_, JSHandle::Cast(generatorFunction)->GetProtoOrHClass()); + JSHandle proto(thread_, JSHandle::Cast(generatorFunction)->GetProtoOrHClass(thread_)); if (!proto->IsECMAObject()) { JSHandle realmHandle = JSObject::GetFunctionRealm(thread_, generatorFunction); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSAsyncGeneratorObject, thread_); @@ -2579,7 +2582,7 @@ JSHandle ObjectFactory::NewJSSymbol() JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetDescription(thread_, JSTaggedValue::Undefined()); obj->SetFlags(0); - obj->SetHashField(SymbolTable::Hash(obj.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, obj.GetTaggedValue())); return obj; } @@ -2599,7 +2602,7 @@ JSHandle ObjectFactory::NewPrivateNameSymbol(const JSHandleSetFlags(0); obj->SetPrivateNameSymbol(); obj->SetDescription(thread_, name); - obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, name.GetTaggedValue())); return obj; } @@ -2612,7 +2615,7 @@ JSHandle ObjectFactory::NewWellKnownSymbol(const JSHandleSetFlags(0); obj->SetWellKnownSymbol(); obj->SetDescription(thread_, name); - obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, name.GetTaggedValue())); return obj; } @@ -2624,7 +2627,7 @@ JSHandle ObjectFactory::NewPublicSymbol(const JSHandle JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetFlags(0); obj->SetDescription(thread_, name); - obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, name.GetTaggedValue())); return obj; } @@ -2632,8 +2635,8 @@ JSHandle ObjectFactory::NewSymbolWithTable(const JSHandle env = vm_->GetGlobalEnv(); JSHandle tableHandle(env->GetRegisterSymbols()); - if (tableHandle->ContainsKey(name.GetTaggedValue())) { - JSTaggedValue objValue = tableHandle->GetSymbol(name.GetTaggedValue()); + if (tableHandle->ContainsKey(thread_, name.GetTaggedValue())) { + JSTaggedValue objValue = tableHandle->GetSymbol(thread_, name.GetTaggedValue()); return JSHandle(thread_, objValue); } @@ -2897,7 +2900,7 @@ JSHandle ObjectFactory::NewAndCopySNameDictionary(JSHandleSet(thread_, i, srcElements->Get(i)); + dstElements->Set(thread_, i, srcElements->Get(thread_, i)); } return dstElements; } @@ -2928,7 +2931,7 @@ JSHandle ObjectFactory::NewAndCopyTaggedArrayByObject(JSHandle dstElements(NewTaggedArrayWithoutInit(newLength, spaceType)); - TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements(thread_).GetTaggedObject()); dstElements->SetExtraLength(srcElements->GetExtraLength()); if (newLength == 0) { return dstElements; @@ -2950,7 +2953,7 @@ JSHandle ObjectFactory::NewAndCopyMutantTaggedArrayByObject(J ASSERT(oldLength <= newLength); MemSpaceType spaceType = newLength < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle dstElements(NewMutantTaggedArrayWithoutInit(newLength, spaceType)); - MutantTaggedArray *srcElements = MutantTaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + MutantTaggedArray *srcElements = MutantTaggedArray::Cast(thisObjHandle->GetElements(thread_).GetTaggedObject()); dstElements->SetExtraLength(srcElements->GetExtraLength()); if (newLength == 0) { return dstElements; @@ -3183,9 +3186,9 @@ JSHandle ObjectFactory::ExtendArray(const JSHandle &ol auto isMutantTaggedArray = old->GetClass()->IsMutantTaggedArray(); for (; index < oldLength; ++index) { if (isMutantTaggedArray) { - newArray->Set(thread_, index, old->Get(index)); + newArray->Set(thread_, index, old->Get(thread_, index)); } else { - newArray->Set(thread_, index, old->Get(index)); + newArray->Set(thread_, index, old->Get(thread_, index)); } } auto isSpecialHole = initVal.IsHole() && isMutantTaggedArray; @@ -3220,7 +3223,7 @@ JSHandle ObjectFactory::CopyPartArray(const JSHandle & newArray->InitializeWithSpecialValue(JSTaggedValue::Hole(), newLength, old->GetExtraLength()); for (uint32_t i = 0; i < newLength; i++) { - JSTaggedValue value = old->Get(i + start); + JSTaggedValue value = old->Get(thread_, i + start); if (value.IsHole()) { break; } @@ -3285,7 +3288,7 @@ JSHandle ObjectFactory::CopyFromKeyArray(const JSHandleSetExtraLength(old->GetExtraLength()); for (uint32_t i = 0; i < newLength; i++) { - JSTaggedValue value = old->Get(i); + JSTaggedValue value = old->Get(thread_, i); newArray->Set(thread_, i, value); } return newArray; @@ -3313,7 +3316,7 @@ JSHandle ObjectFactory::ExtendLayoutInfo(const JSHandle uint32_t oldLength = old->GetLength(); for (uint32_t i = 0; i < oldLength; i++) { - JSTaggedValue value = oldArray->Get(i); + JSTaggedValue value = oldArray->Get(thread_, i); newArray->Set(thread_, i, value); } return JSHandle::Cast(newArray); @@ -3336,9 +3339,9 @@ JSHandle ObjectFactory::CopyAndReSort(const JSHandle &ol size_t keyOffset = 0; size_t attrOffset = sizeof(JSTaggedType); for (int i = 0; i < end; i++) { - JSTaggedValue propKey(Barriers::GetTaggedValue(ToUintPtr(propertiesObj) + i * sizeof(Properties) + + JSTaggedValue propKey(Barriers::GetTaggedValue(thread_, ToUintPtr(propertiesObj) + i * sizeof(Properties) + keyOffset)); - JSTaggedValue propValue(Barriers::GetTaggedValue(ToUintPtr(propertiesObj) + + JSTaggedValue propValue(Barriers::GetTaggedValue(thread_, ToUintPtr(propertiesObj) + i * sizeof(Properties) + attrOffset)); sp[i].key_ = propKey; sp[i].attr_ = propValue; @@ -3675,7 +3678,7 @@ JSHandle ObjectFactory::NewJSSetIterator(const JSHandle &s hclassHandle->SetPrototype(thread_, protoValue); JSHandle iter(NewJSObject(hclassHandle)); iter->GetJSHClass()->SetExtensible(true); - iter->SetIteratedSet(thread_, set->GetLinkedSet()); + iter->SetIteratedSet(thread_, set->GetLinkedSet(thread_)); iter->SetNextIndex(0); iter->SetIterationKind(kind); return iter; @@ -3709,7 +3712,7 @@ JSHandle ObjectFactory::NewJSMapIterator(const JSHandle &m hclassHandle->SetPrototype(thread_, protoValue); JSHandle iter(NewJSObject(hclassHandle)); iter->GetJSHClass()->SetExtensible(true); - iter->SetIteratedMap(thread_, map->GetLinkedMap()); + iter->SetIteratedMap(thread_, map->GetLinkedMap(thread_)); iter->SetNextIndex(0); iter->SetIterationKind(kind); return iter; @@ -4168,11 +4171,11 @@ JSHandle ObjectFactory::CreateObjectClass(const JSHandle &e JSMutableHandle key(thread_, JSTaggedValue::Undefined()); JSHandle layoutInfoHandle = CreateLayoutInfo(length); while (fieldOrder < length) { - key.Update(properties->Get(fieldOrder * 2)); // 2: Meaning to double + key.Update(properties->Get(thread_, fieldOrder * 2)); // 2: Meaning to double ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes = PropertyAttributes::Default(); - if (properties->Get(fieldOrder * 2 + 1).IsAccessor()) { // 2: Meaning to double + if (properties->Get(thread_, fieldOrder * 2 + 1).IsAccessor()) { // 2: Meaning to double attributes.SetIsAccessor(true); } @@ -4200,10 +4203,10 @@ JSHandle ObjectFactory::SetLayoutInObjHClass(const JSHandle newObjHClass(objClass); for (size_t fieldOffset = 0; fieldOffset < length; fieldOffset++) { - key.Update(properties->Get(fieldOffset * 2)); // 2 : pair of key and value + key.Update(properties->Get(thread_, fieldOffset * 2)); // 2 : pair of key and value ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); PropertyAttributes attributes = PropertyAttributes::Default(); - auto value = properties->Get(fieldOffset * 2 + 1); + auto value = properties->Get(thread_, fieldOffset * 2 + 1); if (value.IsAccessor()) { // 2: Meaning to double attributes.SetIsAccessor(true); } @@ -4247,7 +4250,7 @@ JSHandle ObjectFactory::GetObjectLiteralRootHClass(size_t literalLengt return objHClass; } JSHandle hclassCacheArr = JSHandle::Cast(maybeCache); - JSTaggedValue maybeHClass = hclassCacheArr->Get(literalLength); + JSTaggedValue maybeHClass = hclassCacheArr->Get(thread_, literalLength); if (UNLIKELY(maybeHClass.IsHole())) { JSHandle objHClass = CreateObjectLiteralRootHClass(maxPropsNum); hclassCacheArr->Set(thread_, literalLength, objHClass); @@ -4329,7 +4332,7 @@ JSHandle ObjectFactory::SetMachineCodeObjectData(TaggedObject *obj, LOG_FULL(FATAL) << "machine code cast failed"; UNREACHABLE(); } - if (code->SetData(desc, method, length, relocInfo)) { + if (code->SetData(thread_, desc, method, length, relocInfo)) { JSHandle codeObj(thread_, code); return codeObj; } else { @@ -4702,7 +4705,7 @@ JSHandle ObjectFactory::CopyDeque(const JSHandle &old, uint32_t newIndex = 0; uint32_t oldCapacity = old->GetLength(); while (curIndex != last) { - JSTaggedValue value = old->Get(curIndex); + JSTaggedValue value = old->Get(thread_, curIndex); newArray->Set(thread_, newIndex, value); ASSERT(oldCapacity != 0); curIndex = (curIndex + 1) % oldCapacity; @@ -4741,7 +4744,7 @@ JSHandle ObjectFactory::CopyQueue(const JSHandle &old, uint32_t newIndex = 0; uint32_t oldCapacity = old->GetLength(); while (curIndex != tail) { - JSTaggedValue value = old->Get(curIndex); + JSTaggedValue value = old->Get(thread_, curIndex); newArray->Set(thread_, newIndex, value); ASSERT(oldCapacity != 0); curIndex = (curIndex + 1) % oldCapacity; @@ -4918,7 +4921,7 @@ JSHandle ObjectFactory::NewJSAPILinkedListIterator(cons hclassHandle->SetPrototype(thread_, proto); JSHandle iter(NewJSObject(hclassHandle)); iter->GetJSHClass()->SetExtensible(true); - iter->SetIteratedLinkedList(thread_, linkedList->GetDoubleList()); + iter->SetIteratedLinkedList(thread_, linkedList->GetDoubleList(thread_)); iter->SetNextIndex(0); const uint32_t linkedListElementStartIndex = 4; iter->SetDataIndex(linkedListElementStartIndex); @@ -4935,7 +4938,7 @@ JSHandle ObjectFactory::NewJSAPIListIterator(const JSHandleSetPrototype(thread_, proto); JSHandle iter(NewJSObject(hclassHandle)); iter->GetJSHClass()->SetExtensible(true); - iter->SetIteratedList(thread_, List->GetSingleList()); + iter->SetIteratedList(thread_, List->GetSingleList(thread_)); iter->SetNextIndex(0); const uint32_t linkedListElementStartIndex = 4; iter->SetDataIndex(linkedListElementStartIndex); @@ -5198,7 +5201,7 @@ JSHandle ObjectFactory::NewOldSpaceTaggedArray(uint32_t length, JST JSHandle ObjectFactory::NewJSStableArrayWithElements(const JSHandle &elements) { JSHandle cls(thread_, - JSHandle::Cast(vm_->GetGlobalEnv()->GetArrayFunction())->GetProtoOrHClass()); + JSHandle::Cast(vm_->GetGlobalEnv()->GetArrayFunction())->GetProtoOrHClass(thread_)); JSHandle array = JSHandle::Cast(NewJSObject(cls)); array->SetElements(thread_, elements); array->SetLength(elements->GetLength()); @@ -5392,7 +5395,7 @@ JSHandle ObjectFactory::CreateJSObjectWithProperties(size_t prope key.Update(JSTaggedValue(InternString(key))); } ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); - if (UNLIKELY(!JSTaggedValue::IsPureString(key.GetTaggedValue()))) { + if (UNLIKELY(!JSTaggedValue::IsPureString(thread_, key.GetTaggedValue()))) { THROW_TYPE_ERROR_AND_RETURN(thread_, "property key must be string and can not convert into element index", JSHandle()); } @@ -5435,7 +5438,7 @@ JSHandle ObjectFactory::CreateLargeJSObjectWithProperties(size_t key.Update(JSTaggedValue(InternString(key))); } ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); - if (UNLIKELY(!JSTaggedValue::IsPureString(key.GetTaggedValue()))) { + if (UNLIKELY(!JSTaggedValue::IsPureString(thread_, key.GetTaggedValue()))) { THROW_TYPE_ERROR_AND_RETURN(thread_, "property key must be string and can not convert into element index", JSHandle()); } @@ -5473,7 +5476,7 @@ JSHandle ObjectFactory::CreateDictionaryJSObjectWithProperties(si key.Update(JSTaggedValue(InternString(key))); } ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); - if (UNLIKELY(!JSTaggedValue::IsPureString(key.GetTaggedValue()))) { + if (UNLIKELY(!JSTaggedValue::IsPureString(thread_, key.GetTaggedValue()))) { THROW_TYPE_ERROR_AND_RETURN(thread_, "property key must be string and can not convert into element index", JSHandle()); } @@ -5500,7 +5503,7 @@ JSHandle ObjectFactory::CreateJSObjectWithNamedProperties(size_t for (size_t i = 0; i < propertyCount; ++i) { JSHandle key(NewFromUtf8(keys[i])); ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); - if (UNLIKELY(!JSTaggedValue::IsPureString(key.GetTaggedValue()))) { + if (UNLIKELY(!JSTaggedValue::IsPureString(thread_, key.GetTaggedValue()))) { THROW_TYPE_ERROR_AND_RETURN(thread_, "property key must be string and can not convert into element index", JSHandle()); } @@ -5538,7 +5541,7 @@ JSHandle ObjectFactory::CreateLargeJSObjectWithNamedProperties(si for (size_t i = 0; i < propertyCount; ++i) { JSHandle key(NewFromUtf8(keys[i])); ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); - if (UNLIKELY(!JSTaggedValue::IsPureString(key.GetTaggedValue()))) { + if (UNLIKELY(!JSTaggedValue::IsPureString(thread_, key.GetTaggedValue()))) { THROW_TYPE_ERROR_AND_RETURN(thread_, "property key must be string and can not convert into element index", JSHandle()); } @@ -5572,7 +5575,7 @@ JSHandle ObjectFactory::CreateDictionaryJSObjectWithNamedProperti for (size_t i = 0; i < propertyCount; ++i) { JSHandle key(NewFromUtf8(keys[i])); ASSERT(EcmaStringAccessor(key->GetTaggedObject()).IsInternString()); - if (UNLIKELY(!JSTaggedValue::IsPureString(key.GetTaggedValue()))) { + if (UNLIKELY(!JSTaggedValue::IsPureString(thread_, key.GetTaggedValue()))) { THROW_TYPE_ERROR_AND_RETURN(thread_, "property key must be string and can not convert into element index", JSHandle()); } diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index 547a162f91..6fe5a97112 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -380,8 +380,8 @@ public: } int dataIndex = Derived::ELEMENTS_START_INDEX; for (uint32_t i = 0; i < numberOfNodes; i++) { - dataIndex = list->GetElement(dataIndex + Derived::NEXT_PTR_OFFSET).GetInt(); - dstElements->Set(thread, i, list->GetElement(dataIndex)); + dataIndex = list->GetElement(thread, dataIndex + Derived::NEXT_PTR_OFFSET).GetInt(); + dstElements->Set(thread, i, list->GetElement(thread, dataIndex)); } return dstElements; } diff --git a/ecmascript/object_fast_operator-inl.h b/ecmascript/object_fast_operator-inl.h index da0395ef6d..f85f2569b5 100644 --- a/ecmascript/object_fast_operator-inl.h +++ b/ecmascript/object_fast_operator-inl.h @@ -69,23 +69,23 @@ std::pair ObjectFastOperator::HasOwnProperty(JSThread *thre } uint32_t index = 0; - if (JSTaggedValue::ToElementIndex(key, &index)) { + if (JSTaggedValue::ToElementIndex(thread, key, &index)) { ASSERT(index < JSObject::MAX_ELEMENT_INDEX); JSHandle receiverObj(thread, receiver); - if (ElementAccessor::GetElementsLength(receiverObj) == 0) { + if (ElementAccessor::GetElementsLength(thread, receiverObj) == 0) { return std::make_pair(JSTaggedValue::Hole(), true); // Empty Array } - if (!ElementAccessor::IsDictionaryMode(receiverObj)) { - if (ElementAccessor::GetElementsLength(receiverObj) <= index) { + if (!ElementAccessor::IsDictionaryMode(thread, receiverObj)) { + if (ElementAccessor::GetElementsLength(thread, receiverObj) <= index) { return std::make_pair(JSTaggedValue::Hole(), true); } JSTaggedValue value = ElementAccessor::Get(thread, receiverObj, index); return std::make_pair(value, true); } else { NumberDictionary *dictionary = - NumberDictionary::Cast(JSObject::Cast(receiver)->GetElements().GetTaggedObject()); - int entry = dictionary->FindEntry(JSTaggedValue(static_cast(index))); + NumberDictionary::Cast(JSObject::Cast(receiver)->GetElements(thread).GetTaggedObject()); + int entry = dictionary->FindEntry(thread, JSTaggedValue(static_cast(index))); if (entry == -1) { return std::make_pair(JSTaggedValue::Hole(), true); } @@ -96,7 +96,7 @@ std::pair ObjectFastOperator::HasOwnProperty(JSThread *thre if (!EcmaStringAccessor(key).IsInternString()) { JSHandle keyHandle(thread, key); #if ENABLE_NEXT_OPTIMIZATION - EcmaString *str = thread->GetEcmaVM()->GetEcmaStringTable()->TryGetInternString(keyHandle); + EcmaString *str = thread->GetEcmaVM()->GetEcmaStringTable()->TryGetInternString(thread, keyHandle); #else EcmaString *str = thread->GetEcmaVM()->GetEcmaStringTable()->TryGetInternString(thread, keyHandle); #endif @@ -107,16 +107,16 @@ std::pair ObjectFastOperator::HasOwnProperty(JSThread *thre } auto *hclass = receiver.GetTaggedObject()->GetClass(); if (LIKELY(!hclass->IsDictionaryMode())) { - ASSERT(!TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetTaggedObject())->IsDictionaryMode()); + ASSERT(!TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); int entry = JSHClass::FindPropertyEntry(thread, hclass, key); if (entry != -1) { return std::make_pair(JSTaggedValue::Undefined(), true); } } else { - TaggedArray *array = TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties(thread).GetTaggedObject()); ASSERT(array->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { return std::make_pair(JSTaggedValue::Undefined(), true); } @@ -137,12 +137,12 @@ JSTaggedValue ObjectFastOperator::TryFastHasProperty(JSThread *thread, JSTaggedV } // Elements - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index >= 0) { ASSERT(index < JSObject::MAX_ELEMENT_INDEX); JSHandle receiverObj(thread, receiver); - if (!ElementAccessor::IsDictionaryMode(receiverObj)) { - if (index < ElementAccessor::GetElementsLength(receiverObj)) { + if (!ElementAccessor::IsDictionaryMode(thread, receiverObj)) { + if (index < ElementAccessor::GetElementsLength(thread, receiverObj)) { JSTaggedValue value = ElementAccessor::Get(thread, receiverObj, index); return value.IsHole() ? JSTaggedValue::Hole() : JSTaggedValue::True(); } @@ -162,7 +162,7 @@ JSTaggedValue ObjectFastOperator::TryFastHasProperty(JSThread *thread, JSTaggedV key = keyHandle.GetTaggedValue(); receiver = receiverHandler.GetTaggedValue(); } - ASSERT(!TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetTaggedObject())->IsDictionaryMode()); + ASSERT(!TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); int entry = JSHClass::FindPropertyEntry(thread, hclass, key); if (entry != -1) { return JSTaggedValue::True(); @@ -182,7 +182,7 @@ JSTaggedValue ObjectFastOperator::TryFastGetPropertyByValue(JSThread *thread, JS if (UNLIKELY(!key.IsNumber() && !key.IsString())) { return JSTaggedValue::Hole(); } - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (index >= 0) { return TryFastGetPropertyByIndex(thread, receiver, index); } @@ -213,8 +213,8 @@ JSTaggedValue ObjectFastOperator::TryFastGetPropertyByIndex(JSThread *thread, JS auto *hclass = holder.GetTaggedObject()->GetClass(); JSHandle currentHolder(thread, holder); if (!hclass->IsDictionaryElement()) { - ASSERT(!ElementAccessor::IsDictionaryMode(currentHolder)); - if (index < ElementAccessor::GetElementsLength(currentHolder)) { + ASSERT(!ElementAccessor::IsDictionaryMode(thread, currentHolder)); + if (index < ElementAccessor::GetElementsLength(thread, currentHolder)) { JSTaggedValue value = ElementAccessor::Get(thread, currentHolder, index); if (!value.IsHole()) { return value; @@ -230,14 +230,14 @@ JSTaggedValue ObjectFastOperator::TryGetPropertyByNameThroughCacheAtLocal(JSThre { auto *hclass = receiver.GetTaggedObject()->GetClass(); if (LIKELY(!hclass->IsDictionaryMode())) { - ASSERT(!TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetTaggedObject())->IsDictionaryMode()); + ASSERT(!TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); int entry = JSHClass::FindPropertyEntry(thread, hclass, key); if (entry != -1) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(entry)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, entry)); ASSERT(static_cast(attr.GetOffset()) == entry); - auto value = JSObject::Cast(receiver)->GetProperty(hclass, attr); + auto value = JSObject::Cast(receiver)->GetProperty(thread, hclass, attr); if (UNLIKELY(attr.IsAccessor())) { if (GetInternal(status)) { return value; @@ -304,14 +304,15 @@ JSTaggedValue ObjectFastOperator::GetPropertyByName(JSThread *thread, JSTaggedVa } if (LIKELY(!hclass->IsDictionaryMode())) { - ASSERT(!TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject())->IsDictionaryMode()); + ASSERT(!TaggedArray::Cast(JSObject::Cast(holder)->GetProperties(thread).GetTaggedObject()) + ->IsDictionaryMode()); int entry = JSHClass::FindPropertyEntry(thread, hclass, key); if (entry != -1) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(entry)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, entry)); ASSERT(static_cast(attr.GetOffset()) == entry); - auto value = JSObject::Cast(holder)->GetProperty(hclass, attr); + auto value = JSObject::Cast(holder)->GetProperty(thread, hclass, attr); if (UNLIKELY(attr.IsAccessor())) { if (GetInternal(status)) { return value; @@ -328,13 +329,13 @@ JSTaggedValue ObjectFastOperator::GetPropertyByName(JSThread *thread, JSTaggedVa } } } else { - TaggedArray *array = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties(thread).GetTaggedObject()); ASSERT(array->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { - auto value = dict->GetValue(entry); - auto attr = dict->GetAttributes(entry); + auto value = dict->GetValue(thread, entry); + auto attr = dict->GetAttributes(thread, entry); if (UNLIKELY(attr.IsAccessor())) { if (GetInternal(status)) { return value; @@ -352,7 +353,7 @@ JSTaggedValue ObjectFastOperator::GetPropertyByName(JSThread *thread, JSTaggedVa if (UseOwn(status)) { break; } - holder = hclass->GetPrototype(); + holder = hclass->GetPrototype(thread); } while (holder.IsHeapObject()); // not found return JSTaggedValue::Undefined(); @@ -367,17 +368,17 @@ JSTaggedValue ObjectFastOperator::TrySetPropertyByNameThroughCacheAtLocal(JSThre JSTaggedValue receiverVal = receiver.GetTaggedValue(); JSHClass *hclass = receiverVal.GetTaggedObject()->GetClass(); if (LIKELY(!hclass->IsDictionaryMode())) { - ASSERT(!TaggedArray::Cast(JSObject::Cast(receiverVal)->GetProperties().GetTaggedObject())->IsDictionaryMode()); + ASSERT(!TaggedArray::Cast(JSObject::Cast(receiverVal)->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); int entry = JSHClass::FindPropertyEntry(thread, hclass, key.GetTaggedValue()); if (entry != -1) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(entry)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, entry)); ASSERT(static_cast(attr.GetOffset()) == entry); if (UNLIKELY(attr.IsAccessor())) { if (DefineSemantics(status)) { return JSTaggedValue::Hole(); } - auto accessor = JSObject::Cast(receiverVal)->GetProperty(hclass, attr); + auto accessor = JSObject::Cast(receiverVal)->GetProperty(thread, hclass, attr); if (ShouldCallSetter(receiverVal, receiverVal, accessor, attr)) { return CallSetter(thread, receiverVal, value.GetTaggedValue(), accessor); } @@ -404,7 +405,7 @@ JSTaggedValue ObjectFastOperator::TrySetPropertyByNameThroughCacheAtLocal(JSThre } } if (hclass->IsAOT()) { - auto attrVal = JSObject::Cast(receiverVal)->GetProperty(hclass, attr); + auto attrVal = JSObject::Cast(receiverVal)->GetProperty(thread, hclass, attr); if (attrVal.IsHole()) { return JSTaggedValue::Hole(); } @@ -471,17 +472,18 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa } // UpdateRepresentation if (LIKELY(!hclass->IsDictionaryMode())) { - ASSERT(!TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject())->IsDictionaryMode()); + ASSERT(!TaggedArray::Cast(JSObject::Cast(holder)->GetProperties(thread).GetTaggedObject()) + ->IsDictionaryMode()); int entry = JSHClass::FindPropertyEntry(thread, hclass, key); if (entry != -1) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(entry)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, entry)); ASSERT(static_cast(attr.GetOffset()) == entry); if (UNLIKELY(attr.IsAccessor())) { if (DefineSemantics(status) && sCheckMode == SCheckMode::CHECK) { return JSTaggedValue::Hole(); } - auto accessor = JSObject::Cast(holder)->GetProperty(hclass, attr); + auto accessor = JSObject::Cast(holder)->GetProperty(thread, hclass, attr); if (ShouldCallSetter(receiver, holder, accessor, attr)) { return CallSetter(thread, receiver, value, accessor); } @@ -495,7 +497,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa JSTaggedValue::Exception()); } if (hclass->IsAOT()) { - auto attrVal = JSObject::Cast(holder)->GetProperty(hclass, attr); + auto attrVal = JSObject::Cast(holder)->GetProperty(thread, hclass, attr); if (attrVal.IsHole()) { if (receiverHoleEntry == -1 && holder == receiver) { receiverHoleEntry = entry; @@ -503,7 +505,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa if (UseOwn(status)) { break; } - holder = hclass->GetPrototype(); + holder = hclass->GetPrototype(thread); continue; } } @@ -543,17 +545,17 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa return JSTaggedValue::Undefined(); } } else { - TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties(thread).GetTaggedObject()); ASSERT(properties->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(properties); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { - auto attr = dict->GetAttributes(entry); + auto attr = dict->GetAttributes(thread, entry); if (UNLIKELY(attr.IsAccessor())) { if (DefineSemantics(status) && sCheckMode == SCheckMode::CHECK) { return JSTaggedValue::Hole(); } - auto accessor = dict->GetValue(entry); + auto accessor = dict->GetValue(thread, entry); if (ShouldCallSetter(receiver, holder, accessor, attr)) { return CallSetter(thread, receiver, value, accessor); } @@ -591,13 +593,13 @@ JSTaggedValue ObjectFastOperator::SetPropertyByName(JSThread *thread, JSTaggedVa if (UseOwn(status) || DefineSemantics(status)) { break; } - holder = hclass->GetPrototype(); + holder = hclass->GetPrototype(thread); } while (holder.IsHeapObject()); if (receiverHoleEntry != -1) { auto *receiverHClass = receiver.GetTaggedObject()->GetClass(); - LayoutInfo *receiverLayoutInfo = LayoutInfo::Cast(receiverHClass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(receiverLayoutInfo->GetAttr(receiverHoleEntry)); + LayoutInfo *receiverLayoutInfo = LayoutInfo::Cast(receiverHClass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(receiverLayoutInfo->GetAttr(thread, receiverHoleEntry)); JSHandle objHandle(thread, receiver); ElementsKind oldKind = objHandle->GetJSHClass()->GetElementsKind(); auto actualValue = JSHClass::ConvertOrTransitionWithRep(thread, objHandle, @@ -658,20 +660,20 @@ JSTaggedValue ObjectFastOperator::GetPropertyByIndex(JSThread *thread, JSTaggedV } JSHandle currentHolder(thread, holder); if (!hclass->IsDictionaryElement()) { - ASSERT(!ElementAccessor::IsDictionaryMode(currentHolder)); - if (index < ElementAccessor::GetElementsLength(currentHolder)) { + ASSERT(!ElementAccessor::IsDictionaryMode(thread, currentHolder)); + if (index < ElementAccessor::GetElementsLength(thread, currentHolder)) { JSTaggedValue value = ElementAccessor::Get(thread, currentHolder, index); if (!value.IsHole()) { return value; } } } else { - TaggedArray *elements = TaggedArray::Cast(currentHolder->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(currentHolder->GetElements(thread).GetTaggedObject()); NumberDictionary *dict = NumberDictionary::Cast(elements); - int entry = dict->FindEntry(JSTaggedValue(static_cast(index))); + int entry = dict->FindEntry(thread, JSTaggedValue(static_cast(index))); if (entry != -1) { - auto attr = dict->GetAttributes(entry); - auto value = dict->GetValue(entry); + auto attr = dict->GetAttributes(thread, entry); + auto value = dict->GetValue(thread, entry); if (UNLIKELY(attr.IsAccessor())) { return CallGetter(thread, receiver, holder, value); } @@ -682,7 +684,7 @@ JSTaggedValue ObjectFastOperator::GetPropertyByIndex(JSThread *thread, JSTaggedV if (UseOwn(status)) { break; } - holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); + holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(thread); } while (holder.IsHeapObject()); // not found @@ -715,7 +717,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByIndex(JSThread *thread, JSTaggedV return JSTaggedValue::Hole(); } JSHandle arrayHandler(thread, holder); - TaggedArray *elements = TaggedArray::Cast(arrayHandler->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(arrayHandler->GetElements(thread).GetTaggedObject()); if (!hclass->IsDictionaryElement()) { ASSERT(!elements->IsDictionaryMode()); if (UNLIKELY(holder != receiver)) { @@ -724,7 +726,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByIndex(JSThread *thread, JSTaggedV if (index < elements->GetLength()) { JSTaggedValue oldValue = ElementAccessor::Get(thread, arrayHandler, index); if (!oldValue.IsHole()) { - if (holder.IsJSCOWArray()) { + if (holder.IsJSCOWArray(thread)) { [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle holderHandler(thread, holder); JSHandle obj(thread, holder); @@ -741,9 +743,9 @@ JSTaggedValue ObjectFastOperator::SetPropertyByIndex(JSThread *thread, JSTaggedV } } else { NumberDictionary *dict = NumberDictionary::Cast(elements); - int entry = dict->FindEntry(JSTaggedValue(static_cast(index))); + int entry = dict->FindEntry(thread, JSTaggedValue(static_cast(index))); if (entry != -1) { - auto attr = dict->GetAttributes(entry); + auto attr = dict->GetAttributes(thread, entry); if (UNLIKELY((!attr.IsWritable() || !attr.IsConfigurable()) && !hclass->IsJSShared())) { return JSTaggedValue::Hole(); } @@ -754,7 +756,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByIndex(JSThread *thread, JSTaggedV if (DefineSemantics(status)) { return JSTaggedValue::Hole(); } - auto accessor = dict->GetValue(entry); + auto accessor = dict->GetValue(thread, entry); if (ShouldCallSetter(receiver, holder, accessor, attr)) { return CallSetter(thread, receiver, value, accessor); } @@ -767,7 +769,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByIndex(JSThread *thread, JSTaggedV if (UseOwn(status) || DefineSemantics(status)) { break; } - holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); + holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(thread); } while (holder.IsHeapObject()); return AddPropertyByIndex(thread, receiver, index, value); @@ -781,7 +783,7 @@ JSTaggedValue ObjectFastOperator::GetPropertyByValue(JSThread *thread, JSTaggedV return JSTaggedValue::Hole(); } // fast path - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (LIKELY(index >= 0)) { return GetPropertyByIndex(thread, receiver, index); } @@ -808,7 +810,7 @@ JSTaggedValue ObjectFastOperator::SetPropertyByValue(JSThread *thread, JSTaggedV return JSTaggedValue::Hole(); } // fast path - auto index = TryToElementsIndex(key); + auto index = TryToElementsIndex(thread, key); if (LIKELY(index >= 0)) { return SetPropertyByIndex(thread, receiver, index, value); } @@ -902,7 +904,7 @@ JSTaggedValue ObjectFastOperator::FastGetPropertyByIndex(JSThread *thread, JSTag return result; } -JSTaggedValue ObjectFastOperator::FastParseDate(const EcmaString *str) +JSTaggedValue ObjectFastOperator::FastParseDate(const JSThread *thread, const EcmaString *str) { int year = 0; int month = 1; @@ -912,7 +914,7 @@ JSTaggedValue ObjectFastOperator::FastParseDate(const EcmaString *str) CVector tmpBuf; EcmaStringAccessor strAccessor(const_cast(str)); int len = static_cast(strAccessor.GetLength()); - auto data = reinterpret_cast(strAccessor.GetUtf8DataFlat(str, tmpBuf)); + auto data = reinterpret_cast(strAccessor.GetUtf8DataFlat(thread, str, tmpBuf)); if (!GetNumFromString(data, len, &index, &year)) { return JSTaggedValue::Hole(); } @@ -960,7 +962,7 @@ PropertyAttributes ObjectFastOperator::AddPropertyByName(JSThread *thread, JSHan return attr; } - JSMutableHandle array(thread, objHandle->GetProperties()); + JSMutableHandle array(thread, objHandle->GetProperties(thread)); uint32_t length = array->GetLength(); if (length == 0) { length = JSObject::MIN_PROPERTIES_LENGTH; @@ -1100,7 +1102,7 @@ JSTaggedValue ObjectFastOperator::FastGetTypeArrayProperty(JSThread *thread, JST return JSTaggedValue::Undefined(); } uint32_t index = 0; - if (TryStringOrSymbolToIndex(key, &index)) { + if (TryStringOrSymbolToIndex(thread, key, &index)) { if (UNLIKELY(index == JSObject::MAX_ELEMENT_INDEX)) { return JSTaggedValue::Null(); } @@ -1109,13 +1111,13 @@ JSTaggedValue ObjectFastOperator::FastGetTypeArrayProperty(JSThread *thread, JST return JSTaggedValue::Hole(); } -bool ObjectFastOperator::TryStringOrSymbolToIndex(JSTaggedValue key, uint32_t *output) +bool ObjectFastOperator::TryStringOrSymbolToIndex(JSThread *thread, JSTaggedValue key, uint32_t *output) { if (key.IsSymbol()) { return false; } auto strObj = static_cast(key.GetTaggedObject()); - return EcmaStringAccessor(strObj).ToTypedArrayIndex(output); + return EcmaStringAccessor(strObj).ToTypedArrayIndex(thread, output); } JSTaggedValue ObjectFastOperator::FastSetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, @@ -1131,7 +1133,7 @@ JSTaggedValue ObjectFastOperator::FastSetTypeArrayProperty(JSThread *thread, JST return JSTaggedValue::Undefined(); } uint32_t index = 0; - if (TryStringOrSymbolToIndex(key, &index)) { + if (TryStringOrSymbolToIndex(thread, key, &index)) { if (UNLIKELY(index == JSObject::MAX_ELEMENT_INDEX)) { return JSTaggedValue::Null(); } @@ -1157,13 +1159,13 @@ JSTaggedValue ObjectFastOperator::GetContainerProperty(JSThread *thread, JSTagge res = JSAPIQueue::Cast(receiver.GetTaggedObject())->Get(thread, index); break; case JSType::JS_API_PLAIN_ARRAY: - res = JSAPIPlainArray::Cast(receiver.GetTaggedObject())->Get(JSTaggedValue(index)); + res = JSAPIPlainArray::Cast(receiver.GetTaggedObject())->Get(thread, JSTaggedValue(index)); break; case JSType::JS_API_DEQUE: - res = JSAPIDeque::Cast(receiver.GetTaggedObject())->Get(index); + res = JSAPIDeque::Cast(receiver.GetTaggedObject())->Get(thread, index); break; case JSType::JS_API_STACK: - res = JSAPIStack::Cast(receiver.GetTaggedObject())->Get(index); + res = JSAPIStack::Cast(receiver.GetTaggedObject())->Get(thread, index); break; case JSType::JS_API_VECTOR: { auto self = JSHandle(thread, receiver); @@ -1171,7 +1173,7 @@ JSTaggedValue ObjectFastOperator::GetContainerProperty(JSThread *thread, JSTagge break; } case JSType::JS_API_LIST: { - res = JSAPIList::Cast(receiver.GetTaggedObject())->Get(index); + res = JSAPIList::Cast(receiver.GetTaggedObject())->Get(thread, index); break; } case JSType::JS_API_BITVECTOR: { @@ -1184,7 +1186,7 @@ JSTaggedValue ObjectFastOperator::GetContainerProperty(JSThread *thread, JSTagge break; } case JSType::JS_API_LINKED_LIST: { - res = JSAPILinkedList::Cast(receiver.GetTaggedObject())->Get(index); + res = JSAPILinkedList::Cast(receiver.GetTaggedObject())->Get(thread, index); break; } default: @@ -1259,14 +1261,14 @@ JSTaggedValue ObjectFastOperator::AddPropertyByIndex(JSThread *thread, JSTaggedV return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } -int64_t ObjectFastOperator::TryToElementsIndex(JSTaggedValue key) +int64_t ObjectFastOperator::TryToElementsIndex(JSThread *thread, JSTaggedValue key) { if (LIKELY(key.IsInt())) { return key.GetInt(); } if (key.IsString()) { uint32_t index = 0; - if (JSTaggedValue::StringToElementIndex(key, &index)) { + if (JSTaggedValue::StringToElementIndex(thread, key, &index)) { return static_cast(index); } } else if (key.IsDouble()) { diff --git a/ecmascript/object_fast_operator.h b/ecmascript/object_fast_operator.h index b01622d4ad..52c1c1f8b8 100644 --- a/ecmascript/object_fast_operator.h +++ b/ecmascript/object_fast_operator.h @@ -106,7 +106,7 @@ public: static inline JSTaggedValue FastGetPropertyByIndex(JSThread *thread, JSTaggedValue receiver, uint32_t index); - static inline JSTaggedValue FastParseDate(const EcmaString *str); + static inline JSTaggedValue FastParseDate(const JSThread *thread, const EcmaString *str); static inline PropertyAttributes AddPropertyByName(JSThread *thread, JSHandle objHandle, JSHandle keyHandle, @@ -116,7 +116,7 @@ public: static inline JSTaggedValue CallGetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue value); - static inline int64_t TryToElementsIndex(JSTaggedValue key); + static inline int64_t TryToElementsIndex(JSThread *thread, JSTaggedValue key); private: static inline JSTaggedValue CallSetter(JSThread *thread, JSTaggedValue receiver, JSTaggedValue value, JSTaggedValue accessorValue); @@ -136,7 +136,7 @@ private: static inline bool IsJSProxy(JSType jsType); - static inline bool TryStringOrSymbolToIndex(JSTaggedValue key, uint32_t *output); + static inline bool TryStringOrSymbolToIndex(JSThread *thread, JSTaggedValue key, uint32_t *output); static inline JSTaggedValue FastGetTypeArrayProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue holder, JSTaggedValue key, JSType jsType); diff --git a/ecmascript/object_operator.cpp b/ecmascript/object_operator.cpp index c0acc95bb4..197e2900d7 100644 --- a/ecmascript/object_operator.cpp +++ b/ecmascript/object_operator.cpp @@ -48,7 +48,7 @@ void ObjectOperator::HandleKey(const JSHandle &key) if (key->IsString()) { keyFromStringType_ = true; uint32_t index = 0; - if (JSTaggedValue::StringToElementIndex(key.GetTaggedValue(), &index)) { + if (JSTaggedValue::StringToElementIndex(thread_, key.GetTaggedValue(), &index)) { ASSERT(index < JSObject::MAX_ELEMENT_INDEX); elementIndex_ = index; return; @@ -196,7 +196,7 @@ JSHandle ObjectOperator::FastGetValue() { ASSERT(IsFound() && !value_.IsEmpty()); if (value_->IsPropertyBox()) { - value_.Update(PropertyBox::Cast(value_->GetTaggedObject())->GetValue()); + value_.Update(PropertyBox::Cast(value_->GetTaggedObject())->GetValue(thread_)); } if (!IsAccessorDescriptor()) { return value_; @@ -252,7 +252,7 @@ void ObjectOperator::UpdateDetectorOnSetPrototype(const JSThread *thread, JSTagg return; } case JSType::JS_PRIMITIVE_REF: { - if (JSPrimitiveRef::Cast(receiver.GetTaggedObject())->IsString() && + if (JSPrimitiveRef::Cast(receiver.GetTaggedObject())->IsString(thread) && !env->GetStringIteratorDetector()) { env->SetStringIteratorDetector(true); } @@ -348,8 +348,9 @@ void ObjectOperator::UpdateDetector(const JSThread *thread, JSTaggedValue receiv return; } env->SetSetIteratorDetector(true); - } else if ((receiver.IsJSPrimitiveRef() && JSPrimitiveRef::Cast(receiver.GetTaggedObject())->IsString()) || - receiver == env->GetTaggedStringPrototype()) { + } else if ((receiver.IsJSPrimitiveRef() && + JSPrimitiveRef::Cast(receiver.GetTaggedObject())->IsString(thread)) || + receiver == env->GetTaggedStringPrototype()) { if (env->GetStringIteratorDetector()) { return; } @@ -448,7 +449,7 @@ void ObjectOperator::ToPropertyDescriptor(PropertyDescriptor &desc) const auto result = GetValue(); bool isPropertyBox = result.IsPropertyBox(); if (isPropertyBox) { - result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(); + result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(thread_); } AccessorData *accessor = AccessorData::Cast(result.GetTaggedObject()); @@ -463,8 +464,8 @@ void ObjectOperator::ToPropertyDescriptor(PropertyDescriptor &desc) const } desc.SetValue(value); } else { - desc.SetGetter(JSHandle(thread_, accessor->GetGetter())); - desc.SetSetter(JSHandle(thread_, accessor->GetSetter())); + desc.SetGetter(JSHandle(thread_, accessor->GetGetter(thread_))); + desc.SetSetter(JSHandle(thread_, accessor->GetSetter(thread_))); } } @@ -527,17 +528,17 @@ void ObjectOperator::LookupGlobal(const JSHandle &obj) LookupElementInlinedProps(obj); return; } - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread_).GetTaggedObject()); if (array->GetLength() == 0) { return; } GlobalDictionary *dict = GlobalDictionary::Cast(array); - int entry = dict->FindEntry(key_.GetTaggedValue()); + int entry = dict->FindEntry(thread_, key_.GetTaggedValue()); if (entry == -1) { return; } - JSTaggedValue value(dict->GetBox(entry)); - auto attr = dict->GetAttributes(entry).GetValue(); + JSTaggedValue value(dict->GetBox(thread_, entry)); + auto attr = dict->GetAttributes(thread_, entry).GetValue(); SetFound(entry, value, attr, true); } @@ -550,37 +551,37 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) if (obj->IsJSGlobalObject()) { DISALLOW_GARBAGE_COLLECTION; - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread_).GetTaggedObject()); if (array->GetLength() == 0) { return; } GlobalDictionary *dict = GlobalDictionary::Cast(array); - int entry = dict->FindEntry(key_.GetTaggedValue()); + int entry = dict->FindEntry(thread_, key_.GetTaggedValue()); if (entry == -1) { return; } - JSTaggedValue value(dict->GetBox(entry)); - auto attr = dict->GetAttributes(entry).GetValue(); + JSTaggedValue value(dict->GetBox(thread_, entry)); + auto attr = dict->GetAttributes(thread_, entry).GetValue(); SetFound(entry, value, attr, !IsFoundDict()); return; } - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(obj->GetProperties(thread_).GetTaggedObject()); if (!array->IsDictionaryMode()) { JSHClass *jshclass = obj->GetJSHClass(); int entry = JSHClass::FindPropertyEntry(thread_, jshclass, key_.GetTaggedValue()); if (entry == -1) { return; } - JSTaggedValue attrs = jshclass->GetLayout(); + JSTaggedValue attrs = jshclass->GetLayout(thread_); LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(entry)); + PropertyAttributes attr(layoutInfo->GetAttr(thread_, entry)); ASSERT(entry == static_cast(attr.GetOffset())); JSTaggedValue value; if (attr.IsInlinedProps()) { - value = obj->GetPropertyInlinedPropsWithRep(entry, attr); + value = obj->GetPropertyInlinedPropsWithRep(thread_, entry, attr); if (value.IsHole()) { if (receiverHoleEntry_ == -1 && receiver_ == holder_) { receiverHoleEntry_ = entry; @@ -589,7 +590,7 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) } } else { entry -= static_cast(jshclass->GetInlinedProperties()); - value = array->Get(entry); + value = array->Get(thread_, entry); } SetFound(entry, value, attr.GetValue(), !IsFoundDict()); @@ -597,13 +598,13 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) } SetFoundDict(true); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key_.GetTaggedValue()); + int entry = dict->FindEntry(thread_, key_.GetTaggedValue()); if (entry == -1) { return; } - JSTaggedValue value = dict->GetValue(entry); - auto attr = dict->GetAttributes(entry).GetValue(); + JSTaggedValue value = dict->GetValue(thread_, entry); + auto attr = dict->GetAttributes(thread_, entry).GetValue(); SetFound(entry, value, attr, false); } @@ -614,20 +615,20 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle &rec if (!receiver->GetJSHClass()->IsDictionaryElement()) { JSObject::ElementsToDictionary(thread_, receiver); RETURN_IF_ABRUPT_COMPLETION(thread_); - auto dict = NumberDictionary::Cast(receiver->GetElements().GetTaggedObject()); - index = static_cast(dict->FindEntry(JSTaggedValue(index))); - PropertyAttributes origin = dict->GetAttributes(index); + auto dict = NumberDictionary::Cast(receiver->GetElements(thread_).GetTaggedObject()); + index = static_cast(dict->FindEntry(thread_, JSTaggedValue(index))); + PropertyAttributes origin = dict->GetAttributes(thread_, index); attr.SetDictionaryOrder(origin.GetDictionaryOrder()); dict->SetAttributes(thread_, index, attr); } else { - auto dict = NumberDictionary::Cast(receiver->GetElements().GetTaggedObject()); + auto dict = NumberDictionary::Cast(receiver->GetElements(thread_).GetTaggedObject()); dict->SetAttributes(thread_, index, attr); } // update found result UpdateFound(index, attr.GetValue(), false, true); } else if (receiver->IsJSGlobalObject()) { uint32_t index = GetIndex(); - JSHandle dictHandle(thread_, receiver->GetProperties()); + JSHandle dictHandle(thread_, receiver->GetProperties(thread_)); dictHandle->SetAttributes(thread_, index, attr); GlobalDictionary::InvalidatePropertyBox(thread_, dictHandle, index); } else { @@ -635,13 +636,13 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle &rec if (!receiver->GetJSHClass()->IsDictionaryMode()) { JSHandle dict(JSObject::TransitionToDictionary(thread_, receiver)); RETURN_IF_ABRUPT_COMPLETION(thread_); - index = static_cast(dict->FindEntry(key_.GetTaggedValue())); - PropertyAttributes origin = dict->GetAttributes(index); + index = static_cast(dict->FindEntry(thread_, key_.GetTaggedValue())); + PropertyAttributes origin = dict->GetAttributes(thread_, index); attr.SetDictSharedFieldType(attr.GetSharedFieldType()); attr.SetDictionaryOrder(origin.GetDictionaryOrder()); dict->SetAttributes(thread_, index, attr); } else { - auto dict = NameDictionary::Cast(receiver->GetProperties().GetTaggedObject()); + auto dict = NameDictionary::Cast(receiver->GetProperties(thread_).GetTaggedObject()); dict->SetAttributes(thread_, index, attr); } // update found result @@ -654,7 +655,7 @@ bool ObjectOperator::UpdateValueAndDetails(const JSHandle &receiver, c { auto valueAccessor = GetValue(); if (valueAccessor.IsPropertyBox()) { - valueAccessor = PropertyBox::Cast(valueAccessor.GetTaggedObject())->GetValue(); + valueAccessor = PropertyBox::Cast(valueAccessor.GetTaggedObject())->GetValue(thread_); } bool isInternalAccessor = IsAccessorDescriptor() && AccessorData::Cast(valueAccessor.GetTaggedObject())->IsInternal(); @@ -692,9 +693,9 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J bool isInternalAccessor, bool mayThrow) { if (IsElement()) { - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread_).GetTaggedObject()); if (!elements->IsDictionaryMode()) { - if (receiver.GetTaggedValue().IsJSCOWArray()) { + if (receiver.GetTaggedValue().IsJSCOWArray(thread_)) { JSArray::CheckAndCopyArray(thread_, JSHandle(receiver)); } else if (receiver->IsTypedArray()) { return SetTypedArrayPropByIndex(receiver, value); @@ -717,20 +718,20 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J if (receiver->IsJSGlobalObject()) { // need update cell type ? - auto *dict = GlobalDictionary::Cast(receiver->GetProperties().GetTaggedObject()); + auto *dict = GlobalDictionary::Cast(receiver->GetProperties(thread_).GetTaggedObject()); if (isInternalAccessor && !value->IsAccessor()) { - PropertyAttributes attr = dict->GetAttributes(GetIndex()); + PropertyAttributes attr = dict->GetAttributes(thread_, GetIndex()); attr.SetIsAccessor(false); dict->SetAttributes(thread_, GetIndex(), attr); } - PropertyBox *cell = dict->GetBox(GetIndex()); + PropertyBox *cell = dict->GetBox(thread_, GetIndex()); cell->SetValue(thread_, value.GetTaggedValue()); return true; } if (isInternalAccessor) { auto accessor = AccessorData::Cast(GetValue().GetTaggedObject()); - if (accessor->HasSetter()) { + if (accessor->HasSetter(thread_)) { bool res = accessor->CallInternalSet(thread_, JSHandle(receiver), value, mayThrow); if (receiver->GetJSHClass()->IsDictionaryMode()) { SetIsInlinedProps(false); @@ -740,7 +741,7 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J } } - JSMutableHandle properties(thread_, TaggedArray::Cast(receiver->GetProperties().GetTaggedObject())); + JSMutableHandle properties(thread_, TaggedArray::Cast(receiver->GetProperties(thread_).GetTaggedObject())); if (!properties->IsDictionaryMode()) { PropertyAttributes attr = GetAttr(); uint32_t offset = index_; @@ -762,9 +763,9 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J if (attr.IsInlinedProps()) { receiver->SetPropertyInlinedPropsWithRep(thread_, GetIndex(), actualValue.value); } else { - if (receiver.GetTaggedValue().IsJSCOWArray()) { + if (receiver.GetTaggedValue().IsJSCOWArray(thread_)) { JSArray::CheckAndCopyArray(thread_, JSHandle(receiver)); - properties.Update(JSHandle(receiver)->GetProperties()); + properties.Update(JSHandle(receiver)->GetProperties(thread_)); } if (actualValue.isTagged) { properties->Set(thread_, GetIndex(), value.GetTaggedValue()); @@ -812,11 +813,11 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const JSTaggedValue val = GetValue(); if (val.IsPropertyBox()) { PropertyBox *cell = PropertyBox::Cast(val.GetTaggedObject()); - obj = cell->GetValue().GetTaggedObject(); + obj = cell->GetValue(thread_).GetTaggedObject(); } } auto accessor = AccessorData::Cast(obj); - if (!accessor->IsInternal() || !accessor->HasSetter()) { + if (!accessor->IsInternal() || !accessor->HasSetter(thread_)) { attr.SetIsAccessor(false); attrChanged = true; } @@ -826,12 +827,12 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const } else { auto valueAccessor = GetValue(); if (valueAccessor.IsPropertyBox()) { - valueAccessor = PropertyBox::Cast(valueAccessor.GetTaggedObject())->GetValue(); + valueAccessor = PropertyBox::Cast(valueAccessor.GetTaggedObject())->GetValue(thread_); } bool isNotInternalAccessor = IsAccessorDescriptor() && !AccessorData::Cast(valueAccessor.GetTaggedObject())->IsInternal(); if (isNotInternalAccessor && !IsElement()) { - TaggedArray *properties = TaggedArray::Cast(receiver->GetProperties().GetTaggedObject()); + TaggedArray *properties = TaggedArray::Cast(receiver->GetProperties(thread_).GetTaggedObject()); if (attrChanged && !properties->IsDictionaryMode()) { // as some accessorData is in globalEnv, we need to new accessorData. JSHandle accessor = thread_->GetEcmaVM()->GetFactory()->NewAccessorData(); @@ -839,17 +840,17 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const if (desc.HasGetter()) { accessor->SetGetter(thread_, desc.GetGetter().GetTaggedValue()); } else { - accessor->SetGetter(thread_, JSHandle::Cast(value_)->GetGetter()); + accessor->SetGetter(thread_, JSHandle::Cast(value_)->GetGetter(thread_)); } if (desc.HasSetter()) { accessor->SetSetter(thread_, desc.GetSetter().GetTaggedValue()); } else { - accessor->SetSetter(thread_, JSHandle::Cast(value_)->GetSetter()); + accessor->SetSetter(thread_, JSHandle::Cast(value_)->GetSetter(thread_)); } JSHandle dict(JSObject::TransitionToDictionary(thread_, receiver)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - int entry = dict->FindEntry(key_.GetTaggedValue()); + int entry = dict->FindEntry(thread_, key_.GetTaggedValue()); ASSERT(entry != -1); dict->UpdateValueAndAttributes(thread_, entry, accessor.GetTaggedValue(), attr); return true; @@ -928,12 +929,12 @@ void ObjectOperator::WriteElement(const JSHandle &receiver, JSHandleGetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements(thread_).GetTaggedObject()); NumberDictionary *dictionary = NumberDictionary::Cast(elements); dictionary->UpdateValue(thread_, GetIndex(), value.GetTaggedValue()); } @@ -947,13 +948,13 @@ void ObjectOperator::DeleteElementInHolder() const return; } JSHandle holeHandle(thread_, JSTaggedValue::Hole()); - if (!ElementAccessor::IsDictionaryMode(obj)) { - if (obj.GetTaggedValue().IsJSCOWArray()) { + if (!ElementAccessor::IsDictionaryMode(thread_, obj)) { + if (obj.GetTaggedValue().IsJSCOWArray(thread_)) { JSArray::CheckAndCopyArray(thread_, JSHandle(obj)); } ElementAccessor::Set(thread_, obj, index_, holeHandle, true, ElementsKind::HOLE); } else { - TaggedArray *elements = TaggedArray::Cast(obj->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(obj->GetElements(thread_).GetTaggedObject()); JSHandle dictHandle(thread_, elements); JSHandle newDict = NumberDictionary::Remove(thread_, dictHandle, GetIndex()); obj->SetElements(thread_, newDict); @@ -998,7 +999,7 @@ void ObjectOperator::ResetStateForAddProperty() void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) { // if is js string, do special. - if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(obj.GetTaggedValue().GetTaggedObject())->IsString()) { + if (obj->IsJSPrimitiveRef() && JSPrimitiveRef::Cast(obj.GetTaggedValue().GetTaggedObject())->IsString(thread_)) { PropertyDescriptor desc(thread_); bool status = JSPrimitiveRef::StringGetIndexProperty(thread_, obj, elementIndex_, &desc); if (status) { @@ -1018,7 +1019,7 @@ void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) } return; } - TaggedArray *elements = TaggedArray::Cast(obj->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(obj->GetElements(thread_).GetTaggedObject()); if (elements->GetLength() == 0) { return; // Empty Array } @@ -1035,15 +1036,15 @@ void ObjectOperator::LookupElementInlinedProps(const JSHandle &obj) SetFound(elementIndex_, value, PropertyAttributes::GetDefaultAttributes(), !IsFoundDict()); } else { SetFoundDict(true); - NumberDictionary *dictionary = NumberDictionary::Cast(obj->GetElements().GetTaggedObject()); + NumberDictionary *dictionary = NumberDictionary::Cast(obj->GetElements(thread_).GetTaggedObject()); JSTaggedValue key(static_cast(elementIndex_)); - int entry = dictionary->FindEntry(key); + int entry = dictionary->FindEntry(thread_, key); if (entry == -1) { return; } - auto attr = dictionary->GetAttributes(entry).GetValue(); - SetFound(entry, dictionary->GetValue(entry), attr, false); + auto attr = dictionary->GetAttributes(thread_, entry).GetValue(); + SetFound(entry, dictionary->GetValue(thread_, entry), attr, false); } } } @@ -1054,7 +1055,7 @@ void ObjectOperator::AddPropertyInternal(const JSHandle &value) JSHandle obj(GetReceiver()); PropertyAttributes attr = GetAttr(); if (obj->IsJSGlobalObject()) { - JSMutableHandle dict(thread_, obj->GetProperties()); + JSMutableHandle dict(thread_, obj->GetProperties(thread_)); if (dict->GetLength() == 0) { dict.Update(GlobalDictionary::Create(thread_)); } diff --git a/ecmascript/object_operator.h b/ecmascript/object_operator.h index 0b9ff53100..57125792db 100644 --- a/ecmascript/object_operator.h +++ b/ecmascript/object_operator.h @@ -120,7 +120,7 @@ public: if (key_->IsString() && receiver_->IsString()) { JSTaggedValue lenKey = thread_->GlobalConstants()->GetLengthString(); EcmaString *proKey = EcmaString::Cast(key_->GetTaggedObject()); - return EcmaStringAccessor::StringsAreEqual(proKey, EcmaString::Cast(lenKey.GetTaggedObject())); + return EcmaStringAccessor::StringsAreEqual(thread_, proKey, EcmaString::Cast(lenKey.GetTaggedObject())); } return false; } diff --git a/ecmascript/ohos/ohos_pkg_args.h b/ecmascript/ohos/ohos_pkg_args.h index 87cc8e81b6..8e8862085b 100644 --- a/ecmascript/ohos/ohos_pkg_args.h +++ b/ecmascript/ohos/ohos_pkg_args.h @@ -208,11 +208,11 @@ public: return false; } JSHandle valueHandle(jsThread, resultValue); - JSHandle elements(jsThread, valueHandle->GetElements()); + JSHandle elements(jsThread, valueHandle->GetElements(jsThread)); JSMutableHandle entry(jsThread, JSTaggedValue::Undefined()); JSMutableHandle entryHandle(jsThread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < elements->GetLength(); i++) { - entry.Update(elements->Get(i)); + entry.Update(elements->Get(jsThread, i)); if (entry->IsHole()) { continue; } @@ -254,14 +254,14 @@ public: JSMutableHandle key(jsThread, JSTaggedValue::Undefined()); JSMutableHandle value(jsThread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < nameList->GetLength(); i++) { - key.Update(nameList->Get(i)); + key.Update(nameList->Get(jsThread, i)); value.Update(JSObject::GetProperty(jsThread, valueHandle, key).GetValue()); if (!key->IsString() || !value->IsString()) { LOG_COMPILER(ERROR) << "Pkg info parse from js object failed. key and value must be string type."; return false; } - UpdateProperty(ConvertToString(*JSTaggedValue::ToString(jsThread, key)).c_str(), - ConvertToString(*JSTaggedValue::ToString(jsThread, value)).c_str()); + UpdateProperty(ConvertToString(jsThread, *JSTaggedValue::ToString(jsThread, key)).c_str(), + ConvertToString(jsThread, *JSTaggedValue::ToString(jsThread, value)).c_str()); } return Valid(); } diff --git a/ecmascript/patch/patch_loader.cpp b/ecmascript/patch/patch_loader.cpp index 1b4c20c181..993f243147 100644 --- a/ecmascript/patch/patch_loader.cpp +++ b/ecmascript/patch/patch_loader.cpp @@ -156,11 +156,11 @@ PatchErrorCode PatchLoader::UnloadPatchInternal(JSThread *thread, const CString // After the method replaced, the methodId is baseMethodId, // and the JSPandaFile of replaced method is baseFile ReplacedMethod replacedMethod {baseMethodId, baseFileName}; - patchInfo.replacedPatchMethods.emplace(replacedMethod, patchMethod->GetRecordNameStr()); + patchInfo.replacedPatchMethods.emplace(replacedMethod, patchMethod->GetRecordNameStr(thread)); ReplaceMethod(thread, patchMethod, baseMethodLiteral, baseConstpoolValue); LOG_ECMA(DEBUG) << "Replace base method: " - << patchMethod->GetRecordNameStr() - << ":" << patchMethod->GetMethodName(); + << patchMethod->GetRecordNameStr(thread) + << ":" << patchMethod->GetMethodName(thread); } vm->ClearPatchModules(); @@ -189,23 +189,23 @@ Method *PatchLoader::GetPatchMethod(JSThread *thread, Method *patchMethod = nullptr; ConstantPool *baseConstpool = ConstantPool::Cast(constpoolVal.GetTaggedObject()); if (literalIndex == UINT32_MAX) { - JSTaggedValue value = baseConstpool->GetObjectFromCache(constpoolIndex); + JSTaggedValue value = baseConstpool->GetObjectFromCache(thread, constpoolIndex); ASSERT(value.IsMethod()); patchMethod = Method::Cast(value.GetTaggedObject()); } else { ClassLiteral *classLiteral; - if (baseConstpool->GetObjectFromCache(constpoolIndex).IsHole()) { + if (baseConstpool->GetObjectFromCache(thread, constpoolIndex).IsHole()) { JSTaggedValue unsharedBaseConstpool = thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpoolVal); classLiteral = ClassLiteral::Cast( - ConstantPool::Cast(unsharedBaseConstpool.GetTaggedObject())->GetObjectFromCache(constpoolIndex)); + ConstantPool::Cast(unsharedBaseConstpool.GetTaggedObject())->GetObjectFromCache(thread, constpoolIndex)); } else { - classLiteral = ClassLiteral::Cast(baseConstpool->GetObjectFromCache(constpoolIndex)); + classLiteral = ClassLiteral::Cast(baseConstpool->GetObjectFromCache(thread, constpoolIndex)); } - TaggedArray *literalArray = TaggedArray::Cast(classLiteral->GetArray()); + TaggedArray *literalArray = TaggedArray::Cast(classLiteral->GetArray(thread)); JSTaggedValue value = literalArray->Get(thread, literalIndex); ASSERT(value.IsFunctionTemplate()); FunctionTemplate *func = FunctionTemplate::Cast(value.GetTaggedObject()); - patchMethod = Method::Cast(func->GetMethod().GetTaggedObject()); + patchMethod = Method::Cast(func->GetMethod(thread).GetTaggedObject()); } return patchMethod; } @@ -255,8 +255,8 @@ void PatchLoader::UpdateJSFunction(JSThread *thread, PatchInfo &patchInfo) #endif if (JSTaggedValue(obj).IsJSFunction()) { JSFunction *function = JSFunction::Cast(obj); - EntityId methodId = Method::Cast(function->GetMethod())->GetMethodId(); - const JSPandaFile *jsPandaFile = Method::Cast(function->GetMethod())->GetJSPandaFile(); + EntityId methodId = Method::Cast(function->GetMethod(thread))->GetMethodId(); + const JSPandaFile *jsPandaFile = Method::Cast(function->GetMethod(thread))->GetJSPandaFile(thread); CString fileName {}; if (jsPandaFile != nullptr) { fileName = jsPandaFile->GetJSPandaFileDesc(); @@ -271,8 +271,8 @@ void PatchLoader::UpdateJSFunction(JSThread *thread, PatchInfo &patchInfo) } } else if (JSTaggedValue(obj).IsFunctionTemplate()) { auto funcTemp = FunctionTemplate::Cast(obj); - EntityId methodId = Method::Cast(funcTemp->GetMethod())->GetMethodId(); - const JSPandaFile *jsPandaFile = Method::Cast(funcTemp->GetMethod())->GetJSPandaFile(); + EntityId methodId = Method::Cast(funcTemp->GetMethod(thread))->GetMethodId(); + const JSPandaFile *jsPandaFile = Method::Cast(funcTemp->GetMethod(thread))->GetJSPandaFile(thread); CString fileName {}; if (jsPandaFile != nullptr) { fileName = jsPandaFile->GetJSPandaFileDesc(); @@ -307,7 +307,7 @@ void PatchLoader::UpdateModuleForColdPatch(JSThread *thread, EntityId methodId, if (JSTaggedValue(obj).IsJSFunction()) { JSFunction *function = nullptr; function = JSFunction::Cast(obj); - EntityId methodIdLoop = Method::Cast(function->GetMethod())->GetMethodId(); + EntityId methodIdLoop = Method::Cast(function->GetMethod(thread))->GetMethodId(); if (methodId == methodIdLoop) { JSHandle moduleRecord = thread->GetEcmaVM()->FindPatchModule(recordName); @@ -319,7 +319,7 @@ void PatchLoader::UpdateModuleForColdPatch(JSThread *thread, EntityId methodId, } } else if (JSTaggedValue(obj).IsFunctionTemplate()) { auto funcTemp = FunctionTemplate::Cast(obj); - EntityId methodIdLoop = Method::Cast(funcTemp->GetMethod())->GetMethodId(); + EntityId methodIdLoop = Method::Cast(funcTemp->GetMethod(thread))->GetMethodId(); if (methodId == methodIdLoop) { JSHandle moduleRecord = thread->GetEcmaVM()->FindPatchModule(recordName); @@ -355,7 +355,7 @@ void PatchLoader::FindAndReplaceSameMethod(JSThread *thread, const JSPandaFile * uint32_t constpoolNum = item.first; uint32_t baseConstpoolSize = baseConstpool->GetCacheLength(); for (uint32_t constpoolIndex = 0; constpoolIndex < baseConstpoolSize; constpoolIndex++) { - JSTaggedValue constpoolValue = baseConstpool->GetObjectFromCache(constpoolIndex); + JSTaggedValue constpoolValue = baseConstpool->GetObjectFromCache(thread, constpoolIndex); if (!constpoolValue.IsMethod() && !constpoolValue.IsClassLiteral()) { continue; } @@ -376,11 +376,11 @@ void PatchLoader::FindAndReplaceSameMethod(JSThread *thread, const JSPandaFile * CString patchFileName = patchFile->GetJSPandaFileDesc(); ReplacedMethod replacedMethod {patchMethodId, patchFileName}; JSTaggedValue patchConstpoolValue = vm->FindConstpool(patchFile, patchMethodId); - patchInfo.replacedPatchMethods.emplace(replacedMethod, baseMethod->GetRecordNameStr()); + patchInfo.replacedPatchMethods.emplace(replacedMethod, baseMethod->GetRecordNameStr(thread)); ReplaceMethod(thread, baseMethod, patchMethodLiteral, patchConstpoolValue); LOG_ECMA(DEBUG) << "Replace base method: " - << baseMethod->GetRecordNameStr() << ": " - << baseMethod->GetMethodName(); + << baseMethod->GetRecordNameStr(thread) << ": " + << baseMethod->GetMethodName(thread); BaseMethodIndex indexs = {constpoolNum, constpoolIndex}; SaveBaseMethodInfo(patchInfo, baseFile, baseMethodId, indexs); @@ -395,7 +395,7 @@ void PatchLoader::FindAndReplaceSameMethod(JSThread *thread, const JSPandaFile * ConstantPool *baseUnsharedConstpool = ConstantPool::Cast(unsharedConstpool.GetTaggedObject()); const uint32_t len = baseUnsharedConstpool->GetCacheLength(); for (uint32_t constpoolIndex = 0; constpoolIndex < len; constpoolIndex++) { - JSTaggedValue constpoolValue = baseUnsharedConstpool->GetObjectFromCache(constpoolIndex); + JSTaggedValue constpoolValue = baseUnsharedConstpool->GetObjectFromCache(thread, constpoolIndex); if (!constpoolValue.IsMethod() && !constpoolValue.IsClassLiteral()) { continue; } @@ -413,7 +413,7 @@ void PatchLoader::FindAndReplaceClassLiteral(JSThread *thread, const JSPandaFile { // For class literal. ClassLiteral *classLiteral = ClassLiteral::Cast(constpoolValue); - TaggedArray *literalArray = TaggedArray::Cast(classLiteral->GetArray()); + TaggedArray *literalArray = TaggedArray::Cast(classLiteral->GetArray(thread)); uint32_t literalLength = literalArray->GetLength(); for (uint32_t literalIndex = 0; literalIndex < literalLength; literalIndex++) { JSTaggedValue literalItem = literalArray->Get(thread, literalIndex); @@ -423,7 +423,7 @@ void PatchLoader::FindAndReplaceClassLiteral(JSThread *thread, const JSPandaFile // Every record is the same in current class literal. FunctionTemplate *func = FunctionTemplate::Cast(literalItem.GetTaggedObject()); - Method *baseMethod = Method::Cast(func->GetMethod().GetTaggedObject()); + Method *baseMethod = Method::Cast(func->GetMethod(thread).GetTaggedObject()); EntityId baseMethodId = baseMethod->GetMethodId(); MethodLiteral *patchMethodLiteral = FindSameMethod(patchInfo, baseFile, baseMethodId, baseClassInfo); @@ -437,11 +437,11 @@ void PatchLoader::FindAndReplaceClassLiteral(JSThread *thread, const JSPandaFile // and the JSPandaFile of replaced method is patchFile ReplacedMethod replacedMethod {patchMethodId, patchFileName}; JSTaggedValue patchConstpoolValue = thread->GetEcmaVM()->FindConstpool(patchFile, patchMethodId); - patchInfo.replacedPatchMethods.emplace(replacedMethod, baseMethod->GetRecordNameStr()); + patchInfo.replacedPatchMethods.emplace(replacedMethod, baseMethod->GetRecordNameStr(thread)); ReplaceMethod(thread, baseMethod, patchMethodLiteral, patchConstpoolValue); LOG_ECMA(DEBUG) << "Replace base method: " - << baseMethod->GetRecordNameStr() << ": " - << baseMethod->GetMethodName(); + << baseMethod->GetRecordNameStr(thread) << ": " + << baseMethod->GetMethodName(thread); BaseMethodIndex indexs = {constpoolNum, constpoolIndex, literalIndex}; SaveBaseMethodInfo(patchInfo, baseFile, baseMethodId, indexs); diff --git a/ecmascript/patch/quick_fix_manager.cpp b/ecmascript/patch/quick_fix_manager.cpp index 0c03de0f2f..6049db4529 100644 --- a/ecmascript/patch/quick_fix_manager.cpp +++ b/ecmascript/patch/quick_fix_manager.cpp @@ -245,7 +245,7 @@ bool QuickFixManager::IsQuickFixCausedException(JSThread *thread, // get and parse stackinfo. JSHandle stackKey = thread->GlobalConstants()->GetHandledStackString(); JSHandle stack(JSObject::GetProperty(thread, exceptionInfo, stackKey).GetValue()); - CString stackInfo = ConvertToString(*stack); + CString stackInfo = ConvertToString(thread, *stack); CUnorderedSet methodNames = ParseStackInfo(stackInfo); // check whether the methodNames contains a patch method name. diff --git a/ecmascript/pgo_profiler/pgo_extra_profiler.h b/ecmascript/pgo_profiler/pgo_extra_profiler.h index a3acf5a9df..b8dee03964 100644 --- a/ecmascript/pgo_profiler/pgo_extra_profiler.h +++ b/ecmascript/pgo_profiler/pgo_extra_profiler.h @@ -34,14 +34,14 @@ public: DECL_VISIT_OBJECT(RECEIVER_OBJECT_OFFSET, LAST_OFFSET); - JSHClass* GetReceiverHClass() const + JSHClass* GetReceiverHClass(const JSThread *thread) const { - return GetReceiverObject().GetHeapObject()->GetClass(); + return GetReceiverObject(thread).GetHeapObject()->GetClass(); } - JSHClass* GetHolderHClass() const + JSHClass* GetHolderHClass(const JSThread *thread) const { - return GetHolderObject().GetTaggedObject()->GetClass(); + return GetHolderObject(thread).GetTaggedObject()->GetClass(); } void SetReceiver(const JSThread *thread, JSTaggedValue value) @@ -54,14 +54,14 @@ public: SetHolderObject(thread, value); } - JSTaggedValue GetReceiver() const + JSTaggedValue GetReceiver(const JSThread *thread) const { - return GetReceiverObject(); + return GetReceiverObject(thread); } - JSTaggedValue GetHolder() const + JSTaggedValue GetHolder(const JSThread *thread) const { - return GetHolderObject(); + return GetHolderObject(thread); } void Clear(const JSThread *thread) @@ -80,14 +80,14 @@ public: SetHolderObject(thread, JSTaggedValue::Hole()); } - bool operator==(const ExtraProfileTypeInfo& other) const + bool EuqalTo(JSThread *thread, const ExtraProfileTypeInfo& other) const { - return GetReceiverObject() == other.GetReceiverObject() && GetHolderObject() == other.GetHolderObject(); + return GetReceiverObject(thread) == other.GetReceiverObject(thread) && GetHolderObject(thread) == other.GetHolderObject(thread); } - bool IsValid() const + bool IsValid(JSThread *thread) const { - return !GetReceiverObject().IsHole() && !GetReceiverObject().IsUndefined(); + return !GetReceiverObject(thread).IsHole() && !GetReceiverObject(thread).IsUndefined(); } DECL_DUMP() diff --git a/ecmascript/pgo_profiler/pgo_profiler.cpp b/ecmascript/pgo_profiler/pgo_profiler.cpp index a1b91c267d..3902d84641 100644 --- a/ecmascript/pgo_profiler/pgo_profiler.cpp +++ b/ecmascript/pgo_profiler/pgo_profiler.cpp @@ -44,8 +44,9 @@ void PGOProfiler::ProfileDefineClass(JSTaggedType ctor) if (!ctorValue.IsJSFunction()) { return; } + JSThread *thread = vm_->GetJSThread(); auto ctorFunc = JSFunction::Cast(ctorValue.GetTaggedObject()); - auto ctorMethodValue = ctorFunc->GetMethod(); + auto ctorMethodValue = ctorFunc->GetMethod(thread); if (!ctorMethodValue.IsMethod()) { return; } @@ -56,15 +57,15 @@ void PGOProfiler::ProfileDefineClass(JSTaggedType ctor) return; } - auto abcId = GetMethodAbcId(ctorFunc); + auto abcId = GetMethodAbcId(thread, ctorFunc); auto chc = ctorFunc->GetClass(); SetRootProfileType(chc, abcId, entityId, ProfileType::Kind::ConstructorId); - auto protoOrHClass = ctorFunc->GetProtoOrHClass(); + auto protoOrHClass = ctorFunc->GetProtoOrHClass(thread); if (protoOrHClass.IsJSHClass()) { auto ihc = JSHClass::Cast(protoOrHClass.GetTaggedObject()); SetRootProfileType(ihc, abcId, entityId, ProfileType::Kind::ClassId); - protoOrHClass = ihc->GetProto(); + protoOrHClass = ihc->GetProto(thread); } if (protoOrHClass.IsJSObject()) { auto phc = protoOrHClass.GetTaggedObject()->GetClass(); @@ -82,11 +83,12 @@ void PGOProfiler::ProfileClassRootHClass(JSTaggedType ctor, JSTaggedType rootHcV if (!ctorValue.IsJSFunction()) { return; } + JSThread *thread = vm_->GetJSThread(); auto ctorFunc = JSFunction::Cast(ctorValue.GetTaggedObject()); if (!FunctionKindVerify(ctorFunc)) { return; } - auto ctorMethodValue = ctorFunc->GetMethod(); + auto ctorMethodValue = ctorFunc->GetMethod(thread); if (!ctorMethodValue.IsMethod()) { return; } @@ -97,7 +99,7 @@ void PGOProfiler::ProfileClassRootHClass(JSTaggedType ctor, JSTaggedType rootHcV } auto rootHc = JSHClass::Cast(JSTaggedValue(rootHcValue).GetTaggedObject()); - auto abcId = GetMethodAbcId(ctorFunc); + auto abcId = GetMethodAbcId(thread, ctorFunc); SetRootProfileType(rootHc, abcId, entityId, kind); } @@ -111,14 +113,15 @@ void PGOProfiler::ProfileNapiRootHClass(JSTaggedType ctor, JSTaggedType rootHcVa if (!ctorValue.IsJSFunction()) { return; } + JSThread *thread = vm_->GetJSThread(); auto ctorFunc = JSFunction::Cast(ctorValue.GetTaggedObject()); - auto ctorMethodValue = ctorFunc->GetMethod(); + auto ctorMethodValue = ctorFunc->GetMethod(thread); if (!ctorMethodValue.IsMethod()) { return; } auto entityId = Method::Cast(ctorMethodValue)->GetMethodId().GetOffset(); auto rootHc = JSHClass::Cast(JSTaggedValue(rootHcValue).GetTaggedObject()); - auto abcId = GetMethodAbcId(ctorFunc); + auto abcId = GetMethodAbcId(thread, ctorFunc); SetRootProfileType(rootHc, abcId, entityId, kind); } @@ -131,7 +134,7 @@ void PGOProfiler::ProfileProtoTransitionClass(JSHandle func, } auto thread = vm_->GetJSThread(); JSHClass *phc = proto->GetTaggedObject()->GetClass(); - JSHClass *phcRoot = JSHClass::FindRootHClass(phc); + JSHClass *phcRoot = JSHClass::FindRootHClass(thread, phc); auto* transitionTable = vm_->GetFunctionProtoTransitionTable(); JSTaggedType baseIhc = transitionTable->GetFakeParent(JSTaggedType(phcRoot)); if (baseIhc == 0) { @@ -143,7 +146,7 @@ void PGOProfiler::ProfileProtoTransitionClass(JSHandle func, // In the case of `subclass.prototype = Object.create(superclass)`, the current PGO is // unable to collect the pgotype of Object.create(superclass). As a result, when subclass.prototype is modified, // ts hclass cannot be reconstructed during the AOT phase, leading to deoptimization. - JSHClass *baseRoot = JSHClass::FindRootHClass(JSHClass::Cast(JSTaggedValue(baseIhc).GetTaggedObject())); + JSHClass *baseRoot = JSHClass::FindRootHClass(thread, JSHClass::Cast(JSTaggedValue(baseIhc).GetTaggedObject())); if (GetProfileType(baseRoot).IsNone()) { return; } @@ -180,12 +183,12 @@ void PGOProfiler::ProfileProtoTransitionPrototype(JSHandle func, return; } - auto method = func->GetMethod(); + auto thread = vm_->GetJSThread(); + auto method = func->GetMethod(thread); if (Method::Cast(method)->IsNativeWithCallField()) { return; } // set prototype once, and just skip this time - auto thread = vm_->GetJSThread(); JSHandle keyHandle(thread, thread->GlobalConstants()->GetGlobalConstantObject( static_cast(ConstantIndex::PROTO_TRANS_ROOT_HCLASS_SYMBOL_INDEX))); PropertyDescriptor desc(thread); @@ -203,7 +206,7 @@ void PGOProfiler::ProfileProtoTransitionPrototype(JSHandle func, // In the case of `subclass.prototype = Object.create(superclass)`, the current PGO is // unable to collect the pgotype of Object.create(superclass). As a result, when subclass.prototype is modified, // ts hclass cannot be reconstructed during the AOT phase, leading to deoptimization. - JSHClass *baseRoot = JSHClass::FindRootHClass(JSHClass::Cast(baseIhc.GetTaggedValue().GetTaggedObject())); + JSHClass *baseRoot = JSHClass::FindRootHClass(thread, JSHClass::Cast(baseIhc.GetTaggedValue().GetTaggedObject())); if (GetProfileType(baseRoot).IsNone()) { return; } @@ -219,7 +222,7 @@ void PGOProfiler::ProfileProtoTransitionPrototype(JSHandle func, JSObject::DefineOwnProperty(thread, JSHandle::Cast(func), keyHandle, definePropertyDesc); // record phc type - JSHClass *phc0Root = JSHClass::FindRootHClass(oldPrototype->GetTaggedObject()->GetClass()); + JSHClass *phc0Root = JSHClass::FindRootHClass(thread, oldPrototype->GetTaggedObject()->GetClass()); ProfileClassRootHClass(func.GetTaggedType(), JSTaggedType(phc0Root), ProfileType::Kind::PrototypeId); ProfileClassRootHClass(func.GetTaggedType(), transPhc.GetTaggedType(), ProfileType::Kind::TransitionPrototypeId); } @@ -236,7 +239,8 @@ void PGOProfiler::ProfileDefineGetterSetter(JSHClass* receiverHClass, if (!funcValue.IsJSFunction()) { return; } - auto methodValue = JSFunction::Cast(funcValue)->GetMethod(); + JSThread *thread = vm_->GetJSThread(); + auto methodValue = JSFunction::Cast(funcValue)->GetMethod(thread); if (!methodValue.IsMethod()) { return; } @@ -248,29 +252,29 @@ void PGOProfiler::ProfileDefineGetterSetter(JSHClass* receiverHClass, workNode->SetValue(JSTaggedType(JSFunction::Cast(funcValue))); } - JSHandle key(vm_->GetJSThread(), JSTaggedValue(pcOffset)); - JSHandle receiverHClassHandle(vm_->GetJSThread(), receiverHClass); - JSHandle holderHClassHandle(vm_->GetJSThread(), holderHClass); - JSHandle profileTypeInfoValue(vm_->GetJSThread(), function->GetRawProfileTypeInfo()); + JSHandle key(thread, JSTaggedValue(pcOffset)); + JSHandle receiverHClassHandle(thread, receiverHClass); + JSHandle holderHClassHandle(thread, holderHClass); + JSHandle profileTypeInfoValue(thread, function->GetRawProfileTypeInfo(thread)); JSHandle profileTypeInfoCell(profileTypeInfoValue); - if (function->HasProfileTypeInfo(vm_->GetJSThread())) { - JSHandle profileTypeInfo(vm_->GetJSThread(), profileTypeInfoCell->GetValue()); - JSHandle dictJShandle = ProfileTypeInfo::CreateOrGetExtraInfoMap(vm_->GetJSThread(), + if (function->HasProfileTypeInfo(thread)) { + JSHandle profileTypeInfo(thread, profileTypeInfoCell->GetValue(thread)); + JSHandle dictJShandle = ProfileTypeInfo::CreateOrGetExtraInfoMap(thread, profileTypeInfo); - int entry = dictJShandle->FindEntry(key.GetTaggedValue()); + int entry = dictJShandle->FindEntry(thread, key.GetTaggedValue()); if (entry == -1) { - ProfileTypeInfo::UpdateExtraInfoMap(vm_->GetJSThread(), dictJShandle, key, receiverHClassHandle, + ProfileTypeInfo::UpdateExtraInfoMap(thread, dictJShandle, key, receiverHClassHandle, holderHClassHandle, profileTypeInfo); return; } - ExtraProfileTypeInfo *mapInfoObj = ExtraProfileTypeInfo::Cast(dictJShandle->GetValue(entry).GetTaggedObject()); - if (mapInfoObj->GetReceiver() == receiverHClassHandle.GetTaggedValue().CreateAndGetWeakRef() && - mapInfoObj->GetHolder() == holderHClassHandle.GetTaggedValue()) { + ExtraProfileTypeInfo *mapInfoObj = ExtraProfileTypeInfo::Cast(dictJShandle->GetValue(thread, entry).GetTaggedObject()); + if (mapInfoObj->GetReceiver(thread) == receiverHClassHandle.GetTaggedValue().CreateAndGetWeakRef() && + mapInfoObj->GetHolder(thread) == holderHClassHandle.GetTaggedValue()) { return; } - ExtraProfileTypeInfo::Cast(dictJShandle->GetValue(entry).GetTaggedObject())->Clear(vm_->GetJSThread()); + ExtraProfileTypeInfo::Cast(dictJShandle->GetValue(thread, entry).GetTaggedObject())->Clear(thread); } } @@ -316,8 +320,8 @@ void PGOProfiler::UpdateTrackInfo(JSTaggedValue trackInfoVal) { if (trackInfoVal.IsHeapObject()) { auto trackInfo = TrackInfo::Cast(trackInfoVal.GetTaggedObject()); - auto func = trackInfo->GetCachedFunc(); auto thread = vm_->GetJSThread(); + auto func = trackInfo->GetCachedFunc(thread); if (!func.IsWeak()) { return; } @@ -329,7 +333,7 @@ void PGOProfiler::UpdateTrackInfo(JSTaggedValue trackInfoVal) if (!function->HasProfileTypeInfo(thread)) { return; } - auto profileTypeInfoVal = function->GetProfileTypeInfo(); + auto profileTypeInfoVal = function->GetProfileTypeInfo(thread); if (profileTypeInfoVal.IsUndefined() || !profileTypeInfoVal.IsTaggedArray()) { return; } @@ -353,7 +357,7 @@ void PGOProfiler::PGODump(JSTaggedType func) if (!funcValue.IsJSFunction()) { return; } - auto methodValue = JSFunction::Cast(funcValue)->GetMethod(); + auto methodValue = JSFunction::Cast(funcValue)->GetMethod(vm_->GetJSThread()); if (!methodValue.IsMethod()) { return; } @@ -417,7 +421,7 @@ void PGOProfiler::PGOPreDump(JSTaggedType func) if (!funcValue.IsJSFunction()) { return; } - auto methodValue = JSFunction::Cast(funcValue)->GetMethod(); + auto methodValue = JSFunction::Cast(funcValue)->GetMethod(vm_->GetJSThread()); if (!methodValue.IsMethod()) { return; } @@ -452,40 +456,42 @@ void PGOProfiler::UpdateExtraProfileTypeInfo(ApEntityId abcId, if (!func->HasProfileTypeInfo(vm_->GetJSThread())) { return; } - ProfileTypeInfoCell *cell = ProfileTypeInfoCell::Cast(func->GetRawProfileTypeInfo()); - ProfileTypeInfo *info = ProfileTypeInfo::Cast((cell->GetValue()).GetTaggedObject()); - if ((info->GetExtraInfoMap()).IsHole() || (info->GetExtraInfoMap()).IsUndefined()) { + JSThread *thread = vm_->GetJSThread(); + ProfileTypeInfoCell *cell = ProfileTypeInfoCell::Cast(func->GetRawProfileTypeInfo(thread)); + ProfileTypeInfo *info = ProfileTypeInfo::Cast((cell->GetValue(thread)).GetTaggedObject()); + if ((info->GetExtraInfoMap(thread)).IsHole() || (info->GetExtraInfoMap(thread)).IsUndefined()) { return; } - NumberDictionary *dict = NumberDictionary::Cast(info->GetExtraInfoMap().GetTaggedObject()); + NumberDictionary *dict = NumberDictionary::Cast(info->GetExtraInfoMap(thread).GetTaggedObject()); int size = dict->Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(dict->GetKey(hashIndex)); + JSTaggedValue key(dict->GetKey(thread, hashIndex)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(dict->GetValue(hashIndex)); + JSTaggedValue val(dict->GetValue(thread, hashIndex)); ExtraProfileTypeInfo *extraInfo = ExtraProfileTypeInfo::Cast(val.GetTaggedObject()); - if (!extraInfo->IsValid()) { + if (!extraInfo->IsValid(thread)) { continue; } AddObjectInfo(abcId, recordName, methodId, key.GetInt(), - extraInfo->GetReceiverHClass(), - extraInfo->GetReceiverHClass(), - extraInfo->GetHolderHClass()); + extraInfo->GetReceiverHClass(thread), + extraInfo->GetReceiverHClass(thread), + extraInfo->GetHolderHClass(thread)); } } } bool PGOProfiler::HasValidExtraProfileTypeInfo(JSFunction *func) { - if (!func->HasProfileTypeInfo(vm_->GetJSThread())) { + JSThread *thread = vm_->GetJSThread(); + if (!func->HasProfileTypeInfo(thread)) { return false; } - ProfileTypeInfoCell *profileCell = ProfileTypeInfoCell::Cast(func->GetRawProfileTypeInfo()); - ProfileTypeInfo *profileInfo = ProfileTypeInfo::Cast((profileCell->GetValue()).GetTaggedObject()); - JSTaggedValue map = profileInfo->GetExtraInfoMap(); + ProfileTypeInfoCell *profileCell = ProfileTypeInfoCell::Cast(func->GetRawProfileTypeInfo(thread)); + ProfileTypeInfo *profileInfo = ProfileTypeInfo::Cast((profileCell->GetValue(thread)).GetTaggedObject()); + JSTaggedValue map = profileInfo->GetExtraInfoMap(thread); if (map.IsHole() || map.IsUndefined()) { return false; } @@ -523,6 +529,7 @@ void PGOProfiler::DumpBeforeDestroy(JSThread *thread) void PGOProfiler::HandlePGOPreDump() { + JSThread *thread = vm_->GetJSThread(); ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "PGOProfiler::HandlePGOPreDump"); if (!isEnable_ || !vm_->GetJSOptions().IsEnableProfileDump()) { return; @@ -533,31 +540,31 @@ void PGOProfiler::HandlePGOPreDump() holder_->TransferToRunning(); #endif DISALLOW_GARBAGE_COLLECTION; - preDumpWorkList_.Iterate([this](WorkNode* current) { + preDumpWorkList_.Iterate([this, thread](WorkNode* current) { JSTaggedValue funcValue = JSTaggedValue(current->GetValue()); if (!funcValue.IsJSFunction()) { return; } auto func = JSFunction::Cast(funcValue); - if (func->IsSendableOrConcurrentFunction()) { + if (func->IsSendableOrConcurrentFunction(thread)) { return; } - JSTaggedValue methodValue = func->GetMethod(); + JSTaggedValue methodValue = func->GetMethod(thread); if (!methodValue.IsMethod()) { return; } - CString recordName = func->GetRecordName(); + CString recordName = func->GetRecordName(thread); if (recordName.empty()) { return; } - auto abcId = GetMethodAbcId(func); + auto abcId = GetMethodAbcId(thread, func); ProcessExtraProfileTypeInfo(func, abcId, recordName, methodValue, current); ProfileType recordType = GetRecordProfileType(abcId, recordName); - recordInfos_->AddMethod(recordType, Method::Cast(methodValue), SampleMode::HOTNESS_MODE); + recordInfos_->AddMethod(thread, recordType, Method::Cast(methodValue), SampleMode::HOTNESS_MODE); ProfileBytecode(abcId, recordName, funcValue); if (PGOTrace::GetInstance()->IsEnable()) { - PGOTrace::GetInstance()->TryGetMethodData(methodValue, false); + PGOTrace::GetInstance()->TryGetMethodData(thread, methodValue, false); } }); #ifdef USE_CMC_GC @@ -567,6 +574,7 @@ void PGOProfiler::HandlePGOPreDump() void PGOProfiler::HandlePGODump() { + JSThread *thread = vm_->GetJSThread(); ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "PGOProfiler::HandlePGODump"); if (!isEnable_ || !vm_->GetJSOptions().IsEnableProfileDump()) { return; @@ -589,32 +597,32 @@ void PGOProfiler::HandlePGODump() continue; } auto func = JSFunction::Cast(value); - if (func->IsSendableOrConcurrentFunction()) { + if (func->IsSendableOrConcurrentFunction(thread)) { current = PopFromProfileQueue(); continue; } - JSTaggedValue methodValue = func->GetMethod(); + JSTaggedValue methodValue = func->GetMethod(thread); if (!methodValue.IsMethod()) { current = PopFromProfileQueue(); continue; } - CString recordName = func->GetRecordName(); + CString recordName = func->GetRecordName(thread); if (recordName.empty()) { current = PopFromProfileQueue(); continue; } - auto abcId = GetMethodAbcId(func); + auto abcId = GetMethodAbcId(thread, func); ProcessExtraProfileTypeInfo(func, abcId, recordName, methodValue, current); ProfileType recordType = GetRecordProfileType(abcId, recordName); - if (recordInfos_->AddMethod(recordType, Method::Cast(methodValue), SampleMode::HOTNESS_MODE)) { + if (recordInfos_->AddMethod(thread, recordType, Method::Cast(methodValue), SampleMode::HOTNESS_MODE)) { methodCount_++; } ProfileBytecode(abcId, recordName, value); current = PopFromProfileQueue(); if (PGOTrace::GetInstance()->IsEnable()) { - PGOTrace::GetInstance()->TryGetMethodData(methodValue, true); + PGOTrace::GetInstance()->TryGetMethodData(thread, methodValue, true); } } #ifdef USE_CMC_GC @@ -663,16 +671,17 @@ void PGOProfiler::ProfileBytecode(ApEntityId abcId, const CString& recordName, J ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "PGOProfiler::ProfileBytecode"); ClockScope start; JSFunction *function = JSFunction::Cast(funcValue); - if (function->IsSendableOrConcurrentFunction()) { + JSThread *thread = vm_->GetJSThread(); + if (function->IsSendableOrConcurrentFunction(thread)) { return; } - Method *method = Method::Cast(function->GetMethod()); - JSTaggedValue profileTypeInfoVal = function->GetProfileTypeInfo(); + Method *method = Method::Cast(function->GetMethod(thread)); + JSTaggedValue profileTypeInfoVal = function->GetProfileTypeInfo(thread); ASSERT(!profileTypeInfoVal.IsUndefined()); auto profileTypeInfo = ProfileTypeInfo::Cast(profileTypeInfoVal.GetTaggedObject()); auto methodId = method->GetMethodId(); auto pcStart = method->GetBytecodeArray(); - auto codeSize = method->GetCodeSize(); + auto codeSize = method->GetCodeSize(thread); BytecodeInstruction bcIns(pcStart); auto bcInsLast = bcIns.JumpTo(codeSize); bool isForceDump = vm_->GetJSOptions().IsPgoForceDump(); @@ -853,10 +862,10 @@ void PGOProfiler::ProfileBytecode(ApEntityId abcId, const CString& recordName, J case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM8_ID16: case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM8_ID16: case EcmaOpcode::CREATEEMPTYARRAY_IMM8: { - if (method->GetJSPandaFile() == nullptr) { + if (method->GetJSPandaFile(thread) == nullptr) { break; } - auto header = method->GetJSPandaFile()->GetPandaFile()->GetHeader(); + auto header = method->GetJSPandaFile(thread)->GetPandaFile()->GetHeader(); auto traceId = static_cast(reinterpret_cast(pc) - reinterpret_cast(header)); uint8_t slotId = READ_INST_8_0(); @@ -867,10 +876,10 @@ void PGOProfiler::ProfileBytecode(ApEntityId abcId, const CString& recordName, J case EcmaOpcode::CREATEOBJECTWITHBUFFER_IMM16_ID16: case EcmaOpcode::CREATEARRAYWITHBUFFER_IMM16_ID16: case EcmaOpcode::CREATEEMPTYARRAY_IMM16: { - if (method->GetJSPandaFile() == nullptr) { + if (method->GetJSPandaFile(thread) == nullptr) { break; } - auto header = method->GetJSPandaFile()->GetPandaFile()->GetHeader(); + auto header = method->GetJSPandaFile(thread)->GetPandaFile()->GetHeader(); auto traceId = static_cast(reinterpret_cast(pc) - reinterpret_cast(header)); uint16_t slotId = READ_INST_16_0(); @@ -902,7 +911,7 @@ void PGOProfiler::ProfileBytecode(ApEntityId abcId, const CString& recordName, J bcIns = bcIns.GetNext(); } if (PGOTrace::GetInstance()->IsEnable()) { - auto methodData = PGOTrace::GetInstance()->TryGetMethodData(function->GetMethod()); + auto methodData = PGOTrace::GetInstance()->TryGetMethodData(thread, function->GetMethod(thread)); methodData->SetProfileBytecodeTime(start.TotalSpentTime()); } } @@ -910,7 +919,8 @@ void PGOProfiler::ProfileBytecode(ApEntityId abcId, const CString& recordName, J void PGOProfiler::DumpICByName(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo, BCType type) { - JSTaggedValue firstValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue firstValue = profileTypeInfo->Get(thread, slotId); if (!firstValue.IsHeapObject()) { if (firstValue.IsHole()) { // Mega state @@ -921,7 +931,7 @@ void PGOProfiler::DumpICByName(ApEntityId abcId, const CString &recordName, Enti if (firstValue.IsWeak()) { TaggedObject *object = firstValue.GetWeakReferentUnChecked(); if (object->GetClass()->IsHClass()) { - JSTaggedValue secondValue = profileTypeInfo->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo->Get(thread, slotId + 1); JSHClass *hclass = JSHClass::Cast(object); DumpICByNameWithHandler(abcId, recordName, methodId, bcOffset, hclass, secondValue, type); } @@ -933,7 +943,8 @@ void PGOProfiler::DumpICByName(ApEntityId abcId, const CString &recordName, Enti void PGOProfiler::DumpICByValue(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo, BCType type) { - JSTaggedValue firstValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue firstValue = profileTypeInfo->Get(thread, slotId); if (!firstValue.IsHeapObject()) { if (firstValue.IsHole()) { // Mega state @@ -944,7 +955,7 @@ void PGOProfiler::DumpICByValue(ApEntityId abcId, const CString &recordName, Ent if (firstValue.IsWeak()) { TaggedObject *object = firstValue.GetWeakReferentUnChecked(); if (object->GetClass()->IsHClass()) { - JSTaggedValue secondValue = profileTypeInfo->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo->Get(thread, slotId + 1); JSHClass *hclass = JSHClass::Cast(object); DumpICByValueWithHandler(abcId, recordName, methodId, bcOffset, hclass, secondValue, type); } @@ -952,7 +963,7 @@ void PGOProfiler::DumpICByValue(ApEntityId abcId, const CString &recordName, Ent } // Check key if ((firstValue.IsString() || firstValue.IsSymbol())) { - JSTaggedValue secondValue = profileTypeInfo->Get(slotId + 1); + JSTaggedValue secondValue = profileTypeInfo->Get(thread, slotId + 1); DumpICByValueWithPoly(abcId, recordName, methodId, bcOffset, secondValue, type); return; } @@ -967,11 +978,12 @@ void PGOProfiler::DumpICByNameWithPoly(ApEntityId abcId, return; } ASSERT(cacheValue.IsTaggedArray()); + const JSThread *thread = vm_->GetJSThread(); auto array = TaggedArray::Cast(cacheValue); 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); - auto handler = array->Get(i + 1); + auto result = array->Get(thread, i); + auto handler = array->Get(thread, i + 1); if (!result.IsHeapObject() || !result.IsWeak()) { continue; } @@ -998,10 +1010,11 @@ void PGOProfiler::DumpICByValueWithPoly(ApEntityId abcId, return; } auto array = TaggedArray::Cast(cacheValue); + const JSThread *thread = vm_->GetJSThread(); 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); - auto handler = array->Get(i + 1); + auto result = array->Get(thread, i); + auto handler = array->Get(thread, i + 1); if (!result.IsHeapObject() || !result.IsWeak()) { continue; } @@ -1026,40 +1039,40 @@ bool PGOProfiler::DumpICByNameWithHandler(ApEntityId abcId, const CString &recor return AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, hclass, hclass); } else if (secondValue.IsTransitionHandler()) { auto transitionHandler = TransitionHandler::Cast(secondValue.GetTaggedObject()); - auto transitionHClassVal = transitionHandler->GetTransitionHClass(); + auto transitionHClassVal = transitionHandler->GetTransitionHClass(vm_->GetJSThread()); if (transitionHClassVal.IsJSHClass()) { auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); return AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, hclass, transitionHClass); } } else if (secondValue.IsTransWithProtoHandler()) { auto transWithProtoHandler = TransWithProtoHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = transWithProtoHandler->GetProtoCell(); + auto cellValue = transWithProtoHandler->GetProtoCell(vm_->GetJSThread()); if (CheckProtoChangeMarker(cellValue)) { return false; } - auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(); + auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(vm_->GetJSThread()); if (transitionHClassVal.IsJSHClass()) { auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); return AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, hclass, transitionHClass); } } else if (secondValue.IsPrototypeHandler()) { auto prototypeHandler = PrototypeHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(vm_->GetJSThread()); if (CheckProtoChangeMarker(cellValue)) { return false; } - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(vm_->GetJSThread()); auto holderHClass = holder.GetTaggedObject()->GetClass(); auto accessorMethodId = prototypeHandler->GetAccessorMethodId(); return AddObjectInfo( abcId, recordName, methodId, bcOffset, hclass, holderHClass, holderHClass, accessorMethodId); } else if (secondValue.IsStoreAOTHandler()) { StoreAOTHandler *storeAOTHandler = StoreAOTHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = storeAOTHandler->GetProtoCell(); + auto cellValue = storeAOTHandler->GetProtoCell(vm_->GetJSThread()); if (CheckProtoChangeMarker(cellValue)) { return false; } - auto holder = storeAOTHandler->GetHolder(); + auto holder = storeAOTHandler->GetHolder(vm_->GetJSThread()); auto holderHClass = holder.GetTaggedObject()->GetClass(); return AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, holderHClass, holderHClass); } @@ -1084,11 +1097,11 @@ bool PGOProfiler::DumpICLoadByNameWithHandler(ApEntityId abcId, const CString &r return AddBuiltinsInfoByNameInInstance(abcId, recordName, methodId, bcOffset, hclass); } else if (secondValue.IsPrototypeHandler()) { auto prototypeHandler = PrototypeHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(vm_->GetJSThread()); if (CheckProtoChangeMarker(cellValue)) { return ret; } - JSTaggedValue handlerInfoVal = prototypeHandler->GetHandlerInfo(); + JSTaggedValue handlerInfoVal = prototypeHandler->GetHandlerInfo(vm_->GetJSThread()); if (!handlerInfoVal.IsInt()) { return ret; } @@ -1096,7 +1109,7 @@ bool PGOProfiler::DumpICLoadByNameWithHandler(ApEntityId abcId, const CString &r if (HandlerBase::IsNonExist(handlerInfo)) { return ret; } - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(vm_->GetJSThread()); auto holderHClass = holder.GetTaggedObject()->GetClass(); auto accessorMethodId = prototypeHandler->GetAccessorMethodId(); if (!AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, holderHClass, @@ -1152,11 +1165,11 @@ void PGOProfiler::DumpICByValueWithHandler(ApEntityId abcId, const CString &reco AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, hclass, hclass); } else if (secondValue.IsTransitionHandler()) { auto transitionHandler = TransitionHandler::Cast(secondValue.GetTaggedObject()); - auto transitionHClassVal = transitionHandler->GetTransitionHClass(); + auto transitionHClassVal = transitionHandler->GetTransitionHClass(vm_->GetJSThread()); if (!transitionHClassVal.IsJSHClass()) { return ; } - auto handlerInfoValue = transitionHandler->GetHandlerInfo(); + auto handlerInfoValue = transitionHandler->GetHandlerInfo(vm_->GetJSThread()); auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); if (handlerInfoValue.IsInt()) { auto handlerInfo = static_cast(handlerInfoValue.GetInt()); @@ -1169,11 +1182,11 @@ void PGOProfiler::DumpICByValueWithHandler(ApEntityId abcId, const CString &reco AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, hclass, transitionHClass); } else if (secondValue.IsTransWithProtoHandler()) { auto transWithProtoHandler = TransWithProtoHandler::Cast(secondValue.GetTaggedObject()); - auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(); + auto transitionHClassVal = transWithProtoHandler->GetTransitionHClass(vm_->GetJSThread()); if (!transitionHClassVal.IsJSHClass()) { return ; } - auto handlerInfoValue = transWithProtoHandler->GetHandlerInfo(); + auto handlerInfoValue = transWithProtoHandler->GetHandlerInfo(vm_->GetJSThread()); auto transitionHClass = JSHClass::Cast(transitionHClassVal.GetTaggedObject()); if (handlerInfoValue.IsInt()) { auto handlerInfo = static_cast(handlerInfoValue.GetInt()); @@ -1186,7 +1199,7 @@ void PGOProfiler::DumpICByValueWithHandler(ApEntityId abcId, const CString &reco AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, hclass, transitionHClass); } else if (secondValue.IsPrototypeHandler()) { PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(secondValue.GetTaggedObject()); - auto cellValue = prototypeHandler->GetProtoCell(); + auto cellValue = prototypeHandler->GetProtoCell(vm_->GetJSThread()); if (!cellValue.IsProtoChangeMarker()) { return; } @@ -1195,7 +1208,7 @@ void PGOProfiler::DumpICByValueWithHandler(ApEntityId abcId, const CString &reco if (cell->GetHasChanged()) { return; } - JSTaggedValue handlerInfoValue = prototypeHandler->GetHandlerInfo(); + JSTaggedValue handlerInfoValue = prototypeHandler->GetHandlerInfo(vm_->GetJSThread()); if (handlerInfoValue.IsInt()) { auto handlerInfo = static_cast(handlerInfoValue.GetInt()); if (HandlerBase::IsElement(handlerInfo)) { @@ -1204,7 +1217,7 @@ void PGOProfiler::DumpICByValueWithHandler(ApEntityId abcId, const CString &reco return; } } - auto holder = prototypeHandler->GetHolder(); + auto holder = prototypeHandler->GetHolder(vm_->GetJSThread()); auto holderHClass = holder.GetTaggedObject()->GetClass(); AddObjectInfo(abcId, recordName, methodId, bcOffset, hclass, holderHClass, holderHClass); } @@ -1212,12 +1225,13 @@ void PGOProfiler::DumpICByValueWithHandler(ApEntityId abcId, const CString &reco void PGOProfiler::TryDumpProtoTransitionType(JSHClass *hclass) { - JSHClass *ihc1 = JSHClass::FindRootHClass(hclass); + auto thread = vm_->GetJSThread(); + JSHClass *ihc1 = JSHClass::FindRootHClass(thread, hclass); auto transitionType = GetProfileType(ihc1, true); if (!transitionType.IsRootType() || !transitionType.IsTransitionClassType()) { return; } - JSTaggedValue phc1Root = JSHClass::FindProtoRootHClass(ihc1); + JSTaggedValue phc1Root = JSHClass::FindProtoRootHClass(thread, ihc1); if (!phc1Root.IsJSHClass()) { LOG_PGO(DEBUG) << "Phc1Root is not a JSHclass!"; return; @@ -1244,7 +1258,7 @@ void PGOProfiler::TryDumpProtoTransitionType(JSHClass *hclass) auto ihc0RootType = GetProfileType(ihc0Obj); ASSERT(ihc0RootType.IsRootType()); - auto baseRootHClass = JSHClass::FindRootHClass(baseIhcObj); + auto baseRootHClass = JSHClass::FindRootHClass(thread, baseIhcObj); auto baseRootType = GetProfileType(baseRootHClass, true); if (!baseRootType.IsRootType()) { LOG_PGO(DEBUG) << "Unsupported prototypes which cannot be recorded!"; @@ -1263,7 +1277,7 @@ void PGOProfiler::TryDumpProtoTransitionType(JSHClass *hclass) void PGOProfiler::DumpOpType(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo) { - JSTaggedValue slotValue = profileTypeInfo->Get(slotId); + JSTaggedValue slotValue = profileTypeInfo->Get(vm_->GetJSThread(), slotId); if (slotValue.IsInt()) { auto type = slotValue.GetInt(); ProfileType recordType = GetRecordProfileType(abcId, recordName); @@ -1273,7 +1287,7 @@ void PGOProfiler::DumpOpType(ApEntityId abcId, const CString &recordName, Entity bool PGOProfiler::FunctionKindVerify(const JSFunction *ctorFunction) { - FunctionKind kind = Method::Cast(ctorFunction->GetMethod())->GetFunctionKind(); + FunctionKind kind = Method::Cast(ctorFunction->GetMethod(vm_->GetJSThread()))->GetFunctionKind(); return kind == FunctionKind::BASE_CONSTRUCTOR || kind == FunctionKind::CLASS_CONSTRUCTOR || kind == FunctionKind::DERIVED_CONSTRUCTOR; @@ -1282,22 +1296,23 @@ bool PGOProfiler::FunctionKindVerify(const JSFunction *ctorFunction) void PGOProfiler::DumpDefineClass(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo) { - JSTaggedValue slotValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue slotValue = profileTypeInfo->Get(thread, slotId); if (!slotValue.IsProfileTypeInfoCell0()) { return; } - JSTaggedValue handle = ProfileTypeInfoCell::Cast(slotValue)->GetHandle(); + JSTaggedValue handle = ProfileTypeInfoCell::Cast(slotValue)->GetHandle(thread); if (!handle.IsHeapObject() || !handle.IsWeak()) { return; } auto object = handle.GetWeakReferentUnChecked(); if (object->GetClass()->IsJSFunction()) { JSFunction *ctorFunction = JSFunction::Cast(object); - auto ctorMethod = ctorFunction->GetMethod(); + auto ctorMethod = ctorFunction->GetMethod(thread); if (!ctorMethod.IsMethod() || !FunctionKindVerify(ctorFunction)) { return; } - ApEntityId ctorAbcId = GetMethodAbcId(ctorFunction); + ApEntityId ctorAbcId = GetMethodAbcId(thread, ctorFunction); auto ctorJSMethod = Method::Cast(ctorMethod); auto ctorMethodId = ctorJSMethod->GetMethodId().GetOffset(); @@ -1306,32 +1321,32 @@ void PGOProfiler::DumpDefineClass(ApEntityId abcId, const CString &recordName, E return; } PGODefineOpType objDefType(localType); - auto protoOrHClass = ctorFunction->GetProtoOrHClass(); + auto protoOrHClass = ctorFunction->GetProtoOrHClass(thread); if (protoOrHClass.IsJSHClass()) { auto ihc = JSHClass::Cast(protoOrHClass.GetTaggedObject()); SetRootProfileType(ihc, ctorAbcId, ctorMethodId, ProfileType::Kind::ClassId); - recordInfos_->AddRootLayout(JSTaggedType(ihc), localType); - protoOrHClass = ihc->GetProto(); + recordInfos_->AddRootLayout(thread, JSTaggedType(ihc), localType); + protoOrHClass = ihc->GetProto(thread); } - auto ctorRootHClass = JSHClass::FindRootHClass(ctorFunction->GetJSHClass()); + auto ctorRootHClass = JSHClass::FindRootHClass(thread, ctorFunction->GetJSHClass()); auto ctorType = GetProfileType(ctorRootHClass); if (!ctorType.IsRootType()) { LOG_PGO(DEBUG) << "The profileType of constructor root hclass was not found."; } else { objDefType.SetCtorPt(ctorType); - recordInfos_->AddRootLayout(JSTaggedType(ctorRootHClass), ctorType); + recordInfos_->AddRootLayout(thread, JSTaggedType(ctorRootHClass), ctorType); } if (protoOrHClass.IsJSObject()) { auto prototypeHClass = JSObject::Cast(protoOrHClass)->GetClass(); - auto prototypeRootHClass = JSHClass::FindRootHClass(prototypeHClass); + auto prototypeRootHClass = JSHClass::FindRootHClass(thread, prototypeHClass); ProfileType prototypeType = GetProfileType(prototypeRootHClass); if (!prototypeType.IsRootType()) { LOG_PGO(DEBUG) << "The profileType of prototype root hclass was not found."; } else { objDefType.SetPrototypePt(prototypeType); - recordInfos_->AddRootLayout(JSTaggedType(prototypeRootHClass), prototypeType); + recordInfos_->AddRootLayout(thread, JSTaggedType(prototypeRootHClass), prototypeType); } } @@ -1343,7 +1358,8 @@ void PGOProfiler::DumpDefineClass(ApEntityId abcId, const CString &recordName, E void PGOProfiler::DumpCreateObject(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo, int32_t traceId) { - JSTaggedValue slotValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue slotValue = profileTypeInfo->Get(thread, slotId); if (!slotValue.IsHeapObject()) { return; } @@ -1352,7 +1368,7 @@ void PGOProfiler::DumpCreateObject(ApEntityId abcId, const CString &recordName, auto object = slotValue.GetWeakReferentUnChecked(); if (object->GetClass()->IsHClass()) { auto newHClass = JSHClass::Cast(object); - auto rootHClass = JSHClass::FindRootHClass(newHClass); + auto rootHClass = JSHClass::FindRootHClass(thread, newHClass); ProfileType profileType = GetProfileType(rootHClass); if (!profileType.IsRootType()) { return; @@ -1361,7 +1377,7 @@ void PGOProfiler::DumpCreateObject(ApEntityId abcId, const CString &recordName, PGOSampleType currentType(profileType); PGODefineOpType objDefType(profileType); recordInfos_->AddDefine(recordType, methodId, bcOffset, objDefType); - recordInfos_->AddRootLayout(JSTaggedType(rootHClass), profileType); + recordInfos_->AddRootLayout(thread, JSTaggedType(rootHClass), profileType); } } else if (slotValue.IsTrackInfoObject()) { auto currentType = PGOSampleType::CreateProfileType(abcId, traceId, ProfileType::Kind::ArrayLiteralId, true); @@ -1373,10 +1389,10 @@ void PGOProfiler::DumpCreateObject(ApEntityId abcId, const CString &recordName, objDefType.SetElementsLength(trackInfo->GetArrayLength()); objDefType.SetSpaceFlag(trackInfo->GetSpaceFlag()); recordInfos_->AddDefine(recordType, methodId, bcOffset, objDefType); - auto cachedHClass = trackInfo->GetCachedHClass(); + auto cachedHClass = trackInfo->GetCachedHClass(thread); if (cachedHClass.IsJSHClass()) { auto hclass = JSHClass::Cast(cachedHClass.GetTaggedObject()); - recordInfos_->AddRootLayout(JSTaggedType(hclass), profileType); + recordInfos_->AddRootLayout(thread, JSTaggedType(hclass), profileType); } } } @@ -1384,7 +1400,8 @@ void PGOProfiler::DumpCreateObject(ApEntityId abcId, const CString &recordName, void PGOProfiler::DumpCall(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo) { - JSTaggedValue slotValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue slotValue = profileTypeInfo->Get(thread, slotId); ProfileType::Kind kind; int calleeMethodId = 0; ApEntityId calleeAbcId = 0; @@ -1399,9 +1416,9 @@ void PGOProfiler::DumpCall(ApEntityId abcId, const CString &recordName, EntityId } } else if (slotValue.IsJSFunction()) { JSFunction *callee = JSFunction::Cast(slotValue); - Method *calleeMethod = Method::Cast(callee->GetMethod()); + Method *calleeMethod = Method::Cast(callee->GetMethod(thread)); calleeMethodId = static_cast(calleeMethod->GetMethodId().GetOffset()); - calleeAbcId = GetMethodAbcId(callee->GetMethod()); + calleeAbcId = GetMethodAbcId(thread, callee->GetMethod(thread)); kind = ProfileType::Kind::MethodId; } else { return; @@ -1414,10 +1431,11 @@ void PGOProfiler::DumpCall(ApEntityId abcId, const CString &recordName, EntityId void PGOProfiler::DumpGetIterator(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo) { - if (vm_->GetJSThread()->GetEnableLazyBuiltins()) { + const JSThread *thread = vm_->GetJSThread(); + if (thread->GetEnableLazyBuiltins()) { return; } - JSTaggedValue value = profileTypeInfo->Get(slotId); + JSTaggedValue value = profileTypeInfo->Get(thread, slotId); if (!value.IsInt()) { return; } @@ -1432,13 +1450,14 @@ void PGOProfiler::DumpGetIterator(ApEntityId abcId, const CString &recordName, E void PGOProfiler::DumpNewObjRange(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo) { - JSTaggedValue slotValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue slotValue = profileTypeInfo->Get(thread, slotId); int ctorMethodId = 0; if (slotValue.IsInt()) { ctorMethodId = slotValue.GetInt(); } else if (slotValue.IsJSFunction()) { JSFunction *callee = JSFunction::Cast(slotValue); - Method *calleeMethod = Method::Cast(callee->GetMethod()); + Method *calleeMethod = Method::Cast(callee->GetMethod(thread)); ctorMethodId = static_cast(calleeMethod->GetMethodId().GetOffset()); } else { return; @@ -1457,7 +1476,8 @@ void PGOProfiler::DumpNewObjRange(ApEntityId abcId, const CString &recordName, E void PGOProfiler::DumpInstanceof(ApEntityId abcId, const CString &recordName, EntityId methodId, int32_t bcOffset, uint32_t slotId, ProfileTypeInfo *profileTypeInfo) { - JSTaggedValue firstValue = profileTypeInfo->Get(slotId); + const JSThread *thread = vm_->GetJSThread(); + JSTaggedValue firstValue = profileTypeInfo->Get(thread, slotId); if (!firstValue.IsHeapObject()) { if (firstValue.IsHole()) { // Mega state @@ -1487,17 +1507,18 @@ void PGOProfiler::DumpInstanceof(ApEntityId abcId, const CString &recordName, En void PGOProfiler::UpdateLayout(JSHClass *hclass) { - auto parentHClass = hclass->GetParent(); + JSThread *thread = vm_->GetJSThread(); + auto parentHClass = hclass->GetParent(thread); if (!GetProfileType(hclass).IsRootType() && parentHClass.IsJSHClass()) { UpdateTransitionLayout(JSHClass::Cast(parentHClass.GetTaggedObject()), hclass); } else { - auto rootHClass = JSHClass::FindRootHClass(hclass); + auto rootHClass = JSHClass::FindRootHClass(thread, hclass); ProfileType rootType = GetProfileType(rootHClass, true); if (!rootType.IsRootType()) { return; } - auto prototypeHClass = JSHClass::FindProtoRootHClass(rootHClass); + auto prototypeHClass = JSHClass::FindProtoRootHClass(thread, rootHClass); if (prototypeHClass.IsJSHClass()) { auto prototypeObject = JSHClass::Cast(prototypeHClass.GetTaggedObject()); ProfileType prototypeType = GetProfileType(prototypeObject, true); @@ -1508,13 +1529,14 @@ void PGOProfiler::UpdateLayout(JSHClass *hclass) } auto curType = GetOrInsertProfileType(hclass, rootType); - recordInfos_->UpdateLayout(rootType, JSTaggedType(hclass), curType); + recordInfos_->UpdateLayout(thread, rootType, JSTaggedType(hclass), curType); } } void PGOProfiler::UpdateTransitionLayout(JSHClass* parent, JSHClass* child) { - auto rootHClass = JSHClass::FindRootHClass(parent); + JSThread *thread = vm_->GetJSThread(); + auto rootHClass = JSHClass::FindRootHClass(thread, parent); auto rootType = GetProfileType(rootHClass, true); if (!rootType.IsRootType()) { return; @@ -1528,7 +1550,7 @@ void PGOProfiler::UpdateTransitionLayout(JSHClass* parent, JSHClass* child) hclassVec.emplace(parent); while (!GetProfileType(parent).IsRootType()) { - auto parentHCValue = parent->GetParent(); + auto parentHCValue = parent->GetParent(thread); if (!parentHCValue.IsJSHClass()) { break; } @@ -1536,7 +1558,7 @@ void PGOProfiler::UpdateTransitionLayout(JSHClass* parent, JSHClass* child) hclassVec.emplace(parent); } - auto prototypeRootHClassVal = JSHClass::FindProtoRootHClass(rootHClass); + auto prototypeRootHClassVal = JSHClass::FindProtoRootHClass(thread, rootHClass); if (prototypeRootHClassVal.IsJSHClass()) { auto prototypeRootHClass = JSHClass::Cast(prototypeRootHClassVal.GetTaggedObject()); auto prototypeType = GetProfileType(prototypeRootHClass); @@ -1553,7 +1575,7 @@ void PGOProfiler::UpdateTransitionLayout(JSHClass* parent, JSHClass* child) child = hclassVec.top(); hclassVec.pop(); auto childType = GetOrInsertProfileType(child, rootType); - recordInfos_->UpdateTransitionLayout( + recordInfos_->UpdateTransitionLayout(thread, rootType, JSTaggedType(parent), parentType, JSTaggedType(child), childType); parentType = childType; parent = child; @@ -1615,7 +1637,7 @@ void PGOProfiler::UpdatePrototypeChainInfo(JSHClass *receiver, JSHClass *holder, } std::vector> protoChain; - JSTaggedValue proto = JSHClass::FindProtoHClass(receiver); + JSTaggedValue proto = JSHClass::FindProtoHClass(vm_->GetJSThread(), receiver); while (proto.IsJSHClass()) { auto protoHClass = JSHClass::Cast(proto.GetTaggedObject()); if (protoHClass == holder) { @@ -1627,7 +1649,7 @@ void PGOProfiler::UpdatePrototypeChainInfo(JSHClass *receiver, JSHClass *holder, } auto protoType = GetOrInsertProfileType(protoHClass, protoRootType); protoChain.emplace_back(protoRootType, protoType); - proto = JSHClass::FindProtoHClass(protoHClass); + proto = JSHClass::FindProtoHClass(vm_->GetJSThread(), protoHClass); } if (!protoChain.empty()) { info.AddPrototypePt(protoChain); @@ -1811,7 +1833,7 @@ void PGOProfiler::SetRootProfileType(JSHClass *root, ApEntityId abcId, uint32_t ProfileType PGOProfiler::FindRootProfileType(JSHClass *hclass) { - auto rootHClass = JSHClass::FindRootHClass(hclass); + auto rootHClass = JSHClass::FindRootHClass(vm_->GetJSThread(), hclass); return GetProfileType(rootHClass, true); } @@ -1820,7 +1842,7 @@ ProfileType PGOProfiler::GetOrInsertProfileType(JSHClass *child, ProfileType roo ProfileType childType = GetProfileType(child); if (childType.IsNone()) { ASSERT(rootType.IsRootType()); - childType = PGOTypeGenerator::GenerateProfileType(JSTaggedType(child), rootType); + childType = PGOTypeGenerator::GenerateProfileType(vm_->GetJSThread(), JSTaggedType(child), rootType); child->SetProfileType(childType.GetRaw()); } return childType; @@ -1929,12 +1951,12 @@ void PGOProfiler::Reset(bool isEnable) LOG_PGO(INFO) << "reset pgo profiler, pgo profiler is " << (isEnable_ ? "enabled" : "disabled"); } -ApEntityId PGOProfiler::GetMethodAbcId(JSTaggedValue jsMethod) +ApEntityId PGOProfiler::GetMethodAbcId(const JSThread *thread, JSTaggedValue jsMethod) { ASSERT(jsMethod.IsMethod()); CString pfName; - const auto *pf = Method::Cast(jsMethod)->GetJSPandaFile(); + const auto *pf = Method::Cast(jsMethod)->GetJSPandaFile(thread); if (pf != nullptr) { pfName = pf->GetJSPandaFileDesc(); } @@ -1944,12 +1966,12 @@ ApEntityId PGOProfiler::GetMethodAbcId(JSTaggedValue jsMethod) } return abcId; } -ApEntityId PGOProfiler::GetMethodAbcId(JSFunction *jsFunction) +ApEntityId PGOProfiler::GetMethodAbcId(const JSThread *thread, JSFunction *jsFunction) { CString pfName; - auto jsMethod = jsFunction->GetMethod(); + auto jsMethod = jsFunction->GetMethod(thread); if (jsMethod.IsMethod()) { - return GetMethodAbcId(jsMethod); + return GetMethodAbcId(thread, jsMethod); } LOG_PGO(ERROR) << "Get method abc id failed. Not a method."; UNREACHABLE(); @@ -1958,9 +1980,10 @@ ApEntityId PGOProfiler::GetMethodAbcId(JSFunction *jsFunction) ProfileType PGOProfiler::GetRecordProfileType(JSFunction *jsFunction, const CString &recordName) { CString pfName; - auto jsMethod = jsFunction->GetMethod(); + JSThread *thread = vm_->GetJSThread(); + auto jsMethod = jsFunction->GetMethod(thread); if (jsMethod.IsMethod()) { - const auto *pf = Method::Cast(jsMethod)->GetJSPandaFile(); + const auto *pf = Method::Cast(jsMethod)->GetJSPandaFile(thread); if (pf != nullptr) { pfName = pf->GetJSPandaFileDesc(); } @@ -1971,7 +1994,7 @@ ProfileType PGOProfiler::GetRecordProfileType(JSFunction *jsFunction, const CStr << ", recordName: " << recordName; return ProfileType::PROFILE_TYPE_NONE; } - return GetRecordProfileType(pf, GetMethodAbcId(jsFunction), recordName); + return GetRecordProfileType(pf, GetMethodAbcId(thread, jsFunction), recordName); } ProfileType PGOProfiler::GetRecordProfileType(ApEntityId abcId, const CString &recordName) @@ -2104,22 +2127,23 @@ JSTaggedValue PGOProfiler::TryFindKeyInPrototypeChain(TaggedObject *currObj, JSH if (currHC->IsDictionaryMode()) { return JSTaggedValue(currHC); } + JSThread *thread = vm_->GetJSThread(); while (!JSTaggedValue(currHC).IsUndefinedOrNull()) { if (LIKELY(!currHC->IsDictionaryMode())) { - int entry = JSHClass::FindPropertyEntry(vm_->GetJSThread(), currHC, key); + int entry = JSHClass::FindPropertyEntry(thread, currHC, key); if (entry != -1) { return JSTaggedValue(currHC); } } else { - TaggedArray *array = TaggedArray::Cast(JSObject::Cast(currObj)->GetProperties().GetTaggedObject()); + TaggedArray *array = TaggedArray::Cast(JSObject::Cast(currObj)->GetProperties(thread).GetTaggedObject()); ASSERT(array->IsDictionaryMode()); NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { return JSTaggedValue(currHC); } } - auto proto = currHC->GetProto(); + auto proto = currHC->GetProto(thread); if (!proto.IsHeapObject()) { return JSTaggedValue::Undefined(); } diff --git a/ecmascript/pgo_profiler/pgo_profiler.h b/ecmascript/pgo_profiler/pgo_profiler.h index 7dd8a70557..212a0b5d7e 100644 --- a/ecmascript/pgo_profiler/pgo_profiler.h +++ b/ecmascript/pgo_profiler/pgo_profiler.h @@ -95,8 +95,8 @@ public: void UpdateTrackSpaceFlag(TaggedObject* object, RegionSpaceFlag spaceFlag); void UpdateTrackInfo(JSTaggedValue trackInfoVal); JSTaggedValue TryFindKeyInPrototypeChain(TaggedObject* currObj, JSHClass* currHC, JSTaggedValue key); - static ApEntityId PUBLIC_API GetMethodAbcId(JSFunction* jsFunction); - static ApEntityId PUBLIC_API GetMethodAbcId(JSTaggedValue jsMethod); + static ApEntityId PUBLIC_API GetMethodAbcId(const JSThread *thread, JSFunction* jsFunction); + static ApEntityId PUBLIC_API GetMethodAbcId(const JSThread *thread, JSTaggedValue jsMethod); void Reset(bool isEnable); void InsertSkipCtorMethodIdSafe(EntityId ctorMethodId); void SetSaveTimestamp(std::chrono::system_clock::time_point timestamp); diff --git a/ecmascript/pgo_profiler/pgo_profiler_info.cpp b/ecmascript/pgo_profiler/pgo_profiler_info.cpp index b36c12a147..63a74f8273 100644 --- a/ecmascript/pgo_profiler/pgo_profiler_info.cpp +++ b/ecmascript/pgo_profiler/pgo_profiler_info.cpp @@ -189,7 +189,7 @@ uint32_t PGOMethodInfo::CalcOpCodeChecksum(const uint8_t *byteCodeArray, uint32_ return checksum; } -bool PGOMethodInfoMap::AddMethod(Chunk *chunk, Method *jsMethod, SampleMode mode) +bool PGOMethodInfoMap::AddMethod(const JSThread *thread, Chunk *chunk, Method *jsMethod, SampleMode mode) { PGOMethodId methodId(jsMethod->GetMethodId()); auto result = methodInfos_.find(methodId); @@ -199,7 +199,7 @@ bool PGOMethodInfoMap::AddMethod(Chunk *chunk, Method *jsMethod, SampleMode mode info->SetSampleMode(mode); return false; } else { - CString methodName = jsMethod->GetMethodName(); + CString methodName = jsMethod->GetMethodName(thread); size_t strlen = methodName.size(); size_t size = static_cast(PGOMethodInfo::Size(strlen)); void *infoAddr = chunk->Allocate(size); @@ -210,8 +210,8 @@ bool PGOMethodInfoMap::AddMethod(Chunk *chunk, Method *jsMethod, SampleMode mode auto info = new (infoAddr) PGOMethodInfo(methodId, 0, mode, methodName.c_str()); info->IncreaseCount(); methodInfos_.emplace(methodId, info); - auto checksum = PGOMethodInfo::CalcChecksum(jsMethod->GetMethodName(), jsMethod->GetBytecodeArray(), - jsMethod->GetCodeSize()); + auto checksum = PGOMethodInfo::CalcChecksum(jsMethod->GetMethodName(thread), jsMethod->GetBytecodeArray(), + jsMethod->GetCodeSize(thread)); methodsChecksum_.emplace(methodId, checksum); return true; } @@ -646,12 +646,13 @@ PGOMethodInfoMap *PGORecordDetailInfos::GetMethodInfoMap(ProfileType recordProfi } } -bool PGORecordDetailInfos::AddMethod(ProfileType recordProfileType, Method *jsMethod, SampleMode mode) +bool PGORecordDetailInfos::AddMethod(const JSThread *thread, ProfileType recordProfileType, Method *jsMethod, + SampleMode mode) { auto curMethodInfos = GetMethodInfoMap(recordProfileType); ASSERT(curMethodInfos != nullptr); ASSERT(jsMethod != nullptr); - return curMethodInfos->AddMethod(chunk_.get(), jsMethod, mode); + return curMethodInfos->AddMethod(thread, chunk_.get(), jsMethod, mode); } bool PGORecordDetailInfos::AddType(ProfileType recordProfileType, PGOMethodId methodId, int32_t offset, @@ -696,14 +697,14 @@ bool PGORecordDetailInfos::AddDefine( return true; } -bool PGORecordDetailInfos::AddRootLayout(JSTaggedType hclass, ProfileType rootType) +bool PGORecordDetailInfos::AddRootLayout(const JSThread *thread, JSTaggedType hclass, ProfileType rootType) { PGOHClassTreeDesc descInfo(rootType); auto iter = hclassTreeDescInfos_.find(descInfo); if (iter != hclassTreeDescInfos_.end()) { - return const_cast(*iter).DumpForRoot(hclass, rootType); + return const_cast(*iter).DumpForRoot(thread, hclass, rootType); } else { - if (!descInfo.DumpForRoot(hclass, rootType)) { + if (!descInfo.DumpForRoot(thread, hclass, rootType)) { return false; } hclassTreeDescInfos_.emplace(descInfo); @@ -711,14 +712,15 @@ bool PGORecordDetailInfos::AddRootLayout(JSTaggedType hclass, ProfileType rootTy return true; } -bool PGORecordDetailInfos::UpdateLayout(ProfileType rootType, JSTaggedType hclass, ProfileType curType) +bool PGORecordDetailInfos::UpdateLayout(const JSThread *thread, + ProfileType rootType, JSTaggedType hclass, ProfileType curType) { PGOHClassTreeDesc descInfo(rootType); auto iter = hclassTreeDescInfos_.find(descInfo); if (iter != hclassTreeDescInfos_.end()) { - return const_cast(*iter).UpdateLayout(hclass, curType); + return const_cast(*iter).UpdateLayout(thread, hclass, curType); } else { - if (!descInfo.UpdateLayout(hclass, curType)) { + if (!descInfo.UpdateLayout(thread, hclass, curType)) { return false; } hclassTreeDescInfos_.emplace(descInfo); @@ -727,15 +729,16 @@ bool PGORecordDetailInfos::UpdateLayout(ProfileType rootType, JSTaggedType hclas return true; } -bool PGORecordDetailInfos::UpdateTransitionLayout( +bool PGORecordDetailInfos::UpdateTransitionLayout(const JSThread *thread, ProfileType rootType, JSTaggedType parent, ProfileType parentType, JSTaggedType child, ProfileType childType) { PGOHClassTreeDesc descInfo(rootType); auto iter = hclassTreeDescInfos_.find(descInfo); if (iter != hclassTreeDescInfos_.end()) { - return const_cast(*iter).UpdateForTransition(parent, parentType, child, childType); + return const_cast(*iter).UpdateForTransition(thread, parent, parentType, + child, childType); } else { - if (!descInfo.UpdateForTransition(parent, parentType, child, childType)) { + if (!descInfo.UpdateForTransition(thread, parent, parentType, child, childType)) { return false; } hclassTreeDescInfos_.emplace(descInfo); diff --git a/ecmascript/pgo_profiler/pgo_profiler_info.h b/ecmascript/pgo_profiler/pgo_profiler_info.h index 0c0ebfc965..04902d3aa1 100644 --- a/ecmascript/pgo_profiler/pgo_profiler_info.h +++ b/ecmascript/pgo_profiler/pgo_profiler_info.h @@ -311,7 +311,7 @@ public: methodTypeInfos_.clear(); } - bool AddMethod(Chunk *chunk, Method *jsMethod, SampleMode mode); + bool AddMethod(const JSThread *thread, Chunk *chunk, Method *jsMethod, SampleMode mode); bool AddType(Chunk *chunk, PGOMethodId methodId, int32_t offset, PGOSampleType type); bool AddCallTargetType(Chunk *chunk, PGOMethodId methodId, int32_t offset, PGOSampleType type); bool AddObjectInfo(Chunk *chunk, PGOMethodId methodId, int32_t offset, const PGOObjectInfo &info); @@ -500,17 +500,17 @@ public: void InitSections(); // If it is a new method, return true. - bool AddMethod(ProfileType recordProfileType, Method *jsMethod, SampleMode mode); + bool AddMethod(const JSThread *thread, ProfileType recordProfileType, Method *jsMethod, SampleMode mode); bool AddType(ProfileType recordProfileType, PGOMethodId methodId, int32_t offset, PGOSampleType type); bool AddCallTargetType(ProfileType recordProfileType, PGOMethodId methodId, int32_t offset, PGOSampleType type); bool AddObjectInfo(ProfileType recordProfileType, PGOMethodId methodId, int32_t offset, const PGOObjectInfo &info); bool AddDefine(ProfileType recordProfileType, PGOMethodId methodId, int32_t offset, PGODefineOpType type); bool AddRwUseInfo(ProfileType rootType); - bool AddRootLayout(JSTaggedType hclass, ProfileType rootType); - bool UpdateTransitionLayout( + bool AddRootLayout(const JSThread *thread, JSTaggedType hclass, ProfileType rootType); + bool UpdateTransitionLayout(const JSThread *thread, ProfileType rootType, JSTaggedType parent, ProfileType parentType, JSTaggedType child, ProfileType childType); - bool UpdateLayout(ProfileType rootType, JSTaggedType hclass, ProfileType curType); + bool UpdateLayout(const JSThread *thread, ProfileType rootType, JSTaggedType hclass, ProfileType curType); void AddRootPtType(ProfileType rootType, ProfileType ptType); bool IsDumped(ProfileType rootType, ProfileType curType) const; diff --git a/ecmascript/pgo_profiler/pgo_profiler_layout.cpp b/ecmascript/pgo_profiler/pgo_profiler_layout.cpp index 2af1c9f778..b645375774 100644 --- a/ecmascript/pgo_profiler/pgo_profiler_layout.cpp +++ b/ecmascript/pgo_profiler/pgo_profiler_layout.cpp @@ -104,7 +104,7 @@ HClassLayoutDesc *PGOHClassTreeDesc::GetOrInsertHClassLayoutDesc(ProfileType typ } } -bool PGOHClassTreeDesc::DumpForRoot(JSTaggedType root, ProfileType rootType) +bool PGOHClassTreeDesc::DumpForRoot(const JSThread *thread, JSTaggedType root, ProfileType rootType) { ASSERT(rootType.IsRootType()); HClassLayoutDesc *rootLayout; @@ -112,17 +112,17 @@ bool PGOHClassTreeDesc::DumpForRoot(JSTaggedType root, ProfileType rootType) auto rootHClass = JSHClass::Cast(JSTaggedValue(root).GetTaggedObject()); if (iter != transitionLayout_.end()) { rootLayout = iter->second; - return JSHClass::UpdateRootLayoutDescByPGO(rootHClass, rootLayout); + return JSHClass::UpdateRootLayoutDescByPGO(thread, rootHClass, rootLayout); } else { rootLayout = new RootHClassLayoutDesc(rootType, rootHClass->GetObjectType(), rootHClass->GetObjectSizeExcludeInlinedProps()); transitionLayout_.emplace(rootType, rootLayout); } - return JSHClass::DumpRootHClassByPGO(rootHClass, rootLayout); + return JSHClass::DumpRootHClassByPGO(thread, rootHClass, rootLayout); } -bool PGOHClassTreeDesc::DumpForChild(JSTaggedType child, ProfileType childType) +bool PGOHClassTreeDesc::DumpForChild(const JSThread *thread, JSTaggedType child, ProfileType childType) { ASSERT(!childType.IsRootType()); auto childHClass = JSHClass::Cast(JSTaggedValue(child).GetTaggedObject()); @@ -131,20 +131,20 @@ bool PGOHClassTreeDesc::DumpForChild(JSTaggedType child, ProfileType childType) auto iter = transitionLayout_.find(childType); if (iter != transitionLayout_.end()) { childLayout = iter->second; - return JSHClass::UpdateChildLayoutDescByPGO(childHClass, childLayout); + return JSHClass::UpdateChildLayoutDescByPGO(thread, childHClass, childLayout); } else { childLayout = new ChildHClassLayoutDesc(childType); transitionLayout_.emplace(childType, childLayout); - return JSHClass::DumpChildHClassByPGO(childHClass, childLayout); + return JSHClass::DumpChildHClassByPGO(thread, childHClass, childLayout); } } -bool PGOHClassTreeDesc::UpdateLayout(JSTaggedType curHClass, ProfileType curType) +bool PGOHClassTreeDesc::UpdateLayout(const JSThread *thread, JSTaggedType curHClass, ProfileType curType) { if (curType.IsRootType()) { - return DumpForRoot(curHClass, curType); + return DumpForRoot(thread, curHClass, curType); } else { - return DumpForChild(curHClass, curType); + return DumpForChild(thread, curHClass, curType); } } @@ -153,11 +153,11 @@ bool PGOHClassTreeDesc::IsDumped(ProfileType curType) const return transitionLayout_.find(curType) != transitionLayout_.end(); } -bool PGOHClassTreeDesc::UpdateForTransition( +bool PGOHClassTreeDesc::UpdateForTransition(const JSThread *thread, JSTaggedType parent, ProfileType parentType, JSTaggedType child, ProfileType childType) { if (parentType.IsRootType()) { - if (!DumpForRoot(parent, parentType)) { + if (!DumpForRoot(thread, parent, parentType)) { return false; } } @@ -165,7 +165,7 @@ bool PGOHClassTreeDesc::UpdateForTransition( return false; } - bool ret = DumpForChild(child, childType); + bool ret = DumpForChild(thread, child, childType); auto parentLayoutDesc = transitionLayout_.find(parentType)->second; auto childLayoutDesc = transitionLayout_.find(childType)->second; parentLayoutDesc->AddChildHClassLayoutDesc(childLayoutDesc->GetProfileType()); diff --git a/ecmascript/pgo_profiler/pgo_profiler_layout.h b/ecmascript/pgo_profiler/pgo_profiler_layout.h index d833ea0b72..5ac98e320d 100644 --- a/ecmascript/pgo_profiler/pgo_profiler_layout.h +++ b/ecmascript/pgo_profiler/pgo_profiler_layout.h @@ -313,10 +313,11 @@ public: HClassLayoutDesc *GetHClassLayoutDesc(ProfileType type) const; HClassLayoutDesc *GetOrInsertHClassLayoutDesc(ProfileType type, bool root = false); - bool DumpForRoot(JSTaggedType root, ProfileType rootType); - bool DumpForChild(JSTaggedType child, ProfileType childType); - bool UpdateForTransition(JSTaggedType parent, ProfileType parentType, JSTaggedType child, ProfileType childType); - bool UpdateLayout(JSTaggedType curHClass, ProfileType curType); + bool DumpForRoot(const JSThread *thread, JSTaggedType root, ProfileType rootType); + bool DumpForChild(const JSThread *thread, JSTaggedType child, ProfileType childType); + bool UpdateForTransition(const JSThread *thread, JSTaggedType parent, ProfileType parentType, + JSTaggedType child, ProfileType childType); + bool UpdateLayout(const JSThread *thread, JSTaggedType curHClass, ProfileType curType); bool IsDumped(ProfileType curType) const; template diff --git a/ecmascript/pgo_profiler/pgo_trace.h b/ecmascript/pgo_profiler/pgo_trace.h index 2d2383f226..7845e2a440 100644 --- a/ecmascript/pgo_profiler/pgo_trace.h +++ b/ecmascript/pgo_profiler/pgo_trace.h @@ -66,12 +66,12 @@ public: class MethodData { public: - MethodData(JSTaggedValue value, bool hotness) + MethodData(const JSThread *thread, JSTaggedValue value, bool hotness) { Method* method = Method::Cast(value); - name_ = method->GetMethodName(); + name_ = method->GetMethodName(thread); id_ = method->GetMethodId(); - codesize_ = method->GetCodeSize(); + codesize_ = method->GetCodeSize(thread); hotness_ = hotness; } @@ -126,9 +126,9 @@ public: return &(iter->second); } - MethodData* TryGetMethodData(JSTaggedValue value, bool hotness = false) + MethodData* TryGetMethodData(const JSThread *thread, JSTaggedValue value, bool hotness = false) { - MethodData method(value, hotness); + MethodData method(thread, value, hotness); auto data = GetMethodData(method.GetId()); if (data) { data->SetHotness(hotness); diff --git a/ecmascript/pgo_profiler/types/pgo_type_generator.h b/ecmascript/pgo_profiler/types/pgo_type_generator.h index efef863913..3ef15a84bb 100644 --- a/ecmascript/pgo_profiler/types/pgo_type_generator.h +++ b/ecmascript/pgo_profiler/types/pgo_type_generator.h @@ -26,9 +26,9 @@ namespace panda::ecmascript::pgo { class PGOTypeGenerator { public: - static ProfileType GenerateProfileType(JSTaggedType child, ProfileType rootType) + static ProfileType GenerateProfileType(const JSThread *thread, JSTaggedType child, ProfileType rootType) { - std::pair result = JSHClass::DumpToString(child); + std::pair result = JSHClass::DumpToString(thread, child); uint32_t traceId = ComputeHashCode(result.second); if (result.first) { return ProfileType(rootType.GetAbcId(), traceId, ProfileType::Kind::InvalidId); diff --git a/ecmascript/property_accessor.cpp b/ecmascript/property_accessor.cpp index 300451d1e2..81f2b6acae 100644 --- a/ecmascript/property_accessor.cpp +++ b/ecmascript/property_accessor.cpp @@ -58,7 +58,7 @@ void PropertyAccessor::PreLoad() onlyHasSimpleProperties_ = false; tryPrototypeChainEnumCache_ = false; } - std::pair numOfKeys = receiverObj->GetNumberOfEnumKeys(); + std::pair numOfKeys = receiverObj->GetNumberOfEnumKeys(thread_); uint32_t numOfEnumKeys = numOfKeys.first; if (numOfEnumKeys > 0) { AccumulateKeyLength(numOfEnumKeys); @@ -85,8 +85,8 @@ bool PropertyAccessor::HasPrototypeChainEnumCache() tryPrototypeChainEnumCache_ = false; return false; } - JSTaggedValue enumCache = current.GetTaggedObject()->GetClass()->GetEnumCache(); - return enumCache.IsEnumCacheAllValid(); + JSTaggedValue enumCache = current.GetTaggedObject()->GetClass()->GetEnumCache(thread_); + return enumCache.IsEnumCacheAllValid(thread_); } void PropertyAccessor::CollectPrototypeInfo() @@ -107,7 +107,7 @@ void PropertyAccessor::CollectPrototypeInfo() hasPrototypeChainEnumCache_ = false; tryPrototypeChainEnumCache_ = false; } - std::pair numOfKeys = currentObj->GetNumberOfEnumKeys(); + std::pair numOfKeys = currentObj->GetNumberOfEnumKeys(thread_); uint32_t numOfEnumKeys = numOfKeys.first; if (numOfEnumKeys > 0) { AccumulateKeyLength(numOfEnumKeys); @@ -123,7 +123,7 @@ void PropertyAccessor::CollectPrototypeInfo() hasPrototypeChainEnumCache_ = false; tryPrototypeChainEnumCache_ = false; } - current = JSObject::GetPrototype(current); + current = JSObject::GetPrototype(thread_, current); } } @@ -153,7 +153,7 @@ void PropertyAccessor::InitSimplePropertiesEnumCache() } // Set proto's ProtoChainInfoEnumCache to JSTaggedValue::NULL and enable proto's ChangeMarker. - JSTaggedValue proto = JSObject::GetPrototype(receiver_.GetTaggedValue()); + JSTaggedValue proto = JSObject::GetPrototype(thread_, receiver_.GetTaggedValue()); if (proto.IsHeapObject()) { JSHandle enumCache = JSObject::GetOrCreateEnumCache(thread_, JSHandle(thread_, proto.GetTaggedObject()->GetClass())); @@ -232,7 +232,7 @@ JSHandle PropertyAccessor::GetChainKeys(const JSHandle(current), keyArray, &keysNum, shadowQueue); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread_); JSObject::ClearHasDeleteProperty(current); - current.Update(JSObject::GetPrototype(current.GetTaggedValue())); + current.Update(JSObject::GetPrototype(thread_, current.GetTaggedValue())); } AddUndefinedEndIfNeeded(keyArray, keyLength, keysNum); return keyArray; @@ -301,15 +301,15 @@ void PropertyAccessor::AddKey(const JSHandle &value, uint32_t receiverKeysLength = keyArrayOnReceiver->GetLength(); JSMutableHandle key(thread_, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < receiverKeysLength; i++) { - key.Update(keyArrayOnReceiver->Get(i)); + key.Update(keyArrayOnReceiver->Get(thread_, i)); if (JSTaggedValue::Equal(thread_, key, value)) { return; } } - uint32_t shadowKeysSize = shadowQueueOnReceiver->Size(); + uint32_t shadowKeysSize = shadowQueueOnReceiver->Size(thread_); for (uint32_t i = 0; i < shadowKeysSize; i++) { - key.Update(shadowQueueOnReceiver->Get(i)); + key.Update(shadowQueueOnReceiver->Get(thread_, i)); if (JSTaggedValue::Equal(thread_, key, value)) { return; } @@ -330,7 +330,7 @@ JSHandle PropertyAccessor::CombineKeys(const JSHandle allKeys->Copy(thread_, 0, 0, keyArrayOnReceiver.GetObject(), receiverKeysLength); JSMutableHandle value(thread_, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < PrototypeChainKeysLength; i++) { - value.Update(keyArrayOnPrototypeChain->Get(i)); + value.Update(keyArrayOnPrototypeChain->Get(thread_, i)); AddKey(value, allKeys, allKeysLength, keyArrayOnReceiver, shadowQueueOnReceiver); } AddUndefinedEndIfNeeded(allKeys, arraySize, allKeysLength); @@ -344,8 +344,8 @@ JSHandle PropertyAccessor::GetKeysFastWithPrototypeChainEnumCache auto proto = JSTaggedValue::GetPrototype(thread_, receiver_); JSHandle protoHandle(thread_, proto); if (hasPrototypeChainEnumCache_) { - EnumCache* enumCacheProto = EnumCache::Cast(proto.GetTaggedObject()->GetClass()->GetEnumCache()); - JSHandle keyValueOnPrototypeChain(thread_, enumCacheProto->GetEnumCacheAll()); + EnumCache* enumCacheProto = EnumCache::Cast(proto.GetTaggedObject()->GetClass()->GetEnumCache(thread_)); + JSHandle keyValueOnPrototypeChain(thread_, enumCacheProto->GetEnumCacheAll(thread_)); keyArrayOnPrototypeChain = JSHandle::Cast(keyValueOnPrototypeChain); JSHandle::Cast(enumCache_)-> SetProtoChainInfoEnumCache(thread_, keyArrayOnPrototypeChain.GetTaggedValue()); @@ -411,7 +411,7 @@ void PropertyAccessor::PushRemainingKeys(JSHandle object, std::vector< RETURN_IF_ABRUPT_COMPLETION(thread_); uint32_t length = proxyArr->GetLength(); for (uint32_t i = 0; i < length; i++) { - value.Update(proxyArr->Get(i)); + value.Update(proxyArr->Get(thread_, i)); PropertyDescriptor desc(thread_); JSProxy::GetOwnProperty(thread_, JSHandle(object), value, desc); RETURN_IF_ABRUPT_COMPLETION(thread_); @@ -427,7 +427,7 @@ void PropertyAccessor::PushRemainingKeys(JSHandle object, std::vector< JSHandle array = JSTaggedValue::GetOwnEnumPropertyKeys(thread_, JSHandle(object)); uint32_t length = array->GetLength(); for (uint32_t i = 0; i < length; i++) { - value.Update(array->Get(i)); + value.Update(array->Get(thread_, i)); if (!value->IsString()) { array->Set(thread_, i, JSTaggedValue::Hole()); } else { diff --git a/ecmascript/regexp/regexp_parser_cache.cpp b/ecmascript/regexp/regexp_parser_cache.cpp index 55db272a6d..4fdcb51724 100644 --- a/ecmascript/regexp/regexp_parser_cache.cpp +++ b/ecmascript/regexp/regexp_parser_cache.cpp @@ -36,30 +36,32 @@ void RegExpParserCache::Clear() } } -size_t RegExpParserCache::GetHash(EcmaString *pattern, const uint32_t flags) +size_t RegExpParserCache::GetHash(const JSThread *thread, EcmaString *pattern, const uint32_t flags) { - auto hashcode = EcmaStringAccessor(pattern).GetHashcode(); + auto hashcode = EcmaStringAccessor(pattern).GetHashcode(thread); return (hashcode ^ flags) % CACHE_SIZE; } -std::pair RegExpParserCache::GetCache(EcmaString *pattern, const uint32_t flags, +std::pair RegExpParserCache::GetCache(const JSThread *thread, + EcmaString *pattern, const uint32_t flags, CVector &groupName) { - size_t hash = GetHash(pattern, flags); + size_t hash = GetHash(thread, pattern, flags); ParserKey &info = info_[hash]; if (info.flags_ != flags || info.pattern_ == nullptr || - !EcmaStringAccessor::StringsAreEqual(info.pattern_, pattern)) { + !EcmaStringAccessor::StringsAreEqual(thread, 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, +void RegExpParserCache::SetCache(const JSThread *thread, + EcmaString *pattern, const uint32_t flags, const JSTaggedValue codeBuffer, const size_t bufferSize, CVector groupName) { - size_t hash = GetHash(pattern, flags); + size_t hash = GetHash(thread, pattern, flags); ParserKey &info = info_[hash]; info.pattern_ = pattern; info.flags_ = flags; diff --git a/ecmascript/regexp/regexp_parser_cache.h b/ecmascript/regexp/regexp_parser_cache.h index aa167f5ac7..0a2de2b972 100644 --- a/ecmascript/regexp/regexp_parser_cache.h +++ b/ecmascript/regexp/regexp_parser_cache.h @@ -30,14 +30,16 @@ 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, + std::pair GetCache(const JSThread *thread, + EcmaString *pattern, const uint32_t flags, CVector &groupName); - void SetCache(EcmaString *pattern, const uint32_t flags, const JSTaggedValue codeBuffer, + void SetCache(const JSThread *thread, + EcmaString *pattern, const uint32_t flags, const JSTaggedValue codeBuffer, const size_t bufferSize, CVector groupName); void Clear(); private: - size_t GetHash(EcmaString *pattern, const uint32_t flags); + size_t GetHash(const JSThread *thread, EcmaString *pattern, const uint32_t flags); struct ParserKey { EcmaString *pattern_ {nullptr}; diff --git a/ecmascript/require/js_cjs_module.cpp b/ecmascript/require/js_cjs_module.cpp index f535398f65..5149b4cb8f 100644 --- a/ecmascript/require/js_cjs_module.cpp +++ b/ecmascript/require/js_cjs_module.cpp @@ -51,9 +51,9 @@ JSHandle CjsModule::SearchFromModuleCache(JSThread *thread, JSHan false, JSTaggedValue::Undefined()); JSHandle moduleCache = JSHandle(thread, modCache); - if (moduleCache->ContainsModule(filename.GetTaggedValue())) { + if (moduleCache->ContainsModule(thread, filename.GetTaggedValue())) { JSHandle cachedModule = JSHandle(thread, - moduleCache->GetModule(filename.GetTaggedValue())); + moduleCache->GetModule(thread, filename.GetTaggedValue())); JSHandle exportsName = globalConst->GetHandledCjsExportsString(); JSTaggedValue cachedExports = SlowRuntimeStub::LdObjByName(thread, cachedModule.GetTaggedValue(), exportsName.GetTaggedValue(), @@ -95,7 +95,7 @@ JSHandle CjsModule::Load(JSThread *thread, JSHandle & } CString filename = jsPandaFile->GetJSPandaFileDesc(); CString requestEntryPoint = JSPandaFile::ENTRY_MAIN_FUNCTION; - CString requestStr = ModulePathHelper::Utf8ConvertToString(request.GetTaggedValue()); + CString requestStr = ModulePathHelper::Utf8ConvertToString(thread, request.GetTaggedValue()); CString parent; CString dirname; CString recordName; diff --git a/ecmascript/require/js_cjs_module_cache.cpp b/ecmascript/require/js_cjs_module_cache.cpp index d3a6426f2f..ae2e509bbe 100644 --- a/ecmascript/require/js_cjs_module_cache.cpp +++ b/ecmascript/require/js_cjs_module_cache.cpp @@ -21,7 +21,7 @@ JSHandle CjsModuleCache::PutIfAbsentAndReset(const JSThread *thr const JSHandle &key, const JSHandle &value) { - int entry = dictionary->FindEntry(key.GetTaggedValue()); + int entry = dictionary->FindEntry(thread, key.GetTaggedValue()); if (entry != -1) { return ResetModule(thread, dictionary, key, value); } @@ -30,8 +30,8 @@ JSHandle CjsModuleCache::PutIfAbsentAndReset(const JSThread *thr JSHandle newDictionary(HashTable::GrowHashTable(thread, dictionary)); // Compute the key object. - uint32_t hash = Hash(key.GetTaggedValue()); - entry = newDictionary->FindInsertIndex(hash); + uint32_t hash = Hash(thread, key.GetTaggedValue()); + entry = newDictionary->FindInsertIndex(thread, hash); newDictionary->SetEntry(thread, entry, key, value); newDictionary->IncreaseEntries(thread); @@ -43,7 +43,7 @@ JSHandle CjsModuleCache::ResetModule(const JSThread *thread, const JSHandle &key, const JSHandle &value) { - int entry = dictionary->FindEntry(key.GetTaggedValue()); + int entry = dictionary->FindEntry(thread, key.GetTaggedValue()); ASSERT(entry != -1); if (entry == -1) { LOG_FULL(FATAL) << "CjsModuleCache::ResetModule Failed"; diff --git a/ecmascript/require/js_cjs_module_cache.h b/ecmascript/require/js_cjs_module_cache.h index 5616fe5b99..f4b2d57d77 100644 --- a/ecmascript/require/js_cjs_module_cache.h +++ b/ecmascript/require/js_cjs_module_cache.h @@ -54,7 +54,7 @@ public: return ENTRY_SIZE; } - static inline bool IsMatch(const JSTaggedValue &fileName, const JSTaggedValue &other) + static inline bool IsMatch(const JSThread *thread, const JSTaggedValue &fileName, const JSTaggedValue &other) { if (fileName.IsHole() || fileName.IsUndefined()) { return false; @@ -62,14 +62,14 @@ public: auto *nameString = static_cast(fileName.GetTaggedObject()); auto *otherString = static_cast(other.GetTaggedObject()); - return EcmaStringAccessor::StringsAreEqual(nameString, otherString); + return EcmaStringAccessor::StringsAreEqual(thread, nameString, otherString); } - static inline uint32_t Hash(const JSTaggedValue &key) + static inline uint32_t Hash(const JSThread *thread, const JSTaggedValue &key) { ASSERT(key.IsString()); EcmaString *nameStr = static_cast(key.GetTaggedObject()); - return EcmaStringAccessor(nameStr).GetHashcode(); + return EcmaStringAccessor(nameStr).GetHashcode(thread); } static const int DEFAULT_ELEMENTS_NUMBER = 64; @@ -79,39 +79,39 @@ public: return HashTable::Create(thread, numberOfElements); } - inline int FindEntry(const JSTaggedValue &key) + inline int FindEntry(const JSThread *thread, const JSTaggedValue &key) { int size = Size(); int count = 1; JSTaggedValue keyValue; - uint32_t hash = Hash(key); + uint32_t hash = Hash(thread, key); for (uint32_t entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { - keyValue = GetKey(entry); + keyValue = GetKey(thread, entry); if (keyValue.IsHole()) { continue; } if (keyValue.IsUndefined()) { return -1; } - if (IsMatch(key, keyValue)) { + if (IsMatch(thread, key, keyValue)) { return entry; } } return -1; } - inline bool ContainsModule(const JSTaggedValue &key) + inline bool ContainsModule(const JSThread *thread, const JSTaggedValue &key) { - int entry = FindEntry(key); + int entry = FindEntry(thread, key); return entry != -1; } - inline JSTaggedValue GetModule(const JSTaggedValue &key) + inline JSTaggedValue GetModule(const JSThread *thread, const JSTaggedValue &key) { - int entry = FindEntry(key); + int entry = FindEntry(thread, key); ASSERT(entry != -1); - return GetValue(entry); + return GetValue(thread, entry); } inline void SetEntry(const JSThread *thread, int entry, @@ -132,7 +132,8 @@ public: const JSHandle &dictionary, const JSHandle &key, const JSHandle &value); - static int ComputeCompactSize([[maybe_unused]] const JSHandle &table, int computeHashTableSize, + static int ComputeCompactSize([[maybe_unused]] const JSThread *thread, + [[maybe_unused]] const JSHandle &table, int computeHashTableSize, [[maybe_unused]] int tableSize, [[maybe_unused]] int addedElements) { return computeHashTableSize; diff --git a/ecmascript/require/tests/js_cjs_manager_test.cpp b/ecmascript/require/tests/js_cjs_manager_test.cpp index b759eccc8a..2c385ffd90 100644 --- a/ecmascript/require/tests/js_cjs_manager_test.cpp +++ b/ecmascript/require/tests/js_cjs_manager_test.cpp @@ -74,7 +74,7 @@ HWTEST_F_L0(CjsManagerTest, InitializeCommonJS) SlowRuntimeStub::LdObjByName(thread, module.GetTaggedValue(), exportsKey.GetTaggedValue(), false, JSTaggedValue::Undefined()); - EXPECT_EQ(JSTaggedValue::SameValue(exportsVal, JSTaggedValue::Hole()), false); + EXPECT_EQ(JSTaggedValue::SameValue(thread, exportsVal, JSTaggedValue::Hole()), false); } /** diff --git a/ecmascript/require/tests/js_cjs_module_cache_test.cpp b/ecmascript/require/tests/js_cjs_module_cache_test.cpp index fe12a781c1..7d82333bf7 100644 --- a/ecmascript/require/tests/js_cjs_module_cache_test.cpp +++ b/ecmascript/require/tests/js_cjs_module_cache_test.cpp @@ -70,10 +70,10 @@ HWTEST_F_L0(CjsModuleCacheTest, PutIfAbsent) JSHandle::Cast(fileName), JSHandle(module)); JSHandle moduleTested = JSHandle(thread, - newCacheTested->GetModule(fileName.GetTaggedValue())); + newCacheTested->GetModule(thread, fileName.GetTaggedValue())); - EXPECT_TRUE(newCacheTested->ContainsModule(fileName.GetTaggedValue())); - JSHandle fileNameTested(thread, moduleTested->GetFilename()); + EXPECT_TRUE(newCacheTested->ContainsModule(thread, fileName.GetTaggedValue())); + JSHandle fileNameTested(thread, moduleTested->GetFilename(thread)); EXPECT_EQ(EcmaStringAccessor::Compare(vm, fileNameTested, JSHandle(fileName)), 0); } @@ -102,9 +102,9 @@ HWTEST_F_L0(CjsModuleCacheTest, ResetModule) JSHandle newCacheTested = CjsModuleCache::ResetModule(thread, newCache, fileName, JSHandle::Cast(moduleWithNewExp)); JSHandle moduleTested = JSHandle(thread, - newCacheTested->GetModule(fileName.GetTaggedValue())); + newCacheTested->GetModule(thread, fileName.GetTaggedValue())); - JSHandle exportsTested(thread, moduleTested->GetExports()); + JSHandle exportsTested(thread, moduleTested->GetExports(thread)); EXPECT_EQ(EcmaStringAccessor::Compare(vm, exportsTested, test), 0); } } // namespace panda::test diff --git a/ecmascript/sendable_env.h b/ecmascript/sendable_env.h index c5e44dbdde..54df42bd87 100644 --- a/ecmascript/sendable_env.h +++ b/ecmascript/sendable_env.h @@ -42,14 +42,14 @@ public: Set(thread, SENDABLE_PARENT_ENV_INDEX, value); } - JSTaggedValue GetParentEnv() const + JSTaggedValue GetParentEnv(JSThread *thread) const { - return Get(SENDABLE_PARENT_ENV_INDEX); + return Get(thread, SENDABLE_PARENT_ENV_INDEX); } - JSTaggedValue GetProperties(uint32_t index) const + JSTaggedValue GetProperties(JSThread *thread, uint32_t index) const { - return Get(index + SENDABLE_RESERVED_ENV_LENGTH); + return Get(thread, index + SENDABLE_RESERVED_ENV_LENGTH); } void SetProperties(JSThread *thread, uint32_t index, JSTaggedValue value) @@ -57,9 +57,9 @@ public: Set(thread, index + SENDABLE_RESERVED_ENV_LENGTH, value); } - JSTaggedValue GetScopeInfo() const + JSTaggedValue GetScopeInfo(JSThread *thread) const { - return Get(SENDABLE_SCOPE_INFO_INDEX); + return Get(thread, SENDABLE_SCOPE_INFO_INDEX); } void SetScopeInfo(JSThread *thread, JSTaggedValue value) diff --git a/ecmascript/serializer/base_deserializer.cpp b/ecmascript/serializer/base_deserializer.cpp index dfd318de29..4ff7414918 100644 --- a/ecmascript/serializer/base_deserializer.cpp +++ b/ecmascript/serializer/base_deserializer.cpp @@ -181,7 +181,7 @@ void BaseDeserializer::HandleNewObjectEncodeFlag(SerializedObjectSpace space, u } } else if (object->GetClass()->IsJSFunction()) { JSFunction* func = reinterpret_cast(object); - FunctionKind funcKind = func->GetFunctionKind(); + FunctionKind funcKind = func->GetFunctionKind(thread_); if (funcKind == FunctionKind::CONCURRENT_FUNCTION || object->GetClass()->IsJSSharedFunction()) { // defer initialize concurrent function JSHandle funcHandle(thread_, func); @@ -203,7 +203,8 @@ void BaseDeserializer::TransferArrayBufferAttach(uintptr_t objAddr) JSArrayBuffer *arrayBuffer = reinterpret_cast(objAddr); size_t arrayLength = arrayBuffer->GetArrayBufferByteLength(); bool withNativeAreaAllocator = arrayBuffer->GetWithNativeAreaAllocator(); - JSNativePointer *np = reinterpret_cast(arrayBuffer->GetArrayBufferData().GetTaggedObject()); + JSNativePointer *np = + reinterpret_cast(arrayBuffer->GetArrayBufferData(thread_).GetTaggedObject()); arrayBuffer->Attach(thread_, arrayLength, JSTaggedValue(np), withNativeAreaAllocator); } @@ -212,7 +213,8 @@ void BaseDeserializer::IncreaseSharedArrayBufferReference(uintptr_t objAddr) ASSERT(JSTaggedValue(static_cast(objAddr)).IsSharedArrayBuffer()); JSArrayBuffer *arrayBuffer = reinterpret_cast(objAddr); size_t arrayLength = arrayBuffer->GetArrayBufferByteLength(); - JSNativePointer *np = reinterpret_cast(arrayBuffer->GetArrayBufferData().GetTaggedObject()); + JSNativePointer *np = + reinterpret_cast(arrayBuffer->GetArrayBufferData(thread_).GetTaggedObject()); void *buffer = np->GetExternalPointer(); if (JSSharedMemoryManager::GetInstance()->CreateOrLoad(&buffer, arrayLength)) { LOG_ECMA(FATAL) << "BaseDeserializer::IncreaseSharedArrayBufferReference failed"; @@ -228,11 +230,12 @@ void BaseDeserializer::ResetNativePointerBuffer(uintptr_t objAddr, void *bufferP if (obj.IsArrayBuffer()) { JSArrayBuffer *arrayBuffer = reinterpret_cast(objAddr); arrayBuffer->SetWithNativeAreaAllocator(true); - np = reinterpret_cast(arrayBuffer->GetArrayBufferData().GetTaggedObject()); - nativeAreaAllocator->IncreaseNativeSizeStats(arrayBuffer->GetArrayBufferByteLength(), NativeFlag::ARRAY_BUFFER); + np = reinterpret_cast(arrayBuffer->GetArrayBufferData(thread_).GetTaggedObject()); + nativeAreaAllocator->IncreaseNativeSizeStats(arrayBuffer->GetArrayBufferByteLength(), + NativeFlag::ARRAY_BUFFER); } else { JSRegExp *jsRegExp = reinterpret_cast(objAddr); - np = reinterpret_cast(jsRegExp->GetByteCodeBuffer().GetTaggedObject()); + np = reinterpret_cast(jsRegExp->GetByteCodeBuffer(thread_).GetTaggedObject()); nativeAreaAllocator->IncreaseNativeSizeStats(jsRegExp->GetLength(), NativeFlag::REGEXP_BTYECODE); } @@ -498,25 +501,25 @@ JSTaggedType BaseDeserializer::RelocateObjectProtoAddr(uint8_t objectType) case (uint8_t)JSType::JS_OBJECT: return env->GetObjectFunctionPrototype().GetTaggedType(); case (uint8_t)JSType::JS_ERROR: - return JSHandle(env->GetErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_EVAL_ERROR: - return JSHandle(env->GetEvalErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetEvalErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_RANGE_ERROR: - return JSHandle(env->GetRangeErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetRangeErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_REFERENCE_ERROR: - return JSHandle(env->GetReferenceErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetReferenceErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_TYPE_ERROR: - return JSHandle(env->GetTypeErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetTypeErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_AGGREGATE_ERROR: - return JSHandle(env->GetAggregateErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetAggregateErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_URI_ERROR: - return JSHandle(env->GetURIErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetURIErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_SYNTAX_ERROR: - return JSHandle(env->GetSyntaxErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetSyntaxErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_OOM_ERROR: - return JSHandle(env->GetOOMErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetOOMErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_TERMINATION_ERROR: - return JSHandle(env->GetTerminationErrorFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetTerminationErrorFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_DATE: return env->GetDatePrototype().GetTaggedType(); case (uint8_t)JSType::JS_ARRAY: @@ -582,15 +585,15 @@ JSTaggedType BaseDeserializer::RelocateObjectProtoAddr(uint8_t objectType) case (uint8_t)JSType::JS_SHARED_BIGUINT64_ARRAY: return env->GetSharedBigUint64ArrayFunctionPrototype().GetTaggedType(); case (uint8_t)JSType::JS_ARRAY_BUFFER: - return JSHandle(env->GetArrayBufferFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetArrayBufferFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_SHARED_ARRAY_BUFFER: - return JSHandle(env->GetSharedArrayBufferFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetSharedArrayBufferFunction())->GetFunctionPrototype(thread_).GetRawData(); case (uint8_t)JSType::JS_ASYNC_FUNCTION: return env->GetAsyncFunctionPrototype().GetTaggedType(); case (uint8_t)JSType::JS_SHARED_ASYNC_FUNCTION: return env->GetSAsyncFunctionPrototype().GetTaggedType(); case (uint8_t)JSType::BIGINT: - return JSHandle(env->GetBigIntFunction())->GetFunctionPrototype().GetRawData(); + return JSHandle(env->GetBigIntFunction())->GetFunctionPrototype(thread_).GetRawData(); default: LOG_ECMA(ERROR) << "Relocate unsupported JSType: " << JSHClass::DumpJSType(static_cast(objectType)); LOG_ECMA(FATAL) << "this branch is unreachable"; diff --git a/ecmascript/serializer/base_serializer-inl.h b/ecmascript/serializer/base_serializer-inl.h index 23ca7c8707..294fe648bf 100644 --- a/ecmascript/serializer/base_serializer-inl.h +++ b/ecmascript/serializer/base_serializer-inl.h @@ -28,6 +28,7 @@ template void BaseSerializer::SerializeObjectFieldVisitor::VisitObjectRangeImpl(BaseObject *rootObject, uintptr_t startAddr, uintptr_t endAddr, VisitObjectArea area) { + JSThread *thread = serializer_->GetThread(); switch (area) { case VisitObjectArea::RAW_DATA: serializer_->WriteMultiRawData(startAddr, endAddr - startAddr); @@ -45,7 +46,8 @@ void BaseSerializer::SerializeObjectFieldVisitor::VisitObjectRang default: { ObjectSlot end = ObjectSlot(endAddr); for (ObjectSlot slot = ObjectSlot(startAddr); slot < end; slot++) { - [[maybe_unused]] JSTaggedValue value = JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress())); + [[maybe_unused]] JSTaggedValue value = + JSTaggedValue(Barriers::GetTaggedValue(thread, slot.SlotAddress())); } serializer_->SerializeTaggedObjField(serializeType, TaggedObject::Cast(rootObject), ObjectSlot(startAddr), ObjectSlot(endAddr)); diff --git a/ecmascript/serializer/base_serializer.cpp b/ecmascript/serializer/base_serializer.cpp index 8e421914be..57db7cc519 100644 --- a/ecmascript/serializer/base_serializer.cpp +++ b/ecmascript/serializer/base_serializer.cpp @@ -149,11 +149,11 @@ void BaseSerializer::SerializeHClassFieldIndividually(TaggedObject *root, Object switch (fieldOffset) { case JSHClass::PROTOTYPE_OFFSET: { JSHClass *kclass = reinterpret_cast(root); - JSTaggedValue proto = kclass->GetPrototype(); + JSTaggedValue proto = kclass->GetPrototype(thread_); JSType type = kclass->GetObjectType(); if ((serializeSharedEvent_ > 0) && (type == JSType::JS_SHARED_OBJECT || type == JSType::JS_SHARED_FUNCTION)) { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); } else { SerializeObjectProto(kclass, proto); } @@ -176,7 +176,7 @@ void BaseSerializer::SerializeHClassFieldIndividually(TaggedObject *root, Object break; } default: { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); slot++; break; } @@ -212,7 +212,7 @@ void BaseSerializer::SerializeSFunctionFieldIndividually(TaggedObject *root, Obj break; } default: { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); slot++; break; } @@ -222,7 +222,7 @@ void BaseSerializer::SerializeSFunctionFieldIndividually(TaggedObject *root, Obj void BaseSerializer::SerializeSFunctionModule(JSFunction *func) { - JSTaggedValue moduleValue = func->GetModule(); + JSTaggedValue moduleValue = func->GetModule(thread_); if (moduleValue.IsHeapObject()) { #ifdef USE_CMC_GC if (!moduleValue.IsInSharedHeap()) { @@ -280,7 +280,7 @@ void BaseSerializer::SerializeSFunctionEnvFieldIndividually(TaggedObject *root, break; } default: { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); slot++; break; } @@ -303,7 +303,7 @@ void BaseSerializer::SerializeSendableEnvFieldIndividually(TaggedObject *root, O break; } default: { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); slot++; break; } @@ -348,7 +348,7 @@ void BaseSerializer::SerializeAsyncFunctionFieldIndividually(TaggedObject *root, break; } default: { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); slot++; break; } @@ -374,7 +374,7 @@ void BaseSerializer::SerializeTaggedObjField(SerializeType serializeType, Tagged if (serializeType != SerializeType::VALUE_SERIALIZE || !SerializeSpecialObjIndividually(objectType, root, start, end)) { for (ObjectSlot slot = start; slot < end; slot++) { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); } } } @@ -382,16 +382,16 @@ void BaseSerializer::SerializeTaggedObjField(SerializeType serializeType, Tagged void BaseSerializer::SerializeInObjField(TaggedObject *object, ObjectSlot start, ObjectSlot end) { auto hclass = object->GetClass(); - auto layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); + auto layout = LayoutInfo::Cast(hclass->GetLayout(thread_).GetTaggedObject()); size_t index = 0; for (ObjectSlot slot = start; slot < end; slot++) { - auto attr = layout->GetAttr(index++); + auto attr = layout->GetAttr(thread_, index++); if (attr.GetRepresentation() == Representation::DOUBLE || attr.GetRepresentation() == Representation::INT) { auto fieldAddr = slot.SlotAddress(); data_->WriteEncodeFlag(EncodeFlag::PRIMITIVE); data_->WriteRawData(reinterpret_cast(fieldAddr), sizeof(JSTaggedType)); } else { - SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(slot.SlotAddress()))); + SerializeJSTaggedValue(JSTaggedValue(Barriers::GetTaggedValue(thread_, slot.SlotAddress()))); } } } diff --git a/ecmascript/serializer/base_serializer.h b/ecmascript/serializer/base_serializer.h index 4f742ab25a..285f508130 100644 --- a/ecmascript/serializer/base_serializer.h +++ b/ecmascript/serializer/base_serializer.h @@ -44,6 +44,10 @@ public: return std::move(data_); } + JSThread *GetThread() + { + return thread_; + } protected: template class SerializeObjectFieldVisitor final : public BaseObjectVisitor> { diff --git a/ecmascript/serializer/tests/serializer_test.cpp b/ecmascript/serializer/tests/serializer_test.cpp index 298c659c05..399b06f662 100644 --- a/ecmascript/serializer/tests/serializer_test.cpp +++ b/ecmascript/serializer/tests/serializer_test.cpp @@ -84,16 +84,16 @@ public: BaseDeserializer deserializer(thread, data); JSHandle retTrue = deserializer.ReadValue(); - EXPECT_TRUE(JSTaggedValue::SameValue(jsTrue, retTrue)) << "Not same value for JS_TRUE"; + EXPECT_TRUE(JSTaggedValue::SameValue(thread, jsTrue, retTrue)) << "Not same value for JS_TRUE"; JSHandle retFalse = deserializer.ReadValue(); - EXPECT_TRUE(JSTaggedValue::SameValue(jsFalse, retFalse)) << "Not same value for JS_FALSE"; + EXPECT_TRUE(JSTaggedValue::SameValue(thread, jsFalse, retFalse)) << "Not same value for JS_FALSE"; JSHandle retUndefined = deserializer.ReadValue(); JSHandle retNull = deserializer.ReadValue(); JSHandle retHole = deserializer.ReadValue(); - EXPECT_TRUE(JSTaggedValue::SameValue(jsUndefined, retUndefined)) << "Not same value for JS_UNDEFINED"; - EXPECT_TRUE(JSTaggedValue::SameValue(jsNull, retNull)) << "Not same value for JS_NULL"; - EXPECT_TRUE(JSTaggedValue::SameValue(jsHole, retHole)) << "Not same value for JS_HOLE"; + EXPECT_TRUE(JSTaggedValue::SameValue(thread, jsUndefined, retUndefined)) << "Not same value for JS_UNDEFINED"; + EXPECT_TRUE(JSTaggedValue::SameValue(thread, jsNull, retNull)) << "Not same value for JS_NULL"; + EXPECT_TRUE(JSTaggedValue::SameValue(thread, jsHole, retHole)) << "Not same value for JS_HOLE"; Destroy(); } @@ -155,7 +155,7 @@ public: EXPECT_EQ(length, 4U); // 4 : test case double sum = 0.0; for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); double a = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue()->GetNumber(); sum += a; } @@ -179,7 +179,7 @@ public: uint32_t length = array->GetLength(); EXPECT_EQ(length, 10U); for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); JSHandle value = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue(); EXPECT_TRUE(value->GetTaggedObject()->GetClass()->IsJSObject()); @@ -204,7 +204,7 @@ public: uint32_t length = array->GetLength(); EXPECT_EQ(length, 1030U); for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); JSHandle value = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue(); EXPECT_TRUE(value->IsInt()); @@ -234,7 +234,7 @@ public: size_t length = array->GetLength(); EXPECT_EQ(length, 102400U); // 102400: array length for (uint32_t i = 0; i < length; i++) { - EXPECT_TRUE(array->Get(i).IsHole()); + EXPECT_TRUE(array->Get(thread, i).IsHole()); } Destroy(); @@ -286,7 +286,7 @@ public: uint32_t length = array->GetLength(); EXPECT_EQ(length, 2U); for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); JSHandle value = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue(); EXPECT_TRUE(value->IsJSError()); @@ -311,7 +311,7 @@ public: uint32_t length = array->GetLength(); EXPECT_EQ(length, 7U); // 7 : test case for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); JSHandle value = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue(); EXPECT_TRUE(value->IsJSError()); @@ -335,7 +335,7 @@ public: uint32_t length = array->GetLength(); EXPECT_EQ(length, 2U); for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); JSHandle value = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue(); EXPECT_TRUE(value->GetTaggedObject()->GetClass()->IsBigInt()); @@ -368,7 +368,7 @@ public: JSHandle array = JSObject::GetOwnPropertyKeys(thread, retObj); uint32_t length = array->GetLength(); EXPECT_EQ(length, 2U); - JSHandle key(thread, array->Get(0)); + JSHandle key(thread, array->Get(thread, 0)); JSHandle value = JSObject::GetProperty(thread, JSHandle(retObj), key).GetValue(); EXPECT_TRUE(value->IsUndefined()); @@ -397,13 +397,13 @@ public: EXPECT_EQ(propertyLength, 2U); // 2 : test case int sum = 0; for (uint32_t i = 0; i < propertyLength; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); double a = JSObject::GetProperty(thread, JSHandle(retSet), key).GetValue()->GetNumber(); sum += a; } EXPECT_EQ(sum, 16); // 16 : test case - EXPECT_EQ(retSet->GetSize(), 4); // 4 : test case + EXPECT_EQ(retSet->GetSize(thread), 4); // 4 : test case EXPECT_TRUE(retSet->Has(thread, value1.GetTaggedValue())); EXPECT_TRUE(retSet->Has(thread, value2.GetTaggedValue())); EXPECT_TRUE(retSet->Has(thread, value3.GetTaggedValue())); @@ -427,7 +427,7 @@ public: EXPECT_EQ(propertyLength, 23U); // 23 : test case int sum = 0; for (uint32_t i = 0; i < propertyLength; i++) { - JSHandle key(thread, keyArray->Get(i)); + JSHandle key(thread, keyArray->Get(thread, i)); double a = JSObject::GetProperty(thread, JSHandle(retArray), key).GetValue()->GetNumber(); sum += a; } @@ -458,10 +458,10 @@ public: ecmaVm->CollectGarbage(TriggerGCType::OLD_GC); JSHandle resEcmaString = JSHandle::Cast(res); - auto ecmaStringCode = EcmaStringAccessor(ecmaString).GetHashcode(); - auto resEcmaStringCode = EcmaStringAccessor(resEcmaString).GetHashcode(); + auto ecmaStringCode = EcmaStringAccessor(ecmaString).GetHashcode(thread); + auto resEcmaStringCode = EcmaStringAccessor(resEcmaString).GetHashcode(thread); EXPECT_TRUE(ecmaStringCode == resEcmaStringCode) << "Not same HashCode"; - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*ecmaString, *resEcmaString)) << "Not same EcmaString"; + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *ecmaString, *resEcmaString)) << "Not same EcmaString"; Destroy(); } @@ -470,10 +470,10 @@ public: Init(); JSHandle ecmaString = thread->GetEcmaVM()->GetFactory()->NewFromStdString("你好,世界"); JSHandle ecmaString1 = thread->GetEcmaVM()->GetFactory()->NewFromStdString("你好,世界"); - auto ecmaStringCode1 = EcmaStringAccessor(ecmaString).GetHashcode(); - auto ecmaString1Code = EcmaStringAccessor(ecmaString1).GetHashcode(); + auto ecmaStringCode1 = EcmaStringAccessor(ecmaString).GetHashcode(thread); + auto ecmaString1Code = EcmaStringAccessor(ecmaString1).GetHashcode(thread); EXPECT_TRUE(ecmaStringCode1 == ecmaString1Code) << "Not same HashCode"; - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*ecmaString, *ecmaString1)) << "Not same EcmaString"; + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *ecmaString, *ecmaString1)) << "Not same EcmaString"; BaseDeserializer deserializer(thread, data); JSHandle res = deserializer.ReadValue(); @@ -483,10 +483,10 @@ public: ecmaVm->CollectGarbage(TriggerGCType::OLD_GC); JSHandle resEcmaString = JSHandle::Cast(res); - auto ecmaStringCode2 = EcmaStringAccessor(ecmaString).GetHashcode(); - auto resEcmaStringCode = EcmaStringAccessor(resEcmaString).GetHashcode(); + auto ecmaStringCode2 = EcmaStringAccessor(ecmaString).GetHashcode(thread); + auto resEcmaStringCode = EcmaStringAccessor(resEcmaString).GetHashcode(thread); EXPECT_TRUE(ecmaStringCode2 == resEcmaStringCode) << "Not same HashCode"; - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*ecmaString, *resEcmaString)) << "Not same EcmaString"; + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *ecmaString, *resEcmaString)) << "Not same EcmaString"; Destroy(); } @@ -532,7 +532,7 @@ public: EXPECT_TRUE(!res.IsEmpty()) << "[Empty] Deserialize JSDate fail"; EXPECT_TRUE(res->IsDate()) << "[NotJSDate] Deserialize JSDate fail"; JSHandle resDate = JSHandle(res); - EXPECT_TRUE(resDate->GetTimeValue() == JSTaggedValue(tm)) << "Not Same Time Value"; + EXPECT_TRUE(resDate->GetTimeValue(thread) == JSTaggedValue(tm)) << "Not Same Time Value"; Destroy(); } @@ -544,17 +544,17 @@ public: EXPECT_TRUE(!res.IsEmpty()) << "[Empty] Deserialize JSMap fail"; EXPECT_TRUE(res->IsJSMap()) << "[NotJSMap] Deserialize JSMap fail"; JSHandle resMap = JSHandle::Cast(res); - EXPECT_TRUE(originMap->GetSize() == resMap->GetSize()) << "the map size Not equal"; - uint32_t resSize = static_cast(resMap->GetSize()); + EXPECT_TRUE(originMap->GetSize(thread) == resMap->GetSize(thread)) << "the map size Not equal"; + uint32_t resSize = static_cast(resMap->GetSize(thread)); for (uint32_t i = 0; i < resSize; i++) { - JSHandle resKey(thread, resMap->GetKey(i)); - JSHandle resValue(thread, resMap->GetValue(i)); - JSHandle key(thread, originMap->GetKey(i)); - JSHandle value(thread, originMap->GetValue(i)); + JSHandle resKey(thread, resMap->GetKey(thread, i)); + JSHandle resValue(thread, resMap->GetValue(thread, i)); + JSHandle key(thread, originMap->GetKey(thread, i)); + JSHandle value(thread, originMap->GetValue(thread, i)); JSHandle resKeyStr = JSHandle::Cast(resKey); JSHandle keyStr = JSHandle::Cast(key); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*resKeyStr, *keyStr)) << "Not same map key"; + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *resKeyStr, *keyStr)) << "Not same map key"; EXPECT_TRUE(JSTaggedValue::ToInt32(thread, resValue) == JSTaggedValue::ToInt32(thread, value)) << "Not same map value"; } @@ -571,7 +571,7 @@ public: JSHandle resJSArrayBuffer = JSHandle::Cast(res); int32_t resByteLength = static_cast(resJSArrayBuffer->GetArrayBufferByteLength()); EXPECT_TRUE(resByteLength == byteLength) << "Not Same ByteLength"; - JSHandle resBufferData(thread, resJSArrayBuffer->GetArrayBufferData()); + JSHandle resBufferData(thread, resJSArrayBuffer->GetArrayBufferData(thread)); JSHandle resNp = JSHandle::Cast(resBufferData); void *resBuffer = resNp->GetExternalPointer(); ASSERT_NE(resBuffer, nullptr); @@ -591,10 +591,10 @@ public: JSHandle res = deserializer.ReadValue(); EXPECT_TRUE(!res.IsEmpty()); EXPECT_TRUE(res->IsJSObject()); - JSTaggedValue elements = JSHandle(res)->GetElements(); + JSTaggedValue elements = JSHandle(res)->GetElements(thread); EXPECT_TRUE(elements.IsTaggedArray()); EXPECT_EQ(JSHandle(thread, elements)->GetLength(), 10 * 1024); // 10 * 1024: array length - JSTaggedValue value = JSHandle(thread, elements)->Get(0); + JSTaggedValue value = JSHandle(thread, elements)->Get(thread, 0); EXPECT_TRUE(value.IsTaggedArray()); uint32_t length = JSHandle(thread, value)->GetLength(); EXPECT_EQ(length, 11 * 1024); // 11 * 1024: array length @@ -608,11 +608,11 @@ public: JSHandle res = deserializer.ReadValue(); EXPECT_TRUE(!res.IsEmpty()); EXPECT_TRUE(res->IsJSObject()); - JSTaggedValue elements = JSHandle(res)->GetElements(); + JSTaggedValue elements = JSHandle(res)->GetElements(thread); EXPECT_TRUE(elements.IsTaggedArray()); EXPECT_EQ(JSHandle(thread, elements)->GetLength(), 3 * 1024); // 3 * 1024: array length for (int i = 0; i < 5; i++) { // 5: array elements - JSTaggedValue value = JSHandle(thread, elements)->Get(i); + JSTaggedValue value = JSHandle(thread, elements)->Get(thread, i); EXPECT_TRUE(value.IsTaggedArray()); uint32_t length = JSHandle(thread, value)->GetLength(); EXPECT_EQ(length, 3 * 1024); // 3 * 1024: array length @@ -627,21 +627,21 @@ public: JSHandle res = deserializer.ReadValue(); EXPECT_TRUE(!res.IsEmpty()); EXPECT_TRUE(res->IsJSObject()); - JSTaggedValue properties = JSHandle(res)->GetProperties(); + JSTaggedValue properties = JSHandle(res)->GetProperties(thread); EXPECT_TRUE(properties.IsTaggedArray()); EXPECT_EQ(JSHandle(thread, properties)->GetLength(), 3 * 1024); // 3 * 1024: array length for (int i = 0; i < 5; i++) { // 5: array elements - JSTaggedValue value = JSHandle(thread, properties)->Get(i); + JSTaggedValue value = JSHandle(thread, properties)->Get(thread, i); EXPECT_TRUE(value.IsTaggedArray()); uint32_t length = JSHandle(thread, value)->GetLength(); EXPECT_EQ(length, 3 * 1024); // 3 * 1024: array length } - JSTaggedValue elements = JSHandle(res)->GetElements(); + JSTaggedValue elements = JSHandle(res)->GetElements(thread); EXPECT_TRUE(elements.IsTaggedArray()); EXPECT_EQ(JSHandle(thread, elements)->GetLength(), 3 * 1024); // 3 * 1024: array length for (int i = 0; i < 5; i++) { // 5: array elements - JSTaggedValue value = JSHandle(thread, elements)->Get(i); + JSTaggedValue value = JSHandle(thread, elements)->Get(thread, i); EXPECT_TRUE(value.IsTaggedArray()); uint32_t length = JSHandle(thread, value)->GetLength(); EXPECT_EQ(length, 3 * 1024); // 3 * 1024: array length @@ -750,13 +750,13 @@ public: uint32_t resBufferSize = resJSRegexp->GetLength(); EXPECT_TRUE(resBufferSize == bufferSize) << "Not Same Length"; - JSHandle originalSource(thread, resJSRegexp->GetOriginalSource()); + JSHandle originalSource(thread, resJSRegexp->GetOriginalSource(thread)); EXPECT_TRUE(originalSource->IsString()); - JSHandle originalFlags(thread, resJSRegexp->GetOriginalFlags()); + JSHandle originalFlags(thread, resJSRegexp->GetOriginalFlags(thread)); EXPECT_TRUE(originalFlags->IsString()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*JSHandle(originalSource), *pattern)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*JSHandle(originalFlags), *flags)); - JSHandle resBufferData(thread, resJSRegexp->GetByteCodeBuffer()); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *JSHandle(originalSource), *pattern)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *JSHandle(originalFlags), *flags)); + JSHandle resBufferData(thread, resJSRegexp->GetByteCodeBuffer(thread)); JSHandle resNp = JSHandle::Cast(resBufferData); void *resBuffer = resNp->GetExternalPointer(); ASSERT_NE(resBuffer, nullptr); @@ -778,15 +778,15 @@ public: EXPECT_TRUE(res->IsJSInt8Array()) << "[NotJSInt8Array] Deserialize TypedArray fail"; JSHandle resJSInt8Array = JSHandle::Cast(res); - JSHandle typedArrayName(thread, resJSInt8Array->GetTypedArrayName()); + JSHandle typedArrayName(thread, resJSInt8Array->GetTypedArrayName(thread)); uint32_t byteLength = resJSInt8Array->GetByteLength(); uint32_t byteOffset = resJSInt8Array->GetByteOffset(); uint32_t arrayLength = resJSInt8Array->GetArrayLength(); ContentType contentType = resJSInt8Array->GetContentType(); - JSHandle viewedArrayBuffer(thread, resJSInt8Array->GetViewedArrayBufferOrByteArray()); + JSHandle viewedArrayBuffer(thread, resJSInt8Array->GetViewedArrayBufferOrByteArray(thread)); EXPECT_TRUE(typedArrayName->IsString()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*JSHandle(typedArrayName), + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *JSHandle(typedArrayName), *JSHandle(originTypedArrayName))); EXPECT_EQ(byteLength, 10) << "Not Same ByteLength"; // 10: bufferLength EXPECT_EQ(byteOffset, 0) << "Not Same ByteOffset"; @@ -798,7 +798,7 @@ public: JSHandle resJSArrayBuffer(viewedArrayBuffer); uint32_t resTaggedLength = resJSArrayBuffer->GetArrayBufferByteLength(); EXPECT_EQ(resTaggedLength, 10) << "Not same viewedBuffer length"; // 10: bufferLength - JSHandle resBufferData(thread, resJSArrayBuffer->GetArrayBufferData()); + JSHandle resBufferData(thread, resJSArrayBuffer->GetArrayBufferData(thread)); JSHandle resNp = JSHandle::Cast(resBufferData); void *resBuffer = resNp->GetExternalPointer(); for (uint32_t i = 0; i < resTaggedLength; i++) { @@ -817,15 +817,15 @@ public: EXPECT_TRUE(res->IsJSInt8Array()) << "[NotJSInt8Array] Deserialize TypedArray fail"; JSHandle resJSInt8Array = JSHandle::Cast(res); - JSHandle typedArrayName(thread, resJSInt8Array->GetTypedArrayName()); + JSHandle typedArrayName(thread, resJSInt8Array->GetTypedArrayName(thread)); uint32_t byteLength = resJSInt8Array->GetByteLength(); uint32_t byteOffset = resJSInt8Array->GetByteOffset(); uint32_t arrayLength = resJSInt8Array->GetArrayLength(); ContentType contentType = resJSInt8Array->GetContentType(); - JSHandle byteArray(thread, resJSInt8Array->GetViewedArrayBufferOrByteArray()); + JSHandle byteArray(thread, resJSInt8Array->GetViewedArrayBufferOrByteArray(thread)); EXPECT_TRUE(typedArrayName->IsString()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*JSHandle(typedArrayName), + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *JSHandle(typedArrayName), *JSHandle(originTypedArrayName))); EXPECT_EQ(byteLength, 10) << "Not Same ByteLength"; // 10: bufferLength EXPECT_EQ(byteOffset, 0) << "Not Same ByteOffset"; @@ -860,7 +860,7 @@ public: uint32_t length = array->GetLength(); EXPECT_EQ(length, 512U); for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); JSHandle value = JSObject::GetProperty(thread, JSHandle(sObj), key).GetValue(); EXPECT_TRUE(value->IsInt()); @@ -879,10 +879,10 @@ public: JSHandle sFunc = JSHandle::Cast(res); EXPECT_TRUE(sFunc->IsCallable()); - EXPECT_FALSE(sFunc->GetProtoOrHClass().IsHole()); - EXPECT_TRUE(sFunc->GetLexicalEnv().IsTaggedArray()); - EXPECT_TRUE(sFunc->GetHomeObject().IsJSSharedObject()); - JSHandle sObj(thread, sFunc->GetHomeObject()); + EXPECT_FALSE(sFunc->GetProtoOrHClass(thread).IsHole()); + EXPECT_TRUE(sFunc->GetLexicalEnv(thread).IsTaggedArray()); + EXPECT_TRUE(sFunc->GetHomeObject(thread).IsJSSharedObject()); + JSHandle sObj(thread, sFunc->GetHomeObject(thread)); Destroy(); } @@ -938,7 +938,7 @@ public: JSHandle arrBuf = JSHandle::Cast(res); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 5); // 5: bufferLength - JSHandle nativePtr(thread, arrBuf->GetArrayBufferData()); + JSHandle nativePtr(thread, arrBuf->GetArrayBufferData(thread)); EXPECT_TRUE(nativePtr->IsJSNativePointer()) << "[NotJSNativePointer] Deserialize TransferJSArrayBuffer1 fail"; JSHandle np = JSHandle::Cast(nativePtr); uintptr_t bufferAddr = reinterpret_cast(np->GetExternalPointer()); @@ -959,7 +959,7 @@ public: JSHandle arrBuf = JSHandle::Cast(res); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 5); // 5: bufferLength - JSHandle nativePtr(thread, arrBuf->GetArrayBufferData()); + JSHandle nativePtr(thread, arrBuf->GetArrayBufferData(thread)); EXPECT_TRUE(nativePtr->IsJSNativePointer()) << "[NotJSNativePointer] Deserialize TransferJSArrayBuffer2 fail"; JSHandle np = JSHandle::Cast(nativePtr); uintptr_t bufferAddr = reinterpret_cast(np->GetExternalPointer()); @@ -981,7 +981,7 @@ public: JSHandle arrBuf = JSHandle::Cast(res); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 0); - JSHandle nativePtr(thread, arrBuf->GetArrayBufferData()); + JSHandle nativePtr(thread, arrBuf->GetArrayBufferData(thread)); EXPECT_TRUE(nativePtr->IsUndefined()) << "[NotJSNativePointer] Deserialize TransferJSArrayBuffer3 fail"; Destroy(); } @@ -999,7 +999,7 @@ public: JSHandle arrBuf = JSHandle::Cast(res); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 5); // 5: bufferLength - JSHandle nativePtr(thread, arrBuf->GetArrayBufferData()); + JSHandle nativePtr(thread, arrBuf->GetArrayBufferData(thread)); EXPECT_TRUE(reinterpret_cast(nativePtr->GetTaggedObject())->GetDeleter()); Destroy(); } @@ -1874,10 +1874,10 @@ HWTEST_F_L0(JSSerializerTest, SerializeObjectWithConcurrentFunction) JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle concurrentFunction1 = factory->NewJSFunction(env, nullptr, FunctionKind::CONCURRENT_FUNCTION); EXPECT_TRUE(concurrentFunction1->IsJSFunction()); - EXPECT_TRUE(concurrentFunction1->GetFunctionKind() == ecmascript::FunctionKind::CONCURRENT_FUNCTION); + EXPECT_TRUE(concurrentFunction1->GetFunctionKind(thread) == ecmascript::FunctionKind::CONCURRENT_FUNCTION); JSHandle concurrentFunction2 = factory->NewJSFunction(env, nullptr, FunctionKind::CONCURRENT_FUNCTION); EXPECT_TRUE(concurrentFunction2->IsJSFunction()); - EXPECT_TRUE(concurrentFunction2->GetFunctionKind() == ecmascript::FunctionKind::CONCURRENT_FUNCTION); + EXPECT_TRUE(concurrentFunction2->GetFunctionKind(thread) == ecmascript::FunctionKind::CONCURRENT_FUNCTION); JSHandle key1(factory->NewFromASCII("1")); JSHandle key2(factory->NewFromASCII("2")); JSHandle key3(factory->NewFromASCII("abc")); @@ -1964,7 +1964,7 @@ HWTEST_F_L0(JSSerializerTest, TransferJSArrayBuffer1) t1.join(); delete serializer; // test if detached - EXPECT_TRUE(arrBuf->IsDetach()); + EXPECT_TRUE(arrBuf->IsDetach(thread)); }; // Test serialize JSArrayBuffer that not transfer @@ -1999,7 +1999,7 @@ HWTEST_F_L0(JSSerializerTest, TransferJSArrayBuffer2) t1.join(); delete serializer; // test if detached - EXPECT_FALSE(arrBuf->IsDetach()); + EXPECT_FALSE(arrBuf->IsDetach(thread)); }; // Test serialize an empty JSArrayBuffer @@ -2023,7 +2023,7 @@ HWTEST_F_L0(JSSerializerTest, TransferJSArrayBuffer3) t1.join(); delete serializer; // test if detached - EXPECT_FALSE(arrBuf->IsDetach()); + EXPECT_FALSE(arrBuf->IsDetach(thread)); }; // Test serialize JSArrayBuffer with external native buffer that not transfer @@ -2076,7 +2076,7 @@ HWTEST_F_L0(JSSerializerTest, TransferJSArrayBuffer5) JSHandle(thread, JSTaggedValue::Undefined()), JSHandle(thread, JSTaggedValue::Undefined())); EXPECT_TRUE(res) << "serialize JSArrayBuffer with external pointer fail"; - EXPECT_TRUE(arrBuf->IsDetach()); + EXPECT_TRUE(arrBuf->IsDetach(thread)); std::unique_ptr data = serializer->Release(); JSDeserializerTest jsDeserializerTest; std::thread t1(&JSDeserializerTest::TransferJSArrayBufferTest5, jsDeserializerTest, data.release()); @@ -2129,7 +2129,7 @@ HWTEST_F_L0(JSSerializerTest, SerializeJSArrayBufferShared2) int msgBufferLen = static_cast(msg.length()) + 1; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle jsArrayBuffer = factory->NewJSSharedArrayBuffer(msgBufferLen); - JSHandle BufferData(thread, jsArrayBuffer->GetArrayBufferData()); + JSHandle BufferData(thread, jsArrayBuffer->GetArrayBufferData(thread)); JSHandle resNp = JSHandle::Cast(BufferData); void *buffer = resNp->GetExternalPointer(); if (memcpy_s(buffer, msgBufferLen, msg.c_str(), msgBufferLen) != EOK) { @@ -2158,7 +2158,7 @@ HWTEST_F_L0(JSSerializerTest, SerializeJSArrayBufferShared3) int msgBufferLen = static_cast(msg.length()) + 1; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle jsArrayBuffer = factory->NewJSSharedArrayBuffer(msgBufferLen); - JSHandle BufferData(thread, jsArrayBuffer->GetArrayBufferData()); + JSHandle BufferData(thread, jsArrayBuffer->GetArrayBufferData(thread)); JSHandle resNp = JSHandle::Cast(BufferData); void *buffer = resNp->GetExternalPointer(); if (memcpy_s(buffer, msgBufferLen, msg.c_str(), msgBufferLen) != EOK) { diff --git a/ecmascript/serializer/value_serializer.cpp b/ecmascript/serializer/value_serializer.cpp index 78211afa86..63b7493f9b 100644 --- a/ecmascript/serializer/value_serializer.cpp +++ b/ecmascript/serializer/value_serializer.cpp @@ -239,7 +239,7 @@ void ValueSerializer::SerializeObjectImpl(TaggedObject *object, bool isWeak) } case JSType::JS_ARRAY: { JSArray *array = reinterpret_cast(object); - trackInfo = array->GetTrackInfo(); + trackInfo = array->GetTrackInfo(thread_); array->SetTrackInfo(thread_, JSTaggedValue::Undefined()); break; } @@ -249,7 +249,7 @@ void ValueSerializer::SerializeObjectImpl(TaggedObject *object, bool isWeak) break; } case JSType::JS_OBJECT: { - hashfield = Barriers::GetTaggedValue(object, JSObject::HASH_OFFSET); + hashfield = Barriers::GetTaggedValue(thread_, object, JSObject::HASH_OFFSET); Barriers::SetPrimitive(object, JSObject::HASH_OFFSET, JSTaggedValue::VALUE_ZERO); break; } @@ -352,7 +352,7 @@ bool ValueSerializer::SerializeJSArrayBufferPrologue(TaggedObject *object) { ASSERT(object->GetClass()->IsArrayBuffer()); JSArrayBuffer *arrayBuffer = reinterpret_cast(object); - if (arrayBuffer->IsDetach()) { + if (arrayBuffer->IsDetach(thread_)) { std::string errorMessage = "Serialize don't support detached array buffer"; PrintAndRecordErrorMessage(errorMessage); notSupport_ = true; @@ -383,7 +383,7 @@ bool ValueSerializer::SerializeJSArrayBufferPrologue(TaggedObject *object) data_->WriteEncodeFlag(EncodeFlag::ARRAY_BUFFER); data_->WriteUint32(arrayLength); JSNativePointer *np = - reinterpret_cast(arrayBuffer->GetArrayBufferData().GetTaggedObject()); + reinterpret_cast(arrayBuffer->GetArrayBufferData(thread_).GetTaggedObject()); data_->WriteRawData(static_cast(np->GetExternalPointer()), arrayLength); return false; } else { @@ -399,7 +399,7 @@ void ValueSerializer::SerializeJSSharedArrayBufferPrologue(TaggedObject *object) ASSERT(object->GetClass()->IsSharedArrayBuffer()); JSArrayBuffer *arrayBuffer = reinterpret_cast(object); bool transfer = transferDataSet_.find(ToUintPtr(object)) != transferDataSet_.end(); - if (arrayBuffer->IsDetach() || transfer) { + if (arrayBuffer->IsDetach(thread_) || transfer) { std::string errorMessage = "Serialize don't support detached or transfer shared array buffer"; PrintAndRecordErrorMessage(errorMessage); notSupport_ = true; @@ -407,7 +407,8 @@ void ValueSerializer::SerializeJSSharedArrayBufferPrologue(TaggedObject *object) } size_t arrayLength = arrayBuffer->GetArrayBufferByteLength(); if (arrayLength > 0) { - JSNativePointer *np = reinterpret_cast(arrayBuffer->GetArrayBufferData().GetTaggedObject()); + JSNativePointer *np = + reinterpret_cast(arrayBuffer->GetArrayBufferData(thread_).GetTaggedObject()); void *buffer = np->GetExternalPointer(); if (JSSharedMemoryManager::GetInstance()->CreateOrLoad(&buffer, arrayLength)) { std::string errorMessage = "Serialize can't find buffer from shared memory pool"; @@ -424,7 +425,7 @@ void ValueSerializer::SerializeJSSendableArrayBufferPrologue(TaggedObject *objec { ASSERT(object->GetClass()->IsSendableArrayBuffer()); JSSendableArrayBuffer *arrayBuffer = reinterpret_cast(object); - if (arrayBuffer->IsDetach()) { + if (arrayBuffer->IsDetach(thread_)) { std::string errorMessage = "Serialize don't support serialize detached sendable array buffer"; PrintAndRecordErrorMessage(errorMessage); notSupport_ = true; @@ -442,7 +443,7 @@ void ValueSerializer::SerializeJSSendableArrayBufferPrologue(TaggedObject *objec data_->WriteEncodeFlag(EncodeFlag::SENDABLE_ARRAY_BUFFER); data_->WriteUint32(arrayLength); JSNativePointer *np = - reinterpret_cast(arrayBuffer->GetArrayBufferData().GetTaggedObject()); + reinterpret_cast(arrayBuffer->GetArrayBufferData(thread_).GetTaggedObject()); data_->WriteRawData(static_cast(np->GetExternalPointer()), arrayLength); } } @@ -460,7 +461,7 @@ void ValueSerializer::SerializeJSRegExpPrologue(JSRegExp *jsRegExp) data_->WriteEncodeFlag(EncodeFlag::JS_REG_EXP); data_->WriteUint32(bufferSize); JSNativePointer *np = - reinterpret_cast(jsRegExp->GetByteCodeBuffer().GetTaggedObject()); + reinterpret_cast(jsRegExp->GetByteCodeBuffer(thread_).GetTaggedObject()); data_->WriteRawData(static_cast(np->GetExternalPointer()), bufferSize); } diff --git a/ecmascript/shared_object_factory.cpp b/ecmascript/shared_object_factory.cpp index 2ab5eb20d4..ae3659efbe 100644 --- a/ecmascript/shared_object_factory.cpp +++ b/ecmascript/shared_object_factory.cpp @@ -270,7 +270,7 @@ JSHandle ObjectFactory::NewSFunctionByHClass(const JSHandle SetNativePointerToFunctionFromMethod(JSHandle::Cast(function), method); } else if (method->IsAotWithCallField()) { thread_->GetEcmaVM()->GetAOTFileManager()-> - SetAOTFuncEntry(method->GetJSPandaFile(), *function, *method); + SetAOTFuncEntry(method->GetJSPandaFile(thread_), *function, *method); } else { SetCodeEntryToFunctionFromMethod(function, method); } @@ -416,7 +416,7 @@ JSHandle ObjectFactory::CopySArray(const JSHandle &old newArray->SetExtraLength(old->GetExtraLength()); for (uint32_t i = 0; i < newLength; i++) { - newArray->Set(thread_, i, old->Get(i)); + newArray->Set(thread_, i, old->Get(thread_, i)); } #ifdef USE_CMC_GC @@ -447,7 +447,7 @@ JSHandle ObjectFactory::ExtendSArray(const JSHandle &o uint32_t oldLength = old->GetLength(); for (uint32_t i = 0; i < oldLength; i++) { - newArray->Set(thread_, i, old->Get(i)); + newArray->Set(thread_, i, old->Get(thread_, i)); } for (uint32_t i = oldLength; i < length; i++) { newArray->Set(thread_, i, initVal); @@ -534,9 +534,9 @@ JSHandle ObjectFactory::CopyAndReSortSLayoutInfo(const JSHandle ObjectFactory::NewSWellKnownSymbol(const JSHandleSetFlags(0); obj->SetWellKnownSymbol(); obj->SetDescription(thread_, name); - obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, name.GetTaggedValue())); return obj; } @@ -846,7 +846,7 @@ JSHandle ObjectFactory::NewSPublicSymbol(const JSHandle JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetFlags(0); obj->SetDescription(thread_, name); - obj->SetHashField(SymbolTable::Hash(name.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, name.GetTaggedValue())); return obj; } @@ -858,7 +858,7 @@ JSHandle ObjectFactory::NewSConstantPrivateSymbol() JSHandle obj(thread_, JSSymbol::Cast(header)); obj->SetDescription(thread_, JSTaggedValue::Undefined()); obj->SetFlags(0); - obj->SetHashField(SymbolTable::Hash(obj.GetTaggedValue())); + obj->SetHashField(SymbolTable::Hash(thread_, obj.GetTaggedValue())); obj->SetPrivate(); return obj; } diff --git a/ecmascript/shared_objects/js_sendable_arraybuffer.cpp b/ecmascript/shared_objects/js_sendable_arraybuffer.cpp index bfaae59a53..3ce51cef52 100644 --- a/ecmascript/shared_objects/js_sendable_arraybuffer.cpp +++ b/ecmascript/shared_objects/js_sendable_arraybuffer.cpp @@ -60,7 +60,7 @@ void JSSendableArrayBuffer::Attach(JSThread *thread, uint32_t arrayBufferByteLen void JSSendableArrayBuffer::Detach(JSThread *thread, bool transferWithNativeAreaAllocator) { - JSTaggedValue arrayBufferData = GetArrayBufferData(); + JSTaggedValue arrayBufferData = GetArrayBufferData(thread); // already detached. if (arrayBufferData.IsNull()) { return; diff --git a/ecmascript/shared_objects/js_sendable_arraybuffer.h b/ecmascript/shared_objects/js_sendable_arraybuffer.h index 014e970cb4..70e7d60178 100644 --- a/ecmascript/shared_objects/js_sendable_arraybuffer.h +++ b/ecmascript/shared_objects/js_sendable_arraybuffer.h @@ -31,9 +31,9 @@ public: bool transferWithNativeAreaAllocator = false); void Detach(JSThread *thread, bool transferWithNativeAreaAllocator = false); - bool IsDetach() + bool IsDetach(JSThread *thread) { - JSTaggedValue arrayBufferData = GetArrayBufferData(); + JSTaggedValue arrayBufferData = GetArrayBufferData(thread); return arrayBufferData.IsNull(); } diff --git a/ecmascript/shared_objects/js_shared_array.cpp b/ecmascript/shared_objects/js_shared_array.cpp index 3ba5f65ffd..aff316eca0 100644 --- a/ecmascript/shared_objects/js_shared_array.cpp +++ b/ecmascript/shared_objects/js_shared_array.cpp @@ -136,7 +136,7 @@ JSTaggedValue JSSharedArray::ArraySpeciesCreate(JSThread *thread, const JSHandle if (isSArray) { // Let C be Get(originalArray, "constructor"). auto *hclass = originalArray->GetJSHClass(); - JSTaggedValue proto = hclass->GetPrototype(); + JSTaggedValue proto = hclass->GetPrototype(thread); if (hclass->IsJSSharedArray() && !hclass->HasConstructor() && proto.IsJSSharedArray()) { return JSSharedArray::ArrayCreate(thread, length).GetTaggedValue(); } @@ -155,7 +155,7 @@ JSTaggedValue JSSharedArray::ArraySpeciesCreate(JSThread *thread, const JSHandle if (*realmC != *env) { JSTaggedValue realmArrayConstructor = realmC->GetSharedArrayFunction().GetTaggedValue(); // If SameValue(C, realmC.[[intrinsics]].[[%Array%]]) is true, let C be undefined. - if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realmArrayConstructor)) { + if (JSTaggedValue::SameValue(thread, constructor.GetTaggedValue(), realmArrayConstructor)) { return JSSharedArray::ArrayCreate(thread, length).GetTaggedValue(); } } @@ -212,7 +212,7 @@ JSHandle JSSharedArray::SetCapacity(const JSThread *thread, const J void JSSharedArray::SetCapacity(JSThread *thread, const JSHandle &array, uint32_t oldLen, uint32_t newLen, bool isNew) { - TaggedArray *element = TaggedArray::Cast(array->GetElements().GetTaggedObject()); + TaggedArray *element = TaggedArray::Cast(array->GetElements(thread).GetTaggedObject()); if (element->IsDictionaryMode()) { // LCOV_EXCL_START THROW_TYPE_ERROR(thread, "SendableArray don't support dictionary mode."); @@ -319,7 +319,7 @@ bool JSSharedArray::DefineOwnProperty(JSThread *thread, const JSHandle THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); } - if (sCheckMode == SCheckMode::CHECK && !(JSSharedArray::Cast(*array)->IsKeyInRange(key))) { + if (sCheckMode == SCheckMode::CHECK && !(JSSharedArray::Cast(*array)->IsKeyInRange(thread, key))) { auto error = containers::ContainerError::BusinessError(thread, containers::ErrorFlag::RANGE_ERROR, "Key out of length."); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, false); @@ -479,7 +479,7 @@ JSTaggedValue JSSharedArray::Sort(JSThread *thread, const JSHandle item(thread, JSTaggedValue::Undefined()); while (j < itemCount) { - item.Update(sortedList->Get(j)); + item.Update(sortedList->Get(thread, j)); JSSharedArray::FastSetPropertyByValue(thread, obj, j, item); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); ++j; @@ -527,7 +527,7 @@ bool JSSharedArray::IncludeInSortedValue(JSThread *thread, const JSHandle obj) { - JSHandle arr(thread, obj->GetElements()); + JSHandle arr(thread, obj->GetElements(thread)); // Check whether array is shared in the nonmovable space before set properties and elements. // If true, then really copy array in the semi space. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -536,7 +536,7 @@ void JSSharedArray::CheckAndCopyArray(const JSThread *thread, JSHandleSetElements(thread, newArray.GetTaggedValue()); } - JSHandle prop(thread, obj->GetProperties()); + JSHandle prop(thread, obj->GetProperties(thread)); if (prop.GetTaggedValue().IsCOWArray()) { auto newProps = factory->CopyArray(prop, prop->GetLength(), prop->GetLength(), JSTaggedValue::Hole(), MemSpaceType::SHARED_OLD_SPACE); @@ -546,7 +546,7 @@ void JSSharedArray::CheckAndCopyArray(const JSThread *thread, JSHandle &obj) { - JSHandle elements(thread, obj->GetElements()); + JSHandle elements(thread, obj->GetElements(thread)); ASSERT(!obj->GetJSHClass()->IsDictionaryElement()); uint32_t length = elements->GetLength(); // fixme(hzzhouzebin) Optimize Delete later. diff --git a/ecmascript/shared_objects/js_shared_array.h b/ecmascript/shared_objects/js_shared_array.h index 87d90b785b..cf5256444d 100644 --- a/ecmascript/shared_objects/js_shared_array.h +++ b/ecmascript/shared_objects/js_shared_array.h @@ -56,9 +56,9 @@ public: SetLength(length); } - inline uint32_t GetHintLength() const + inline uint32_t GetHintLength(const JSThread *thread) const { - auto trackInfo = GetTrackInfo(); + auto trackInfo = GetTrackInfo(thread); if (trackInfo.IsInt()) { int hint = trackInfo.GetInt(); return hint > 0 ? hint : 0; @@ -71,7 +71,7 @@ public: return index < GetArrayLength(); } - inline bool IsKeyInRange(const JSHandle &key) + inline bool IsKeyInRange(const JSThread *thread, const JSHandle &key) { uint32_t keyValue = 0; if (key->IsInt()) { @@ -79,7 +79,7 @@ public: } if (key->IsString()) { - JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &keyValue); + JSTaggedValue::ToElementIndex(const_cast(thread), key.GetTaggedValue(), &keyValue); } if (key->IsDouble()) { diff --git a/ecmascript/shared_objects/js_shared_array_iterator.cpp b/ecmascript/shared_objects/js_shared_array_iterator.cpp index 501156d0f3..7f34d72074 100644 --- a/ecmascript/shared_objects/js_shared_array_iterator.cpp +++ b/ecmascript/shared_objects/js_shared_array_iterator.cpp @@ -39,7 +39,7 @@ JSTaggedValue JSSharedArrayIterator::Next(EcmaRuntimeCallInfo *argv) // 4.Let a be O.[[IteratedArrayLike]]. JSHandle iter(thisObj); - JSHandle array(thread, iter->GetIteratedArray()); + JSHandle array(thread, iter->GetIteratedArray(thread)); if (array->IsJSSharedArray()) { [[maybe_unused]] ConcurrentApiScope scope(thread, array); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); diff --git a/ecmascript/shared_objects/js_shared_map.cpp b/ecmascript/shared_objects/js_shared_map.cpp index af4dab8bcf..6269ee4fe3 100644 --- a/ecmascript/shared_objects/js_shared_map.cpp +++ b/ecmascript/shared_objects/js_shared_map.cpp @@ -31,7 +31,7 @@ void JSSharedMap::Set(JSThread *thread, const JSHandle &map, JSHandle::Cast(map)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); JSHandle newMap = LinkedHashMap::Set(thread, mapHandle, key, value); map->SetLinkedMap(thread, newMap); } @@ -41,7 +41,7 @@ bool JSSharedMap::Delete(JSThread *thread, const JSHandle &map, con [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(map)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); int entry = mapHandle->FindElement(thread, key.GetTaggedValue()); if (entry == -1) { return false; @@ -55,7 +55,7 @@ void JSSharedMap::Clear(JSThread *thread, const JSHandle &map) [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(map)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle(thread, LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())); JSHandle newMap = LinkedHashMap::Clear(thread, mapHandle); map->SetLinkedMap(thread, newMap); } @@ -64,21 +64,21 @@ bool JSSharedMap::Has(JSThread *thread, const JSHandle &map, JSTagg { [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(map)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->Has(thread, key); + return LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->Has(thread, key); } JSTaggedValue JSSharedMap::Get(JSThread *thread, const JSHandle &map, JSTaggedValue key) { [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(map)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); - return LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->Get(thread, key); + return LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->Get(thread, key); } uint32_t JSSharedMap::GetSize(JSThread *thread, const JSHandle &map) { [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(map)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - return LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->NumberOfElements(); + return LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->NumberOfElements(); } JSTaggedValue JSSharedMap::GetKey(JSThread *thread, const JSHandle &map, uint32_t entry) @@ -86,7 +86,7 @@ JSTaggedValue JSSharedMap::GetKey(JSThread *thread, const JSHandle [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(map)); ASSERT_PRINT(entry >= 0 && entry < GetSize(thread, map), "entry must be non-negative integer less than capacity"); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); - return LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->GetKey(entry); + return LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->GetKey(thread, entry); } JSTaggedValue JSSharedMap::GetValue(JSThread *thread, const JSHandle &map, uint32_t entry) @@ -94,6 +94,6 @@ JSTaggedValue JSSharedMap::GetValue(JSThread *thread, const JSHandle scope(thread, JSHandle::Cast(map)); ASSERT_PRINT(entry >= 0 && entry < GetSize(thread, map), "entry must be non-negative integer less than capacity"); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); - return LinkedHashMap::Cast(map->GetLinkedMap().GetTaggedObject())->GetValue(entry); + return LinkedHashMap::Cast(map->GetLinkedMap(thread).GetTaggedObject())->GetValue(thread, entry); } } // namespace panda::ecmascript diff --git a/ecmascript/shared_objects/js_shared_map_iterator.cpp b/ecmascript/shared_objects/js_shared_map_iterator.cpp index f91ea47b97..099012627d 100644 --- a/ecmascript/shared_objects/js_shared_map_iterator.cpp +++ b/ecmascript/shared_objects/js_shared_map_iterator.cpp @@ -38,13 +38,13 @@ JSTaggedValue JSSharedMapIterator::NextInternal(JSThread *thread, JSHandle iter(thisObj); JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); - if (iter->GetIteratedMap().IsUndefined()) { + if (iter->GetIteratedMap(thread).IsUndefined()) { return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } - JSHandle iteratedMap(thread, iter->GetIteratedMap()); + JSHandle iteratedMap(thread, iter->GetIteratedMap(thread)); [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(iteratedMap)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - JSHandle map(thread, iteratedMap->GetLinkedMap()); + JSHandle map(thread, iteratedMap->GetLinkedMap(thread)); int index = static_cast(iter->GetNextIndex()); IterationKind itemKind = iter->GetIterationKind(); @@ -53,14 +53,14 @@ JSTaggedValue JSSharedMapIterator::NextInternal(JSThread *thread, JSHandle keyHandle(thread, JSTaggedValue::Undefined()); while (index < totalElements) { - JSTaggedValue key = map->GetKey(index); + JSTaggedValue key = map->GetKey(thread, index); if (!key.IsHole()) { iter->SetNextIndex(index + 1); keyHandle.Update(key); if (itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, keyHandle, false).GetTaggedValue(); } - JSHandle value(thread, map->GetValue(index)); + JSHandle value(thread, map->GetValue(thread, index)); if (itemKind == IterationKind::VALUE) { return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } diff --git a/ecmascript/shared_objects/js_shared_set.cpp b/ecmascript/shared_objects/js_shared_set.cpp index bce8cde0c1..af99a52c9b 100755 --- a/ecmascript/shared_objects/js_shared_set.cpp +++ b/ecmascript/shared_objects/js_shared_set.cpp @@ -30,7 +30,7 @@ void JSSharedSet::Add(JSThread *thread, const JSHandle &set, const JSHandle::Cast(set)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())); JSHandle newSet = LinkedHashSet::Add(thread, setHandle, value); set->SetLinkedSet(thread, newSet); } @@ -40,7 +40,7 @@ bool JSSharedSet::Delete(JSThread *thread, const JSHandle &set, con [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(set)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())); int entry = setHandle->FindElement(thread, value.GetTaggedValue()); if (entry == -1) { return false; @@ -54,7 +54,7 @@ void JSSharedSet::Clear(JSThread *thread, const JSHandle &set) [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(set)); RETURN_IF_ABRUPT_COMPLETION(thread); - JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle(thread, LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())); JSHandle newSet = LinkedHashSet::Clear(thread, setHandle); set->SetLinkedSet(thread, newSet); } @@ -63,14 +63,14 @@ bool JSSharedSet::Has(JSThread *thread, const JSHandle &set, JSTagg { [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(set)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())->Has(thread, value); + return LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())->Has(thread, value); } uint32_t JSSharedSet::GetSize(JSThread *thread, const JSHandle &set) { [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(set)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - return LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())->NumberOfElements(); + return LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())->NumberOfElements(); } JSTaggedValue JSSharedSet::GetValue(JSThread *thread, const JSHandle &set, int entry) @@ -79,6 +79,6 @@ JSTaggedValue JSSharedSet::GetValue(JSThread *thread, const JSHandle= 0 && static_cast(entry) < GetSize(thread, set), "entry must be non-negative integer less than capacity"); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); - return LinkedHashSet::Cast(set->GetLinkedSet().GetTaggedObject())->GetValue(entry); + return LinkedHashSet::Cast(set->GetLinkedSet(thread).GetTaggedObject())->GetValue(thread, entry); } } // namespace panda::ecmascript diff --git a/ecmascript/shared_objects/js_shared_set_iterator.cpp b/ecmascript/shared_objects/js_shared_set_iterator.cpp index a4403fec41..544f98b373 100755 --- a/ecmascript/shared_objects/js_shared_set_iterator.cpp +++ b/ecmascript/shared_objects/js_shared_set_iterator.cpp @@ -37,22 +37,22 @@ JSTaggedValue JSSharedSetIterator::NextInternal(JSThread *thread, JSHandle iter(thisObj); JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); - if (iter->GetIteratedSet().IsUndefined()) { + if (iter->GetIteratedSet(thread).IsUndefined()) { return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); } - JSHandle iteratedSet(thread, iter->GetIteratedSet()); + JSHandle iteratedSet(thread, iter->GetIteratedSet(thread)); [[maybe_unused]] ConcurrentApiScope scope(thread, JSHandle::Cast(iteratedSet)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - JSHandle set(thread, iteratedSet->GetLinkedSet()); + JSHandle set(thread, iteratedSet->GetLinkedSet(thread)); int index = static_cast(iter->GetNextIndex()); IterationKind itemKind = iter->GetIterationKind(); int totalElements = set->NumberOfElements() + set->NumberOfDeletedElements(); while (index < totalElements) { - if (!set->GetKey(index).IsHole()) { + if (!set->GetKey(thread, index).IsHole()) { iter->SetNextIndex(index + 1); - JSHandle key(thread, set->GetKey(index)); + JSHandle key(thread, set->GetKey(thread, index)); if (itemKind == IterationKind::VALUE || itemKind == IterationKind::KEY) { return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); } diff --git a/ecmascript/snapshot/mem/snapshot_processor.cpp b/ecmascript/snapshot/mem/snapshot_processor.cpp index 2251f9a48c..86381ff756 100644 --- a/ecmascript/snapshot/mem/snapshot_processor.cpp +++ b/ecmascript/snapshot/mem/snapshot_processor.cpp @@ -1313,7 +1313,7 @@ void SnapshotProcessor::DeserializeString(uintptr_t stringBegin, uintptr_t strin size_t strSize = EcmaStringAccessor(str).ObjectSize(); strSize = AlignUp(strSize, static_cast(MemAlignment::MEM_ALIGN_OBJECT)); { - auto hashcode = EcmaStringAccessor(str).GetHashcode(); + auto hashcode = EcmaStringAccessor(str).GetHashcode(thread); #if ENABLE_NEXT_OPTIMIZATION EcmaString *strFromTable = stringTable->GetOrInternString( vm_, hashcode, @@ -1343,16 +1343,16 @@ void SnapshotProcessor::DeserializeString(uintptr_t stringBegin, uintptr_t strin JSHandle stringHandle(thread, value); return stringHandle; }, - [str](EcmaString *foundString) { + [str, thread](EcmaString *foundString) { ASSERT(EcmaStringAccessor(str).NotTreeString()); - return EcmaStringAccessor::StringsAreEqual(foundString, str); + return EcmaStringAccessor::StringsAreEqual(thread, foundString, str); }); ASSERT(strFromTable != nullptr); deserializeStringVector_.emplace_back(thread, strFromTable); #else RuntimeLockHolder locker(thread, stringTable->stringTable_[EcmaStringTable::GetTableId(hashcode)].mutex_); - auto strFromTable = stringTable->GetStringThreadUnsafe(str, hashcode); + auto strFromTable = stringTable->GetStringThreadUnsafe(thread, str, hashcode); if (strFromTable) { deserializeStringVector_.emplace_back(thread, strFromTable); } else { @@ -1371,7 +1371,7 @@ void SnapshotProcessor::DeserializeString(uintptr_t stringBegin, uintptr_t strin UNREACHABLE(); } str = reinterpret_cast(newObj); - stringTable->InsertStringToTableWithHashThreadUnsafe(str, hashcode); + stringTable->InsertStringToTableWithHashThreadUnsafe(thread, str, hashcode); deserializeStringVector_.emplace_back(thread, str); } #endif @@ -1497,13 +1497,14 @@ void SnapshotProcessor::SerializeObject(TaggedObject *objectHeader, CQueueGetJSThread(); if (area != VisitObjectArea::IN_OBJECT) { return false; } auto hclass = root->GetClass(); ASSERT(!hclass->IsAllTaggedProp()); - auto layout = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - auto attr = layout->GetAttr(index++); + auto layout = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + auto attr = layout->GetAttr(thread, index++); if (attr.GetRepresentation() == Representation::DOUBLE) { auto fieldAddr = reinterpret_cast(slot.SlotAddress()); SetObjectEncodeField(obj, slot.SlotAddress() - ToUintPtr(root), diff --git a/ecmascript/snapshot/tests/snapshot_test.cpp b/ecmascript/snapshot/tests/snapshot_test.cpp index da130c0ca1..1fdb07c176 100644 --- a/ecmascript/snapshot/tests/snapshot_test.cpp +++ b/ecmascript/snapshot/tests/snapshot_test.cpp @@ -141,23 +141,23 @@ HWTEST_F_L0(SnapshotTest, SerializeConstPool) auto constpool1 = reinterpret_cast(beginRegion->GetBegin()); EXPECT_EQ((*constpool)->GetSize(), constpool1->GetSize()); - EXPECT_TRUE(constpool1->GetObjectFromCache(0).IsJSFunction()); - EXPECT_TRUE(constpool1->GetObjectFromCache(1).IsJSFunction()); - EXPECT_TRUE(constpool1->GetObjectFromCache(3).IsJSFunction()); - EcmaString *str11 = reinterpret_cast(constpool1->Get(2).GetTaggedObject()); - EcmaString *str22 = reinterpret_cast(constpool1->Get(4).GetTaggedObject()); - EcmaString *str33 = reinterpret_cast(constpool1->Get(5).GetTaggedObject()); - EcmaString *str44 = reinterpret_cast(constpool1->Get(6).GetTaggedObject()); - EcmaString *str55 = reinterpret_cast(constpool1->Get(7).GetTaggedObject()); - EcmaString *str66 = reinterpret_cast(constpool1->Get(8).GetTaggedObject()); - EcmaString *str77 = reinterpret_cast(constpool1->Get(9).GetTaggedObject()); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str11).ToCString().c_str(), "str11"), 0); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str22).ToCString().c_str(), "str22"), 0); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str33).ToCString().c_str(), "str11"), 0); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str44).ToCString().c_str(), "str333333333333"), 0); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str55).ToCString().c_str(), "str11str333333333333"), 0); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str66).ToCString().c_str(), "str11str333333333333"), 0); - EXPECT_EQ(std::strcmp(EcmaStringAccessor(str77).ToCString().c_str(), "str44"), 0); + EXPECT_TRUE(constpool1->GetObjectFromCache(thread, 0).IsJSFunction()); + EXPECT_TRUE(constpool1->GetObjectFromCache(thread, 1).IsJSFunction()); + EXPECT_TRUE(constpool1->GetObjectFromCache(thread, 3).IsJSFunction()); + EcmaString *str11 = reinterpret_cast(constpool1->Get(thread, 2).GetTaggedObject()); + EcmaString *str22 = reinterpret_cast(constpool1->Get(thread, 4).GetTaggedObject()); + EcmaString *str33 = reinterpret_cast(constpool1->Get(thread, 5).GetTaggedObject()); + EcmaString *str44 = reinterpret_cast(constpool1->Get(thread, 6).GetTaggedObject()); + EcmaString *str55 = reinterpret_cast(constpool1->Get(thread, 7).GetTaggedObject()); + EcmaString *str66 = reinterpret_cast(constpool1->Get(thread, 8).GetTaggedObject()); + EcmaString *str77 = reinterpret_cast(constpool1->Get(thread, 9).GetTaggedObject()); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str11).ToCString(thread).c_str(), "str11"), 0); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str22).ToCString(thread).c_str(), "str22"), 0); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str33).ToCString(thread).c_str(), "str11"), 0); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str44).ToCString(thread).c_str(), "str333333333333"), 0); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str55).ToCString(thread).c_str(), "str11str333333333333"), 0); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str66).ToCString(thread).c_str(), "str11str333333333333"), 0); + EXPECT_EQ(std::strcmp(EcmaStringAccessor(str77).ToCString(thread).c_str(), "str44"), 0); std::remove(fileName.c_str()); } @@ -190,13 +190,13 @@ HWTEST_F_L0(SnapshotTest, SerializeDifferentSpace) auto constpool1 = reinterpret_cast(beginRegion->GetBegin()); EXPECT_EQ((*constpool)->GetSize(), constpool1->GetSize()); - EXPECT_TRUE(constpool1->GetObjectFromCache(0).IsTaggedArray()); - EXPECT_TRUE(constpool1->GetObjectFromCache(100).IsTaggedArray()); - EXPECT_TRUE(constpool1->GetObjectFromCache(300).IsTaggedArray()); + EXPECT_TRUE(constpool1->GetObjectFromCache(thread, 0).IsTaggedArray()); + EXPECT_TRUE(constpool1->GetObjectFromCache(thread, 100).IsTaggedArray()); + EXPECT_TRUE(constpool1->GetObjectFromCache(thread, 300).IsTaggedArray()); - auto obj1 = constpool1->GetObjectFromCache(0).GetTaggedObject(); + auto obj1 = constpool1->GetObjectFromCache(thread, 0).GetTaggedObject(); EXPECT_TRUE(Region::ObjectAddressToRange(obj1)->InOldSpace()); - auto obj2 = constpool1->GetObjectFromCache(100).GetTaggedObject(); + auto obj2 = constpool1->GetObjectFromCache(thread, 100).GetTaggedObject(); EXPECT_TRUE(Region::ObjectAddressToRange(obj2)->InOldSpace()); std::remove(fileName.c_str()); } @@ -235,11 +235,11 @@ HWTEST_F_L0(SnapshotTest, SerializeMultiFile) auto beginRegion = const_cast(ecmaVm->GetHeap())->GetOldSpace()->GetCurrentRegion(); auto constpool = reinterpret_cast(beginRegion->GetBegin()); - EXPECT_TRUE(constpool->GetObjectFromCache(0).IsTaggedArray()); - EXPECT_TRUE(constpool->GetObjectFromCache(100).IsTaggedArray()); - auto obj1 = constpool->GetObjectFromCache(0).GetTaggedObject(); + EXPECT_TRUE(constpool->GetObjectFromCache(thread, 0).IsTaggedArray()); + EXPECT_TRUE(constpool->GetObjectFromCache(thread, 100).IsTaggedArray()); + auto obj1 = constpool->GetObjectFromCache(thread, 0).GetTaggedObject(); EXPECT_TRUE(Region::ObjectAddressToRange(obj1)->InOldSpace()); - auto obj2 = constpool->GetObjectFromCache(100).GetTaggedObject(); + auto obj2 = constpool->GetObjectFromCache(thread, 100).GetTaggedObject(); EXPECT_TRUE(Region::ObjectAddressToRange(obj2)->InOldSpace()); std::remove(fileName1.c_str()); std::remove(fileName2.c_str()); @@ -337,10 +337,10 @@ HWTEST_F_L0(SnapshotTest, SerializeHugeObject) auto lastRegion = const_cast(ecmaVm->GetHeap())->GetHugeObjectSpace()->GetCurrentRegion(); auto array4 = reinterpret_cast(lastRegion->GetBegin()); - EXPECT_TRUE(array4->Get(0).IsTaggedArray()); - EXPECT_TRUE(array4->Get(1).IsJSFunction()); - EXPECT_TRUE(array4->Get(2).IsJSFunction()); - EXPECT_TRUE(array4->Get(3).IsJSFunction()); + EXPECT_TRUE(array4->Get(thread, 0).IsTaggedArray()); + EXPECT_TRUE(array4->Get(thread, 1).IsJSFunction()); + EXPECT_TRUE(array4->Get(thread, 2).IsJSFunction()); + EXPECT_TRUE(array4->Get(thread, 3).IsJSFunction()); std::remove(fileName.c_str()); } diff --git a/ecmascript/stubs/runtime_optimized_stubs-inl.h b/ecmascript/stubs/runtime_optimized_stubs-inl.h index 9c2ce3cf59..ea5b273eb9 100644 --- a/ecmascript/stubs/runtime_optimized_stubs-inl.h +++ b/ecmascript/stubs/runtime_optimized_stubs-inl.h @@ -43,14 +43,14 @@ JSTaggedValue RuntimeStubs::DecodePercentEncoding(JSThread *thread, int32_t &n, // c. If the code units at index (k +1) and (k + 2) within string do not represent hexadecimal // digits, throw a URIError exception. if (!(codeUnit == '%')) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint16_t frontChart = GetCodeUnit(sp, k + 1, strLen); uint16_t behindChart = GetCodeUnit(sp, k + 2, strLen); // 2: means plus 2 if (!(base::utf_helper::IsHexDigits(frontChart) && base::utf_helper::IsHexDigits(behindChart))) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } #if !ENABLE_NEXT_OPTIMIZATION @@ -60,7 +60,7 @@ JSTaggedValue RuntimeStubs::DecodePercentEncoding(JSThread *thread, int32_t &n, #endif // e. If the two most significant bits in B are not 10, throw a URIError exception. if (!((bb & base::utf_helper::BIT_MASK_2) == base::utf_helper::BIT_MASK_1)) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } k += 2; // 2: means plus 2 @@ -74,7 +74,7 @@ JSTaggedValue RuntimeStubs::UTF16EncodeCodePoint(JSThread *thread, const std::ve const JSHandle &str, std::u16string &resStr) { if (!base::utf_helper::IsValidUTF8(oct)) { - CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + CString errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint32_t vv = base::StringHelper::Utf8ToU32String(oct); @@ -114,13 +114,13 @@ JSTaggedValue RuntimeStubs::DecodePercentEncoding(JSThread *thread, const JSHand // iii. If the code units at index (k+1) and (k + 2) within string do not represent hexadecimal digits, // throw a URIError exception. if ((k + 2) >= strLen) { // 2: means plus 2 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } uint16_t frontChar = GetCodeUnit(sp, k + 1, strLen); uint16_t behindChar = GetCodeUnit(sp, k + 2, strLen); // 2: means plus 2 if (!(base::utf_helper::IsHexDigits(frontChar) && base::utf_helper::IsHexDigits(behindChar))) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } #if !ENABLE_NEXT_OPTIMIZATION @@ -166,7 +166,7 @@ JSTaggedValue RuntimeStubs::DecodePercentEncoding(JSThread *thread, const JSHand } // 2. If n equals 1 or n is greater than 4, throw a URIError exception. if ((n == 1) || (n > 4)) { - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } @@ -174,7 +174,7 @@ JSTaggedValue RuntimeStubs::DecodePercentEncoding(JSThread *thread, const JSHand // 5. If k + (3 × (n – 1)) is greater than or equal to strLen, throw a URIError exception. if (k + (3 * (n - 1)) >= strLen) { // 3: means multiply by 3 - errorMsg = "DecodeURI: invalid character: " + ConvertToString(str.GetTaggedValue()); + errorMsg = "DecodeURI: invalid character: " + ConvertToString(thread, str.GetTaggedValue()); THROW_URI_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception()); } DecodePercentEncoding(thread, n, k, str, bb, oct, sp, strLen); diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index b413ae9919..5f391f03b7 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -242,7 +242,7 @@ JSTaggedValue RuntimeStubs::RuntimeCloseIterator(JSThread *thread, const JSHandl JSHandle result = JSIterator::IteratorClose(thread, iter, record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (result->IsCompletionRecord()) { - return CompletionRecord::Cast(result->GetTaggedObject())->GetValue(); + return CompletionRecord::Cast(result->GetTaggedObject())->GetValue(thread); } return result.GetTaggedValue(); } @@ -375,17 +375,17 @@ JSTaggedValue RuntimeStubs::RuntimeAsyncFunctionAwaitUncaught(JSThread *thread, JSHandle obj = JSTaggedValue::ToObject(thread, asyncFuncObj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle generator = JSHandle::Cast(obj); - JSHandle queue(thread, generator->GetAsyncGeneratorQueue()); - if (queue->Empty()) { + JSHandle queue(thread, generator->GetAsyncGeneratorQueue(thread)); + if (queue->Empty(thread)) { return JSTaggedValue::Undefined(); } - JSHandle next(thread, queue->Front()); - JSHandle completion(thread, next->GetCapability()); - JSHandle promise(thread, completion->GetPromise()); + JSHandle next(thread, queue->Front(thread)); + JSHandle completion(thread, next->GetCapability(thread)); + JSHandle promise(thread, completion->GetPromise(thread)); return promise.GetTaggedValue(); } JSHandle asyncFuncObjHandle(asyncFuncObj); - JSHandle promise(thread, asyncFuncObjHandle->GetPromise()); + JSHandle promise(thread, asyncFuncObjHandle->GetPromise(thread)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return promise.GetTaggedValue(); @@ -395,7 +395,7 @@ JSTaggedValue RuntimeStubs::RuntimeAsyncFunctionResolveOrReject(JSThread *thread const JSHandle &asyncFuncObj, const JSHandle &value, bool is_resolve) { JSHandle asyncFuncObjHandle(asyncFuncObj); - JSHandle promise(thread, asyncFuncObjHandle->GetPromise()); + JSHandle promise(thread, asyncFuncObjHandle->GetPromise(thread)); if (thread->GetEcmaVM()->GetJSOptions().EnablePendingCheak()) { thread->GetEcmaVM()->RemoveAsyncStackTrace(promise); @@ -406,9 +406,9 @@ JSTaggedValue RuntimeStubs::RuntimeAsyncFunctionResolveOrReject(JSThread *thread JSHandle thisArg = globalConst->GetHandledUndefined(); JSHandle activeFunc; if (is_resolve) { - activeFunc = JSHandle(thread, reactions->GetResolveFunction()); + activeFunc = JSHandle(thread, reactions->GetResolveFunction(thread)); } else { - activeFunc = JSHandle(thread, reactions->GetRejectFunction()); + activeFunc = JSHandle(thread, reactions->GetRejectFunction(thread)); } JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, activeFunc, thisArg, undefined, 1); @@ -427,7 +427,7 @@ JSTaggedValue RuntimeStubs::RuntimeAsyncGeneratorResolve(JSThread *thread, JSHan JSHandle asyncGeneratorObjHandle(asyncFuncObj); JSHandle valueHandle(value); - JSHandle genContextHandle(thread, asyncGeneratorObjHandle->GetGeneratorContext()); + JSHandle genContextHandle(thread, asyncGeneratorObjHandle->GetGeneratorContext(thread)); // save stack, should copy cur_frame, function execute over will free cur_frame SaveFrameToContext(thread, genContextHandle); @@ -462,7 +462,7 @@ JSTaggedValue RuntimeStubs::RuntimeCopyDataProperties(JSThread *thread, const JS uint32_t keysLen = keys->GetLength(); for (uint32_t i = 0; i < keysLen; i++) { PropertyDescriptor desc(thread); - key.Update(keys->Get(i)); + key.Update(keys->Get(thread, i)); bool success = JSTaggedValue::GetOwnProperty(thread, from, key, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -498,7 +498,7 @@ JSTaggedValue RuntimeStubs::RuntimeStArraySpread(JSThread *thread, const JSHandl uint32_t dstLen = static_cast(index.GetInt()); uint32_t strLen = EcmaStringAccessor(srcFlat).GetLength(); for (uint32_t i = 0; i < strLen; i++) { - uint16_t res = EcmaStringAccessor(srcFlat).Get(i); + uint16_t res = EcmaStringAccessor(srcFlat).Get(thread, i); JSHandle strValue(factory->NewFromUtf16Literal(&res, 1)); JSTaggedValue::SetProperty(thread, dst, dstLen + i, strValue, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -512,7 +512,7 @@ JSTaggedValue RuntimeStubs::RuntimeStArraySpread(JSThread *thread, const JSHandl } if (index.GetInt() == 0 && src->IsStableJSArray(thread)) { - JSHandle srcElements(thread, JSHandle::Cast(src)->GetElements()); + JSHandle srcElements(thread, JSHandle::Cast(src)->GetElements(thread)); uint32_t length = JSHandle::Cast(src)->GetArrayLength(); JSHandle dstElements = factory->NewTaggedArray(length); JSHandle dstArray = JSHandle::Cast(dst); @@ -660,7 +660,7 @@ JSTaggedValue RuntimeStubs::RuntimeStOwnByValue(JSThread *thread, const JSHandle const GlobalEnvConstants *globalConst = thread->GlobalConstants(); if (obj->IsClassConstructor() && - JSTaggedValue::SameValue(key, globalConst->GetHandledPrototypeString())) { + JSTaggedValue::SameValue(thread, key, globalConst->GetHandledPrototypeString())) { return RuntimeThrowTypeError(thread, "In a class, static property named 'prototype' throw a TypeError"); } @@ -683,7 +683,7 @@ JSTaggedValue RuntimeStubs::RuntimeLdSuperByValue(JSThread *thread, const JSHand { ASSERT(thisFunc.IsJSFunction()); // get Homeobject form function - JSHandle homeObject(thread, JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject()); + JSHandle homeObject(thread, JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(thread)); JSHandle superBase(thread, JSTaggedValue::GetSuperBase(thread, homeObject)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue::RequireObjectCoercible(thread, superBase); @@ -702,7 +702,7 @@ JSTaggedValue RuntimeStubs::RuntimeStSuperByValue(JSThread *thread, const JSHand { ASSERT(thisFunc.IsJSFunction()); // get Homeobject form function - JSHandle homeObject(thread, JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject()); + JSHandle homeObject(thread, JSFunction::Cast(thisFunc.GetTaggedObject())->GetHomeObject(thread)); JSHandle superBase(thread, JSTaggedValue::GetSuperBase(thread, homeObject)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue::RequireObjectCoercible(thread, superBase); @@ -783,7 +783,7 @@ JSTaggedValue RuntimeStubs::RuntimeStGlobalRecord(JSThread *thread, const JSHand ObjectFactory* factory = thread->GetEcmaVM()->GetFactory(); if (thread->GetEcmaVM()->GetJSOptions().IsEnableLoweringBuiltin()) { BuiltinIndex& builtinIndex = BuiltinIndex::GetInstance(); - auto index = builtinIndex.GetBuiltinIndex(prop.GetTaggedValue()); + auto index = builtinIndex.GetBuiltinIndex(thread, prop.GetTaggedValue()); if (index != BuiltinIndex::NOT_FOUND) { auto box = factory->NewPropertyBox(JSHandle(thread, JSTaggedValue::Hole())); thread->GetBuiltinEntriesPointer()->ClearByIndex(index, box.GetTaggedValue()); @@ -795,7 +795,7 @@ JSTaggedValue RuntimeStubs::RuntimeStGlobalRecord(JSThread *thread, const JSHand GlobalDictionary *dict = GlobalDictionary::Cast(env->GetGlobalRecord()->GetTaggedObject()); // cross files global record name binding judgment - int entry = dict->FindEntry(prop.GetTaggedValue()); + int entry = dict->FindEntry(thread, prop.GetTaggedValue()); if (entry != -1) { return RuntimeThrowSyntaxError(thread, "Duplicate identifier"); } @@ -862,7 +862,7 @@ JSTaggedValue RuntimeStubs::RuntimeResolveClass(JSThread *thread, const JSHandle FrameHandler frameHandler(thread); JSTaggedValue currentFunc = frameHandler.GetFunction(); - JSHandle ecmaModule(thread, JSFunction::Cast(currentFunc.GetTaggedObject())->GetModule()); + JSHandle ecmaModule(thread, JSFunction::Cast(currentFunc.GetTaggedObject())->GetModule(thread)); RuntimeSetClassInheritanceRelationship(thread, JSHandle(ctor), base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -872,7 +872,7 @@ JSTaggedValue RuntimeStubs::RuntimeResolveClass(JSThread *thread, const JSHandle // only traverse the value of key-value pair for (uint32_t index = 1; index < literalBufferLength - 1; index += 2) { // 2: key-value pair - JSTaggedValue value = literal->Get(index); + JSTaggedValue value = literal->Get(thread, index); if (LIKELY(value.IsJSFunction())) { JSFunction *func = JSFunction::Cast(value.GetTaggedObject()); func->SetLexicalEnv(thread, lexenv.GetTaggedValue()); @@ -891,7 +891,7 @@ JSTaggedValue RuntimeStubs::RuntimeCloneClassFromTemplate(JSThread *thread, cons const GlobalEnvConstants *globalConst = thread->GlobalConstants(); ASSERT(ctor.GetTaggedValue().IsClassConstructor()); - JSHandle clsPrototype(thread, ctor->GetFunctionPrototype()); + JSHandle clsPrototype(thread, ctor->GetFunctionPrototype(thread)); bool canShareHClass = false; JSHandle cloneClass = factory->CloneClassCtor(ctor, lexenv, canShareHClass); @@ -941,7 +941,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread, } [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - CString entry = ModuleManager::GetRecordName(module.GetTaggedValue()); + CString entry = ModuleManager::GetRecordName(thread, module.GetTaggedValue()); // For class constructor. auto methodObj = ConstantPool::GetMethodFromCache(thread, constpool.GetTaggedValue(), methodId); @@ -953,7 +953,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread, JSHandle cp(thread, thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpoolHandle.GetTaggedValue())); - JSTaggedValue val = cp->GetObjectFromCache(literalId); + JSTaggedValue val = cp->GetObjectFromCache(thread, literalId); if (val.IsAOTLiteralInfo()) { JSHandle aotLiteralInfo(thread, val); ihc.Update(aotLiteralInfo->GetIhc()); @@ -963,7 +963,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreateClassWithBuffer(JSThread *thread, JSTaggedValue literalObj = ConstantPool::GetClassLiteralFromCache(thread, cp, literalId, entry); JSHandle classLiteral(thread, literalObj); - JSHandle arrayHandle(thread, classLiteral->GetArray()); + JSHandle arrayHandle(thread, classLiteral->GetArray(thread)); JSHandle extractor = factory->NewClassInfoExtractor(method); auto literalLength = arrayHandle->GetLength(); ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, arrayHandle, literalLength); @@ -999,9 +999,9 @@ void RuntimeStubs::SetProfileTypeInfoCellToFunction(JSThread *thread, const JSHa ASSERT(jsFunc->IsJSFunction()); ASSERT(!jsFunc->IsSharedFunction()); - auto profileTypeInfo = jsFunc->GetProfileTypeInfo(); + auto profileTypeInfo = jsFunc->GetProfileTypeInfo(thread); if (profileTypeInfo.IsUndefined()) { - JSHandle method(thread, jsFunc->GetMethod()); + JSHandle method(thread, jsFunc->GetMethod(thread)); uint32_t slotSize = method->GetSlotSize(); profileTypeInfo = RuntimeNotifyInlineCache(thread, jsFunc, slotSize); } @@ -1009,7 +1009,7 @@ void RuntimeStubs::SetProfileTypeInfoCellToFunction(JSThread *thread, const JSHa ASSERT(!profileTypeInfo.IsUndefined()); JSHandle profileTypeArray(thread, profileTypeInfo); - JSTaggedValue slotValue = profileTypeArray->Get(slotId); + JSTaggedValue slotValue = profileTypeArray->Get(thread, slotId); if (slotValue.IsUndefined()) { JSHandle handleUndefined(thread, JSTaggedValue::Undefined()); JSHandle newProfileTypeInfoCell = @@ -1034,7 +1034,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreateSharedClass(JSThread *thread, } [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - CString entry = ModuleManager::GetRecordName(module.GetTaggedValue()); + CString entry = ModuleManager::GetRecordName(thread, module.GetTaggedValue()); auto methodObj = ConstantPool::GetMethodFromCache(thread, constpool.GetTaggedValue(), methodId); JSHandle method(thread, methodObj); @@ -1044,16 +1044,16 @@ JSTaggedValue RuntimeStubs::RuntimeCreateSharedClass(JSThread *thread, JSHandle sendableEnv(thread, JSTaggedValue::Undefined()); if (module->IsSourceTextModule()) { JSHandle moduleRecord = JSHandle::Cast(module); - sendableEnv = JSHandle(thread, moduleRecord->GetSendableEnv()); + sendableEnv = JSHandle(thread, moduleRecord->GetSendableEnv(thread)); } auto literalObj = ConstantPool::GetClassLiteralFromCache( thread, constpoolHandle, literalId, entry, sendableEnv, ClassKind::SENDABLE); JSHandle classLiteral(thread, literalObj); - JSHandle arrayHandle(thread, classLiteral->GetArray()); + JSHandle arrayHandle(thread, classLiteral->GetArray(thread)); auto literalLength = arrayHandle->GetLength(); ASSERT(literalLength > 0); // fieldTypeId is the last element in literal buffer - auto fieldTypeId = static_cast(arrayHandle->Get(literalLength - 1).GetInt()); + auto fieldTypeId = static_cast(arrayHandle->Get(thread, literalLength - 1).GetInt()); // Don't trim array, because define class maybe called on muilt-time in the same vm or diferrent vm JSHandle extractor = factory->NewClassInfoExtractor(method); ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, arrayHandle, @@ -1077,7 +1077,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreateSharedClass(JSThread *thread, uint32_t arrayLength = fieldTypeArray->GetLength(); ASSERT(arrayLength > 0); - auto instanceFieldNums = static_cast(fieldTypeArray->Get(arrayLength - 1).GetInt()); + auto instanceFieldNums = static_cast(fieldTypeArray->Get(thread, arrayLength - 1).GetInt()); // Don't trim array, because define class maybe called on muilt-time in the same vm or diferrent vm uint32_t instanceLength = instanceFieldNums * 2; // 2: key and value ASSERT(instanceLength < arrayLength); @@ -1111,7 +1111,7 @@ JSTaggedValue RuntimeStubs::RuntimeSetClassInheritanceRelationship(JSThread *thr JSHandle parentPrototype; // hole means parent is not present - Method *method = Method::Cast(JSHandle::Cast(ctor)->GetMethod().GetTaggedObject()); + Method *method = Method::Cast(JSHandle::Cast(ctor)->GetMethod(thread).GetTaggedObject()); if (parent->IsHole()) { method->SetFunctionKind(FunctionKind::CLASS_CONSTRUCTOR); parentPrototype = @@ -1135,7 +1135,7 @@ JSTaggedValue RuntimeStubs::RuntimeSetClassInheritanceRelationship(JSThread *thr ctor->GetTaggedObject()->GetClass()->SetPrototype(thread, parent); // __proto__ - JSHandle clsPrototype(thread, JSHandle(ctor)->GetFunctionPrototype()); + JSHandle clsPrototype(thread, JSHandle(ctor)->GetFunctionPrototype(thread)); clsPrototype->GetClass()->SetPrototype(thread, parentPrototype); // ctor -> hclass -> EnableProtoChangeMarker @@ -1144,13 +1144,13 @@ JSTaggedValue RuntimeStubs::RuntimeSetClassInheritanceRelationship(JSThread *thr JSHClass::EnableProtoChangeMarker(thread, JSHandle(thread, constructor->GetClass())); // prototype -> hclass -> EnableProtoChangeMarker JSHClass::EnableProtoChangeMarker(thread, - JSHandle(thread, constructor->GetFunctionPrototype().GetTaggedObject()->GetClass())); + JSHandle(thread, constructor->GetFunctionPrototype(thread).GetTaggedObject()->GetClass())); } // by enableing the ProtoChangeMarker, the IHC generated in the Aot stage // is registered into the listener of its prototype. In this way, it is ensured // that when the prototype changes, the affected IHC can be notified. - JSTaggedValue protoOrHClass = JSHandle(ctor)->GetProtoOrHClass(); + JSTaggedValue protoOrHClass = JSHandle(ctor)->GetProtoOrHClass(thread); if (protoOrHClass.IsJSHClass()) { JSHClass *ihc = JSHClass::Cast(protoOrHClass.GetTaggedObject()); if (ihc->IsAOT()) { @@ -1194,8 +1194,8 @@ JSTaggedValue RuntimeStubs::RuntimeNotifyInlineCache(JSThread *thread, const JSH } else { profileTypeInfo = factory->NewProfileTypeInfo(icSlotSize); } - Method* method = Method::Cast(function->GetMethod()); - auto codeSize = method->GetCodeSize(); + Method* method = Method::Cast(function->GetMethod(thread)); + auto codeSize = method->GetCodeSize(thread); if (pgo::PGOProfilerManager::GetInstance()->IsBigMethod(codeSize)) { LOG_ECMA(DEBUG) << "method size is too large, skip pgo. code size: " << codeSize << ", max code size: " << pgo::PGOProfilerManager::GetInstance()->GetMaxAotMethodSize(); @@ -1212,7 +1212,7 @@ JSTaggedValue RuntimeStubs::RuntimeStOwnByValueWithNameSet(JSThread *thread, con const GlobalEnvConstants *globalConst = thread->GlobalConstants(); if (obj->IsClassConstructor() && - JSTaggedValue::SameValue(key, globalConst->GetHandledPrototypeString())) { + JSTaggedValue::SameValue(thread, key, globalConst->GetHandledPrototypeString())) { return RuntimeThrowTypeError(thread, "In a class, static property named 'prototype' throw a TypeError"); } @@ -1282,7 +1282,7 @@ JSTaggedValue RuntimeStubs::RuntimeSuspendGenerator(JSThread *thread, const JSHa { if (genObj->IsAsyncGeneratorObject()) { JSHandle generatorObjectHandle(genObj); - JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext()); + JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext(thread)); // save stack, should copy cur_frame, function execute over will free cur_frame SaveFrameToContext(thread, genContextHandle); @@ -1296,7 +1296,7 @@ JSTaggedValue RuntimeStubs::RuntimeSuspendGenerator(JSThread *thread, const JSHa if (genObj->IsGeneratorObject()) { JSHandle generatorObjectHandle(genObj); - JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext()); + JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext(thread)); // set TaskInfo for TaskPool generatorObjectHandle->SetTaskInfo(thread->GetTaskInfo()); // save stack, should copy cur_frame, function execute over will free cur_frame @@ -1319,7 +1319,7 @@ void RuntimeStubs::RuntimeSetGeneratorState(JSThread *thread, const JSHandle generatorObjectHandle(genObj); - JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext()); + JSHandle genContextHandle(thread, generatorObjectHandle->GetGeneratorContext(thread)); // change state switch (index) { @@ -1538,12 +1538,12 @@ JSTaggedValue RuntimeStubs::RuntimeLdPrivateProperty(JSThread *thread, JSTaggedV { JSTaggedValue currentLexicalEnv = lexicalEnv; for (uint32_t i = 0; i < levelIndex; i++) { - currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(); + currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(thread); ASSERT(!currentLexicalEnv.IsUndefined()); } - JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(slotIndex); + JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(thread, slotIndex); // private property is invisible for proxy - JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField() : obj); + JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField(thread) : obj); JSHandle handleKey(thread, key); if (handleKey->IsJSFunction()) { // getter JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); @@ -1568,12 +1568,12 @@ JSTaggedValue RuntimeStubs::RuntimeStPrivateProperty(JSThread *thread, JSTaggedV { JSTaggedValue currentLexicalEnv = lexicalEnv; for (uint32_t i = 0; i < levelIndex; i++) { - currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(); + currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(thread); ASSERT(!currentLexicalEnv.IsUndefined()); } - JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(slotIndex); + JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(thread, slotIndex); // private property is invisible for proxy - JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField() : obj); + JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField(thread) : obj); JSHandle handleKey(thread, key); JSHandle handleValue(thread, value); if (handleKey->IsJSFunction()) { // setter @@ -1605,11 +1605,11 @@ JSTaggedValue RuntimeStubs::RuntimeTestIn(JSThread *thread, JSTaggedValue lexica } JSTaggedValue currentLexicalEnv = lexicalEnv; for (uint32_t i = 0; i < levelIndex; i++) { - currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(); + currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(thread); ASSERT(!currentLexicalEnv.IsUndefined()); } - JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(slotIndex); - JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField() : obj); + JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(thread, slotIndex); + JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField(thread) : obj); JSHandle handleKey(thread, key); bool res = JSTaggedValue::IsPropertyKey(handleKey) && JSTaggedValue::HasProperty(thread, handleObj, handleKey); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1673,9 +1673,9 @@ JSTaggedValue RuntimeStubs::RuntimeLdGlobalRecord(JSThread *thread, JSTaggedValu EcmaVM *vm = thread->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); GlobalDictionary *dict = GlobalDictionary::Cast(env->GetGlobalRecord()->GetTaggedObject()); - int entry = dict->FindEntry(key); + int entry = dict->FindEntry(thread, key); if (entry != -1) { - return JSTaggedValue(dict->GetBox(entry)); + return JSTaggedValue(dict->GetBox(thread, entry)); } return JSTaggedValue::Undefined(); } @@ -1697,14 +1697,14 @@ JSTaggedValue RuntimeStubs::RuntimeTryUpdateGlobalRecord(JSThread *thread, JSTag EcmaVM *vm = thread->GetEcmaVM(); JSHandle env = vm->GetGlobalEnv(); GlobalDictionary *dict = GlobalDictionary::Cast(env->GetGlobalRecord()->GetTaggedObject()); - int entry = dict->FindEntry(prop); + int entry = dict->FindEntry(thread, prop); ASSERT(entry != -1); - if (dict->GetAttributes(entry).IsConstProps()) { + if (dict->GetAttributes(thread, entry).IsConstProps()) { return RuntimeThrowTypeError(thread, "const variable can not be modified"); } - PropertyBox *box = dict->GetBox(entry); + PropertyBox *box = dict->GetBox(thread, entry); box->SetValue(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::True(); @@ -1728,7 +1728,7 @@ JSTaggedValue RuntimeStubs::RuntimeLdGlobalVarFromProto(JSThread *thread, const { ASSERT(globalObj->IsJSGlobalObject()); JSHandle global(globalObj); - JSHandle obj(thread, JSObject::GetPrototype(global)); + JSHandle obj(thread, JSObject::GetPrototype(thread, global)); OperationResult res = JSTaggedValue::GetProperty(thread, obj, prop); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res.GetValue().GetTaggedValue(); @@ -1763,7 +1763,7 @@ JSTaggedValue RuntimeStubs::RuntimeDynamicImport(JSThread *thread, const JSHandl // get current filename JSFunction *function = JSFunction::Cast(func->GetTaggedObject()); - const JSPandaFile *jsPandaFile = function->GetCallTarget()->GetJSPandaFile(); + const JSPandaFile *jsPandaFile = function->GetCallTarget(thread)->GetJSPandaFile(thread); ASSERT(jsPandaFile != nullptr); CString currentfilename = jsPandaFile->GetJSPandaFileDesc(); @@ -1772,7 +1772,7 @@ JSTaggedValue RuntimeStubs::RuntimeDynamicImport(JSThread *thread, const JSHandl if (jsPandaFile->IsBundlePack()) { dirPath.Update(factory->NewFromUtf8(currentfilename).GetTaggedValue()); } else { - recordName.Update(factory->NewFromUtf8(function->GetRecordName())); + recordName.Update(factory->NewFromUtf8(function->GetRecordName(thread))); dirPath.Update(factory->NewFromUtf8(currentfilename).GetTaggedValue()); } @@ -1783,8 +1783,8 @@ JSTaggedValue RuntimeStubs::RuntimeDynamicImport(JSThread *thread, const JSHandl JSHandle job = ecmaVm->GetMicroJobQueue(); JSHandle argv = factory->NewTaggedArray(5); // 5: 5 means parameters stored in array - argv->Set(thread, 0, promiseCapability->GetResolve()); - argv->Set(thread, 1, promiseCapability->GetReject()); // 1 : reject method + argv->Set(thread, 0, promiseCapability->GetResolve(thread)); + argv->Set(thread, 1, promiseCapability->GetReject(thread)); // 1 : reject method argv->Set(thread, 2, dirPath); // 2 : current file path(containing file name) argv->Set(thread, 3, specifier); // 3 : request module's path argv->Set(thread, 4, recordName); // 4 : js recordName or undefined @@ -1792,7 +1792,7 @@ JSTaggedValue RuntimeStubs::RuntimeDynamicImport(JSThread *thread, const JSHandl JSHandle dynamicImportJob(env->GetDynamicImportJob()); job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, dynamicImportJob, argv); - return promiseCapability->GetPromise(); + return promiseCapability->GetPromise(thread); } JSTaggedValue RuntimeStubs::RuntimeEq(JSThread *thread, const JSHandle &left, @@ -2224,7 +2224,7 @@ JSTaggedValue RuntimeStubs::RuntimeNewLexicalEnv(JSThread *thread, uint16_t numV JSTaggedValue currentEnv = thread->GetCurrentLexenv(); // currentEnv is LexicalEnv/GlobalEnv for normal function, and is SFunctionEnv/Undefined for SharedFunction. if LIKELY(currentEnv.IsHeapObject()) { - newEnv->SetGlobalEnv(thread, BaseEnv::Cast(currentEnv.GetTaggedObject())->GetGlobalEnv()); + newEnv->SetGlobalEnv(thread, BaseEnv::Cast(currentEnv.GetTaggedObject())->GetGlobalEnv(thread)); } newEnv->SetParentEnv(thread, currentEnv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2236,9 +2236,9 @@ JSTaggedValue RuntimeStubs::RuntimeNewSendableEnv(JSThread *thread, uint16_t num ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle newEnv = factory->NewSendableEnv(numVars); - JSTaggedValue module = JSFunction::Cast(thread->GetCurrentFunction())->GetModule(); + JSTaggedValue module = JSFunction::Cast(thread->GetCurrentFunction())->GetModule(thread); JSHandle moduleHandle(thread, module); - newEnv->SetParentEnv(thread, moduleHandle->GetSendableEnv()); + newEnv->SetParentEnv(thread, moduleHandle->GetSendableEnv(thread)); newEnv->SetScopeInfo(thread, JSTaggedValue::Hole()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return newEnv.GetTaggedValue(); @@ -2264,7 +2264,7 @@ void RuntimeStubs::DefineFuncTryUseAOTHClass(JSThread* thread, const JSHandle& ihc, const JSHandle& aotLiteralInfo) { - FunctionKind kind = Method::Cast(func->GetMethod())->GetFunctionKind(); + FunctionKind kind = Method::Cast(func->GetMethod(thread))->GetFunctionKind(); // The HClass of AOT comes from .ai deserialization if (!ihc->IsUndefined() && kind == FunctionKind::BASE_CONSTRUCTOR) { ASSERT(!aotLiteralInfo.GetTaggedValue().IsHole()); @@ -2274,7 +2274,7 @@ void RuntimeStubs::DefineFuncTryUseAOTHClass(JSThread* thread, // build inheritance JSHandle parentPrototype = env->GetObjectFunctionPrototype(); - JSHandle clsPrototype(thread, func->GetFunctionPrototype()); + JSHandle clsPrototype(thread, func->GetFunctionPrototype(thread)); clsPrototype->GetClass()->SetPrototype(thread, parentPrototype); // set "constructor" in prototype @@ -2309,7 +2309,7 @@ JSTaggedValue RuntimeStubs::RuntimeDefinefunc(JSThread *thread, const JSHandleGetEcmaVM()->FindUnsharedConstpool(constpoolHandle.GetTaggedValue()); if (!unsharedCp.IsHole()) { JSHandle unsharedCpHandle(thread, unsharedCp); - JSTaggedValue val = unsharedCpHandle->GetObjectFromCache(methodId); + JSTaggedValue val = unsharedCpHandle->GetObjectFromCache(thread, methodId); if (val.IsAOTLiteralInfo()) { aotLiteralInfo.Update(val); ihc.Update(aotLiteralInfo->GetIhc()); @@ -2326,7 +2326,7 @@ JSTaggedValue RuntimeStubs::RuntimeDefinefunc(JSThread *thread, const JSHandleIsSourceTextModule()) { JSHandle sendableFuncModuleRecord(sendableFuncModule); sendableFuncModuleRecord->SetSendableEnv( - thread, JSHandle::Cast(module)->GetSendableEnv()); + thread, JSHandle::Cast(module)->GetSendableEnv(thread)); } result->SetModule(thread, sendableFuncModule.GetTaggedValue()); auto globalConst = thread->GlobalConstants(); @@ -2391,10 +2391,10 @@ JSTaggedValue RuntimeStubs::CommonCreateObjectWithExcludedKeys(JSThread *thread, uint32_t numAllKeys = allKeys->GetLength(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < numAllKeys; i++) { - key.Update(allKeys->Get(i)); + key.Update(allKeys->Get(thread, i)); bool isExcludedKey = false; for (uint32_t j = 0; j < numExcludedKeys; j++) { - if (JSTaggedValue::Equal(thread, key, JSHandle(thread, excludedKeys->Get(j)))) { + if (JSTaggedValue::Equal(thread, key, JSHandle(thread, excludedKeys->Get(thread, j)))) { isExcludedKey = true; break; } @@ -2474,15 +2474,16 @@ JSTaggedValue RuntimeStubs::RuntimeDefineMethod(JSThread *thread, const JSHandle return func.GetTaggedValue(); } -JSTaggedValue RuntimeStubs::RuntimeLdSendableClass(const JSHandle &env, uint16_t level) +JSTaggedValue RuntimeStubs::RuntimeLdSendableClass(JSThread *thread, const JSHandle &env, + uint16_t level) { JSTaggedValue currentEnv(env.GetTaggedValue()); for (uint32_t i = 0; i < level; i++) { ASSERT(currentEnv.IsLexicalEnv()); - currentEnv = LexicalEnv::Cast(currentEnv.GetTaggedObject())->GetParentEnv(); + currentEnv = LexicalEnv::Cast(currentEnv.GetTaggedObject())->GetParentEnv(thread); } ASSERT(currentEnv.IsSFunctionEnv()); - return SFunctionEnv::Cast(currentEnv.GetTaggedObject())->GetConstructor(); + return SFunctionEnv::Cast(currentEnv.GetTaggedObject())->GetConstructor(thread); } JSTaggedValue RuntimeStubs::RuntimeCallSpread(JSThread *thread, @@ -2506,10 +2507,10 @@ JSTaggedValue RuntimeStubs::RuntimeCallSpread(JSThread *thread, void RuntimeStubs::RuntimeSetPatchModule(JSThread *thread, const JSHandle &func) { - JSHandle methodHandle(thread, Method::Cast(func->GetMethod())); + JSHandle methodHandle(thread, Method::Cast(func->GetMethod(thread))); const JSHandle coldReloadRecordName = thread->GetEcmaVM()->FindPatchModule(MethodLiteral::GetRecordName( - methodHandle->GetJSPandaFile(), methodHandle->GetMethodId())); + methodHandle->GetJSPandaFile(thread), methodHandle->GetMethodId())); if (!coldReloadRecordName->IsHole()) { func->SetModule(thread, coldReloadRecordName.GetTaggedValue()); } @@ -2526,7 +2527,7 @@ JSTaggedValue RuntimeStubs::RuntimeDefineGetterSetterByValue(JSThread *thread, c RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto globalConst = thread->GlobalConstants(); if (obj.GetTaggedValue().IsClassConstructor() && - JSTaggedValue::SameValue(propKey, globalConst->GetHandledPrototypeString())) { + JSTaggedValue::SameValue(thread, propKey, globalConst->GetHandledPrototypeString())) { return RuntimeThrowTypeError( thread, "In a class, computed property names for static getter that are named 'prototype' throw a TypeError"); @@ -2559,12 +2560,12 @@ JSTaggedValue RuntimeStubs::RuntimeDefineGetterSetterByValue(JSThread *thread, c !(obj.GetTaggedValue().IsClassPrototype() || obj.GetTaggedValue().IsClassConstructor()); PropertyDescriptor desc(thread, true, enumerable, true); if (!getter->IsUndefined()) { - Method *method = Method::Cast(JSHandle::Cast(getter)->GetMethod().GetTaggedObject()); + Method *method = Method::Cast(JSHandle::Cast(getter)->GetMethod(thread).GetTaggedObject()); method->SetFunctionKind(FunctionKind::GETTER_FUNCTION); desc.SetGetter(getter); } if (!setter->IsUndefined()) { - Method *method = Method::Cast(JSHandle::Cast(setter)->GetMethod().GetTaggedObject()); + Method *method = Method::Cast(JSHandle::Cast(setter)->GetMethod(thread).GetTaggedObject()); method->SetFunctionKind(FunctionKind::SETTER_FUNCTION); desc.SetSetter(setter); } @@ -2655,7 +2656,7 @@ JSTaggedValue RuntimeStubs::RuntimeGetCallSpreadArgs(JSThread *thread, const JSH while (true) { next.Update(JSIterator::IteratorStep(thread, itor).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::SameValue(next.GetTaggedValue(), JSTaggedValue::False())) { + if (JSTaggedValue::SameValue(thread, next.GetTaggedValue(), JSTaggedValue::False())) { break; } nextArg.Update(JSIterator::IteratorValue(thread, next).GetTaggedValue()); @@ -2704,7 +2705,7 @@ JSTaggedValue RuntimeStubs::RuntimeNewLexicalEnvWithName(JSThread *thread, uint1 JSTaggedValue currentEnv = thread->GetCurrentLexenv(); // currentEnv is LexicalEnv/GlobalEnv for normal function, and is SFunctionEnv/Undefined for SharedFunction. if LIKELY(currentEnv.IsHeapObject()) { - newEnv->SetGlobalEnv(thread, BaseEnv::Cast(currentEnv.GetTaggedObject())->GetGlobalEnv()); + newEnv->SetGlobalEnv(thread, BaseEnv::Cast(currentEnv.GetTaggedObject())->GetGlobalEnv(thread)); } newEnv->SetParentEnv(thread, currentEnv); JSTaggedValue scopeInfo = ScopeInfoExtractor::GenerateScopeInfo(thread, scopeId); @@ -2778,7 +2779,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptNewLexicalEnvWithName(JSThread *thread, ui // currentEnv is LexicalEnv/GlobalEnv for normal function, and is SFunctionEnv/Undefined for SharedFunction. if LIKELY(currentEnv->IsHeapObject()) { TaggedObject* obj = currentEnv.GetTaggedValue().GetTaggedObject(); - newEnv->SetGlobalEnv(thread, BaseEnv::Cast(obj)->GetGlobalEnv()); + newEnv->SetGlobalEnv(thread, BaseEnv::Cast(obj)->GetGlobalEnv(thread)); } newEnv->SetParentEnv(thread, currentEnv.GetTaggedValue()); JSTaggedValue scopeInfo = RuntimeOptGenerateScopeInfo(thread, scopeId, func.GetTaggedValue()); @@ -2848,7 +2849,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptAsyncGeneratorResolve(JSThread *thread, JS JSHandle asyncGeneratorObjHandle(asyncFuncObj); JSHandle valueHandle(value); - JSHandle genContextHandle(thread, asyncGeneratorObjHandle->GetGeneratorContext()); + JSHandle genContextHandle(thread, asyncGeneratorObjHandle->GetGeneratorContext(thread)); ASSERT(flag.IsBoolean()); bool done = flag.IsTrue(); return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, asyncGeneratorObjHandle, valueHandle, done); @@ -2885,12 +2886,12 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructProxy(JSThread *thread, JSHandle< { STACK_LIMIT_CHECK(thread, JSTaggedValue::Exception()); // step 1 ~ 4 get ProxyHandler and ProxyTarget - JSHandle handler(thread, ctor->GetHandler()); + JSHandle handler(thread, ctor->GetHandler(thread)); if (handler->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor: handler is null", JSTaggedValue::Exception()); } ASSERT(handler->IsECMAObject()); - JSHandle target(thread, ctor->GetTarget()); + JSHandle target(thread, ctor->GetTarget(thread)); // 5.Let trap be GetMethod(handler, "construct"). JSHandle key(thread->GlobalConstants()->GetHandledProxyConstructString()); @@ -2914,13 +2915,13 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructProxy(JSThread *thread, JSHandle< if (preArgsSize > 0) { JSHandle tgaPreArgs = JSHandle::Cast(preArgs); for (uint32_t i = 0; i < preArgsSize; ++i) { - JSTaggedValue value = tgaPreArgs->Get(i); + JSTaggedValue value = tgaPreArgs->Get(thread, i); arr->Set(thread, i, value); } } for (uint32_t i = 0; i < argsCount; ++i) { - JSTaggedValue value = args->Get(i); + JSTaggedValue value = args->Get(thread, i); arr->Set(thread, i + preArgsSize, value); } JSHandle newArr = JSArray::CreateArrayFromList(thread, arr); @@ -2947,12 +2948,12 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructBoundFunction(JSThread *thread, J JSHandle preArgs, JSHandle args) { - JSHandle target(thread, ctor->GetBoundTarget()); + JSHandle target(thread, ctor->GetBoundTarget(thread)); if (!target->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception()); } - JSHandle boundArgs(thread, ctor->GetBoundArguments()); + JSHandle boundArgs(thread, ctor->GetBoundArguments(thread)); JSMutableHandle newPreArgs(thread, preArgs.GetTaggedValue()); if (newPreArgs->IsUndefined()) { newPreArgs.Update(boundArgs.GetTaggedValue()); @@ -2961,7 +2962,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructBoundFunction(JSThread *thread, J TaggedArray::Append(thread, boundArgs, JSHandle::Cast(preArgs)).GetTaggedValue()); } JSMutableHandle newTargetMutable(thread, newTgt.GetTaggedValue()); - if (JSTaggedValue::SameValue(ctor.GetTaggedValue(), newTgt.GetTaggedValue())) { + if (JSTaggedValue::SameValue(thread, ctor.GetTaggedValue(), newTgt.GetTaggedValue())) { newTargetMutable.Update(target.GetTaggedValue()); } return RuntimeOptConstruct(thread, target, newTargetMutable, newPreArgs, args); @@ -2972,7 +2973,7 @@ JSTaggedValue RuntimeStubs::GetResultValue(JSThread *thread, bool isAotMethod, J { JSTaggedValue resultValue; if (isAotMethod) { - uint32_t numArgs = ctor->GetCallTarget()->GetNumArgsWithCallField(); + uint32_t numArgs = ctor->GetCallTarget(thread)->GetNumArgsWithCallField(); bool needPushArgv = numArgs != size; const JSTaggedType *prevFp = thread->GetLastLeaveFrame(); if (ctor->IsCompiledFastCall()) { @@ -3006,7 +3007,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructGeneric(JSThread *thread, JSHandl } JSHandle obj(thread, JSTaggedValue::Undefined()); - if (ctor->IsBase()) { + if (ctor->IsBase(thread)) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); obj = JSHandle(factory->NewJSObjectByConstructor(ctor, newTgt)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -3035,15 +3036,15 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructGeneric(JSThread *thread, JSHandl if (preArgsSize > 0) { JSHandle tgaPreArgs = JSHandle::Cast(preArgs); for (uint32_t i = 0; i < preArgsSize; ++i) { - JSTaggedValue value = tgaPreArgs->Get(i); + JSTaggedValue value = tgaPreArgs->Get(thread, i); values.emplace_back(value.GetRawData()); } for (uint32_t i = 0; i < argsCount; ++i) { - values.emplace_back(args->Get(i).GetRawData()); + values.emplace_back(args->Get(thread, i).GetRawData()); } } else { for (uint32_t i = 0; i < argsCount; ++i) { - values.emplace_back(args->Get(i).GetRawData()); + values.emplace_back(args->Get(thread, i).GetRawData()); } } JSTaggedValue resultValue = RuntimeStubs::GetResultValue(thread, isCompiledCode, ctor, values, newTgt, size, obj); @@ -3056,7 +3057,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptConstructGeneric(JSThread *thread, JSHandl return resultValue; } - if (ctor->IsBase()) { + if (ctor->IsBase(thread)) { return obj.GetTaggedValue(); } if (!resultValue.IsUndefined()) { @@ -3078,7 +3079,7 @@ JSTaggedValue RuntimeStubs::RuntimeOptNewObjRange(JSThread *thread, uintptr_t ar } JSTaggedValue object = RuntimeOptConstruct(thread, ctor, ctor, undefined, args); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!object.IsUndefined() && !object.IsECMAObject() && !JSHandle(ctor)->IsBase()) { + if (!object.IsUndefined() && !object.IsECMAObject() && !JSHandle(ctor)->IsBase(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Derived constructor must return object or undefined", JSTaggedValue::Exception()); } @@ -3089,9 +3090,9 @@ JSTaggedValue RuntimeStubs::RuntimeOptGenerateScopeInfo(JSThread *thread, uint16 { EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory(); - Method *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget(); - const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); - JSHandle constpool(thread, method->GetConstantPool()); + Method *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget(thread); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(thread); + JSHandle constpool(thread, method->GetConstantPool(thread)); panda_file::File::EntityId id = constpool->GetEntityId(scopeId); JSHandle elementsLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, id, constpool); @@ -3105,10 +3106,10 @@ JSTaggedValue RuntimeStubs::RuntimeOptGenerateScopeInfo(JSThread *thread, uint16 size_t length = elementsLiteral->GetLength(); for (size_t i = 1; i < length; i += 2) { // 2: Each literal buffer contains a pair of key-value. - JSTaggedValue val = elementsLiteral->Get(i); + JSTaggedValue val = elementsLiteral->Get(thread, i); ASSERT(val.IsString()); - CString name = ConvertToString(EcmaString::Cast(val.GetTaggedObject())); - int32_t slot = elementsLiteral->Get(i + 1).GetInt(); + CString name = ConvertToString(thread, EcmaString::Cast(val.GetTaggedObject())); + int32_t slot = elementsLiteral->Get(thread, i + 1).GetInt(); scopeDebugInfo->scopeInfo.emplace(name, slot); } @@ -3234,14 +3235,14 @@ JSTaggedValue RuntimeStubs::RuntimeCreatePrivateProperty(JSThread *thread, JSTag JSHandle handleModule(thread, module); JSHandle unsharedConstpoolHandle( thread, thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpool)); - CString entry = ModuleManager::GetRecordName(handleModule.GetTaggedValue()); + CString entry = ModuleManager::GetRecordName(thread, handleModule.GetTaggedValue()); uint32_t length = handleLexicalEnv->GetLength() - LexicalEnv::RESERVED_ENV_LENGTH; uint32_t startIndex = 0; - while (startIndex < length && !handleLexicalEnv->GetProperties(startIndex).IsHole()) { + while (startIndex < length && !handleLexicalEnv->GetProperties(thread, startIndex).IsHole()) { startIndex++; } - JSTaggedValue aotSymbolInfo = unsharedConstpoolHandle->GetAotSymbolInfo(); + JSTaggedValue aotSymbolInfo = unsharedConstpoolHandle->GetAotSymbolInfo(thread); JSHandle aotSymbolInfoHandle(thread, aotSymbolInfo); FrameHandler frameHandler(thread); uint32_t abcId = frameHandler.GetAbcId(); @@ -3250,7 +3251,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreatePrivateProperty(JSThread *thread, JSTag auto index = startIndex + i; uint64_t id = JSSymbol::GeneratePrivateId(abcId, literalId, index); JSHandle symbolHandle; - JSTaggedValue symbol = ConstantPool::GetSymbolFromSymbolInfo(aotSymbolInfoHandle, id); + JSTaggedValue symbol = ConstantPool::GetSymbolFromSymbolInfo(thread, aotSymbolInfoHandle, id); if (ConstantPool::IsAotSymbolInfoExist(aotSymbolInfoHandle, symbol)) { symbolHandle = JSHandle(thread, symbol); } else { @@ -3264,18 +3265,19 @@ JSTaggedValue RuntimeStubs::RuntimeCreatePrivateProperty(JSThread *thread, JSTag JSTaggedValue literalObj = ConstantPool::GetClassLiteralFromCache(thread, unsharedConstpoolHandle, literalId, entry); JSHandle classLiteral(thread, literalObj); - JSHandle literalBuffer(thread, classLiteral->GetArray()); + JSHandle literalBuffer(thread, classLiteral->GetArray(thread)); uint32_t literalBufferLength = literalBuffer->GetLength(); if (literalBufferLength == 0) { return JSTaggedValue::Undefined(); } // instace property number is hidden in the last index of literal buffer - uint32_t instacePropertyCount = static_cast(literalBuffer->Get(literalBufferLength - 1).GetInt()); + uint32_t instacePropertyCount = + static_cast(literalBuffer->Get(thread, literalBufferLength - 1).GetInt()); ASSERT(startIndex + count + literalBufferLength - (instacePropertyCount == 0) <= length); JSMutableHandle literalValue(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < literalBufferLength - 1; i++) { - literalValue.Update(literalBuffer->Get(i)); + literalValue.Update(literalBuffer->Get(thread, i)); if (LIKELY(literalValue->IsFunctionTemplate())) { auto literalFunc = JSHandle::Cast(literalValue); JSHandle func = factory->CreateJSFunctionFromTemplate(literalFunc); @@ -3289,7 +3291,7 @@ JSTaggedValue RuntimeStubs::RuntimeCreatePrivateProperty(JSThread *thread, JSTag auto index = startIndex + count + literalBufferLength - 1; uint64_t id = JSSymbol::GeneratePrivateId(abcId, literalId, index); JSHandle symbolHandle; - JSTaggedValue symbol = ConstantPool::GetSymbolFromSymbolInfo(aotSymbolInfoHandle, id); + JSTaggedValue symbol = ConstantPool::GetSymbolFromSymbolInfo(thread, aotSymbolInfoHandle, id); if (ConstantPool::IsAotSymbolInfoExist(aotSymbolInfoHandle, symbol)) { symbolHandle = JSHandle(thread, symbol); } else { @@ -3307,12 +3309,12 @@ JSTaggedValue RuntimeStubs::RuntimeDefinePrivateProperty(JSThread *thread, JSTag { JSTaggedValue currentLexicalEnv = lexicalEnv; for (uint32_t i = 0; i < levelIndex; i++) { - currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(); + currentLexicalEnv = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetParentEnv(thread); ASSERT(!currentLexicalEnv.IsUndefined()); } - JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(slotIndex); + JSTaggedValue key = LexicalEnv::Cast(currentLexicalEnv.GetTaggedObject())->GetProperties(thread, slotIndex); // private property is invisible for proxy - JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField() : obj); + JSHandle handleObj(thread, obj.IsJSProxy() ? JSProxy::Cast(obj)->GetPrivateField(thread) : obj); JSHandle handleKey(thread, key); JSHandle handleValue(thread, value); PropertyDescriptor desc(thread); @@ -3361,11 +3363,11 @@ JSTaggedValue RuntimeStubs::RuntimeNotifyDebuggerStatement(JSThread *thread) return JSTaggedValue::Hole(); } -bool RuntimeStubs::CheckElementsNumber(JSHandle elements, uint32_t len) +bool RuntimeStubs::CheckElementsNumber(const JSThread *thread, JSHandle elements, uint32_t len) { ASSERT(len <= elements->GetLength()); for (uint32_t i = 0; i < len; i++) { - if (!elements->Get(i).IsNumber()) { + if (!elements->Get(thread, i).IsNumber()) { return false; } } @@ -3392,7 +3394,7 @@ JSTaggedValue RuntimeStubs::TryCopyCOWArray(JSThread *thread, JSHandle JSArray::CheckAndCopyArray(thread, holderHandler); isCOWArray = false; } - return holderHandler->GetElements(); + return holderHandler->GetElements(thread); } JSTaggedValue RuntimeStubs::ArrayNumberSort(JSThread *thread, JSHandle thisObj, uint32_t len) @@ -3400,17 +3402,17 @@ JSTaggedValue RuntimeStubs::ArrayNumberSort(JSThread *thread, JSHandle JSMutableHandle presentValue(thread, JSTaggedValue::Undefined()); JSMutableHandle middleValue(thread, JSTaggedValue::Undefined()); JSMutableHandle previousValue(thread, JSTaggedValue::Undefined()); - bool isCOWArray = JSHandle(thisObj)->IsJSCOWArray(); - JSMutableHandle elements(thread, thisObj->GetElements()); + bool isCOWArray = JSHandle(thisObj)->IsJSCOWArray(thread); + JSMutableHandle elements(thread, thisObj->GetElements(thread)); std::map> cachedString; for (uint32_t i = 1; i < len; i++) { uint32_t beginIndex = 0; uint32_t endIndex = i; - presentValue.Update(elements->Get(i)); + presentValue.Update(elements->Get(thread, i)); JSHandle presentString = GetOrCreateNumberString(thread, presentValue, cachedString); while (beginIndex < endIndex) { uint32_t middleIndex = beginIndex + (endIndex - beginIndex) / 2; // 2 : half - middleValue.Update(elements->Get(middleIndex)); + middleValue.Update(elements->Get(thread, middleIndex)); JSHandle middleString = GetOrCreateNumberString(thread, middleValue, cachedString); double compareResult = ArrayHelper::StringSortCompare(thread, middleString, presentString); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -3422,7 +3424,7 @@ JSTaggedValue RuntimeStubs::ArrayNumberSort(JSThread *thread, JSHandle } if (endIndex >= 0 && endIndex < i) { for (uint32_t j = i; j > endIndex; j--) { - previousValue.Update(elements->Get(j - 1)); + previousValue.Update(elements->Get(thread, j - 1)); elements.Update(TryCopyCOWArray(thread, JSHandle(thisObj), isCOWArray)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); elements->Set(thread, j, previousValue); @@ -3440,7 +3442,7 @@ JSTaggedType RuntimeStubs::RuntimeTryGetInternString(uintptr_t argGlue, const JS auto thread = JSThread::GlueToJSThread(argGlue); #if ENABLE_NEXT_OPTIMIZATION EcmaString *str = - thread->GetEcmaVM()->GetEcmaStringTable()->TryGetInternString(string); + thread->GetEcmaVM()->GetEcmaStringTable()->TryGetInternString(thread, string); #else EcmaString *str = thread->GetEcmaVM()->GetEcmaStringTable()->TryGetInternString(thread, string); @@ -3451,16 +3453,17 @@ JSTaggedType RuntimeStubs::RuntimeTryGetInternString(uintptr_t argGlue, const JS return JSTaggedValue::Cast(static_cast(str)); } -uint32_t RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(const JSHandle &func, uintptr_t nativePc) +uint32_t RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(JSThread *thread, const JSHandle &func, + uintptr_t nativePc) { // Compute current bytecodePc according to nativePc of returnAddress LOG_BASELINEJIT(DEBUG) << "nativePc address: " << std::hex << nativePc; - const MachineCode *machineCode = MachineCode::Cast(func->GetBaselineCode().GetTaggedObject()); + const MachineCode *machineCode = MachineCode::Cast(func->GetBaselineCode(thread).GetTaggedObject()); const uintptr_t nativePcStart = machineCode->GetFuncAddr(); LOG_BASELINEJIT(DEBUG) << "baselineCode nativeStart address: " << std::hex << nativePcStart; - const Method *thisMethod = Method::Cast(func->GetMethod().GetTaggedObject()); + const Method *thisMethod = Method::Cast(func->GetMethod(thread).GetTaggedObject()); const uint8_t *bytecodeStart = thisMethod->GetBytecodeArray(); - const uint8_t *bytecodeEnd = bytecodeStart + thisMethod->GetCodeSize(); + const uint8_t *bytecodeEnd = bytecodeStart + thisMethod->GetCodeSize(thread); LOG_BASELINEJIT(DEBUG) << "bytecodePc start: " << reinterpret_cast(bytecodeStart); LOG_BASELINEJIT(DEBUG) << "bytecodePc end: " << reinterpret_cast(bytecodeEnd); const uint8_t *offsetTableAddr = machineCode->GetStackMapOrOffsetTableAddress(); @@ -3490,23 +3493,23 @@ uint32_t RuntimeStubs::RuntimeGetBytecodePcOfstForBaseline(const JSHandle &func, uint64_t bytecodePos) +uintptr_t RuntimeStubs::RuntimeGetNativePcOfstForBaseline(JSThread *thread, const JSHandle &func, uint64_t bytecodePos) { const uint8_t *bytecodePc = reinterpret_cast(bytecodePos); // Compute current nativePc according to bytecodePc LOG_BASELINEJIT(DEBUG) << "bytecodePc address: " << std::hex << reinterpret_cast(bytecodePc); auto opcode = kungfu::Bytecodes::GetOpcode(bytecodePc); LOG_BASELINEJIT(DEBUG) << "bytecode: " << kungfu::GetEcmaOpcodeStr(opcode); - const Method *thisMethod = Method::Cast(func->GetMethod().GetTaggedObject()); - LOG_TRACE(INFO) << "deopt to baseline method name: " << thisMethod->GetMethodName(); + const Method *thisMethod = Method::Cast(func->GetMethod(thread).GetTaggedObject()); + LOG_TRACE(INFO) << "deopt to baseline method name: " << thisMethod->GetMethodName(thread); const uint8_t *bytecodeStart = thisMethod->GetBytecodeArray(); - const uint8_t *bytecodeEnd = bytecodeStart + thisMethod->GetCodeSize(); + const uint8_t *bytecodeEnd = bytecodeStart + thisMethod->GetCodeSize(thread); ASSERT(bytecodeStart < bytecodeEnd); LOG_BASELINEJIT(DEBUG) << "bytecodePc start: " << std::hex << reinterpret_cast(bytecodeStart); LOG_BASELINEJIT(DEBUG) << "bytecodePc end: " << std::hex << reinterpret_cast(bytecodeEnd); ASSERT(bytecodeEnd >= bytecodeStart && bytecodePc <= bytecodeEnd); - const MachineCode *machineCode = MachineCode::Cast(func->GetBaselineCode().GetTaggedObject()); + const MachineCode *machineCode = MachineCode::Cast(func->GetBaselineCode(thread).GetTaggedObject()); const uintptr_t nativePcStart = machineCode->GetFuncAddr(); LOG_BASELINEJIT(DEBUG) << "baselineCode nativeStart address: " << std::hex << nativePcStart; const uint8_t *offsetTableAddr = machineCode->GetStackMapOrOffsetTableAddress(); diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index d242fc2273..443b696ea5 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -288,12 +288,13 @@ void RuntimeStubs::CopyTypedArrayBuffer(uintptr_t argGlue, JSTypedArray *srcArra uint32_t uTarStartPos = static_cast(tarStartPos); uint32_t uCount = static_cast(count); if (LIKELY(srcType == tarType)) { - JSTaggedValue srcBuffer = srcArray->GetViewedArrayBufferOrByteArray(); - JSTaggedValue targetBuffer = targetArray->GetViewedArrayBufferOrByteArray(); + auto thread = JSThread::GlueToJSThread(argGlue); + JSTaggedValue srcBuffer = srcArray->GetViewedArrayBufferOrByteArray(thread); + JSTaggedValue targetBuffer = targetArray->GetViewedArrayBufferOrByteArray(thread); uint32_t srcByteIndex = uSrcStartPos * srcElementSize + srcArray->GetByteOffset(); uint32_t targetByteIndex = uTarStartPos * srcElementSize + targetArray->GetByteOffset(); - uint8_t *srcBuf = (uint8_t *) builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(srcBuffer, srcByteIndex); - uint8_t *targetBuf = (uint8_t *) builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(targetBuffer, + uint8_t *srcBuf = (uint8_t *) builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcBuffer, srcByteIndex); + uint8_t *targetBuf = (uint8_t *) builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, targetBuffer, targetByteIndex); if (memmove_s(targetBuf, srcElementSize * uCount, srcBuf, srcElementSize * uCount) != EOK) { LOG_FULL(FATAL) << "memmove_s failed"; @@ -359,7 +360,7 @@ DEF_RUNTIME_STUBS(ComputeHashcode) { JSTaggedType ecmaString = GetTArg(argv, argc, 0); // 0: means the zeroth parameter auto string = reinterpret_cast(ecmaString); - uint32_t result = EcmaStringAccessor(string).ComputeHashcode(); + uint32_t result = EcmaStringAccessor(string).ComputeHashcode(JSThread::GlueToJSThread(argGlue)); return JSTaggedValue(static_cast(result)).GetRawData(); } @@ -445,7 +446,7 @@ DEF_RUNTIME_STUBS(NumberDictionaryPut) if (needTransToDict.IsTrue()) { JSObject::ElementsToDictionary(thread, objHandle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); - JSHandle dict(thread, objHandle->GetElements()); + JSHandle dict(thread, objHandle->GetElements(thread)); return NumberDictionary::Put(thread, dict, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData(); } else { JSHandle dict(thread, JSTaggedValue(reinterpret_cast(array))); @@ -485,7 +486,7 @@ DEF_RUNTIME_STUBS(CheckAndCopyArray) JSTaggedType argReceiver = GetTArg(argv, argc, 0); // 0: means the zeroth parameter JSHandle receiverHandle(thread, reinterpret_cast(argReceiver)); JSArray::CheckAndCopyArray(thread, receiverHandle); - return receiverHandle->GetElements().GetRawData(); + return receiverHandle->GetElements(thread).GetRawData(); } DEF_RUNTIME_STUBS(JSArrayReduceUnStable) @@ -590,7 +591,7 @@ DEF_RUNTIME_STUBS(CopyAndUpdateObjLayout) PropertyAttributes attrValue(attr); // 1. Copy - JSHandle oldLayout(thread, newHClassHandle->GetLayout()); + JSHandle oldLayout(thread, newHClassHandle->GetLayout(thread)); JSHandle newLayout(factory->CopyLayoutInfo(oldLayout)); newHClassHandle->SetLayout(thread, newLayout); @@ -626,7 +627,7 @@ DEF_RUNTIME_STUBS(UpdateHClassForElementsKind) if (!thread->IsPGOProfilerEnable()) { return JSTaggedValue::Hole().GetRawData(); } - JSTaggedValue trackInfoVal = JSHandle(receiver)->GetTrackInfo(); + JSTaggedValue trackInfoVal = JSHandle(receiver)->GetTrackInfo(thread); if (trackInfoVal.IsHeapObject() && trackInfoVal.IsWeak()) { TrackInfo *trackInfo = TrackInfo::Cast(trackInfoVal.GetWeakReferentUnChecked()); thread->GetEcmaVM()->GetPGOProfiler()->UpdateTrackInfo(JSTaggedValue(trackInfo)); @@ -681,7 +682,7 @@ DEF_RUNTIME_STUBS(RuntimeDump) JSHandle obj = JSHandle(GetHArg(argv, argc, 0)); { std::ostringstream oss; - obj->Dump(oss); + obj->Dump(thread, oss); LOG_ECMA(ERROR) << "RuntimeDump: " << oss.str(); } @@ -698,7 +699,7 @@ void RuntimeStubs::Dump(JSTaggedType rawValue) DISALLOW_GARBAGE_COLLECTION; std::ostringstream oss; auto value = JSTaggedValue(rawValue); - value.Dump(oss); + value.Dump(THREAD_ARG_PLACEHOLDER, oss); LOG_ECMA(INFO) << "dump log for read-only crash " << oss.str(); } @@ -740,7 +741,7 @@ void RuntimeStubs::DumpToStreamWithHint(std::ostream &out, std::string_view hint << std::setfill('0') << value.GetRawData() << ") "; out << std::dec << std::setfill(' '); // Recovers integer radix & fill character // Dumps tagged value - value.Dump(out); + value.Dump(THREAD_ARG_PLACEHOLDER, out); // End line out << dumpDelimiterLine << " End dump: " << hint << ' ' << dumpDelimiterLine; } @@ -847,7 +848,7 @@ DEF_RUNTIME_STUBS(GetNativePcOfstForBaseline) RUNTIME_STUBS_HEADER(GetNativePcOfstForBaseline); JSHandle func = GetHArg(argv, argc, 0); // 0: means the zeroth parameter uint64_t bytecodePc = static_cast(GetTArg(argv, argc, 1)); // 1: means the first parameter - return RuntimeGetNativePcOfstForBaseline(func, bytecodePc); + return RuntimeGetNativePcOfstForBaseline(thread, func, bytecodePc); } DEF_RUNTIME_STUBS(Inc) @@ -879,7 +880,7 @@ DEF_RUNTIME_STUBS(RegularJSObjDeletePrototype) uint32_t index = 0; if (value.IsString()) { auto string = JSHandle(thread, value); - if (EcmaStringAccessor(string).ToElementIndex(&index)) { + if (EcmaStringAccessor(string).ToElementIndex(thread, &index)) { value = JSTaggedValue(index); } else if (!EcmaStringAccessor(string).IsInternString()) { JSTaggedValue key(RuntimeTryGetInternString(argGlue, string)); @@ -979,7 +980,7 @@ DEF_RUNTIME_STUBS(DumpObject) JSHandle targetId = GetHArg(argv, argc, 1); // 1: means the first parameter LOG_ECMA(INFO) << "InstanceOf Stability Testing Num: " << targetId->GetInt(); std::ostringstream oss; - target->Dump(oss); + target->Dump(thread, oss); LOG_ECMA(INFO) << "dump log for instance of target: " << oss.str(); return JSTaggedValue::True().GetRawData(); } @@ -989,7 +990,7 @@ DEF_RUNTIME_STUBS(DumpHeapObjectAddress) RUNTIME_STUBS_HEADER(DumpHeapObjectAddress); JSHandle target = GetHArg(argv, argc, 0); // 0: means the zeroth parameter std::ostringstream oss; - target->DumpHeapObjAddress(oss); + target->DumpHeapObjAddress(thread, oss); LOG_ECMA(INFO) << "dump log for instance of target: " << oss.str(); return JSTaggedValue::True().GetRawData(); } @@ -1119,7 +1120,7 @@ DEF_RUNTIME_STUBS(SuperCallSpread) JSHandle func = GetHArg(argv, argc, 0); // 0: means the zeroth parameter JSHandle array = GetHArg(argv, argc, 1); // 1: means the first parameter auto sp = const_cast(thread->GetCurrentInterpretedFrame()); - JSTaggedValue function = InterpreterAssembly::GetNewTarget(sp); + JSTaggedValue function = InterpreterAssembly::GetNewTarget(thread, sp); return RuntimeSuperCallSpread(thread, func, JSHandle(thread, function), array).GetRawData(); } @@ -1138,9 +1139,9 @@ DEF_RUNTIME_STUBS(SuperCallForwardAllArgs) auto sp = const_cast(thread->GetCurrentInterpretedFrame()); JSHandle func = GetHArg(argv, argc, 0); // 0: index of child constructor JSHandle superFunc(thread, JSTaggedValue::GetPrototype(thread, func)); - auto newTarget = JSHandle(thread, InterpreterAssembly::GetNewTarget(sp)); + auto newTarget = JSHandle(thread, InterpreterAssembly::GetNewTarget(thread, sp)); uint32_t startIdx = 0; - uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(sp, 0, startIdx); // 0: rest args start idx + uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(thread, sp, 0, startIdx); // 0: rest args start idx return RuntimeSuperCallForwardAllArgs(thread, sp, superFunc, newTarget, restNumArgs, startIdx).GetRawData(); } @@ -1584,7 +1585,7 @@ DEF_RUNTIME_STUBS(LdSendableClass) RUNTIME_STUBS_HEADER(LdSendableClass); JSHandle env = GetHArg(argv, argc, 0); // 0: means the zeroth parameter uint16_t level = static_cast(GetArg(argv, argc, 1).GetInt()); // 1: means the first parameter - return RuntimeLdSendableClass(env, level).GetRawData(); + return RuntimeLdSendableClass(thread, env, level).GetRawData(); } DEF_RUNTIME_STUBS(SetClassConstructorLength) @@ -1600,8 +1601,8 @@ DEF_RUNTIME_STUBS(UpdateHotnessCounter) RUNTIME_STUBS_HEADER(UpdateHotnessCounter); JSHandle thisFunc = GetHArg(argv, argc, 0); // 0: means the zeroth parameter thread->CheckSafepoint(); - JSHandle method(thread, thisFunc->GetMethod()); - auto profileTypeInfo = thisFunc->GetProfileTypeInfo(); + JSHandle method(thread, thisFunc->GetMethod(thread)); + auto profileTypeInfo = thisFunc->GetProfileTypeInfo(thread); if (profileTypeInfo.IsUndefined()) { uint32_t slotSize = method->GetSlotSize(); auto res = RuntimeNotifyInlineCache(thread, thisFunc, slotSize); @@ -1631,9 +1632,9 @@ DEF_RUNTIME_STUBS(UpdateHotnessCounterWithProf) RUNTIME_STUBS_HEADER(UpdateHotnessCounterWithProf); JSHandle thisFunc = GetHArg(argv, argc, 0); // 0: means the zeroth parameter thread->CheckSafepoint(); - auto profileTypeInfo = thisFunc->GetProfileTypeInfo(); + auto profileTypeInfo = thisFunc->GetProfileTypeInfo(thread); if (profileTypeInfo.IsUndefined()) { - uint32_t slotSize = thisFunc->GetCallTarget()->GetSlotSize(); + uint32_t slotSize = thisFunc->GetCallTarget(thread)->GetSlotSize(); auto res = RuntimeNotifyInlineCache(thread, thisFunc, slotSize); return res.GetRawData(); } @@ -1662,7 +1663,7 @@ DEF_RUNTIME_STUBS(CountInterpExecFuncs) { RUNTIME_STUBS_HEADER(CountInterpExecFuncs); JSHandle thisFunc = GetHArg(argv, argc, 0); // 0: means the zeroth parameter - Jit::CountInterpExecFuncs(thisFunc); + Jit::CountInterpExecFuncs(thread, thisFunc); return JSTaggedValue::Undefined().GetRawData(); } @@ -1837,11 +1838,11 @@ DEF_RUNTIME_STUBS(UpFrame) reinterpret_cast(curNativePc); JSHandle funcVal = JSHandle(thread, frameHandler.GetFunction()); JSHandle func = JSHandle::Cast(funcVal); - curBytecodePcOfst = RuntimeGetBytecodePcOfstForBaseline(func, curNativePc); + curBytecodePcOfst = RuntimeGetBytecodePcOfstForBaseline(thread, func, curNativePc); } else { curBytecodePcOfst = frameHandler.GetBytecodeOffset(); } - pcOffset = method->FindCatchBlock(curBytecodePcOfst); + pcOffset = method->FindCatchBlock(thread, curBytecodePcOfst); if (pcOffset != INVALID_INDEX) { thread->SetCurrentFrame(frameHandler.GetSp()); thread->SetLastFp(frameHandler.GetFp()); @@ -2043,7 +2044,7 @@ DEF_RUNTIME_STUBS(HandleResolutionIsNullOrString) ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName(requiredModule.GetTaggedValue())); CString recordStr = ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName(module.GetTaggedValue())); CString msg = "the requested module '" + requestMod + SourceTextModule::GetResolveErrorReason(resolution) + - ModulePathHelper::Utf8ConvertToString(bindingName) + + ModulePathHelper::Utf8ConvertToString(thread, bindingName) + "' which imported by '" + recordStr + "'"; THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE( thread, ErrorType::SYNTAX_ERROR, msg.c_str(), JSTaggedValue::Exception().GetRawData()); @@ -2075,10 +2076,10 @@ DEF_RUNTIME_STUBS(GetResolvedRecordIndexBindingModule) JSTaggedType argModuleManager = GetTArg(argv, argc, 2); // 2: means the second parameter ModuleManager *moduleManager = reinterpret_cast(argModuleManager); JSTaggedValue recordName = GetArg(argv, argc, 3); // 3: means the third parameter - CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName); + CString recordNameStr = ModulePathHelper::Utf8ConvertToString(thread, recordName); if (!moduleManager->IsEvaluatedModule(recordNameStr)) { auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty(); - CString fileName = ModulePathHelper::Utf8ConvertToString((binding->GetAbcFileName())); + CString fileName = ModulePathHelper::Utf8ConvertToString(thread, (binding->GetAbcFileName(thread))); if (!JSPandaFileExecutor::LazyExecuteModule(thread, recordNameStr, fileName, isMergedAbc)) { // LCOV_EXCL_BR_LINE LOG_ECMA(FATAL) << "LazyExecuteModule failed"; @@ -2094,7 +2095,7 @@ DEF_RUNTIME_STUBS(GetResolvedRecordBindingModule) JSTaggedType argModuleManager = GetTArg(argv, argc, 1); // 1: means the first parameter ModuleManager *moduleManager = reinterpret_cast(argModuleManager); JSTaggedValue recordName = GetArg(argv, argc, 2); // 2: means the second parameter - CString recordNameStr = ModulePathHelper::Utf8ConvertToString(recordName); + CString recordNameStr = ModulePathHelper::Utf8ConvertToString(thread, recordName); if (!moduleManager->IsEvaluatedModule(recordNameStr)) { auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty(); CString fileName = module->GetEcmaModuleFilenameString(); @@ -2526,7 +2527,7 @@ DEF_RUNTIME_STUBS(MethodEntry) RUNTIME_STUBS_HEADER(MethodEntry); JSHandle func = GetHArg(argv, argc, 0); // 0: means the zeroth parameter if (func.GetTaggedValue().IsECMAObject()) { - Method *method = ECMAObject::Cast(func.GetTaggedValue().GetTaggedObject())->GetCallTarget(); + Method *method = ECMAObject::Cast(func.GetTaggedValue().GetTaggedObject())->GetCallTarget(thread); if (method->IsNativeWithCallField()) { return JSTaggedValue::Hole().GetRawData(); } @@ -2537,7 +2538,7 @@ DEF_RUNTIME_STUBS(MethodEntry) continue; } auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager(); - debuggerMgr->GetNotificationManager()->MethodEntryEvent(thread, method, funcObj->GetLexicalEnv()); + debuggerMgr->GetNotificationManager()->MethodEntryEvent(thread, method, funcObj->GetLexicalEnv(thread)); return JSTaggedValue::Hole().GetRawData(); } } @@ -2596,7 +2597,7 @@ DEF_RUNTIME_STUBS(GetUnmapedArgs) auto sp = const_cast(thread->GetCurrentInterpretedFrame()); uint32_t startIdx = 0; // 0: means restIdx - uint32_t actualNumArgs = InterpreterAssembly::GetNumArgs(sp, 0, startIdx); + uint32_t actualNumArgs = InterpreterAssembly::GetNumArgs(thread, sp, 0, startIdx); return RuntimeGetUnmapedArgs(thread, sp, actualNumArgs, startIdx).GetRawData(); } @@ -2606,7 +2607,7 @@ DEF_RUNTIME_STUBS(CopyRestArgs) JSTaggedValue restIdx = GetArg(argv, argc, 0); // 0: means the zeroth parameter auto sp = const_cast(thread->GetCurrentInterpretedFrame()); uint32_t startIdx = 0; - uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(sp, restIdx.GetInt(), startIdx); + uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(thread, sp, restIdx.GetInt(), startIdx); return RuntimeCopyRestArgs(thread, sp, restNumArgs, startIdx).GetRawData(); } @@ -2771,7 +2772,7 @@ DEF_RUNTIME_STUBS(SuperCall) JSTaggedValue firstVRegIdx = GetArg(argv, argc, 1); // 1: means the first parameter JSTaggedValue length = GetArg(argv, argc, 2); // 2: means the second parameter auto sp = const_cast(thread->GetCurrentInterpretedFrame()); - JSTaggedValue newTarget = InterpreterAssembly::GetNewTarget(sp); + JSTaggedValue newTarget = InterpreterAssembly::GetNewTarget(thread, sp); return RuntimeSuperCall(thread, func, JSHandle(thread, newTarget), static_cast(firstVRegIdx.GetInt()), static_cast(length.GetInt())).GetRawData(); @@ -3016,7 +3017,7 @@ DEF_RUNTIME_STUBS(ProfileOptimizedCode) EcmaOpcode ecmaOpcode = static_cast(GetArg(argv, argc, 2).GetInt()); OptCodeProfiler::Mode mode = static_cast(GetArg(argv, argc, 3).GetInt()); OptCodeProfiler* profiler = thread->GetEcmaVM()->GetOptCodeProfiler(); - profiler->Update(func, bcIndex, ecmaOpcode, mode); + profiler->Update(thread, func, bcIndex, ecmaOpcode, mode); return JSTaggedValue::Undefined().GetRawData(); } @@ -3040,20 +3041,20 @@ DEF_RUNTIME_STUBS(VerifyVTableLoading) JSHandle verifiedPathValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); - if (UNLIKELY(!JSTaggedValue::SameValue(typedPathValue, verifiedPathValue))) { + if (UNLIKELY(!JSTaggedValue::SameValue(thread, typedPathValue, verifiedPathValue))) { std::ostringstream oss; - receiver->Dump(oss); + receiver->Dump(thread, oss); LOG_ECMA(ERROR) << "Verify VTable Load Failed, receiver: " << oss.str(); oss.str(""); LOG_ECMA(ERROR) << "Verify VTable Load Failed, key: " - << EcmaStringAccessor(key.GetTaggedValue()).ToStdString(); + << EcmaStringAccessor(key.GetTaggedValue()).ToStdString(thread); - typedPathValue->Dump(oss); + typedPathValue->Dump(thread, oss); LOG_ECMA(ERROR) << "Verify VTable Load Failed, typed path value: " << oss.str(); oss.str(""); - verifiedPathValue->Dump(oss); + verifiedPathValue->Dump(thread, oss); LOG_ECMA(ERROR) << "Verify VTable Load Failed, verified path value: " << oss.str(); } return JSTaggedValue::Undefined().GetRawData(); @@ -3068,20 +3069,20 @@ DEF_RUNTIME_STUBS(VerifyVTableStoring) JSHandle verifiedValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); - if (UNLIKELY(!JSTaggedValue::SameValue(storeValue, verifiedValue))) { + if (UNLIKELY(!JSTaggedValue::SameValue(thread, storeValue, verifiedValue))) { std::ostringstream oss; - receiver->Dump(oss); + receiver->Dump(thread, oss); LOG_ECMA(ERROR) << "Verify VTable Store Failed, receiver: " << oss.str(); oss.str(""); LOG_ECMA(ERROR) << "Verify VTable Store Failed, key: " - << EcmaStringAccessor(key.GetTaggedValue()).ToStdString(); + << EcmaStringAccessor(key.GetTaggedValue()).ToStdString(thread); - storeValue->Dump(oss); + storeValue->Dump(thread, oss); LOG_ECMA(ERROR) << "Verify VTable Store Failed, typed path store value: " << oss.str(); oss.str(""); - verifiedValue->Dump(oss); + verifiedValue->Dump(thread, oss); LOG_ECMA(ERROR) << "Verify VTable Store Failed, verified path load value: " << oss.str(); } return JSTaggedValue::Undefined().GetRawData(); @@ -3116,7 +3117,7 @@ DEF_RUNTIME_STUBS(StringEqual) EcmaVM *vm = thread->GetEcmaVM(); left = JSHandle(thread, EcmaStringAccessor::Flatten(vm, left)); right = JSHandle(thread, EcmaStringAccessor::Flatten(vm, right)); - if (EcmaStringAccessor::StringsAreEqualDiffUtfEncoding(*left, *right)) { + if (EcmaStringAccessor::StringsAreEqualDiffUtfEncoding(thread, *left, *right)) { return JSTaggedValue::VALUE_TRUE; } return JSTaggedValue::VALUE_FALSE; @@ -3213,21 +3214,22 @@ DEF_RUNTIME_STUBS(ContainerRBTreeForEach) JSMutableHandle queue(thread, thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0)); JSMutableHandle treeNode(thread, JSTaggedValue::Undefined()); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, node))); - while (!queue->Empty()) { + while (!queue->Empty(thread)) { treeNode.Update(queue->Pop(thread)); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3: three args RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); info->SetCallArg(containersType == kungfu::ContainersType::HASHSET_FOREACH ? - treeNode->GetKey() : treeNode->GetValue(), treeNode->GetKey(), thisHandle.GetTaggedValue()); + treeNode->GetKey(thread) : treeNode->GetValue(thread), + treeNode->GetKey(thread), thisHandle.GetTaggedValue()); JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult.GetRawData()); - if (!treeNode->GetLeft().IsHole()) { - JSHandle left(thread, treeNode->GetLeft()); + if (!treeNode->GetLeft(thread).IsHole()) { + JSHandle left(thread, treeNode->GetLeft(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left))); } - if (!treeNode->GetRight().IsHole()) { - JSHandle right(thread, treeNode->GetRight()); + if (!treeNode->GetRight(thread).IsHole()) { + JSHandle right(thread, treeNode->GetRight(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right))); } } @@ -3303,7 +3305,7 @@ DEF_RUNTIME_STUBS(DecodeURIComponent) } } else { ASSERT(stringAcc.IsSlicedString()); - auto parent = SlicedEcmaString::Cast(string.GetTaggedValue())->GetParent(); + auto parent = SlicedEcmaString::Cast(string.GetTaggedValue())->GetParent(thread); auto parentStrAcc = EcmaStringAccessor(parent); auto startIndex = SlicedEcmaString::Cast(string.GetTaggedValue())->GetStartIndex(); #if !ENABLE_NEXT_OPTIMIZATION @@ -3326,11 +3328,11 @@ DEF_RUNTIME_STUBS(DecodeURIComponent) return result.GetRawData(); } -void RuntimeStubs::UpdateFieldType(JSTaggedType hclass, uint64_t value) +void RuntimeStubs::UpdateFieldType(uintptr_t argGlue, JSTaggedType hclass, uint64_t value) { auto cls = reinterpret_cast(hclass); PropertyAttributes attrValue(value); - JSHClass::UpdateFieldType(cls, attrValue); + JSHClass::UpdateFieldType(JSThread::GlueToJSThread(argGlue), cls, attrValue); } JSTaggedType RuntimeStubs::GetActualArgvNoGC(uintptr_t argGlue) @@ -3582,20 +3584,20 @@ void RuntimeStubs::CMCGCMarkingBarrier([[maybe_unused]] uintptr_t argGlue, JSTaggedType RuntimeStubs::ReadBarrier(uintptr_t argGlue, uintptr_t addr) { - (void)argGlue; - return Barriers::GetTaggedValue(addr); + auto thread = JSThread::GlueToJSThread(argGlue); + return Barriers::GetTaggedValue(thread, addr); } void RuntimeStubs::CopyCallTarget(uintptr_t argGlue, uintptr_t callTarget) { - (void)argGlue; - base::GCHelper::CopyCallTarget(reinterpret_cast(callTarget)); // callTarget should be ToSpace Reference + auto thread = JSThread::GlueToJSThread(argGlue); + base::GCHelper::CopyCallTarget(thread, reinterpret_cast(callTarget)); } void RuntimeStubs::CopyArgvArray(uintptr_t argGlue, uintptr_t argv, uint64_t argc) { - (void)argGlue; - base::GCHelper::CopyArgvArray(reinterpret_cast(argv), argc); // argv should be ToSpace Reference + auto thread = JSThread::GlueToJSThread(argGlue); + base::GCHelper::CopyArgvArray(thread, reinterpret_cast(argv), argc); // argv should be ToSpace Reference } bool RuntimeStubs::BigIntEquals(JSTaggedType left, JSTaggedType right) @@ -3610,17 +3612,19 @@ bool RuntimeStubs::BigIntSameValueZero(JSTaggedType left, JSTaggedType right) return BigInt::SameValueZero(JSTaggedValue(left), JSTaggedValue(right)); } -JSTaggedValue RuntimeStubs::JSHClassFindProtoTransitions(JSHClass *cls, JSTaggedValue key, JSTaggedValue proto) +JSTaggedValue RuntimeStubs::JSHClassFindProtoTransitions(uintptr_t argGlue, JSHClass *cls, JSTaggedValue key, + JSTaggedValue proto) { DISALLOW_GARBAGE_COLLECTION; - return JSTaggedValue(cls->FindProtoTransitions(key, proto)); + return JSTaggedValue(cls->FindProtoTransitions(JSThread::GlueToJSThread(argGlue), key, proto)); } -JSTaggedValue RuntimeStubs::NumberHelperStringToDouble(EcmaString *numberString) +JSTaggedValue RuntimeStubs::NumberHelperStringToDouble(uintptr_t argGlue, EcmaString *numberString) { DISALLOW_GARBAGE_COLLECTION; CVector buf; - Span str = EcmaStringAccessor(numberString).ToUtf8Span(buf); + JSThread *thread = JSThread::GlueToJSThread(argGlue); + Span str = EcmaStringAccessor(numberString).ToUtf8Span(thread, buf); if (base::NumberHelper::IsEmptyString(str.begin(), str.end())) { return base::BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); } @@ -3695,7 +3699,7 @@ void RuntimeStubs::SaveFrameToContext(JSThread *thread, JSHandleSetRegsArray(thread, regsArray.GetTaggedValue()); JSTaggedValue function = frameHandler.GetFunction(); JSFunction *func = JSFunction::Cast(function.GetTaggedObject()); - Method *method = func->GetCallTarget(); + Method *method = func->GetCallTarget(thread); if (func->IsCompiledCode()) { bool isFastCall = func->IsCompiledFastCall(); // get this flag before clear it uintptr_t entry = isFastCall ? thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_FastCallToAsmInterBridge) @@ -3724,19 +3728,19 @@ JSTaggedValue RuntimeStubs::CallBoundFunction(EcmaRuntimeCallInfo *info) { JSThread *thread = info->GetThread(); JSHandle boundFunc(info->GetFunction()); - if (boundFunc->GetBoundTarget().IsJSFunction()) { - JSHandle targetFunc(thread, boundFunc->GetBoundTarget()); + if (boundFunc->GetBoundTarget(thread).IsJSFunction()) { + JSHandle targetFunc(thread, boundFunc->GetBoundTarget(thread)); if (targetFunc->IsClassConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot called without 'new'", JSTaggedValue::Exception()); } } - JSHandle boundArgs(thread, boundFunc->GetBoundArguments()); + JSHandle boundArgs(thread, boundFunc->GetBoundArguments(thread)); const uint32_t boundLength = boundArgs->GetLength(); const uint32_t argsLength = info->GetArgsNumber() + boundLength; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, - JSHandle(thread, boundFunc->GetBoundTarget()), + JSHandle(thread, boundFunc->GetBoundTarget(thread)), info->GetThis(), undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boundLength == 0) { @@ -3772,12 +3776,12 @@ DEF_RUNTIME_STUBS(AotInlineTrace) JSTaggedValue inlineFunc = GetArg(argv, argc, 1); // 1: means the first parameter JSFunction *callerJSFunc = JSFunction::Cast(callerFunc); JSFunction *inlineJSFunc = JSFunction::Cast(inlineFunc); - Method *callerMethod = Method::Cast(JSFunction::Cast(callerJSFunc)->GetMethod()); - Method *inlineMethod = Method::Cast(JSFunction::Cast(inlineJSFunc)->GetMethod()); - auto callerRecordName = callerMethod->GetRecordNameStr(); - auto inlineRecordNanme = inlineMethod->GetRecordNameStr(); - const std::string callerFuncName(callerMethod->GetMethodName()); - const std::string inlineFuncNanme(inlineMethod->GetMethodName()); + Method *callerMethod = Method::Cast(JSFunction::Cast(callerJSFunc)->GetMethod(thread)); + Method *inlineMethod = Method::Cast(JSFunction::Cast(inlineJSFunc)->GetMethod(thread)); + auto callerRecordName = callerMethod->GetRecordNameStr(thread); + auto inlineRecordNanme = inlineMethod->GetRecordNameStr(thread); + const std::string callerFuncName(callerMethod->GetMethodName(thread)); + const std::string inlineFuncNanme(inlineMethod->GetMethodName(thread)); std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName); std::string inlineFullName = inlineFuncNanme + "@" + std::string(inlineRecordNanme); @@ -3790,9 +3794,9 @@ DEF_RUNTIME_STUBS(AotInlineBuiltinTrace) RUNTIME_STUBS_HEADER(AotInlineBuiltinTrace); JSTaggedValue callerFunc = GetArg(argv, argc, 0); JSFunction *callerJSFunc = JSFunction::Cast(callerFunc); - Method *callerMethod = Method::Cast(callerJSFunc->GetMethod()); - auto callerRecordName = callerMethod->GetRecordNameStr(); - const std::string callerFuncName(callerMethod->GetMethodName()); + Method *callerMethod = Method::Cast(callerJSFunc->GetMethod(thread)); + auto callerRecordName = callerMethod->GetRecordNameStr(thread); + const std::string callerFuncName(callerMethod->GetMethodName(thread)); std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName); auto builtinId = static_cast(GetArg(argv, argc, 1).GetInt()); @@ -3806,9 +3810,9 @@ DEF_RUNTIME_STUBS(AotCallBuiltinTrace) RUNTIME_STUBS_HEADER(AotCallBuiltinTrace); JSTaggedValue callerFunc = GetArg(argv, argc, 0); JSFunction *callerJSFunc = JSFunction::Cast(callerFunc); - Method *callerMethod = Method::Cast(callerJSFunc->GetMethod()); - auto callerRecordName = callerMethod->GetRecordNameStr(); - const std::string callerFuncName(callerMethod->GetMethodName()); + Method *callerMethod = Method::Cast(callerJSFunc->GetMethod(thread)); + auto callerRecordName = callerMethod->GetRecordNameStr(thread); + const std::string callerFuncName(callerMethod->GetMethodName(thread)); std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName); auto builtinId = static_cast(GetArg(argv, argc, 1).GetInt()); @@ -3856,9 +3860,9 @@ JSTaggedValue RuntimeStubs::RuntimeArraySort(JSThread *thread, JSHandle hclass(thread, thisObjHandle->GetClass()); if (!hclass->IsDictionaryElement()) { - JSHandle elements(thread, thisObjHandle->GetElements()); + JSHandle elements(thread, thisObjHandle->GetElements(thread)); // remove elements number check with pgo later and add int fast path at the same time - if (len <= elements->GetLength() && CheckElementsNumber(elements, len)) { + if (len <= elements->GetLength() && CheckElementsNumber(thread, elements, len)) { return ArrayNumberSort(thread, thisObjHandle, len); } } @@ -3883,13 +3887,13 @@ void RuntimeStubs::StartCallTimer(uintptr_t argGlue, JSTaggedType func, bool isA DISALLOW_GARBAGE_COLLECTION; auto thread = JSThread::GlueToJSThread(argGlue); JSTaggedValue callTarget(func); - Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod()); + Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod(thread)); if (method->IsNativeWithCallField()) { return; } size_t methodId = method->GetMethodId().GetOffset(); auto callTimer = thread->GetEcmaVM()->GetCallTimer(); - callTimer->InitialStatAndTimer(method, methodId, isAot); + callTimer->InitialStatAndTimer(thread, method, methodId, isAot); callTimer->StartCount(methodId, isAot); } @@ -3898,12 +3902,12 @@ void RuntimeStubs::EndCallTimer(uintptr_t argGlue, JSTaggedType func) DISALLOW_GARBAGE_COLLECTION; auto thread = JSThread::GlueToJSThread(argGlue); JSTaggedValue callTarget(func); - Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod()); + Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod(thread)); if (method->IsNativeWithCallField()) { return; } auto callTimer = thread->GetEcmaVM()->GetCallTimer(); - callTimer->StopCount(method); + callTimer->StopCount(thread, method); } int32_t RuntimeStubs::StringGetStart(bool isUtf8, EcmaString *srcString, int32_t length, int32_t startIndex) @@ -3979,7 +3983,7 @@ DEF_RUNTIME_STUBS(NameDictionaryGetAllEnumKeys) uint32_t keys = 0; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle keyArray = factory->NewTaggedArray(numOfKeys); - NameDictionary *dict = NameDictionary::Cast(object->GetProperties().GetTaggedObject()); + NameDictionary *dict = NameDictionary::Cast(object->GetProperties(thread).GetTaggedObject()); dict->GetAllEnumKeys(thread, 0, keyArray, &keys); if (keys < keyArray->GetLength()) { keyArray->Trim(thread, keys); @@ -4068,7 +4072,7 @@ DEF_RUNTIME_STUBS(ParseInt) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); } - return base::NumberHelper::StringToNumber(*numberString, radix).GetRawData(); + return base::NumberHelper::StringToNumber(thread, *numberString, radix).GetRawData(); } int RuntimeStubs::IntLexicographicCompare(JSTaggedType x, JSTaggedType y) @@ -4113,11 +4117,11 @@ DEF_RUNTIME_STUBS(LocaleCompareCacheable) return result.GetRawData(); } -JSTaggedValue RuntimeStubs::StringToNumber(JSTaggedType numberString, int32_t radix) +JSTaggedValue RuntimeStubs::StringToNumber(uintptr_t argGlue, JSTaggedType numberString, int32_t radix) { DISALLOW_GARBAGE_COLLECTION; auto input = EcmaString::Cast(JSTaggedValue(numberString)); - return base::NumberHelper::StringToNumber(input, radix); + return base::NumberHelper::StringToNumber(JSThread::GlueToJSThread(argGlue), input, radix); } void RuntimeStubs::ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newLength) @@ -4167,14 +4171,15 @@ static bool CompareFloat(T x, T y) return false; } -void RuntimeStubs::SortTypedArray(JSTypedArray *typedArray) +void RuntimeStubs::SortTypedArray(uintptr_t argGlue, JSTypedArray *typedArray) { DISALLOW_GARBAGE_COLLECTION; JSHClass *hclass = typedArray->GetClass(); const JSType jsType = hclass->GetObjectType(); - JSTaggedValue buffer = typedArray->GetViewedArrayBufferOrByteArray(); + JSThread *thread = JSThread::GlueToJSThread(argGlue); + JSTaggedValue buffer = typedArray->GetViewedArrayBufferOrByteArray(thread); const uint32_t len = typedArray->GetArrayLength(); - void *pointer = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(buffer); + void *pointer = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, buffer); switch (jsType) { case JSType::JS_INT8_ARRAY: std::sort(static_cast(pointer), static_cast(pointer) + len); @@ -4206,14 +4211,15 @@ void RuntimeStubs::SortTypedArray(JSTypedArray *typedArray) } } -void RuntimeStubs::ReverseTypedArray(JSTypedArray *typedArray) +void RuntimeStubs::ReverseTypedArray(uintptr_t argGlue, JSTypedArray *typedArray) { DISALLOW_GARBAGE_COLLECTION; JSHClass *hclass = typedArray->GetClass(); const JSType jsType = hclass->GetObjectType(); - JSTaggedValue buffer = typedArray->GetViewedArrayBufferOrByteArray(); + JSThread *thread = JSThread::GlueToJSThread(argGlue); + JSTaggedValue buffer = typedArray->GetViewedArrayBufferOrByteArray(thread); const uint32_t len = typedArray->GetArrayLength(); - void *pointer = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(buffer); + void *pointer = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, buffer); switch (jsType) { case JSType::JS_INT8_ARRAY: std::reverse(static_cast(pointer), static_cast(pointer) + len); @@ -4245,12 +4251,13 @@ void RuntimeStubs::ReverseTypedArray(JSTypedArray *typedArray) } } -void RuntimeStubs::FinishObjSizeTracking(JSHClass *cls) +void RuntimeStubs::FinishObjSizeTracking(uintptr_t argGlue, JSHClass *cls) { - uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(cls); + JSThread *thread = JSThread::GlueToJSThread(argGlue); + uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(thread, cls); if (finalInObjPropsNum < cls->GetInlinedProperties()) { // UpdateObjSize with finalInObjPropsNum - JSHClass::VisitTransitionAndUpdateObjSize(cls, finalInObjPropsNum); + JSHClass::VisitTransitionAndUpdateObjSize(thread, cls, finalInObjPropsNum); } } @@ -4307,8 +4314,8 @@ DEF_RUNTIME_STUBS(TraceLoadDetail) } else { auto prof = JSHandle::Cast(profile); auto slot = slotId.GetInt(); - auto first = prof->GetIcSlot(slot); - auto second = prof->GetIcSlot(slot + 1); + auto first = prof->GetIcSlot(thread, slot); + auto second = prof->GetIcSlot(thread, slot + 1); if (first.IsHole()) { if (second.IsHole()) { msg += "other-mega, "; @@ -4363,7 +4370,7 @@ DEF_RUNTIME_STUBS(TraceLoadDetail) while (value->IsECMAObject()) { depth++; auto currHC = value->GetTaggedObject()->GetClass(); - auto proto = currHC->GetProto(); + auto proto = currHC->GetProto(thread); value = JSHandle(thread, proto); } msg += "Depth: " + std::to_string(depth); @@ -4819,7 +4826,7 @@ DEF_RUNTIME_STUBS(GetCollationValueFromIcuCollator) JSHandle collator = GetHArg(argv, argc, 0); // 0: means the zeroth parameter UErrorCode status = U_ZERO_ERROR; - icu::Collator *icuCollator = collator->GetIcuCollator(); + icu::Collator *icuCollator = collator->GetIcuCollator(thread); icu::Locale icu_locale(icuCollator->getLocale(ULOC_VALID_LOCALE, status)); std::string collation_value = icu_locale.getUnicodeKeywordValue("co", status); @@ -4893,7 +4900,7 @@ void RuntimeStubs::ReverseArray(uintptr_t argGlue, JSTaggedType *dst, uint32_t l auto thread = JSThread::GlueToJSThread(argGlue); if (thread->IsCMCGCConcurrentCopying()) { for (uint32_t i = 0; i < length; i++) { - Barriers::UpdateSlot(dst, i * sizeof(JSTaggedType)); + Barriers::UpdateSlot(thread, dst, i * sizeof(JSTaggedType)); } } #else @@ -4913,8 +4920,9 @@ JSTaggedValue RuntimeStubs::FindPatchModule(uintptr_t argGlue, JSTaggedValue res void RuntimeStubs::FatalPrintMisstakenResolvedBinding(int32_t index, JSTaggedValue curModule) { DISALLOW_GARBAGE_COLLECTION; + JSThread *thread = JSThread::GetCurrent(); std::ostringstream oss; - curModule.Dump(oss); + curModule.Dump(thread, oss); LOG_ECMA(FATAL) << "Get module value failed, mistaken ResolvedBinding" << ", index: " << index << ", currentModule: " << oss.str(); UNREACHABLE(); diff --git a/ecmascript/stubs/runtime_stubs.h b/ecmascript/stubs/runtime_stubs.h index 73c8a075b7..a853fb63a1 100644 --- a/ecmascript/stubs/runtime_stubs.h +++ b/ecmascript/stubs/runtime_stubs.h @@ -137,17 +137,18 @@ public: static double FloatCbrt(double x); static double FloatCeil(double x); static double CallDateNow(); - static void UpdateFieldType(JSTaggedType hclass, uint64_t value); + static void UpdateFieldType(uintptr_t argGlue, JSTaggedType hclass, uint64_t value); static bool BigIntEquals(JSTaggedType left, JSTaggedType right); static bool BigIntSameValueZero(JSTaggedType key, JSTaggedType other); - static JSTaggedValue JSHClassFindProtoTransitions(JSHClass *cls, JSTaggedValue key, JSTaggedValue proto); - static void FinishObjSizeTracking(JSHClass *cls); - static JSTaggedValue NumberHelperStringToDouble(EcmaString *str); + static JSTaggedValue JSHClassFindProtoTransitions(uintptr_t argGlue, JSHClass *cls, + JSTaggedValue key, JSTaggedValue proto); + static void FinishObjSizeTracking(uintptr_t argGlue, JSHClass *cls); + static JSTaggedValue NumberHelperStringToDouble(uintptr_t argGlue, EcmaString *str); static JSTaggedValue GetStringToListCacheArray(uintptr_t argGlue); static int IntLexicographicCompare(JSTaggedType x, JSTaggedType y); static int DoubleLexicographicCompare(JSTaggedType x, JSTaggedType y); static int FastArraySortString(uintptr_t argGlue, JSTaggedValue x, JSTaggedValue y); - static JSTaggedValue StringToNumber(JSTaggedType numberString, int32_t radix); + static JSTaggedValue StringToNumber(uintptr_t argGlue, JSTaggedType numberString, int32_t radix); static void ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newLength); static double TimeClip(double time); static double SetDateValues(double year, double month, double day); @@ -161,10 +162,12 @@ public: static int32_t StringGetEnd(bool isUtf8, EcmaString *srcString, int32_t start, int32_t length, int32_t startIndex); static void CopyTypedArrayBuffer(uintptr_t argGlue, JSTypedArray *srcArray, JSTypedArray *targetArray, int32_t srcStartPos, int32_t tarStartPos, int32_t count); - static inline uint32_t RuntimeGetBytecodePcOfstForBaseline(const JSHandle &func, uintptr_t nativePc); - static void ReverseTypedArray(JSTypedArray *typedArray); - static void SortTypedArray(JSTypedArray *typedArray); - static inline uintptr_t RuntimeGetNativePcOfstForBaseline(const JSHandle &func, uint64_t bytecodePos); + static inline uint32_t RuntimeGetBytecodePcOfstForBaseline(JSThread *thread, + const JSHandle &func, uintptr_t nativePc); + static void ReverseTypedArray(uintptr_t argGlue, JSTypedArray *typedArray); + static void SortTypedArray(uintptr_t argGlue, JSTypedArray *typedArray); + static inline uintptr_t RuntimeGetNativePcOfstForBaseline(JSThread *thread, + const JSHandle &func, uint64_t bytecodePos); static void ObjectCopy(uintptr_t argGlue, JSTaggedType *dst, JSTaggedType *src, uint32_t count); static void FillObject(JSTaggedType *dst, JSTaggedType value, uint32_t count); static void ReverseArray(uintptr_t argGlue, JSTaggedType *dst, uint32_t length); @@ -278,7 +281,8 @@ private: const JSHandle &constpool, uint16_t methodId, uint16_t literalId, uint16_t length, const JSHandle &module); - static inline JSTaggedValue RuntimeLdSendableClass(const JSHandle &env, uint16_t level); + static inline JSTaggedValue RuntimeLdSendableClass(JSThread *thread, const JSHandle &env, + uint16_t level); static inline JSTaggedValue RuntimeSetClassInheritanceRelationship(JSThread *thread, const JSHandle &ctor, const JSHandle &base, @@ -525,7 +529,7 @@ private: static inline JSTaggedValue RuntimeUpdateAOTHClass(JSThread *thread, const JSHandle &oldhclass, const JSHandle &newhclass, JSTaggedValue key); static inline JSTaggedValue RuntimeNotifyDebuggerStatement(JSThread *thread); - static inline bool CheckElementsNumber(JSHandle elements, uint32_t len); + static inline bool CheckElementsNumber(const JSThread *thread, JSHandle elements, uint32_t len); static inline JSHandle GetOrCreateNumberString(JSThread *thread, JSHandle presentValue, std::map> &cachedString); static inline JSTaggedValue TryCopyCOWArray(JSThread *thread, JSHandle holderHandler, bool &isCOWArray); diff --git a/ecmascript/stubs/test_runtime_stubs.cpp b/ecmascript/stubs/test_runtime_stubs.cpp index aafb9ab494..97e66e7f71 100644 --- a/ecmascript/stubs/test_runtime_stubs.cpp +++ b/ecmascript/stubs/test_runtime_stubs.cpp @@ -112,7 +112,7 @@ DEF_RUNTIME_STUBS(DefineProxyFunc) JSHandle proxyHandle = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); ASSERT(*proxyHandle != nullptr); // check taggedvalue - proxyHandle.GetTaggedValue().D(); + proxyHandle.GetTaggedValue().D(thread); return proxyHandle.GetTaggedValue().GetRawData(); } @@ -131,7 +131,7 @@ DEF_RUNTIME_STUBS(DefineProxyHandler) // 1. handler has "Call" JSHandle funcKey = thread->GlobalConstants()->GetHandledApplyString(); JSObject::SetProperty(thread, JSHandle(handlerHandle), funcKey, funcHandle); - handlerHandle.GetTaggedValue().D(); + handlerHandle.GetTaggedValue().D(thread); return handlerHandle.GetTaggedValue().GetRawData(); } @@ -145,9 +145,9 @@ DEF_RUNTIME_STUBS(DefineProxyFunc2) ASSERT(targetHandle->IsECMAObject()); JSHandle proxyHandle = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); - targetHandle.GetTaggedValue().D(); - handlerHandle.GetTaggedValue().D(); - proxyHandle.GetTaggedValue().D(); + targetHandle.GetTaggedValue().D(thread); + handlerHandle.GetTaggedValue().D(thread); + proxyHandle.GetTaggedValue().D(thread); ASSERT(*proxyHandle != nullptr); return proxyHandle.GetTaggedValue().GetRawData(); } @@ -157,7 +157,7 @@ DEF_RUNTIME_STUBS(DumpTaggedType) RUNTIME_STUBS_HEADER(DumpTaggedType); CONVERT_ARG_HANDLE_CHECKED(JSTaggedValue, value, 0); ASSERT(value->IsECMAObject()); - value->D(); + value->D(thread); return value.GetTaggedValue().GetRawData(); } #endif diff --git a/ecmascript/symbol_table.h b/ecmascript/symbol_table.h index 4cbe4feba2..1614b41b54 100644 --- a/ecmascript/symbol_table.h +++ b/ecmascript/symbol_table.h @@ -47,7 +47,7 @@ public: { return ENTRY_SIZE; } - static inline bool IsMatch(const JSTaggedValue &name, const JSTaggedValue &other) + static inline bool IsMatch(const JSThread *thread, const JSTaggedValue &name, const JSTaggedValue &other) { if (name.IsHole() || name.IsUndefined()) { return false; @@ -55,14 +55,14 @@ public: auto *nameString = static_cast(name.GetTaggedObject()); auto *otherString = static_cast(other.GetTaggedObject()); - return EcmaStringAccessor::StringsAreEqual(nameString, otherString); + return EcmaStringAccessor::StringsAreEqual(thread, nameString, otherString); } - static inline uint32_t Hash(const JSTaggedValue &obj) + static inline uint32_t Hash(const JSThread *thread, const JSTaggedValue &obj) { if (obj.IsHeapObject()) { if (obj.IsString()) { auto *nameString = static_cast(obj.GetTaggedObject()); - return EcmaStringAccessor(nameString).GetHashcode(); + return EcmaStringAccessor(nameString).GetHashcode(thread); } return JSSymbol::ComputeHash(); } @@ -76,31 +76,31 @@ public: return HashTable::Create(thread, numberOfElements); } - inline bool ContainsKey(const JSTaggedValue &key) + inline bool ContainsKey(const JSThread *thread, const JSTaggedValue &key) { - int entry = FindEntry(key); + int entry = FindEntry(thread, key); return entry != -1; } - inline JSTaggedValue GetSymbol(const JSTaggedValue &key) + inline JSTaggedValue GetSymbol(const JSThread *thread, const JSTaggedValue &key) { - int entry = FindEntry(key); + int entry = FindEntry(thread, key); ASSERT(entry != -1); - return GetValue(entry); + return GetValue(thread, entry); } - inline JSTaggedValue FindSymbol(const JSTaggedValue &value) + inline JSTaggedValue FindSymbol(JSThread *thread, const JSTaggedValue &value) { JSSymbol *symbol = JSSymbol::Cast(value.GetTaggedObject()); - JSTaggedValue des = symbol->GetDescription(); + JSTaggedValue des = symbol->GetDescription(thread); if (!des.IsUndefined()) { - if (ContainsKey(des)) { + if (ContainsKey(thread, des)) { return des; } } return JSTaggedValue::Undefined(); } - static int ComputeCompactSize([[maybe_unused]] const JSHandle &table, int computeHashTableSize, + static int ComputeCompactSize([[maybe_unused]] const JSThread *thread, [[maybe_unused]] const JSHandle &table, int computeHashTableSize, [[maybe_unused]] int tableSize, [[maybe_unused]] int addedElements) { return computeHashTableSize; diff --git a/ecmascript/tagged_array-inl.h b/ecmascript/tagged_array-inl.h index 6b35c46b3d..4611a1511b 100644 --- a/ecmascript/tagged_array-inl.h +++ b/ecmascript/tagged_array-inl.h @@ -52,14 +52,22 @@ inline void TaggedArray::Set(const JSThread *thread, uint32_t idx, const T &valu #define MAYBE_INLINE #endif // ECMASCRIPT_TAGGED_ARRAY_CPP -MAYBE_INLINE JSTaggedValue TaggedArray::Get(uint32_t idx) const +MAYBE_INLINE JSTaggedValue TaggedArray::Get(const JSThread *thread, uint32_t idx) const { ASSERT(idx < GetLength()); // Note: Here 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. size_t offset = JSTaggedValue::TaggedTypeSize() * idx; // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) - return JSTaggedValue(Barriers::GetTaggedValue(reinterpret_cast(ToUintPtr(this)), + return JSTaggedValue(Barriers::GetTaggedValue(thread, GetData(), offset)); +} + +MAYBE_INLINE JSTaggedValue TaggedArray::GetPrimitive(uint32_t idx) const +{ + ASSERT(idx < GetLength()); + size_t offset = JSTaggedValue::TaggedTypeSize() * idx; + // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) + return JSTaggedValue(Barriers::GetPrimitive(reinterpret_cast(ToUintPtr(this)), DATA_OFFSET + offset)); } diff --git a/ecmascript/tagged_array.cpp b/ecmascript/tagged_array.cpp index 072af1bdae..1686de53f8 100644 --- a/ecmascript/tagged_array.cpp +++ b/ecmascript/tagged_array.cpp @@ -22,27 +22,22 @@ namespace panda::ecmascript { -JSTaggedValue TaggedArray::Get([[maybe_unused]] const JSThread *thread, uint32_t idx) const -{ - return Get(idx); -} - -uint32_t TaggedArray::GetIdx(const JSTaggedValue &value) const +uint32_t TaggedArray::GetIdx(const JSThread *thread, const JSTaggedValue &value) const { uint32_t length = GetLength(); for (uint32_t i = 0; i < length; i++) { - if (JSTaggedValue::SameValue(Get(i), value)) { + if (JSTaggedValue::SameValue(thread, Get(thread, i), value)) { return i; } } return TaggedArray::MAX_ARRAY_INDEX; } -JSTaggedValue TaggedArray::GetBit(uint32_t idx, uint32_t bitOffset) const +JSTaggedValue TaggedArray::GetBit(const JSThread *thread, uint32_t idx, uint32_t bitOffset) const { ASSERT(idx < GetLength()); - JSTaggedType element = Get(idx).GetRawData(); + JSTaggedType element = Get(thread, idx).GetRawData(); return JSTaggedValue(int((element >> bitOffset) & 1ULL)); } @@ -50,7 +45,7 @@ JSTaggedValue TaggedArray::GetBit(uint32_t idx, uint32_t bitOffset) const void TaggedArray::SetBit(const JSThread *thread, uint32_t idx, uint32_t bitOffset, const JSTaggedValue &value) { ASSERT(idx < GetLength()); - JSTaggedType element = Get(idx).GetRawData(); + JSTaggedType element = Get(thread, idx).GetRawData(); if (value.IsZero()) { element &= ~(1ULL << bitOffset); } else { @@ -69,10 +64,10 @@ JSHandle TaggedArray::Append(const JSThread *thread, const JSHandle JSHandle argument = factory->NewTaggedArray(length); uint32_t index = 0; for (; index < firstLength; ++index) { - argument->Set(thread, index, first->Get(index)); + argument->Set(thread, index, first->Get(thread, index)); } for (; index < length; ++index) { - argument->Set(thread, index, second->Get(index - firstLength)); + argument->Set(thread, index, second->Get(thread, index - firstLength)); } return argument; } @@ -88,7 +83,7 @@ JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const JSHandle argument = factory->NewTaggedArray(copyLength); uint32_t index = 0; for (; index < firstLength; ++index) { - JSTaggedValue val = first->Get(index); + JSTaggedValue val = first->Get(thread, index); if (val.IsHole()) { break; } @@ -96,7 +91,7 @@ JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const ASSERT(copyLength >= index); } for (uint32_t i = 0; i < secondLength; ++i) { - JSTaggedValue val = second->Get(i); + JSTaggedValue val = second->Get(thread, i); if (val.IsHole()) { break; } @@ -106,12 +101,12 @@ JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const return argument; } -bool TaggedArray::HasDuplicateEntry() const +bool TaggedArray::HasDuplicateEntry(const JSThread *thread) const { uint32_t length = GetLength(); for (uint32_t i = 0; i < length; i++) { for (uint32_t j = i + 1; j < length; j++) { - if (JSTaggedValue::SameValue(Get(i), Get(j))) { + if (JSTaggedValue::SameValue(thread, Get(thread, i), Get(thread, j))) { return true; } } @@ -170,7 +165,7 @@ void TaggedArray::RemoveElementByIndex(const JSThread *thread, JSHandleSet(thread, index, srcArray->Get(index + 1)); + srcArray->Set(thread, index, srcArray->Get(thread, index + 1)); index++; } } @@ -183,7 +178,7 @@ void TaggedArray::InsertElementByIndex(const JSThread *thread, JSHandleGetLength()); while (effectiveLength != index && effectiveLength > 0) { - JSTaggedValue oldValue = srcArray->Get(effectiveLength - 1); + JSTaggedValue oldValue = srcArray->Get(thread, effectiveLength - 1); srcArray->Set(thread, effectiveLength, oldValue); effectiveLength--; } diff --git a/ecmascript/tagged_array.h b/ecmascript/tagged_array.h index e2665eaf33..b9b99faab3 100644 --- a/ecmascript/tagged_array.h +++ b/ecmascript/tagged_array.h @@ -34,12 +34,11 @@ public: CAST_CHECK(TaggedArray, IsTaggedArray); - JSTaggedValue Get(uint32_t idx) const; + JSTaggedValue Get(const JSThread *thread, uint32_t idx) const; + JSTaggedValue GetPrimitive(uint32_t idx) const; - JSTaggedValue Get([[maybe_unused]] const JSThread *thread, uint32_t idx) const; - - uint32_t GetIdx(const JSTaggedValue &value) const; - JSTaggedValue GetBit(uint32_t idx, uint32_t bitOffset) const; + uint32_t GetIdx(const JSThread *thread, const JSTaggedValue &value) const; + JSTaggedValue GetBit(const JSThread *thread, uint32_t idx, uint32_t bitOffset) const; template inline void Set(const JSThread *thread, uint32_t idx, const T &value); @@ -74,7 +73,7 @@ public: bool IsDictionaryMode() const; - bool HasDuplicateEntry() const; + bool HasDuplicateEntry(const JSThread *thread) const; bool IsYoungAndNotMarking(const JSThread *thread); diff --git a/ecmascript/tagged_dictionary.cpp b/ecmascript/tagged_dictionary.cpp index fe4ba21854..bf8a4cfd7e 100644 --- a/ecmascript/tagged_dictionary.cpp +++ b/ecmascript/tagged_dictionary.cpp @@ -18,7 +18,7 @@ #include "ecmascript/js_object-inl.h" namespace panda::ecmascript { -int NameDictionary::Hash(const JSTaggedValue &key) +int NameDictionary::Hash(const JSThread *thread, const JSTaggedValue &key) { if (key.IsHeapObject()) { JSTaggedValue jsKey(key); @@ -28,7 +28,7 @@ int NameDictionary::Hash(const JSTaggedValue &key) } if (jsKey.IsString()) { auto keyString = reinterpret_cast(key.GetTaggedObject()); - return EcmaStringAccessor(keyString).GetHashcode(); + return EcmaStringAccessor(keyString).GetHashcode(thread); } } // key must be object @@ -42,7 +42,8 @@ int NameDictionary::Hash(const uint8_t* str, int strSize) return BaseString::ComputeHashForData(str, strSize, 0); } -bool NameDictionary::IsMatch(const JSTaggedValue &key, const JSTaggedValue &other) +bool NameDictionary::IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &other) { return key == other; } @@ -68,9 +69,9 @@ void NameDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray int size = Size(); CVector> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); std::pair pair(key, attr); sortArr.push_back(pair); } @@ -86,9 +87,9 @@ void NameDictionary::UpdateAllAttributesToNoWitable(const JSThread *thread) { int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); attr.SetWritable(false); SetAttributes(thread, hashIndex, attr); } @@ -101,9 +102,9 @@ void NameDictionary::GetAllKeysByFilter(const JSThread *thread, uint32_t &keyArr int size = Size(); CVector> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); bool bIgnore = FilterHelper::IgnoreKeyByFilter(attr, filter); if (bIgnore) { continue; @@ -125,15 +126,15 @@ void NameDictionary::GetAllKeysByFilter(const JSThread *thread, uint32_t &keyArr } } -std::pair NameDictionary::GetNumOfEnumKeys() const +std::pair NameDictionary::GetNumOfEnumKeys(const JSThread *thread) const { uint32_t enumKeys = 0; uint32_t shadowKeys = 0; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (key.IsString()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); if (attr.IsEnumerable()) { enumKeys++; } else { @@ -151,9 +152,9 @@ void NameDictionary::GetAllEnumKeys(JSThread *thread, int offset, JSHandle, PropertyAttributes>> sortArr; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSHandle keyHandle(thread, GetKey(hashIndex)); + JSHandle keyHandle(thread, GetKey(thread, hashIndex)); if (keyHandle->IsString()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); if (attr.IsEnumerable()) { std::pair, PropertyAttributes> pair(keyHandle, attr); bool isDuplicated = JSObject::IsDepulicateKeys(thread, keyArray, lastLength, shadowQueue, keyHandle); @@ -180,9 +181,9 @@ void NameDictionary::GetAllEnumKeys(JSThread *thread, int offset, JSHandle, PropertyAttributes>> sortArr; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSHandle keyHandle(thread, GetKey(hashIndex)); + JSHandle keyHandle(thread, GetKey(thread, hashIndex)); if (keyHandle->IsString()) { - PropertyAttributes attr = GetAttributes(hashIndex); + PropertyAttributes attr = GetAttributes(thread, hashIndex); if (attr.IsEnumerable()) { std::pair, PropertyAttributes> pair(keyHandle, attr); sortArr.push_back(pair); @@ -207,10 +208,10 @@ JSHandle NameDictionary::CreateInSharedHeap(const JSThread *thre return OrderHashTableT::Create(thread, numberOfElements, MemSpaceKind::SHARED); } -PropertyAttributes NameDictionary::GetAttributes(int entry) const +PropertyAttributes NameDictionary::GetAttributes(const JSThread *thread, int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return PropertyAttributes(Get(index)); + return PropertyAttributes(Get(thread, index)); } void NameDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) @@ -246,7 +247,7 @@ void NameDictionary::ClearEntry(const JSThread *thread, int entry) SetEntry(thread, entry, hole, hole, metaData); } -int NumberDictionary::Hash(const JSTaggedValue &key) +int NumberDictionary::Hash([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key) { if (key.IsInt()) { int keyValue = key.GetInt(); @@ -261,7 +262,8 @@ int NumberDictionary::Hash(const JSTaggedValue &key) UNREACHABLE(); } -bool NumberDictionary::IsMatch(const JSTaggedValue &key, const JSTaggedValue &other) +bool NumberDictionary::IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &other) { if (key.IsHole() || key.IsUndefined()) { return false; @@ -298,7 +300,7 @@ void NumberDictionary::GetAllKeys(const JSThread *thread, const JSHandleSize(); CVector sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = obj->GetKey(hashIndex); + JSTaggedValue key = obj->GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { sortArr.push_back(JSTaggedValue(static_cast(key.GetInt()))); } @@ -323,12 +325,12 @@ void NumberDictionary::GetAllKeysByFilter(const JSThread *thread, const JSHandle CVector sortArr; uint32_t size = static_cast(obj->Size()); for (uint32_t hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = obj->GetKey(hashIndex); + JSTaggedValue key = obj->GetKey(thread, hashIndex); if (key.IsUndefined() || key.IsHole()) { continue; } - PropertyAttributes attr = obj->GetAttributes(hashIndex); + PropertyAttributes attr = obj->GetAttributes(thread, hashIndex); bool bIgnore = FilterHelper::IgnoreKeyByFilter(attr, filter); if (!bIgnore) { sortArr.push_back(JSTaggedValue(static_cast(key.GetInt()))); @@ -351,9 +353,9 @@ void NumberDictionary::GetAllEnumKeys(JSThread *thread, const JSHandleSize(); CVector sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = obj->GetKey(hashIndex); + JSTaggedValue key = obj->GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = obj->GetAttributes(hashIndex); + PropertyAttributes attr = obj->GetAttributes(thread, hashIndex); if (attr.IsEnumerable()) { sortArr.push_back(JSTaggedValue(static_cast(key.GetInt()))); } @@ -388,10 +390,10 @@ JSHandle NumberDictionary::CreateInSharedHeap(const JSThread * return OrderHashTableT::Create(thread, numberOfElements, MemSpaceKind::SHARED); } -PropertyAttributes NumberDictionary::GetAttributes(int entry) const +PropertyAttributes NumberDictionary::GetAttributes(const JSThread *thread, int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return PropertyAttributes(Get(index)); + return PropertyAttributes(Get(thread, index)); } void NumberDictionary::SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData) @@ -439,7 +441,7 @@ JSHandle PointerToIndexDictionary::PutIfAbsent( const JSHandle &value) { /* no need to add key if exist */ - int entry = dictionary->FindEntry(key.GetTaggedValue()); + int entry = dictionary->FindEntry(thread, key.GetTaggedValue()); if (entry != -1) { return dictionary; } @@ -447,8 +449,8 @@ JSHandle PointerToIndexDictionary::PutIfAbsent( JSHandle newDictionary = HashTableT::GrowHashTable(thread, dictionary); // Compute the key object - uint32_t hash = static_cast(PointerToIndexDictionary::Hash(key.GetTaggedValue())); - entry = newDictionary->FindInsertIndex(hash); + uint32_t hash = static_cast(PointerToIndexDictionary::Hash(thread, key.GetTaggedValue())); + entry = newDictionary->FindInsertIndex(thread, hash); newDictionary->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue()); newDictionary->IncreaseEntries(thread); return newDictionary; @@ -496,10 +498,10 @@ void FunctionProtoTransitionTable::InsertTransitionItem(const JSThread *thread, JSHandle transPhc) { JSHandle protoTransitionHandle(thread, protoTransitionTable_); - int32_t entry1 = protoTransitionHandle->FindEntry(ihc.GetTaggedValue()); + int32_t entry1 = protoTransitionHandle->FindEntry(thread, ihc.GetTaggedValue()); if (entry1 != -1) { - JSHandle protoArray(thread, protoTransitionHandle->GetValue(entry1)); - auto entry2 = protoArray->FindEntry(baseIhc.GetTaggedValue()); + JSHandle protoArray(thread, protoTransitionHandle->GetValue(thread, entry1)); + auto entry2 = protoArray->FindEntry(thread, baseIhc.GetTaggedValue()); if (entry2 != -1) { LOG_ECMA(DEBUG) << "Record prototype for current function already!"; return; @@ -524,18 +526,18 @@ std::pair FunctionProtoTransitionTable::FindTransi ASSERT(ihc->IsJSHClass()); ASSERT(baseIhc->IsJSHClass()); JSHandle protoTransitionHandle(thread, protoTransitionTable_); - int32_t entry1 = protoTransitionHandle->FindEntry(ihc.GetTaggedValue()); + int32_t entry1 = protoTransitionHandle->FindEntry(thread, ihc.GetTaggedValue()); if (entry1 == -1) { LOG_ECMA(DEBUG) << "Selected ihc not found2!"; return std::make_pair(JSTaggedValue::Undefined(), JSTaggedValue::Undefined()); } - JSHandle protoArray(thread, protoTransitionHandle->GetValue(entry1)); - int32_t entry2 = protoArray->FindEntry(baseIhc.GetTaggedValue()); + JSHandle protoArray(thread, protoTransitionHandle->GetValue(thread, entry1)); + int32_t entry2 = protoArray->FindEntry(thread, baseIhc.GetTaggedValue()); if (entry2 == -1) { LOG_ECMA(ERROR) << "Selected baseIhc not found!"; return std::make_pair(JSTaggedValue::Undefined(), JSTaggedValue::Undefined()); } - return protoArray->GetTransition(entry2); + return protoArray->GetTransition(thread, entry2); } bool FunctionProtoTransitionTable::TryInsertFakeParentItem(JSTaggedType child, JSTaggedType parent) @@ -606,40 +608,40 @@ void ProtoArray::SetEntry(const JSThread *thread, uint32_t index, JSTaggedValue Set(thread, phcIndex, transPhc); } -JSTaggedValue ProtoArray::GetKey(uint32_t index) const +JSTaggedValue ProtoArray::GetKey(const JSThread *thread, uint32_t index) const { uint32_t entryIndex = index * ENTRY_SIZE; uint32_t keyIndex = entryIndex + KEY_INDEX; - return Get(keyIndex); + return Get(thread, keyIndex); } -std::pair ProtoArray::GetTransition(uint32_t index) const +std::pair ProtoArray::GetTransition(const JSThread *thread, uint32_t index) const { uint32_t entryIndex = index * ENTRY_SIZE + KEY_INDEX; - JSTaggedValue transIhc = Get(entryIndex + TRANS_IHC_INDEX); - JSTaggedValue transPhc = Get(entryIndex + TRANS_PHC_INDEX); + JSTaggedValue transIhc = Get(thread, entryIndex + TRANS_IHC_INDEX); + JSTaggedValue transPhc = Get(thread, entryIndex + TRANS_PHC_INDEX); return std::make_pair(transIhc, transPhc); } -std::pair ProtoArray::FindTransition(JSTaggedValue key) const +std::pair ProtoArray::FindTransition(const JSThread *thread, JSTaggedValue key) const { for (uint32_t i = 0; i < ENTRY_NUMBER; i++) { uint32_t index = i * ENTRY_SIZE + KEY_INDEX; - JSTaggedValue keyValue = Get(index); + JSTaggedValue keyValue = Get(thread, index); if (keyValue == key) { - JSTaggedValue transIhc = Get(index + TRANS_IHC_INDEX); - JSTaggedValue transPhc = Get(index + TRANS_PHC_INDEX); + JSTaggedValue transIhc = Get(thread, index + TRANS_IHC_INDEX); + JSTaggedValue transPhc = Get(thread, index + TRANS_PHC_INDEX); return std::make_pair(transIhc, transPhc); } } return std::make_pair(JSTaggedValue::Undefined(), JSTaggedValue::Undefined()); } -int32_t ProtoArray::FindEntry(JSTaggedValue key) const +int32_t ProtoArray::FindEntry(const JSThread *thread, JSTaggedValue key) const { for (uint32_t i = 0; i < ENTRY_NUMBER; i++) { uint32_t index = i * ENTRY_SIZE + KEY_INDEX; - JSTaggedValue keyValue = Get(index); + JSTaggedValue keyValue = Get(thread, index); if (keyValue == key) { return i; } diff --git a/ecmascript/tagged_dictionary.h b/ecmascript/tagged_dictionary.h index 2e954860a5..4b02e70304 100644 --- a/ecmascript/tagged_dictionary.h +++ b/ecmascript/tagged_dictionary.h @@ -41,10 +41,11 @@ public: { return ENTRY_SIZE; } - static int PUBLIC_API Hash(const JSTaggedValue &key); + static int PUBLIC_API Hash(const JSThread *thread, const JSTaggedValue &key); static int Hash(const uint8_t* str, int strSize); - static bool PUBLIC_API IsMatch(const JSTaggedValue &key, const JSTaggedValue &other); + static bool PUBLIC_API IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &other); static bool IsMatch(const uint8_t* str, int size, const JSTaggedValue &other); static JSHandle Create(const JSThread *thread, @@ -52,7 +53,7 @@ public: static JSHandle PUBLIC_API CreateInSharedHeap(const JSThread *thread, int numberOfElements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); // Returns the property metaData for the property at entry. - PropertyAttributes PUBLIC_API GetAttributes(int entry) const; + PropertyAttributes PUBLIC_API GetAttributes(const JSThread *thread, int entry) const; void PUBLIC_API SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData); void PUBLIC_API SetEntry(const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, const PropertyAttributes &metaData); @@ -65,7 +66,7 @@ public: void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const; void GetAllKeysByFilter(const JSThread *thread, uint32_t &keyArrayEffectivelength, TaggedArray *keyArray, uint32_t filter) const; - std::pair GetNumOfEnumKeys() const; + std::pair GetNumOfEnumKeys(const JSThread *thread) const; void GetAllEnumKeys(JSThread *thread, int offset, JSHandle keyArray, uint32_t *keys, JSHandle shadowQueue, int32_t lastLength) const; void GetAllEnumKeys(JSThread *thread, int offset, JSHandle keyArray, uint32_t *keys) const; @@ -84,12 +85,12 @@ public: { return a.GetDictionaryOrder() < b.GetDictionaryOrder(); } - void Dump(std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; - void Dump() const DUMP_API_ATTR + void Dump(const JSThread *thread, std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; + void Dump(const JSThread *thread) const DUMP_API_ATTR { - Dump(std::cout); + Dump(thread, std::cout); } - void DumpForSnapshot(std::vector &vec) const; + void DumpForSnapshot(const JSThread *thread, std::vector &vec) const; static constexpr int ENTRY_KEY_INDEX = 0; static constexpr int ENTRY_VALUE_INDEX = 1; @@ -116,14 +117,15 @@ public: { return ENTRY_SIZE; } - static int PUBLIC_API Hash(const JSTaggedValue &key); - static bool PUBLIC_API IsMatch(const JSTaggedValue &key, const JSTaggedValue &other); + static int PUBLIC_API Hash([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key); + static bool PUBLIC_API IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, + const JSTaggedValue &other); static JSHandle Create(const JSThread *thread, int numberOfElements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); static JSHandle CreateInSharedHeap( const JSThread *thread, int numberOfElements = OrderHashTableT::DEFAULT_ELEMENTS_NUMBER); // Returns the property metaData for the property at entry. - PropertyAttributes PUBLIC_API GetAttributes(int entry) const; + PropertyAttributes PUBLIC_API GetAttributes(const JSThread *thread, int entry) const; void SetAttributes(const JSThread *thread, int entry, const PropertyAttributes &metaData); void SetEntry([[maybe_unused]] const JSThread *thread, int entry, const JSTaggedValue &key, const JSTaggedValue &value, const PropertyAttributes &metaData); @@ -144,12 +146,12 @@ public: ASSERT(a.IsNumber() && b.IsNumber()); return a.GetNumber() < b.GetNumber(); } - void Dump(std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; - void Dump() const DUMP_API_ATTR + void Dump(const JSThread *thread, std::ostream &os, bool isPrivacy = false) const DUMP_API_ATTR; + void Dump(const JSThread *thread) const DUMP_API_ATTR { - Dump(std::cout); + Dump(thread, std::cout); } - void DumpForSnapshot(std::vector &vec) const; + void DumpForSnapshot(const JSThread *thread, std::vector &vec) const; static constexpr int ENTRY_KEY_INDEX = 0; static constexpr int ENTRY_VALUE_INDEX = 1; @@ -186,12 +188,12 @@ public: SetValue(thread, entry, value); } - static int32_t Hash(const JSTaggedValue &key) + static int32_t Hash([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key) { return static_cast(key.GetRawData()); } - static bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other) + static bool IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, const JSTaggedValue &other) { return key == other; } @@ -242,10 +244,10 @@ public: static JSHandle Create(const JSThread *thread); void SetEntry(const JSThread *thread, uint32_t index, JSTaggedValue key, JSTaggedValue transIhc, JSTaggedValue transPhc); - JSTaggedValue GetKey(uint32_t index) const; - std::pair GetTransition(uint32_t index) const; - int32_t FindEntry(JSTaggedValue key) const; - std::pair FindTransition(JSTaggedValue key) const; + JSTaggedValue GetKey(const JSThread *thread, uint32_t index) const; + std::pair GetTransition(const JSThread *thread, uint32_t index) const; + int32_t FindEntry(const JSThread *thread, JSTaggedValue key) const; + std::pair FindTransition(const JSThread *thread, JSTaggedValue key) const; static bool GetEntry(JSHandle hclass); private: diff --git a/ecmascript/tagged_hash_array.cpp b/ecmascript/tagged_hash_array.cpp index 5c1564ba03..dcc5d8ee6c 100644 --- a/ecmascript/tagged_hash_array.cpp +++ b/ecmascript/tagged_hash_array.cpp @@ -35,7 +35,7 @@ JSTaggedValue TaggedHashArray::GetNode(JSThread *thread, int hash, JSTaggedValue { uint32_t nodeLength = GetLength(); ASSERT(nodeLength > 0); - JSTaggedValue nodeValue = Get(((nodeLength - 1) & hash)); + JSTaggedValue nodeValue = Get(thread, ((nodeLength - 1) & hash)); JSTaggedValue hashValue = JSTaggedValue(hash); if (nodeValue.IsHole()) { return JSTaggedValue::Hole(); @@ -48,10 +48,11 @@ JSTaggedValue TaggedHashArray::GetNode(JSThread *thread, int hash, JSTaggedValue JSTaggedValue nextNodeVa = nodeValue; while (!nextNodeVa.IsHole()) { LinkedNode *nextNode = LinkedNode::Cast(nextNodeVa.GetTaggedObject()); - if (nextNode->GetHash() == hashValue && JSTaggedValue::SameValue(key, nextNode->GetKey())) { + if (nextNode->GetHash(thread) == hashValue && + JSTaggedValue::SameValue(thread, key, nextNode->GetKey(thread))) { return nextNodeVa; } - nextNodeVa = nextNode->GetNext(); + nextNodeVa = nextNode->GetNext(thread); } } return JSTaggedValue::Hole(); @@ -67,9 +68,9 @@ JSHandle TaggedHashArray::NewLinkedNode(JSThread *thread, int hash, JSHandle TaggedHashArray::CreateLinkedNodeFrom(JSThread *thread, JSHandle treeNode) { - JSHandle key(thread, treeNode->GetKey()); - JSHandle value(thread, treeNode->GetValue()); - return NewLinkedNode(thread, treeNode->GetHash().GetInt(), key, value); + JSHandle key(thread, treeNode->GetKey(thread)); + JSHandle value(thread, treeNode->GetValue(thread)); + return NewLinkedNode(thread, treeNode->GetHash(thread).GetInt(), key, value); } JSHandle TaggedHashArray::NewTreeNode(JSThread *thread, int hash, JSHandle key, @@ -81,9 +82,9 @@ JSHandle TaggedHashArray::NewTreeNode(JSThread *thread, int hash, JS JSHandle TaggedHashArray::CreateTreeNodeFrom(JSThread *thread, JSHandle linkedNode) { - JSHandle key(thread, linkedNode->GetKey()); - JSHandle value(thread, linkedNode->GetValue()); - return NewTreeNode(thread, linkedNode->GetHash().GetInt(), key, value); + JSHandle key(thread, linkedNode->GetKey(thread)); + JSHandle value(thread, linkedNode->GetValue(thread)); + return NewTreeNode(thread, linkedNode->GetHash(thread).GetInt(), key, value); } void TaggedHashArray::TreeingBin(JSThread *thread, const JSHandle &tab, int hash) @@ -91,7 +92,7 @@ void TaggedHashArray::TreeingBin(JSThread *thread, const JSHandleGetLength(); ASSERT(length > 0); uint32_t index = (length - 1) & hash; - JSTaggedValue nodeVa = tab->Get(index); + JSTaggedValue nodeVa = tab->Get(thread, index); if (!nodeVa.IsHole()) { JSHandle node(thread, nodeVa); JSHandle root = LinkedNode::Treeing(thread, node); @@ -111,15 +112,15 @@ JSHandle TaggedHashArray::Resize(JSThread *thread, const JSHand JSHandle newTab(thread, newTabValue); JSMutableHandle oldValue(thread, JSTaggedValue::Undefined()); for (uint32_t j = 0; j < oldCapacity; ++j) { - oldValue.Update(oldTab->Get(j)); + oldValue.Update(oldTab->Get(thread, j)); if (oldValue->IsHole()) { continue; } else if (oldValue->IsRBTreeNode()) { RBTreeNode::Divide(thread, newTab, oldValue, j, oldCapacity); } else if (oldValue->IsLinkedNode()) { LinkedNode *node = LinkedNode::Cast(oldValue.GetTaggedValue().GetTaggedObject()); - if (node->GetNext().IsHole()) { - int newhash = (node->GetHash().GetInt()) & (newCapacity - 1); + if (node->GetNext(thread).IsHole()) { + int newhash = (node->GetHash(thread).GetInt()) & (newCapacity - 1); newTab->Set(thread, newhash, JSTaggedValue(node)); } else { // preserve order NodeDisperse(thread, newTab, oldValue.GetTaggedValue(), j, oldCapacity); @@ -138,8 +139,8 @@ void TaggedHashArray::NodeDisperse(JSThread *thread, const JSHandleGetNext(); - if (((LinkedNode::Cast(nodeVa.GetTaggedObject())->GetHash().GetInt()) & oldCapacity) == 0) { + next = LinkedNode::Cast(nodeVa.GetTaggedObject())->GetNext(thread); + if (((LinkedNode::Cast(nodeVa.GetTaggedObject())->GetHash(thread).GetInt()) & oldCapacity) == 0) { if (loTail.IsHole()) { loHead = nodeVa; } else { @@ -172,7 +173,7 @@ JSTaggedValue TaggedHashArray::SetVal(JSThread *thread, JSHandleGetLength(); ASSERT(length > 0); uint32_t index = (length - 1) & hash; - JSHandle node(thread, table->Get(index)); + JSHandle node(thread, table->Get(thread, index)); if (node->IsHole()) { JSHandle newNode = TaggedHashArray::NewLinkedNode(thread, hash, key, value); table->Set(thread, index, newNode.GetTaggedValue()); @@ -184,13 +185,13 @@ JSTaggedValue TaggedHashArray::SetVal(JSThread *thread, JSHandle nextVal(thread, node.GetTaggedValue()); do { root.Update(nextVal); - currentKey.Update(root->GetKey()); - if (root->GetHash().GetInt() == hash && (!key->IsHole() && - JSTaggedValue::SameValue(key.GetTaggedValue(), currentKey.GetTaggedValue()))) { + currentKey.Update(root->GetKey(thread)); + if (root->GetHash(thread).GetInt() == hash && (!key->IsHole() && + JSTaggedValue::SameValue(thread, key.GetTaggedValue(), currentKey.GetTaggedValue()))) { root->SetValue(thread, value.GetTaggedValue()); return JSTaggedValue::Undefined(); } - nextVal.Update(root->GetNext()); + nextVal.Update(root->GetNext(thread)); count++; } while (!nextVal->IsHole()); JSHandle newNode = TaggedHashArray::NewLinkedNode(thread, hash, key, value); @@ -203,7 +204,7 @@ JSTaggedValue TaggedHashArray::SetVal(JSThread *thread, JSHandle root = JSHandle::Cast(node); uint32_t curCount = root->GetCount(); JSHandle changeNode = RBTreeNode::Set(thread, root, hash, key, value); - changeNode->SetIsRed(thread, JSTaggedValue(false)); + changeNode->SetIsRed(false); table->Set(thread, index, changeNode); uint32_t updateCount = changeNode->GetCount(); if (curCount == updateCount) { @@ -219,28 +220,30 @@ JSTaggedValue TaggedHashArray::RemoveNode(JSThread *thread, int hash, JSTaggedVa uint32_t length = GetLength(); ASSERT(length > 0); uint32_t index = (length - 1) & hash; - JSTaggedValue node = Get(index); + JSTaggedValue node = Get(thread, index); if (node.IsHole()) { return JSTaggedValue::Hole(); } else if (node.IsLinkedNode()) { LinkedNode *head = LinkedNode::Cast(node.GetTaggedObject()); - JSTaggedValue newKey = head->GetKey(); - if (head->GetHash().GetInt() == hash && (!key.IsHole() && JSTaggedValue::SameValue(key, newKey))) { - Set(thread, index, head->GetNext()); - return head->GetValue(); + JSTaggedValue newKey = head->GetKey(thread); + if (head->GetHash(thread).GetInt() == hash && (!key.IsHole() && + JSTaggedValue::SameValue(thread, key, newKey))) { + Set(thread, index, head->GetNext(thread)); + return head->GetValue(thread); } - JSTaggedValue nodeNextVa = head->GetNext(); + JSTaggedValue nodeNextVa = head->GetNext(thread); LinkedNode *previousNode = head; while (!nodeNextVa.IsHole()) { LinkedNode *nodeNext = LinkedNode::Cast(nodeNextVa.GetTaggedObject()); - newKey = nodeNext->GetKey(); - if (nodeNext->GetHash().GetInt() == hash && (!key.IsHole() && JSTaggedValue::SameValue(key, newKey))) { - previousNode->SetNext(thread, nodeNext->GetNext()); + newKey = nodeNext->GetKey(thread); + if (nodeNext->GetHash(thread).GetInt() == hash && (!key.IsHole() && + JSTaggedValue::SameValue(thread, key, newKey))) { + previousNode->SetNext(thread, nodeNext->GetNext(thread)); Set(thread, index, node); - return nodeNext->GetValue(); + return nodeNext->GetValue(thread); } previousNode = LinkedNode::Cast(nodeNextVa.GetTaggedObject()); - nodeNextVa = nodeNext->GetNext(); + nodeNextVa = nodeNext->GetNext(thread); } } else if (node.IsRBTreeNode()) { JSTaggedValue oldValue = JSTaggedValue::Hole(); @@ -251,8 +254,8 @@ JSTaggedValue TaggedHashArray::RemoveNode(JSThread *thread, int hash, JSTaggedVa } //set root node as black RBTreeNode *root = RBTreeNode::Cast(rootTreeNodeVa.GetTaggedObject()); - if (root->GetIsRed().ToBoolean()) { - root->SetIsRed(thread, JSTaggedValue(false)); + if (root->GetIsRed()) { + root->SetIsRed(false); rootTreeNodeVa = JSTaggedValue(root); } if (!rootTreeNodeVa.IsHole()) { @@ -267,8 +270,8 @@ JSHandle TaggedHashArray::GetCurrentNode(JSThread *thread, JSMuta const JSHandle &tableArr, uint32_t &index) { JSMutableHandle rootValue(thread, JSTaggedValue::Undefined()); - if (queue->Empty()) { - rootValue.Update(tableArr->Get(index)); + if (queue->Empty(thread)) { + rootValue.Update(tableArr->Get(thread, index)); if (rootValue->IsHole()) { ++index; return rootValue; @@ -278,22 +281,22 @@ JSHandle TaggedHashArray::GetCurrentNode(JSThread *thread, JSMuta } if (rootValue->IsRBTreeNode()) { JSHandle root = JSHandle::Cast(rootValue); - if (!root->GetLeft().IsHole()) { - JSHandle left(thread, root->GetLeft()); + if (!root->GetLeft(thread).IsHole()) { + JSHandle left(thread, root->GetLeft(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left))); } - if (!root->GetRight().IsHole()) { - JSHandle right(thread, root->GetRight()); + if (!root->GetRight(thread).IsHole()) { + JSHandle right(thread, root->GetRight(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right))); } } else { JSHandle root = JSHandle::Cast(rootValue); - if (!root->GetNext().IsHole()) { - JSHandle next(thread, root->GetNext()); + if (!root->GetNext(thread).IsHole()) { + JSHandle next(thread, root->GetNext(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, next))); } } - if (queue->Empty()) { + if (queue->Empty(thread)) { ++index; } return rootValue; diff --git a/ecmascript/tagged_hash_table.h b/ecmascript/tagged_hash_table.h index 449efad396..ab93ffe9e6 100644 --- a/ecmascript/tagged_hash_table.h +++ b/ecmascript/tagged_hash_table.h @@ -30,17 +30,17 @@ class TaggedHashTable : public TaggedArray { public: inline int EntriesCount() const { - return Get(NUMBER_OF_ENTRIES_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_ENTRIES_INDEX).GetInt(); } inline int HoleEntriesCount() const { - return Get(NUMBER_OF_HOLE_ENTRIES_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_HOLE_ENTRIES_INDEX).GetInt(); } inline int Size() const { - return Get(SIZE_INDEX).GetInt(); + return GetPrimitive(SIZE_INDEX).GetInt(); } inline void IncreaseEntries(const JSThread *thread) @@ -79,7 +79,7 @@ public: } return table; } - int newSize = Derived::ComputeCompactSize(table, ComputeHashTableSize(table->Size() + numOfAddedElements), + int newSize = Derived::ComputeCompactSize(thread, table, ComputeHashTableSize(table->Size() + numOfAddedElements), table->Size(), numOfAddedElements); newSize = std::max(newSize, MIN_SHRINK_SIZE); int length = Derived::GetEntryIndex(newSize); @@ -112,23 +112,23 @@ public: static JSHandle Insert(const JSThread *thread, JSHandle &table, const JSHandle &key, const JSHandle &value) { - int entry = table->FindEntry(key.GetTaggedValue()); + int entry = table->FindEntry(thread, key.GetTaggedValue()); if (entry != -1) { table->SetValue(thread, entry, value.GetTaggedValue()); return table; } // Make sure the key object has an identity hash code. - uint32_t hash = static_cast(Derived::Hash(key.GetTaggedValue())); + uint32_t hash = static_cast(Derived::Hash(thread, key.GetTaggedValue())); JSHandle newTable = GrowHashTable(thread, table); - newTable->AddElement(thread, newTable->FindInsertIndex(hash), key, value); + newTable->AddElement(thread, newTable->FindInsertIndex(thread, hash), key, value); return newTable; } static JSHandle Remove(const JSThread *thread, JSHandle &table, const JSHandle &key) { - int entry = table->FindEntry(key.GetTaggedValue()); + int entry = table->FindEntry(thread, key.GetTaggedValue()); if (entry == -1) { return table; } @@ -182,22 +182,22 @@ public: return true; } - JSTaggedValue GetKey(int entry) const + JSTaggedValue GetKey(const JSThread *thread, int entry) const { int index = Derived::GetKeyIndex(entry); if (UNLIKELY((index < 0 || index > static_cast(GetLength())))) { return JSTaggedValue::Undefined(); } - return Get(index); + return Get(thread, index); } - JSTaggedValue GetValue(int entry) const + JSTaggedValue GetValue(const JSThread *thread, int entry) const { int index = Derived::GetValueIndex(entry); if (UNLIKELY((index < 0 || index > static_cast(GetLength())))) { return JSTaggedValue::Undefined(); } - return Get(index); + return Get(thread, index); } inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const @@ -207,7 +207,7 @@ public: int arrayIndex = 0; int size = Size(); for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { keyArray->Set(thread, arrayIndex + offset, key); arrayIndex++; @@ -215,11 +215,11 @@ public: } } - inline void GetAllKeysIntoVector(std::vector &vector) const + inline void GetAllKeysIntoVector(const JSThread *thread, std::vector &vector) const { int capacity = Size(); for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key = GetKey(hashIndex); + JSTaggedValue key = GetKey(thread, hashIndex); if (!key.IsUndefined() && !key.IsHole()) { vector.push_back(key); } @@ -229,29 +229,29 @@ public: inline void Swap(const JSThread *thread, int src, int dst); // Find entry for key otherwise return -1. - inline int FindEntry(const JSTaggedValue &key) + inline int FindEntry(const JSThread *thread, const JSTaggedValue &key) { int size = Size(); int count = 1; JSTaggedValue keyValue; - int32_t hash = static_cast(Derived::Hash(key)); + int32_t hash = static_cast(Derived::Hash(thread, key)); for (uint32_t entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { - keyValue = GetKey(entry); + keyValue = GetKey(thread, entry); if (keyValue.IsHole()) { continue; } if (keyValue.IsUndefined()) { return -1; } - if (Derived::IsMatch(key, keyValue)) { + if (Derived::IsMatch(thread, key, keyValue)) { return entry; } } return -1; } - inline int FindEntry(const uint8_t* str, int strSize) + inline int FindEntry(const JSThread *thread, const uint8_t* str, int strSize) { int size = Size(); int count = 1; @@ -259,7 +259,7 @@ public: int32_t hash = static_cast(Derived::Hash(str, strSize)); for (uint32_t entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { - keyValue = GetKey(entry); + keyValue = GetKey(thread, entry); if (keyValue.IsHole()) { continue; } @@ -274,13 +274,13 @@ public: return -1; } - inline int FindInsertIndex(uint32_t hash) + inline int FindInsertIndex(const JSThread *thread, uint32_t hash) { int size = Size(); int count = 1; // GrowHashTable will guarantee the hash table is never full. for (uint32_t entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { - if (!IsKey(GetKey(entry))) { + if (!IsKey(GetKey(thread, entry))) { return entry; } } @@ -314,16 +314,16 @@ public: // Rehash elements to new table for (int i = 0; i < currentSize; i++) { int fromIndex = Derived::GetKeyIndex(i); - JSTaggedValue k = this->GetKey(i); + JSTaggedValue k = this->GetKey(thread, i); if (!IsKey(k)) { continue; } - uint32_t hash = static_cast(Derived::Hash(k)); - int insertionIndex = Derived::GetKeyIndex(newTable->FindInsertIndex(hash)); - JSTaggedValue tv = Get(fromIndex); + uint32_t hash = static_cast(Derived::Hash(thread, k)); + int insertionIndex = Derived::GetKeyIndex(newTable->FindInsertIndex(thread, hash)); + JSTaggedValue tv = Get(thread, fromIndex); newTable->Set(thread, insertionIndex, tv); for (int j = 1; j < Derived::GetEntrySize(); j++) { - tv = Get(fromIndex + j); + tv = Get(thread, fromIndex + j); newTable->Set(thread, insertionIndex + j, tv); } } @@ -425,7 +425,7 @@ public: const PropertyAttributes &metaData) { /* no need to add key if exist */ - int entry = table->FindEntry(key.GetTaggedValue()); + int entry = table->FindEntry(thread, key.GetTaggedValue()); if (entry != -1) { return table; } @@ -438,8 +438,8 @@ public: JSHandle newTable = HashTableT::GrowHashTable(thread, table); // Compute the key object. - uint32_t hash = static_cast(Derived::Hash(key.GetTaggedValue())); - entry = newTable->FindInsertIndex(hash); + uint32_t hash = static_cast(Derived::Hash(thread, key.GetTaggedValue())); + entry = newTable->FindInsertIndex(thread, hash); newTable->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); newTable->IncreaseEntries(thread); @@ -456,7 +456,7 @@ public: attr.SetDictionaryOrder(enumIndex); attr.SetRepresentation(Representation::TAGGED); attr.SetDictSharedFieldType(metaData.GetSharedFieldType()); - int entry = table->FindEntry(key.GetTaggedValue()); + int entry = table->FindEntry(thread, key.GetTaggedValue()); if (entry != -1) { table->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); return table; @@ -466,8 +466,8 @@ public: JSHandle newTable = HashTableT::GrowHashTable(thread, table); // Compute the key object. - uint32_t hash = static_cast(Derived::Hash(key.GetTaggedValue())); - entry = newTable->FindInsertIndex(hash); + uint32_t hash = static_cast(Derived::Hash(thread, key.GetTaggedValue())); + entry = newTable->FindInsertIndex(thread, hash); newTable->SetEntry(thread, entry, key.GetTaggedValue(), value.GetTaggedValue(), attr); newTable->IncreaseEntries(thread); @@ -476,7 +476,7 @@ public: } static JSHandle Remove(const JSThread *thread, const JSHandle &table, int entry) { - if (!(table->IsKey(table->GetKey(entry)))) { + if (!(table->IsKey(table->GetKey(thread, entry)))) { return table; } table->ClearEntry(thread, entry); @@ -490,7 +490,7 @@ public: } inline int GetNextEnumerationIndex() const { - return HashTableT::Get(NEXT_ENUMERATION_INDEX).GetInt(); + return HashTableT::GetPrimitive(NEXT_ENUMERATION_INDEX).GetInt(); } inline int NextEnumerationIndex(const JSThread *thread) @@ -499,12 +499,12 @@ public: auto table = Derived::Cast(this); if (!PropertyAttributes::IsValidIndex(index)) { - std::vector indexOrder = GetEnumerationOrder(); + std::vector indexOrder = GetEnumerationOrder(thread); int length = static_cast(indexOrder.size()); for (int i = 0; i < length; i++) { int oldIndex = indexOrder[i]; int enumIndex = PropertyAttributes::INITIAL_PROPERTY_INDEX + i; - PropertyAttributes attr = table->GetAttributes(oldIndex); + PropertyAttributes attr = table->GetAttributes(thread, oldIndex); attr.SetDictionaryOrder(enumIndex); attr.SetRepresentation(Representation::TAGGED); table->SetAttributes(thread, oldIndex, attr); @@ -514,25 +514,25 @@ public: return index; } - inline std::vector GetEnumerationOrder() + inline std::vector GetEnumerationOrder(const JSThread *thread) { std::vector result; auto table = Derived::Cast(this); int size = table->Size(); for (int i = 0; i < size; i++) { - if (table->IsKey(table->GetKey(i))) { + if (table->IsKey(table->GetKey(thread, i))) { result.push_back(i); } } - std::sort(result.begin(), result.end(), [table](int a, int b) { - PropertyAttributes attrA = table->GetAttributes(a); - PropertyAttributes attrB = table->GetAttributes(b); + std::sort(result.begin(), result.end(), [table, thread](int a, int b) { + PropertyAttributes attrA = table->GetAttributes(thread, a); + PropertyAttributes attrB = table->GetAttributes(thread, b); return attrA.GetDictionaryOrder() < attrB.GetDictionaryOrder(); }); return result; } - static int ComputeCompactSize([[maybe_unused]] const JSHandle &table, int computeHashTableSize, + static int ComputeCompactSize([[maybe_unused]] const JSThread *thread, [[maybe_unused]] const JSHandle &table, int computeHashTableSize, [[maybe_unused]] int tableSize, [[maybe_unused]] int addedElements) { return computeHashTableSize; diff --git a/ecmascript/tagged_list.cpp b/ecmascript/tagged_list.cpp index 866d26e862..bb4c825340 100644 --- a/ecmascript/tagged_list.cpp +++ b/ecmascript/tagged_list.cpp @@ -48,7 +48,7 @@ void TaggedList::CopyArray(const JSThread *thread, JSHandle &t if (deleteNodeNum == 0) { int capacity = GetCapacityFromTaggedArray(); for (int i = 0; i < capacity; i++) { - value.Update(GetElement(i)); + value.Update(GetElement(thread, i)); taggedList->SetElement(thread, i, value.GetTaggedValue()); } taggedList->SetNumberOfDeletedNodes(thread, NumberOfDeletedNodes()); @@ -68,16 +68,16 @@ void TaggedList::CopyArray(const JSThread *thread, JSHandle &t if constexpr (std::is_same_v) { taggedList->SetElement(thread, ELEMENTS_START_INDEX + PREV_PTR_OFFSET, JSTaggedValue(tailTableIndex)); } - int srcDataIndex = GetElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); + int srcDataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); for (int i = 0; i < actualNodeNum; i++) { int index = nextTailIndex + i * Derived::ENTRY_SIZE; - taggedList->SetElement(thread, index, GetElement(srcDataIndex)); + taggedList->SetElement(thread, index, GetElement(thread, srcDataIndex)); taggedList->SetElement(thread, index + NEXT_PTR_OFFSET, JSTaggedValue(index + Derived::ENTRY_SIZE)); if constexpr (std::is_same_v) { taggedList->SetElement(thread, index + PREV_PTR_OFFSET, JSTaggedValue(ELEMENTS_START_INDEX + i * Derived::ENTRY_SIZE)); } - srcDataIndex = GetElement(srcDataIndex + NEXT_PTR_OFFSET).GetInt(); + srcDataIndex = GetPrimitiveElement(srcDataIndex + NEXT_PTR_OFFSET).GetInt(); } taggedList->SetElement(thread, tailTableIndex + NEXT_PTR_OFFSET, JSTaggedValue(ELEMENTS_START_INDEX)); } @@ -106,7 +106,7 @@ void TaggedList::Clear(const JSThread *thread) int numberOfNodes = NumberOfNodes(); int dataIndex = ELEMENTS_START_INDEX; for (int i = 0; i < numberOfNodes; i++) { - dataIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + dataIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); SetElement(thread, dataIndex, JSTaggedValue::Hole()); } JSTaggedValue data = JSTaggedValue(ELEMENTS_START_INDEX); @@ -149,16 +149,16 @@ JSHandle TaggedList::OwnKeys(JSThread *thread, const JSHan } template -int TaggedList::FindIndexByElement(const JSTaggedValue &element) +int TaggedList::FindIndexByElement(const JSThread *thread, const JSTaggedValue &element) { int dataIndex = ELEMENTS_START_INDEX; - int nextDataIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + int nextDataIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); int nodeSum = 0; while (nextDataIndex != ELEMENTS_START_INDEX) { dataIndex = nextDataIndex; - JSTaggedValue data = GetElement(dataIndex); - nextDataIndex = GetElement(nextDataIndex + NEXT_PTR_OFFSET).GetInt(); - if (JSTaggedValue::SameValue(data, element)) { + JSTaggedValue data = GetElement(thread, dataIndex); + nextDataIndex = GetPrimitiveElement(nextDataIndex + NEXT_PTR_OFFSET).GetInt(); + if (JSTaggedValue::SameValue(thread, data, element)) { return nodeSum; } nodeSum++; @@ -167,19 +167,19 @@ int TaggedList::FindIndexByElement(const JSTaggedValue &element) } template -int TaggedList::FindLastIndexByElement(const JSTaggedValue &element) +int TaggedList::FindLastIndexByElement(const JSThread *thread, const JSTaggedValue &element) { int dataIndex = ELEMENTS_START_INDEX; - int nextIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + int nextIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); int nodeSum = 0; int lastIndex = -1; while (nextIndex != ELEMENTS_START_INDEX) { dataIndex = nextIndex; - JSTaggedValue data = GetElement(dataIndex); - if (JSTaggedValue::SameValue(data, element)) { + JSTaggedValue data = GetElement(thread, dataIndex); + if (JSTaggedValue::SameValue(thread, data, element)) { lastIndex = nodeSum; } - nextIndex = GetElement(nextIndex + NEXT_PTR_OFFSET).GetInt(); + nextIndex = GetPrimitiveElement(nextIndex + NEXT_PTR_OFFSET).GetInt(); nodeSum++; } return lastIndex; @@ -189,14 +189,14 @@ template int TaggedList::FindDataIndexByNodeIndex(int index) const { int dataIndex = ELEMENTS_START_INDEX; - int nextIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + int nextIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); int nodeSum = 0; while (nextIndex != ELEMENTS_START_INDEX) { dataIndex = nextIndex; if (nodeSum == index) { return dataIndex; } - nextIndex = GetElement(nextIndex + NEXT_PTR_OFFSET).GetInt(); + nextIndex = GetPrimitiveElement(nextIndex + NEXT_PTR_OFFSET).GetInt(); nodeSum++; } return -1; @@ -208,7 +208,7 @@ void TaggedList::MapNodeIndexToDataIndex(std::vector &nodeIndexMap int i = 0; int nextIndex = ELEMENTS_START_INDEX; while (i < length) { - nextIndex = GetElement(nextIndex + NEXT_PTR_OFFSET).GetInt(); + nextIndex = GetPrimitiveElement(nextIndex + NEXT_PTR_OFFSET).GetInt(); nodeIndexMapToDataIndex[i] = nextIndex; i++; } @@ -217,10 +217,10 @@ void TaggedList::MapNodeIndexToDataIndex(std::vector &nodeIndexMap template void TaggedList::RemoveNode(JSThread *thread, int prevDataIndex) { - int tailTableIndex = GetElement(TAIL_TABLE_INDEX).GetInt(); - if (tailTableIndex != GetElement(HEAD_TABLE_INDEX).GetInt()) { - int dataIndex = GetElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); - int nextDataIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + int tailTableIndex = GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); + if (tailTableIndex != GetElement(thread, HEAD_TABLE_INDEX).GetInt()) { + int dataIndex = GetPrimitiveElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); + int nextDataIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); if (dataIndex == tailTableIndex) { SetElement(thread, TAIL_TABLE_INDEX, JSTaggedValue(prevDataIndex)); } @@ -239,27 +239,27 @@ int TaggedList::FindPrevNodeByIndex(int index) const { int prevDataIndex = ELEMENTS_START_INDEX; int nodeSum = 0; - int len = GetElement(NUMBER_OF_NODE_INDEX).GetInt(); + int len = GetPrimitiveElement(NUMBER_OF_NODE_INDEX).GetInt(); while (nodeSum <= len) { if (nodeSum == index) { return prevDataIndex; } - prevDataIndex = GetElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); + prevDataIndex = GetPrimitiveElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); nodeSum++; } return -1; } template -int TaggedList::FindPrevNodeByValue(const JSTaggedValue &element) +int TaggedList::FindPrevNodeByValue(const JSThread *thread, const JSTaggedValue &element) { int dataIndex = ELEMENTS_START_INDEX; int nodeSum = 0; - int len = GetElement(NUMBER_OF_NODE_INDEX).GetInt(); + int len = GetPrimitiveElement(NUMBER_OF_NODE_INDEX).GetInt(); while (nodeSum <= len) { - int nextDataIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); - JSTaggedValue data = GetElement(nextDataIndex); - if (JSTaggedValue::SameValue(data, element)) { + int nextDataIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + JSTaggedValue data = GetElement(thread, nextDataIndex); + if (JSTaggedValue::SameValue(thread, data, element)) { return dataIndex; } dataIndex = nextDataIndex; @@ -269,28 +269,28 @@ int TaggedList::FindPrevNodeByValue(const JSTaggedValue &element) } template -JSTaggedValue TaggedList::FindElementByIndex(int index) const +JSTaggedValue TaggedList::FindElementByIndex(const JSThread *thread, int index) const { - int dataIndex = GetElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); + int dataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); int nodeSum = 0; while (dataIndex != ELEMENTS_START_INDEX) { if (nodeSum == index) { - return GetElement(dataIndex); + return GetElement(thread, dataIndex); } - dataIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + dataIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); nodeSum++; } return JSTaggedValue::Undefined(); } template -std::pair TaggedList::FindElementByDataIndex(int dataindex) const +std::pair TaggedList::FindElementByDataIndex(const JSThread *thread, int dataindex) const { - int targetDataIndex = GetElement(dataindex + NEXT_PTR_OFFSET).GetInt(); - JSTaggedValue value = GetElement(targetDataIndex); + int targetDataIndex = GetPrimitiveElement(dataindex + NEXT_PTR_OFFSET).GetInt(); + JSTaggedValue value = GetElement(thread, targetDataIndex); while (value.IsHole() && targetDataIndex != ELEMENTS_START_INDEX) { - targetDataIndex = GetElement(targetDataIndex + NEXT_PTR_OFFSET).GetInt(); - value = GetElement(targetDataIndex); + targetDataIndex = GetPrimitiveElement(targetDataIndex + NEXT_PTR_OFFSET).GetInt(); + value = GetElement(thread, targetDataIndex); } if (targetDataIndex == ELEMENTS_START_INDEX) { return std::make_pair(-1, JSTaggedValue::Undefined()); @@ -302,8 +302,8 @@ template JSTaggedValue TaggedList::RemoveByIndex(JSThread *thread, const int &index) { int prevDataIndex = FindPrevNodeByIndex(index); - int curDataIndex = GetElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); - JSTaggedValue data = GetElement(curDataIndex); + int curDataIndex = GetPrimitiveElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); + JSTaggedValue data = GetElement(thread, curDataIndex); RemoveNode(thread, prevDataIndex); return data; } @@ -317,7 +317,7 @@ JSTaggedValue TaggedSingleList::Create(const JSThread *thread, int numberOfEleme JSTaggedValue TaggedSingleList::Add(const JSThread *thread, const JSHandle &taggedList, const JSHandle &value) { - int prevDataIndex = taggedList->GetElement(TAIL_TABLE_INDEX).GetInt(); + int prevDataIndex = taggedList->GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); return TaggedSingleList::AddNode(thread, taggedList, value, -1, prevDataIndex); } @@ -329,7 +329,7 @@ JSTaggedValue TaggedSingleList::ConvertToArray(const JSThread *thread, const JSH JSTaggedValue TaggedSingleList::Insert(JSThread *thread, const JSHandle &taggedList, const JSHandle &value, const int index) { - int tailIndex = taggedList->GetElement(TAIL_TABLE_INDEX).GetInt(); + int tailIndex = taggedList->GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); int prevDataIndex = (index == -1) ? tailIndex : taggedList->FindPrevNodeByIndex(index); return TaggedSingleList::AddNode(thread, taggedList, value, index, prevDataIndex); } @@ -344,7 +344,7 @@ JSTaggedValue TaggedSingleList::AddNode(const JSThread *thread, const JSHandleGetElement(TAIL_TABLE_INDEX).GetInt(); + prevDataIndex = list->GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); } else { prevDataIndex = list->FindPrevNodeByIndex(index); } @@ -361,16 +361,16 @@ void TaggedSingleList::InsertNode(const JSThread *thread, const JSHandle TaggedSingleList::GetByDataIndex(const int dataIndex) +std::pair TaggedSingleList::GetByDataIndex(const JSThread *thread, const int dataIndex) { - return FindElementByDataIndex(dataIndex); + return FindElementByDataIndex(thread, dataIndex); } -int TaggedSingleList::GetIndexOf(const JSTaggedValue &element) +int TaggedSingleList::GetIndexOf(const JSThread *thread, const JSTaggedValue &element) { - return FindIndexByElement(element); + return FindIndexByElement(thread, element); } -int TaggedSingleList::GetLastIndexOf(const JSTaggedValue &element) +int TaggedSingleList::GetLastIndexOf(const JSThread *thread, const JSTaggedValue &element) { - return FindLastIndexByElement(element); + return FindLastIndexByElement(thread, element); } JSTaggedValue TaggedSingleList::Set(JSThread *thread, const JSHandle &taggedList, @@ -420,7 +420,7 @@ JSTaggedValue TaggedSingleList::ReplaceAllElements(JSThread *thread, const JSHan JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (int k = 0; k < length; k++) { dataIndex = taggedList->GetNextDataIndex(dataIndex); - JSTaggedValue kValue = taggedList->GetElement(dataIndex); + JSTaggedValue kValue = taggedList->GetElement(thread, dataIndex); JSTaggedValue key = JSTaggedValue(k); EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, 3); // 3:three args @@ -457,10 +457,10 @@ JSTaggedValue TaggedSingleList::Sort(JSThread *thread, const JSHandleGetElement(nodeIndexMapToDataIndex[i])); + presentValue.Update(taggedList->GetElement(thread, nodeIndexMapToDataIndex[i])); while (beginIndex < endIndex) { middleIndex = (beginIndex + endIndex) / 2; // 2 : half - middleValue.Update(taggedList->GetElement(nodeIndexMapToDataIndex[middleIndex])); + middleValue.Update(taggedList->GetElement(thread, nodeIndexMapToDataIndex[middleIndex])); compareResult = base::ArrayHelper::SortCompare(thread, callbackFn, middleValue, presentValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (compareResult > 0) { @@ -472,7 +472,7 @@ JSTaggedValue TaggedSingleList::Sort(JSThread *thread, const JSHandle endIndex; j--) { - previousValue.Update(taggedList->GetElement(nodeIndexMapToDataIndex[j - 1])); + previousValue.Update(taggedList->GetElement(thread, nodeIndexMapToDataIndex[j - 1])); taggedList->SetElement(thread, nodeIndexMapToDataIndex[j], previousValue.GetTaggedValue()); } taggedList->SetElement(thread, nodeIndexMapToDataIndex[endIndex], presentValue.GetTaggedValue()); @@ -488,13 +488,13 @@ void TaggedSingleList::GetSubList(JSThread *thread, const JSHandleGetElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); + int dataIndex = taggedList->GetPrimitiveElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); int nodeSum = 0; while (dataIndex != ELEMENTS_START_INDEX) { if (nodeSum == fromIndex) { fromDataIndex = dataIndex; } - dataIndex = taggedList->GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + dataIndex = taggedList->GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); nodeSum++; if (nodeSum == toIndex) { toDataIndex = dataIndex; @@ -507,11 +507,11 @@ void TaggedSingleList::GetSubList(JSThread *thread, const JSHandleGetElement(fromDataIndex)); + dataHandle.Update(taggedList->GetElement(thread, fromDataIndex)); subList->SetElement(thread, preDataIndex + NEXT_PTR_OFFSET, JSTaggedValue(curDataIndex)); subList->SetElement(thread, curDataIndex, dataHandle.GetTaggedValue()); preDataIndex = curDataIndex; - fromDataIndex = taggedList->GetElement(fromDataIndex + NEXT_PTR_OFFSET).GetInt(); + fromDataIndex = taggedList->GetPrimitiveElement(fromDataIndex + NEXT_PTR_OFFSET).GetInt(); } subList->SetElement(thread, curDataIndex + NEXT_PTR_OFFSET, JSTaggedValue(ELEMENTS_START_INDEX)); subList->SetElement(thread, HEAD_TABLE_INDEX, JSTaggedValue(ELEMENTS_START_INDEX)); @@ -520,7 +520,7 @@ void TaggedSingleList::GetSubList(JSThread *thread, const JSHandleSetNumberOfDeletedNodes(thread, 0); } -JSTaggedValue TaggedSingleList::Equal(const JSHandle &compareList) +JSTaggedValue TaggedSingleList::Equal(const JSThread *thread, const JSHandle &compareList) { int compareListLength = compareList->NumberOfNodes(); if (compareListLength != NumberOfNodes()) { @@ -532,9 +532,9 @@ JSTaggedValue TaggedSingleList::Equal(const JSHandle &compareL while (nodeSum < compareListLength) { compareNode = compareList->GetNextDataIndex(compareNode); valueNode = GetNextDataIndex(valueNode); - JSTaggedValue compareValue = compareList->GetElement(compareNode); - JSTaggedValue value = GetElement(valueNode); - if (!JSTaggedValue::SameValue(compareValue, value)) { + JSTaggedValue compareValue = compareList->GetElement(thread, compareNode); + JSTaggedValue value = GetElement(thread, valueNode); + if (!JSTaggedValue::SameValue(thread, compareValue, value)) { return JSTaggedValue::False(); } nodeSum++; @@ -554,7 +554,7 @@ JSTaggedValue TaggedSingleList::RemoveByIndex(JSThread *thread, const int &index JSTaggedValue TaggedSingleList::Remove(JSThread *thread, const JSTaggedValue &element) { - int prevDataIndex = FindPrevNodeByValue(element); + int prevDataIndex = FindPrevNodeByValue(thread, element); if (prevDataIndex == -1) { return JSTaggedValue::False(); } @@ -570,7 +570,7 @@ JSHandle TaggedSingleList::OwnKeys(JSThread *thread, const JSHandle JSTaggedValue TaggedSingleList::SortByNodeOrder(const JSThread *thread, const JSHandle &taggedList) { int actualNodeNum = taggedList->NumberOfNodes(); - int nextDataIndex = taggedList->GetElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); + int nextDataIndex = taggedList->GetPrimitiveElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); uint32_t length = static_cast(actualNodeNum); JSHandle list = TaggedList::Create( thread, length < DEFAULT_ARRAY_LENGHT ? DEFAULT_ARRAY_LENGHT : length); @@ -584,10 +584,10 @@ JSTaggedValue TaggedSingleList::SortByNodeOrder(const JSThread *thread, const JS for (int i = 0; i < actualNodeNum; ++i) { int curDataIndex = ELEMENTS_START_INDEX + (i + 1) * TaggedSingleList::ENTRY_SIZE; - list->SetElement(thread, curDataIndex, taggedList->GetElement(nextDataIndex)); + list->SetElement(thread, curDataIndex, taggedList->GetElement(thread, nextDataIndex)); list->SetElement(thread, curDataIndex + NEXT_PTR_OFFSET, JSTaggedValue(curDataIndex + TaggedSingleList::ENTRY_SIZE)); - nextDataIndex = taggedList->GetElement(nextDataIndex + NEXT_PTR_OFFSET).GetInt(); + nextDataIndex = taggedList->GetPrimitiveElement(nextDataIndex + NEXT_PTR_OFFSET).GetInt(); } list->SetElement(thread, tailTableIndex + NEXT_PTR_OFFSET, JSTaggedValue(ELEMENTS_START_INDEX)); return list.GetTaggedValue(); @@ -604,7 +604,7 @@ JSTaggedValue TaggedDoubleList::Create(const JSThread *thread, int numberOfEleme JSTaggedValue TaggedDoubleList::Add(const JSThread *thread, const JSHandle &taggedList, const JSHandle &value) { - int prevDataIndex = taggedList->GetElement(TAIL_TABLE_INDEX).GetInt(); + int prevDataIndex = taggedList->GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); return TaggedDoubleList::AddNode(thread, taggedList, value, -1, prevDataIndex); } @@ -637,7 +637,7 @@ JSTaggedValue TaggedDoubleList::AddNode(const JSThread *thread, const JSHandleGetElement(TAIL_TABLE_INDEX).GetInt(); + prevDataIndex = list->GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); } else if (index == 0) { prevDataIndex = list->FindPrevNodeByIndex(0); } else { @@ -656,7 +656,7 @@ void TaggedDoubleList::InsertNode(const JSThread *thread, const JSHandle index) { - return FindElementByIndex(index); + return FindElementByIndex(thread, index); } else { - return FindElementByIndexAtLast(index); + return FindElementByIndexAtLast(thread, index); } } -std::pair TaggedDoubleList::GetByDataIndex(const int dataIndex) +std::pair TaggedDoubleList::GetByDataIndex(const JSThread *thread, const int dataIndex) { - return FindElementByDataIndex(dataIndex); + return FindElementByDataIndex(thread, dataIndex); } int TaggedDoubleList::GetPrevNode(const int index) @@ -698,21 +698,21 @@ int TaggedDoubleList::GetPrevNode(const int index) int leftNodeLen = len - 1 - index; // When insert at last if (leftNodeLen == -1) { - return GetElement(TAIL_TABLE_INDEX).GetInt(); + return GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); } // when index >= (len / 2), search doubleList from the end return FindPrevNodeByIndexAtLast(leftNodeLen); } } -int TaggedDoubleList::GetIndexOf(const JSTaggedValue &element) +int TaggedDoubleList::GetIndexOf(const JSThread *thread, const JSTaggedValue &element) { - return FindIndexByElement(element); + return FindIndexByElement(thread, element); } -int TaggedDoubleList::GetLastIndexOf(const JSTaggedValue &element) +int TaggedDoubleList::GetLastIndexOf(const JSThread *thread, const JSTaggedValue &element) { - return FindLastIndexByElement(element); + return FindLastIndexByElement(thread, element); } JSTaggedValue TaggedDoubleList::Set(JSThread *thread, const JSHandle &taggedList, const int index, @@ -744,17 +744,17 @@ void TaggedDoubleList::Clear(const JSThread *thread) JSTaggedValue TaggedDoubleList::RemoveFirst(JSThread *thread) { - int firstDataIndex = GetElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); - JSTaggedValue firstData = GetElement(firstDataIndex); + int firstDataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); + JSTaggedValue firstData = GetElement(thread, firstDataIndex); RemoveNode(thread, ELEMENTS_START_INDEX); return firstData; } JSTaggedValue TaggedDoubleList::RemoveLast(JSThread *thread) { - int lastDataIndex = GetElement(ELEMENTS_START_INDEX + 2).GetInt(); - int prevDataIndex = GetElement(lastDataIndex + 2).GetInt(); - JSTaggedValue lastData = GetElement(lastDataIndex); + int lastDataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + 2).GetInt(); + int prevDataIndex = GetPrimitiveElement(lastDataIndex + 2).GetInt(); + JSTaggedValue lastData = GetElement(thread, lastDataIndex); RemoveNode(thread, prevDataIndex); return lastData; } @@ -762,15 +762,15 @@ JSTaggedValue TaggedDoubleList::RemoveLast(JSThread *thread) JSTaggedValue TaggedDoubleList::RemoveByIndex(JSThread *thread, const int &index) { int prevDataIndex = GetPrevNode(index); - int curDataIndex = GetElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); - JSTaggedValue data = GetElement(curDataIndex); + int curDataIndex = GetPrimitiveElement(prevDataIndex + NEXT_PTR_OFFSET).GetInt(); + JSTaggedValue data = GetElement(thread, curDataIndex); RemoveNode(thread, prevDataIndex); return data; } JSTaggedValue TaggedDoubleList::Remove(JSThread *thread, const JSTaggedValue &element) { - int prevDataIndex = FindPrevNodeByValue(element); + int prevDataIndex = FindPrevNodeByValue(thread, element); if (prevDataIndex == -1) { return JSTaggedValue::False(); } @@ -781,7 +781,7 @@ JSTaggedValue TaggedDoubleList::Remove(JSThread *thread, const JSTaggedValue &el JSTaggedValue TaggedDoubleList::RemoveFirstFound(JSThread *thread, const JSHandle &taggedList, const JSTaggedValue &element) { - int prevDataIndex = taggedList->FindPrevNodeByValue(element); + int prevDataIndex = taggedList->FindPrevNodeByValue(thread, element); if (prevDataIndex == -1) { JSTaggedValue error = containers::ContainerError::BusinessError(thread, containers::ErrorFlag::IS_NOT_EXIST_ERROR, @@ -795,7 +795,7 @@ JSTaggedValue TaggedDoubleList::RemoveFirstFound(JSThread *thread, const JSHandl JSTaggedValue TaggedDoubleList::RemoveLastFound(JSThread *thread, const JSHandle &taggedList, const JSTaggedValue &element) { - int prevDataIndex = taggedList->FindPrevNodeByValueAtLast(element); + int prevDataIndex = taggedList->FindPrevNodeByValueAtLast(thread, element); if (prevDataIndex == -1) { JSTaggedValue error = containers::ContainerError::BusinessError(thread, containers::ErrorFlag::IS_NOT_EXIST_ERROR, @@ -811,18 +811,18 @@ JSHandle TaggedDoubleList::OwnKeys(JSThread *thread, const JSHandle return TaggedList::OwnKeys(thread, taggedList); } -JSTaggedValue TaggedDoubleList::FindElementByIndexAtLast(int index) const +JSTaggedValue TaggedDoubleList::FindElementByIndexAtLast(const JSThread *thread, int index) const { int dataIndex = ELEMENTS_START_INDEX; - int preDataIndex = GetElement(dataIndex + PREV_PTR_OFFSET).GetInt(); - int nodeSum = GetElement(NUMBER_OF_NODE_INDEX).GetInt() - 1; + int preDataIndex = GetPrimitiveElement(dataIndex + PREV_PTR_OFFSET).GetInt(); + int nodeSum = GetElement(thread, NUMBER_OF_NODE_INDEX).GetInt() - 1; while (preDataIndex != ELEMENTS_START_INDEX) { dataIndex = preDataIndex; - JSTaggedValue dataValue = GetElement(dataIndex); + JSTaggedValue dataValue = GetElement(thread, dataIndex); if (nodeSum == index) { return dataValue; } - preDataIndex = GetElement(preDataIndex + PREV_PTR_OFFSET).GetInt(); + preDataIndex = GetPrimitiveElement(preDataIndex + PREV_PTR_OFFSET).GetInt(); nodeSum--; } return JSTaggedValue::Undefined(); @@ -830,11 +830,11 @@ JSTaggedValue TaggedDoubleList::FindElementByIndexAtLast(int index) const int TaggedDoubleList::FindPrevNodeByIndexAtLast(const int index) const { - int prevDataIndex = GetElement(ELEMENTS_START_INDEX + PREV_PTR_OFFSET).GetInt(); + int prevDataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + PREV_PTR_OFFSET).GetInt(); int nodeSum = 0; - int len = GetElement(NUMBER_OF_NODE_INDEX).GetInt(); + int len = GetPrimitiveElement(NUMBER_OF_NODE_INDEX).GetInt(); while (nodeSum <= len) { - int prePreDataIndex = GetElement(prevDataIndex + PREV_PTR_OFFSET).GetInt(); + int prePreDataIndex = GetPrimitiveElement(prevDataIndex + PREV_PTR_OFFSET).GetInt(); if (nodeSum == index) { return prePreDataIndex; } @@ -844,15 +844,15 @@ int TaggedDoubleList::FindPrevNodeByIndexAtLast(const int index) const return -1; } -int TaggedDoubleList::FindPrevNodeByValueAtLast(const JSTaggedValue &element) +int TaggedDoubleList::FindPrevNodeByValueAtLast(const JSThread *thread, const JSTaggedValue &element) { - int prevDataIndex = GetElement(ELEMENTS_START_INDEX + PREV_PTR_OFFSET).GetInt(); + int prevDataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + PREV_PTR_OFFSET).GetInt(); int nodeSum = 0; - int len = GetElement(NUMBER_OF_NODE_INDEX).GetInt(); + int len = GetPrimitiveElement(NUMBER_OF_NODE_INDEX).GetInt(); while (nodeSum <= len) { - int prePreDataIndex = GetElement(prevDataIndex + PREV_PTR_OFFSET).GetInt(); - JSTaggedValue data = GetElement(prevDataIndex); - if (JSTaggedValue::SameValue(data, element)) { + int prePreDataIndex = GetPrimitiveElement(prevDataIndex + PREV_PTR_OFFSET).GetInt(); + JSTaggedValue data = GetElement(thread, prevDataIndex); + if (JSTaggedValue::SameValue(thread, data, element)) { return prePreDataIndex; } prevDataIndex = prePreDataIndex; diff --git a/ecmascript/tagged_list.h b/ecmascript/tagged_list.h index 67d07dc201..7bcd52dfa8 100644 --- a/ecmascript/tagged_list.h +++ b/ecmascript/tagged_list.h @@ -41,31 +41,31 @@ public: static JSHandle OwnKeys(JSThread *thread, const JSHandle &taggedList); void CopyArray(const JSThread *thread, JSHandle &taggedList); void Clear(const JSThread *thread); - JSTaggedValue FindElementByIndex(int index) const; - std::pair FindElementByDataIndex(int dataindex) const; - int FindIndexByElement(const JSTaggedValue &element); - int FindLastIndexByElement(const JSTaggedValue &element); + JSTaggedValue FindElementByIndex(const JSThread *thread, int index) const; + std::pair FindElementByDataIndex(const JSThread *thread, int dataindex) const; + int FindIndexByElement(const JSThread *thread, const JSTaggedValue &element); + int FindLastIndexByElement(const JSThread *thread, const JSTaggedValue &element); int FindDataIndexByNodeIndex(int index) const; void MapNodeIndexToDataIndex(std::vector &nodeIndexMapToDataIndex, int length); void RemoveNode(JSThread *thread, int prevDataIndex); int FindPrevNodeByIndex(int index) const; - int FindPrevNodeByValue(const JSTaggedValue &element); + int FindPrevNodeByValue(const JSThread *thread, const JSTaggedValue &element); JSTaggedValue RemoveByIndex(JSThread *thread, const int &index); inline int Length() { return NumberOfNodes(); } - inline JSTaggedValue GetFirst() + inline JSTaggedValue GetFirst(const JSThread *thread) { - int firstDataIndex = GetElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); - return GetElement(firstDataIndex); + int firstDataIndex = GetPrimitiveElement(ELEMENTS_START_INDEX + NEXT_PTR_OFFSET).GetInt(); + return GetElement(thread, firstDataIndex); } - inline JSTaggedValue GetLast() + inline JSTaggedValue GetLast(const JSThread *thread) { - int lastDataIndex = GetElement(TAIL_TABLE_INDEX).GetInt(); - return GetElement(lastDataIndex); + int lastDataIndex = GetPrimitiveElement(TAIL_TABLE_INDEX).GetInt(); + return GetElement(thread, lastDataIndex); } inline int GetCapacityFromTaggedArray() @@ -81,22 +81,30 @@ public: Set(thread, index, element); } - inline JSTaggedValue GetElement(int index) const + inline JSTaggedValue GetElement(const JSThread *thread, int index) const { if (UNLIKELY((index < 0 || index >= static_cast(GetLength())))) { return JSTaggedValue::Undefined(); } - return Get(index); + return Get(thread, index); + } + + inline JSTaggedValue GetPrimitiveElement(int index) const + { + if (UNLIKELY((index < 0 || index >= static_cast(GetLength())))) { + return JSTaggedValue::Undefined(); + } + return GetPrimitive(index); } inline int NumberOfNodes() const { - return Get(NUMBER_OF_NODE_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_NODE_INDEX).GetInt(); } inline int NumberOfDeletedNodes() const { - return Get(NUMBER_OF_DELETED_NODES_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_DELETED_NODES_INDEX).GetInt(); } inline void SetNumberOfDeletedNodes(const JSThread *thread, int nod) @@ -111,7 +119,7 @@ public: int GetNextDataIndex(int dataIndex) const { - dataIndex = GetElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); + dataIndex = GetPrimitiveElement(dataIndex + NEXT_PTR_OFFSET).GetInt(); if (dataIndex != ELEMENTS_START_INDEX) { return dataIndex; } @@ -150,16 +158,16 @@ public: void Clear(const JSThread *thread); bool IsEmpty() const; - bool Has(const JSTaggedValue &value); - JSTaggedValue Get(const int index); - std::pair GetByDataIndex(const int dataIndex); - int GetIndexOf(const JSTaggedValue &value); - int GetLastIndexOf(const JSTaggedValue &value); + bool Has(const JSThread *thread, const JSTaggedValue &value); + JSTaggedValue Get(const JSThread *thread, const int index); + std::pair GetByDataIndex(const JSThread *thread, const int dataIndex); + int GetIndexOf(const JSThread *thread, const JSTaggedValue &value); + int GetLastIndexOf(const JSThread *thread, const JSTaggedValue &value); void InsertNode(const JSThread *thread, const JSHandle &value, const int prevDataIndex, const int finalDataIndex); JSTaggedValue RemoveByIndex(JSThread *thread, const int &index); JSTaggedValue Remove(JSThread *thread, const JSTaggedValue &element); - JSTaggedValue Equal(const JSHandle &compareList); + JSTaggedValue Equal(const JSThread *thread, const JSHandle &compareList); DECL_DUMP() }; @@ -189,24 +197,24 @@ public: static JSTaggedValue RemoveLastFound(JSThread *thread, const JSHandle &taggedList, const JSTaggedValue &element); void Clear(const JSThread *thread); - JSTaggedValue Get(const int index); - std::pair GetByDataIndex(const int dataIndex); + JSTaggedValue Get(const JSThread *thread, const int index); + std::pair GetByDataIndex(const JSThread *thread, const int dataIndex); int GetPrevNode(const int index); - bool Has(const JSTaggedValue &value); + bool Has(const JSThread *thread, const JSTaggedValue &value); void InsertNode(const JSThread *thread, const JSHandle &value, const int prevDataIndex, const int finalDataIndex); JSTaggedValue RemoveFirst(JSThread *thread); JSTaggedValue RemoveLast(JSThread *thread); JSTaggedValue RemoveByIndex(JSThread *thread, const int &index); JSTaggedValue Remove(JSThread *thread, const JSTaggedValue &element); - int GetIndexOf(const JSTaggedValue &value); - int GetLastIndexOf(const JSTaggedValue &value); + int GetIndexOf(const JSThread *thread, const JSTaggedValue &value); + int GetLastIndexOf(const JSThread *thread, const JSTaggedValue &value); int FindPrevNodeByIndexAtLast(const int index) const; - int FindPrevNodeByValueAtLast(const JSTaggedValue &element); + int FindPrevNodeByValueAtLast(const JSThread *thread, const JSTaggedValue &element); DECL_DUMP() protected: - inline JSTaggedValue FindElementByIndexAtLast(int index) const; + inline JSTaggedValue FindElementByIndexAtLast(const JSThread *thread, int index) const; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_LIST_H diff --git a/ecmascript/tagged_node.cpp b/ecmascript/tagged_node.cpp index ce9c0a42c1..ced70f78dd 100644 --- a/ecmascript/tagged_node.cpp +++ b/ecmascript/tagged_node.cpp @@ -25,11 +25,11 @@ JSHandle LinkedNode::Treeing(JSThread *thread, const JSHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); while (!next.GetTaggedValue().IsHole()) { - key.Update(next->GetKey()); - value.Update(next->GetValue()); - rootNode.Update(RBTreeNode::Set(thread, rootNode, next->GetHash().GetInt(), key, value)); - rootNode->SetIsRed(thread, JSTaggedValue(false)); - next.Update(next->GetNext()); + key.Update(next->GetKey(thread)); + value.Update(next->GetValue(thread)); + rootNode.Update(RBTreeNode::Set(thread, rootNode, next->GetHash(thread).GetInt(), key, value)); + rootNode->SetIsRed(false); + next.Update(next->GetNext(thread)); } return rootNode; } @@ -40,7 +40,7 @@ void RBTreeNode::InitRBTreeNode(JSThread *thread, int hash, JSHandle &t JSHandle &head, JSHandle &tail) { if (!treeNode.GetTaggedValue().IsHole()) { - JSHandle leftChild = JSHandle(thread, treeNode->GetLeft()); + JSHandle leftChild = JSHandle(thread, treeNode->GetLeft(thread)); InOrderTraverse(thread, leftChild, head, tail); JSHandle linkedNode = TaggedHashArray::CreateLinkedNodeFrom(thread, treeNode); if (tail.GetTaggedValue().IsHole()) { @@ -66,7 +66,7 @@ void RBTreeNode::InOrderTraverse(JSThread *thread, const JSHandle &t tail->SetNext(thread, linkedNode.GetTaggedValue()); } tail = linkedNode; - JSHandle rightChild(thread, treeNode->GetRight()); + JSHandle rightChild(thread, treeNode->GetRight(thread)); InOrderTraverse(thread, rightChild, head, tail); } } @@ -85,13 +85,13 @@ void RBTreeNode::InOrderTraverse(JSThread *thread, const JSHandle &t LinkedNodeStruct &nodeStruct) { if (!treeNode.GetTaggedValue().IsHole()) { - JSHandle leftChild(thread, treeNode->GetLeft()); + JSHandle leftChild(thread, treeNode->GetLeft(thread)); InOrderTraverse(thread, leftChild, bit, nodeStruct); JSHandle linkedNode = TaggedHashArray::CreateLinkedNodeFrom(thread, treeNode); // the elements from each bin must either stay at same index, // or move with a power of two offset in the new table - if ((static_cast(linkedNode->GetHash().GetInt()) & static_cast(bit)) == 0) { + if ((static_cast(linkedNode->GetHash(thread).GetInt()) & static_cast(bit)) == 0) { if (nodeStruct.lowerTail.GetTaggedValue().IsHole()) { nodeStruct.lowerHead = linkedNode; } else { @@ -107,7 +107,7 @@ void RBTreeNode::InOrderTraverse(JSThread *thread, const JSHandle &t nodeStruct.higherTail = linkedNode; } - JSHandle rightChild(thread, treeNode->GetRight()); + JSHandle rightChild(thread, treeNode->GetRight(thread)); InOrderTraverse(thread, rightChild, bit, nodeStruct); } } @@ -128,12 +128,12 @@ void RBTreeNode::Divide(JSThread *thread, JSHandle table, JSMutableHandle lowerHead(thread, nodeStruct.lowerHead); while (!lowerHead.GetTaggedValue().IsHole()) { loCount++; - lowerHead.Update(lowerHead->GetNext()); + lowerHead.Update(lowerHead->GetNext(thread)); } JSMutableHandle higherHead(thread, nodeStruct.higherHead); while (!higherHead.GetTaggedValue().IsHole()) { loCount++; - higherHead.Update(higherHead->GetNext()); + higherHead.Update(higherHead->GetNext(thread)); } if (!nodeStruct.lowerHead.GetTaggedValue().IsHole()) { @@ -154,10 +154,10 @@ void RBTreeNode::Divide(JSThread *thread, JSHandle table, } } -int RBTreeNode::Compare(int hash1, JSTaggedValue key1, int hash2, JSTaggedValue key2) +int RBTreeNode::Compare(const JSThread *thread, int hash1, JSTaggedValue key1, int hash2, JSTaggedValue key2) { ASSERT(!key1.IsHole() && !key2.IsHole()); - if (JSTaggedValue::SameValue(key1, key2)) { + if (JSTaggedValue::SameValue(thread, key1, key2)) { return 0; } if (hash1 < hash2) { @@ -173,7 +173,7 @@ bool RBTreeNode::IsRed(JSTaggedValue treeNodeValue) return false; } RBTreeNode *treeNode = RBTreeNode::Cast(treeNodeValue.GetTaggedObject()); - return treeNode->GetIsRed().ToBoolean(); + return treeNode->GetIsRed(); } // insert the key-value pair in the subtree rooted at treeNode @@ -184,10 +184,11 @@ JSHandle RBTreeNode::Set(JSThread *thread, JSHandle tree treeNode = TaggedHashArray::NewTreeNode(thread, hash, key, value); return treeNode; } - JSHandle treeNodeKey(thread, treeNode->GetKey()); - int cmp = Compare(hash, key.GetTaggedValue(), treeNode->GetHash().GetInt(), treeNodeKey.GetTaggedValue()); - JSHandle leftChild(thread, treeNode->GetLeft()); - JSHandle rightChild(thread, treeNode->GetRight()); + JSHandle treeNodeKey(thread, treeNode->GetKey(thread)); + int cmp = + Compare(thread, hash, key.GetTaggedValue(), treeNode->GetHash(thread).GetInt(),treeNodeKey.GetTaggedValue()); + JSHandle leftChild(thread, treeNode->GetLeft(thread)); + JSHandle rightChild(thread, treeNode->GetRight(thread)); if (cmp < 0) { JSHandle left = Set(thread, leftChild, hash, key, value); treeNode->SetLeft(thread, left); @@ -198,22 +199,22 @@ JSHandle RBTreeNode::Set(JSThread *thread, JSHandle tree treeNode->SetValue(thread, value); } - if (IsRed(treeNode->GetRight()) && !IsRed(treeNode->GetLeft())) { + if (IsRed(treeNode->GetRight(thread)) && !IsRed(treeNode->GetLeft(thread))) { treeNode = JSHandle(thread, treeNode->RotateLeft(thread)); } - JSTaggedValue leftChildVa = treeNode->GetLeft(); + JSTaggedValue leftChildVa = treeNode->GetLeft(thread); if (!leftChildVa.IsHole()) { leftChild = JSHandle(thread, leftChildVa); - if (IsRed(treeNode->GetLeft()) && IsRed(leftChild->GetLeft())) { + if (IsRed(treeNode->GetLeft(thread)) && IsRed(leftChild->GetLeft(thread))) { treeNode = JSHandle(thread, treeNode->RotateRight(thread)); } } - if (IsRed(treeNode->GetLeft()) && IsRed(treeNode->GetRight())) { + if (IsRed(treeNode->GetLeft(thread)) && IsRed(treeNode->GetRight(thread))) { treeNode->FlipColors(thread); } // 1 : root count - uint32_t count = Count(treeNode->GetLeft()) + Count(treeNode->GetRight()) + 1; + uint32_t count = Count(treeNode->GetLeft(thread)) + Count(treeNode->GetRight(thread)) + 1; treeNode->SetCount(count); return treeNode; @@ -222,17 +223,17 @@ JSHandle RBTreeNode::Set(JSThread *thread, JSHandle tree // make a right-leaning link lean to the left RBTreeNode *RBTreeNode::RotateLeft(JSThread *thread) { - ASSERT(!JSTaggedValue(this).IsHole() && IsRed(GetRight())); - RBTreeNode *temp = RBTreeNode::Cast(GetRight().GetTaggedObject()); - SetRight(thread, temp->GetLeft()); + ASSERT(!JSTaggedValue(this).IsHole() && IsRed(GetRight(thread))); + RBTreeNode *temp = RBTreeNode::Cast(GetRight(thread).GetTaggedObject()); + SetRight(thread, temp->GetLeft(thread)); temp->SetLeft(thread, JSTaggedValue(this)); - RBTreeNode *tempLeft = RBTreeNode::Cast(temp->GetLeft().GetTaggedObject()); - temp->SetIsRed(thread, tempLeft->GetIsRed()); - tempLeft->SetIsRed(thread, JSTaggedValue(true)); + RBTreeNode *tempLeft = RBTreeNode::Cast(temp->GetLeft(thread).GetTaggedObject()); + temp->SetIsRed(tempLeft->GetIsRed()); + tempLeft->SetIsRed(true); temp->SetCount(GetCount()); // 1 : root count - uint32_t count = Count(GetLeft()) + Count(GetRight()) + 1; + uint32_t count = Count(GetLeft(thread)) + Count(GetRight(thread)) + 1; SetCount(count); return temp; @@ -241,17 +242,17 @@ RBTreeNode *RBTreeNode::RotateLeft(JSThread *thread) // make a left-leaning link lean to the right RBTreeNode *RBTreeNode::RotateRight(JSThread *thread) { - ASSERT(!JSTaggedValue(this).IsHole() && IsRed(GetLeft())); - RBTreeNode *temp = RBTreeNode::Cast(GetLeft().GetTaggedObject()); - SetLeft(thread, temp->GetRight()); + ASSERT(!JSTaggedValue(this).IsHole() && IsRed(GetLeft(thread))); + RBTreeNode *temp = RBTreeNode::Cast(GetLeft(thread).GetTaggedObject()); + SetLeft(thread, temp->GetRight(thread)); temp->SetRight(thread, JSTaggedValue(this)); - RBTreeNode *tempRight = RBTreeNode::Cast(temp->GetRight().GetTaggedObject()); - temp->SetIsRed(thread, tempRight->GetIsRed()); - tempRight->SetIsRed(thread, JSTaggedValue(true)); + RBTreeNode *tempRight = RBTreeNode::Cast(temp->GetRight(thread).GetTaggedObject()); + temp->SetIsRed(tempRight->GetIsRed()); + tempRight->SetIsRed(true); temp->SetCount(GetCount()); // 1 : root count - uint32_t count = Count(GetLeft()) + Count(GetRight()) + 1; + uint32_t count = Count(GetLeft(thread)) + Count(GetRight(thread)) + 1; SetCount(count); return temp; @@ -260,31 +261,31 @@ RBTreeNode *RBTreeNode::RotateRight(JSThread *thread) // flip the colors of a node and its two children void RBTreeNode::FlipColors(JSThread *thread) { - SetIsRed(thread, JSTaggedValue(!GetIsRed().ToBoolean())); - RBTreeNode *leftChild = RBTreeNode::Cast(GetLeft().GetTaggedObject()); - leftChild->SetIsRed(thread, JSTaggedValue(!leftChild->GetIsRed().ToBoolean())); - RBTreeNode *rightChild = RBTreeNode::Cast(GetRight().GetTaggedObject()); - rightChild->SetIsRed(thread, JSTaggedValue(!rightChild->GetIsRed().ToBoolean())); + SetIsRed(!GetIsRed()); + RBTreeNode *leftChild = RBTreeNode::Cast(GetLeft(thread).GetTaggedObject()); + leftChild->SetIsRed(!leftChild->GetIsRed()); + RBTreeNode *rightChild = RBTreeNode::Cast(GetRight(thread).GetTaggedObject()); + rightChild->SetIsRed(!rightChild->GetIsRed()); } // restore red-black tree invariant JSTaggedValue RBTreeNode::Balance(JSThread *thread, RBTreeNode *treeNode) { - if (IsRed(treeNode->GetRight()) && !IsRed(treeNode->GetLeft())) { + if (IsRed(treeNode->GetRight(thread)) && !IsRed(treeNode->GetLeft(thread))) { treeNode = treeNode->RotateLeft(thread); } - JSTaggedValue leftValue = treeNode->GetLeft(); + JSTaggedValue leftValue = treeNode->GetLeft(thread); if (!leftValue.IsHole()) { RBTreeNode *leftChild = RBTreeNode::Cast(leftValue.GetTaggedObject()); - if (IsRed(treeNode->GetLeft()) && IsRed(leftChild->GetLeft())) { + if (IsRed(treeNode->GetLeft(thread)) && IsRed(leftChild->GetLeft(thread))) { treeNode = treeNode->RotateRight(thread); } } - if (IsRed(treeNode->GetLeft()) && IsRed(treeNode->GetRight())) { + if (IsRed(treeNode->GetLeft(thread)) && IsRed(treeNode->GetRight(thread))) { treeNode->FlipColors(thread); } // 1 : root count - uint32_t count = Count(treeNode->GetLeft()) + Count(treeNode->GetRight()) + 1; + uint32_t count = Count(treeNode->GetLeft(thread)) + Count(treeNode->GetRight(thread)) + 1; treeNode->SetCount(count); return JSTaggedValue(treeNode); @@ -294,8 +295,8 @@ RBTreeNode *RBTreeNode::MoveRedLeft(JSThread *thread) { RBTreeNode *treeNode = this; treeNode->FlipColors(thread); - RBTreeNode *rightChild = RBTreeNode::Cast(treeNode->GetRight().GetTaggedObject()); - if (IsRed(rightChild->GetLeft())) { + RBTreeNode *rightChild = RBTreeNode::Cast(treeNode->GetRight(thread).GetTaggedObject()); + if (IsRed(rightChild->GetLeft(thread))) { rightChild = rightChild->RotateRight(thread); treeNode->SetRight(thread, JSTaggedValue(rightChild)); treeNode = treeNode->RotateLeft(thread); @@ -309,8 +310,8 @@ RBTreeNode *RBTreeNode::MoveRedRight(JSThread *thread) { RBTreeNode *treeNode = this; treeNode->FlipColors(thread); - RBTreeNode *leftChild = RBTreeNode::Cast(treeNode->GetLeft().GetTaggedObject()); - if (IsRed(leftChild->GetLeft())) { + RBTreeNode *leftChild = RBTreeNode::Cast(treeNode->GetLeft(thread).GetTaggedObject()); + if (IsRed(leftChild->GetLeft(thread))) { treeNode = treeNode->RotateRight(thread); treeNode->FlipColors(thread); } @@ -321,13 +322,13 @@ RBTreeNode *RBTreeNode::MoveRedRight(JSThread *thread) // delete the key-value pair with the minimum key rooted at treeNode JSTaggedValue RBTreeNode::DeleteMin(JSThread *thread, RBTreeNode *treeNode) { - if (treeNode->GetLeft().IsHole()) { + if (treeNode->GetLeft(thread).IsHole()) { return JSTaggedValue::Hole(); } - RBTreeNode *leftChild = RBTreeNode::Cast(treeNode->GetLeft().GetTaggedObject()); - if (!IsRed(treeNode->GetLeft()) && !IsRed(leftChild->GetLeft())) { + RBTreeNode *leftChild = RBTreeNode::Cast(treeNode->GetLeft(thread).GetTaggedObject()); + if (!IsRed(treeNode->GetLeft(thread)) && !IsRed(leftChild->GetLeft(thread))) { treeNode = treeNode->MoveRedLeft(thread); - leftChild = RBTreeNode::Cast(treeNode->GetLeft().GetTaggedObject()); + leftChild = RBTreeNode::Cast(treeNode->GetLeft(thread).GetTaggedObject()); } treeNode->SetLeft(thread, DeleteMin(thread, leftChild)); @@ -342,46 +343,47 @@ JSTaggedValue RBTreeNode::Delete(JSThread *thread, const JSTaggedValue &treeNode return JSTaggedValue::Hole(); } RBTreeNode *treeNode = RBTreeNode::Cast(treeNodeVa.GetTaggedObject()); - JSTaggedValue leftChildVa = treeNode->GetLeft(); - JSTaggedValue treeNodeKey = treeNode->GetKey(); - int cmp = Compare(hash, key, treeNode->GetHash().GetInt(), treeNodeKey); + JSTaggedValue leftChildVa = treeNode->GetLeft(thread); + JSTaggedValue treeNodeKey = treeNode->GetKey(thread); + int cmp = Compare(thread, hash, key, treeNode->GetHash(thread).GetInt(), treeNodeKey); if (cmp < 0) { if (!leftChildVa.IsHole() && - !IsRed(treeNode->GetLeft()) && !IsRed(RBTreeNode::Cast(leftChildVa.GetTaggedObject())->GetLeft())) { + !IsRed(treeNode->GetLeft(thread)) && + !IsRed(RBTreeNode::Cast(leftChildVa.GetTaggedObject())->GetLeft(thread))) { treeNode = treeNode->MoveRedLeft(thread); } - leftChildVa = treeNode->GetLeft(); + leftChildVa = treeNode->GetLeft(thread); JSTaggedValue leftValue = Delete(thread, leftChildVa, hash, key, oldValue); treeNode->SetLeft(thread, leftValue); } else { - if (IsRed(treeNode->GetLeft())) { + if (IsRed(treeNode->GetLeft(thread))) { treeNode = treeNode->RotateRight(thread); - treeNodeKey = treeNode->GetKey(); + treeNodeKey = treeNode->GetKey(thread); } - cmp = Compare(hash, key, treeNode->GetHash().GetInt(), treeNodeKey); - if (cmp == 0 && treeNode->GetRight().IsHole()) { - oldValue = treeNode->GetValue(); + cmp = Compare(thread, hash, key, treeNode->GetHash(thread).GetInt(), treeNodeKey); + if (cmp == 0 && treeNode->GetRight(thread).IsHole()) { + oldValue = treeNode->GetValue(thread); return JSTaggedValue::Hole(); } - JSTaggedValue rightChildVa = treeNode->GetRight(); + JSTaggedValue rightChildVa = treeNode->GetRight(thread); if (!rightChildVa.IsHole() && - !IsRed(rightChildVa) && !IsRed(RBTreeNode::Cast(rightChildVa.GetTaggedObject())->GetLeft())) { + !IsRed(rightChildVa) && !IsRed(RBTreeNode::Cast(rightChildVa.GetTaggedObject())->GetLeft(thread))) { treeNode = treeNode->MoveRedRight(thread); - treeNodeKey = treeNode->GetKey(); + treeNodeKey = treeNode->GetKey(thread); } - cmp = Compare(hash, key, treeNode->GetHash().GetInt(), treeNodeKey); - rightChildVa = treeNode->GetRight(); + cmp = Compare(thread, hash, key, treeNode->GetHash(thread).GetInt(), treeNodeKey); + rightChildVa = treeNode->GetRight(thread); if (rightChildVa.IsHole()) { return Balance(thread, treeNode); } RBTreeNode *rightChild = RBTreeNode::Cast(rightChildVa.GetTaggedObject()); if (cmp == 0) { - oldValue = treeNode->GetValue(); - RBTreeNode *minNode = rightChild->Min(); - treeNode->SetKey(thread, minNode->GetKey()); - treeNode->SetValue(thread, minNode->GetValue()); - treeNode->SetHash(thread, minNode->GetHash()); + oldValue = treeNode->GetValue(thread); + RBTreeNode *minNode = rightChild->Min(thread); + treeNode->SetKey(thread, minNode->GetKey(thread)); + treeNode->SetValue(thread, minNode->GetValue(thread)); + treeNode->SetHash(thread, minNode->GetHash(thread)); treeNode->SetRight(thread, DeleteMin(thread, rightChild)); } else { JSTaggedValue tmpValue = Delete(thread, rightChildVa, hash, key, oldValue); @@ -392,12 +394,12 @@ JSTaggedValue RBTreeNode::Delete(JSThread *thread, const JSTaggedValue &treeNode } // the smallest key in subtree rooted at treeNode; hole if no such key -RBTreeNode *RBTreeNode::Min() +RBTreeNode *RBTreeNode::Min(JSThread *thread) { - if (GetLeft().IsHole()) { + if (GetLeft(thread).IsHole()) { return this; } else { - return RBTreeNode::Cast(GetLeft().GetTaggedObject())->Min(); + return RBTreeNode::Cast(GetLeft(thread).GetTaggedObject())->Min(thread); } } @@ -412,18 +414,18 @@ JSTaggedValue RBTreeNode::GetTreeNode(JSThread *thread, JSHandle JSMutableHandle currentKey(thread, JSTaggedValue::Hole()); JSMutableHandle left(thread, JSTaggedValue::Hole()); JSMutableHandle right(thread, JSTaggedValue::Hole()); - while (!queue->Empty()) { + while (!queue->Empty(thread)) { root.Update(queue->Pop(thread)); - currentKey.Update(root->GetKey()); - if (root->GetHash().GetInt() == hash && (!currentKey->IsHole() && JSTaggedValue::SameValue(key, currentKey))) { + currentKey.Update(root->GetKey(thread)); + if (root->GetHash(thread).GetInt() == hash && (!currentKey->IsHole() && JSTaggedValue::SameValue(thread, key, currentKey))) { return root.GetTaggedValue(); } - if (!root->GetLeft().IsHole()) { - left.Update(root->GetLeft()); + if (!root->GetLeft(thread).IsHole()) { + left.Update(root->GetLeft(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left))); } - if (!root->GetRight().IsHole()) { - right.Update(root->GetRight()); + if (!root->GetRight(thread).IsHole()) { + right.Update(root->GetRight(thread)); queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right))); } } diff --git a/ecmascript/tagged_node.h b/ecmascript/tagged_node.h index 67b418a738..e7450398eb 100644 --- a/ecmascript/tagged_node.h +++ b/ecmascript/tagged_node.h @@ -63,10 +63,10 @@ public: } if (key.IsString()) { auto keyString = reinterpret_cast(key.GetTaggedObject()); - return EcmaStringAccessor(keyString).GetHashcode(); + return EcmaStringAccessor(keyString).GetHashcode(thread); } if (key.IsECMAObject()) { - int32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(); + int32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(thread); if (hash == 0) { hash = base::RandomGenerator::GenerateIdentityHash(); JSHandle ecmaObj(thread, key); @@ -127,11 +127,11 @@ public: static constexpr size_t LEFT_OFFSET = TaggedNode::SIZE; ACCESSORS(Left, LEFT_OFFSET, RIGHT_OFFSET); ACCESSORS(Right, RIGHT_OFFSET, ISRED_OFFSET); - ACCESSORS(IsRed, ISRED_OFFSET, COUNT_OFFSET); + ACCESSORS_FIXED_SIZE_FIELD(IsRed, bool, uint64_t, ISRED_OFFSET, COUNT_OFFSET); ACCESSORS_PRIMITIVE_FIELD(Count, uint32_t, COUNT_OFFSET, LAST_OFFSET) DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT(TaggedObject::SIZE, COUNT_OFFSET) + DECL_VISIT_OBJECT(TaggedObject::SIZE, ISRED_OFFSET) void InitRBTreeNode(JSThread *thread, int hash, JSHandle key, JSHandle value, int count); @@ -147,7 +147,7 @@ public: JSHandle &head, JSHandle &tail); static JSHandle Detreeing(JSThread *thread, const JSHandle &root); static uint32_t Count(JSTaggedValue nodeValue); - static int Compare(int hash1, JSTaggedValue key1, int hash2, JSTaggedValue key2); + static int Compare(const JSThread *thread, int hash1, JSTaggedValue key1, int hash2, JSTaggedValue key2); static bool IsRed(JSTaggedValue treeNodeValue); private: static void InOrderTraverse(JSThread *thread, const JSHandle &treeNode, @@ -159,7 +159,7 @@ private: void FlipColors(JSThread *thread); RBTreeNode *MoveRedLeft(JSThread *thread); RBTreeNode *MoveRedRight(JSThread *thread); - RBTreeNode *Min(); + RBTreeNode *Min(JSThread *thread); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_NODE_H diff --git a/ecmascript/tagged_queue.h b/ecmascript/tagged_queue.h index c177efee0a..b52297c6fd 100644 --- a/ecmascript/tagged_queue.h +++ b/ecmascript/tagged_queue.h @@ -32,15 +32,15 @@ public: inline JSTaggedValue Pop(JSThread *thread) { - if (Empty()) { + if (Empty(thread)) { return JSTaggedValue::Hole(); } - uint32_t start = GetStart().GetArrayLength(); - JSTaggedValue value = Get(start); + uint32_t start = GetStart(thread).GetArrayLength(); + JSTaggedValue value = Get(thread, start); Set(thread, start, JSTaggedValue::Hole()); - uint32_t capacity = GetCapacity().GetArrayLength(); + uint32_t capacity = GetCapacity(thread).GetArrayLength(); ASSERT(capacity != 0); SetStart(thread, JSTaggedValue((start + 1) % capacity)); return value; @@ -49,7 +49,7 @@ public: static TaggedQueue *Push(const JSThread *thread, const JSHandle &queue, const JSHandle &value) { - uint32_t capacity = queue->GetCapacity().GetArrayLength(); + uint32_t capacity = queue->GetCapacity(thread).GetArrayLength(); if (capacity == 0) { // If there is no capacity, directly create a queue whose capacity is MIN_CAPACITY. Add elements. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -61,9 +61,9 @@ public: return *newQueue; } - uint32_t start = queue->GetStart().GetArrayLength(); - uint32_t end = queue->GetEnd().GetArrayLength(); - uint32_t size = queue->Size(); + uint32_t start = queue->GetStart(thread).GetArrayLength(); + uint32_t end = queue->GetEnd(thread).GetArrayLength(); + uint32_t size = queue->Size(thread); if ((end + 1) % capacity == start) { // The original queue is full and needs to be expanded. if (capacity == MAX_QUEUE_INDEX) { @@ -77,7 +77,7 @@ public: JSHandle newQueue = factory->NewTaggedQueue(newCapacity); uint32_t newEnd = 0; for (uint32_t i = start; newEnd < size; i = (i + 1) % capacity) { - newQueue->Set(thread, newEnd, queue->Get(i)); + newQueue->Set(thread, newEnd, queue->Get(thread, i)); newEnd++; } @@ -96,49 +96,49 @@ public: static inline void PushFixedQueue(const JSThread *thread, const JSHandle &queue, const JSHandle &value) { - uint32_t end = queue->GetEnd().GetArrayLength(); - uint32_t capacity = queue->GetCapacity().GetArrayLength(); + uint32_t end = queue->GetEnd(thread).GetArrayLength(); + uint32_t capacity = queue->GetCapacity(thread).GetArrayLength(); ASSERT(capacity != 0); queue->Set(thread, end, value.GetTaggedValue()); queue->SetEnd(thread, JSTaggedValue((end + 1) % capacity)); } - inline bool Empty() + inline bool Empty(const JSThread *thread) { - return GetStart() == GetEnd(); + return GetStart(thread) == GetEnd(thread); } - inline JSTaggedValue Front() + inline JSTaggedValue Front(const JSThread *thread) { - if (Empty()) { + if (Empty(thread)) { return JSTaggedValue::Hole(); } - uint32_t start = GetStart().GetArrayLength(); - return JSTaggedValue(Get(start)); + uint32_t start = GetStart(thread).GetArrayLength(); + return JSTaggedValue(Get(thread, start)); } - inline JSTaggedValue Back() + inline JSTaggedValue Back(const JSThread *thread) { - if (Empty()) { + if (Empty(thread)) { return JSTaggedValue::Hole(); } - return JSTaggedValue(Get(GetEnd().GetArrayLength() - 1)); + return JSTaggedValue(Get(thread, GetEnd(thread).GetArrayLength() - 1)); } - inline uint32_t Size() + inline uint32_t Size(const JSThread *thread) { - uint32_t capacity = GetCapacity().GetArrayLength(); + uint32_t capacity = GetCapacity(thread).GetArrayLength(); if (capacity == 0) { return 0; } - uint32_t end = GetEnd().GetArrayLength(); - uint32_t start = GetStart().GetArrayLength(); + uint32_t end = GetEnd(thread).GetArrayLength(); + uint32_t start = GetStart(thread).GetArrayLength(); return (end - start + capacity) % capacity; } - inline JSTaggedValue Get(uint32_t index) const + inline JSTaggedValue Get(const JSThread *thread, uint32_t index) const { - return TaggedArray::Get(QueueToArrayIndex(index)); + return TaggedArray::Get(thread, QueueToArrayIndex(index)); } inline void Set(const JSThread *thread, uint32_t index, JSTaggedValue value) @@ -166,9 +166,9 @@ private: TaggedArray::Set(thread, CAPACITY_INDEX, capacity); } - inline JSTaggedValue GetCapacity() const + inline JSTaggedValue GetCapacity(const JSThread *thread) const { - return TaggedArray::Get(CAPACITY_INDEX); + return TaggedArray::Get(thread, CAPACITY_INDEX); } inline void SetStart(const JSThread *thread, JSTaggedValue start) @@ -176,9 +176,9 @@ private: TaggedArray::Set(thread, START_INDEX, start); } - inline JSTaggedValue GetStart() const + inline JSTaggedValue GetStart(const JSThread *thread) const { - return TaggedArray::Get(START_INDEX); + return TaggedArray::Get(thread, START_INDEX); } inline void SetEnd(const JSThread *thread, JSTaggedValue end) @@ -186,9 +186,9 @@ private: TaggedArray::Set(thread, END_INDEX, end); } - inline JSTaggedValue GetEnd() const + inline JSTaggedValue GetEnd(const JSThread *thread) const { - return TaggedArray::Get(END_INDEX); + return TaggedArray::Get(thread, END_INDEX); } static inline TaggedQueue *Create(JSThread *thread, uint32_t capacity, diff --git a/ecmascript/tagged_tree.cpp b/ecmascript/tagged_tree.cpp index 244a8e5b03..d93bfd9c8d 100644 --- a/ecmascript/tagged_tree.cpp +++ b/ecmascript/tagged_tree.cpp @@ -39,7 +39,7 @@ JSHandle TaggedTree::Create(const JSThread *thread, int number template void TaggedTree::InsertRebalance(const JSThread *thread, int index) { - while (IsValidIndex(index) && GetColor(GetParent(index)) == TreeColor::RED) { + while (IsValidIndex(thread, index) && GetColor(GetParent(index)) == TreeColor::RED) { if (IsLeft(GetParent(index))) { int bro = GetLeftBrother(GetParent(index)); if (GetColor(bro)) { @@ -311,7 +311,7 @@ template int TaggedTree::FindEntry(JSThread *thread, const JSHandle &tree, const JSHandle &key) { int parentIndex = tree->GetRootEntries(); - JSMutableHandle parentKey(thread, tree->GetKey(parentIndex)); + JSMutableHandle parentKey(thread, tree->GetKey(thread, parentIndex)); ComparisonResult res; while (!parentKey->IsHole()) { res = EntryCompare(thread, key, parentKey, tree); @@ -331,7 +331,7 @@ int TaggedTree::FindEntry(JSThread *thread, const JSHandle &tr } parentIndex = child.GetInt(); } - parentKey.Update(tree->GetKey(parentIndex)); + parentKey.Update(tree->GetKey(thread, parentIndex)); } return -1; } @@ -340,7 +340,7 @@ template ComparisonResult TaggedTree::EntryCompare(JSThread *thread, const JSHandle valueX, const JSHandle valueY, JSHandle tree) { - JSTaggedValue fn = tree->GetCompare(); + JSTaggedValue fn = tree->GetCompare(thread); if (fn.IsHole()) { return OrdinayEntryCompare(thread, valueX, valueY); } @@ -418,7 +418,7 @@ JSHandle TaggedTree::Insert(JSThread *thread, JSHandle &key, const JSHandle &value) { ASSERT(IsKey(key.GetTaggedValue())); - JSMutableHandle parentKey(thread, tree->GetRootKey()); + JSMutableHandle parentKey(thread, tree->GetRootKey(thread)); if (parentKey->IsHole()) { tree->SetRoot(thread, 0, key.GetTaggedValue(), value.GetTaggedValue()); tree->SetNumberOfElements(thread, tree->NumberOfElements() + 1); @@ -447,7 +447,7 @@ JSHandle TaggedTree::Insert(JSThread *thread, JSHandleGetKey(parentIndex)); + parentKey.Update(newTree->GetKey(thread, parentIndex)); } uint32_t entry = newTree->NumberOfElements() + newTree->NumberOfDeletedElements(); @@ -473,7 +473,7 @@ JSHandle TaggedTree::GrowCapacity(const JSThread *thread, JSHa int newCapacity = ComputeCapacity(oldCapacity); int length = ELEMENTS_START_INDEX + newCapacity * (Derived::ENTRY_SIZE); JSHandle newTree = AdjustTaggedTree(thread, tree, length); - JSTaggedValue fn = tree->GetCompare(); + JSTaggedValue fn = tree->GetCompare(thread); if (!fn.IsUndefined() && !fn.IsNull()) { newTree->SetCompare(thread, fn); } @@ -486,7 +486,7 @@ JSTaggedValue TaggedTree::GetLowerKey(JSThread *thread, const JSHandle< const JSHandle &key) { int parentIndex = tree->GetRootEntries(); - JSMutableHandle parentKey(thread, tree->GetKey(parentIndex)); + JSMutableHandle parentKey(thread, tree->GetKey(thread, parentIndex)); int resultIndex = -1; ComparisonResult res; while (parentIndex >= 0) { @@ -498,9 +498,9 @@ JSTaggedValue TaggedTree::GetLowerKey(JSThread *thread, const JSHandle< } else { parentIndex = tree->GetLeftChildIndex(parentIndex); } - parentKey.Update(tree->GetKey(parentIndex)); + parentKey.Update(tree->GetKey(thread, parentIndex)); } - JSTaggedValue lowerKey = tree->GetKey(resultIndex); + JSTaggedValue lowerKey = tree->GetKey(thread, resultIndex); return tree->Transform(lowerKey); } @@ -509,7 +509,7 @@ JSTaggedValue TaggedTree::GetHigherKey(JSThread *thread, const JSHandle const JSHandle &key) { int parentIndex = tree->GetRootEntries(); - JSMutableHandle parentKey(thread, tree->GetKey(parentIndex)); + JSMutableHandle parentKey(thread, tree->GetKey(thread, parentIndex)); int resultIndex = -1; ComparisonResult res; while (parentIndex >= 0) { @@ -521,9 +521,9 @@ JSTaggedValue TaggedTree::GetHigherKey(JSThread *thread, const JSHandle } else { parentIndex = tree->GetRightChildIndex(parentIndex); } - parentKey.Update(tree->GetKey(parentIndex)); + parentKey.Update(tree->GetKey(thread, parentIndex)); } - JSTaggedValue lowerKey = tree->GetKey(resultIndex); + JSTaggedValue lowerKey = tree->GetKey(thread, resultIndex); return tree->Transform(lowerKey); } @@ -541,7 +541,7 @@ JSHandle TaggedTree::Shrink(const JSThread *thread, const JSHa int length = ELEMENTS_START_INDEX + static_cast(newCapacity) * (Derived::ENTRY_SIZE); JSHandle newTree = AdjustTaggedTree(thread, tree, length); - JSTaggedValue fn = tree->GetCompare(); + JSTaggedValue fn = tree->GetCompare(thread); JSHandle compareFn = JSHandle(thread, fn); if (!compareFn->IsUndefined() && !compareFn->IsNull()) { newTree->SetCompare(thread, compareFn.GetTaggedValue()); @@ -584,7 +584,7 @@ bool TaggedTreeMap::HasValue([[maybe_unused]] const JSThread *thread, JSTaggedVa entries.push(root); while (!entries.empty()) { int parent = entries.front(); - if (JSTaggedValue::SameValue(GetValue(parent), value)) { + if (JSTaggedValue::SameValue(thread, GetValue(thread, parent), value)) { return true; } int left = GetLeftChildIndex(parent); @@ -607,8 +607,8 @@ JSTaggedValue TaggedTreeMap::SetAll(JSThread *thread, JSHandle &d JSHandle map = dst; while (!entries.empty()) { int parent = entries.front(); - map = Insert(thread, map, JSHandle(thread, src->GetKey(parent)), - JSHandle(thread, src->GetValue(parent))); + map = Insert(thread, map, JSHandle(thread, src->GetKey(thread, parent)), + JSHandle(thread, src->GetValue(thread, parent))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int left = src->GetLeftChildIndex(parent); if (left >= 0) { diff --git a/ecmascript/tagged_tree.h b/ecmascript/tagged_tree.h index 866818c6fd..c52cbb3c7b 100644 --- a/ecmascript/tagged_tree.h +++ b/ecmascript/tagged_tree.h @@ -60,32 +60,32 @@ public: inline uint32_t NumberOfElements() const { - return Get(NUMBER_OF_ELEMENTS_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_ELEMENTS_INDEX).GetInt(); } inline uint32_t NumberOfDeletedElements() const { - return Get(NUMBER_OF_HOLE_ENTRIES_INDEX).GetInt(); + return GetPrimitive(NUMBER_OF_HOLE_ENTRIES_INDEX).GetInt(); } inline int Capacity() const { - return Get(CAPACITY_INDEX).GetInt(); + return GetPrimitive(CAPACITY_INDEX).GetInt(); } - inline JSTaggedValue GetKey(int entry) const + inline JSTaggedValue GetKey(const JSThread *thread, int entry) const { if (entry < 0) { return JSTaggedValue::Hole(); } int index = EntryToIndex(entry); - return GetElement(index); + return GetElement(thread, index); } - inline JSTaggedValue GetValue(int entry) const + inline JSTaggedValue GetValue(const JSThread *thread, int entry) const { int index = static_cast(EntryToIndex(entry) + Derived::ENTRY_VALUE_INDEX); - return GetElement(index); + return GetElement(thread, index); } inline TreeColor GetColor(int entry) const @@ -94,7 +94,7 @@ public: return TreeColor::BLACK; } int index = static_cast(EntryToIndex(entry) + Derived::ENTRY_COLOR_INDEX); - JSTaggedValue color = GetElement(index); + JSTaggedValue color = GetPrimitive(index); return color.GetInt() == TreeColor::RED ? TreeColor::RED : TreeColor::BLACK; } @@ -125,7 +125,7 @@ public: inline int GetRootEntries() const { - return Get(ROOT_INDEX).GetInt(); + return GetPrimitive(ROOT_INDEX).GetInt(); } static int FindEntry(JSThread *thread, const JSHandle &tree, const JSHandle &key); @@ -150,9 +150,9 @@ public: Set(thread, COMPARE_FUNCTION_INDEX, fn); } - inline JSTaggedValue GetCompare() const + inline JSTaggedValue GetCompare(const JSThread *thread) const { - return Get(COMPARE_FUNCTION_INDEX); + return Get(thread, COMPARE_FUNCTION_INDEX); } inline int GetMinimum(int entry) const @@ -178,7 +178,7 @@ public: inline int GetParent(int entry) const { int index = static_cast(EntryToIndex(entry) + Derived::ENTRY_PARENT_INDEX); - JSTaggedValue parent = GetElement(index); + JSTaggedValue parent = GetPrimitive(index); return parent.GetInt(); } @@ -188,7 +188,7 @@ public: return JSTaggedValue::Hole(); } int index = static_cast(EntryToIndex(parent) + Derived::ENTRY_LEFT_CHILD_INDEX); - return Get(index); + return GetPrimitive(index); } inline JSTaggedValue GetRightChild(int parent) const @@ -197,7 +197,7 @@ public: return JSTaggedValue::Hole(); } int index = static_cast(EntryToIndex(parent) + Derived::ENTRY_RIGHT_CHILD_INDEX); - return Get(index); + return GetPrimitive(index); } inline int GetLeftChildIndex(int parent) const @@ -206,7 +206,7 @@ public: return -1; } int index = static_cast(EntryToIndex(parent) + Derived::ENTRY_LEFT_CHILD_INDEX); - JSTaggedValue child = Get(index); + JSTaggedValue child = GetPrimitive(index); return child.IsHole() ? -1 : child.GetInt(); } @@ -216,21 +216,21 @@ public: return -1; } int index = static_cast(EntryToIndex(parent) + Derived::ENTRY_RIGHT_CHILD_INDEX); - JSTaggedValue child = Get(index); + JSTaggedValue child = GetPrimitive(index); return child.IsHole() ? -1 : child.GetInt(); } protected: - inline JSTaggedValue GetElement(int index) const + inline JSTaggedValue GetElement(const JSThread *thread, int index) const { ASSERT(index >= 0 && index < static_cast(GetLength())); - return Get(index); + return Get(thread, index); } // get root - inline JSTaggedValue GetRootKey() const + inline JSTaggedValue GetRootKey(const JSThread *thread) const { - return GetKey(GetRootEntries()); + return GetKey(thread, GetRootEntries()); } inline int EntryToIndex(uint32_t entry) const @@ -293,9 +293,9 @@ protected: void InsertRebalance(const JSThread *thread, int index); void DeleteRebalance(const JSThread *thread, int index); - inline bool IsValidIndex(int entry) const + inline bool IsValidIndex(const JSThread *thread, int entry) const { - return entry != GetRootEntries() && !GetKey(entry).IsHole(); + return entry != GetRootEntries() && !GetKey(thread, entry).IsHole(); } inline int GetLeftBrother(int entry) const @@ -375,18 +375,18 @@ protected: inline void CopyEntry(const JSThread *thread, int parent, const JSHandle &newTree, int index) { - newTree->SetKey(thread, index, GetKey(parent)); + newTree->SetKey(thread, index, GetKey(thread, parent)); newTree->SetColor(thread, index, GetColor(parent)); } inline void CopyData(const JSThread *thread, int dst, int src) { - SetKey(thread, dst, GetKey(src)); + SetKey(thread, dst, GetKey(thread, src)); } inline void CopyAllData(const JSThread *thread, int parent, const JSHandle &newTree, int index) { - newTree->SetKey(thread, index, GetKey(parent)); - newTree->SetValue(thread, index, GetValue(parent)); + newTree->SetKey(thread, index, GetKey(thread, parent)); + newTree->SetValue(thread, index, GetValue(thread, parent)); newTree->SetColor(thread, index, GetColor(parent)); newTree->SetParent(thread, index, JSTaggedValue(GetParent(parent))); newTree->SetRightChild(thread, index, GetRightChild(parent)); @@ -432,7 +432,7 @@ public: const JSHandle &key) { int index = RBTree::FindEntry(thread, map, key); - return index == -1 ? JSTaggedValue::Undefined() : map->GetValue(index); + return index == -1 ? JSTaggedValue::Undefined() : map->GetValue(thread, index); } static JSTaggedValue Delete(JSThread *thread, const JSHandle &map, int entry); @@ -443,15 +443,15 @@ public: static JSTaggedValue GetHigherKey(JSThread *thread, const JSHandle &map, const JSHandle &key); - inline JSTaggedValue GetFirstKey() const + inline JSTaggedValue GetFirstKey(const JSThread *thread) const { - JSTaggedValue key = GetKey(GetMinimum(GetRootEntries())); + JSTaggedValue key = GetKey(thread, GetMinimum(GetRootEntries())); return Transform(key); } - inline JSTaggedValue GetLastKey() const + inline JSTaggedValue GetLastKey(const JSThread *thread) const { - JSTaggedValue key = GetKey(GetMaximum(GetRootEntries())); + JSTaggedValue key = GetKey(thread, GetMaximum(GetRootEntries())); return Transform(key); } @@ -470,12 +470,12 @@ public: inline void CopyEntry(const JSThread *thread, int parent, const JSHandle &newMap, int index) { RBTree::CopyEntry(thread, parent, newMap, index); - newMap->SetValue(thread, index, GetValue(parent)); + newMap->SetValue(thread, index, GetValue(thread, parent)); } inline void CopyData(const JSThread *thread, int dst, int src) { RBTree::CopyData(thread, dst, src); - SetValue(thread, dst, GetValue(src)); + SetValue(thread, dst, GetValue(thread, src)); } inline void RemoveEntry(const JSThread *thread, int index) @@ -502,15 +502,15 @@ public: static JSTaggedValue GetHigherKey(JSThread *thread, const JSHandle &set, const JSHandle &key); - inline JSTaggedValue GetFirstKey() const + inline JSTaggedValue GetFirstKey(const JSThread *thread) const { - JSTaggedValue key = GetKey(GetMinimum(GetRootEntries())); + JSTaggedValue key = GetKey(thread, GetMinimum(GetRootEntries())); return Transform(key); } - inline JSTaggedValue GetLastKey() const + inline JSTaggedValue GetLastKey(const JSThread *thread) const { - JSTaggedValue key = GetKey(GetMaximum(GetRootEntries())); + JSTaggedValue key = GetKey(thread, GetMaximum(GetRootEntries())); return Transform(key); } @@ -529,13 +529,13 @@ public: inline void CopyEntry(const JSThread *thread, int parent, const JSHandle &newMap, int index) { RBTree::CopyEntry(thread, parent, newMap, index); - newMap->SetValue(thread, index, GetValue(parent)); + newMap->SetValue(thread, index, GetValue(thread, parent)); } inline void CopyData(const JSThread *thread, int dst, int src) { RBTree::CopyData(thread, dst, src); - SetValue(thread, dst, GetValue(src)); + SetValue(thread, dst, GetValue(thread, src)); } inline void RemoveEntry(const JSThread *thread, int index) diff --git a/ecmascript/template_map.h b/ecmascript/template_map.h index f735819e1b..7d7c652722 100644 --- a/ecmascript/template_map.h +++ b/ecmascript/template_map.h @@ -23,11 +23,11 @@ namespace panda::ecmascript { class TemplateMap : public TaggedHashTable { public: using HashTable = TaggedHashTable; - static inline bool IsMatch(const JSTaggedValue &key, const JSTaggedValue &other) + static inline bool IsMatch([[maybe_unused]] const JSThread *thread, const JSTaggedValue &key, const JSTaggedValue &other) { return key == other; } - static inline int Hash(const JSTaggedValue &obj) + static inline int Hash([[maybe_unused]] const JSThread *thread, const JSTaggedValue &obj) { ASSERT(obj.IsJSArray()); JSArray *array = JSArray::Cast(obj.GetTaggedObject()); @@ -59,7 +59,7 @@ public: { return HashTable::Create(thread, numberOfElements); } - static int ComputeCompactSize([[maybe_unused]] const JSHandle &table, int computeHashTableSize, + static int ComputeCompactSize([[maybe_unused]] const JSThread *thread, [[maybe_unused]] const JSHandle &table, int computeHashTableSize, [[maybe_unused]] int tableSize, [[maybe_unused]] int addedElements) { return computeHashTableSize; diff --git a/ecmascript/template_string.cpp b/ecmascript/template_string.cpp index 51df52d9fa..c55507eb5e 100644 --- a/ecmascript/template_string.cpp +++ b/ecmascript/template_string.cpp @@ -26,9 +26,9 @@ JSHandle TemplateString::GetTemplateObject(JSThread *thread, JSHa RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSHandle templateMapTag = env->GetTemplateMap(); JSHandle templateMap(templateMapTag); - int32_t element = templateMap->FindEntry(rawStringsTag.GetTaggedValue()); + int32_t element = templateMap->FindEntry(thread, rawStringsTag.GetTaggedValue()); if (element != -1) { - return JSHandle(thread, templateMap->GetValue(element)); + return JSHandle(thread, templateMap->GetValue(thread, element)); } JSHandle cookedStringsTag = JSObject::GetProperty(thread, templateLiteral, 1).GetValue(); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); diff --git a/ecmascript/tests/accessor_data_test.cpp b/ecmascript/tests/accessor_data_test.cpp index 4fba99849e..3009bac6a9 100644 --- a/ecmascript/tests/accessor_data_test.cpp +++ b/ecmascript/tests/accessor_data_test.cpp @@ -103,11 +103,11 @@ HWTEST_F_L0(AccessorDataTest, HasSetter) // 1.Create normal AccessorData object by NewAccessorData function. JSHandle accHandle = factory->NewAccessorData(); - EXPECT_EQ(accHandle->HasSetter(), false); + EXPECT_EQ(accHandle->HasSetter(thread), false); accHandle->SetSetter(thread, JSTaggedValue::Undefined()); - EXPECT_EQ(accHandle->HasSetter(), false); + EXPECT_EQ(accHandle->HasSetter(thread), false); accHandle->SetSetter(thread, normalFunction); - EXPECT_EQ(accHandle->HasSetter(), true); + EXPECT_EQ(accHandle->HasSetter(thread), true); // 2.Create internal AccessorData object by NewInternalAccessor function. void *setter = nullptr; @@ -127,9 +127,9 @@ HWTEST_F_L0(AccessorDataTest, HasSetter) AccessorData *acc = AccessorData::Cast(accObject); acc->SetGetter(thread, JSTaggedValue::Undefined()); acc->SetSetter(thread, JSTaggedValue::Undefined()); - EXPECT_EQ(acc->HasSetter(), false); + EXPECT_EQ(acc->HasSetter(thread), false); acc->SetSetter(thread, normalFunction); - EXPECT_EQ(acc->HasSetter(), true); + EXPECT_EQ(acc->HasSetter(thread), true); // 4.Create internal AccessorData object from dynamic class. JSHandle internalAccClass = @@ -156,7 +156,7 @@ HWTEST_F_L0(AccessorDataTest, CallInternalSet) // Construct objects and specify specific prototypes. JSFunction *func1 = globalEnv->GetObjectFunction().GetObject(); - Method::Cast(func1->GetMethod().GetTaggedObject())->SetFunctionKind(FunctionKind::BASE_CONSTRUCTOR); + Method::Cast(func1->GetMethod(thread).GetTaggedObject())->SetFunctionKind(FunctionKind::BASE_CONSTRUCTOR); JSHandle funcTagVal1 = factory->CloneJSFunction(JSHandle(thread, func1)); diff --git a/ecmascript/tests/base_string_test.cpp b/ecmascript/tests/base_string_test.cpp index b038cf1292..3b8094c9e6 100644 --- a/ecmascript/tests/base_string_test.cpp +++ b/ecmascript/tests/base_string_test.cpp @@ -33,6 +33,12 @@ namespace panda::test { EXPECT_TRUE(BaseString::CanBeCompressed(arrayU16Comp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]))); EXPECT_FALSE(BaseString::CanBeCompressed(arrayU16NotComp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]))); } + + auto LoadBarrier() { + return [this](const void *obj, size_t offset) { + return Barriers::GetTaggedObject(thread, obj, offset); + }; + } }; /* @@ -105,7 +111,7 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf8( instance, &arrayU8[0], lengthEcmaStrU8, true)); for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { - EXPECT_EQ(arrayU8[i], handleEcmaStrU8->ToBaseString()->At(Barriers::GetTaggedObject, i)); + EXPECT_EQ(arrayU8[i], handleEcmaStrU8->ToBaseString()->At(LoadBarrier(), i)); } EXPECT_EQ(handleEcmaStrU8->ToBaseString()->GetLength(), lengthEcmaStrU8); EXPECT_TRUE(handleEcmaStrU8->ToBaseString()->IsUtf8()); @@ -455,10 +461,10 @@ namespace panda::test { instance, handleEcmaStrFrontU8, handleEcmaStrBackU8)); EXPECT_TRUE(handleEcmaStrConcatU8->ToBaseString()->IsUtf8()); for (uint32_t i = 0; i < lengthEcmaStrFrontU8; i++) { - EXPECT_EQ(handleEcmaStrConcatU8->ToBaseString()->At(Barriers::GetTaggedObject, i), arrayFrontU8[i]); + EXPECT_EQ(handleEcmaStrConcatU8->ToBaseString()->At(LoadBarrier(), i), arrayFrontU8[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU8; i++) { - EXPECT_EQ(handleEcmaStrConcatU8->ToBaseString()->At(Barriers::GetTaggedObject, i + lengthEcmaStrFrontU8), + EXPECT_EQ(handleEcmaStrConcatU8->ToBaseString()->At(LoadBarrier(), i + lengthEcmaStrFrontU8), arrayBackU8[i]); } EXPECT_EQ(handleEcmaStrConcatU8->ToBaseString()->GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU8); @@ -493,12 +499,12 @@ namespace panda::test { handleEcmaStrBackU16NotComp)); EXPECT_TRUE(handleEcmaStrConcatU16NotComp->ToBaseString()->IsUtf16()); for (uint32_t i = 0; i < lengthEcmaStrFrontU16NotComp; i++) { - EXPECT_EQ(handleEcmaStrConcatU16NotComp->ToBaseString()->At(Barriers::GetTaggedObject, i), + EXPECT_EQ(handleEcmaStrConcatU16NotComp->ToBaseString()->At(LoadBarrier(), i), arrayFrontU16NotComp[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { EXPECT_EQ( - handleEcmaStrConcatU16NotComp->ToBaseString()->At(Barriers::GetTaggedObject, i + + handleEcmaStrConcatU16NotComp->ToBaseString()->At(LoadBarrier(), i + lengthEcmaStrFrontU16NotComp), arrayBackU16NotComp[i]); } EXPECT_EQ(handleEcmaStrConcatU16NotComp->ToBaseString()->GetLength(), @@ -532,12 +538,12 @@ namespace panda::test { handleEcmaStrBackU16NotComp)); EXPECT_TRUE(handleEcmaStrConcatU8U16NotComp->ToBaseString()->IsUtf16()); for (uint32_t i = 0; i < lengthEcmaStrFrontU8; i++) { - EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->ToBaseString()->At(Barriers::GetTaggedObject, i), + EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->ToBaseString()->At(LoadBarrier(), i), arrayFrontU8[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { EXPECT_EQ( - handleEcmaStrConcatU8U16NotComp->ToBaseString()->At(Barriers::GetTaggedObject, i + lengthEcmaStrFrontU8), + handleEcmaStrConcatU8U16NotComp->ToBaseString()->At(LoadBarrier(), i + lengthEcmaStrFrontU8), arrayBackU16NotComp[i]); } EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->ToBaseString()->GetLength(), @@ -565,8 +571,8 @@ namespace panda::test { EcmaStringAccessor::FastSubString( instance, handleEcmaStrU8, indexStartSubU8, lengthSubU8)); for (uint32_t i = 0; i < lengthSubU8; i++) { - EXPECT_EQ(handleEcmaStrSubU8->ToBaseString()->At(Barriers::GetTaggedObject, i), - handleEcmaStrU8->ToBaseString()->At(Barriers::GetTaggedObject, i + indexStartSubU8)); + EXPECT_EQ(handleEcmaStrSubU8->ToBaseString()->At(LoadBarrier(), i), + handleEcmaStrU8->ToBaseString()->At(LoadBarrier(), i + indexStartSubU8)); } EXPECT_EQ(handleEcmaStrSubU8->ToBaseString()->GetLength(), lengthSubU8); } @@ -593,8 +599,8 @@ namespace panda::test { instance, handleEcmaStrU16Comp, indexStartSubU16Comp, lengthSubU16Comp)); for (uint32_t i = 0; i < lengthSubU16Comp; i++) { - EXPECT_EQ(handleEcmaStrSubU16Comp->ToBaseString()->At(Barriers::GetTaggedObject, i), - handleEcmaStrU16Comp->ToBaseString()->At(Barriers::GetTaggedObject, i + indexStartSubU16Comp)); + EXPECT_EQ(handleEcmaStrSubU16Comp->ToBaseString()->At(LoadBarrier(), i), + handleEcmaStrU16Comp->ToBaseString()->At(LoadBarrier(), i + indexStartSubU16Comp)); } EXPECT_EQ(handleEcmaStrSubU16Comp->ToBaseString()->GetLength(), lengthSubU16Comp); } @@ -622,8 +628,8 @@ namespace panda::test { instance, handleEcmaStrU16NotComp, indexStartSubU16NotComp, lengthSubU16NotComp)); for (uint32_t i = 0; i < lengthSubU16NotComp; i++) { - EXPECT_EQ(handleEcmaStrSubU16NotComp->ToBaseString()->At(Barriers::GetTaggedObject, i), - handleEcmaStrU16NotComp->ToBaseString()->At(Barriers::GetTaggedObject, + EXPECT_EQ(handleEcmaStrSubU16NotComp->ToBaseString()->At(LoadBarrier(), i), + handleEcmaStrU16NotComp->ToBaseString()->At(LoadBarrier(), i + indexStartSubU16NotComp)); } EXPECT_EQ(handleEcmaStrSubU16NotComp->ToBaseString()->GetLength(), lengthSubU16NotComp); @@ -645,7 +651,7 @@ namespace panda::test { EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 2, 7); EXPECT_TRUE(res->ToBaseString()->IsUtf8()); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, res->ToBaseString(), tmpString->ToBaseString())); + BaseString::StringsAreEqual(LoadBarrier(), res->ToBaseString(), tmpString->ToBaseString())); } { JSHandle sourceString = factory->NewFromUtf8("整数integer"); @@ -654,7 +660,7 @@ namespace panda::test { EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 0, 2); EXPECT_TRUE(res->ToBaseString()->IsUtf16()); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, res->ToBaseString(), tmpString->ToBaseString())); + BaseString::StringsAreEqual(LoadBarrier(), res->ToBaseString(), tmpString->ToBaseString())); } { JSHandle sourceString = factory->NewFromUtf8("整数integer"); @@ -663,7 +669,7 @@ namespace panda::test { EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 1, 7); EXPECT_TRUE(res->ToBaseString()->IsUtf16()); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, res->ToBaseString(), tmpString->ToBaseString())); + BaseString::StringsAreEqual(LoadBarrier(), res->ToBaseString(), tmpString->ToBaseString())); } { JSHandle sourceString = factory->NewFromASCII("integer123"); @@ -672,7 +678,7 @@ namespace panda::test { EcmaString* res = EcmaStringAccessor::FastSubString(instance, sourceString, 0, 7); EXPECT_TRUE(res->ToBaseString()->IsUtf8()); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject,res->ToBaseString(), tmpString->ToBaseString())); + BaseString::StringsAreEqual(LoadBarrier(),res->ToBaseString(), tmpString->ToBaseString())); } } @@ -699,15 +705,15 @@ namespace panda::test { instance, sizeEcmaStrU8WriteTo, true)); uint32_t indexStartWriteFromArrayU8 = 2; uint32_t lengthWriteFromArrayU8 = 2; - handleEcmaStrAllocTrueWriteTo->ToBaseString()->WriteData(Barriers::GetTaggedObject, + handleEcmaStrAllocTrueWriteTo->ToBaseString()->WriteData(LoadBarrier(), handleEcmaStrU8WriteFrom->ToBaseString(), indexStartWriteFromArrayU8, sizeEcmaStrU8WriteTo, lengthWriteFromArrayU8); for (uint32_t i = 0; i < lengthWriteFromArrayU8; i++) { EXPECT_EQ( - handleEcmaStrAllocTrueWriteTo->ToBaseString()->At(Barriers::GetTaggedObject, i + + handleEcmaStrAllocTrueWriteTo->ToBaseString()->At(LoadBarrier(), i + indexStartWriteFromArrayU8 - ), handleEcmaStrU8WriteFrom->ToBaseString()->At(Barriers::GetTaggedObject, i)); + ), handleEcmaStrU8WriteFrom->ToBaseString()->At(LoadBarrier(), i)); } } @@ -729,7 +735,7 @@ namespace panda::test { instance, sizeEcmaStrU8WriteTo, true)); uint32_t indexAtWriteFromU8 = 4; handleEcmaStrAllocTrueWriteTo->ToBaseString()->WriteData(indexAtWriteFromU8, u8Write); - EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->ToBaseString()->At(Barriers::GetTaggedObject, indexAtWriteFromU8), + EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->ToBaseString()->At(LoadBarrier(), indexAtWriteFromU8), u8Write); } @@ -757,14 +763,14 @@ namespace panda::test { instance, sizeEcmaStrU16WriteTo, false)); uint32_t indexStartWriteFromArrayU16 = 3; uint32_t numBytesWriteFromArrayU16 = 2 * 3; - handleEcmaStrU16WriteTo->ToBaseString()->WriteData(Barriers::GetTaggedObject, + handleEcmaStrU16WriteTo->ToBaseString()->WriteData(LoadBarrier(), handleEcmaStrU16WriteFrom->ToBaseString(), indexStartWriteFromArrayU16, sizeEcmaStrU16WriteTo, numBytesWriteFromArrayU16); for (uint32_t i = 0; i < (numBytesWriteFromArrayU16 / 2); i++) { EXPECT_EQ( - handleEcmaStrU16WriteTo->ToBaseString()->At(Barriers::GetTaggedObject, i + indexStartWriteFromArrayU16), - handleEcmaStrU16WriteFrom->ToBaseString()->At(Barriers::GetTaggedObject, i)); + handleEcmaStrU16WriteTo->ToBaseString()->At(LoadBarrier(), i + indexStartWriteFromArrayU16), + handleEcmaStrU16WriteFrom->ToBaseString()->At(LoadBarrier(), i)); } } @@ -790,14 +796,14 @@ namespace panda::test { instance, sizeEcmaStrU16WriteTo, false)); uint32_t indexStartWriteFromU8ToU16 = 1; uint32_t numBytesWriteFromU8ToU16 = 4; - handleEcmaStrU16WriteTo->ToBaseString()->WriteData(Barriers::GetTaggedObject, + handleEcmaStrU16WriteTo->ToBaseString()->WriteData(LoadBarrier(), handleEcmaStrU8WriteFrom->ToBaseString(), indexStartWriteFromU8ToU16, sizeEcmaStrU16WriteTo, numBytesWriteFromU8ToU16); for (uint32_t i = 0; i < numBytesWriteFromU8ToU16; i++) { EXPECT_EQ( - handleEcmaStrU16WriteTo->ToBaseString()->At(Barriers::GetTaggedObject, i + indexStartWriteFromU8ToU16), - handleEcmaStrU8WriteFrom->ToBaseString()->At(Barriers::GetTaggedObject, i)); + handleEcmaStrU16WriteTo->ToBaseString()->At(LoadBarrier(), i + indexStartWriteFromU8ToU16), + handleEcmaStrU8WriteFrom->ToBaseString()->At(LoadBarrier(), i)); } } @@ -818,7 +824,7 @@ namespace panda::test { char u8Write = 'a'; uint32_t indexAt = 4; handleEcmaStrU16WriteTo->ToBaseString()->WriteData(indexAt, u8Write); - EXPECT_EQ(handleEcmaStrU16WriteTo->ToBaseString()->At(Barriers::GetTaggedObject, indexAt), u8Write); + EXPECT_EQ(handleEcmaStrU16WriteTo->ToBaseString()->At(LoadBarrier(), indexAt), u8Write); } /* @@ -845,10 +851,10 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false)); - EXPECT_EQ(handleEcmaStrU8->ToBaseString()->GetUtf8Length(Barriers::GetTaggedObject), lengthEcmaStrU8 + 1); - EXPECT_EQ(handleEcmaStrU16Comp->ToBaseString()->GetUtf8Length(Barriers::GetTaggedObject), + EXPECT_EQ(handleEcmaStrU8->ToBaseString()->GetUtf8Length(LoadBarrier()), lengthEcmaStrU8 + 1); + EXPECT_EQ(handleEcmaStrU16Comp->ToBaseString()->GetUtf8Length(LoadBarrier()), lengthEcmaStrU16Comp + 1); - EXPECT_EQ(handleEcmaStrU16NotComp->ToBaseString()->GetUtf8Length(Barriers::GetTaggedObject), + EXPECT_EQ(handleEcmaStrU16NotComp->ToBaseString()->GetUtf8Length(LoadBarrier()), 2 * lengthEcmaStrU16NotComp + 1); } @@ -926,13 +932,13 @@ namespace panda::test { size_t indexStartFromArrayU8 = 2; size_t lengthCopyToEcmaStrU8 = 3; size_t lengthReturnU8 = handleEcmaStrU8CopyFrom->ToBaseString()->CopyDataRegionUtf8( - Barriers::GetTaggedObject, arrayU8CopyTo, indexStartFromArrayU8, + LoadBarrier(), arrayU8CopyTo, indexStartFromArrayU8, lengthCopyToEcmaStrU8, lengthArrayU8Target); EXPECT_EQ(lengthReturnU8, lengthCopyToEcmaStrU8); for (uint32_t i = 0; i < lengthCopyToEcmaStrU8; i++) { EXPECT_EQ(arrayU8CopyTo[i], - handleEcmaStrU8CopyFrom->ToBaseString()->At(Barriers::GetTaggedObject, i + indexStartFromArrayU8)); + handleEcmaStrU8CopyFrom->ToBaseString()->At(LoadBarrier(), i + indexStartFromArrayU8)); } for (uint32_t i = lengthCopyToEcmaStrU8; i < lengthArrayU8Target; i++) { EXPECT_EQ(arrayU8CopyTo[i], defaultByteForU8CopyTo); @@ -955,13 +961,13 @@ namespace panda::test { size_t indexStartFromArrayU16Comp = 2; size_t lengthCopyToEcmaStrU16Comp = 3; size_t lengthReturnU16Comp = handleEcmaStrU16CompCopyFrom->ToBaseString()->CopyDataRegionUtf8( - Barriers::GetTaggedObject, &arrayU16CompCopyTo[0], + LoadBarrier(), &arrayU16CompCopyTo[0], indexStartFromArrayU16Comp, lengthCopyToEcmaStrU16Comp, lengthArrayU16Target); EXPECT_EQ(lengthReturnU16Comp, lengthCopyToEcmaStrU16Comp); for (uint32_t i = 0; i < lengthReturnU16Comp; i++) { EXPECT_EQ(arrayU16CompCopyTo[i], - handleEcmaStrU16CompCopyFrom->ToBaseString()->At(Barriers::GetTaggedObject, i + + handleEcmaStrU16CompCopyFrom->ToBaseString()->At(LoadBarrier(), i + indexStartFromArrayU16Comp)); } for (uint32_t i = lengthReturnU16Comp; i < lengthArrayU16Target; i++) { @@ -994,13 +1000,13 @@ namespace panda::test { EXPECT_TRUE(checkResUtf16 == 0); size_t lengthReturnU16NotComp = handleEcmaStrU16NotCompCopyFrom->ToBaseString()->CopyDataUtf16( - Barriers::GetTaggedObject, &arrayU16NotCompCopyTo[0], + LoadBarrier(), &arrayU16NotCompCopyTo[0], lengthArrayU16Target); EXPECT_EQ(lengthReturnU16NotComp, lengthEcmaStrU16NotCompCopyFrom); for (uint32_t i = 0; i < lengthReturnU16NotComp; i++) { EXPECT_EQ(arrayU16NotCompCopyTo[i], - handleEcmaStrU16NotCompCopyFrom->ToBaseString()->At(Barriers::GetTaggedObject, i)); + handleEcmaStrU16NotCompCopyFrom->ToBaseString()->At(LoadBarrier(), i)); } for (uint32_t i = lengthReturnU16NotComp; i < lengthArrayU16Target; i++) { EXPECT_EQ(arrayU16NotCompCopyTo[i], @@ -1034,13 +1040,13 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf8( instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), handleEcmaStrU8No2->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), handleEcmaStrU8No3->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU8No3->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU8No3->ToBaseString(), handleEcmaStrU8No1->ToBaseString())); } @@ -1070,10 +1076,10 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true)); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), handleEcmaStrU16CompNo2->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), handleEcmaStrU16CompNo3->ToBaseString())); } @@ -1103,13 +1109,13 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true)); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16CompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16CompNo1->ToBaseString(), handleEcmaStrU16CompNo2->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16CompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16CompNo1->ToBaseString(), handleEcmaStrU16CompNo3->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16CompNo3->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16CompNo3->ToBaseString(), handleEcmaStrU16CompNo1->ToBaseString())); } @@ -1135,10 +1141,10 @@ namespace panda::test { instance, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true)); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), handleEcmaStrU16NotCompNo1->ToBaseString())); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16NotCompNo1->ToBaseString(), handleEcmaStrU8No1->ToBaseString())); } @@ -1164,10 +1170,10 @@ namespace panda::test { instance, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true)); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16CompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16CompNo1->ToBaseString(), handleEcmaStrU16NotCompNo1->ToBaseString())); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16NotCompNo1->ToBaseString(), handleEcmaStrU16CompNo1->ToBaseString())); } @@ -1200,13 +1206,13 @@ namespace panda::test { instance, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false)); EXPECT_TRUE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16NotCompNo1->ToBaseString(), handleEcmaStrU16NotCompNo2->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo1->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16NotCompNo1->ToBaseString(), handleEcmaStrU16NotCompNo3->ToBaseString())); EXPECT_FALSE( - BaseString::StringsAreEqual(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo3->ToBaseString(), + BaseString::StringsAreEqual(LoadBarrier(), handleEcmaStrU16NotCompNo3->ToBaseString(), handleEcmaStrU16NotCompNo1->ToBaseString())); } @@ -1236,16 +1242,16 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf8( instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); EXPECT_TRUE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), & + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), & arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), &arrayU8No1 + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), &arrayU8No1 [0], lengthEcmaStrU8No1, false)); EXPECT_FALSE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU8No2->ToBaseString(), &arrayU8No1 + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU8No2->ToBaseString(), &arrayU8No1 [0], lengthEcmaStrU8No1, true)); EXPECT_FALSE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU8No3->ToBaseString(), &arrayU8No1 + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU8No3->ToBaseString(), &arrayU8No1 [0], lengthEcmaStrU8No1, true)); } @@ -1277,16 +1283,16 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true)); EXPECT_TRUE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU16CompNo1->ToBaseString(), + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU16CompNo1->ToBaseString(), &arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU16CompNo1->ToBaseString(), + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU16CompNo1->ToBaseString(), &arrayU8No1[0], lengthEcmaStrU8No1, false)); EXPECT_FALSE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU16CompNo2->ToBaseString(), + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU16CompNo2->ToBaseString(), &arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE( - BaseString::StringIsEqualUint8Data(Barriers::GetTaggedObject, handleEcmaStrU16CompNo3->ToBaseString(), + BaseString::StringIsEqualUint8Data(LoadBarrier(), handleEcmaStrU16CompNo3->ToBaseString(), &arrayU8No1[0], lengthEcmaStrU8No1, true)); } @@ -1331,13 +1337,13 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf8( instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); EXPECT_TRUE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU8No1->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU8No1->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU8No2->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU8No2->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU8No3->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU8No3->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); } @@ -1372,16 +1378,16 @@ namespace panda::test { EcmaStringAccessor::CreateFromUtf16( instance, &arrayU16CompNo4[0], lengthEcmaStrU16CompNo4, true)); EXPECT_TRUE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16CompNo1->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16CompNo1->ToBaseString(), & arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16CompNo2->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16CompNo2->ToBaseString(), & arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16CompNo3->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16CompNo3->ToBaseString(), & arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); EXPECT_TRUE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16CompNo4->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16CompNo4->ToBaseString(), & arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); } @@ -1419,23 +1425,23 @@ namespace panda::test { instance, &arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, false)); EXPECT_TRUE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo1->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16NotCompNo1->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo1->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16NotCompNo1->ToBaseString(), & arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo2->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16NotCompNo2->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo3->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16NotCompNo3->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE( - BaseString::StringsAreEqualUtf16(Barriers::GetTaggedObject, handleEcmaStrU16NotCompNo4->ToBaseString(), & + BaseString::StringsAreEqualUtf16(LoadBarrier(), handleEcmaStrU16NotCompNo4->ToBaseString(), & arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); } @@ -1495,7 +1501,7 @@ namespace panda::test { for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { hashExpect = hashExpect * 31 + arrayU8[i]; } - EXPECT_EQ(handleEcmaStrU8->ToBaseString()->GetHashcode(Barriers::GetTaggedObject), hashExpect); + EXPECT_EQ(handleEcmaStrU8->ToBaseString()->GetHashcode(LoadBarrier()), hashExpect); } /* @@ -1517,7 +1523,7 @@ namespace panda::test { for (uint32_t i = 0; i < lengthEcmaStrU16Comp; i++) { hashExpect = hashExpect * 31 + arrayU16Comp[i]; } - EXPECT_EQ(handleEcmaStrU16Comp->ToBaseString()->GetHashcode(Barriers::GetTaggedObject), hashExpect); + EXPECT_EQ(handleEcmaStrU16Comp->ToBaseString()->GetHashcode(LoadBarrier()), hashExpect); } /* @@ -1540,7 +1546,7 @@ namespace panda::test { for (uint32_t i = 0; i < lengthEcmaStrU16NotComp; i++) { hashExpect = hashExpect * 31 + arrayU16NotComp[i]; } - EXPECT_EQ(handleEcmaStrU16NotComp->ToBaseString()->GetHashcode(Barriers::GetTaggedObject), hashExpect); + EXPECT_EQ(handleEcmaStrU16NotComp->ToBaseString()->GetHashcode(LoadBarrier()), hashExpect); } /* @@ -1554,7 +1560,7 @@ namespace panda::test { { // GetHashcode(). EcmaString made by CreateEmptyString(). JSHandle handleEcmaStrEmpty(thread, EcmaStringAccessor::CreateEmptyString(instance)); - EXPECT_EQ(handleEcmaStrEmpty->ToBaseString()->GetHashcode(Barriers::GetTaggedObject), 0U); + EXPECT_EQ(handleEcmaStrEmpty->ToBaseString()->GetHashcode(LoadBarrier()), 0U); } /* @@ -1631,7 +1637,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf8()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf16()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(result); } @@ -1643,7 +1649,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf8()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf8()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(!result); } @@ -1655,7 +1661,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf16()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf16()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(result); } @@ -1667,7 +1673,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf8()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf8()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(result); } @@ -1679,7 +1685,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf8()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf16()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(!result); } @@ -1691,7 +1697,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf8()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf8()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(!result); } @@ -1703,7 +1709,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf16()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf16()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(!result); } @@ -1715,7 +1721,7 @@ namespace panda::test { EXPECT_TRUE(firstString->ToBaseString()->IsUtf8()); EXPECT_TRUE(secondString->ToBaseString()->IsUtf16()); bool result = sourceString->ToBaseString()->EqualToSplicedString( - Barriers::GetTaggedObject, firstString->ToBaseString(), secondString->ToBaseString()); + LoadBarrier(), firstString->ToBaseString(), secondString->ToBaseString()); EXPECT_TRUE(!result); } } @@ -1724,13 +1730,13 @@ namespace panda::test { { ObjectFactory* factory = thread->GetEcmaVM()->GetFactory(); JSHandle testString = factory->NewFromASCII("bar2bazJavaScriptbaz"); - CString str = ConvertToString(*testString, StringConvertedUsage::LOGICOPERATION, false); + CString str = ConvertToString(thread, *testString, StringConvertedUsage::LOGICOPERATION, false); EXPECT_EQ(str, CString("bar2bazJavaScriptbaz")); } HWTEST_F_L0(BaseStringTest, ConvertToString002) { - CString str = ConvertToString(nullptr, StringConvertedUsage::LOGICOPERATION, false); + CString str = ConvertToString(thread, nullptr, StringConvertedUsage::LOGICOPERATION, false); EXPECT_EQ(str, CString("")); } @@ -1738,7 +1744,7 @@ namespace panda::test { { ObjectFactory* factory = thread->GetEcmaVM()->GetFactory(); JSHandle testString = factory->NewFromASCII("test"); - CString str = ConvertToString(*testString); + CString str = ConvertToString(thread, *testString); EXPECT_EQ(str, CString("test")); } } // namespace panda::test diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index 9a9d980370..aaf44e1d2a 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -156,17 +156,17 @@ HWTEST_F_L0(EcmaDumpTest, Dump) std::ostringstream os; JSTaggedValue value1(100); - value1.Dump(os); + value1.Dump(thread, os); JSTaggedValue value2(100.0); - JSTaggedValue(value2.GetRawData()).Dump(os); + JSTaggedValue(value2.GetRawData()).Dump(thread, os); - JSTaggedValue::Undefined().Dump(os); + JSTaggedValue::Undefined().Dump(thread, os); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - env.GetTaggedValue().Dump(os); + env.GetTaggedValue().Dump(thread, os); JSHandle objFunc(env->GetObjectFunction()); - objFunc.GetTaggedValue().Dump(os); + objFunc.GetTaggedValue().Dump(thread, os); } #endif // #ifndef NDEBUG @@ -362,7 +362,7 @@ static JSHandle NewJSAPIArrayList(JSThread *thread, ObjectFactor JSHandle arrayListClass = factory->NewEcmaHClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto); JSHandle jsArrayList = JSHandle::Cast(factory->NewJSObjectWithInit(arrayListClass)); - jsArrayList->SetLength(thread, JSTaggedValue(0)); + jsArrayList->SetLength(0); return jsArrayList; } @@ -469,9 +469,9 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) #define DUMP_FOR_HANDLE(dumpHandle) \ do { \ - JSTaggedValue dumpValue = (dumpHandle).GetTaggedValue(); \ - dumpValue.Dump(os); \ - dumpValue.DumpForSnapshot(snapshotVector); \ + JSTaggedValue dumpValue = (dumpHandle).GetTaggedValue(); \ + dumpValue.Dump(thread, os); \ + dumpValue.DumpForSnapshot(thread, snapshotVector); \ /* Testing runtime stubs: */ \ JSTaggedType dumpRawData = dumpValue.GetRawData(); \ uintptr_t hintStr = reinterpret_cast("Testing with: " #dumpHandle); \ @@ -983,7 +983,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::FUNCTION_TEMPLATE: { - auto method = JSFunction::Cast(globalEnv->GetTaggedObjectFunction())->GetMethod(); + auto method = JSFunction::Cast(globalEnv->GetTaggedObjectFunction())->GetMethod(thread); JSHandle methodHandle(thread, method); JSHandle handleUndefined(thread, JSTaggedValue::Undefined()); JSHandle funcTemp = factory->NewFunctionTemplate(methodHandle, handleUndefined, 0); diff --git a/ecmascript/tests/ecma_string_accessor_test.cpp b/ecmascript/tests/ecma_string_accessor_test.cpp index 555f01e310..321d253f9a 100644 --- a/ecmascript/tests/ecma_string_accessor_test.cpp +++ b/ecmascript/tests/ecma_string_accessor_test.cpp @@ -108,7 +108,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, CreateFromUtf8) JSHandle handleEcmaStrU8(thread, EcmaStringAccessor::CreateFromUtf8(instance, &arrayU8[0], lengthEcmaStrU8, true)); for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { - EXPECT_EQ(arrayU8[i], EcmaStringAccessor(handleEcmaStrU8).Get(i)); + EXPECT_EQ(arrayU8[i], EcmaStringAccessor(handleEcmaStrU8).Get(thread, i)); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU8).GetLength(), lengthEcmaStrU8); EXPECT_TRUE(EcmaStringAccessor(handleEcmaStrU8).IsUtf8()); @@ -164,10 +164,10 @@ HWTEST_F_L0(EcmaStringAccessorTest, Concat_001) EcmaStringAccessor::Concat(instance, handleEcmaStrFrontU8, handleEcmaStrBackU8)); EXPECT_TRUE(EcmaStringAccessor(handleEcmaStrConcatU8).IsUtf8()); for (uint32_t i = 0; i < lengthEcmaStrFrontU8; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8).Get(i), arrayFrontU8[i]); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8).Get(thread, i), arrayFrontU8[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU8; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8).Get(i + lengthEcmaStrFrontU8), arrayBackU8[i]); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8).Get(thread, i + lengthEcmaStrFrontU8), arrayBackU8[i]); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8).GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU8); } @@ -194,10 +194,10 @@ HWTEST_F_L0(EcmaStringAccessorTest, Concat_002) EcmaStringAccessor::Concat(instance, handleEcmaStrFrontU16NotComp, handleEcmaStrBackU16NotComp)); EXPECT_TRUE(EcmaStringAccessor(handleEcmaStrConcatU16NotComp).IsUtf16()); for (uint32_t i = 0; i < lengthEcmaStrFrontU16NotComp; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU16NotComp).Get(i), arrayFrontU16NotComp[i]); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU16NotComp).Get(thread, i), arrayFrontU16NotComp[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU16NotComp).Get(i + lengthEcmaStrFrontU16NotComp), + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU16NotComp).Get(thread, i + lengthEcmaStrFrontU16NotComp), arrayBackU16NotComp[i]); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU16NotComp).GetLength(), @@ -252,8 +252,8 @@ HWTEST_F_L0(EcmaStringAccessorTest, FastSubString_002) JSHandle handleEcmaStrSubU16Comp(thread, EcmaStringAccessor::FastSubString(instance, handleEcmaStrU16Comp, indexStartSubU16Comp, lengthSubU16Comp)); for (uint32_t i = 0; i < lengthSubU16Comp; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU16Comp).Get(i), - EcmaStringAccessor(handleEcmaStrU16Comp).Get(i + indexStartSubU16Comp)); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU16Comp).Get(thread, i), + EcmaStringAccessor(handleEcmaStrU16Comp).Get(thread, i + indexStartSubU16Comp)); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU16Comp).GetLength(), lengthSubU16Comp); } @@ -277,8 +277,8 @@ HWTEST_F_L0(EcmaStringAccessorTest, FastSubString_003) JSHandle handleEcmaStrSubU16NotComp(thread, EcmaStringAccessor::FastSubString( instance, handleEcmaStrU16NotComp, indexStartSubU16NotComp, lengthSubU16NotComp)); for (uint32_t i = 0; i < lengthSubU16NotComp; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU16NotComp).Get(i), - EcmaStringAccessor(handleEcmaStrU16NotComp).Get(i + indexStartSubU16NotComp)); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU16NotComp).Get(thread, i), + EcmaStringAccessor(handleEcmaStrU16NotComp).Get(thread, i + indexStartSubU16NotComp)); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU16NotComp).GetLength(), lengthSubU16NotComp); } @@ -298,7 +298,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, FastSubString_004) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EcmaString *res = EcmaStringAccessor::FastSubString(instance, sourceString, 2, 7); EXPECT_TRUE(EcmaStringAccessor(res).IsUtf8()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(res, *tmpString)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, res, *tmpString)); } { JSHandle sourceString = factory->NewFromUtf8("整数integer"); @@ -306,7 +306,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, FastSubString_004) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EcmaString *res = EcmaStringAccessor::FastSubString(instance, sourceString, 0, 2); EXPECT_TRUE(EcmaStringAccessor(res).IsUtf16()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(res, *tmpString)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, res, *tmpString)); } { JSHandle sourceString = factory->NewFromUtf8("整数integer"); @@ -314,7 +314,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, FastSubString_004) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EcmaString *res = EcmaStringAccessor::FastSubString(instance, sourceString, 1, 7); EXPECT_TRUE(EcmaStringAccessor(res).IsUtf16()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(res, *tmpString)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, res, *tmpString)); } { JSHandle sourceString = factory->NewFromASCII("integer123"); @@ -322,7 +322,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, FastSubString_004) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf8()); EcmaString *res = EcmaStringAccessor::FastSubString(instance, sourceString, 0, 7); EXPECT_TRUE(EcmaStringAccessor(res).IsUtf8()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(res, *tmpString)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, res, *tmpString)); } } @@ -346,9 +346,9 @@ HWTEST_F_L0(EcmaStringAccessorTest, GetUtf8Length) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16Comp[0], lengthEcmaStrU16Comp, true)); JSHandle handleEcmaStrU16NotComp(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false)); - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU8).GetUtf8Length(), lengthEcmaStrU8 + 1); - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16Comp).GetUtf8Length(), lengthEcmaStrU16Comp + 1); - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16NotComp).GetUtf8Length(), 2 * lengthEcmaStrU16NotComp + 1); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU8).GetUtf8Length(thread), lengthEcmaStrU8 + 1); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16Comp).GetUtf8Length(thread), lengthEcmaStrU16Comp + 1); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16NotComp).GetUtf8Length(thread), 2 * lengthEcmaStrU16NotComp + 1); } /* @@ -494,7 +494,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, WriteToFlatUtf8) uint8_t arrayU8CopyTo[lengthArrayU8Target]; size_t lengthReturnU8 = EcmaStringAccessor(handleEcmaStrU8CopyFrom) - .WriteToFlatUtf8(&arrayU8CopyTo[0], lengthArrayU8Target); + .WriteToFlatUtf8(thread, &arrayU8CopyTo[0], lengthArrayU8Target); EXPECT_EQ(lengthReturnU8, lengthArrayU8Target); for (uint32_t i = 0; i < lengthReturnU8 - 1; i++) { @@ -511,7 +511,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, WriteToFlatUtf8) uint8_t arrayU8CompCopyTo[lengthArrayU16Target]; size_t lengthReturnU16Comp = EcmaStringAccessor(handleEcmaStrU16CompCopyFrom) - .WriteToFlatUtf8(&arrayU8CompCopyTo[0], lengthArrayU16Target); + .WriteToFlatUtf8(thread, &arrayU8CompCopyTo[0], lengthArrayU16Target); EXPECT_EQ(lengthReturnU16Comp, lengthArrayU16Target); for (uint32_t i = 0; i < lengthReturnU16Comp - 1; i++) { @@ -523,7 +523,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, WriteToFlatUtf8) std::string str( "您订单尾号为:1442的车辆提车点已由重庆市渝北区龙兴镇新能源办公大楼变更为重庆市江北区鱼嘴镇永和路39号2屋208室,请携带好相关材料按照预约时间前往提车点提车2,如有296ss"); JSHandle ecmaStr = thread->GetEcmaVM()->GetFactory()->NewFromStdString(str); - uint32_t len = EcmaStringAccessor(ecmaStr).WriteToFlatUtf8(buffer, 198, true); + uint32_t len = EcmaStringAccessor(ecmaStr).WriteToFlatUtf8(thread, buffer, 198, true); EXPECT_EQ(len, 197); } @@ -549,11 +549,11 @@ HWTEST_F_L0(EcmaStringAccessorTest, WriteToFlatUtf16) EXPECT_TRUE(checkResUtf16 == 0); size_t lengthReturnU16NotComp = EcmaStringAccessor(handleEcmaStrU16NotCompCopyFrom) - .WriteToFlatUtf16(&arrayU16NotCompCopyTo[0], lengthArrayU16Target); + .WriteToFlatUtf16(thread, &arrayU16NotCompCopyTo[0], lengthArrayU16Target); EXPECT_EQ(lengthReturnU16NotComp, lengthEcmaStrU16NotCompCopyFrom); for (uint32_t i = 0; i < lengthReturnU16NotComp; i++) { - EXPECT_EQ(arrayU16NotCompCopyTo[i], EcmaStringAccessor(handleEcmaStrU16NotCompCopyFrom).Get(i)); + EXPECT_EQ(arrayU16NotCompCopyTo[i], EcmaStringAccessor(handleEcmaStrU16NotCompCopyFrom).Get(thread, i)); } for (uint32_t i = lengthReturnU16NotComp; i < lengthArrayU16Target; i++) { EXPECT_EQ(arrayU16NotCompCopyTo[i], ((uint16_t)defaultOneByteValueOfArrayU16NotCompCopyTo) * (1 + (1 << 8))); @@ -579,11 +579,11 @@ HWTEST_F_L0(EcmaStringAccessorTest, ReadData_001) EcmaStringAccessor::CreateLineString(instance, sizeEcmaStrU8WriteTo, true)); uint32_t indexStartWriteFromArrayU8 = 2; uint32_t lengthWriteFromArrayU8 = 2; - EcmaStringAccessor::ReadData(*handleEcmaStrAllocTrueWriteTo, *handleEcmaStrU8WriteFrom, indexStartWriteFromArrayU8, + EcmaStringAccessor::ReadData(thread, *handleEcmaStrAllocTrueWriteTo, *handleEcmaStrU8WriteFrom, indexStartWriteFromArrayU8, sizeEcmaStrU8WriteTo, lengthWriteFromArrayU8); for (uint32_t i = 0; i < lengthWriteFromArrayU8; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrAllocTrueWriteTo).Get(i + indexStartWriteFromArrayU8), - EcmaStringAccessor(handleEcmaStrU8WriteFrom).Get(i)); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrAllocTrueWriteTo).Get(thread, i + indexStartWriteFromArrayU8), + EcmaStringAccessor(handleEcmaStrU8WriteFrom).Get(thread, i)); } } @@ -608,11 +608,11 @@ HWTEST_F_L0(EcmaStringAccessorTest, ReadData_002) EcmaStringAccessor::CreateLineString(instance, sizeEcmaStrU16WriteTo, false)); uint32_t indexStartWriteFromArrayU16 = 3; uint32_t numBytesWriteFromArrayU16 = 2 * 3; - EcmaStringAccessor::ReadData(*handleEcmaStrU16WriteTo, *handleEcmaStrU16WriteFrom, indexStartWriteFromArrayU16, + EcmaStringAccessor::ReadData(thread, *handleEcmaStrU16WriteTo, *handleEcmaStrU16WriteFrom, indexStartWriteFromArrayU16, sizeEcmaStrU16WriteTo, numBytesWriteFromArrayU16); for (uint32_t i = 0; i < (numBytesWriteFromArrayU16 / 2); i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16WriteTo).Get(i + indexStartWriteFromArrayU16), - EcmaStringAccessor(handleEcmaStrU16WriteFrom).Get(i)); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16WriteTo).Get(thread, i + indexStartWriteFromArrayU16), + EcmaStringAccessor(handleEcmaStrU16WriteFrom).Get(thread, i)); } } @@ -635,12 +635,12 @@ HWTEST_F_L0(EcmaStringAccessorTest, ReadData_003) EcmaStringAccessor::CreateLineString(instance, sizeEcmaStrU16WriteTo, false)); uint32_t indexStartWriteFromU8ToU16 = 1; uint32_t numBytesWriteFromU8ToU16 = 4; - EcmaStringAccessor::ReadData(*handleEcmaStrU16WriteTo, *handleEcmaStrU8WriteFrom, + EcmaStringAccessor::ReadData(thread, *handleEcmaStrU16WriteTo, *handleEcmaStrU8WriteFrom, indexStartWriteFromU8ToU16, sizeEcmaStrU16WriteTo, numBytesWriteFromU8ToU16); for (uint32_t i = 0; i < numBytesWriteFromU8ToU16; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16WriteTo).Get(i + indexStartWriteFromU8ToU16), - EcmaStringAccessor(handleEcmaStrU8WriteFrom).Get(i)); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16WriteTo).Get(thread, i + indexStartWriteFromU8ToU16), + EcmaStringAccessor(handleEcmaStrU8WriteFrom).Get(thread, i)); } } @@ -660,7 +660,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, Set_001) EcmaStringAccessor::CreateLineString(instance, sizeEcmaStrU8WriteTo, true)); uint32_t indexAtWriteFromU8 = 4; EcmaStringAccessor(handleEcmaStrAllocTrueWriteTo).Set(indexAtWriteFromU8, u8Write); - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrAllocTrueWriteTo).Get(indexAtWriteFromU8), u8Write); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrAllocTrueWriteTo).Get(thread, indexAtWriteFromU8), u8Write); } /* @@ -679,7 +679,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, Set_002) char u8Write = 'a'; uint32_t indexAt = 4; EcmaStringAccessor(handleEcmaStrU16WriteTo).Set(indexAt, u8Write); - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16WriteTo).Get(indexAt), u8Write); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16WriteTo).Get(thread, indexAt), u8Write); } /* @@ -700,7 +700,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, GetHashcode_001) for (uint32_t i = 0; i < lengthEcmaStrU8; i++) { hashExpect = hashExpect * 31 + arrayU8[i]; } - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU8).GetHashcode(), hashExpect); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU8).GetHashcode(thread), hashExpect); } /* @@ -721,7 +721,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, GetHashcode_002) for (uint32_t i = 0; i < lengthEcmaStrU16Comp; i++) { hashExpect = hashExpect * 31 + arrayU16Comp[i]; } - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16Comp).GetHashcode(), hashExpect); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16Comp).GetHashcode(thread), hashExpect); } /* @@ -742,7 +742,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, GetHashcode_003) for (uint32_t i = 0; i < lengthEcmaStrU16NotComp; i++) { hashExpect = hashExpect * 31 + arrayU16NotComp[i]; } - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16NotComp).GetHashcode(), hashExpect); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrU16NotComp).GetHashcode(thread), hashExpect); } /* @@ -756,7 +756,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, GetHashcode_004) { // GetHashcode(). EcmaString made by CreateEmptyString(). JSHandle handleEcmaStrEmpty(thread, EcmaStringAccessor::CreateEmptyString(instance)); - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrEmpty).GetHashcode(), 0U); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrEmpty).GetHashcode(thread), 0U); } /* @@ -1121,9 +1121,9 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqual_001) EcmaStringAccessor::CreateFromUtf8(instance, &arrayU8No2[0], lengthEcmaStrU8No2, true)); JSHandle handleEcmaStrU8No3(thread, EcmaStringAccessor::CreateFromUtf8(instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU8No2)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU8No3)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU8No3, *handleEcmaStrU8No1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU8No1, *handleEcmaStrU8No2)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU8No1, *handleEcmaStrU8No3)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU8No3, *handleEcmaStrU8No1)); } /* @@ -1148,8 +1148,8 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqual_002) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true)); JSHandle handleEcmaStrU16CompNo3(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo2)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo3)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU8No1, *handleEcmaStrU16CompNo2)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU8No1, *handleEcmaStrU16CompNo3)); } /* @@ -1174,9 +1174,9 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqual_003) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true)); JSHandle handleEcmaStrU16CompNo3(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo2)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo3)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16CompNo3, *handleEcmaStrU16CompNo1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo2)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo3)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16CompNo3, *handleEcmaStrU16CompNo1)); } /* @@ -1197,8 +1197,8 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqual_004) EcmaStringAccessor::CreateFromUtf8(instance, &arrayU8No1[0], lengthEcmaStrU8No1, true)); JSHandle handleEcmaStrU16NotCompNo1(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16NotCompNo1)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU8No1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU8No1, *handleEcmaStrU16NotCompNo1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16NotCompNo1, *handleEcmaStrU8No1)); } /* @@ -1219,8 +1219,8 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqual_005) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true)); JSHandle handleEcmaStrU16NotCompNo1(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16NotCompNo1)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16CompNo1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16CompNo1, *handleEcmaStrU16NotCompNo1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16NotCompNo1, *handleEcmaStrU16CompNo1)); } /* @@ -1245,9 +1245,9 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqual_006) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, false)); JSHandle handleEcmaStrU16NotCompNo3(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo2)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo3)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(*handleEcmaStrU16NotCompNo3, *handleEcmaStrU16NotCompNo1)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo2)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo3)); + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqual(thread, *handleEcmaStrU16NotCompNo3, *handleEcmaStrU16NotCompNo1)); } /* @@ -1273,13 +1273,13 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqualUtf8_001) JSHandle handleEcmaStrU8No3(thread, EcmaStringAccessor::CreateFromUtf8(instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); EXPECT_TRUE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + thread, *handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + thread, *handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); EXPECT_FALSE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU8No2, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + thread, *handleEcmaStrU8No2, &arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU8No3, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + thread, *handleEcmaStrU8No3, &arrayU8No1[0], lengthEcmaStrU8No1, true)); } /* @@ -1310,13 +1310,13 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqualUtf8_002) JSHandle handleEcmaStrU16CompNo3(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true)); EXPECT_TRUE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU16CompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + thread, *handleEcmaStrU16CompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU16CompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + thread, *handleEcmaStrU16CompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); EXPECT_FALSE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU16CompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + thread, *handleEcmaStrU16CompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, true)); EXPECT_FALSE(EcmaStringAccessor::StringIsEqualUint8Data( - *handleEcmaStrU16CompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + thread, *handleEcmaStrU16CompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, true)); } /* @@ -1357,11 +1357,11 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqualUtf16_001) JSHandle handleEcmaStrU8No3(thread, EcmaStringAccessor::CreateFromUtf8(instance, &arrayU8No3[0], lengthEcmaStrU8No3, true)); EXPECT_TRUE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU8No1, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); + thread, *handleEcmaStrU8No1, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU8No2, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); + thread, *handleEcmaStrU8No2, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU8No3, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); + thread, *handleEcmaStrU8No3, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); } /* @@ -1395,13 +1395,13 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqualUtf16_002) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16CompNo4[0], lengthEcmaStrU16CompNo4, true)); EXPECT_TRUE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU16CompNo1, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + thread, *handleEcmaStrU16CompNo1, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU16CompNo2, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + thread, *handleEcmaStrU16CompNo2, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU16CompNo3, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + thread, *handleEcmaStrU16CompNo3, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); EXPECT_TRUE(EcmaStringAccessor::StringsAreEqualUtf16( - *handleEcmaStrU16CompNo4, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); + thread, *handleEcmaStrU16CompNo4, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1)); } /* @@ -1430,15 +1430,15 @@ HWTEST_F_L0(EcmaStringAccessorTest, StringsAreEqualUtf16_003) EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false)); JSHandle handleEcmaStrU16NotCompNo4(thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, false)); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo1[0], + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqualUtf16(thread, *handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo2[0], + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(thread, *handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo2, &arrayU16NotCompNo1[0], + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(thread, *handleEcmaStrU16NotCompNo2, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo3, &arrayU16NotCompNo1[0], + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(thread, *handleEcmaStrU16NotCompNo3, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); - EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo4, &arrayU16NotCompNo1[0], + EXPECT_FALSE(EcmaStringAccessor::StringsAreEqualUtf16(thread, *handleEcmaStrU16NotCompNo4, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1)); } @@ -1459,7 +1459,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf16()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(result); } @@ -1470,7 +1470,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf8()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(!result); } @@ -1481,7 +1481,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf16()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(result); } @@ -1492,7 +1492,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf8()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(result); } @@ -1503,7 +1503,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf16()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(!result); } @@ -1514,7 +1514,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf8()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(!result); } @@ -1525,7 +1525,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf16()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(!result); } @@ -1536,7 +1536,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_001) EXPECT_TRUE(EcmaStringAccessor(sourceString).IsUtf16()); EXPECT_TRUE(EcmaStringAccessor(firstString).IsUtf8()); EXPECT_TRUE(EcmaStringAccessor(secondString).IsUtf16()); - bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(*firstString, *secondString); + bool result = EcmaStringAccessor(sourceString).EqualToSplicedString(thread, *firstString, *secondString); EXPECT_TRUE(!result); } } @@ -1556,7 +1556,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_002) JSHandle firstString = factory->NewFromUtf8("123"); JSHandle secondString = factory->NewFromUtf8("A"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1565,7 +1565,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_002) JSHandle firstString = factory->NewFromUtf8("A"); JSHandle secondString = factory->NewFromUtf8("123"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1574,7 +1574,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_002) JSHandle firstString = factory->NewFromUtf8("123456789"); JSHandle secondString = factory->NewFromUtf8("A"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1583,7 +1583,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_002) JSHandle firstString = factory->NewFromUtf8("123456789011"); JSHandle secondString = factory->NewFromUtf8("A"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } } @@ -1603,7 +1603,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("123456789"); JSHandle secondString = factory->NewFromUtf8("01"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1612,7 +1612,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("1234567890"); JSHandle secondString = factory->NewFromUtf8("1"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1621,7 +1621,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("123456789"); JSHandle secondString = factory->NewFromUtf8("01"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1630,7 +1630,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("12345678"); JSHandle secondString = factory->NewFromUtf8("901"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1639,7 +1639,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("1234567"); JSHandle secondString = factory->NewFromUtf8("8901"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1648,7 +1648,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("12345"); JSHandle secondString = factory->NewFromUtf8("6789"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1657,7 +1657,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_003) JSHandle firstString = factory->NewFromUtf8("1234"); JSHandle secondString = factory->NewFromUtf8("56789"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } } @@ -1678,7 +1678,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_004) JSHandle firstString = factory->NewFromUtf8("你好"); JSHandle secondString = factory->NewFromUtf8("在干嘛"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1687,7 +1687,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_004) JSHandle firstString = factory->NewFromUtf8("你吃"); JSHandle secondString = factory->NewFromUtf8("饭了么"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1696,7 +1696,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_004) JSHandle firstString = factory->NewFromUtf8("你你你你你你你你你"); JSHandle secondString = factory->NewFromUtf8("我我我我我我我我我"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } } @@ -1716,7 +1716,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_005) JSHandle firstString = factory->NewFromUtf8("你"); JSHandle secondString = factory->NewFromUtf8("好233"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1725,7 +1725,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_005) JSHandle firstString = factory->NewFromUtf8("你好"); JSHandle secondString = factory->NewFromUtf8("abc"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1734,7 +1734,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_005) JSHandle firstString = factory->NewFromUtf8("233"); JSHandle secondString = factory->NewFromUtf8("你好"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1743,7 +1743,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_005) JSHandle firstString = factory->NewFromUtf8("abc"); JSHandle secondString = factory->NewFromUtf8("你好"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1752,7 +1752,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_005) JSHandle firstString = factory->NewFromUtf8("你吃"); JSHandle secondString = factory->NewFromUtf8("饭了么abc"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1761,7 +1761,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_005) JSHandle firstString = factory->NewFromUtf8("你吃饭了么"); JSHandle secondString = factory->NewFromUtf8("abc"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } } @@ -1781,7 +1781,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_006) JSHandle firstString = factory->NewFromUtf8("你好"); JSHandle secondString = factory->NewFromUtf8(""); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1790,7 +1790,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_006) JSHandle firstString = factory->NewFromUtf8(""); JSHandle secondString = factory->NewFromUtf8("你好"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1799,7 +1799,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_006) JSHandle firstString = factory->NewFromUtf8("233"); JSHandle secondString = factory->NewFromUtf8(""); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } @@ -1808,7 +1808,7 @@ HWTEST_F_L0(EcmaStringAccessorTest, EqualToSplicedString_006) JSHandle firstString = factory->NewFromUtf8(""); JSHandle secondString = factory->NewFromUtf8("233"); JSHandle ans = factory->ConcatFromString(firstString, secondString); - bool result = EcmaStringAccessor::StringsAreEqual(*allString, *ans); + bool result = EcmaStringAccessor::StringsAreEqual(thread, *allString, *ans); EXPECT_TRUE(result); } } diff --git a/ecmascript/tests/ecma_string_hash_test.cpp b/ecmascript/tests/ecma_string_hash_test.cpp index 4159406fef..58e3f8b74d 100644 --- a/ecmascript/tests/ecma_string_hash_test.cpp +++ b/ecmascript/tests/ecma_string_hash_test.cpp @@ -40,10 +40,11 @@ public: } static uint32_t ComputeConcatHash( + const JSThread *thread, const JSHandle &firstString, const JSHandle &secondString) { - return EcmaString::CalculateConcatHashCode(firstString, secondString); + return EcmaString::CalculateConcatHashCode(thread, firstString, secondString); } }; #if ENABLE_NEXT_OPTIMIZATION @@ -120,7 +121,7 @@ HWTEST_F_L0(EcmaStringHashTest, CalculateConcatHashCode) std::string totalString = firstData + secondData; uint32_t totalHash = ComputeHashOpt(reinterpret_cast(totalString.data()), totalString.size(), 0); - uint32_t concatHash = ComputeConcatHash(firstString, secondString); + uint32_t concatHash = ComputeConcatHash(thread, firstString, secondString); EXPECT_EQ(totalHash, concatHash); } #endif diff --git a/ecmascript/tests/ecma_string_table_test.cpp b/ecmascript/tests/ecma_string_table_test.cpp index 7c94e8207c..4600933028 100644 --- a/ecmascript/tests/ecma_string_table_test.cpp +++ b/ecmascript/tests/ecma_string_table_test.cpp @@ -40,8 +40,8 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternFlattenString_EmptyString) table->GetOrInternFlattenString(thread->GetEcmaVM(), *emptyEcmaStrHandle); EXPECT_TRUE(!EcmaStringAccessor(emptyEcmaStrHandle).IsInternString()); #if ENABLE_NEXT_OPTIMIZATION - EcmaString *emptyEcmaStr = table->TryGetInternString(emptyEcmaStrHandle); - EXPECT_STREQ(EcmaStringAccessor(emptyEcmaStr).ToCString().c_str(), ""); + EcmaString *emptyEcmaStr = table->TryGetInternString(thread, emptyEcmaStrHandle); + EXPECT_STREQ(EcmaStringAccessor(emptyEcmaStr).ToCString(thread).c_str(), ""); EXPECT_TRUE(EcmaStringAccessor(emptyEcmaStr).IsInternString()); #endif } @@ -63,7 +63,7 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_utf8Data) EXPECT_TRUE(!EcmaStringAccessor(ecmaStrCreatePtr).IsInternString()); EcmaString *ecmaStrGetPtr = table->GetOrInternString(vm, utf8Data, sizeof(utf8Data), true); - EXPECT_STREQ(EcmaStringAccessor(ecmaStrGetPtr).ToCString().c_str(), "hello"); + EXPECT_STREQ(EcmaStringAccessor(ecmaStrGetPtr).ToCString(thread).c_str(), "hello"); EXPECT_TRUE(EcmaStringAccessor(ecmaStrGetPtr).IsInternString()); } @@ -85,7 +85,7 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_utf16Data) EXPECT_TRUE(!EcmaStringAccessor(ecmaStrCreatePtr).IsInternString()); EcmaString *ecmaStrGetPtr = table->GetOrInternString(vm, utf16Data, sizeof(utf16Data) / sizeof(uint16_t), false); - EXPECT_STREQ(EcmaStringAccessor(ecmaStrGetPtr).ToCString().c_str(), "编码解码"); + EXPECT_STREQ(EcmaStringAccessor(ecmaStrGetPtr).ToCString(thread).c_str(), "编码解码"); EXPECT_TRUE(EcmaStringAccessor(ecmaStrGetPtr).IsInternString()); } @@ -106,12 +106,12 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_EcmaString) EXPECT_TRUE(EcmaStringAccessor(ecmaStrCreateHandle).IsInternString()); EcmaString *ecmaStrGetPtr = table->GetOrInternString(vm, *ecmaStrCreateHandle); - EXPECT_STREQ(EcmaStringAccessor(ecmaStrGetPtr).ToCString().c_str(), "hello world"); + EXPECT_STREQ(EcmaStringAccessor(ecmaStrGetPtr).ToCString(thread).c_str(), "hello world"); EXPECT_TRUE(EcmaStringAccessor(ecmaStrGetPtr).IsInternString()); #if ENABLE_NEXT_OPTIMIZATION - EcmaString *ecmaStr = table->TryGetInternString(ecmaStrCreateHandle); - EXPECT_STREQ(EcmaStringAccessor(ecmaStr).ToCString().c_str(), "hello world"); + EcmaString *ecmaStr = table->TryGetInternString(thread, ecmaStrCreateHandle); + EXPECT_STREQ(EcmaStringAccessor(ecmaStr).ToCString(thread).c_str(), "hello world"); EXPECT_TRUE(EcmaStringAccessor(ecmaStr).IsInternString()); #endif } @@ -126,7 +126,7 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_EcmaString) HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_CheckStringTable) { #if ENABLE_NEXT_OPTIMIZATION - EXPECT_TRUE(thread->GetEcmaVM()->GetEcmaStringTable()->CheckStringTableValidity()); + EXPECT_TRUE(thread->GetEcmaVM()->GetEcmaStringTable()->CheckStringTableValidity(thread)); #else EXPECT_TRUE(thread->GetEcmaVM()->GetEcmaStringTable()->CheckStringTableValidity(thread)); #endif @@ -173,7 +173,7 @@ HWTEST_F_L0(EcmaStringTableTest, LoadOrStore_ConcurrentAccess) EcmaVM *vm = thread->GetEcmaVM(); JSHandle value1 = vm->GetFactory()->NewFromASCII("value"); for (int i = 0; i < 8000; ++i) { // check 8000 store operations - ASSERT_TRUE(map->Load(i, *value1) != nullptr); + ASSERT_TRUE(map->Load(thread, i, *value1) != nullptr); } delete map; } @@ -189,15 +189,17 @@ HWTEST_F_L0(EcmaStringTableTest, LoadOrStore_InsertNewKey) HashTrieMap *map = new HashTrieMap(); uint32_t key = 0x12345678; JSHandle value(thread, *vm->GetFactory()->NewFromASCII("test_value")); - EcmaString *loadResult1 = map->Load(key, *value); + EcmaString *loadResult1 = map->Load(thread, key, *value); EXPECT_EQ(loadResult1, nullptr); // Test insertion EcmaString *result = map->LoadOrStore( vm, key, [value]() { return value; }, - [value](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*value, foudString); }); + [this, value](EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *value, foudString); + }); EXPECT_EQ(result, *value); - EcmaString *loadResult2 = map->Load(key, *value); - EXPECT_STREQ(EcmaStringAccessor(loadResult2).ToCString().c_str(), "test_value"); + EcmaString *loadResult2 = map->Load(thread, key, *value); + EXPECT_STREQ(EcmaStringAccessor(loadResult2).ToCString(thread).c_str(), "test_value"); EXPECT_EQ(loadResult2, *value); delete map; } @@ -219,15 +221,19 @@ HWTEST_F_L0(EcmaStringTableTest, LoadOrStore_StoreExistingKey) // Initial insertion map->LoadOrStore( vm, key, [original]() { return original; }, - [original](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*original, foudString); }); + [this, original](EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *original, foudString); + }); // store overflow map->LoadOrStore( vm, key, [origina2]() { return origina2; }, - [origina2](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*origina2, foudString); }); + [this, origina2](EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *origina2, foudString); + }); - EXPECT_EQ(map->Load(key, *original), *original); - EXPECT_EQ(map->Load(key, *origina2), *origina2); + EXPECT_EQ(map->Load(thread, key, *original), *original); + EXPECT_EQ(map->Load(thread, key, *origina2), *origina2); delete map; } @@ -251,20 +257,28 @@ HWTEST_F_L0(EcmaStringTableTest, Expand_HashCollisionHandling) // Insert first key map->LoadOrStore( vm, key1, [value1]() { return value1; }, - [value1](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*value1, foudString); }); + [this, value1] (EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *value1, foudString); + }); // Insert second key causing collision map->LoadOrStore( vm, key2, [value2]() { return value2; }, - [value2](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*value2, foudString); }); + [this, value2](EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *value2, foudString); + }); // Insert overflow key3:[value3 value4] map->LoadOrStore( vm, key3, [value3]() { return value3; }, - [value3](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*value3, foudString); }); + [this, value3](EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *value3, foudString); + }); map->LoadOrStore( vm, key3, [value4]() { return value4; }, - [value4](EcmaString *foudString) { return EcmaStringAccessor::StringsAreEqual(*value4, foudString); }); + [this, value4](EcmaString *foudString) { + return EcmaStringAccessor::StringsAreEqual(thread, *value4, foudString); + }); /*map: └── Indirect (----) @@ -311,7 +325,8 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternStringFromCompressedSubString_SubStr uint32_t utf8Len = EcmaStringAccessor(*originalStr).GetLength() - offset; EcmaString *internStr = table->GetOrInternStringFromCompressedSubString(vm, originalStr, offset, utf8Len); - EXPECT_STREQ(EcmaStringAccessor(internStr).ToCString().c_str(), "0x680x650x6c0x6c0x6f0x200x770x6f0x720x6c0x64"); + EXPECT_STREQ(EcmaStringAccessor(internStr).ToCString(thread).c_str(), + "0x680x650x6c0x6c0x6f0x200x770x6f0x720x6c0x64"); EXPECT_TRUE(EcmaStringAccessor(internStr).IsInternString()); } @@ -332,7 +347,7 @@ HWTEST_F_L0(EcmaStringTableTest, GetOrInternString_ConcatenatedStrings) EcmaString *concatenated = table->GetOrInternString(vm, str1, str2); - EXPECT_STREQ(EcmaStringAccessor(concatenated).ToCString().c_str(), "helloworld"); + EXPECT_STREQ(EcmaStringAccessor(concatenated).ToCString(thread).c_str(), "helloworld"); EXPECT_TRUE(EcmaStringAccessor(concatenated).IsInternString()); } @@ -351,9 +366,9 @@ HWTEST_F_L0(EcmaStringTableTest, TryGetInternString_ExistingString) JSHandle original = factory->NewFromASCII("test"); table->GetOrInternString(vm, *original); - EcmaString *retrieved = table->TryGetInternString(original); + EcmaString *retrieved = table->TryGetInternString(thread, original); - EXPECT_STREQ(EcmaStringAccessor(retrieved).ToCString().c_str(), "test"); + EXPECT_STREQ(EcmaStringAccessor(retrieved).ToCString(thread).c_str(), "test"); EXPECT_TRUE(EcmaStringAccessor(retrieved).IsInternString()); } #endif diff --git a/ecmascript/tests/ecma_test_common.h b/ecmascript/tests/ecma_test_common.h index abc2b301a1..378cb3e083 100644 --- a/ecmascript/tests/ecma_test_common.h +++ b/ecmascript/tests/ecma_test_common.h @@ -46,9 +46,10 @@ public: using CreateStringUtf16Func = std::function; using StringAreEqualUtf16Func = - std::function; + std::function; using StringIsEqualUint8Func = - std::function; + std::function; using Compare = std::function &left, const JSHandle &right)>; @@ -66,10 +67,10 @@ public: thread, EcmaStringAccessor::Concat(instance, handleEcmaStrFrontU8, handleEcmaStrBackU16NotComp)); EXPECT_TRUE(EcmaStringAccessor(handleEcmaStrConcatU8U16NotComp).IsUtf16()); for (uint32_t i = 0; i < g_lenFrontU8; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8U16NotComp).Get(i), g_arrayFrontU8[i]); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8U16NotComp).Get(thread, i), g_arrayFrontU8[i]); } for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8U16NotComp).Get(i + g_lenFrontU8), + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8U16NotComp).Get(thread, i + g_lenFrontU8), arrayBackU16NotComp[i]); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrConcatU8U16NotComp).GetLength(), @@ -86,8 +87,8 @@ public: JSHandle handleEcmaStrSubU8( thread, EcmaStringAccessor::FastSubString(instance, handleEcmaStrU8, indexStartSubU8, lengthSubU8)); for (uint32_t i = 0; i < lengthSubU8; i++) { - EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU8).Get(i), - EcmaStringAccessor(handleEcmaStrU8).Get(i + indexStartSubU8)); + EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU8).Get(thread, i), + EcmaStringAccessor(handleEcmaStrU8).Get(thread, i + indexStartSubU8)); } EXPECT_EQ(EcmaStringAccessor(handleEcmaStrSubU8).GetLength(), lengthSubU8); } @@ -139,11 +140,11 @@ public: JSHandle handleEcmaStrU16NotCompNo4( thread, EcmaStringAccessor::CreateFromUtf16(instance, &arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, false)); - EXPECT_FALSE(stringIsEqualFunc(*handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); - EXPECT_TRUE(stringIsEqualFunc(*handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); - EXPECT_FALSE(stringIsEqualFunc(*handleEcmaStrU16NotCompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, false)); - EXPECT_FALSE(stringIsEqualFunc(*handleEcmaStrU16NotCompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, false)); - EXPECT_FALSE(stringIsEqualFunc(*handleEcmaStrU16NotCompNo4, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE(stringIsEqualFunc(thread, *handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_TRUE(stringIsEqualFunc(thread, *handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true)); + EXPECT_FALSE(stringIsEqualFunc(thread, *handleEcmaStrU16NotCompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE(stringIsEqualFunc(thread, *handleEcmaStrU16NotCompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, false)); + EXPECT_FALSE(stringIsEqualFunc(thread, *handleEcmaStrU16NotCompNo4, &arrayU8No1[0], lengthEcmaStrU8No1, false)); } static void TryLowerCommonCase(JSThread *thread, const EcmaVM *instance, JSHandle &lowerStr, @@ -151,7 +152,7 @@ public: { { JSHandle lowerEcmaString(thread, EcmaStringAccessor::TryToLower(instance, lowerStr)); - EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), lowerEcmaString.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, lowerStr.GetTaggedValue(), lowerEcmaString.GetTaggedValue())); EXPECT_EQ(EcmaStringAccessor(lowerStr).GetLength(), EcmaStringAccessor(lowerEcmaString).GetLength()); EXPECT_TRUE(EcmaStringAccessor(lowerEcmaString).IsUtf8()); EXPECT_FALSE(EcmaStringAccessor(lowerEcmaString).IsUtf16()); @@ -159,7 +160,7 @@ public: for (size_t i = 0; i < caseStrings.size(); i++) { JSHandle lowerEcmaString(thread, EcmaStringAccessor::TryToLower(instance, caseStrings[i])); - EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), lowerEcmaString.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, lowerStr.GetTaggedValue(), lowerEcmaString.GetTaggedValue())); EXPECT_EQ(EcmaStringAccessor(lowerStr).GetLength(), EcmaStringAccessor(lowerEcmaString).GetLength()); EXPECT_TRUE(EcmaStringAccessor(lowerEcmaString).IsUtf8()); EXPECT_FALSE(EcmaStringAccessor(lowerEcmaString).IsUtf16()); @@ -249,15 +250,15 @@ public: std::string ivalue = myValue + std::to_string(i); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); - JSTaggedValue gValue = toor->Get(i); + JSTaggedValue gValue = toor->Get(thread, i); EXPECT_EQ(gValue, value.GetTaggedValue()); } - JSTaggedValue gValue = toor->Get(10); // 10: index + JSTaggedValue gValue = toor->Get(thread, 10); // 10: index EXPECT_EQ(gValue, JSTaggedValue::Undefined()); std::string ivalue = myValue + std::to_string(1); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); - EXPECT_TRUE(toor->Has(value.GetTaggedValue())); + EXPECT_TRUE(toor->Has(thread, value.GetTaggedValue())); } template @@ -265,17 +266,17 @@ public: { constexpr uint32_t NODE_NUMBERS = 9; JSMutableHandle value(thread, JSTaggedValue::Undefined()); - EXPECT_EQ(toor->GetLast(), JSTaggedValue::Undefined()); - EXPECT_EQ(toor->GetFirst(), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetLast(thread), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetFirst(thread), JSTaggedValue::Undefined()); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { value.Update(JSTaggedValue(i + 1)); T::Add(thread, toor, value); } - EXPECT_EQ(toor->GetLast().GetInt(), g_numberNine); - EXPECT_EQ(toor->GetFirst().GetInt(), 1); + EXPECT_EQ(toor->GetLast(thread).GetInt(), g_numberNine); + EXPECT_EQ(toor->GetFirst(thread).GetInt(), 1); value.Update(JSTaggedValue(g_nintyNine)); - int len = toor->Length(); + int len = toor->Length(thread); toor->Insert(thread, toor, value, len); return value; } @@ -284,60 +285,60 @@ public: static void GetIndexOfAndGetLastIndexOfCommon(JSThread *thread, JSHandle &toor) { auto value = ListGetLastCommon(thread, toor); - EXPECT_EQ(toor->GetIndexOf(value.GetTaggedValue()).GetInt(), g_numberNine); - EXPECT_EQ(toor->GetLastIndexOf(value.GetTaggedValue()).GetInt(), g_numberNine); - EXPECT_EQ(toor->Length(), 10); // 10: len + EXPECT_EQ(toor->GetIndexOf(thread, value.GetTaggedValue()).GetInt(), g_numberNine); + EXPECT_EQ(toor->GetLastIndexOf(thread, value.GetTaggedValue()).GetInt(), g_numberNine); + EXPECT_EQ(toor->Length(thread), 10); // 10: len value.Update(JSTaggedValue(g_hundred)); toor->Insert(thread, toor, value, 0); - EXPECT_EQ(toor->GetIndexOf(value.GetTaggedValue()).GetInt(), 0); - EXPECT_EQ(toor->GetLastIndexOf(value.GetTaggedValue()).GetInt(), 0); - EXPECT_EQ(toor->Length(), 11); // 11: len + EXPECT_EQ(toor->GetIndexOf(thread, value.GetTaggedValue()).GetInt(), 0); + EXPECT_EQ(toor->GetLastIndexOf(thread, value.GetTaggedValue()).GetInt(), 0); + EXPECT_EQ(toor->Length(thread), 11); // 11: len value.Update(JSTaggedValue(g_hundredAndOne)); toor->Insert(thread, toor, value, g_numberFive); - EXPECT_EQ(toor->GetIndexOf(value.GetTaggedValue()).GetInt(), g_numberFive); - EXPECT_EQ(toor->GetLastIndexOf(value.GetTaggedValue()).GetInt(), g_numberFive); - EXPECT_EQ(toor->Length(), 12); // 12: len + EXPECT_EQ(toor->GetIndexOf(thread, value.GetTaggedValue()).GetInt(), g_numberFive); + EXPECT_EQ(toor->GetLastIndexOf(thread, value.GetTaggedValue()).GetInt(), g_numberFive); + EXPECT_EQ(toor->Length(thread), 12); // 12: len - toor->Dump(); + toor->Dump(thread); } template static void InsertAndGetLastCommon(JSThread *thread, JSHandle &toor) { auto value = ListGetLastCommon(thread, toor); - EXPECT_EQ(toor->GetLast().GetInt(), g_nintyNine); - EXPECT_EQ(toor->Length(), 10); // 10: len + EXPECT_EQ(toor->GetLast(thread).GetInt(), g_nintyNine); + EXPECT_EQ(toor->Length(thread), 10); // 10: len value.Update(JSTaggedValue(g_hundred)); toor->Insert(thread, toor, value, 0); - EXPECT_EQ(toor->GetFirst().GetInt(), g_hundred); - EXPECT_EQ(toor->Length(), 11); // 11: len + EXPECT_EQ(toor->GetFirst(thread).GetInt(), g_hundred); + EXPECT_EQ(toor->Length(thread), 11); // 11: len - toor->Dump(); + toor->Dump(thread); value.Update(JSTaggedValue(g_hundredAndOne)); toor->Insert(thread, toor, value, g_numberFive); - EXPECT_EQ(toor->Length(), 12); // 12: len - toor->Dump(); - EXPECT_EQ(toor->Get(g_numberFive).GetInt(), g_hundredAndOne); + EXPECT_EQ(toor->Length(thread), 12); // 12: len + toor->Dump(thread); + EXPECT_EQ(toor->Get(thread, g_numberFive).GetInt(), g_hundredAndOne); } template static void ListRemoveCommon(JSThread *thread, JSHandle &toor, JSMutableHandle &value) { constexpr uint32_t NODE_NUMBERS = 20; - EXPECT_EQ(toor->GetLast(), JSTaggedValue::Undefined()); - EXPECT_EQ(toor->GetFirst(), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetLast(thread), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetFirst(thread), JSTaggedValue::Undefined()); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { value.Update(JSTaggedValue(i)); T::Add(thread, toor, value); } - EXPECT_EQ(toor->Length(), NODE_NUMBERS); + EXPECT_EQ(toor->Length(thread), NODE_NUMBERS); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { value.Update(JSTaggedValue(i)); - JSTaggedValue gValue = toor->Get(i); + JSTaggedValue gValue = toor->Get(thread, i); EXPECT_EQ(gValue, value.GetTaggedValue()); } } @@ -435,11 +436,11 @@ public: JSTaggedValue value(newObj2); value.CreateWeakRef(); array->Set(thread, 1, value); - EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(0)); - EXPECT_EQ(value, array->Get(1)); + EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(thread, 0)); + EXPECT_EQ(value, array->Get(thread, 1)); ecmaVM->CollectGarbage(type); - EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(0)); - EXPECT_EQ(JSTaggedValue::Undefined(), array->Get(1)); // 1 : index + EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(thread, 0)); + EXPECT_EQ(JSTaggedValue::Undefined(), array->Get(thread, 1)); // 1 : index } static void ArrayKeepGcCommon(JSThread *thread, TriggerGCType type) @@ -454,14 +455,14 @@ public: JSTaggedValue value(newObj2.GetTaggedValue()); value.CreateWeakRef(); array->Set(thread, 1, value); - EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(0)); - EXPECT_EQ(value, array->Get(1)); + EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(thread, 0)); + EXPECT_EQ(value, array->Get(thread, 1)); ecmaVM->CollectGarbage(type); - EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(0)); - EXPECT_EQ(true, array->Get(1).IsWeak()); + EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(thread, 0)); + EXPECT_EQ(true, array->Get(thread, 1).IsWeak()); value = newObj2.GetTaggedValue(); value.CreateWeakRef(); - EXPECT_EQ(value, array->Get(1)); + EXPECT_EQ(value, array->Get(thread, 1)); } }; }; // namespace panda::test diff --git a/ecmascript/tests/gc_region_promotion_test.cpp b/ecmascript/tests/gc_region_promotion_test.cpp index 9f0c0c37f7..39eba71003 100644 --- a/ecmascript/tests/gc_region_promotion_test.cpp +++ b/ecmascript/tests/gc_region_promotion_test.cpp @@ -99,11 +99,11 @@ HWTEST_F_L0(GCTest, NewToOldPromotionYoungGCTest) EXPECT_TRUE(testCase.regionNewToNew_->InYoungSpace()); EXPECT_TRUE(testCase.regionNewToOld_->InOldSpace()); EXPECT_FALSE(testCase.regionNewToOld_->InNewToOldSet()); - EXPECT_TRUE(testCase.newToNewArray_->Get(0).IsUndefined()); - EXPECT_TRUE(testCase.newArray_->Get(0).IsUndefined()); - EXPECT_TRUE(testCase.oldArray_->Get(0).IsUndefined()); + EXPECT_TRUE(testCase.newToNewArray_->Get(thread, 0).IsUndefined()); + EXPECT_TRUE(testCase.newArray_->Get(thread, 0).IsUndefined()); + EXPECT_TRUE(testCase.oldArray_->Get(thread, 0).IsUndefined()); EXPECT_EQ(*reinterpret_cast(testCase.weakGlobal_), JSTaggedValueInternals::VALUE_UNDEFINED); - JSTaggedType newToOldArrayFromArray = testCase.newToNewArray_->Get(1).GetRawData(); + JSTaggedType newToOldArrayFromArray = testCase.newToNewArray_->Get(thread, 1).GetRawData(); JSTaggedType newToOldArray = testCase.newToOldArray_.GetTaggedValue().GetRawData(); EXPECT_EQ(newToOldArrayFromArray, newToOldArray); heap->GetOldSpace()->EnumerateRegions([](Region *region) { @@ -124,11 +124,11 @@ HWTEST_F_L0(GCTest, NewToOldPromotionOldGCTest) EXPECT_TRUE(testCase.regionNewToNew_->InYoungSpace()); EXPECT_TRUE(testCase.regionNewToOld_->InOldSpace()); EXPECT_FALSE(testCase.regionNewToOld_->InNewToOldSet()); - EXPECT_TRUE(testCase.newToNewArray_->Get(0).IsUndefined()); - EXPECT_TRUE(testCase.newArray_->Get(0).IsUndefined()); - EXPECT_TRUE(testCase.oldArray_->Get(0).IsUndefined()); + EXPECT_TRUE(testCase.newToNewArray_->Get(thread, 0).IsUndefined()); + EXPECT_TRUE(testCase.newArray_->Get(thread, 0).IsUndefined()); + EXPECT_TRUE(testCase.oldArray_->Get(thread, 0).IsUndefined()); EXPECT_EQ(*reinterpret_cast(testCase.weakGlobal_), JSTaggedValueInternals::VALUE_UNDEFINED); - JSTaggedType newToOldArrayFromArray = testCase.newToNewArray_->Get(1).GetRawData(); + JSTaggedType newToOldArrayFromArray = testCase.newToNewArray_->Get(thread, 1).GetRawData(); JSTaggedType newToOldArray = testCase.newToOldArray_.GetTaggedValue().GetRawData(); EXPECT_EQ(newToOldArrayFromArray, newToOldArray); heap->GetOldSpace()->EnumerateRegions([](Region *region) { diff --git a/ecmascript/tests/global_dictionary_test.cpp b/ecmascript/tests/global_dictionary_test.cpp index 0517ec4c41..41de4e251d 100644 --- a/ecmascript/tests/global_dictionary_test.cpp +++ b/ecmascript/tests/global_dictionary_test.cpp @@ -37,8 +37,8 @@ HWTEST_F_L0(GlobalDictionaryTest, IsMatch) JSHandle globalKey = factory->NewFromASCII("key"); JSTaggedValue globalOtherKey = globalKey.GetTaggedValue(); - EXPECT_EQ(GlobalDictionary::IsMatch(globalKey.GetTaggedValue(), globalOtherKey), true); - EXPECT_EQ(GlobalDictionary::IsMatch(globalKey.GetTaggedValue(), JSTaggedValue::Undefined()), false); + EXPECT_EQ(GlobalDictionary::IsMatch(thread, globalKey.GetTaggedValue(), globalOtherKey), true); + EXPECT_EQ(GlobalDictionary::IsMatch(thread, globalKey.GetTaggedValue(), JSTaggedValue::Undefined()), false); } /** @@ -55,13 +55,13 @@ HWTEST_F_L0(GlobalDictionaryTest, Hash) uint8_t utf8ArrayName[4] = {0, 2, 5}; // The last element is "\0" uint32_t utf8ArrayNameLen = sizeof(utf8ArrayName) - 1; JSHandle nameStringUtf8Obj = factory->NewFromUtf8(utf8ArrayName, utf8ArrayNameLen); - EXPECT_EQ(GlobalDictionary::Hash(nameStringUtf8Obj.GetTaggedValue()), 67); // 67 = (0 << 5 - 0 + 2) << 5 - 2 + 5 + EXPECT_EQ(GlobalDictionary::Hash(thread, nameStringUtf8Obj.GetTaggedValue()), 67); // 67 = (0 << 5 - 0 + 2) << 5 - 2 + 5 // test obj is string(uint16_t) uint16_t utf16ArrayName[] = {0x1, 0x2, 0x1}; uint32_t utf16ArrayNameLen = sizeof(utf16ArrayName) / sizeof(utf16ArrayName[0]); JSHandle nameStringUtf16Obj = factory->NewFromUtf16(utf16ArrayName, utf16ArrayNameLen); // 1024 = (1 << 5 - 0 + 1) << 5 - 1 + 1 - EXPECT_EQ(GlobalDictionary::Hash(nameStringUtf16Obj.GetTaggedValue()), 1024); + EXPECT_EQ(GlobalDictionary::Hash(thread, nameStringUtf16Obj.GetTaggedValue()), 1024); } /** @@ -89,13 +89,13 @@ HWTEST_F_L0(GlobalDictionaryTest, GetBoxAndValue) JSHandle newDict = handleDict->PutIfAbsent(thread, handleDict, globalKey1, propertyBox1, attribute); - EXPECT_TRUE(handleDict->GetBox(0) != nullptr); - EXPECT_EQ(handleDict->GetValue(0).GetInt(), 123); + EXPECT_TRUE(handleDict->GetBox(thread, 0) != nullptr); + EXPECT_EQ(handleDict->GetValue(thread, 0).GetInt(), 123); - EXPECT_TRUE(newDict->GetBox(0) != nullptr); - EXPECT_EQ(newDict->GetValue(0).GetInt(), 123); - EXPECT_TRUE(newDict->GetBox(1) != nullptr); - EXPECT_EQ(newDict->GetValue(1).GetInt(), 100); + EXPECT_TRUE(newDict->GetBox(thread, 0) != nullptr); + EXPECT_EQ(newDict->GetValue(thread, 0).GetInt(), 123); + EXPECT_TRUE(newDict->GetBox(thread, 1) != nullptr); + EXPECT_EQ(newDict->GetValue(thread, 1).GetInt(), 100); } /** @@ -113,7 +113,7 @@ HWTEST_F_L0(GlobalDictionaryTest, GetAttributes) // set attributes call SetAttributes function for (int i = 0; i < numberofElements; i++) { handleDict->SetAttributes(thread, i, PropertyAttributes(i)); - EXPECT_EQ(handleDict->GetAttributes(i).GetPropertyMetaData(), i); + EXPECT_EQ(handleDict->GetAttributes(thread, i).GetPropertyMetaData(), i); } } @@ -138,9 +138,9 @@ HWTEST_F_L0(GlobalDictionaryTest, ClearEntry) handleValue.GetTaggedValue(), PropertyAttributes(i)); } // check attributes in three - EXPECT_EQ(handleDict->GetAttributes(3).GetPropertyMetaData(), 3); + EXPECT_EQ(handleDict->GetAttributes(thread, 3).GetPropertyMetaData(), 3); handleDict->ClearEntry(thread, 3); - EXPECT_EQ(handleDict->GetAttributes(3).GetPropertyMetaData(), 0); + EXPECT_EQ(handleDict->GetAttributes(thread, 3).GetPropertyMetaData(), 0); } /** @@ -165,8 +165,8 @@ HWTEST_F_L0(GlobalDictionaryTest, UpdateValueAndAttributes) propertyBox.GetTaggedValue(), PropertyAttributes(i)); } // check attributes in five - EXPECT_EQ(handleDict->GetAttributes(5).GetPropertyMetaData(), 5); - EXPECT_EQ(handleDict->GetValue(5).GetInt(), 5); + EXPECT_EQ(handleDict->GetAttributes(thread, 5).GetPropertyMetaData(), 5); + EXPECT_EQ(handleDict->GetValue(thread, 5).GetInt(), 5); // Update value and attributes for (int i = 0; i < numberofElements; i++) { JSHandle handleValue(thread, JSTaggedValue(static_cast(i + 1))); @@ -175,8 +175,8 @@ HWTEST_F_L0(GlobalDictionaryTest, UpdateValueAndAttributes) PropertyAttributes(static_cast(i + 1))); } // check attributes in five - EXPECT_EQ(handleDict->GetAttributes(5).GetPropertyMetaData(), 6); - EXPECT_EQ(handleDict->GetValue(5).GetInt(), 6); + EXPECT_EQ(handleDict->GetAttributes(thread, 5).GetPropertyMetaData(), 6); + EXPECT_EQ(handleDict->GetValue(thread, 5).GetInt(), 6); } /** @@ -211,13 +211,13 @@ HWTEST_F_L0(GlobalDictionaryTest, GetAllKeys) dictHandle->GetAllKeys(thread, offset, *keyArray); // Skip the first seven positions for (uint32_t i = 0; i < offset; i++) { - EXPECT_TRUE(keyArray->Get(i).IsHole()); + EXPECT_TRUE(keyArray->Get(thread, i).IsHole()); } // check key name - JSHandle resultFirstKey(thread, keyArray->Get(offset)); - JSHandle resultLastKey(thread, keyArray->Get(arraySize - 1)); - EXPECT_EQ(nameKey[0], EcmaStringAccessor(resultFirstKey).ToCString().c_str()); - EXPECT_EQ(nameKey[15], EcmaStringAccessor(resultLastKey).ToCString().c_str()); + JSHandle resultFirstKey(thread, keyArray->Get(thread, offset)); + JSHandle resultLastKey(thread, keyArray->Get(thread, arraySize - 1)); + EXPECT_EQ(nameKey[0], EcmaStringAccessor(resultFirstKey).ToCString(thread).c_str()); + EXPECT_EQ(nameKey[15], EcmaStringAccessor(resultLastKey).ToCString(thread).c_str()); } /** @@ -258,10 +258,10 @@ HWTEST_F_L0(GlobalDictionaryTest, GetEnumAllKeys) JSHandle keyArray = factory->NewTaggedArray(arraySize); dictHandle->GetEnumAllKeys(thread, offset, *keyArray, &keys); EXPECT_EQ(keys, 8U); - JSHandle resultFirstKey(thread, keyArray->Get(offset)); - JSHandle resultLastKey(thread, keyArray->Get(offset + keys - 1U)); - EXPECT_EQ(nameKey[1], EcmaStringAccessor(resultFirstKey).ToCString().c_str()); - EXPECT_EQ(nameKey[15], EcmaStringAccessor(resultLastKey).ToCString().c_str()); + JSHandle resultFirstKey(thread, keyArray->Get(thread, offset)); + JSHandle resultLastKey(thread, keyArray->Get(thread, offset + keys - 1U)); + EXPECT_EQ(nameKey[1], EcmaStringAccessor(resultFirstKey).ToCString(thread).c_str()); + EXPECT_EQ(nameKey[15], EcmaStringAccessor(resultLastKey).ToCString(thread).c_str()); } /** @@ -313,8 +313,8 @@ HWTEST_F_L0(GlobalDictionaryTest, InvalidatePropertyBox) // calling InvalidatePropertyBox function to Invalidate the PropertyBox PropertyAttributes newAttr(10); GlobalDictionary::InvalidatePropertyBox(thread, handleDict, invalidatedPosition); - EXPECT_EQ(handleDict->GetAttributes(invalidatedPosition).GetBoxType(), PropertyBoxType::MUTABLE); - EXPECT_EQ(handleDict->GetAttributes(invalidatedSet).GetDictionaryOrder(), invalidatedPosition); - EXPECT_EQ(handleDict->GetValue(invalidatedPosition).GetInt(), invalidatedPosition); + EXPECT_EQ(handleDict->GetAttributes(thread, invalidatedPosition).GetBoxType(), PropertyBoxType::MUTABLE); + EXPECT_EQ(handleDict->GetAttributes(thread, invalidatedSet).GetDictionaryOrder(), invalidatedPosition); + EXPECT_EQ(handleDict->GetValue(thread, invalidatedPosition).GetInt(), invalidatedPosition); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/huge_object_test.cpp b/ecmascript/tests/huge_object_test.cpp index 2c8821e9b6..ddb5be52da 100644 --- a/ecmascript/tests/huge_object_test.cpp +++ b/ecmascript/tests/huge_object_test.cpp @@ -53,7 +53,7 @@ HWTEST_F_L0(HugeObjectTest, LargeArrayKeep) EXPECT_EQ(*arrayHandle, reinterpret_cast(array)); ecmaVm->CollectGarbage(TriggerGCType::YOUNG_GC); // Trigger GC. ecmaVm->CollectGarbage(TriggerGCType::OLD_GC); // Trigger GC. - EXPECT_EQ(*newObj, array->Get(0).GetTaggedObject()); + EXPECT_EQ(*newObj, array->Get(thread, 0).GetTaggedObject()); EXPECT_EQ(*arrayHandle, reinterpret_cast(array)); } diff --git a/ecmascript/tests/js_api_arraylist_iterator_test.cpp b/ecmascript/tests/js_api_arraylist_iterator_test.cpp index 89f025bca9..633d890c12 100644 --- a/ecmascript/tests/js_api_arraylist_iterator_test.cpp +++ b/ecmascript/tests/js_api_arraylist_iterator_test.cpp @@ -67,7 +67,7 @@ HWTEST_F_L0(JSAPIArrayListIteratorTest, Next) EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue(i)); } else { - EXPECT_EQ(arrayListIterator->GetIteratedArrayList(), JSTaggedValue::Undefined()); + EXPECT_EQ(arrayListIterator->GetIteratedArrayList(thread), JSTaggedValue::Undefined()); EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue::Undefined()); } diff --git a/ecmascript/tests/js_api_arraylist_test.cpp b/ecmascript/tests/js_api_arraylist_test.cpp index b628ef3b4f..3648c2d2ff 100644 --- a/ecmascript/tests/js_api_arraylist_test.cpp +++ b/ecmascript/tests/js_api_arraylist_test.cpp @@ -36,11 +36,12 @@ public: JSHandle value = GetCallArg(argv, 0); JSHandle key = GetCallArg(argv, 1); JSHandle arrayList = GetCallArg(argv, 2); // 2 means the secode arg + JSThread *thread = argv->GetThread(); if (!arrayList->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIArrayList::Cast(arrayList.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - JSTaggedValue result = elements->Get(key->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + JSTaggedValue result = elements->Get(thread, key->GetInt()); EXPECT_EQ(result, value.GetTaggedValue()); } } @@ -103,9 +104,9 @@ HWTEST_F_L0(JSAPIArrayListTest, Add) JSHandle value(thread, JSTaggedValue(i * 10)); JSAPIArrayList::Add(thread, arrayList, value); } - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); for (uint32_t i = 0; i < increasedLength; i++) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(i * 10)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i * 10)); } } @@ -129,14 +130,14 @@ HWTEST_F_L0(JSAPIArrayListTest, Insert) JSHandle insertValue(thread, JSTaggedValue(99 + i)); JSAPIArrayList::Insert(thread, arrayList, insertValue, insertStartFrom + i); } - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); for (uint32_t i = 0; i < basicLength + insertNums; i++) { if (i < insertStartFrom) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(i * 10)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i * 10)); } else if (i >= insertStartFrom && i < insertStartFrom + insertNums) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(99 + i - insertStartFrom)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(99 + i - insertStartFrom)); } else if (i >= insertStartFrom + insertNums) { - EXPECT_EQ(elements->Get(i), JSTaggedValue((i - insertNums) * 10)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue((i - insertNums) * 10)); } } @@ -162,16 +163,16 @@ HWTEST_F_L0(JSAPIArrayListTest, Clear) { JSHandle arrayList(thread, CreateArrayList()); EXPECT_TRUE(JSAPIArrayList::IsEmpty(arrayList)); - EXPECT_EQ(arrayList->GetLength(), JSTaggedValue(0)); + EXPECT_EQ(arrayList->GetLength(), 0); JSHandle value(thread, JSTaggedValue(99)); JSAPIArrayList::Add(thread, arrayList, value); EXPECT_FALSE(JSAPIArrayList::IsEmpty(arrayList)); - EXPECT_EQ(arrayList->GetLength(), JSTaggedValue(1)); + EXPECT_EQ(arrayList->GetLength(), 1); JSAPIArrayList::Clear(thread, arrayList); EXPECT_TRUE(JSAPIArrayList::IsEmpty(arrayList)); - EXPECT_EQ(arrayList->GetLength(), JSTaggedValue(0)); + EXPECT_EQ(arrayList->GetLength(), 0); } /** @@ -189,11 +190,11 @@ HWTEST_F_L0(JSAPIArrayListTest, Clone) JSAPIArrayList::Add(thread, arrayList, value); } JSHandle newArrayList = JSAPIArrayList::Clone(thread, arrayList); - JSHandle elements(thread, arrayList->GetElements()); - JSHandle newElements(thread, newArrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); + JSHandle newElements(thread, newArrayList->GetElements(thread)); for (uint32_t i = 0; i < length; i++) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(i)); - EXPECT_EQ(newElements->Get(i), JSTaggedValue(i)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i)); + EXPECT_EQ(newElements->Get(thread, i), JSTaggedValue(i)); } } @@ -325,10 +326,10 @@ HWTEST_F_L0(JSAPIArrayListTest, RemoveByIndex_Remove) // Delete elements with indexes between [0, 55]. JSAPIArrayList::RemoveByIndex(thread, arrayList, 0); } - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); for (uint32_t i = 0; i < addElementNums - removeElementNums; i++) { // The value of the corresponding index [0, 199] is [56, 255]. - EXPECT_EQ(elements->Get(i), JSTaggedValue(i + removeElementNums)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i + removeElementNums)); } } @@ -340,11 +341,11 @@ HWTEST_F_L0(JSAPIArrayListTest, RemoveByIndex_Remove) // Delete 44 elements whose element values are in [56, 99]. JSAPIArrayList::Remove(thread, arrayList, value); } - JSHandle elements(thread, arrayList->GetElements()); + JSHandle elements(thread, arrayList->GetElements(thread)); for (uint32_t i = 0; i < addElementNums - 100 - 1; i++) { // The value of the corresponding index [0, 155] is [100, 255]. - EXPECT_EQ(elements->Get(i), JSTaggedValue(i + 100)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i + 100)); } JSHandle value(thread, JSTaggedValue(addElementNums)); bool result = JSAPIArrayList::Remove(thread, arrayList, value); @@ -375,20 +376,20 @@ HWTEST_F_L0(JSAPIArrayListTest, RemoveByRange) // Remove the value between 50 and 100 of the index element. JSAPIArrayList::RemoveByRange(thread, arrayList, fromIndexValue, toIndexValue); - uint32_t length = arrayList->GetLength().GetArrayLength(); - JSHandle elements(thread, arrayList->GetElements()); + uint32_t length = arrayList->GetLength(); + JSHandle elements(thread, arrayList->GetElements(thread)); for (uint32_t i = 0; i < length - (toIndex - formIndex); i++) { // The value of the corresponding index [0, 100] is [0, 49] ∪ [100, 149]. if (i >= 0 && i < 50) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(i)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i)); } else if (i > 50) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(i + 50)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i + 50)); } } // throw error test uint32_t smallIndex = -1; - uint32_t bigIndex = arrayList->GetLength().GetArrayLength() + 10; + uint32_t bigIndex = arrayList->GetLength() + 10; uint32_t zeroIndex = 0; JSHandle smallIndexValue(thread, JSTaggedValue(smallIndex)); JSHandle bigIndexValue(thread, JSTaggedValue(bigIndex)); @@ -435,7 +436,7 @@ HWTEST_F_L0(JSAPIArrayListTest, RemoveByRangeAndGetHeapUsedSize) JSAPIArrayList::RemoveByRange(thread, arrayList, fromIndexValue, toIndexValue); // test heap is normal after RemoveByRange, GetLiveObjectSize will iterate heap instance->GetHeap()->GetLiveObjectSize(); - EXPECT_EQ(arrayList->GetLength().GetInt(), 8); // 8: new length + EXPECT_EQ(arrayList->GetLength(), 8); // 8: new length } /** @@ -451,10 +452,10 @@ HWTEST_F_L0(JSAPIArrayListTest, ReplaceAllElements) EXPECT_EQ(result.GetTaggedValue(), JSTaggedValue::Undefined()); // Recheck the results after replace. - uint32_t length = arrayList->GetLength().GetArrayLength(); - JSHandle elements(thread, arrayList->GetElements()); + uint32_t length = arrayList->GetLength(); + JSHandle elements(thread, arrayList->GetElements(thread)); for (uint32_t i = 0; i < length; i++) { - EXPECT_EQ(elements->Get(i), JSTaggedValue(i)); + EXPECT_EQ(elements->Get(thread, i), JSTaggedValue(i)); } } @@ -479,15 +480,15 @@ HWTEST_F_L0(JSAPIArrayListTest, SubArrayList) JSTaggedValue subArrayListValue = JSAPIArrayList::SubArrayList(thread, arrayList, fromIndexValue, toIndexValue); JSHandle subArrayList(thread, subArrayListValue); - JSHandle subElements(thread, subArrayList->GetElements()); - for (uint32_t i = 0; i < subArrayList->GetLength().GetArrayLength(); i++) { + JSHandle subElements(thread, subArrayList->GetElements(thread)); + for (uint32_t i = 0; i < subArrayList->GetLength(); i++) { // The element value interval of substring is [50, 100] - EXPECT_EQ(subElements->Get(i), JSTaggedValue(i + formIndex)); + EXPECT_EQ(subElements->Get(thread, i), JSTaggedValue(i + formIndex)); } // throw error test uint32_t smallIndex = -1; - uint32_t bigIndex = arrayList->GetLength().GetArrayLength() + 10; + uint32_t bigIndex = arrayList->GetLength() + 10; uint32_t zeroIndex = 0; JSHandle smallIndexValue(thread, JSTaggedValue(smallIndex)); JSHandle bigIndexValue(thread, JSTaggedValue(bigIndex)); @@ -514,13 +515,13 @@ HWTEST_F_L0(JSAPIArrayListTest, SubArrayList) EXPECT_EXCEPTION(); // newLength == 0 - uint32_t arrayLength = arrayList->GetLength().GetArrayLength(); + uint32_t arrayLength = arrayList->GetLength(); JSHandle fromIndexValue0(thread, JSTaggedValue(arrayLength - 1)); JSHandle toIndexValue0(thread, JSTaggedValue(arrayLength)); JSTaggedValue newSubArrayListValue = JSAPIArrayList::SubArrayList(thread, arrayList, fromIndexValue0, toIndexValue0); JSHandle newSubArrayList(thread, newSubArrayListValue); - int newLength = static_cast(newSubArrayList->GetLength().GetArrayLength()); + int newLength = static_cast(newSubArrayList->GetLength()); EXPECT_EQ(newLength, 1); } @@ -561,7 +562,7 @@ HWTEST_F_L0(JSAPIArrayListTest, Get_Set_Has) JSHandle arrayList(thread, CreateArrayList()); // test Has of empty arraylist - EXPECT_FALSE(arrayList->Has(JSTaggedValue(0))); + EXPECT_FALSE(arrayList->Has(thread, JSTaggedValue(0))); uint32_t elementsNum = 256; for (uint32_t i = 0; i < elementsNum; i++) { @@ -572,9 +573,9 @@ HWTEST_F_L0(JSAPIArrayListTest, Get_Set_Has) JSHandle getValue(thread, arrayList->Get(thread, i)); EXPECT_EQ(getValue.GetTaggedValue(), JSTaggedValue(i * 10)); - bool isHas = arrayList->Has(JSTaggedValue(i * 10)); + bool isHas = arrayList->Has(thread, JSTaggedValue(i * 10)); EXPECT_EQ(isHas, true); - EXPECT_FALSE(arrayList->Has(JSTaggedValue(-(i + 1)))); + EXPECT_FALSE(arrayList->Has(thread, JSTaggedValue(-(i + 1)))); } // test Get exception @@ -603,10 +604,10 @@ HWTEST_F_L0(JSAPIArrayListTest, OwnKeys) JSAPIArrayList::Add(thread, arrayList, value); } JSHandle keys = JSAPIArrayList::OwnKeys(thread, arrayList); - uint32_t length = arrayList->GetLength().GetArrayLength(); + uint32_t length = arrayList->GetLength(); for (uint32_t i = 0; i < length; i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(keys->Get(i).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), + EcmaString::Cast(keys->Get(thread, i).GetTaggedObject()))); } } diff --git a/ecmascript/tests/js_api_bitvector_iterator_test.cpp b/ecmascript/tests/js_api_bitvector_iterator_test.cpp index 69c4e5bb21..bbe899979b 100644 --- a/ecmascript/tests/js_api_bitvector_iterator_test.cpp +++ b/ecmascript/tests/js_api_bitvector_iterator_test.cpp @@ -121,7 +121,7 @@ HWTEST_F_L0(JSAPIBitVectorIteratorTest, Next) EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue(1)); } else { - EXPECT_EQ(bitVectorIterator->GetIteratedBitVector(), JSTaggedValue::Undefined()); + EXPECT_EQ(bitVectorIterator->GetIteratedBitVector(thread), JSTaggedValue::Undefined()); EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue::Undefined()); } diff --git a/ecmascript/tests/js_api_bitvector_test.cpp b/ecmascript/tests/js_api_bitvector_test.cpp index 8438c83d95..b83c0cf8b5 100644 --- a/ecmascript/tests/js_api_bitvector_test.cpp +++ b/ecmascript/tests/js_api_bitvector_test.cpp @@ -127,7 +127,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, Push) JSHandle value(thread, JSTaggedValue(1)); JSAPIBitVector::Push(thread, bitVector, value); } - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); for (uint32_t i = 0; i < increasedLength; i++) { @@ -171,7 +171,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, Set) JSHandle value(thread, JSTaggedValue(0)); JSAPIBitVector::Push(thread, bitVector, value); } - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); JSTaggedValue res = bitVector->Set(thread, index, JSTaggedValue(1)); @@ -234,7 +234,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, Has_instance) JSHandle value(thread, JSTaggedValue(1)); JSAPIBitVector::Push(thread, bitVector, value); } - bool res = bitVector->Has(JSTaggedValue(1)); + bool res = bitVector->Has(thread, JSTaggedValue(1)); EXPECT_TRUE(res); } @@ -285,7 +285,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, SetBitsByRange) JSTaggedValue res = JSAPIBitVector::SetBitsByRange(thread, bitVector, value, value1, value2); EXPECT_EQ(res, JSTaggedValue::Undefined()); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); for (uint32_t i = startIndex; i < endIndex; i++) { @@ -336,7 +336,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, SetAllBits) JSHandle value(thread, JSTaggedValue(1)); JSTaggedValue res = JSAPIBitVector::SetAllBits(thread, bitVector, value); EXPECT_EQ(res, JSTaggedValue::Undefined()); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); for (uint32_t i = 0; i < increasedLength; i++) { @@ -430,7 +430,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, FlipBitByIndex) } JSTaggedValue res = JSAPIBitVector::FlipBitByIndex(thread, bitVector, index); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); EXPECT_EQ(res, JSTaggedValue::Undefined()); @@ -458,7 +458,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, FlipBitsByRange) JSTaggedValue res = JSAPIBitVector::FlipBitsByRange(thread, bitVector, value1, value2); EXPECT_EQ(res, JSTaggedValue::Undefined()); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); for (uint32_t i = startIndex; i < endIndex; i++) { @@ -485,7 +485,7 @@ HWTEST_F_L0(JSAPIBitVectorTest, Resize) JSAPIBitVector::Resize(thread, bitVector, newLength); EXPECT_EQ(bitVector->GetLength(), newLength); - JSHandle np(thread, bitVector->GetNativePointer()); + JSHandle np(thread, bitVector->GetNativePointer(thread)); auto elements = reinterpret_cast> *>(np->GetExternalPointer()); for (uint32_t i = increasedLength; i < newLength; i++) { @@ -509,8 +509,8 @@ HWTEST_F_L0(JSAPIBitVectorTest, OwnKeys) } JSHandle keys = JSAPIBitVector::OwnKeys(thread, bitVector); - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(0))), - EcmaString::Cast(keys->Get(0).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(0))), + EcmaString::Cast(keys->Get(thread, 0).GetTaggedObject()))); } /** diff --git a/ecmascript/tests/js_api_deque_iterator_test.cpp b/ecmascript/tests/js_api_deque_iterator_test.cpp index adfdbaddd5..1da987bedf 100644 --- a/ecmascript/tests/js_api_deque_iterator_test.cpp +++ b/ecmascript/tests/js_api_deque_iterator_test.cpp @@ -69,7 +69,7 @@ HWTEST_F_L0(JSAPIDequeIteratorTest, Next) EXPECT_TRUE(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()->IsString()); } else { - EXPECT_TRUE(dequeIterator->GetIteratedDeque().IsUndefined()); + EXPECT_TRUE(dequeIterator->GetIteratedDeque(thread).IsUndefined()); EXPECT_TRUE(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()->IsUndefined()); } } @@ -144,10 +144,10 @@ HWTEST_F_L0(JSAPIDequeIteratorTest, SetIteratedDeque) JSAPIDeque::InsertFront(thread, jsDeque2, value); } JSHandle dequeIterator = factory->NewJSAPIDequeIterator(jsDeque1); - EXPECT_EQ(dequeIterator->GetIteratedDeque(), jsDeque1.GetTaggedValue()); + EXPECT_EQ(dequeIterator->GetIteratedDeque(thread), jsDeque1.GetTaggedValue()); dequeIterator->SetIteratedDeque(thread, jsDeque2.GetTaggedValue()); - EXPECT_EQ(dequeIterator->GetIteratedDeque(), jsDeque2.GetTaggedValue()); + EXPECT_EQ(dequeIterator->GetIteratedDeque(thread), jsDeque2.GetTaggedValue()); } /** diff --git a/ecmascript/tests/js_api_deque_test.cpp b/ecmascript/tests/js_api_deque_test.cpp index 4a3691de6d..0f991396ba 100644 --- a/ecmascript/tests/js_api_deque_test.cpp +++ b/ecmascript/tests/js_api_deque_test.cpp @@ -55,17 +55,17 @@ HWTEST_F_L0(JSAPIDequeTest, InsertFrontAndGetFront) JSHandle toor(thread, CreateDeque()); // test GetFront of empty deque - EXPECT_EQ(toor->GetFront(), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetFront(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()); JSAPIDeque::InsertFront(thread, toor, value); - EXPECT_EQ(toor->GetFront(), value.GetTaggedValue()); + EXPECT_EQ(toor->GetFront(thread), value.GetTaggedValue()); } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIDequeTest, InsertEndAndGetTail) @@ -77,17 +77,17 @@ HWTEST_F_L0(JSAPIDequeTest, InsertEndAndGetTail) JSHandle toor(thread, CreateDeque()); // test GetTail of empty deque - EXPECT_EQ(toor->GetTail(), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetTail(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()); JSAPIDeque::InsertEnd(thread, toor, value); - EXPECT_EQ(toor->GetTail(), value.GetTaggedValue()); + EXPECT_EQ(toor->GetTail(thread), value.GetTaggedValue()); } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIDequeTest, PopFirst) @@ -109,7 +109,7 @@ HWTEST_F_L0(JSAPIDequeTest, PopFirst) EXPECT_EQ(toor->PopFirst(thread), value.GetTaggedValue()); } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIDequeTest, PopLast) @@ -131,7 +131,7 @@ HWTEST_F_L0(JSAPIDequeTest, PopLast) EXPECT_EQ(toor->PopLast(thread), value.GetTaggedValue()); } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIDequeTest, GetOwnProperty) @@ -232,8 +232,8 @@ HWTEST_F_L0(JSAPIDequeTest, OwnKeys) EXPECT_TRUE(keyArray->GetClass()->IsTaggedArray()); EXPECT_TRUE(keyArray->GetLength() == elementsNums); for (uint32_t i = 0; i < elementsNums; i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(keyArray->Get(i).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), + EcmaString::Cast(keyArray->Get(thread, i).GetTaggedObject()))); } } } // namespace panda::test diff --git a/ecmascript/tests/js_api_hashmap_test.cpp b/ecmascript/tests/js_api_hashmap_test.cpp index 8de6dbac10..2200973f90 100644 --- a/ecmascript/tests/js_api_hashmap_test.cpp +++ b/ecmascript/tests/js_api_hashmap_test.cpp @@ -301,7 +301,7 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIteratorRBTreeTest) JSHandle valueStr = thread->GlobalConstants()->GetHandledValueString(); std::vector hashCollisionVector = {1013, 1015, 1021, 1023, 1045, 1047, 1053, 1055, 1077, 1079, 1085}; - JSHandle hashArray(thread, hashMap->GetTable()); + JSHandle hashArray(thread, hashMap->GetTable(thread)); hashArray = TaggedHashArray::Resize(thread, hashArray, NODE_NUMBERS); hashMap->SetTable(thread, hashArray); @@ -335,7 +335,7 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIteratorDiffNodeTest) JSHandle hashMap(thread, CreateHashMap()); JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); - JSHandle hashArray(thread, hashMap->GetTable()); + JSHandle hashArray(thread, hashMap->GetTable(thread)); hashArray = TaggedHashArray::Resize(thread, hashArray, NODE_NUMBERS); hashMap->SetTable(thread, hashArray); std::vector treeNumsVector = {1224, 1285, 1463, 4307, 5135, 5903, 6603, 6780, 8416, 9401, 9740}; @@ -364,7 +364,7 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIteratorDiffNodeTest) JSHandle hashmapIterator = factory->NewJSAPIHashMapIterator(hashMap, IterationKind::VALUE); int32_t count = 0; - while (!hashmapIterator->GetIteratedHashMap().IsUndefined()) { + while (!hashmapIterator->GetIteratedHashMap(thread).IsUndefined()) { auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(hashmapIterator.GetTaggedValue()); @@ -384,7 +384,7 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIteratorDiffNodeRandomlyTest) JSHandle hashMap(thread, CreateHashMap()); JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); - JSHandle hashArray(thread, hashMap->GetTable()); + JSHandle hashArray(thread, hashMap->GetTable(thread)); hashArray = TaggedHashArray::Resize(thread, hashArray, NODE_NUMBERS); hashMap->SetTable(thread, hashArray); std::vector treeNumsVector = {1224, 1285, 1463, 4307, 5135, 5903, 6603, 6780, 8416, 9401, 9740}; @@ -416,7 +416,7 @@ HWTEST_F_L0(JSAPIHashMapTest, JSAPIHashMapIteratorDiffNodeRandomlyTest) } JSHandle hashmapIterator = factory->NewJSAPIHashMapIterator(hashMap, IterationKind::VALUE); int32_t count = 0; - while (!hashmapIterator->GetIteratedHashMap().IsUndefined()) { + while (!hashmapIterator->GetIteratedHashMap(thread).IsUndefined()) { auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(hashmapIterator.GetTaggedValue()); diff --git a/ecmascript/tests/js_api_lightweightmap_test.cpp b/ecmascript/tests/js_api_lightweightmap_test.cpp index 239e1d4b1d..69d45601e2 100644 --- a/ecmascript/tests/js_api_lightweightmap_test.cpp +++ b/ecmascript/tests/js_api_lightweightmap_test.cpp @@ -70,7 +70,7 @@ protected: std::vector>& values) { JSHandle lwm(thread, CreateLightWeightMap()); - JSHandle valueArray(thread, JSTaggedValue(TaggedArray::Cast(lwm->GetValues().GetTaggedObject()))); + JSHandle valueArray(thread, JSTaggedValue(TaggedArray::Cast(lwm->GetValues(thread).GetTaggedObject()))); for (int i = 1; i <= 3; i++) { // 3: key value count; 1: start key JSHandle key(thread, JSTaggedValue(i)); diff --git a/ecmascript/tests/js_api_lightweightset_test.cpp b/ecmascript/tests/js_api_lightweightset_test.cpp index e981b5393e..51fee63963 100644 --- a/ecmascript/tests/js_api_lightweightset_test.cpp +++ b/ecmascript/tests/js_api_lightweightset_test.cpp @@ -63,7 +63,7 @@ HWTEST_F_L0(JSAPILightWeightSetTest, AddIncreaseCapacityAddAll) uint32_t tmp = NODE_NUMBERS * 2; // 2 means the value JSAPILightWeightSet::IncreaseCapacityTo(thread, lws, static_cast(tmp)); - uint32_t capacity = TaggedArray::Cast(lws->GetValues().GetTaggedObject())->GetLength(); + uint32_t capacity = TaggedArray::Cast(lws->GetValues(thread).GetTaggedObject())->GetLength(); EXPECT_EQ(JSTaggedValue(capacity), JSTaggedValue(tmp)); // test IncreaseCapacityTo exception @@ -191,9 +191,9 @@ HWTEST_F_L0(JSAPILightWeightSetTest, IsEmptyHasHasAll) } } EXPECT_EQ(hasAllLws->GetSize(), NODE_NUMBERS - 5); // 5 means the value - result = lws->HasAll(JSHandle::Cast(hasAllLws)); + result = lws->HasAll(thread, JSHandle::Cast(hasAllLws)); EXPECT_FALSE(result); - result = hasAllLws->HasAll(JSHandle::Cast(lws)); + result = hasAllLws->HasAll(thread, JSHandle::Cast(lws)); EXPECT_FALSE(result); } @@ -221,7 +221,7 @@ HWTEST_F_L0(JSAPILightWeightSetTest, GetIndexOfRemoveRemoveAtGetValueAt) EXPECT_EQ(index, 5); // 5 means the value // test GetValueAt - JSTaggedValue jsValue = lws->GetValueAt(5); // 5 means the value + JSTaggedValue jsValue = lws->GetValueAt(thread, 5); // 5 means the value EXPECT_EQ(value.GetTaggedValue(), jsValue); // test Remove @@ -292,21 +292,21 @@ HWTEST_F_L0(JSAPILightWeightSetTest, SpecialReturnTestEnsureCapacityGetValueAtGe } // test special return of EnsureCapacity - JSHandle array(thread, lws->GetValues()); + JSHandle array(thread, lws->GetValues(thread)); JSAPILightWeightSet::EnsureCapacity(thread, lws, 0); - JSHandle newArray(thread, lws->GetValues()); + JSHandle newArray(thread, lws->GetValues(thread)); EXPECT_TRUE(array->GetLength() == newArray->GetLength()); // test special return of GetValueAt - JSTaggedValue result1 = lws->GetValueAt(-1); + JSTaggedValue result1 = lws->GetValueAt(thread, -1); EXPECT_EQ(result1, JSTaggedValue::Undefined()); - JSTaggedValue result2 = lws->GetValueAt(static_cast(NODE_NUMBERS * 2)); + JSTaggedValue result2 = lws->GetValueAt(thread, static_cast(NODE_NUMBERS * 2)); EXPECT_EQ(result2, JSTaggedValue::Undefined()); // test special return of GetHashAt - JSTaggedValue result3 = lws->GetHashAt(-1); + JSTaggedValue result3 = lws->GetHashAt(thread, -1); EXPECT_EQ(result3, JSTaggedValue::Undefined()); - JSTaggedValue result4 = lws->GetHashAt(static_cast(NODE_NUMBERS * 2)); + JSTaggedValue result4 = lws->GetHashAt(thread, static_cast(NODE_NUMBERS * 2)); EXPECT_EQ(result4, JSTaggedValue::Undefined()); } @@ -327,17 +327,17 @@ HWTEST_F_L0(JSAPILightWeightSetTest, GetHashAtHasHash) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { hash.Update(JSTaggedValue(lws->Hash(thread, JSTaggedValue(i)))); int32_t index = lws->GetHashIndex(thread, hash, size); - JSTaggedValue getHash= lws->GetHashAt(index); + JSTaggedValue getHash= lws->GetHashAt(thread, index); EXPECT_EQ(getHash, hash.GetTaggedValue()); } // test HasHash for (uint32_t i = 0; i < NODE_NUMBERS; i++) { hash.Update(JSTaggedValue(lws->Hash(thread, JSTaggedValue(i)))); - EXPECT_TRUE(lws->HasHash(hash)); + EXPECT_TRUE(lws->HasHash(thread, hash)); } hash.Update(JSTaggedValue(lws->Hash(thread, JSTaggedValue(NODE_NUMBERS)))); - EXPECT_FALSE(lws->HasHash(hash)); + EXPECT_FALSE(lws->HasHash(thread, hash)); } HWTEST_F_L0(JSAPILightWeightSetTest, ToString) diff --git a/ecmascript/tests/js_api_linked_list_iterator_test.cpp b/ecmascript/tests/js_api_linked_list_iterator_test.cpp index 5596657616..406b323913 100644 --- a/ecmascript/tests/js_api_linked_list_iterator_test.cpp +++ b/ecmascript/tests/js_api_linked_list_iterator_test.cpp @@ -62,7 +62,7 @@ HWTEST_F_L0(JSAPILinkedListIteratorTest, NextCreateLinkedListIterator) JSHandle linkedListIterator( thread, JSAPILinkedListIterator::CreateLinkedListIterator(thread, taggedValueHandle).GetTaggedValue()); JSHandle valueStr = thread->GlobalConstants()->GetHandledValueString(); - uint32_t capacity = static_cast(linkedList->Length()); + uint32_t capacity = static_cast(linkedList->Length(thread)); for (uint32_t i = 0; i < capacity; i++) { auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); @@ -78,7 +78,7 @@ HWTEST_F_L0(JSAPILinkedListIteratorTest, NextCreateLinkedListIterator) EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue(i)); } else { - EXPECT_EQ(linkedListIterator->GetIteratedLinkedList(), JSTaggedValue::Undefined()); + EXPECT_EQ(linkedListIterator->GetIteratedLinkedList(thread), JSTaggedValue::Undefined()); EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue::Undefined()); } diff --git a/ecmascript/tests/js_api_linked_list_test.cpp b/ecmascript/tests/js_api_linked_list_test.cpp index 5300ea1592..07fccb0e18 100644 --- a/ecmascript/tests/js_api_linked_list_test.cpp +++ b/ecmascript/tests/js_api_linked_list_test.cpp @@ -63,7 +63,7 @@ HWTEST_F_L0(JSAPILinkedListTest, AddAndHas) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSAPILinkedList::Add(thread, toor, value); } - EXPECT_EQ(toor->Length(), NODE_NUMBERS); + EXPECT_EQ(toor->Length(thread), NODE_NUMBERS); EcmaTestCommon::ListAddHasCommon(thread, toor, value, myValue, NODE_NUMBERS) ; } @@ -73,13 +73,13 @@ HWTEST_F_L0(JSAPILinkedListTest, AddFirstAndGetFirst) JSHandle value(thread, JSTaggedValue(1)); JSHandle list(thread, CreateLinkedList()); list->Add(thread, list, value); - EXPECT_EQ(list->Length(), 1); - EXPECT_EQ(list->Get(0).GetInt(), 1); + EXPECT_EQ(list->Length(thread), 1); + EXPECT_EQ(list->Get(thread, 0).GetInt(), 1); JSHandle value1(thread, JSTaggedValue(2)); list->AddFirst(thread, list, value1); - EXPECT_EQ(list->Length(), 2); - EXPECT_EQ(list->GetFirst().GetInt(), 2); + EXPECT_EQ(list->Length(thread), 2); + EXPECT_EQ(list->GetFirst(thread).GetInt(), 2); } HWTEST_F_L0(JSAPILinkedListTest, InsertAndGetLast) @@ -103,35 +103,35 @@ HWTEST_F_L0(JSAPILinkedListTest, Remove) EXPECT_EQ(JSAPILinkedList::RemoveFirst(thread, toor), JSTaggedValue(0)); value.Update(JSTaggedValue(0)); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 19); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 19); EXPECT_EQ(JSAPILinkedList::RemoveLast(thread, toor), JSTaggedValue(19)); value.Update(JSTaggedValue(19)); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 18); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 18); value.Update(JSTaggedValue(5)); EXPECT_EQ(JSAPILinkedList::RemoveByIndex(thread, toor, 4), value.GetTaggedValue()); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 17); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 17); value.Update(JSTaggedValue(8)); EXPECT_EQ(toor->Remove(thread, value.GetTaggedValue()), JSTaggedValue::True()); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 16); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 16); value.Update(JSTaggedValue(11)); EXPECT_EQ(JSAPILinkedList::RemoveFirstFound(thread, toor, value.GetTaggedValue()), JSTaggedValue::True()); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 15); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 15); value.Update(JSTaggedValue(14)); EXPECT_EQ(JSAPILinkedList::RemoveLastFound(thread, toor, value.GetTaggedValue()), JSTaggedValue::True()); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 14); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 14); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPILinkedListTest, SpecialReturnOfRemove) @@ -148,7 +148,7 @@ HWTEST_F_L0(JSAPILinkedListTest, SpecialReturnOfRemove) EXPECT_EXCEPTION(); // test Remove and RemoveLastFound linkedlist whose nodeLength less than 0 - JSHandle doubleList(thread, linkedList->GetDoubleList()); + JSHandle doubleList(thread, linkedList->GetDoubleList(thread)); doubleList->SetNumberOfNodes(thread, -1); EXPECT_EQ(linkedList->Remove(thread, value.GetTaggedValue()), JSTaggedValue::False()); @@ -169,8 +169,8 @@ HWTEST_F_L0(JSAPILinkedListTest, Clear) list->Clear(thread); - EXPECT_EQ(list->Length(), 0); - EXPECT_TRUE(list->GetFirst().IsUndefined()); + EXPECT_EQ(list->Length(thread), 0); + EXPECT_TRUE(list->GetFirst(thread).IsUndefined()); } HWTEST_F_L0(JSAPILinkedListTest, Set) @@ -188,7 +188,7 @@ HWTEST_F_L0(JSAPILinkedListTest, Set) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { value.Update(JSTaggedValue(i + 1)); - JSTaggedValue gValue = toor->Get(i); + JSTaggedValue gValue = toor->Get(thread, i); EXPECT_EQ(gValue, value.GetTaggedValue()); } } @@ -281,9 +281,9 @@ HWTEST_F_L0(JSAPILinkedListTest, Clone) JSHandle cloneList = JSAPILinkedList::Clone(thread, list); for (uint32_t i = 0; i < elementsNums; i++) { - EXPECT_EQ(cloneList->Get(i), list->Get(i)); + EXPECT_EQ(cloneList->Get(thread, i), list->Get(thread, i)); } - EXPECT_EQ(list->Length(), cloneList->Length()); + EXPECT_EQ(list->Length(thread), cloneList->Length(thread)); } HWTEST_F_L0(JSAPILinkedListTest, OwnKeys) @@ -298,8 +298,8 @@ HWTEST_F_L0(JSAPILinkedListTest, OwnKeys) EXPECT_TRUE(keyArray->GetClass()->IsTaggedArray()); EXPECT_TRUE(keyArray->GetLength() == elementsNums); for (uint32_t i = 0; i < elementsNums; i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(keyArray->Get(i).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), + EcmaString::Cast(keyArray->Get(thread, i).GetTaggedObject()))); } } } // namespace panda::test diff --git a/ecmascript/tests/js_api_list_iterator_test.cpp b/ecmascript/tests/js_api_list_iterator_test.cpp index 91125ad6bc..5a5407f825 100644 --- a/ecmascript/tests/js_api_list_iterator_test.cpp +++ b/ecmascript/tests/js_api_list_iterator_test.cpp @@ -62,7 +62,7 @@ HWTEST_F_L0(JSAPIListIteratorTest, NextCreateListIterator) JSHandle listIterator( thread, JSAPIListIterator::CreateListIterator(thread, taggedValueHandle).GetTaggedValue()); JSHandle valueStr = thread->GlobalConstants()->GetHandledValueString(); - uint32_t capacity = static_cast(list->Length()); + uint32_t capacity = static_cast(list->Length(thread)); for (uint32_t i = 0; i < capacity; i++) { auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); @@ -78,7 +78,7 @@ HWTEST_F_L0(JSAPIListIteratorTest, NextCreateListIterator) EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue(i)); } else { - EXPECT_EQ(listIterator->GetIteratedList(), JSTaggedValue::Undefined()); + EXPECT_EQ(listIterator->GetIteratedList(thread), JSTaggedValue::Undefined()); EXPECT_EQ((JSObject::GetProperty(thread, resultObj, valueStr).GetValue()).GetTaggedValue(), JSTaggedValue::Undefined()); } diff --git a/ecmascript/tests/js_api_list_test.cpp b/ecmascript/tests/js_api_list_test.cpp index 3aaae07d2b..1dcf88cafc 100644 --- a/ecmascript/tests/js_api_list_test.cpp +++ b/ecmascript/tests/js_api_list_test.cpp @@ -57,7 +57,7 @@ HWTEST_F_L0(JSAPIListTest, AddHasAndIsEmpty) JSHandle toor(thread, CreateList()); - EXPECT_TRUE(toor->IsEmpty()); + EXPECT_TRUE(toor->IsEmpty(thread)); std::string myValue("myvalue"); for (int i = 0; i < NODE_NUMBERS; i++) { @@ -65,11 +65,11 @@ HWTEST_F_L0(JSAPIListTest, AddHasAndIsEmpty) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSAPIList::Add(thread, toor, value); } - EXPECT_EQ(toor->Length(), NODE_NUMBERS); - EXPECT_FALSE(toor->IsEmpty()); + EXPECT_EQ(toor->Length(thread), NODE_NUMBERS); + EXPECT_FALSE(toor->IsEmpty(thread)); EcmaTestCommon::ListAddHasCommon(thread, toor, value, myValue, NODE_NUMBERS); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIListTest, InsertAndGetLastAndGetFirst) @@ -92,15 +92,15 @@ HWTEST_F_L0(JSAPIListTest, Remove) value.Update(JSTaggedValue(4)); EXPECT_EQ(JSAPIList::RemoveByIndex(thread, toor, 4), value.GetTaggedValue()); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 19); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 19); value.Update(JSTaggedValue(8)); EXPECT_EQ(toor->Remove(thread, value.GetTaggedValue()), JSTaggedValue::True()); - EXPECT_EQ(toor->Has(value.GetTaggedValue()), false); - EXPECT_EQ(toor->Length(), 18); + EXPECT_EQ(toor->Has(thread, value.GetTaggedValue()), false); + EXPECT_EQ(toor->Length(thread), 18); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIListTest, Clear) @@ -114,8 +114,8 @@ HWTEST_F_L0(JSAPIListTest, Clear) list->Clear(thread); - EXPECT_EQ(list->Length(), 0); - EXPECT_TRUE(list->GetFirst().IsUndefined()); + EXPECT_EQ(list->Length(thread), 0); + EXPECT_TRUE(list->GetFirst(thread).IsUndefined()); } HWTEST_F_L0(JSAPIListTest, Set) @@ -132,7 +132,7 @@ HWTEST_F_L0(JSAPIListTest, Set) for (uint32_t i = 0; i < NODE_NUMBERS; i++) { value.Update(JSTaggedValue(i + 1)); - JSTaggedValue gValue = toor->Get(i); + JSTaggedValue gValue = toor->Get(thread, i); EXPECT_EQ(gValue, value.GetTaggedValue()); } } @@ -230,7 +230,7 @@ HWTEST_F_L0(JSAPIListTest, GetSubList) // throw error test uint32_t smallIndex = -1; - uint32_t bigIndex = List->Length() + 10; + uint32_t bigIndex = List->Length(thread) + 10; uint32_t zeroIndex = 0; // fromIndex < 0 @@ -266,8 +266,8 @@ HWTEST_F_L0(JSAPIListTest, OwnKeys) EXPECT_TRUE(keyArray->GetClass()->IsTaggedArray()); EXPECT_TRUE(keyArray->GetLength() == elementsNums); for (uint32_t i = 0; i < elementsNums; i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(keyArray->Get(i).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), + EcmaString::Cast(keyArray->Get(thread, i).GetTaggedObject()))); } } } // namespace panda::test diff --git a/ecmascript/tests/js_api_plain_array_test.cpp b/ecmascript/tests/js_api_plain_array_test.cpp index e085ef43a9..6878c3001d 100644 --- a/ecmascript/tests/js_api_plain_array_test.cpp +++ b/ecmascript/tests/js_api_plain_array_test.cpp @@ -114,11 +114,11 @@ HWTEST_F_L0(JSAPIPlainArrayTest, PA_AddAndGetKeyAtAndClear) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); // test getKeyAt - JSTaggedValue gvalue = array->GetKeyAt(i); + JSTaggedValue gvalue = array->GetKeyAt(thread, i); EXPECT_EQ(gvalue, key.GetTaggedValue()); } - EXPECT_EQ(array->GetKeyAt(-1), JSTaggedValue::Undefined()); - EXPECT_EQ(array->GetKeyAt(NODE_NUMBERS), JSTaggedValue::Undefined()); + EXPECT_EQ(array->GetKeyAt(thread, -1), JSTaggedValue::Undefined()); + EXPECT_EQ(array->GetKeyAt(thread, NODE_NUMBERS), JSTaggedValue::Undefined()); // test clear array->Clear(thread); EXPECT_EQ(array->GetSize(), 0); // 0 means the value @@ -152,14 +152,14 @@ HWTEST_F_L0(JSAPIPlainArrayTest, PA_CloneAndHasAndGet) // test has key.Update(JSTaggedValue(103)); // 103 means the value int32_t lkey = 103; - bool result = array->Has(lkey); + bool result = array->Has(thread, lkey); EXPECT_TRUE(result); - EXPECT_FALSE(array->Has(lkey * 2)); + EXPECT_FALSE(array->Has(thread, lkey * 2)); // test get myValue = std::string("myvalue3"); value.Update(factory->NewFromStdString(myValue).GetTaggedValue()); - EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, array->Get(key.GetTaggedValue())), value)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, array->Get(thread, key.GetTaggedValue())), value)); } HWTEST_F_L0(JSAPIPlainArrayTest, PA_GetIndexOfKeyAndGeIndexOfValueAndIsEmptyAndRemoveRangeFrom) @@ -169,16 +169,16 @@ HWTEST_F_L0(JSAPIPlainArrayTest, PA_GetIndexOfKeyAndGeIndexOfValueAndIsEmptyAndR auto array = GetIndexOfKeyAndGeIndexOfValueGetArray(value, NODE_NUMBERS); value.Update(JSTaggedValue(103)); // 103 means the value int32_t lvalue = 103; - JSTaggedValue value2 = array->GetIndexOfKey(lvalue); + JSTaggedValue value2 = array->GetIndexOfKey(thread, lvalue); EXPECT_EQ(value2.GetNumber(), 3); // 3 means the value - EXPECT_EQ(array->GetIndexOfKey(lvalue * 2), JSTaggedValue(-1)); + EXPECT_EQ(array->GetIndexOfKey(thread, lvalue * 2), JSTaggedValue(-1)); std::string myValue = "myvalue2"; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); value.Update(factory->NewFromStdString(myValue).GetTaggedValue()); - JSTaggedValue value3 = array->GetIndexOfValue(value.GetTaggedValue()); + JSTaggedValue value3 = array->GetIndexOfValue(thread, value.GetTaggedValue()); EXPECT_EQ(value3.GetNumber(), 2); // 2 means the value - EXPECT_EQ(array->GetIndexOfValue(JSTaggedValue(0)), JSTaggedValue(-1)); + EXPECT_EQ(array->GetIndexOfValue(thread, JSTaggedValue(0)), JSTaggedValue(-1)); value.Update(JSTaggedValue(1)); int32_t batchSize = 3; // 3 means the value diff --git a/ecmascript/tests/js_api_queue_iterator_test.cpp b/ecmascript/tests/js_api_queue_iterator_test.cpp index 0f764d0e86..dca4a03c23 100644 --- a/ecmascript/tests/js_api_queue_iterator_test.cpp +++ b/ecmascript/tests/js_api_queue_iterator_test.cpp @@ -68,11 +68,11 @@ HWTEST_F_L0(JSAPIQueueIteratorTest, Next) if (i <= DEFAULT_LENGTH - 1U) { value.Update(factory->NewFromStdString(resultValue).GetTaggedValue()); EXPECT_EQ(queueIterator->GetNextIndex(), i + 1U); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, valueStr).GetValue(), value), true); } else { - EXPECT_TRUE(queueIterator->GetIteratedQueue().IsUndefined()); + EXPECT_TRUE(queueIterator->GetIteratedQueue(thread).IsUndefined()); EXPECT_TRUE(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()->IsUndefined()); } } @@ -148,10 +148,10 @@ HWTEST_F_L0(JSAPIQueueIteratorTest, SetIteratedQueue) JSAPIQueue::Add(thread, jsQueue2, value); } JSHandle queueIterator = factory->NewJSAPIQueueIterator(jsQueue1); - EXPECT_EQ(queueIterator->GetIteratedQueue(), jsQueue1.GetTaggedValue()); + EXPECT_EQ(queueIterator->GetIteratedQueue(thread), jsQueue1.GetTaggedValue()); queueIterator->SetIteratedQueue(thread, jsQueue2.GetTaggedValue()); - EXPECT_EQ(queueIterator->GetIteratedQueue(), jsQueue2.GetTaggedValue()); + EXPECT_EQ(queueIterator->GetIteratedQueue(thread), jsQueue2.GetTaggedValue()); } /** diff --git a/ecmascript/tests/js_api_queue_test.cpp b/ecmascript/tests/js_api_queue_test.cpp index f8c39c1a71..e217d84c1d 100644 --- a/ecmascript/tests/js_api_queue_test.cpp +++ b/ecmascript/tests/js_api_queue_test.cpp @@ -53,17 +53,17 @@ HWTEST_F_L0(JSAPIQueueTest, AddAndHasAndSetAndGet) JSMutableHandle value(thread, JSTaggedValue::Undefined()); std::string queueValue("queuevalue"); JSHandle jsQueue = TestCommon(value, queueValue, DEFAULT_LENGTH); - EXPECT_EQ(jsQueue->GetSize(), DEFAULT_LENGTH); + EXPECT_EQ(jsQueue->GetSize(thread), DEFAULT_LENGTH); EXPECT_EQ(JSAPIQueue::GetArrayLength(thread, jsQueue), DEFAULT_LENGTH); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // test Set, Has and Get std::string ivalue = queueValue + std::to_string(10); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); - EXPECT_FALSE(jsQueue->Has(value.GetTaggedValue())); + EXPECT_FALSE(jsQueue->Has(thread, value.GetTaggedValue())); jsQueue->Set(thread, 0, value.GetTaggedValue()); EXPECT_EQ(jsQueue->Get(thread, 0), value.GetTaggedValue()); - EXPECT_TRUE(jsQueue->Has(value.GetTaggedValue())); + EXPECT_TRUE(jsQueue->Has(thread, value.GetTaggedValue())); // test Get exception JSTaggedValue result = jsQueue->Get(thread, DEFAULT_LENGTH); @@ -93,13 +93,13 @@ HWTEST_F_L0(JSAPIQueueTest, PopFirstAndGetFirst) EXPECT_EQ(JSAPIQueue::GetArrayLength(thread, jsQueue), DEFAULT_LENGTH); std::string firstValue = queueValue + std::to_string(0U); value.Update(factory->NewFromStdString(firstValue).GetTaggedValue()); - EXPECT_TRUE(JSTaggedValue::SameValue( + EXPECT_TRUE(JSTaggedValue::SameValue(thread, JSHandle(thread, JSAPIQueue::GetFirst(thread, jsQueue)), value)); // test Pop for (uint32_t i = 0; i < DEFAULT_LENGTH; i++) { std::string ivalue = queueValue + std::to_string(i); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); - EXPECT_TRUE(JSTaggedValue::SameValue( + EXPECT_TRUE(JSTaggedValue::SameValue(thread, JSHandle(thread, JSAPIQueue::Pop(thread, jsQueue)), value)); EXPECT_EQ(JSAPIQueue::GetArrayLength(thread, jsQueue), (DEFAULT_LENGTH - i - 1U)); } @@ -116,8 +116,8 @@ HWTEST_F_L0(JSAPIQueueTest, OwnKeys) JSHandle arrayKey = JSAPIQueue::OwnKeys(thread, jsQueue); EXPECT_EQ(arrayKey->GetLength(), DEFAULT_LENGTH); for (int32_t i = 0; i < static_cast(DEFAULT_LENGTH); i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(arrayKey->Get(i).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), + EcmaString::Cast(arrayKey->Get(thread, i).GetTaggedObject()))); } } @@ -129,12 +129,12 @@ HWTEST_F_L0(JSAPIQueueTest, GetNextPosition) std::string queueValue("queuevalue"); JSHandle jsQueue = TestCommon(value, queueValue, DEFAULT_LENGTH); // test GetNextPosition - EXPECT_EQ(jsQueue->GetSize(), DEFAULT_LENGTH); + EXPECT_EQ(jsQueue->GetSize(thread), DEFAULT_LENGTH); for (uint32_t i = 0; i < DEFAULT_LENGTH;) { std::string ivalue = queueValue + std::to_string(i); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); EXPECT_EQ(jsQueue->Get(thread, i), value.GetTaggedValue()); - i = jsQueue->GetNextPosition(i); + i = jsQueue->GetNextPosition(thread, i); } } @@ -217,10 +217,10 @@ HWTEST_F_L0(JSAPIQueueTest, GrowCapacity) { JSHandle jsQueue = CreateQueue(0); JSHandle value(thread, JSTaggedValue(0)); - JSHandle element(thread, jsQueue->GetElements()); + JSHandle element(thread, jsQueue->GetElements(thread)); EXPECT_EQ(element->GetLength(), 0U); JSAPIQueue::Add(thread, jsQueue, value); - JSHandle newElement(thread, jsQueue->GetElements()); + JSHandle newElement(thread, jsQueue->GetElements(thread)); EXPECT_EQ(newElement->GetLength(), static_cast(JSAPIQueue::DEFAULT_CAPACITY_LENGTH)); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_api_stack_iterator_test.cpp b/ecmascript/tests/js_api_stack_iterator_test.cpp index c5709408a7..920ded7117 100644 --- a/ecmascript/tests/js_api_stack_iterator_test.cpp +++ b/ecmascript/tests/js_api_stack_iterator_test.cpp @@ -69,7 +69,7 @@ HWTEST_F_L0(JSAPIStackIteratorTest, Next) EXPECT_TRUE(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()->IsString()); } else { - EXPECT_TRUE(stackIterator->GetIteratedStack().IsUndefined()); + EXPECT_TRUE(stackIterator->GetIteratedStack(thread).IsUndefined()); EXPECT_TRUE(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()->IsUndefined()); } } @@ -144,16 +144,16 @@ HWTEST_F_L0(JSAPIStackIteratorTest, SetIteratedStack) JSAPIStack::Push(thread, jsStack2, value); } JSHandle stackIterator = factory->NewJSAPIStackIterator(jsStack1); - EXPECT_EQ(stackIterator->GetIteratedStack(), jsStack1.GetTaggedValue()); + EXPECT_EQ(stackIterator->GetIteratedStack(thread), jsStack1.GetTaggedValue()); stackIterator->SetIteratedStack(thread, jsStack2.GetTaggedValue()); - JSHandle jsAPIStackTo(thread, JSAPIStack::Cast(stackIterator->GetIteratedStack().GetTaggedObject())); + JSHandle jsAPIStackTo(thread, JSAPIStack::Cast(stackIterator->GetIteratedStack(thread).GetTaggedObject())); EXPECT_EQ(jsAPIStackTo->GetSize(), static_cast(DEFAULT_LENGTH - 1U)); for (uint32_t i = 0; i < DEFAULT_LENGTH; i++) { std::string ivalue = stackValue + std::to_string(i + 2U); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); - EXPECT_EQ(jsAPIStackTo->Search(value), static_cast(i)); + EXPECT_EQ(jsAPIStackTo->Search(thread, value), static_cast(i)); } } diff --git a/ecmascript/tests/js_api_stack_test.cpp b/ecmascript/tests/js_api_stack_test.cpp index 42e582dc3e..1c4a8a9eab 100644 --- a/ecmascript/tests/js_api_stack_test.cpp +++ b/ecmascript/tests/js_api_stack_test.cpp @@ -53,9 +53,9 @@ protected: JSTaggedValue result = JSAPIStack::Push(thread, toor, value); EXPECT_EQ(result, value.GetTaggedValue()); if (search) { - EXPECT_EQ(toor->Search(value), static_cast(i)); + EXPECT_EQ(toor->Search(thread, value), static_cast(i)); } else { - EXPECT_EQ(toor->Peek(), value.GetTaggedValue()); + EXPECT_EQ(toor->Peek(thread), value.GetTaggedValue()); EXPECT_EQ(toor->Empty(), false); } } @@ -78,7 +78,7 @@ HWTEST_F_L0(JSAPIStackTest, PushAndPeek) JSHandle toor(thread, CreateStack()); // test Peek empty - EXPECT_EQ(toor->Peek(), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->Peek(thread), JSTaggedValue::Undefined()); std::string myValue("myvalue"); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { @@ -86,11 +86,11 @@ HWTEST_F_L0(JSAPIStackTest, PushAndPeek) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSTaggedValue result = JSAPIStack::Push(thread, toor, value); EXPECT_EQ(result, value.GetTaggedValue()); - EXPECT_EQ(toor->Peek(), value.GetTaggedValue()); + EXPECT_EQ(toor->Peek(thread), value.GetTaggedValue()); } EXPECT_EQ(static_cast(toor->GetTop() + 1), NODE_NUMBERS); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIStackTest, Pop) @@ -110,7 +110,7 @@ HWTEST_F_L0(JSAPIStackTest, Pop) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSTaggedValue result = JSAPIStack::Push(thread, toor, value); EXPECT_EQ(result, value.GetTaggedValue()); - EXPECT_EQ(toor->Peek(), value.GetTaggedValue()); + EXPECT_EQ(toor->Peek(thread), value.GetTaggedValue()); } for (uint32_t i = NODE_NUMBERS; i >= 1; i--) { @@ -120,7 +120,7 @@ HWTEST_F_L0(JSAPIStackTest, Pop) EXPECT_EQ(gValue, value.GetTaggedValue()); } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIStackTest, Empty) @@ -141,7 +141,7 @@ HWTEST_F_L0(JSAPIStackTest, Empty) } } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIStackTest, Search) @@ -152,9 +152,9 @@ HWTEST_F_L0(JSAPIStackTest, Search) std::string myValue("myvalue"); auto toor = SearchAndEmptyCommon(value, myValue, NODE_NUMBERS, true); value.Update(factory->NewFromStdString(myValue).GetTaggedValue()); - EXPECT_EQ(toor->Search(value), -1); + EXPECT_EQ(toor->Search(thread, value), -1); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIStackTest, GetOwnProperty) @@ -261,7 +261,7 @@ HWTEST_F_L0(JSAPIStackTest, Has) JSHandle toor(thread, CreateStack()); // test Has empty - EXPECT_FALSE(toor->Has(JSTaggedValue(0))); + EXPECT_FALSE(toor->Has(thread, JSTaggedValue(0))); uint32_t elementsNums = 8; for (uint32_t i = 0; i < elementsNums; i++) { @@ -269,9 +269,9 @@ HWTEST_F_L0(JSAPIStackTest, Has) JSAPIStack::Push(thread, toor, value); } for (uint32_t i = 0; i < elementsNums; i++) { - EXPECT_TRUE(toor->Has(JSTaggedValue(i))); + EXPECT_TRUE(toor->Has(thread, JSTaggedValue(i))); } - EXPECT_FALSE(toor->Has(JSTaggedValue(elementsNums))); + EXPECT_FALSE(toor->Has(thread, JSTaggedValue(elementsNums))); } /** @@ -292,8 +292,8 @@ HWTEST_F_L0(JSAPIStackTest, OwnKeys) EXPECT_TRUE(keyArray->GetClass()->IsTaggedArray()); EXPECT_TRUE(keyArray->GetLength() == elementsNums); for (uint32_t i = 0; i < elementsNums; i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(*(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(keyArray->Get(i).GetTaggedObject()))); + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), + EcmaString::Cast(keyArray->Get(thread, i).GetTaggedObject()))); } } } // namespace panda::test diff --git a/ecmascript/tests/js_api_tree_map_iterator_test.cpp b/ecmascript/tests/js_api_tree_map_iterator_test.cpp index bea4b5bef5..75b881d3fe 100644 --- a/ecmascript/tests/js_api_tree_map_iterator_test.cpp +++ b/ecmascript/tests/js_api_tree_map_iterator_test.cpp @@ -98,8 +98,8 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, SetIteratedMap) JSAPITreeMap::Set(thread, jsTreeMap, key, value); } treeMapIterator->SetIteratedMap(thread, jsTreeMap.GetTaggedValue()); - JSHandle treeMapTo(thread, JSAPITreeMap::Cast(treeMapIterator->GetIteratedMap().GetTaggedObject())); - EXPECT_EQ(treeMapTo->GetSize(), static_cast(DEFAULT_LENGTH)); + JSHandle treeMapTo(thread, JSAPITreeMap::Cast(treeMapIterator->GetIteratedMap(thread).GetTaggedObject())); + EXPECT_EQ(treeMapTo->GetSize(thread), static_cast(DEFAULT_LENGTH)); for (uint32_t i = 0; i < DEFAULT_LENGTH; i++) { std::string ikey = mapKey + std::to_string(i); std::string ivalue = mapValue + std::to_string(i + 2U); @@ -195,7 +195,7 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, KEY_Next) JSHandle resultObj(thread, result); std::string resultKey = mapKey + std::to_string(i); keyValue[0].Update(factory->NewFromStdString(resultKey).GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, valueStr).GetValue(), keyValue[0]), true); EXPECT_EQ(treeMapKeyIterator->GetNextIndex(), (i + 1U)); } @@ -229,7 +229,7 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, VALUE_Next) JSHandle resultObj(thread, result); std::string resultKey = mapValue + std::to_string(i + 1U); keyValue[1].Update(factory->NewFromStdString(resultKey).GetTaggedValue()); // 1 : value index - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, valueStr).GetValue(), keyValue[1]), true); // 1 : value index EXPECT_EQ(treeMapKeyIterator->GetNextIndex(), (i + 1U)); } @@ -272,7 +272,7 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, KEY_AND_VALUE_Next) JSHandle keyValueArr(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()); for (int index = 0; index < 2; index++) { JSHandle indexValue(thread, JSTaggedValue(index)); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, keyValueArr, indexValue).GetValue(), value), true); resultKeyAndValue = mapValue + std::to_string(i + 2U); value.Update(factory->NewFromStdString(resultKeyAndValue).GetTaggedValue()); diff --git a/ecmascript/tests/js_api_tree_map_test.cpp b/ecmascript/tests/js_api_tree_map_test.cpp index 0f15aec699..7817e6beed 100644 --- a/ecmascript/tests/js_api_tree_map_test.cpp +++ b/ecmascript/tests/js_api_tree_map_test.cpp @@ -65,7 +65,7 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapSetAndGet) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSAPITreeMap::Set(thread, tmap, key, value); } - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS); // test Set exception key.Update(JSTaggedValue::Hole()); @@ -103,14 +103,14 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapDeleteAndHas) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSAPITreeMap::Set(thread, tmap, key, value); } - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS); for (int i = 0; i < REMOVE_SIZE; i++) { std::string ikey = myKey + std::to_string(i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); [[maybe_unused]] JSTaggedValue dvalue = JSAPITreeMap::Delete(thread, tmap, key); } - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS - REMOVE_SIZE); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS - REMOVE_SIZE); for (int i = 0; i < REMOVE_SIZE; i++) { std::string ikey = myKey + std::to_string(i); @@ -157,7 +157,7 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapReplaceAndClear) value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSAPITreeMap::Set(thread, tmap, key, value); } - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS); for (int i = 0; i < NODE_NUMBERS / 2; i++) { std::string ikey = myKey + std::to_string(i); @@ -208,7 +208,7 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapReplaceAndClear) } JSAPITreeMap::Clear(thread, tmap); - EXPECT_EQ(tmap->GetSize(), 0); + EXPECT_EQ(tmap->GetSize(thread), 0); for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); std::string ivalue = myValue + std::to_string(i); @@ -305,17 +305,17 @@ HWTEST_F_L0(JSAPITreeMapTest, TreeMapGetKeyAndGetValue) } JSAPITreeMap::Set(thread, tmap, key, value); } - EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tmap->GetSize(thread), NODE_NUMBERS); // test GetKey and GetValue for (int i = 0; i < NODE_NUMBERS; i++) { - EXPECT_EQ(tmap->GetKey(i), JSTaggedValue(i)); + EXPECT_EQ(tmap->GetKey(thread, i), JSTaggedValue(i)); if (i == NODE_NUMBERS / 2) { - EXPECT_EQ(tmap->GetValue(i), JSTaggedValue::Undefined()); + EXPECT_EQ(tmap->GetValue(thread, i), JSTaggedValue::Undefined()); } else { - EXPECT_EQ(tmap->GetValue(i), JSTaggedValue(i)); + EXPECT_EQ(tmap->GetValue(thread, i), JSTaggedValue(i)); } } - EXPECT_EQ(tmap->GetKey(-1), JSTaggedValue::Undefined()); + EXPECT_EQ(tmap->GetKey(thread, -1), JSTaggedValue::Undefined()); } } // namespace panda::test diff --git a/ecmascript/tests/js_api_tree_set_iterator_test.cpp b/ecmascript/tests/js_api_tree_set_iterator_test.cpp index b72c1c81a8..c08ad1ac46 100644 --- a/ecmascript/tests/js_api_tree_set_iterator_test.cpp +++ b/ecmascript/tests/js_api_tree_set_iterator_test.cpp @@ -84,8 +84,8 @@ HWTEST_F_L0(JSAPITreeSetIteratorTest, SetIteratedSet) JSAPITreeSet::Add(thread, jsTreeSet, key); } treeSetIterator->SetIteratedSet(thread, jsTreeSet.GetTaggedValue()); - JSHandle treeSetTo(thread, JSAPITreeSet::Cast(treeSetIterator->GetIteratedSet().GetTaggedObject())); - EXPECT_EQ(treeSetTo->GetSize(), static_cast(DEFAULT_LENGTH)); + JSHandle treeSetTo(thread, JSAPITreeSet::Cast(treeSetIterator->GetIteratedSet(thread).GetTaggedObject())); + EXPECT_EQ(treeSetTo->GetSize(thread), static_cast(DEFAULT_LENGTH)); for (uint32_t i = 0; i < DEFAULT_LENGTH; i++) { std::string ikey = setKey + std::to_string(i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); @@ -179,7 +179,7 @@ HWTEST_F_L0(JSAPITreeSetIteratorTest, KEY_Next) JSHandle resultObj(thread, result); std::string resultKey = setKey + std::to_string(i); key.Update(factory->NewFromStdString(resultKey).GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, valueStr).GetValue(), key), true); EXPECT_EQ(treeSetIterator->GetNextIndex(), (i + 1U)); } @@ -257,7 +257,7 @@ HWTEST_F_L0(JSAPITreeSetIteratorTest, KEY_AND_VALUE_Next) JSHandle keyValueArr(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()); for (int index = 0; index < 2; index++) { JSHandle indexValue(thread, JSTaggedValue(index)); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, keyValueArr, indexValue).GetValue(), key), true); } EXPECT_EQ(treeSetIterator->GetNextIndex(), (i + 1U)); diff --git a/ecmascript/tests/js_api_tree_set_test.cpp b/ecmascript/tests/js_api_tree_set_test.cpp index 29dab6e4ef..0de2fd7c7d 100644 --- a/ecmascript/tests/js_api_tree_set_test.cpp +++ b/ecmascript/tests/js_api_tree_set_test.cpp @@ -56,7 +56,7 @@ protected: key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); JSAPITreeSet::Add(thread, tset, key); } - EXPECT_EQ(tset->GetSize(), nums); + EXPECT_EQ(tset->GetSize(thread), nums); return tset; } }; @@ -117,7 +117,7 @@ HWTEST_F_L0(JSAPITreeSetTest, TreeSetDeleteAndHas) bool success = JSAPITreeSet::Delete(thread, tset, key); EXPECT_EQ(success, true); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - REMOVE_SIZE); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - REMOVE_SIZE); for (int i = 0; i < REMOVE_SIZE; i++) { std::string ikey = myKey + std::to_string(i); @@ -149,7 +149,7 @@ HWTEST_F_L0(JSAPITreeSetTest, TreeSetClear) auto tset = TestCommon(key, myKey, NODE_NUMBERS); JSAPITreeSet::Clear(thread, tset); - EXPECT_EQ(tset->GetSize(), 0); + EXPECT_EQ(tset->GetSize(thread), 0); for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); @@ -181,13 +181,13 @@ HWTEST_F_L0(JSAPITreeSetTest, TreeSetPop) key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); JSAPITreeSet::Add(thread, tset, key); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS); // test popFirst std::string fkey = myKey + std::to_string(0); key.Update(factory->NewFromStdString(fkey).GetTaggedValue()); JSTaggedValue fvalue = JSAPITreeSet::PopFirst(thread, tset); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - 1); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - 1); EXPECT_EQ(fvalue, key.GetTaggedValue()); bool has = JSAPITreeSet::Has(thread, tset, key); EXPECT_EQ(has, false); @@ -196,7 +196,7 @@ HWTEST_F_L0(JSAPITreeSetTest, TreeSetPop) std::string lkey = myKey + std::to_string(NODE_NUMBERS - 1); key.Update(factory->NewFromStdString(lkey).GetTaggedValue()); JSTaggedValue lvalue = JSAPITreeSet::PopLast(thread, tset); - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - 2); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS - 2); EXPECT_EQ(lvalue, key.GetTaggedValue()); has = JSAPITreeSet::Has(thread, tset, key); EXPECT_EQ(has, false); @@ -272,12 +272,12 @@ HWTEST_F_L0(JSAPITreeSetTest, TreeSetGetKey) key.Update(JSTaggedValue(i)); JSAPITreeSet::Add(thread, tset, key); } - EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); + EXPECT_EQ(tset->GetSize(thread), NODE_NUMBERS); // test GetKey for (int i = 0; i < NODE_NUMBERS; i++) { - EXPECT_EQ(tset->GetKey(i), JSTaggedValue(i)); + EXPECT_EQ(tset->GetKey(thread, i), JSTaggedValue(i)); } - EXPECT_EQ(tset->GetKey(-1), JSTaggedValue::Undefined()); + EXPECT_EQ(tset->GetKey(thread, -1), JSTaggedValue::Undefined()); } } // namespace panda::test diff --git a/ecmascript/tests/js_api_vector_iterator_test.cpp b/ecmascript/tests/js_api_vector_iterator_test.cpp index d811680cdd..84ca1d93bb 100644 --- a/ecmascript/tests/js_api_vector_iterator_test.cpp +++ b/ecmascript/tests/js_api_vector_iterator_test.cpp @@ -77,7 +77,8 @@ HWTEST_F_L0(JSAPIVectorIteratorTest, SetIteratedVector) JSAPIVector::Add(thread, jsVector, value); } vectorIterator->SetIteratedVector(thread, jsVector.GetTaggedValue()); - JSHandle VectorTo(thread, JSAPIVector::Cast(vectorIterator->GetIteratedVector().GetTaggedObject())); + JSHandle VectorTo(thread, + JSAPIVector::Cast(vectorIterator->GetIteratedVector(thread).GetTaggedObject())); EXPECT_EQ(VectorTo->GetSize(), static_cast(DEFAULT_LENGTH)); for (uint32_t i = 0; i < DEFAULT_LENGTH; i++) { std::string ivalue = vectorValue + std::to_string(i); @@ -143,11 +144,11 @@ HWTEST_F_L0(JSAPIVectorIteratorTest, Next) std::string resultValue = vectorValue + std::to_string(i); if (i <= DEFAULT_LENGTH - 1U) { value.Update(factory->NewFromStdString(resultValue).GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, resultObj, valueStr).GetValue(), value), true); } else { - EXPECT_TRUE(vectorIterator->GetIteratedVector().IsUndefined()); + EXPECT_TRUE(vectorIterator->GetIteratedVector(thread).IsUndefined()); EXPECT_TRUE(JSObject::GetProperty(thread, resultObj, valueStr).GetValue()->IsUndefined()); } } diff --git a/ecmascript/tests/js_api_vector_test.cpp b/ecmascript/tests/js_api_vector_test.cpp index d5e11c7972..68de99e216 100644 --- a/ecmascript/tests/js_api_vector_test.cpp +++ b/ecmascript/tests/js_api_vector_test.cpp @@ -78,7 +78,7 @@ HWTEST_F_L0(JSAPIVectorTest, AddGetHas) // test Has of empty vector value.Update(JSTaggedValue(NODE_NUMBERS)); - EXPECT_FALSE(toor->Has(value.GetTaggedValue())); + EXPECT_FALSE(toor->Has(thread, value.GetTaggedValue())); std::string myValue("myvalue"); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { @@ -87,10 +87,10 @@ HWTEST_F_L0(JSAPIVectorTest, AddGetHas) bool result = JSAPIVector::Add(thread, toor, value); EXPECT_TRUE(result); EXPECT_EQ(JSAPIVector::Get(thread, toor, i), value.GetTaggedValue()); - EXPECT_TRUE(toor->Has(value.GetTaggedValue())); + EXPECT_TRUE(toor->Has(thread, value.GetTaggedValue())); } value.Update(JSTaggedValue(NODE_NUMBERS)); - EXPECT_FALSE(toor->Has(value.GetTaggedValue())); + EXPECT_FALSE(toor->Has(thread, value.GetTaggedValue())); EXPECT_EQ(static_cast(toor->GetSize()), NODE_NUMBERS); // test Get exception @@ -99,7 +99,7 @@ HWTEST_F_L0(JSAPIVectorTest, AddGetHas) JSAPIVector::Get(thread, toor, static_cast(NODE_NUMBERS)); EXPECT_EXCEPTION(); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIVectorTest, RemoveByIndexAndRemove) @@ -128,7 +128,7 @@ HWTEST_F_L0(JSAPIVectorTest, RemoveByIndexAndRemove) EXPECT_EQ(result1, JSTaggedValue::Exception()); EXPECT_EXCEPTION(); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIVectorTest, RemoveByRangeAndGetHeapUsedSize) @@ -157,7 +157,7 @@ HWTEST_F_L0(JSAPIVectorTest, ClearAndisEmpty) JSAPIVector::Clear(thread, toor); EXPECT_EQ(toor->IsEmpty(), true); - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIVectorTest, GetIndexOf) @@ -177,7 +177,7 @@ HWTEST_F_L0(JSAPIVectorTest, GetIndexOf) EXPECT_EQ(JSAPIVector::GetIndexOf(thread, toor, value), static_cast(i)); } - toor->Dump(); + toor->Dump(thread); } HWTEST_F_L0(JSAPIVectorTest, GetOwnProperty) @@ -279,10 +279,10 @@ HWTEST_F_L0(JSAPIVectorTest, IncreaseCapacityToTrimToCurrentLength) JSAPIVector::Add(thread, toor, value); } JSAPIVector::IncreaseCapacityTo(thread, toor, 80); - JSHandle elementData(thread, toor->GetElements()); + JSHandle elementData(thread, toor->GetElements(thread)); EXPECT_EQ(static_cast(elementData->GetLength()), 80); JSAPIVector::TrimToCurrentLength(thread, toor); - JSHandle newElementData(thread, toor->GetElements()); + JSHandle newElementData(thread, toor->GetElements(thread)); EXPECT_EQ(newElementData->GetLength(), elementsNums); // test IncreaseCapacityTo exception @@ -332,7 +332,7 @@ HWTEST_F_L0(JSAPIVectorTest, SetLengthGetIndexFromGetLastElementGetLastIndexOf) JSHandle toor(thread, CreateVector()); // test GetLastElement of empty vector - EXPECT_EQ(toor->GetLastElement(), JSTaggedValue::Undefined()); + EXPECT_EQ(toor->GetLastElement(thread), JSTaggedValue::Undefined()); // test GetLastIndexOf of empty vector uint32_t elementsNums = 20; @@ -351,7 +351,7 @@ HWTEST_F_L0(JSAPIVectorTest, SetLengthGetIndexFromGetLastElementGetLastIndexOf) EXPECT_EXCEPTION(); // test GetLastElement - EXPECT_EQ(toor->GetLastElement(), JSTaggedValue(elementsNums - 1)); + EXPECT_EQ(toor->GetLastElement(thread), JSTaggedValue(elementsNums - 1)); // test GetLastIndexOf EXPECT_EQ(JSAPIVector::GetLastIndexOf(thread, toor, obj), static_cast(elementsNums - 1)); @@ -458,9 +458,9 @@ HWTEST_F_L0(JSAPIVectorTest, OwnKeys) EXPECT_TRUE(keyArray->GetClass()->IsTaggedArray()); EXPECT_TRUE(keyArray->GetLength() == elementsNums); for (uint32_t i = 0; i < elementsNums; i++) { - ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual( + ASSERT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(base::NumberHelper::NumberToString(thread, JSTaggedValue(i))), - EcmaString::Cast(keyArray->Get(i).GetTaggedObject()) + EcmaString::Cast(keyArray->Get(thread, i).GetTaggedObject()) )); } } @@ -474,13 +474,13 @@ HWTEST_F_L0(JSAPIVectorTest, OwnKeys) HWTEST_F_L0(JSAPIVectorTest, GetFirstElement) { JSHandle toor(thread, CreateVector()); - EXPECT_EQ(JSAPIVector::GetFirstElement(toor), JSTaggedValue::Undefined()); + EXPECT_EQ(JSAPIVector::GetFirstElement(thread, toor), JSTaggedValue::Undefined()); uint32_t elementsNums = 8; for (uint32_t i = 0; i < elementsNums; i++) { JSHandle value(thread, JSTaggedValue(i)); JSAPIVector::Add(thread, toor, value); } - EXPECT_EQ(JSAPIVector::GetFirstElement(toor), JSTaggedValue(0)); + EXPECT_EQ(JSAPIVector::GetFirstElement(thread, toor), JSTaggedValue(0)); } } // namespace panda::test diff --git a/ecmascript/tests/js_arguments_test.cpp b/ecmascript/tests/js_arguments_test.cpp index 4567f87704..b169176d58 100644 --- a/ecmascript/tests/js_arguments_test.cpp +++ b/ecmascript/tests/js_arguments_test.cpp @@ -135,7 +135,7 @@ HWTEST_F_L0(JsArgumentsTest, GetOwnProperty) PropertyDescriptor Desc(thread); JSHandle caller = thread->GetEcmaVM()->GetFactory()->NewFromASCII("caller"); // key is not caller - EXPECT_FALSE(JSTaggedValue::SameValue(key.GetTaggedValue(), caller.GetTaggedValue())); + EXPECT_FALSE(JSTaggedValue::SameValue(thread, key.GetTaggedValue(), caller.GetTaggedValue())); EXPECT_TRUE(JSArguments::GetOwnProperty(thread, JSHandle(jsarg), key, Desc)); EXPECT_EQ(Desc.GetValue()->GetInt(), 1); } diff --git a/ecmascript/tests/js_array_buffer_test.cpp b/ecmascript/tests/js_array_buffer_test.cpp index 24431beb9c..c9933082cc 100644 --- a/ecmascript/tests/js_array_buffer_test.cpp +++ b/ecmascript/tests/js_array_buffer_test.cpp @@ -86,13 +86,13 @@ HWTEST_F_L0(JsArrayBufferTest, Attach_Detach_IsDetach) JSHandle arrBuf = factory->NewJSArrayBuffer(5); arrBuf->Attach(thread, length + 1, JSHandle::Cast(nativePointer).GetTaggedValue()); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 6U); - EXPECT_EQ(arrBuf->GetArrayBufferData().GetRawData(), + EXPECT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), JSHandle::Cast(nativePointer).GetTaggedValue().GetRawData()); arrBuf->Detach(thread); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 0U); - EXPECT_EQ(arrBuf->GetArrayBufferData().GetRawData(), JSTaggedValue::Null().GetRawData()); - EXPECT_TRUE(arrBuf->IsDetach()); + EXPECT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), JSTaggedValue::Null().GetRawData()); + EXPECT_TRUE(arrBuf->IsDetach(thread)); vm->GetNativeAreaAllocator()->FreeBuffer(buffer); vm->GetNativeAreaAllocator()->FreeBuffer(data); } diff --git a/ecmascript/tests/js_array_iterator_test.cpp b/ecmascript/tests/js_array_iterator_test.cpp index 9fd2f23f25..5592eeec30 100644 --- a/ecmascript/tests/js_array_iterator_test.cpp +++ b/ecmascript/tests/js_array_iterator_test.cpp @@ -57,7 +57,7 @@ HWTEST_F_L0(JSArrayIteratorTest, SetIteratedArray) JSHandle handleJSArrayIter = factory->NewJSArrayIterator(handleJSObjectTaggedArrayFrom1, IterationKind::KEY); - JSHandle handleJSArrayTo1(thread, JSArray::Cast(handleJSArrayIter->GetIteratedArray().GetTaggedObject())); + JSHandle handleJSArrayTo1(thread, JSArray::Cast(handleJSArrayIter->GetIteratedArray(thread).GetTaggedObject())); EXPECT_EQ(handleJSArrayTo1->GetArrayLength(), static_cast(numArrayFrom1)); for (int i = 0; i < numArrayFrom1; i++) { EXPECT_EQ(JSArray::FastGetPropertyByValue(thread, JSHandle(handleJSArrayTo1), i)->GetNumber(), @@ -67,7 +67,7 @@ HWTEST_F_L0(JSArrayIteratorTest, SetIteratedArray) // Call "SetIteratedArray" function in this HWTEST_F_L0. handleJSArrayIter->SetIteratedArray(thread, handleJSObjectTaggedArrayFrom2); - JSHandle handleJSArrayTo2(thread, JSArray::Cast(handleJSArrayIter->GetIteratedArray().GetTaggedObject())); + JSHandle handleJSArrayTo2(thread, JSArray::Cast(handleJSArrayIter->GetIteratedArray(thread).GetTaggedObject())); EXPECT_EQ(handleJSArrayTo2->GetArrayLength(), static_cast(numArrayFrom2)); for (int i = 0; i < numArrayFrom2; i++) { EXPECT_EQ(JSArray::FastGetPropertyByValue(thread, JSHandle(handleJSArrayTo2), i)->GetNumber(), diff --git a/ecmascript/tests/js_array_test.cpp b/ecmascript/tests/js_array_test.cpp index 4652b282f6..65b73f7a51 100644 --- a/ecmascript/tests/js_array_test.cpp +++ b/ecmascript/tests/js_array_test.cpp @@ -178,30 +178,30 @@ HWTEST_F_L0(JSArrayTest, COWArray) JSHandle cloneArray = factory->CloneArrayLiteral(array); for (int i = 0; i < 5; i++) { - JSTaggedValue value1 = TaggedArray::Cast(cloneArray->GetElements().GetTaggedObject())->Get(i); - JSTaggedValue value2 = TaggedArray::Cast(array->GetElements().GetTaggedObject())->Get(i); + JSTaggedValue value1 = TaggedArray::Cast(cloneArray->GetElements(thread).GetTaggedObject())->Get(thread, i); + JSTaggedValue value2 = TaggedArray::Cast(array->GetElements(thread).GetTaggedObject())->Get(thread, i); EXPECT_EQ(value1.GetRawData(), value2.GetRawData()); } #if defined ENABLE_COW_ARRAY // Elements array is shared to use the same array. - EXPECT_EQ(cloneArray->GetElements().GetTaggedObject(), array->GetElements().GetTaggedObject()); + EXPECT_EQ(cloneArray->GetElements(thread).GetTaggedObject(), array->GetElements(thread).GetTaggedObject()); #endif JSHandle lengthKeyHandle(thread->GlobalConstants()->GetHandledLengthString()); // Change the value and the elements will not be shared. JSArray::FastSetPropertyByValue(thread, JSHandle(cloneArray), 0, lengthKeyHandle); - EXPECT_TRUE(TaggedArray::Cast(cloneArray->GetElements().GetTaggedObject())->Get(0) != - TaggedArray::Cast(array->GetElements().GetTaggedObject())->Get(0)); + EXPECT_TRUE(TaggedArray::Cast(cloneArray->GetElements(thread).GetTaggedObject())->Get(thread, 0) != + TaggedArray::Cast(array->GetElements(thread).GetTaggedObject())->Get(thread, 0)); #if defined ENABLE_COW_ARRAY - EXPECT_TRUE(cloneArray->GetElements().GetTaggedObject() != array->GetElements().GetTaggedObject()); + EXPECT_TRUE(cloneArray->GetElements(thread).GetTaggedObject() != array->GetElements(thread).GetTaggedObject()); #endif for (int i = 1; i < 5; i++) { - JSTaggedValue value1 = TaggedArray::Cast(cloneArray->GetElements().GetTaggedObject())->Get(i); - JSTaggedValue value2 = TaggedArray::Cast(array->GetElements().GetTaggedObject())->Get(i); + JSTaggedValue value1 = TaggedArray::Cast(cloneArray->GetElements(thread).GetTaggedObject())->Get(thread, i); + JSTaggedValue value2 = TaggedArray::Cast(array->GetElements(thread).GetTaggedObject())->Get(thread, i); EXPECT_EQ(value1.GetRawData(), value2.GetRawData()); } } @@ -229,7 +229,7 @@ HWTEST_F_L0(JSArrayTest, TrackInfo) auto floatHandle = JSHandle(thread, JSTaggedValue(10.1)); ASSERT_TRUE(JSHClass::TransitToElementsKind(thread, obj, floatHandle, ElementsKind::NONE)); auto numberHClass = JSTaggedValue(thread->GetArrayInstanceHClass(ElementsKind::NUMBER, false)); - ASSERT_EQ(trackInfo->GetCachedHClass(), numberHClass); + ASSERT_EQ(trackInfo->GetCachedHClass(thread), numberHClass); ASSERT_EQ(trackInfo->GetElementsKind(), ElementsKind::NUMBER); } } // namespace panda::test diff --git a/ecmascript/tests/js_async_function_test.cpp b/ecmascript/tests/js_async_function_test.cpp index 8ef96631f9..ba736cbd2d 100644 --- a/ecmascript/tests/js_async_function_test.cpp +++ b/ecmascript/tests/js_async_function_test.cpp @@ -38,17 +38,17 @@ HWTEST_F_L0(JSAsyncFunctionTest, SetAsyncContext) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle asyncFuncObj = factory->NewJSAsyncFuncObject(); - JSHandle asyncFuncObjVal(thread, asyncFuncObj->GetGeneratorContext()); + JSHandle asyncFuncObjVal(thread, asyncFuncObj->GetGeneratorContext(thread)); JSHandle fulFunc = factory->NewJSAsyncAwaitStatusFunction(MethodIndex::BUILTINS_PROMISE_HANDLER_ASYNC_AWAIT_FULFILLED); fulFunc->SetAsyncContext(thread, asyncFuncObjVal); - EXPECT_EQ(JSTaggedValue::SameValue(fulFunc->GetAsyncContext(), asyncFuncObjVal.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, fulFunc->GetAsyncContext(thread), 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); + rejFunc->SetAsyncContext(thread, asyncFuncObj->GetGeneratorContext(thread)); + EXPECT_EQ(JSTaggedValue::SameValue(thread, rejFunc->GetAsyncContext(thread), asyncFuncObjVal.GetTaggedValue()), true); } /** @@ -69,8 +69,8 @@ HWTEST_F_L0(JSAsyncFunctionTest, AsyncFunctionAwait) // check AsyncPromise queue and queue cannot execute auto microJobQueue = thread->GetEcmaVM()->GetMicroJobQueue(); - EXPECT_FALSE(microJobQueue->GetPromiseJobQueue().IsUndefined()); + EXPECT_FALSE(microJobQueue->GetPromiseJobQueue(thread).IsUndefined()); // promiese is undefined. - EXPECT_TRUE(asyncFuncObj->GetPromise().IsUndefined()); + EXPECT_TRUE(asyncFuncObj->GetPromise(thread).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 93e2af01d2..23968c813e 100644 --- a/ecmascript/tests/js_bigint_test.cpp +++ b/ecmascript/tests/js_bigint_test.cpp @@ -280,34 +280,34 @@ HWTEST_F_L0(JSBigintTest, ToString_ToStdString) JSHandle bigint2 = BigIntHelper::SetBigInt(thread, bigintStdStr2, BigInt::DECIMAL); JSHandle bigintEcmaStrBin1 = BigInt::ToString(thread, bigint1, BigInt::BINARY); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrBin1).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrBin1).ToCString(thread).c_str(), "111111111111111111111111111111111111111111111111111111"); JSHandle bigintEcmaStrOct1 = BigInt::ToString(thread, bigint1, BigInt::OCTAL); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrOct1).ToCString().c_str(), "777777777777777777"); + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrOct1).ToCString(thread).c_str(), "777777777777777777"); JSHandle bigintEcmaStrDec1 = BigInt::ToString(thread, bigint1, BigInt::DECIMAL); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrDec1).ToCString().c_str(), "18014398509481983"); + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrDec1).ToCString(thread).c_str(), "18014398509481983"); JSHandle bigintEcmaStrHex1 = BigInt::ToString(thread, bigint1, BigInt::HEXADECIMAL); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrHex1).ToCString().c_str(), "3fffffffffffff"); + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrHex1).ToCString(thread).c_str(), "3fffffffffffff"); JSHandle bigintEcmaStrBin2 = BigInt::ToString(thread, bigint2, BigInt::BINARY); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrBin2).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrBin2).ToCString(thread).c_str(), "1000100100010000100001111010010110001011011000001110010110001"); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrBin2).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrBin2).ToCString(thread).c_str(), (bigint2->ToStdString(BigInt::BINARY)).c_str()); JSHandle bigintEcmaStrOct2 = BigInt::ToString(thread, bigint2, BigInt::OCTAL); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrOct2).ToCString().c_str(), "104420417226133016261"); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrOct2).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrOct2).ToCString(thread).c_str(), "104420417226133016261"); + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrOct2).ToCString(thread).c_str(), (bigint2->ToStdString(BigInt::OCTAL)).c_str()); JSHandle bigintEcmaStrDec2 = BigInt::ToString(thread, bigint2, BigInt::DECIMAL); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrDec2).ToCString().c_str(), "1234567890987654321"); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrDec2).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrDec2).ToCString(thread).c_str(), "1234567890987654321"); + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrDec2).ToCString(thread).c_str(), (bigint2->ToStdString(BigInt::DECIMAL)).c_str()); JSHandle bigintEcmaStrHex2 = BigInt::ToString(thread, bigint2, BigInt::HEXADECIMAL); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrHex2).ToCString().c_str(), "112210f4b16c1cb1"); - EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrHex2).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrHex2).ToCString(thread).c_str(), "112210f4b16c1cb1"); + EXPECT_STREQ(EcmaStringAccessor(bigintEcmaStrHex2).ToCString(thread).c_str(), (bigint2->ToStdString(BigInt::HEXADECIMAL)).c_str()); } diff --git a/ecmascript/tests/js_collator_test.cpp b/ecmascript/tests/js_collator_test.cpp index 8760a325cc..d7963e1e60 100644 --- a/ecmascript/tests/js_collator_test.cpp +++ b/ecmascript/tests/js_collator_test.cpp @@ -49,7 +49,7 @@ HWTEST_F_L0(JSCollatorTest, GetIcuCollatorAndCompare) icuCollator->setStrength(icu::Collator::PRIMARY); // Call "SetIcuCollator" function set icu collator JSCollator::SetIcuCollator(thread, collator, icuCollator, JSCollator::FreeIcuCollator); - icu::Collator *icuCollator1 = collator->GetIcuCollator(); + icu::Collator *icuCollator1 = collator->GetIcuCollator(thread); EXPECT_TRUE(icuCollator1 == icuCollator); JSTaggedValue result = JSCollator::CompareStrings(thread, icuCollator1, string1, string2); EXPECT_EQ(result.GetInt(), 0); // equivalent @@ -60,7 +60,7 @@ HWTEST_F_L0(JSCollatorTest, GetIcuCollatorAndCompare) icuCollator = icu::Collator::createInstance(zhLocale, status); icuCollator->setStrength(icu::Collator::PRIMARY); JSCollator::SetIcuCollator(thread, collator, icuCollator, JSCollator::FreeIcuCollator); - icu::Collator *icuCollator2 = collator->GetIcuCollator(); + icu::Collator *icuCollator2 = collator->GetIcuCollator(thread); EXPECT_TRUE(icuCollator2 == icuCollator); result = JSCollator::CompareStrings(thread, icuCollator2, string1, string2); EXPECT_EQ(result.GetInt(), 0); // equivalent @@ -84,17 +84,17 @@ HWTEST_F_L0(JSCollatorTest, InitializeCollatorAndGetIcuCollator) JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); JSHandle initCollator = JSCollator::InitializeCollator(thread, collator, localeStr, undefinedHandle); - EXPECT_EQ(JSTaggedValue::SameValue(collator.GetTaggedValue(), initCollator.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, collator.GetTaggedValue(), initCollator.GetTaggedValue()), true); // check attributes - EXPECT_TRUE(initCollator->GetBoundCompare().IsUndefined()); + EXPECT_TRUE(initCollator->GetBoundCompare(thread).IsUndefined()); EXPECT_EQ(initCollator->GetIgnorePunctuation(), false); EXPECT_EQ(initCollator->GetSensitivity(), SensitivityOption::VARIANT); EXPECT_EQ(initCollator->GetCaseFirst(), CaseFirstOption::UNDEFINED); - EXPECT_TRUE(initCollator->GetCollation().IsUndefined()); + EXPECT_TRUE(initCollator->GetCollation(thread).IsUndefined()); EXPECT_EQ(initCollator->GetUsage(), UsageOption::SORT); - EXPECT_TRUE(JSTaggedValue::SameValue(JSHandle(thread, initCollator->GetLocale()), localeStr)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, JSHandle(thread, initCollator->GetLocale(thread)), localeStr)); // check icucollator - icu::Collator *icuCollator = initCollator->GetIcuCollator(); + icu::Collator *icuCollator = initCollator->GetIcuCollator(thread); EXPECT_EQ(icuCollator->getStrength(), icu::Collator::TERTIARY); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_dataview_test.cpp b/ecmascript/tests/js_dataview_test.cpp index 2228c9cf96..992c5968ab 100644 --- a/ecmascript/tests/js_dataview_test.cpp +++ b/ecmascript/tests/js_dataview_test.cpp @@ -97,13 +97,13 @@ HWTEST_F_L0(JSDataViewTest, SetDataView) // Call "SetDataView" function through "NewJSDataView" function of "object_factory.cpp" JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf, offsetDataView, lengthDataView); - EXPECT_TRUE(handleDataView->GetDataView().IsTrue()); + EXPECT_TRUE(handleDataView->GetDataView(thread).IsTrue()); // Call "SetDataView" function in this HWTEST_F_L0. handleDataView->SetDataView(thread, JSTaggedValue::False()); - EXPECT_TRUE(handleDataView->GetDataView().IsFalse()); + EXPECT_TRUE(handleDataView->GetDataView(thread).IsFalse()); handleDataView->SetDataView(thread, JSTaggedValue::True()); - EXPECT_TRUE(handleDataView->GetDataView().IsTrue()); + EXPECT_TRUE(handleDataView->GetDataView(thread).IsTrue()); } /* @@ -136,13 +136,13 @@ HWTEST_F_L0(JSDataViewTest, SetViewedArrayBuffer) JSHandle handleDataView = factory->NewJSDataView(handleArrayBuf1, offsetDataView, lengthDataView); JSHandle handleTagValDataViewFrom1(thread, handleArrayBuf1.GetTaggedValue()); - JSHandle handleTagValDataViewTo1(thread, handleDataView->GetViewedArrayBuffer()); + JSHandle handleTagValDataViewTo1(thread, handleDataView->GetViewedArrayBuffer(thread)); EXPECT_TRUE(JSTaggedValue::Equal(thread, handleTagValDataViewFrom1, handleTagValDataViewTo1)); // Call "SetViewedArrayBuffer" function in this HWTEST_F_L0. handleDataView->SetViewedArrayBuffer(thread, handleArrayBuf2.GetTaggedValue()); JSHandle handleTagValDataViewFrom2(thread, handleArrayBuf2.GetTaggedValue()); - JSHandle handleTagValDataViewTo2(thread, handleDataView->GetViewedArrayBuffer()); + JSHandle handleTagValDataViewTo2(thread, handleDataView->GetViewedArrayBuffer(thread)); EXPECT_TRUE(JSTaggedValue::Equal(thread, handleTagValDataViewFrom2, handleTagValDataViewTo2)); EXPECT_FALSE(JSTaggedValue::Equal(thread, handleTagValDataViewFrom1, handleTagValDataViewFrom2)); } diff --git a/ecmascript/tests/js_date_test.cpp b/ecmascript/tests/js_date_test.cpp index b6f113fb36..d7e8ea1334 100644 --- a/ecmascript/tests/js_date_test.cpp +++ b/ecmascript/tests/js_date_test.cpp @@ -41,13 +41,13 @@ HWTEST_F_L0(JSDateTest, Create) { double tm = 0.0; JSHandle jsDate(thread, JSDateCreate(thread)); - EXPECT_EQ(jsDate->GetTimeValue(), JSTaggedValue(tm)); - EXPECT_EQ(jsDate->GetLocalOffset(), JSTaggedValue(JSDate::MAX_DOUBLE)); + EXPECT_EQ(jsDate->GetTimeValue(thread), JSTaggedValue(tm)); + EXPECT_EQ(jsDate->GetLocalOffset(thread), JSTaggedValue(JSDate::MAX_DOUBLE)); tm = 28 * 60 * 60 * 1000; jsDate->SetTimeValue(thread, JSTaggedValue(tm)); - [[maybe_unused]] double temp = jsDate->GetTimeValue().GetDouble(); - EXPECT_EQ(jsDate->GetTimeValue(), JSTaggedValue(tm)); + [[maybe_unused]] double temp = jsDate->GetTimeValue(thread).GetDouble(); + EXPECT_EQ(jsDate->GetTimeValue(thread), JSTaggedValue(tm)); } HWTEST_F_L0(JSDateTest, MakeTime) diff --git a/ecmascript/tests/js_date_time_format_first_test.cpp b/ecmascript/tests/js_date_time_format_first_test.cpp index 81b4847f6a..288a2a5aa4 100644 --- a/ecmascript/tests/js_date_time_format_first_test.cpp +++ b/ecmascript/tests/js_date_time_format_first_test.cpp @@ -47,12 +47,12 @@ HWTEST_F_L0(JSDateTimeFormatTest, Set_Get_IcuLocale) icu::Locale locale1("ko", "Kore", "KR"); JSDateTimeFormat::SetIcuLocale(thread, dtf, locale1, JSDateTimeFormat::FreeIcuLocale); - icu::Locale *resLocale1 = dtf->GetIcuLocale(); + icu::Locale *resLocale1 = dtf->GetIcuLocale(thread); EXPECT_STREQ(resLocale1->getBaseName(), "ko_Kore_KR"); icu::Locale locale2("zh", "Hans", "Cn"); JSDateTimeFormat::SetIcuLocale(thread, dtf, locale2, JSDateTimeFormat::FreeIcuLocale); - icu::Locale *resLocale2 = dtf->GetIcuLocale(); + icu::Locale *resLocale2 = dtf->GetIcuLocale(thread); EXPECT_STREQ(resLocale2->getBaseName(), "zh_Hans_CN"); } @@ -81,7 +81,7 @@ HWTEST_F_L0(JSDateTimeFormatTest, Set_Get_IcuSimpleDateFormat) icu::UnicodeString pattern("yyyy.MM.dd HH:mm:ss"); icu::SimpleDateFormat sdf(pattern, status); JSDateTimeFormat::SetIcuSimpleDateFormat(thread, dtf, sdf, JSDateTimeFormat::FreeSimpleDateFormat); - icu::SimpleDateFormat *resSdf = dtf->GetIcuSimpleDateFormat(); + icu::SimpleDateFormat *resSdf = dtf->GetIcuSimpleDateFormat(thread); UDate timeStamp = resSdf->parse(dateTime1, status); EXPECT_EQ(timeStamp, 1653448174000); status = UErrorCode::U_ZERO_ERROR; @@ -95,7 +95,7 @@ HWTEST_F_L0(JSDateTimeFormatTest, Set_Get_IcuSimpleDateFormat) icu::UnicodeString pattern2("yyyyy.MMMMM.dd GGG hh:mm::ss aaa"); icu::SimpleDateFormat sdf2(pattern2, status); JSDateTimeFormat::SetIcuSimpleDateFormat(thread, dtf, sdf2, JSDateTimeFormat::FreeSimpleDateFormat); - icu::SimpleDateFormat *resSdf2 = dtf->GetIcuSimpleDateFormat(); + icu::SimpleDateFormat *resSdf2 = dtf->GetIcuSimpleDateFormat(thread); timeStamp = resSdf2->parse(dateTime1, status); EXPECT_EQ(timeStamp, 0); status = UErrorCode::U_ZERO_ERROR; @@ -136,9 +136,9 @@ HWTEST_F_L0(JSDateTimeFormatTest, InitializeDateTimeFormat) dtf = JSDateTimeFormat::InitializeDateTimeFormat( thread, dtf, JSHandle::Cast(locales), JSHandle::Cast(options)); - JSHandle localeTagVal(thread, dtf->GetLocale()); + JSHandle localeTagVal(thread, dtf->GetLocale(thread)); JSHandle localeEcmaStr = JSHandle::Cast(localeTagVal); - std::string localeStr = LocaleHelper::ConvertToStdString(localeEcmaStr); + std::string localeStr = LocaleHelper::ConvertToStdString(thread, localeEcmaStr); EXPECT_STREQ(localeStr.c_str(), "zh-Hans-CN-u-ca-chinese"); } @@ -169,17 +169,17 @@ HWTEST_F_L0(JSDateTimeFormatTest, ToDateTimeOptions_001) options = JSDateTimeFormat::ToDateTimeOptions( thread, JSHandle::Cast(options), RequiredOption::ANY, DefaultsOption::ALL); // test "ALL" auto yearEcmaStr = JSHandle::Cast(JSObject::GetProperty(thread, options, yearKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(yearEcmaStr).c_str(), "numeric"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, yearEcmaStr).c_str(), "numeric"); auto monthEcmaStr = JSHandle::Cast(JSObject::GetProperty(thread, options, monthKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(monthEcmaStr).c_str(), "numeric"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, monthEcmaStr).c_str(), "numeric"); auto dayEcmaStr = JSHandle::Cast(JSObject::GetProperty(thread, options, dayKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dayEcmaStr).c_str(), "numeric"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dayEcmaStr).c_str(), "numeric"); auto hourEcmaStr = JSHandle::Cast(JSObject::GetProperty(thread, options, hourKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(hourEcmaStr).c_str(), "numeric"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, hourEcmaStr).c_str(), "numeric"); auto minuteEcmaStr = JSHandle::Cast(JSObject::GetProperty(thread, options, minuteKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(minuteEcmaStr).c_str(), "numeric"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, minuteEcmaStr).c_str(), "numeric"); auto secondEcmaStr = JSHandle::Cast(JSObject::GetProperty(thread, options, secondKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(secondEcmaStr).c_str(), "numeric"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, secondEcmaStr).c_str(), "numeric"); } HWTEST_F_L0(JSDateTimeFormatTest, ToDateTimeOptions_002) @@ -220,24 +220,24 @@ HWTEST_F_L0(JSDateTimeFormatTest, ToDateTimeOptions_002) options = JSDateTimeFormat::ToDateTimeOptions( thread, JSHandle::Cast(options), RequiredOption::ANY, DefaultsOption::ALL); // test "ANY" auto weekdayStr = JSHandle::Cast(JSObject::GetProperty(thread, options, weekdayKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(weekdayStr).c_str(), "narrow"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, weekdayStr).c_str(), "narrow"); auto yearStr = JSHandle::Cast(JSObject::GetProperty(thread, options, yearKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(yearStr).c_str(), "2-digit"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, yearStr).c_str(), "2-digit"); auto monthStr = JSHandle::Cast(JSObject::GetProperty(thread, options, monthKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(monthStr).c_str(), "2-digit"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, monthStr).c_str(), "2-digit"); auto dayStr = JSHandle::Cast(JSObject::GetProperty(thread, options, dayKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dayStr).c_str(), "2-digit"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dayStr).c_str(), "2-digit"); auto dayPeriodStr = JSHandle::Cast(JSObject::GetProperty(thread, options, dayPeriodKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dayPeriodStr).c_str(), "narrow"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dayPeriodStr).c_str(), "narrow"); auto hourStr = JSHandle::Cast(JSObject::GetProperty(thread, options, hourKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(hourStr).c_str(), "2-digit"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, hourStr).c_str(), "2-digit"); auto minuteStr = JSHandle::Cast(JSObject::GetProperty(thread, options, minuteKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(minuteStr).c_str(), "2-digit"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, minuteStr).c_str(), "2-digit"); auto secondStr = JSHandle::Cast(JSObject::GetProperty(thread, options, secondKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(secondStr).c_str(), "2-digit"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, secondStr).c_str(), "2-digit"); auto fracSecStr = JSHandle::Cast(JSObject::GetProperty(thread, options, fracSecKey).GetValue()); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(fracSecStr).c_str(), "1"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, fracSecStr).c_str(), "1"); } @@ -261,8 +261,8 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_001) // When the option is blank, the default format is "yyyy/MM/dd", the year, month and day are all numeric, // because the default option in initialization is "DefaultsOption::DATE". JSHandle dateTimeEcamStr1 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp1); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr1).c_str(), "2022/5/25"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr1).c_str(), "2022/5/25"); JSHandle dateTimeEcamStr2 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp2); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr2).c_str(), "2022/5/30"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr2).c_str(), "2022/5/30"); } } // namespace panda::test diff --git a/ecmascript/tests/js_date_time_format_second_test.cpp b/ecmascript/tests/js_date_time_format_second_test.cpp index 91b3b4098a..098765d636 100644 --- a/ecmascript/tests/js_date_time_format_second_test.cpp +++ b/ecmascript/tests/js_date_time_format_second_test.cpp @@ -55,9 +55,9 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_002) // Format to include all options by "DefaultsOption::ALL". JSHandle dateTimeEcamStr1 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp1); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr1).c_str(), "2022/5/25 上午11:09:34"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr1).c_str(), "2022/5/25 上午11:09:34"); JSHandle dateTimeEcamStr2 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp2); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr2).c_str(), "2022/5/30 下午10:30:12"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr2).c_str(), "2022/5/30 下午10:30:12"); } static JSHandle FormatCommonSet(JSThread *thread, JSHandle& options, icu::Locale& icuLocale, @@ -104,9 +104,10 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_003) double timeStamp2 = 1653921012999; // test "2022-05-30 22:30:12.999" JSHandle dateTimeEcamStr1 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp1); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr1).c_str(), "22年05月25日星期三 上午11:09:34.000"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr1).c_str(), + "22年05月25日星期三 上午11:09:34.000"); JSHandle dateTimeEcamStr2 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp2); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr2).c_str(), "22年05月30日星期一 晚上10:30:12.999"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr2).c_str(), "22年05月30日星期一 晚上10:30:12.999"); } HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_004) @@ -118,10 +119,10 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_004) double timeStamp2 = 1653921012999; // test "2022-05-30 22:30:12.999" JSHandle dateTimeEcamStr1 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp1); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr1).c_str(), + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr1).c_str(), "Wednesday, 05/25/22, 11:09:34.000 in the morning"); JSHandle dateTimeEcamStr2 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp2); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr2).c_str(), + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr2).c_str(), "Monday, 05/30/22, 10:30:12.999 at night"); } @@ -130,7 +131,7 @@ std::string GetDateTimePartStringTest(JSThread *thread, JSHandle JSHandle partObj = JSHandle::Cast(part); JSHandle partValue = JSObject::GetProperty(thread, partObj, key).GetValue(); JSHandle partEcmaStr = JSHandle::Cast(partValue); - std::string partStr = LocaleHelper::ConvertToStdString(partEcmaStr); + std::string partStr = LocaleHelper::ConvertToStdString(thread, partEcmaStr); return partStr; } @@ -158,7 +159,7 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTimeToParts_001) double timeStamp = 1653448174123; // test "2022-05-25 11:09:34.123" // Use default date time format and format date and time to parts. JSHandle dateTimeEcamStr1 = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr1).c_str(), "2022/5/25"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr1).c_str(), "2022/5/25"); JSHandle dateTimeArray1 = JSDateTimeFormat::FormatDateTimeToParts(thread, dtf, timeStamp); auto year = JSTaggedValue::GetProperty(thread, JSHandle::Cast(dateTimeArray1), 0).GetValue(); auto literal1 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(dateTimeArray1), 1).GetValue(); @@ -260,7 +261,8 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTimeToParts_002) thread, JSHandle::Cast(options), RequiredOption::ANY, DefaultsOption::ALL); JSHandle dtf = EcmaTestCommon::CreateDateTimeFormatTest(thread, icuLocale, options); JSHandle dateTimeEcamStr = JSDateTimeFormat::FormatDateTime(thread, dtf, timeStamp); - EXPECT_STREQ(LocaleHelper::ConvertToStdString(dateTimeEcamStr).c_str(), "22年05月25日星期三 上午11:09:34.123"); + EXPECT_STREQ(LocaleHelper::ConvertToStdString(thread, dateTimeEcamStr).c_str(), + "22年05月25日星期三 上午11:09:34.123"); JSHandle dateTimeArray = JSDateTimeFormat::FormatDateTimeToParts(thread, dtf, timeStamp); auto year = JSTaggedValue::GetProperty(thread, JSHandle::Cast(dateTimeArray), 0).GetValue(); @@ -316,13 +318,13 @@ HWTEST_F_L0(JSDateTimeFormatTest, GainAvailableLocales) dtf = JSDateTimeFormat::InitializeDateTimeFormat( thread, dtf, JSHandle::Cast(locales), JSHandle::Cast(options)); - JSHandle localeTagVal(thread, dtf->GetLocale()); + JSHandle localeTagVal(thread, dtf->GetLocale(thread)); JSHandle localesTagArr = factory->NewTaggedArray(1); localesTagArr->Set(thread, 0, localeTagVal); env->SetDateTimeFormatLocales(thread, localesTagArr); JSHandle gainLocales2 = JSDateTimeFormat::GainAvailableLocales(thread); EXPECT_EQ(gainLocales2->GetLength(), 1U); - EXPECT_STREQ(EcmaStringAccessor(gainLocales2->Get(0)).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(gainLocales2->Get(thread, 0)).ToCString(thread).c_str(), "zh-Hans-CN-u-ca-chinese"); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_displaynames_test.cpp b/ecmascript/tests/js_displaynames_test.cpp index 58c27dcd8e..c2ec67ff9c 100644 --- a/ecmascript/tests/js_displaynames_test.cpp +++ b/ecmascript/tests/js_displaynames_test.cpp @@ -49,11 +49,11 @@ HWTEST_F_L0(JSDisplayNamesTest, GetIcuLocaleDisplayNames) EXPECT_TRUE(iculocaledisplaynames != nullptr); JSDisplayNames::SetIcuLocaleDisplayNames( thread, displayNames, iculocaledisplaynames, JSDisplayNames::FreeIcuLocaleDisplayNames); - icu::LocaleDisplayNames *resultIculocaledisplaynames = displayNames->GetIcuLocaleDisplayNames(); + icu::LocaleDisplayNames *resultIculocaledisplaynames = displayNames->GetIcuLocaleDisplayNames(thread); EXPECT_TRUE(iculocaledisplaynames == resultIculocaledisplaynames); JSHandle localeStr = intl::LocaleHelper::ToLanguageTag(thread, resultIculocaledisplaynames->getLocale()); - EXPECT_STREQ(EcmaStringAccessor(localeStr).ToCString().c_str(), "en"); + EXPECT_STREQ(EcmaStringAccessor(localeStr).ToCString(thread).c_str(), "en"); } /** @@ -70,7 +70,7 @@ HWTEST_F_L0(JSDisplayNamesTest, GetAvailableLocales) EXPECT_NE(localeLen, 0U); for (uint32_t i = 0; i < localeLen; i++) { - EXPECT_FALSE(displayLocale->Get(i).IsHole()); + EXPECT_FALSE(displayLocale->Get(thread, i).IsHole()); } } @@ -127,12 +127,12 @@ HWTEST_F_L0(JSDisplayNamesTest, InitializeDisplayNames) SetOptionProperties(thread, displayOptions, displayOptionsProperty); // options is not empty JSDisplayNames::InitializeDisplayNames(thread, displayNames, localeStr, JSHandle(displayOptions)); - JSHandle setlocale(thread, displayNames->GetLocale()); + JSHandle setlocale(thread, displayNames->GetLocale(thread)); EXPECT_EQ(displayNames->GetStyle(), StyOption::SHORT); EXPECT_EQ(displayNames->GetType(), TypednsOption::SCRIPT); EXPECT_EQ(displayNames->GetFallback(), FallbackOption::NONE); - EXPECT_STREQ(EcmaStringAccessor(setlocale).ToCString().c_str(), "en-US"); - EXPECT_TRUE(displayNames->GetIcuLocaleDisplayNames() != nullptr); + EXPECT_STREQ(EcmaStringAccessor(setlocale).ToCString(thread).c_str(), "en-US"); + EXPECT_TRUE(displayNames->GetIcuLocaleDisplayNames(thread) != nullptr); } /** @@ -166,19 +166,19 @@ HWTEST_F_L0(JSDisplayNamesTest, CanonicalCodeForDisplayNames) JSHandle code = factory->NewFromASCII("Kana"); JSHandle resultDisplay = JSDisplayNames::CanonicalCodeForDisplayNames(thread, initDisplayNames, initDisplayNames->GetType(), code); - EXPECT_STREQ(EcmaStringAccessor(resultDisplay).ToCString().c_str(), "片假名"); + EXPECT_STREQ(EcmaStringAccessor(resultDisplay).ToCString(thread).c_str(), "片假名"); // CanonicalCode for languege code = factory->NewFromASCII("fr"); initDisplayNames->SetType(TypednsOption::LANGUAGE); resultDisplay = JSDisplayNames::CanonicalCodeForDisplayNames(thread, initDisplayNames, initDisplayNames->GetType(), code); - EXPECT_STREQ(EcmaStringAccessor(resultDisplay).ToCString().c_str(), "法文"); + EXPECT_STREQ(EcmaStringAccessor(resultDisplay).ToCString(thread).c_str(), "法文"); // CanonicalCode for region code = factory->NewFromASCII("US"); initDisplayNames->SetType(TypednsOption::REGION); resultDisplay = JSDisplayNames::CanonicalCodeForDisplayNames(thread, initDisplayNames, initDisplayNames->GetType(), code); - EXPECT_STREQ(EcmaStringAccessor(resultDisplay).ToCString().c_str(), "美國"); + EXPECT_STREQ(EcmaStringAccessor(resultDisplay).ToCString(thread).c_str(), "美國"); } /** @@ -218,13 +218,13 @@ HWTEST_F_L0(JSDisplayNamesTest, ResolvedOptions) JSDisplayNames::InitializeDisplayNames(thread, displayNames, locale, JSHandle(displayOptions)); JSDisplayNames::ResolvedOptions(thread, initDisplayNames, displayOptions); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, displayOptions, styleKey).GetValue(), styleValue), true); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, displayOptions, localeKey).GetValue(), locale), true); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, displayOptions, fallBackKey).GetValue(), fallBackValue), true); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, displayOptions, typeKey).GetValue(), typeValue), true); } } // namespace panda::test diff --git a/ecmascript/tests/js_finalization_registry_test.cpp b/ecmascript/tests/js_finalization_registry_test.cpp index c0d31d3954..eee1a3dcef 100644 --- a/ecmascript/tests/js_finalization_registry_test.cpp +++ b/ecmascript/tests/js_finalization_registry_test.cpp @@ -92,11 +92,11 @@ HWTEST_F_L0(JSFinalizationRegistryTest, Register_001) cellRecord->SetToWeakRefTarget(thread, target.GetTaggedValue()); cellRecord->SetHeldValue(thread, heldValue); JSHandle cell(cellRecord); - JSHandle expectNoUnregister(thread, finaRegObj->GetNoUnregister()); + JSHandle expectNoUnregister(thread, finaRegObj->GetNoUnregister(thread)); expectNoUnregister = CellRecordVector::Append(thread, expectNoUnregister, cell); JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); - JSHandle noUnregister(thread, finaRegObj->GetNoUnregister()); + JSHandle noUnregister(thread, finaRegObj->GetNoUnregister(thread)); JSHandle finRegLists = env->GetFinRegLists(); EXPECT_EQ(finRegLists.GetTaggedValue().GetRawData(), JSHandle::Cast(finaRegObj).GetTaggedValue().GetRawData()); @@ -129,11 +129,11 @@ HWTEST_F_L0(JSFinalizationRegistryTest, Register_002) JSHandle array = JSHandle(CellRecordVector::Create(thread)); array = CellRecordVector::Append(thread, array, cell); JSHandle arrayValue(array); - JSHandle expectMaybeUnregister(thread, finaRegObj->GetMaybeUnregister()); + JSHandle expectMaybeUnregister(thread, finaRegObj->GetMaybeUnregister(thread)); expectMaybeUnregister = LinkedHashMap::SetWeakRef(thread, expectMaybeUnregister, unregisterToken, arrayValue); JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); - JSHandle maybeUnregister(thread, finaRegObj->GetMaybeUnregister()); + JSHandle maybeUnregister(thread, finaRegObj->GetMaybeUnregister(thread)); EXPECT_EQ(expectMaybeUnregister.GetTaggedValue().GetRawData(), maybeUnregister.GetTaggedValue().GetRawData()); JSHandle finRegLists = env->GetFinRegLists(); @@ -166,7 +166,7 @@ static void RegisterUnRegisterTestCommon(JSThread *thread, bool testUnRegister = cellRecord->SetToWeakRefTarget(thread, target.GetTaggedValue()); cellRecord->SetHeldValue(thread, heldValue); JSHandle cell(cellRecord); - JSHandle noUnregister(thread, finaRegObj->GetNoUnregister()); + JSHandle noUnregister(thread, finaRegObj->GetNoUnregister(thread)); noUnregister = CellRecordVector::Append(thread, noUnregister, cell); finaRegObj->SetNoUnregister(thread, noUnregister); JSFinalizationRegistry::AddFinRegLists(thread, finaRegObj); diff --git a/ecmascript/tests/js_function_test.cpp b/ecmascript/tests/js_function_test.cpp index 1e9ea0a80f..dfc94ad1c8 100644 --- a/ecmascript/tests/js_function_test.cpp +++ b/ecmascript/tests/js_function_test.cpp @@ -47,11 +47,11 @@ HWTEST_F_L0(JSFunctionTest, Create) JSHandle env = ecmaVM->GetGlobalEnv(); JSHandle funHandle = thread->GetEcmaVM()->GetFactory()->NewJSFunction(env); EXPECT_TRUE(*funHandle != nullptr); - EXPECT_EQ(funHandle->GetProtoOrHClass(), JSTaggedValue::Hole()); + EXPECT_EQ(funHandle->GetProtoOrHClass(thread), JSTaggedValue::Hole()); JSHandle lexicalEnv = thread->GetEcmaVM()->GetFactory()->NewLexicalEnv(0); funHandle->SetLexicalEnv(thread, lexicalEnv.GetTaggedValue()); - EXPECT_EQ(funHandle->GetLexicalEnv(), lexicalEnv.GetTaggedValue()); + EXPECT_EQ(funHandle->GetLexicalEnv(thread), lexicalEnv.GetTaggedValue()); EXPECT_TRUE(*lexicalEnv != nullptr); } HWTEST_F_L0(JSFunctionTest, MakeConstructor) @@ -79,7 +79,7 @@ HWTEST_F_L0(JSFunctionTest, MakeConstructor) JSObject::GetProperty(thread, JSHandle(obj), constructorKey).GetValue().GetTaggedValue(); EXPECT_EQ(constructor, funcHandle.GetTaggedValue()); EXPECT_EQ(proto, obj.GetTaggedValue()); - EXPECT_EQ(func->GetFunctionKind(), FunctionKind::BASE_CONSTRUCTOR); + EXPECT_EQ(func->GetFunctionKind(thread), FunctionKind::BASE_CONSTRUCTOR); } HWTEST_F_L0(JSFunctionTest, OrdinaryHasInstance) @@ -143,6 +143,6 @@ HWTEST_F_L0(JSFunctionTest, SetSymbolFunctionName) JSHandle functionName = JSFunctionBase::GetFunctionName(thread, JSHandle(jsFunction)); EXPECT_TRUE(functionName->IsString()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(*(JSHandle(functionName)), *name)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, *(JSHandle(functionName)), *name)); } } // namespace panda::test diff --git a/ecmascript/tests/js_hclass_test.cpp b/ecmascript/tests/js_hclass_test.cpp index 2eeb9eb623..f2d3ccabdc 100644 --- a/ecmascript/tests/js_hclass_test.cpp +++ b/ecmascript/tests/js_hclass_test.cpp @@ -38,15 +38,15 @@ HWTEST_F_L0(JSHClassTest, InitializeClass) JSHandle objectClass = factory->NewEcmaHClass(TaggedArray::SIZE, JSType::TAGGED_ARRAY, nullHandle); // Get object properties - EXPECT_EQ(objectClass->GetLayout(), JSTaggedValue::Null()); - EXPECT_EQ(objectClass->GetPrototype(), JSTaggedValue::Null()); + EXPECT_EQ(objectClass->GetLayout(thread), JSTaggedValue::Null()); + EXPECT_EQ(objectClass->GetPrototype(thread), JSTaggedValue::Null()); EXPECT_EQ(objectClass->GetObjectType(), JSType::TAGGED_ARRAY); EXPECT_TRUE(objectClass->IsExtensible()); EXPECT_TRUE(!objectClass->IsPrototype()); - EXPECT_EQ(objectClass->GetTransitions(), JSTaggedValue::Undefined()); - EXPECT_EQ(objectClass->GetProtoChangeMarker(), JSTaggedValue::Null()); - EXPECT_EQ(objectClass->GetProtoChangeDetails(), JSTaggedValue::Null()); - EXPECT_EQ(objectClass->GetEnumCache(), JSTaggedValue::Null()); + EXPECT_EQ(objectClass->GetTransitions(thread), JSTaggedValue::Undefined()); + EXPECT_EQ(objectClass->GetProtoChangeMarker(thread), JSTaggedValue::Null()); + EXPECT_EQ(objectClass->GetProtoChangeDetails(thread), JSTaggedValue::Null()); + EXPECT_EQ(objectClass->GetEnumCache(thread), JSTaggedValue::Null()); } #ifndef USE_CMC_GC @@ -135,8 +135,8 @@ HWTEST_F_L0(JSHClassTest, Clone) EXPECT_TRUE(*cloneClass != nullptr); EXPECT_TRUE(objectClass->GetObjectSize() == cloneClass->GetObjectSize()); EXPECT_EQ(cloneClass->GetObjectSize(), 64U); // 64 : 64 not missing the size of inlinedproperties - EXPECT_TRUE(objectClass->GetLayout() == cloneClass->GetLayout()); - EXPECT_EQ(JSTaggedValue::SameValue(objectClass->GetPrototype(), cloneClass->GetPrototype()), true); + EXPECT_TRUE(objectClass->GetLayout(thread) == cloneClass->GetLayout(thread)); + EXPECT_EQ(JSTaggedValue::SameValue(thread, objectClass->GetPrototype(thread), cloneClass->GetPrototype(thread)), true); EXPECT_TRUE(objectClass->GetBitField() == cloneClass->GetBitField()); EXPECT_TRUE(objectClass->GetBitField1() == cloneClass->GetBitField1()); EXPECT_TRUE(objectClass->NumberOfProps() == cloneClass->NumberOfProps()); @@ -146,8 +146,8 @@ HWTEST_F_L0(JSHClassTest, Clone) EXPECT_TRUE(*cloneClass != nullptr); EXPECT_TRUE(objectClass->GetObjectSize() > cloneClass->GetObjectSize()); EXPECT_EQ(cloneClass->GetObjectSize(), 32U); // 32 : 32 missing the size of inlinedproperties - EXPECT_TRUE(objectClass->GetLayout() == cloneClass->GetLayout()); - EXPECT_EQ(JSTaggedValue::SameValue(objectClass->GetPrototype(), cloneClass->GetPrototype()), true); + EXPECT_TRUE(objectClass->GetLayout(thread) == cloneClass->GetLayout(thread)); + EXPECT_EQ(JSTaggedValue::SameValue(thread, objectClass->GetPrototype(thread), cloneClass->GetPrototype(thread)), true); EXPECT_TRUE(objectClass->GetBitField() == cloneClass->GetBitField()); EXPECT_TRUE(objectClass->GetBitField1() > cloneClass->GetBitField1()); EXPECT_TRUE(objectClass->NumberOfProps() == cloneClass->NumberOfProps()); @@ -179,7 +179,7 @@ HWTEST_F_L0(JSHClassTest, TransitionElementsToDictionary) ElementsKind oldKind = jsObject->GetJSHClass()->GetElementsKind(); JSHClass::TransitionElementsToDictionary(thread, jsObject); JSObject::TryMigrateToGenericKindForJSObject(thread, jsObject, oldKind); - auto resultDict = NameDictionary::Cast(jsObject->GetProperties().GetTaggedObject()); + auto resultDict = NameDictionary::Cast(jsObject->GetProperties(thread).GetTaggedObject()); EXPECT_TRUE(resultDict != nullptr); EXPECT_EQ(resultDict->EntriesCount(), 3); // 3 : 3 entry @@ -227,7 +227,7 @@ HWTEST_F_L0(JSHClassTest, SetPropertyOfObjHClass_001) JSHandle childObj = factory->NewJSObject(childClass); std::vector keyVector; - JSObject::GetAllKeysForSerialization(childObj, keyVector); + JSObject::GetAllKeysForSerialization(thread, childObj, keyVector); EXPECT_EQ(keyVector.size(), 3U); EXPECT_TRUE(JSObject::HasProperty(thread, childObj, keyHandle0)); EXPECT_TRUE(JSObject::HasProperty(thread, childObj, keyHandle2)); @@ -289,7 +289,7 @@ HWTEST_F_L0(JSHClassTest, AddProperty) } EXPECT_TRUE(objClass1 == objClass); std::vector keyVector; - JSObject::GetAllKeysForSerialization(Obj, keyVector); + JSObject::GetAllKeysForSerialization(thread, Obj, keyVector); EXPECT_EQ(keyVector.size(), 3U); EXPECT_TRUE(JSObject::HasProperty(thread, Obj, keyHandle0)); EXPECT_TRUE(JSObject::HasProperty(thread, Obj, keyHandle1)); @@ -324,10 +324,10 @@ HWTEST_F_L0(JSHClassTest, TransitionExtension) // obj has no key "PreventExtensions" JSHandle newClass2 = JSHClass::TransitionExtension(thread, obj2Class); EXPECT_FALSE(newClass2->IsExtensible()); - JSHandle dictionary(thread, obj2Class->GetTransitions()); + JSHandle dictionary(thread, obj2Class->GetTransitions(thread)); // find key std::vector keyVector; - dictionary->GetAllKeysIntoVector(keyVector); + dictionary->GetAllKeysIntoVector(thread, keyVector); EXPECT_TRUE((keyVector[0] == keyHandle0.GetTaggedValue()) || (keyVector[0] == preExtensionsKey.GetTaggedValue())); EXPECT_TRUE((keyVector[1] == keyHandle0.GetTaggedValue()) || (keyVector[1] == preExtensionsKey.GetTaggedValue())); } @@ -357,11 +357,11 @@ HWTEST_F_L0(JSHClassTest, TransitionProto) JSHClass::AddProperty(thread, Obj, obj3Key, attr); JSObject::TryMigrateToGenericKindForJSObject(thread, Obj, oldKind); JSHandle newClass = JSHClass::TransitionProto(thread, objClass, funcPrototype); - EXPECT_EQ(newClass->GetPrototype(), funcPrototype.GetTaggedValue()); - JSHandle transitionDictionary(thread, objClass->GetTransitions()); + EXPECT_EQ(newClass->GetPrototype(thread), funcPrototype.GetTaggedValue()); + JSHandle transitionDictionary(thread, objClass->GetTransitions(thread)); // find key std::vector keyVector; - transitionDictionary->GetAllKeysIntoVector(keyVector); + transitionDictionary->GetAllKeysIntoVector(thread, keyVector); EXPECT_EQ(keyVector.size(), 2U); EXPECT_EQ(keyVector[0], obj1Key.GetTaggedValue()); EXPECT_EQ(keyVector[1], prototypeKey.GetTaggedValue()); @@ -399,11 +399,11 @@ HWTEST_F_L0(JSHClassTest, TransitionToDictionary) JSObject::TransitionToDictionary(thread, Obj2); // refresh users JSHandle obj1Class(thread, Obj1->GetJSHClass()); - JSTaggedValue protoDetails = obj1Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails = obj1Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails.IsProtoChangeDetails()); - JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetails.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetails.GetTaggedObject())->GetChangeListener(thread); JSHandle listeners(thread, listenersValue.GetTaggedObject()); - uint32_t holeIndex = ChangeListener::CheckHole(listeners); + uint32_t holeIndex = ChangeListener::CheckHole(thread, listeners); EXPECT_TRUE(holeIndex == 0U); // new class JSHandle newClass(thread, Obj2->GetClass()); @@ -429,8 +429,8 @@ HWTEST_F_L0(JSHClassTest, UpdatePropertyMetaData) JSObject::TryMigrateToGenericKindForJSObject(thread, Obj, oldKind); // update metaData objClass->UpdatePropertyMetaData(thread, objKey.GetTaggedValue(), newAttr); - LayoutInfo *layoutInfo = LayoutInfo::Cast(objClass->GetLayout().GetTaggedObject()); - EXPECT_EQ(layoutInfo->GetAttr(oldAttr.GetOffset()).GetPropertyMetaData(), newAttr.GetPropertyMetaData()); + LayoutInfo *layoutInfo = LayoutInfo::Cast(objClass->GetLayout(thread).GetTaggedObject()); + EXPECT_EQ(layoutInfo->GetAttr(thread, oldAttr.GetOffset()).GetPropertyMetaData(), newAttr.GetPropertyMetaData()); } HWTEST_F_L0(JSHClassTest, SetPrototype) @@ -442,9 +442,9 @@ HWTEST_F_L0(JSHClassTest, SetPrototype) JSHandle objectFuncPrototype = env->GetObjectFunctionPrototype(); JSHandle objectClass = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_OBJECT, nullHandle); - EXPECT_EQ(objectClass->GetPrototype(), nullHandle.GetTaggedValue()); + EXPECT_EQ(objectClass->GetPrototype(thread), nullHandle.GetTaggedValue()); objectClass->SetPrototype(thread, objectFuncPrototype); - EXPECT_EQ(objectClass->GetPrototype(), objectFuncPrototype.GetTaggedValue()); + EXPECT_EQ(objectClass->GetPrototype(thread), objectFuncPrototype.GetTaggedValue()); } HWTEST_F_L0(JSHClassTest, ProxyHClassClone) @@ -468,6 +468,6 @@ HWTEST_F_L0(JSHClassTest, ProxyHClassClone) EXPECT_EQ(newHClass->GetObjectSize(), hclass->GetObjectSize()); EXPECT_EQ(newHClass->GetInlinedPropsStartSize(), hclass->GetInlinedPropsStartSize()); EXPECT_EQ(newHClass->GetInlinedProperties(), hclass->GetInlinedProperties()); - EXPECT_EQ(newHClass->GetLayout(), hclass->GetLayout()); + EXPECT_EQ(newHClass->GetLayout(thread), hclass->GetLayout(thread)); } } // namespace panda::test diff --git a/ecmascript/tests/js_iterator_test.cpp b/ecmascript/tests/js_iterator_test.cpp index caf5675050..d1d4e7264e 100644 --- a/ecmascript/tests/js_iterator_test.cpp +++ b/ecmascript/tests/js_iterator_test.cpp @@ -44,7 +44,7 @@ HWTEST_F_L0(JSIteratorTest, GetIterator) EXPECT_TRUE(array->IsArray(thread)); JSHandle iter(JSIterator::GetIterator(thread, array)); EXPECT_TRUE(iter->IsJSArrayIterator()); - EXPECT_TRUE(iter->GetIteratedArray().IsArray(thread)); + EXPECT_TRUE(iter->GetIteratedArray(thread).IsArray(thread)); } HWTEST_F_L0(JSIteratorTest, IteratorNext) diff --git a/ecmascript/tests/js_list_format_test.cpp b/ecmascript/tests/js_list_format_test.cpp index 06652fda17..d3058cb199 100644 --- a/ecmascript/tests/js_list_format_test.cpp +++ b/ecmascript/tests/js_list_format_test.cpp @@ -39,7 +39,7 @@ HWTEST_F_L0(JSListFormatTest, Set_Get_IcuListFormatter_001) 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(); + icu::ListFormatter *resFormatter = jsFormatter->GetIcuListFormatter(thread); EXPECT_TRUE(resFormatter != nullptr); const int32_t itemNum = 3; @@ -62,7 +62,7 @@ HWTEST_F_L0(JSListFormatTest, Set_Get_IcuListFormatter_002) 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(); + icu::ListFormatter *resFormatter = jsFormatter->GetIcuListFormatter(thread); EXPECT_TRUE(resFormatter != nullptr); const int32_t itemNum = 3; @@ -135,7 +135,7 @@ HWTEST_F_L0(JSListFormatTest, InitializeListFormat) factory->NewJSIntlIcuData(locales, icuLocale, JSLocale::FreeIcuLocale); listFormatter = JSListFormat::InitializeListFormat(thread, listFormatter, JSHandle::Cast(locales), optionsVal); - icu::ListFormatter *resFormatter = listFormatter->GetIcuListFormatter(); + icu::ListFormatter *resFormatter = listFormatter->GetIcuListFormatter(thread); EXPECT_TRUE(resFormatter != nullptr); const int32_t itemNum = 3; @@ -185,7 +185,7 @@ HWTEST_F_L0(JSListFormatTest, FormatList_001) std::vector strs{"Zero", "One", "Two"}; JSHandle valueArr = FormatCommon(thread, strs); JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); - EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString().c_str(), "Zero, One, and Two"); + EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString(thread).c_str(), "Zero, One, and Two"); } HWTEST_F_L0(JSListFormatTest, FormatList_002) @@ -201,7 +201,7 @@ HWTEST_F_L0(JSListFormatTest, FormatList_002) std::vector strs{"Zero", "One", "Two"}; JSHandle valueArr = FormatCommon(thread, strs); JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); - EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString().c_str(), "Zero One Two"); + EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString(thread).c_str(), "Zero One Two"); } HWTEST_F_L0(JSListFormatTest, FormatList_003) @@ -216,7 +216,7 @@ HWTEST_F_L0(JSListFormatTest, FormatList_003) std::vector strs{"苹果", "梨子", "桃"}; JSHandle valueArr = FormatCommon(thread, strs); JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); - EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString().c_str(), "苹果、梨子或桃"); + EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString(thread).c_str(), "苹果、梨子或桃"); } std::string GetListPartStringTest(JSThread *thread, JSHandle key, JSHandle part) @@ -224,7 +224,7 @@ std::string GetListPartStringTest(JSThread *thread, JSHandle key, JSHandle partObj = JSHandle::Cast(part); JSHandle partValue = JSObject::GetProperty(thread, partObj, key).GetValue(); JSHandle partEcmaStr = JSHandle::Cast(partValue); - std::string partStr = intl::LocaleHelper::ConvertToStdString(partEcmaStr); + std::string partStr = intl::LocaleHelper::ConvertToStdString(thread, partEcmaStr); return partStr; } @@ -240,7 +240,7 @@ HWTEST_F_L0(JSListFormatTest, FormatListToParts) std::vector strs{"苹果", "梨子", "桃"}; JSHandle valueArr = FormatCommon(thread, strs); JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); - EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString().c_str(), "苹果、梨子和桃"); + EXPECT_STREQ(EcmaStringAccessor(valueStr).ToCString(thread).c_str(), "苹果、梨子和桃"); auto globalConst = thread->GlobalConstants(); JSHandle typeKey = globalConst->GetHandledTypeString(); @@ -284,8 +284,8 @@ HWTEST_F_L0(JSListFormatTest, StringListFromIterable) 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(EcmaStringAccessor(resValue0.GetTaggedValue()).ToCString().c_str(), "one"); - EXPECT_STREQ(EcmaStringAccessor(resValue1.GetTaggedValue()).ToCString().c_str(), "two"); - EXPECT_STREQ(EcmaStringAccessor(resValue2.GetTaggedValue()).ToCString().c_str(), "three"); + EXPECT_STREQ(EcmaStringAccessor(resValue0.GetTaggedValue()).ToCString(thread).c_str(), "one"); + EXPECT_STREQ(EcmaStringAccessor(resValue1.GetTaggedValue()).ToCString(thread).c_str(), "two"); + EXPECT_STREQ(EcmaStringAccessor(resValue2.GetTaggedValue()).ToCString(thread).c_str(), "three"); } } // namespace panda::test diff --git a/ecmascript/tests/js_locale_test.cpp b/ecmascript/tests/js_locale_test.cpp index 609a33a989..77381970cb 100644 --- a/ecmascript/tests/js_locale_test.cpp +++ b/ecmascript/tests/js_locale_test.cpp @@ -57,7 +57,7 @@ HWTEST_F_L0(JSLocaleTest, JSIntlIteratorTest) arrayData->Set(thread, i, languageStr); } // construct a JSIntlIterator object - JSIntlIterator jsIntlIterator(arrayData, arrayDataLength); + JSIntlIterator jsIntlIterator(thread, arrayData, arrayDataLength); EXPECT_TRUE(jsIntlIterator.hasNext()); // call "next" function to traverse the container for (uint32_t i = 0; i < arrayDataLength; i++) { @@ -104,7 +104,7 @@ HWTEST_F_L0(JSLocaleTest, GetIcuField) factory->NewJSIntlIcuData(locale, icuLocale, JSLocale::FreeIcuLocale); // call "GetIcuLocale" function Get IcuField - icu::Locale *result = locale->GetIcuLocale(); + icu::Locale *result = locale->GetIcuLocale(thread); EXPECT_STREQ(result->getBaseName(), "zh_Hans_CN"); } @@ -147,7 +147,7 @@ HWTEST_F_L0(JSLocaleTest, PutElement) int index = 1; JSHandle recordObj = JSLocale::PutElement(thread, index, jsArray, fieldTypeString, value); - EXPECT_EQ(JSTaggedValue::SameValue( + EXPECT_EQ(JSTaggedValue::SameValue(thread, JSObject::GetProperty(thread, recordObj, typeString).GetValue(), fieldTypeString), true); EXPECT_EQ(JSObject::GetProperty(thread, recordObj, valueString).GetValue()->GetInt(), 11); @@ -186,22 +186,22 @@ HWTEST_F_L0(JSLocaleTest, GetNumberFieldType) JSTaggedValue x(0.0f / 0.0f); // Nan JSHandle nanString = globalConst->GetHandledNanString(); JSHandle fieldTypeString = JSLocale::GetNumberFieldType(thread, x, fieldId); - EXPECT_EQ(JSTaggedValue::SameValue(fieldTypeString, nanString), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, fieldTypeString, nanString), true); JSTaggedValue y(-10); // integer(sign bit) JSHandle integerString = globalConst->GetHandledIntegerString(); fieldTypeString = JSLocale::GetNumberFieldType(thread, y, fieldId); - EXPECT_EQ(JSTaggedValue::SameValue(fieldTypeString, integerString), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, fieldTypeString, integerString), true); fieldId = 10; // UNUM_SIGN_FIELD JSHandle minusSignString = globalConst->GetHandledMinusSignString(); fieldTypeString = JSLocale::GetNumberFieldType(thread, y, fieldId); - EXPECT_EQ(JSTaggedValue::SameValue(fieldTypeString, minusSignString), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, fieldTypeString, minusSignString), true); JSTaggedValue z(10); // no sign bit JSHandle plusSignString = globalConst->GetHandledPlusSignString(); fieldTypeString = JSLocale::GetNumberFieldType(thread, z, fieldId); - EXPECT_EQ(JSTaggedValue::SameValue(fieldTypeString, plusSignString), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, fieldTypeString, plusSignString), true); } /** @@ -284,9 +284,9 @@ HWTEST_F_L0(JSLocaleTest, SetNumberFormatDigitOptions_Significant) JSLocale::SetNumberFormatDigitOptions(thread, jsNumberFormat, JSHandle(optionsObj), 1, 1, NotationOption::COMPACT); - EXPECT_EQ(jsNumberFormat->GetMinimumSignificantDigits().GetInt(), 11); - EXPECT_EQ(jsNumberFormat->GetMaximumSignificantDigits().GetInt(), 12); - EXPECT_EQ(jsNumberFormat->GetMinimumIntegerDigits().GetInt(), 10); + EXPECT_EQ(jsNumberFormat->GetMinimumSignificantDigits(thread).GetInt(), 11); + EXPECT_EQ(jsNumberFormat->GetMaximumSignificantDigits(thread).GetInt(), 12); + EXPECT_EQ(jsNumberFormat->GetMinimumIntegerDigits(thread).GetInt(), 10); EXPECT_EQ(jsNumberFormat->GetRoundingType(), RoundingType::SIGNIFICANTDIGITS); } @@ -307,9 +307,9 @@ HWTEST_F_L0(JSLocaleTest, SetNumberFormatDigitOptions_Fraction) JSLocale::SetNumberFormatDigitOptions(thread, jsPluralRules, JSHandle(optionsObj), 10, 13, NotationOption::EXCEPTION); - EXPECT_EQ(jsPluralRules->GetMinimumFractionDigits().GetInt(), 10); - EXPECT_EQ(jsPluralRules->GetMaximumFractionDigits().GetInt(), 13); - EXPECT_EQ(jsPluralRules->GetMinimumIntegerDigits().GetInt(), 10); + EXPECT_EQ(jsPluralRules->GetMinimumFractionDigits(thread).GetInt(), 10); + EXPECT_EQ(jsPluralRules->GetMaximumFractionDigits(thread).GetInt(), 13); + EXPECT_EQ(jsPluralRules->GetMinimumIntegerDigits(thread).GetInt(), 10); EXPECT_EQ(jsPluralRules->GetRoundingType(), RoundingType::FRACTIONDIGITS); } @@ -491,10 +491,10 @@ HWTEST_F_L0(JSLocaleTest, GetOption) JSHandle optionValue = JSLocale::GetOption(thread, optionsObj, languageProperty, OptionType::STRING, arrayValue, fallback); - EXPECT_EQ(JSTaggedValue::SameValue(optionValue, languageValue), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, optionValue, languageValue), true); optionValue = JSLocale::GetOption(thread, optionsObj, regionProperty, OptionType::STRING, arrayValue, fallback); - EXPECT_EQ(JSTaggedValue::SameValue(optionValue, fallback), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, optionValue, fallback), true); } /** diff --git a/ecmascript/tests/js_map_iterator_test.cpp b/ecmascript/tests/js_map_iterator_test.cpp index 0efe9b8c56..55ecd21f83 100644 --- a/ecmascript/tests/js_map_iterator_test.cpp +++ b/ecmascript/tests/js_map_iterator_test.cpp @@ -86,10 +86,10 @@ HWTEST_F_L0(JSMapIteratorTest, SetIteratedMap) JSMapIterator::CreateMapIterator(thread, JSHandle::Cast(jsMap1), iterKind); JSHandle jsMapIterator = JSHandle::Cast(mapIteratorVal); - EXPECT_EQ(jsMap1->GetLinkedMap(), jsMapIterator->GetIteratedMap()); - jsMapIterator->SetIteratedMap(thread, JSHandle(thread, jsMap2->GetLinkedMap())); - EXPECT_NE(jsMap1->GetLinkedMap(), jsMapIterator->GetIteratedMap()); - EXPECT_EQ(jsMap2->GetLinkedMap(), jsMapIterator->GetIteratedMap()); + EXPECT_EQ(jsMap1->GetLinkedMap(thread), jsMapIterator->GetIteratedMap(thread)); + jsMapIterator->SetIteratedMap(thread, JSHandle(thread, jsMap2->GetLinkedMap(thread))); + EXPECT_NE(jsMap1->GetLinkedMap(thread), jsMapIterator->GetIteratedMap(thread)); + EXPECT_EQ(jsMap2->GetLinkedMap(thread), jsMapIterator->GetIteratedMap(thread)); } /** @@ -159,14 +159,14 @@ HWTEST_F_L0(JSMapIteratorTest, Update) JSMap::Set(thread, jsMap1, keyHandle2, keyHandle2); JSMap::Set(thread, jsMap1, keyHandle3, keyHandle3); - JSHandle mapHandle1(thread, LinkedHashMap::Cast(jsMap1->GetLinkedMap().GetTaggedObject())); - JSHandle mapHandle2(thread, LinkedHashMap::Cast(jsMap2->GetLinkedMap().GetTaggedObject())); + JSHandle mapHandle1(thread, LinkedHashMap::Cast(jsMap1->GetLinkedMap(thread).GetTaggedObject())); + JSHandle mapHandle2(thread, LinkedHashMap::Cast(jsMap2->GetLinkedMap(thread).GetTaggedObject())); mapHandle1->Rehash(thread, *mapHandle2); // create SetIterator with jsMap1 JSHandle mapIterator = factory->NewJSMapIterator(jsMap1, IterationKind::KEY); // update MapIterator mapIterator->Update(thread); - LinkedHashMap *resultMap = LinkedHashMap::Cast(mapIterator->GetIteratedMap().GetTaggedObject()); + LinkedHashMap *resultMap = LinkedHashMap::Cast(mapIterator->GetIteratedMap(thread).GetTaggedObject()); EXPECT_TRUE(resultMap->Has(thread, keyHandle1.GetTaggedValue())); EXPECT_TRUE(resultMap->Has(thread, keyHandle2.GetTaggedValue())); EXPECT_TRUE(resultMap->Has(thread, keyHandle3.GetTaggedValue())); @@ -233,7 +233,7 @@ HWTEST_F_L0(JSMapIteratorTest, KEY_AND_VALUE_Next) for (int32_t i = 0; i < iteratorLength; i++) { JSHandle nextTagValResult(thread, JSMapIterator::Next(ecmaRuntimeCallInfo)); JSHandle iteratorVal(thread, JSIterator::IteratorValue(thread, nextTagValResult).GetTaggedValue()); - JSHandle elementsIterVal(thread, iteratorVal->GetElements()); + JSHandle elementsIterVal(thread, iteratorVal->GetElements(thread)); EXPECT_EQ(i, elementsIterVal->Get(thread, 0).GetInt()); EXPECT_EQ(i + 10, elementsIterVal->Get(thread, 1).GetInt()); // 10: means expected value } diff --git a/ecmascript/tests/js_map_test.cpp b/ecmascript/tests/js_map_test.cpp index 6114e71571..8a4f3e9931 100644 --- a/ecmascript/tests/js_map_test.cpp +++ b/ecmascript/tests/js_map_test.cpp @@ -81,14 +81,14 @@ HWTEST_F_L0(JSMapTest, DeleteAndGet) JSMap::Set(thread, map, key, value); EXPECT_TRUE(map->Has(thread, key.GetTaggedValue())); } - EXPECT_EQ(map->GetSize(), 40); + EXPECT_EQ(map->GetSize(thread), 40); // whether jsMap has delete key keyArray[3] = '1' + 8; JSHandle deleteKey(factory->NewFromASCII(keyArray)); - EXPECT_EQ(map->GetValue(8), JSTaggedValue(8)); + EXPECT_EQ(map->GetValue(thread, 8), JSTaggedValue(8)); JSMap::Delete(thread, map, deleteKey); EXPECT_FALSE(map->Has(thread, deleteKey.GetTaggedValue())); - EXPECT_EQ(map->GetSize(), 39); + EXPECT_EQ(map->GetSize(thread), 39); } HWTEST_F_L0(JSMapTest, DeleteAndGet2) @@ -113,7 +113,7 @@ HWTEST_F_L0(JSMapTest, DeleteAndGet2) JSHandle deletefunc = thread->GetGlobalEnv()->GetMapDelete(); for (int i = 0; i < 10; i++) { - JSHandle key(thread, taggedArray->Get(i)); + JSHandle key(thread, taggedArray->Get(thread, i)); JSHandle value(thread, JSTaggedValue(i)); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(setfunc.GetTaggedValue()); @@ -123,12 +123,12 @@ HWTEST_F_L0(JSMapTest, DeleteAndGet2) JSFunction::Call(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSTaggedValue hashField = - JSTaggedValue(Barriers::GetTaggedValue(key->GetTaggedObject(), ECMAObject::HASH_OFFSET)); + JSTaggedValue(Barriers::GetTaggedValue(thread, key->GetTaggedObject(), ECMAObject::HASH_OFFSET)); EXPECT_TRUE(hashField.IsTaggedArray()); } thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC); for (int i = 0; i < 10; i++) { - JSHandle key(thread, taggedArray->Get(i)); + JSHandle key(thread, taggedArray->Get(thread, i)); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(getfunc.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); @@ -138,12 +138,12 @@ HWTEST_F_L0(JSMapTest, DeleteAndGet2) EXPECT_TRUE(res.GetInt() == i); TestHelper::TearDownFrame(thread, prev); JSTaggedValue hashField = - JSTaggedValue(Barriers::GetTaggedValue(key->GetTaggedObject(), ECMAObject::HASH_OFFSET)); + JSTaggedValue(Barriers::GetTaggedValue(thread, key->GetTaggedObject(), ECMAObject::HASH_OFFSET)); EXPECT_TRUE(hashField.IsTaggedArray()); } thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC); for (int i = 0; i < 10; i++) { - JSHandle key(thread, taggedArray->Get(i)); + JSHandle key(thread, taggedArray->Get(thread, i)); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(deletefunc.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); @@ -153,7 +153,7 @@ HWTEST_F_L0(JSMapTest, DeleteAndGet2) EXPECT_TRUE(res.IsTrue()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue hashField = - JSTaggedValue(Barriers::GetTaggedValue(key->GetTaggedObject(), ECMAObject::HASH_OFFSET)); + JSTaggedValue(Barriers::GetTaggedValue(thread, key->GetTaggedObject(), ECMAObject::HASH_OFFSET)); EXPECT_TRUE(hashField.IsTaggedArray()); } } diff --git a/ecmascript/tests/js_number_format_test.cpp b/ecmascript/tests/js_number_format_test.cpp index a9b177ae8f..097b23e2c6 100644 --- a/ecmascript/tests/js_number_format_test.cpp +++ b/ecmascript/tests/js_number_format_test.cpp @@ -46,7 +46,7 @@ HWTEST_F_L0(JSNumberFormatTest, GetIcuCallTarget) icu::number::NumberFormatter::withLocale(icuLocale).roundingMode(UNUM_ROUND_HALFUP); // Set IcuCallTarget factory->NewJSIntlIcuData(numberFormat, icuNumberFormatter, JSNumberFormat::FreeIcuNumberformat); - icu::number::LocalizedNumberFormatter *resultIcuNumberFormatter = numberFormat->GetIcuCallTarget(); + icu::number::LocalizedNumberFormatter *resultIcuNumberFormatter = numberFormat->GetIcuCallTarget(thread); EXPECT_TRUE(resultIcuNumberFormatter != nullptr); // Use IcuCallTarget format Int int64_t value = -123456; @@ -54,7 +54,7 @@ HWTEST_F_L0(JSNumberFormatTest, GetIcuCallTarget) icu::number::FormattedNumber formattedNumber = resultIcuNumberFormatter->formatInt(value, status); icu::UnicodeString result = formattedNumber.toString(status); JSHandle stringValue = intl::LocaleHelper::UStringToString(thread, result); - EXPECT_STREQ("-123,456", EcmaStringAccessor(stringValue).ToCString().c_str()); + EXPECT_STREQ("-123,456", EcmaStringAccessor(stringValue).ToCString(thread).c_str()); } /** @@ -78,24 +78,24 @@ HWTEST_F_L0(JSNumberFormatTest, InitializeNumberFormat) 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", EcmaStringAccessor(localeStr).ToCString().c_str()); + EXPECT_TRUE(numberFormat->GetNumberingSystem(thread).IsUndefined()); + JSHandle localeStr(thread, numberFormat->GetLocale(thread).GetTaggedObject()); + EXPECT_STREQ("zh-Hans-CN", EcmaStringAccessor(localeStr).ToCString(thread).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()); + EXPECT_EQ(numberFormat->GetMinimumIntegerDigits(thread).GetInt(), 1); // 1 : 1 default minimum integer + EXPECT_EQ(numberFormat->GetMinimumFractionDigits(thread).GetInt(), 0); // 0 : 0 default minimum fraction + EXPECT_EQ(numberFormat->GetMaximumFractionDigits(thread).GetInt(), 3); // 1 : 1 default maximum fraction + EXPECT_EQ(numberFormat->GetMinimumSignificantDigits(thread).GetInt(), 0); // 0 : 0 default minimum sigfraction + EXPECT_EQ(numberFormat->GetMaximumSignificantDigits(thread).GetInt(), 0); // 0 : 0 default maximum sigfraction + EXPECT_TRUE(numberFormat->GetUseGrouping(thread).IsTrue()); + EXPECT_TRUE(numberFormat->GetBoundFormat(thread).IsUndefined()); + EXPECT_TRUE(numberFormat->GetUnit(thread).IsUndefined()); + EXPECT_TRUE(numberFormat->GetCurrency(thread).IsUndefined()); } /** @@ -153,7 +153,7 @@ HWTEST_F_L0(JSNumberFormatTest, FormatNumeric) JSNumberFormat::FormatNumeric(thread, numberFormat, jsBigInt.GetTaggedValue()); JSHandle resultEcmaStr(thread, formatResult.GetTaggedValue()); - EXPECT_STREQ("123,456,789", EcmaStringAccessor(resultEcmaStr).ToCString().c_str()); + EXPECT_STREQ("123,456,789", EcmaStringAccessor(resultEcmaStr).ToCString(thread).c_str()); } /** @@ -183,7 +183,7 @@ HWTEST_F_L0(JSNumberFormatTest, UnwrapNumberFormat) factory->NewJSObjectByConstructor(JSHandle::Cast(disPlayNamesHandle), disPlayNamesHandle)); // object has no Instance JSHandle unwrapNumberFormat1 = JSNumberFormat::UnwrapNumberFormat(thread, numberFormat); - EXPECT_TRUE(JSTaggedValue::SameValue(numberFormat, unwrapNumberFormat1)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, numberFormat, unwrapNumberFormat1)); // object has Instance JSHandle unwrapNumberFormat2 = JSNumberFormat::UnwrapNumberFormat(thread, disPlayNamesObj); EXPECT_TRUE(unwrapNumberFormat2->IsUndefined()); diff --git a/ecmascript/tests/js_object_test.cpp b/ecmascript/tests/js_object_test.cpp index a49d2ccd3c..f0b6e28ca0 100644 --- a/ecmascript/tests/js_object_test.cpp +++ b/ecmascript/tests/js_object_test.cpp @@ -405,7 +405,7 @@ HWTEST_F_L0(JSObjectTest, GetOwnPropertyKeys) EXPECT_EQ(length, 4U); int sum = 0; for (uint32_t i = 0; i < length; i++) { - JSHandle key(thread, array->Get(i)); + JSHandle key(thread, array->Get(thread, i)); sum += JSObject::GetProperty(thread, JSHandle(obj), key).GetValue()->GetInt(); } EXPECT_EQ(sum, 10); @@ -455,7 +455,7 @@ HWTEST_F_L0(JSObjectTest, EnumerableOwnNames) JSHandle names = JSObject::EnumerableOwnNames(thread, obj); - JSHandle keyFromNames(thread, JSTaggedValue(names->Get(0))); + JSHandle keyFromNames(thread, JSTaggedValue(names->Get(thread, 0))); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(obj), keyFromNames).GetValue()->GetInt(), 1); PropertyDescriptor descNoEnum(thread); @@ -474,7 +474,7 @@ HWTEST_F_L0(JSObjectTest, EnumerableOwnNames) JSHandle namesNoConfig = JSObject::EnumerableOwnNames(thread, obj); - JSHandle keyNoConfig(thread, JSTaggedValue(namesNoConfig->Get(0))); + JSHandle keyNoConfig(thread, JSTaggedValue(namesNoConfig->Get(thread, 0))); EXPECT_EQ(JSObject::GetProperty(thread, JSHandle(obj), keyNoConfig).GetValue()->GetInt(), 1); } @@ -835,7 +835,7 @@ HWTEST_F_L0(JSObjectTest, FastToSlow) } ecmaVM->SetEnableForceGC(true); - EXPECT_FALSE(TaggedArray::Cast(obj1->GetProperties().GetTaggedObject())->IsDictionaryMode()); + EXPECT_FALSE(TaggedArray::Cast(obj1->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); number.Update(JSTaggedValue(PropertyAttributes::MAX_FAST_PROPS_CAPACITY)); number.Update(JSTaggedValue::ToString(thread, number).GetTaggedValue()); @@ -843,8 +843,8 @@ HWTEST_F_L0(JSObjectTest, FastToSlow) newkey.Update(JSTaggedValue(newString)); JSObject::SetProperty(thread, JSHandle(obj1), newkey, value); - EXPECT_TRUE(TaggedArray::Cast(obj1->GetProperties().GetTaggedObject())->IsDictionaryMode()); - NameDictionary *dict = NameDictionary::Cast(obj1->GetProperties().GetTaggedObject()); + EXPECT_TRUE(TaggedArray::Cast(obj1->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); + NameDictionary *dict = NameDictionary::Cast(obj1->GetProperties(thread).GetTaggedObject()); EXPECT_EQ(dict->EntriesCount(), static_cast(PropertyAttributes::MAX_FAST_PROPS_CAPACITY + 1)); EXPECT_EQ(dict->NextEnumerationIndex(thread), static_cast(PropertyAttributes::MAX_FAST_PROPS_CAPACITY + 1)); @@ -871,13 +871,13 @@ HWTEST_F_L0(JSObjectTest, DeleteMiddle) JSObject::SetProperty(thread, JSHandle(obj1), newkey, value); } - EXPECT_FALSE(TaggedArray::Cast(obj1->GetProperties().GetTaggedObject())->IsDictionaryMode()); + EXPECT_FALSE(TaggedArray::Cast(obj1->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); JSMutableHandle key5(thread, factory->NewFromASCII("x5")); JSObject::DeleteProperty(thread, (obj1), key5); - EXPECT_TRUE(TaggedArray::Cast(obj1->GetProperties().GetTaggedObject())->IsDictionaryMode()); - NameDictionary *dict = NameDictionary::Cast(obj1->GetProperties().GetTaggedObject()); + EXPECT_TRUE(TaggedArray::Cast(obj1->GetProperties(thread).GetTaggedObject())->IsDictionaryMode()); + NameDictionary *dict = NameDictionary::Cast(obj1->GetProperties(thread).GetTaggedObject()); EXPECT_EQ(dict->EntriesCount(), 9); EXPECT_FALSE(JSObject::HasProperty(thread, obj1, key5)); } @@ -894,45 +894,45 @@ HWTEST_F_L0(JSObjectTest, ElementFastToSlow) // test dictionary [0,1,2,...,2000] JSHandle obj1 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); - EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); JSObject::SetProperty(thread, JSHandle(obj1), keyStr, key2); JSObject::SetProperty(thread, JSHandle(obj1), key0, key0); - EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); JSHandle hclass(thread, obj1->GetJSHClass()); JSObject::SetProperty(thread, JSHandle(obj1), key1, key1); - EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj1->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); EXPECT_EQ(obj1->GetJSHClass(), *hclass); JSObject::SetProperty(thread, JSHandle(obj1), key2000, key2000); - EXPECT_TRUE(TaggedArray::Cast(obj1->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(TaggedArray::Cast(obj1->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); JSTaggedValue value = JSObject::GetProperty(thread, JSHandle(obj1), keyStr).GetValue().GetTaggedValue(); EXPECT_EQ(value, key2.GetTaggedValue()); // test holey [0,,2] JSHandle obj2 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread, JSHandle(obj2), key0, key0); - EXPECT_TRUE(!TaggedArray::Cast(obj2->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj2->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); JSHandle hclass2(thread, obj2->GetJSHClass()); JSObject::SetProperty(thread, JSHandle(obj2), key2, key2); - EXPECT_TRUE(!TaggedArray::Cast(obj2->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj2->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); EXPECT_EQ(obj2->GetJSHClass(), *hclass2); // test change attr JSHandle obj3 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread, JSHandle(obj3), key0, key0); JSObject::SetProperty(thread, JSHandle(obj3), key1, key1); JSObject::SetProperty(thread, JSHandle(obj3), key2, key2); - EXPECT_TRUE(!TaggedArray::Cast(obj3->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj3->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); PropertyDescriptor desc(thread); desc.SetValue(key1); desc.SetWritable(false); JSObject::DefineOwnProperty(thread, obj3, key1, desc); - EXPECT_TRUE(TaggedArray::Cast(obj3->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(TaggedArray::Cast(obj3->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); // test delete element JSHandle obj4 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread, JSHandle(obj4), key0, key0); JSObject::SetProperty(thread, JSHandle(obj4), key1, key1); JSObject::SetProperty(thread, JSHandle(obj4), key2, key2); - EXPECT_TRUE(!TaggedArray::Cast(obj4->GetElements().GetTaggedObject())->IsDictionaryMode()); + EXPECT_TRUE(!TaggedArray::Cast(obj4->GetElements(thread).GetTaggedObject())->IsDictionaryMode()); JSHandle value1001(thread, JSTaggedValue(1001)); JSHandle obj100 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); @@ -973,24 +973,24 @@ HWTEST_F_L0(JSObjectTest, EnableProtoChangeMarker) JSHandle obj1Class(thread, obj1->GetJSHClass()); JSHandle obj2Class(thread, obj2->GetJSHClass()); - JSTaggedValue obj2Marker = obj2Class->GetProtoChangeMarker(); + JSTaggedValue obj2Marker = obj2Class->GetProtoChangeMarker(thread); EXPECT_TRUE(obj2Marker.IsProtoChangeMarker()); bool hasChanged2 = ProtoChangeMarker::Cast(obj2Marker.GetTaggedObject())->GetHasChanged(); EXPECT_TRUE(!hasChanged2); - JSTaggedValue obj1Marker = obj1Class->GetProtoChangeMarker(); + JSTaggedValue obj1Marker = obj1Class->GetProtoChangeMarker(thread); EXPECT_TRUE(!obj1Marker.IsProtoChangeMarker()); - JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); - JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); - JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(!listeners1.IsUndefined()); - JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners2.IsUndefined()); uint32_t index = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue listenersResult = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index); + JSTaggedValue listenersResult = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(thread, index); EXPECT_TRUE(listenersResult == obj2Class.GetTaggedValue()); } @@ -1044,34 +1044,34 @@ HWTEST_F_L0(JSObjectTest, BuildRegisterTree) EXPECT_TRUE(result5Marker->IsProtoChangeMarker()); EXPECT_TRUE(!(ProtoChangeMarker::Cast(result5Marker->GetTaggedObject())->GetHasChanged())); - EXPECT_TRUE(obj4Class->GetProtoChangeMarker().IsProtoChangeMarker()); - EXPECT_TRUE(!obj6Class->GetProtoChangeMarker().IsProtoChangeMarker()); + EXPECT_TRUE(obj4Class->GetProtoChangeMarker(thread).IsProtoChangeMarker()); + EXPECT_TRUE(!obj6Class->GetProtoChangeMarker(thread).IsProtoChangeMarker()); JSHandle result7Marker = JSHClass::EnableProtoChangeMarker(thread, obj7Class); EXPECT_TRUE(result7Marker->IsProtoChangeMarker()); EXPECT_TRUE(!(ProtoChangeMarker::Cast(result7Marker->GetTaggedObject())->GetHasChanged())); - JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); - JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners1Value != JSTaggedValue(0)); JSHandle listeners1(thread, listeners1Value.GetTaggedObject()); - JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); uint32_t index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners1->Get(index2) == obj2Class.GetTaggedValue()); + EXPECT_TRUE(listeners1->Get(thread, index2) == obj2Class.GetTaggedValue()); - JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners2Value != JSTaggedValue(0)); JSHandle listeners2(thread, listeners2Value.GetTaggedObject()); - JSTaggedValue protoDetails4 = obj4Class->GetProtoChangeDetails(); - JSTaggedValue protoDetails6 = obj6Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails4 = obj4Class->GetProtoChangeDetails(thread); + JSTaggedValue protoDetails6 = obj6Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails4.IsProtoChangeDetails()); EXPECT_TRUE(protoDetails6.IsProtoChangeDetails()); uint32_t index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners2->Get(index4) == obj4Class.GetTaggedValue()); + EXPECT_TRUE(listeners2->Get(thread, index4) == obj4Class.GetTaggedValue()); uint32_t index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners2->Get(index6) == obj6Class.GetTaggedValue()); + EXPECT_TRUE(listeners2->Get(thread, index6) == obj6Class.GetTaggedValue()); EXPECT_TRUE(listeners1->GetEnd() == 1U); EXPECT_TRUE(listeners2->GetEnd() == 2U); @@ -1126,27 +1126,27 @@ HWTEST_F_L0(JSObjectTest, NoticeThroughChain) JSHClass::NoticeThroughChain(thread, obj2Class); JSHClass::UnregisterOnProtoChain(thread, obj2Class); - JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); - JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners1Value != JSTaggedValue(0)); JSHandle listeners1(thread, listeners1Value.GetTaggedObject()); - uint32_t holeIndex = ChangeListener::CheckHole(listeners1); + uint32_t holeIndex = ChangeListener::CheckHole(thread, listeners1); EXPECT_TRUE(holeIndex == 0U); - JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); - JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners2Value = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners2Value != JSTaggedValue(0)); uint32_t index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); - EXPECT_TRUE(listeners1->Get(index2).IsHole()); + EXPECT_TRUE(listeners1->Get(thread, index2).IsHole()); - JSTaggedValue obj6Marker = obj6Class->GetProtoChangeMarker(); + JSTaggedValue obj6Marker = obj6Class->GetProtoChangeMarker(thread); EXPECT_TRUE(obj6Marker.IsProtoChangeMarker()); bool hasChanged6 = ProtoChangeMarker::Cast(obj6Marker.GetTaggedObject())->GetHasChanged(); EXPECT_TRUE(hasChanged6); - JSTaggedValue obj4Marker = obj4Class->GetProtoChangeMarker(); + JSTaggedValue obj4Marker = obj4Class->GetProtoChangeMarker(thread); EXPECT_TRUE(obj4Marker.IsProtoChangeMarker()); bool hasChanged4 = ProtoChangeMarker::Cast(obj4Marker.GetTaggedObject())->GetHasChanged(); EXPECT_TRUE(hasChanged4); @@ -1201,32 +1201,32 @@ HWTEST_F_L0(JSObjectTest, ChangeProtoAndNoticeTheChain) JSHandle obj4Class(thread, obj4->GetJSHClass()); JSHandle obj6Class(thread, obj6->GetJSHClass()); - JSTaggedValue obj6Marker = obj6Class->GetProtoChangeMarker(); + JSTaggedValue obj6Marker = obj6Class->GetProtoChangeMarker(thread); EXPECT_TRUE(obj6Marker.IsProtoChangeMarker()); bool hasChanged6 = ProtoChangeMarker::Cast(obj6Marker.GetTaggedObject())->GetHasChanged(); EXPECT_TRUE(hasChanged6); - JSTaggedValue obj4Marker = obj4Class->GetProtoChangeMarker(); + JSTaggedValue obj4Marker = obj4Class->GetProtoChangeMarker(thread); EXPECT_TRUE(obj4Marker.IsProtoChangeMarker()); bool hasChanged4 = ProtoChangeMarker::Cast(obj4Marker.GetTaggedObject())->GetHasChanged(); EXPECT_TRUE(hasChanged4); - JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails1 = obj1Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails1.IsProtoChangeDetails()); - JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails2 = obj2Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails2.IsProtoChangeDetails()); - JSTaggedValue protoDetails3 = obj3Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails3 = obj3Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails3.IsProtoChangeDetails()); - JSTaggedValue protoDetails4 = obj4Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails4 = obj4Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails4.IsProtoChangeDetails()); - JSTaggedValue protoDetails6 = obj6Class->GetProtoChangeDetails(); + JSTaggedValue protoDetails6 = obj6Class->GetProtoChangeDetails(thread); EXPECT_TRUE(protoDetails6.IsProtoChangeDetails()); - JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners1 = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners1 != JSTaggedValue(0)); - JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners2 != JSTaggedValue(0)); - JSTaggedValue listeners3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetChangeListener(); + JSTaggedValue listeners3 = ProtoChangeDetails::Cast(protoDetails3.GetTaggedObject())->GetChangeListener(thread); EXPECT_TRUE(listeners3 != JSTaggedValue(0)); uint32_t index2 = ProtoChangeDetails::Cast(protoDetails2.GetTaggedObject())->GetRegisterIndex(); @@ -1234,10 +1234,10 @@ HWTEST_F_L0(JSObjectTest, ChangeProtoAndNoticeTheChain) uint32_t index4 = ProtoChangeDetails::Cast(protoDetails4.GetTaggedObject())->GetRegisterIndex(); uint32_t index6 = ProtoChangeDetails::Cast(protoDetails6.GetTaggedObject())->GetRegisterIndex(); - JSTaggedValue result2 = ChangeListener::Cast(listeners3.GetTaggedObject())->Get(index2); - JSTaggedValue result3 = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(index3); - JSTaggedValue result4 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index4); - JSTaggedValue result6 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(index6); + JSTaggedValue result2 = ChangeListener::Cast(listeners3.GetTaggedObject())->Get(thread, index2); + JSTaggedValue result3 = ChangeListener::Cast(listeners1.GetTaggedObject())->Get(thread, index3); + JSTaggedValue result4 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(thread, index4); + JSTaggedValue result6 = ChangeListener::Cast(listeners2.GetTaggedObject())->Get(thread, index6); EXPECT_TRUE(result2 == obj2Class.GetTaggedValue()); EXPECT_TRUE(result3 == obj3Class.GetTaggedValue()); @@ -1251,14 +1251,14 @@ HWTEST_F_L0(JSObjectTest, NativePointerField) JSHandle objFunc(thread, JSObjectTestCreate(thread)); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); ECMAObject::SetHash(thread, 87, JSHandle::Cast(obj)); - EXPECT_TRUE(obj->GetHash() == 87); + EXPECT_TRUE(obj->GetHash(thread) == 87); ECMAObject::SetNativePointerFieldCount(thread, obj, 1); char array[] = "Hello World!"; ECMAObject::SetNativePointerField(thread, obj, 0, array, nullptr, nullptr); - int32_t count = obj->GetNativePointerFieldCount(); + int32_t count = obj->GetNativePointerFieldCount(thread); EXPECT_TRUE(count == 1); - void *pointer = obj->GetNativePointerField(0); + void *pointer = obj->GetNativePointerField(thread, 0); EXPECT_TRUE(pointer == array); } @@ -1298,10 +1298,10 @@ HWTEST_F_L0(JSObjectTest, UpdateWeakTransitions) JSObject::SetProperty(thread, obj1, keyA, JSHandle(thread, JSTaggedValue(1))); JSObject::SetProperty(thread, obj2, keyB, JSHandle(thread, JSTaggedValue(2))); - EXPECT_TRUE(hc0->GetTransitions().IsTaggedArray()); - EXPECT_EQ(hc0->FindTransitions(keyA.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), + EXPECT_TRUE(hc0->GetTransitions(thread).IsTaggedArray()); + EXPECT_EQ(hc0->FindTransitions(thread, keyA.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), obj1->GetClass()); - EXPECT_EQ(hc0->FindTransitions(keyB.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), + EXPECT_EQ(hc0->FindTransitions(thread, keyB.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), obj2->GetClass()); hca.Update(JSTaggedValue(obj1->GetClass())); hcb.Update(JSTaggedValue(obj2->GetClass())); @@ -1316,9 +1316,9 @@ HWTEST_F_L0(JSObjectTest, UpdateWeakTransitions) // collect hc1, hc2 vm->CollectGarbage(TriggerGCType::FULL_GC); - EXPECT_EQ(hc0->FindTransitions(keyA.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), + EXPECT_EQ(hc0->FindTransitions(thread, keyA.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), hca.GetObject()); - EXPECT_EQ(hc0->FindTransitions(keyB.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), + EXPECT_EQ(hc0->FindTransitions(thread, keyB.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), hcb.GetObject()); JSHandle obj3 = factory->NewJSObject(hc0); @@ -1330,10 +1330,10 @@ HWTEST_F_L0(JSObjectTest, UpdateWeakTransitions) JSObject::SetProperty(thread, obj3, keyA, JSHandle(thread, JSTaggedValue(5))); JSObject::SetProperty(thread, obj4, keyB, JSHandle(thread, JSTaggedValue(6))); - EXPECT_TRUE(hc0->GetTransitions().IsTaggedArray()); - EXPECT_EQ(hc0->FindTransitions(keyA.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), + EXPECT_TRUE(hc0->GetTransitions(thread).IsTaggedArray()); + EXPECT_EQ(hc0->FindTransitions(thread, keyA.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), obj3->GetClass()); - EXPECT_EQ(hc0->FindTransitions(keyB.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), + EXPECT_EQ(hc0->FindTransitions(thread, keyB.GetTaggedValue(), attr.GetTaggedValue(), Representation::NONE), obj4->GetClass()); EXPECT_EQ(obj3->GetClass(), hca.GetObject()); EXPECT_EQ(obj4->GetClass(), hcb.GetObject()); diff --git a/ecmascript/tests/js_plural_rules_test.cpp b/ecmascript/tests/js_plural_rules_test.cpp index e68c778e91..af720ae72f 100644 --- a/ecmascript/tests/js_plural_rules_test.cpp +++ b/ecmascript/tests/js_plural_rules_test.cpp @@ -43,10 +43,10 @@ HWTEST_F_L0(JSPluralRulesTest, GetIcuPluralRules) JSHandle stringValue1 = intl::LocaleHelper::UStringToString(thread, result1); JSPluralRules::SetIcuPluralRules(thread, pluralRules, *icuPluralRules, JSPluralRules::FreeIcuPluralRules); - icu::PluralRules *getPluralRules = pluralRules->GetIcuPluralRules(); + icu::PluralRules *getPluralRules = pluralRules->GetIcuPluralRules(thread); icu::UnicodeString result2 = getPluralRules->select(0); JSHandle stringValue2 = intl::LocaleHelper::UStringToString(thread, result2); - EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(*stringValue1, *stringValue2), true); + EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(thread, *stringValue1, *stringValue2), true); delete icuPluralRules; } @@ -67,14 +67,14 @@ HWTEST_F_L0(JSPluralRulesTest, BuildLocaleSet) JSHandle localeSet = JSPluralRules::BuildLocaleSet(thread, icuAvailableLocales); EXPECT_EQ(localeSet->GetLength(), 4U); - resultStr = JSHandle(thread, localeSet->Get(0).GetTaggedObject()); - EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(*resultStr, *localeStr4), true); - resultStr = JSHandle(thread, localeSet->Get(1).GetTaggedObject()); - EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(*resultStr, *localeStr1), true); - resultStr = JSHandle(thread, localeSet->Get(2).GetTaggedObject()); - EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(*resultStr, *localeStr3), true); - resultStr = JSHandle(thread, localeSet->Get(3).GetTaggedObject()); - EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(*resultStr, *localeStr2), true); + resultStr = JSHandle(thread, localeSet->Get(thread, 0).GetTaggedObject()); + EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(thread, *resultStr, *localeStr4), true); + resultStr = JSHandle(thread, localeSet->Get(thread, 1).GetTaggedObject()); + EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(thread, *resultStr, *localeStr1), true); + resultStr = JSHandle(thread, localeSet->Get(thread, 2).GetTaggedObject()); + EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(thread, *resultStr, *localeStr3), true); + resultStr = JSHandle(thread, localeSet->Get(thread, 3).GetTaggedObject()); + EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(thread, *resultStr, *localeStr2), true); } HWTEST_F_L0(JSPluralRulesTest, InitializePluralRules) @@ -91,15 +91,15 @@ HWTEST_F_L0(JSPluralRulesTest, InitializePluralRules) JSPluralRules::InitializePluralRules(thread, pluralRules, localeStr, optionHandle); EXPECT_TRUE(*initPluralRules != nullptr); - JSHandle resultLocaleStr(thread, initPluralRules->GetLocale().GetTaggedObject()); - EXPECT_STREQ("en", EcmaStringAccessor(resultLocaleStr).ToCString().c_str()); + JSHandle resultLocaleStr(thread, initPluralRules->GetLocale(thread).GetTaggedObject()); + EXPECT_STREQ("en", EcmaStringAccessor(resultLocaleStr).ToCString(thread).c_str()); EXPECT_EQ(initPluralRules->GetType(), TypeOption::CARDINAL); EXPECT_EQ(initPluralRules->GetRoundingType(), RoundingType::FRACTIONDIGITS); - EXPECT_EQ(initPluralRules->GetMinimumIntegerDigits().GetInt(), 1); // 1 : 1 default minimum integer - EXPECT_EQ(initPluralRules->GetMinimumFractionDigits().GetInt(), 0); // 0 : 0 default minimum fraction - EXPECT_EQ(initPluralRules->GetMaximumFractionDigits().GetInt(), 3); // 3 : 3 default maximum fraction - EXPECT_EQ(initPluralRules->GetMinimumSignificantDigits().GetInt(), 0); // 0 : 0 default minimum sigfraction - EXPECT_EQ(initPluralRules->GetMaximumSignificantDigits().GetInt(), 0); // 0 : 0 default maximum sigfraction + EXPECT_EQ(initPluralRules->GetMinimumIntegerDigits(thread).GetInt(), 1); // 1 : 1 default minimum integer + EXPECT_EQ(initPluralRules->GetMinimumFractionDigits(thread).GetInt(), 0); // 0 : 0 default minimum fraction + EXPECT_EQ(initPluralRules->GetMaximumFractionDigits(thread).GetInt(), 3); // 3 : 3 default maximum fraction + EXPECT_EQ(initPluralRules->GetMinimumSignificantDigits(thread).GetInt(), 0); // 0 : 0 default minimum sigfraction + EXPECT_EQ(initPluralRules->GetMaximumSignificantDigits(thread).GetInt(), 0); // 0 : 0 default maximum sigfraction } HWTEST_F_L0(JSPluralRulesTest, ResolvePlural) @@ -125,6 +125,6 @@ HWTEST_F_L0(JSPluralRulesTest, ResolvePlural) EXPECT_TRUE(*initPluralRules != nullptr); // resolve plural nan JSHandle resolveRules = JSPluralRules::ResolvePlural(thread, initPluralRules, n); - EXPECT_STREQ("other", EcmaStringAccessor(resolveRules).ToCString().c_str()); + EXPECT_STREQ("other", EcmaStringAccessor(resolveRules).ToCString(thread).c_str()); } } // namespace panda::test diff --git a/ecmascript/tests/js_promise_test.cpp b/ecmascript/tests/js_promise_test.cpp index 0d20ce92ad..5f8b7c805a 100644 --- a/ecmascript/tests/js_promise_test.cpp +++ b/ecmascript/tests/js_promise_test.cpp @@ -41,8 +41,8 @@ HWTEST_F_L0(JSPromiseTest, CreateResolvingFunctions) JSHandle jsPromise = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(promiseFunc), promiseFunc)); JSHandle reactions = JSPromise::CreateResolvingFunctions(thread, jsPromise); - JSHandle resolve(thread, reactions->GetResolveFunction()); - JSHandle reject(thread, reactions->GetRejectFunction()); + JSHandle resolve(thread, reactions->GetResolveFunction(thread)); + JSHandle reject(thread, reactions->GetRejectFunction(thread)); EXPECT_EQ(resolve->IsCallable(), true); EXPECT_EQ(reject->IsCallable(), true); } @@ -54,18 +54,18 @@ HWTEST_F_L0(JSPromiseTest, NewPromiseCapability) JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promise); - JSHandle newPromise(thread, capbility->GetPromise()); + JSHandle newPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::PENDING); - JSHandle resolve(thread, capbility->GetResolve()); - JSHandle reject(thread, capbility->GetReject()); + JSHandle resolve(thread, capbility->GetResolve(thread)); + JSHandle reject(thread, capbility->GetReject(thread)); EXPECT_EQ(resolve.GetTaggedValue().IsCallable(), true); EXPECT_EQ(resolve.GetTaggedValue().IsCallable(), true); - JSHandle resolvedPromise(thread, resolve->GetPromise()); - JSHandle rejectedPromise(thread, reject->GetPromise()); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise.GetTaggedValue(), resolvedPromise.GetTaggedValue()), true); - EXPECT_EQ(JSTaggedValue::SameValue(newPromise.GetTaggedValue(), rejectedPromise.GetTaggedValue()), true); + JSHandle resolvedPromise(thread, resolve->GetPromise(thread)); + JSHandle rejectedPromise(thread, reject->GetPromise(thread)); + EXPECT_EQ(JSTaggedValue::SameValue(thread, newPromise.GetTaggedValue(), resolvedPromise.GetTaggedValue()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, newPromise.GetTaggedValue(), rejectedPromise.GetTaggedValue()), true); } HWTEST_F_L0(JSPromiseTest, FullFillPromise) @@ -74,17 +74,17 @@ HWTEST_F_L0(JSPromiseTest, FullFillPromise) JSHandle env = ecmaVM->GetGlobalEnv(); JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promise); - JSHandle newPromise(thread, capbility->GetPromise()); + JSHandle newPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(newPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(newPromise->GetPromiseResult(thread).IsUndefined(), true); - JSHandle resolve(thread, capbility->GetResolve()); + JSHandle resolve(thread, capbility->GetResolve(thread)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); 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); + EXPECT_EQ(JSTaggedValue::SameValue(thread, newPromise->GetPromiseResult(thread), JSTaggedValue(33)), true); } HWTEST_F_L0(JSPromiseTest, RejectPromise) @@ -93,16 +93,16 @@ HWTEST_F_L0(JSPromiseTest, RejectPromise) JSHandle env = ecmaVM->GetGlobalEnv(); JSHandle promise = env->GetPromiseFunction(); JSHandle capbility = JSPromise::NewPromiseCapability(thread, promise); - JSHandle newPromise(thread, capbility->GetPromise()); + JSHandle newPromise(thread, capbility->GetPromise(thread)); EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::PENDING); - EXPECT_EQ(newPromise->GetPromiseResult().IsUndefined(), true); + EXPECT_EQ(newPromise->GetPromiseResult(thread).IsUndefined(), true); - JSHandle reject(thread, capbility->GetReject()); + JSHandle reject(thread, capbility->GetReject(thread)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); 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); + EXPECT_EQ(JSTaggedValue::SameValue(thread, newPromise->GetPromiseResult(thread), JSTaggedValue(44)), true); } } // namespace panda::test diff --git a/ecmascript/tests/js_proxy_test.cpp b/ecmascript/tests/js_proxy_test.cpp index 3bbb9614a5..edcc75979a 100644 --- a/ecmascript/tests/js_proxy_test.cpp +++ b/ecmascript/tests/js_proxy_test.cpp @@ -262,7 +262,7 @@ HWTEST_F_L0(JSProxyTest, DeleteProperty) EXPECT_TRUE(JSProxy::DeleteProperty(thread, proxyHandle, key)); PropertyDescriptor resDesc(thread); JSProxy::GetOwnProperty(thread, proxyHandle, key, resDesc); - EXPECT_TRUE(JSTaggedValue::SameValue(resDesc.GetValue().GetTaggedValue(), JSTaggedValue::Undefined())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, resDesc.GetValue().GetTaggedValue(), JSTaggedValue::Undefined())); // 2. handler has "deleteProperty" EcmaVM *vm = thread->GetEcmaVM(); @@ -295,7 +295,7 @@ HWTEST_F_L0(JSProxyTest, GetPrototypeOf) EXPECT_TRUE(targetHandle->IsECMAObject()); JSObject::SetPrototype(thread, JSHandle(targetHandle), proto); EXPECT_TRUE( - JSTaggedValue::SameValue(JSTaggedValue::GetPrototype(thread, targetHandle), proto.GetTaggedValue())); + JSTaggedValue::SameValue(thread, JSTaggedValue::GetPrototype(thread, targetHandle), proto.GetTaggedValue())); JSHandle handlerHandle(factory->NewJSObjectByConstructor(JSHandle(hclass), hclass)); EXPECT_TRUE(handlerHandle->IsECMAObject()); @@ -303,7 +303,7 @@ HWTEST_F_L0(JSProxyTest, GetPrototypeOf) JSHandle proxyHandle = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); EXPECT_TRUE(*proxyHandle != nullptr); - EXPECT_TRUE(JSTaggedValue::SameValue(JSProxy::GetPrototype(thread, proxyHandle), proto.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, JSProxy::GetPrototype(thread, proxyHandle), proto.GetTaggedValue())); // 2. handler has "GetPrototypeOf" EcmaVM *vm = thread->GetEcmaVM(); @@ -314,7 +314,7 @@ HWTEST_F_L0(JSProxyTest, GetPrototypeOf) JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); EXPECT_TRUE(*proxyHandle2 != nullptr); - EXPECT_TRUE(JSTaggedValue::SameValue(JSProxy::GetPrototype(thread, proxyHandle2), JSTaggedValue::Null())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, JSProxy::GetPrototype(thread, proxyHandle2), JSTaggedValue::Null())); } JSTaggedValue HandlerSetPrototype([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -340,7 +340,7 @@ HWTEST_F_L0(JSProxyTest, SetPrototypeOf) JSProxy::SetPrototype(thread, proxyHandle, proto); EXPECT_TRUE( - JSTaggedValue::SameValue(JSTaggedValue::GetPrototype(thread, targetHandle), proto.GetTaggedValue())); + JSTaggedValue::SameValue(thread, JSTaggedValue::GetPrototype(thread, targetHandle), proto.GetTaggedValue())); // 2. handler has "SetPrototypeOf" EcmaVM *vm = thread->GetEcmaVM(); @@ -476,7 +476,7 @@ HWTEST_F_L0(JSProxyTest, OwnPropertyKeys) EXPECT_TRUE(*proxyHandle != nullptr); JSHandle res = JSProxy::OwnPropertyKeys(thread, proxyHandle); - EXPECT_TRUE(JSTaggedValue::SameValue(res->Get(0), key.GetTaggedValue())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, res->Get(thread, 0), key.GetTaggedValue())); // 2. handler has "OwnPropertyKeys" EcmaVM *vm = thread->GetEcmaVM(); @@ -488,7 +488,7 @@ HWTEST_F_L0(JSProxyTest, OwnPropertyKeys) JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); EXPECT_TRUE(*proxyHandle2 != nullptr); JSHandle res2 = JSProxy::OwnPropertyKeys(thread, proxyHandle2); - EXPECT_TRUE(res2->GetLength() == 0U || !JSTaggedValue::SameValue(res2->Get(0), key.GetTaggedValue())); + EXPECT_TRUE(res2->GetLength() == 0U || !JSTaggedValue::SameValue(thread, res2->Get(thread, 0), key.GetTaggedValue())); } JSTaggedValue HandlerCall([[maybe_unused]] EcmaRuntimeCallInfo *argv) @@ -521,7 +521,7 @@ HWTEST_F_L0(JSProxyTest, Call) EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(proxyHandle), JSHandle(proxyHandle), undefined, 0); JSTaggedValue res = JSProxy::CallInternal(info); - EXPECT_TRUE(JSTaggedValue::SameValue(res, JSTaggedValue::True())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, res, JSTaggedValue::True())); // 2. handler has "Call" JSHandle funcKey = thread->GlobalConstants()->GetHandledApplyString(); @@ -535,7 +535,7 @@ HWTEST_F_L0(JSProxyTest, Call) EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(proxyHandle2), JSHandle(proxyHandle2), undefined, 0); JSTaggedValue res2 = JSProxy::CallInternal(runtimeInfo); - EXPECT_TRUE(JSTaggedValue::SameValue(res2, JSTaggedValue::False())); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, res2, JSTaggedValue::False())); } JSTaggedValue HandlerConstruct([[maybe_unused]] EcmaRuntimeCallInfo *argv) diff --git a/ecmascript/tests/js_relative_time_format_test.cpp b/ecmascript/tests/js_relative_time_format_test.cpp index 1446b21aea..73a08fad2b 100644 --- a/ecmascript/tests/js_relative_time_format_test.cpp +++ b/ecmascript/tests/js_relative_time_format_test.cpp @@ -41,10 +41,10 @@ HWTEST_F_L0(JSRelativeTimeFormatTest, InitializeRelativeTimeFormat) JSHandle undefinedOptions(thread, JSTaggedValue::Undefined()); JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relativeTimeFormat, locales, undefinedOptions); // Initialize attribute comparison - JSHandle numberingSystemStr(thread, relativeTimeFormat->GetNumberingSystem().GetTaggedObject()); - EXPECT_STREQ("latn", EcmaStringAccessor(numberingSystemStr).ToCString().c_str()); - JSHandle localeStr(thread, relativeTimeFormat->GetLocale().GetTaggedObject()); - EXPECT_STREQ("en", EcmaStringAccessor(localeStr).ToCString().c_str()); + JSHandle numberingSystemStr(thread, relativeTimeFormat->GetNumberingSystem(thread).GetTaggedObject()); + EXPECT_STREQ("latn", EcmaStringAccessor(numberingSystemStr).ToCString(thread).c_str()); + JSHandle localeStr(thread, relativeTimeFormat->GetLocale(thread).GetTaggedObject()); + EXPECT_STREQ("en", EcmaStringAccessor(localeStr).ToCString(thread).c_str()); EXPECT_EQ(NumericOption::ALWAYS, relativeTimeFormat->GetNumeric()); EXPECT_EQ(RelativeStyleOption::LONG, relativeTimeFormat->GetStyle()); } @@ -69,11 +69,11 @@ HWTEST_F_L0(JSRelativeTimeFormatTest, GetIcuRTFFormatter) // Set Icu RelativeDateTimeFormatter to Icu Field factory->NewJSIntlIcuData(relativeTimeFormat, rtfFormatter, JSRelativeTimeFormat::FreeIcuRTFFormatter); // Get Icu Field - icu::RelativeDateTimeFormatter *resultRelativeDateTimeFormatter = relativeTimeFormat->GetIcuRTFFormatter(); + icu::RelativeDateTimeFormatter *resultRelativeDateTimeFormatter = relativeTimeFormat->GetIcuRTFFormatter(thread); icu::UnicodeString result2 = resultRelativeDateTimeFormatter->formatNumericToValue(value, UDAT_REL_UNIT_YEAR, status).toString(status); JSHandle stringValue2 = intl::LocaleHelper::UStringToString(thread, result2); - EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(*stringValue1, *stringValue2), true); + EXPECT_EQ(EcmaStringAccessor::StringsAreEqual(thread, *stringValue1, *stringValue2), true); } HWTEST_F_L0(JSRelativeTimeFormatTest, UnwrapRelativeTimeFormat) @@ -97,7 +97,7 @@ HWTEST_F_L0(JSRelativeTimeFormatTest, UnwrapRelativeTimeFormat) // object has no Instance JSHandle unwrapNumberFormat1 = JSRelativeTimeFormat::UnwrapRelativeTimeFormat(thread, relativeTimeFormat); - EXPECT_TRUE(JSTaggedValue::SameValue(relativeTimeFormat, unwrapNumberFormat1)); + EXPECT_TRUE(JSTaggedValue::SameValue(thread, relativeTimeFormat, unwrapNumberFormat1)); // object has Instance JSHandle unwrapNumberFormat2 = JSRelativeTimeFormat::UnwrapRelativeTimeFormat(thread, disPlayNamesObj); diff --git a/ecmascript/tests/js_sendable_arraybuffer_test.cpp b/ecmascript/tests/js_sendable_arraybuffer_test.cpp index e7b89afa1c..b7af66b147 100644 --- a/ecmascript/tests/js_sendable_arraybuffer_test.cpp +++ b/ecmascript/tests/js_sendable_arraybuffer_test.cpp @@ -100,10 +100,10 @@ HWTEST_F_L0(JsSendableArrayBufferTest, AttachTest001) size_t length = 5; const JSHandle arrBuf = factory->NewJSSendableArrayBuffer(5); factory->NewJSSendableArrayBufferData(arrBuf, 5); - JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(); + JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(thread); arrBuf->Attach(thread, length + 1, taggedValue); ASSERT_EQ(arrBuf->GetArrayBufferByteLength(), 6U); - ASSERT_EQ(arrBuf->GetArrayBufferData().GetRawData(), taggedValue.GetRawData()); + ASSERT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), taggedValue.GetRawData()); } /** @@ -119,10 +119,10 @@ HWTEST_F_L0(JsSendableArrayBufferTest, AttachTest002) size_t length = 5; const JSHandle arrBuf = factory->NewJSSendableArrayBuffer(5); factory->NewJSSendableArrayBufferData(arrBuf, 5); - JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(); + JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(thread); arrBuf->Attach(thread, length + 1, taggedValue, true); ASSERT_EQ(arrBuf->GetArrayBufferByteLength(), 6U); - ASSERT_EQ(arrBuf->GetArrayBufferData().GetRawData(), taggedValue.GetRawData()); + ASSERT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), taggedValue.GetRawData()); } /** @@ -138,15 +138,15 @@ HWTEST_F_L0(JsSendableArrayBufferTest, DetachTest001) size_t length = 5; const JSHandle arrBuf = factory->NewJSSendableArrayBuffer(5); factory->NewJSSendableArrayBufferData(arrBuf, 5); - JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(); + JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(thread); arrBuf->Attach(thread, length + 1, taggedValue); ASSERT_EQ(arrBuf->GetArrayBufferByteLength(), 6U); - ASSERT_EQ(arrBuf->GetArrayBufferData().GetRawData(), taggedValue.GetRawData()); + ASSERT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), taggedValue.GetRawData()); arrBuf->Detach(thread); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 0U); - EXPECT_EQ(arrBuf->GetArrayBufferData().GetRawData(), JSTaggedValue::Null().GetRawData()); - EXPECT_TRUE(arrBuf->IsDetach()); + EXPECT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), JSTaggedValue::Null().GetRawData()); + EXPECT_TRUE(arrBuf->IsDetach(thread)); } /** @@ -162,15 +162,15 @@ HWTEST_F_L0(JsSendableArrayBufferTest, DetachTest002) size_t length = 5; const JSHandle arrBuf = factory->NewJSSendableArrayBuffer(5); factory->NewJSSendableArrayBufferData(arrBuf, 5); - JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(); + JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(thread); arrBuf->Attach(thread, length + 1, taggedValue, true); ASSERT_EQ(arrBuf->GetArrayBufferByteLength(), 6U); - ASSERT_EQ(arrBuf->GetArrayBufferData().GetRawData(), taggedValue.GetRawData()); + ASSERT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), taggedValue.GetRawData()); arrBuf->Detach(thread, true); EXPECT_EQ(arrBuf->GetArrayBufferByteLength(), 0U); - EXPECT_EQ(arrBuf->GetArrayBufferData().GetRawData(), JSTaggedValue::Null().GetRawData()); - EXPECT_TRUE(arrBuf->IsDetach()); + EXPECT_EQ(arrBuf->GetArrayBufferData(thread).GetRawData(), JSTaggedValue::Null().GetRawData()); + EXPECT_TRUE(arrBuf->IsDetach(thread)); } /** @@ -186,7 +186,7 @@ HWTEST_F_L0(JsSendableArrayBufferTest, DetachTest003) size_t length = 5; const JSHandle arrBuf = factory->NewJSSendableArrayBuffer(5); factory->NewJSSendableArrayBufferData(arrBuf, 5); - JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(); + JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(thread); arrBuf->Attach(thread, length + 1, taggedValue); arrBuf->Detach(thread); @@ -202,7 +202,7 @@ HWTEST_F_L0(JsSendableArrayBufferTest, AttachTest003) size_t length = 5; const JSHandle arrBuf = factory->NewJSSendableArrayBuffer(5); factory->NewJSSendableArrayBufferData(arrBuf, 5); - JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(); + JSTaggedValue taggedValue = arrBuf->GetArrayBufferData(thread); arrBuf->Attach(thread, length + 1, taggedValue, false); ASSERT_EQ(arrBuf->GetArrayBufferByteLength(), 6U); } diff --git a/ecmascript/tests/js_set_iterator_test.cpp b/ecmascript/tests/js_set_iterator_test.cpp index 20e15db65f..1e7f5173d8 100644 --- a/ecmascript/tests/js_set_iterator_test.cpp +++ b/ecmascript/tests/js_set_iterator_test.cpp @@ -55,7 +55,7 @@ HWTEST_F_L0(JSSetIteratorTest, CreateSetIterator) EXPECT_EQ(setIteratorValue1->IsJSSetIterator(), true); JSHandle setIterator1(setIteratorValue1); - EXPECT_EQ(JSTaggedValue::SameValue(setIterator1->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, setIterator1->GetIteratedSet(thread), jsSet->GetLinkedSet(thread)), true); EXPECT_EQ(setIterator1->GetNextIndex(), 0U); EXPECT_EQ(setIterator1->GetIterationKind(), IterationKind::KEY); @@ -64,7 +64,7 @@ HWTEST_F_L0(JSSetIteratorTest, CreateSetIterator) EXPECT_EQ(setIteratorValue2->IsJSSetIterator(), true); JSHandle setIterator2(setIteratorValue2); - EXPECT_EQ(JSTaggedValue::SameValue(setIterator2->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(JSTaggedValue::SameValue(thread, setIterator2->GetIteratedSet(thread), jsSet->GetLinkedSet(thread)), true); EXPECT_EQ(setIterator2->GetNextIndex(), 0U); EXPECT_EQ(setIterator2->GetIterationKind(), IterationKind::VALUE); } @@ -91,14 +91,14 @@ HWTEST_F_L0(JSSetIteratorTest, Update) 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())); + JSHandle setHandle1(thread, LinkedHashSet::Cast(jsSet1->GetLinkedSet(thread).GetTaggedObject())); + JSHandle setHandle2(thread, LinkedHashSet::Cast(jsSet2->GetLinkedSet(thread).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()); + LinkedHashSet *resultSet = LinkedHashSet::Cast(setIterator->GetIteratedSet(thread).GetTaggedObject()); EXPECT_TRUE(resultSet->Has(thread, keyHandle1.GetTaggedValue())); EXPECT_TRUE(resultSet->Has(thread, keyHandle2.GetTaggedValue())); EXPECT_TRUE(resultSet->Has(thread, keyHandle3.GetTaggedValue())); diff --git a/ecmascript/tests/js_set_test.cpp b/ecmascript/tests/js_set_test.cpp index ffb233d4e5..c21812e98f 100644 --- a/ecmascript/tests/js_set_test.cpp +++ b/ecmascript/tests/js_set_test.cpp @@ -79,13 +79,13 @@ HWTEST_F_L0(JSSetTest, DeleteAndGet) JSSet::Add(thread, set, key); EXPECT_TRUE(set->Has(thread, key.GetTaggedValue())); } - EXPECT_EQ(set->GetSize(), 40); + EXPECT_EQ(set->GetSize(thread), 40); // whether jsSet has delete key keyArray[3] = '1' + 8; JSHandle deleteKey(factory->NewFromASCII(keyArray)); JSSet::Delete(thread, set, deleteKey); EXPECT_FALSE(set->Has(thread, deleteKey.GetTaggedValue())); - EXPECT_EQ(set->GetSize(), 39); + EXPECT_EQ(set->GetSize(thread), 39); } HWTEST_F_L0(JSSetTest, Iterator) diff --git a/ecmascript/tests/js_shared_array_test.cpp b/ecmascript/tests/js_shared_array_test.cpp index 95d65424e0..60a9799f0d 100644 --- a/ecmascript/tests/js_shared_array_test.cpp +++ b/ecmascript/tests/js_shared_array_test.cpp @@ -200,8 +200,8 @@ HWTEST_F_L0(JSSharedArrayTest, LengthSetterTest003) EXPECT_TRUE(arr != nullptr); JSHandle self(thread, arr); auto *hclass = self->GetJSHClass(); - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, JSArray::LENGTH_INLINE_PROPERTY_INDEX)); attr.SetWritable(false); layoutInfo->SetNormalAttr(thread, 0, attr); JSHandle value(thread, JSTaggedValue(10)); @@ -225,8 +225,8 @@ HWTEST_F_L0(JSSharedArrayTest, LengthSetterTest004) EXPECT_TRUE(arr != nullptr); JSHandle self(thread, arr); auto *hclass = self->GetJSHClass(); - LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout().GetTaggedObject()); - PropertyAttributes attr(layoutInfo->GetAttr(JSArray::LENGTH_INLINE_PROPERTY_INDEX)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(hclass->GetLayout(thread).GetTaggedObject()); + PropertyAttributes attr(layoutInfo->GetAttr(thread, JSArray::LENGTH_INLINE_PROPERTY_INDEX)); attr.SetWritable(false); layoutInfo->SetNormalAttr(thread, 0, attr); JSHandle value(thread, JSTaggedValue(10)); @@ -265,7 +265,7 @@ HWTEST_F_L0(JSSharedArrayTest, CheckAndCopyArray) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle jsArray = factory->NewJSSArray(); - JSHandle prop(thread, jsArray->GetProperties()); + JSHandle prop(thread, jsArray->GetProperties(thread)); JSHClass* hclass = JSHandle(prop)->GetClass(); hclass->SetObjectType(JSType::COW_TAGGED_ARRAY); ASSERT_EQ(hclass->GetObjectType(), JSType::COW_TAGGED_ARRAY); diff --git a/ecmascript/tests/js_stable_array_test.cpp b/ecmascript/tests/js_stable_array_test.cpp index d2b142c732..7e9a5b9d43 100644 --- a/ecmascript/tests/js_stable_array_test.cpp +++ b/ecmascript/tests/js_stable_array_test.cpp @@ -129,7 +129,7 @@ HWTEST_F_L0(JSStableArrayTest, Pop) EXPECT_EQ(handleArr->GetArrayLength(), static_cast(lengthArr - i)); if (i != 5) { EXPECT_EQ(handleTagArr->GetLength(), static_cast(lengthArr)); - EXPECT_EQ(handleTagArr->Get(lengthArr - i), JSTaggedValue::Hole()); + EXPECT_EQ(handleTagArr->Get(thread, lengthArr - i), JSTaggedValue::Hole()); } else { EXPECT_EQ(handleTagArr->GetLength(), static_cast(lengthArr - i)); } @@ -191,14 +191,14 @@ HWTEST_F_L0(JSStableArrayTest, Splice) // Check the JSArray(in-out-parameter) changed through calling the Splice function. EXPECT_EQ(handleArr->GetArrayLength(), lengthArr - actualDeleteCount + countInsert); for (int32_t i = 0; i < offsetStartInsert; i++) { - EXPECT_EQ(handleTagArr->Get(i).GetNumber(), i * 10); + EXPECT_EQ(handleTagArr->Get(thread, i).GetNumber(), i * 10); } - EXPECT_EQ(handleTagArr->Get(offsetStartInsert).GetNumber(), + EXPECT_EQ(handleTagArr->Get(thread, offsetStartInsert).GetNumber(), handleTagValInsertElement1.GetTaggedValue().GetNumber()); - EXPECT_EQ(handleTagArr->Get(offsetStartInsert + 1).GetNumber(), + EXPECT_EQ(handleTagArr->Get(thread, offsetStartInsert + 1).GetNumber(), handleTagValInsertElement2.GetTaggedValue().GetNumber()); for (int32_t i = offsetStartInsert + countInsert; i < lengthArr - actualDeleteCount + countInsert; i++) { - EXPECT_EQ(handleTagArr->Get(i).GetNumber(), (i + actualDeleteCount - countInsert) * 10); + EXPECT_EQ(handleTagArr->Get(thread, i).GetNumber(), (i + actualDeleteCount - countInsert) * 10); } } @@ -229,10 +229,10 @@ HWTEST_F_L0(JSStableArrayTest, Shift) EXPECT_EQ(JSStableArray::Shift(handleArr, ecmaRuntimeCallInfo), JSTaggedValue(i * 10)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(handleArr->GetArrayLength(), static_cast(lengthArr - (i + 1))); - EXPECT_EQ(handleTagArr->Get(0), JSTaggedValue((i + 1) * 10)); + EXPECT_EQ(handleTagArr->Get(thread, 0), JSTaggedValue((i + 1) * 10)); if (i != 4) { EXPECT_EQ(handleTagArr->GetLength(), static_cast(lengthArr)); - EXPECT_EQ(handleTagArr->Get(lengthArr - (i + 1)), JSTaggedValue::Hole()); + EXPECT_EQ(handleTagArr->Get(thread, lengthArr - (i + 1)), JSTaggedValue::Hole()); continue; } EXPECT_EQ(handleTagArr->GetLength(), static_cast(lengthArr - (i + 1))); @@ -266,7 +266,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_NumberElements_UndefinedSep) TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), "0,1,2,3,4,5,6,7,8,9"); + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "0,1,2,3,4,5,6,7,8,9"); EXPECT_FALSE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); } @@ -298,7 +298,8 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_UndefinedSep) TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), "abc,abc,abc,abc,abc,abc,abc,abc,abc,abc"); + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), + "abc,abc,abc,abc,abc,abc,abc,abc,abc,abc"); EXPECT_FALSE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); } @@ -329,7 +330,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_NumberElements_DefinedSep) TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), "0^1^2^3^4^5^6^7^8^9"); + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "0^1^2^3^4^5^6^7^8^9"); EXPECT_FALSE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); } @@ -364,7 +365,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_DefinedSep) TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "a <> a <> a <> a <> a <> a <> a <> a <> a <> a"); EXPECT_FALSE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); } @@ -391,7 +392,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_ManyTiny) JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); // 256 x a - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @@ -400,7 +401,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_ManyTiny) sep = ","; handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); JSHandle handleEcmaStrRet2(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet2).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet2).ToCString(thread).c_str(), "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a," "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a," "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a," @@ -435,7 +436,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_LargeString) } JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @@ -467,7 +468,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_LargeString2) JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," @@ -510,7 +511,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_LargeString3) JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb," "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc," @@ -539,7 +540,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_Stack) JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); // 32 x a - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a"); EXPECT_FALSE(EcmaStringAccessor(handleEcmaStrRet).IsTreeString()); } @@ -565,7 +566,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_Stack1) // sep is Undefined JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa," @@ -593,7 +594,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_Vector) JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); // 128 x a - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a," "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a," "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a," @@ -622,7 +623,7 @@ HWTEST_F_L0(JSStableArrayTest, Join_StringElements_Vector1) } JSHandle handleTagValEcmaStrRet = CallJoin(handleTagArr, sep, lengthArr); JSHandle handleEcmaStrRet(handleTagValEcmaStrRet); - EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString().c_str(), + EXPECT_STREQ(EcmaStringAccessor(handleEcmaStrRet).ToCString(thread).c_str(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @@ -781,7 +782,7 @@ HWTEST_F_L0(JSStableArrayTest, With) JSHandle(thread, JSTaggedValue(INT_VALUE_666))); JSHandle destTaggedValue(thread, resultArr); JSHandle destArr(destTaggedValue); - JSHandle destTaggedArr(thread, TaggedArray::Cast(destArr->GetElements().GetTaggedObject())); + JSHandle destTaggedArr(thread, TaggedArray::Cast(destArr->GetElements(thread).GetTaggedObject())); for (uint32_t i = 0; i < ARRAY_LENGTH_4; ++i) { JSHandle arrObjHandle(handleArr); EXPECT_EQ(ElementAccessor::Get(thread, arrObjHandle, i).GetNumber(), i); diff --git a/ecmascript/tests/js_symbol_test.cpp b/ecmascript/tests/js_symbol_test.cpp index 005217ae6d..99da646492 100644 --- a/ecmascript/tests/js_symbol_test.cpp +++ b/ecmascript/tests/js_symbol_test.cpp @@ -28,23 +28,23 @@ HWTEST_F_L0(JSSymbolTest, SymbolCreate) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle normallSymbol = factory->NewJSSymbol(); EXPECT_TRUE(*normallSymbol != nullptr); - EXPECT_TRUE(normallSymbol->GetDescription().IsUndefined()); + EXPECT_TRUE(normallSymbol->GetDescription(thread).IsUndefined()); JSHandle privateSymbol = factory->NewPrivateSymbol(); EXPECT_TRUE(*privateSymbol != nullptr); EXPECT_TRUE(privateSymbol->IsPrivate()); - EXPECT_TRUE(privateSymbol->GetDescription().IsUndefined()); + EXPECT_TRUE(privateSymbol->GetDescription(thread).IsUndefined()); JSHandle symbolName(factory->NewFromASCII("hello world")); JSHandle privateNameSymbol = factory->NewPrivateNameSymbol(symbolName); EXPECT_TRUE(*privateNameSymbol != nullptr); EXPECT_TRUE(privateNameSymbol->IsPrivateNameSymbol()); - EXPECT_FALSE(privateNameSymbol->GetDescription().IsUndefined()); + EXPECT_FALSE(privateNameSymbol->GetDescription(thread).IsUndefined()); JSHandle wellKnowSymbol = factory->NewWellKnownSymbol(symbolName); EXPECT_TRUE(*wellKnowSymbol != nullptr); EXPECT_TRUE(wellKnowSymbol->IsWellKnownSymbol()); - EXPECT_FALSE(wellKnowSymbol->GetDescription().IsUndefined()); + EXPECT_FALSE(wellKnowSymbol->GetDescription(thread).IsUndefined()); } HWTEST_F_L0(JSSymbolTest, SymbolEqual) @@ -59,17 +59,17 @@ HWTEST_F_L0(JSSymbolTest, SymbolEqual) JSSymbol *helloWord1Symbol = JSSymbol::Cast(helloWord1SymbolVal->GetTaggedObject()); JSSymbol *helloWord2Symbol = JSSymbol::Cast(helloWord2SymbolVal->GetTaggedObject()); JSSymbol *hiWordSymbol = JSSymbol::Cast(hiWordSymbolVal->GetTaggedObject()); - EXPECT_TRUE(JSSymbol::Equal(*helloWord1Symbol, *helloWord2Symbol)); + EXPECT_TRUE(JSSymbol::Equal(thread, *helloWord1Symbol, *helloWord2Symbol)); helloWord2Symbol->SetFlags(1); - EXPECT_FALSE(JSSymbol::Equal(*helloWord1Symbol, *helloWord2Symbol)); - EXPECT_FALSE(JSSymbol::Equal(*helloWord1Symbol, *hiWordSymbol)); + EXPECT_FALSE(JSSymbol::Equal(thread, *helloWord1Symbol, *helloWord2Symbol)); + EXPECT_FALSE(JSSymbol::Equal(thread, *helloWord1Symbol, *hiWordSymbol)); } HWTEST_F_L0(JSSymbolTest, ConvertToString001) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle symbol = factory->NewPublicSymbolWithChar("bbb"); - CString str = ConvertToString(symbol.GetTaggedValue()); + CString str = ConvertToString(thread, symbol.GetTaggedValue()); EXPECT_EQ(str, CString("bbb")); } @@ -80,7 +80,7 @@ HWTEST_F_L0(JSSymbolTest, ConvertToString002) symbol->SetDescription(thread, JSTaggedValue::Undefined()); symbol->SetFlags(0); symbol->SetHashField(0); - CString str = ConvertToString(symbol.GetTaggedValue()); + CString str = ConvertToString(thread, symbol.GetTaggedValue()); EXPECT_EQ(str, CString("Symbol()")); } } // namespace panda::test diff --git a/ecmascript/tests/js_tagged_queue_test.cpp b/ecmascript/tests/js_tagged_queue_test.cpp index 60e7b4b17b..6bd4faa3be 100644 --- a/ecmascript/tests/js_tagged_queue_test.cpp +++ b/ecmascript/tests/js_tagged_queue_test.cpp @@ -33,60 +33,60 @@ HWTEST_F_L0(JSTaggedQueueTest, Create) { JSHandle queue = thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0); EXPECT_TRUE(*queue != nullptr); - EXPECT_TRUE(queue->Empty()); - EXPECT_EQ(queue->Size(), 0U); - EXPECT_EQ(queue->Front(), JSTaggedValue::Hole()); - EXPECT_EQ(queue->Back(), JSTaggedValue::Hole()); + EXPECT_TRUE(queue->Empty(thread)); + EXPECT_EQ(queue->Size(thread), 0U); + EXPECT_EQ(queue->Front(thread), JSTaggedValue::Hole()); + EXPECT_EQ(queue->Back(thread), JSTaggedValue::Hole()); } HWTEST_F_L0(JSTaggedQueueTest, PopAndPush) { JSHandle queue = thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0); - EXPECT_TRUE(queue->Empty()); + EXPECT_TRUE(queue->Empty(thread)); JSHandle queue2(thread, TaggedQueue::Push(thread, queue, JSHandle(thread, JSTaggedValue(0)))); - EXPECT_FALSE(queue2->Empty()); - EXPECT_EQ(queue2->Size(), 1U); - EXPECT_EQ(queue2->Front(), JSTaggedValue(0)); - EXPECT_EQ(queue2->Back(), JSTaggedValue(0)); + EXPECT_FALSE(queue2->Empty(thread)); + EXPECT_EQ(queue2->Size(thread), 1U); + EXPECT_EQ(queue2->Front(thread), JSTaggedValue(0)); + EXPECT_EQ(queue2->Back(thread), JSTaggedValue(0)); JSHandle queue3(thread, TaggedQueue::Push(thread, queue2, JSHandle(thread, JSTaggedValue(1)))); - EXPECT_EQ(queue3->Size(), 2U); - EXPECT_EQ(queue3->Front(), JSTaggedValue(0)); - EXPECT_EQ(queue3->Back(), JSTaggedValue(1)); + EXPECT_EQ(queue3->Size(thread), 2U); + EXPECT_EQ(queue3->Front(thread), JSTaggedValue(0)); + EXPECT_EQ(queue3->Back(thread), JSTaggedValue(1)); EXPECT_NE(queue3.GetTaggedValue(), queue2.GetTaggedValue()); JSHandle queue4(thread, TaggedQueue::Push(thread, queue3, JSHandle(thread, JSTaggedValue(2)))); - EXPECT_EQ(queue4->Size(), 3U); - EXPECT_EQ(queue4->Front(), JSTaggedValue(0)); - EXPECT_EQ(queue4->Back(), JSTaggedValue(2)); + EXPECT_EQ(queue4->Size(thread), 3U); + EXPECT_EQ(queue4->Front(thread), JSTaggedValue(0)); + EXPECT_EQ(queue4->Back(thread), JSTaggedValue(2)); EXPECT_NE(queue4.GetTaggedValue(), queue3.GetTaggedValue()); JSHandle queue5(thread, TaggedQueue::Push(thread, queue4, JSHandle(thread, JSTaggedValue(3)))); - EXPECT_EQ(queue5->Size(), 4U); - EXPECT_EQ(queue5->Front(), JSTaggedValue(0)); - EXPECT_EQ(queue5->Back(), JSTaggedValue(3)); + EXPECT_EQ(queue5->Size(thread), 4U); + EXPECT_EQ(queue5->Front(thread), JSTaggedValue(0)); + EXPECT_EQ(queue5->Back(thread), JSTaggedValue(3)); EXPECT_NE(queue5.GetTaggedValue(), queue4.GetTaggedValue()); EXPECT_EQ(queue5->Pop(thread), JSTaggedValue(0)); - EXPECT_EQ(queue5->Size(), 3U); - EXPECT_EQ(queue5->Front(), JSTaggedValue(1)); + EXPECT_EQ(queue5->Size(thread), 3U); + EXPECT_EQ(queue5->Front(thread), JSTaggedValue(1)); EXPECT_EQ(queue5->Pop(thread), JSTaggedValue(1)); - EXPECT_EQ(queue5->Size(), 2U); - EXPECT_EQ(queue5->Front(), JSTaggedValue(2)); + EXPECT_EQ(queue5->Size(thread), 2U); + EXPECT_EQ(queue5->Front(thread), JSTaggedValue(2)); EXPECT_EQ(queue5->Pop(thread), JSTaggedValue(2)); - EXPECT_EQ(queue5->Size(), 1U); - EXPECT_EQ(queue5->Front(), JSTaggedValue(3)); + EXPECT_EQ(queue5->Size(thread), 1U); + EXPECT_EQ(queue5->Front(thread), JSTaggedValue(3)); EXPECT_EQ(queue5->Pop(thread), JSTaggedValue(3)); - EXPECT_EQ(queue5->Size(), 0U); - EXPECT_EQ(queue5->Front(), JSTaggedValue::Hole()); - EXPECT_TRUE(queue5->Empty()); + EXPECT_EQ(queue5->Size(thread), 0U); + EXPECT_EQ(queue5->Front(thread), JSTaggedValue::Hole()); + EXPECT_TRUE(queue5->Empty(thread)); } } // namespace panda::test diff --git a/ecmascript/tests/js_typed_array_test.cpp b/ecmascript/tests/js_typed_array_test.cpp index ffcb6a6a3a..5753275c93 100644 --- a/ecmascript/tests/js_typed_array_test.cpp +++ b/ecmascript/tests/js_typed_array_test.cpp @@ -101,8 +101,8 @@ HWTEST_F_L0(JSTypedArrayTest, ToPropKey_001) JSHandle handleEcmaStrPropKeyTo2 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo2); EXPECT_NE(0U, sizeof(handleUndefined)); EXPECT_NE(0U, sizeof(handleHole)); - CString uniCharArrTo1(EcmaStringAccessor(handleEcmaStrPropKeyTo1).ToCString()); - CString uniCharArrTo2(EcmaStringAccessor(handleEcmaStrPropKeyTo2).ToCString()); + CString uniCharArrTo1(EcmaStringAccessor(handleEcmaStrPropKeyTo1).ToCString(thread)); + CString uniCharArrTo2(EcmaStringAccessor(handleEcmaStrPropKeyTo2).ToCString(thread)); EXPECT_EQ(uniCharArrTo1[0], 'u'); EXPECT_EQ(uniCharArrTo1[1], 'n'); EXPECT_EQ(uniCharArrTo1[2], 'd'); @@ -138,10 +138,10 @@ HWTEST_F_L0(JSTypedArrayTest, ToPropKey_002) JSHandle handleEcmaStrPropKeyTo2 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo2); JSHandle handleEcmaStrPropKeyTo3 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo3); JSHandle handleEcmaStrPropKeyTo4 = JSHandle::Cast(hnadleTagValEcmaStrPropKeyTo4); - CString uniCharArrTo1(EcmaStringAccessor(handleEcmaStrPropKeyTo1).ToCString()); - CString uniCharArrTo2(EcmaStringAccessor(handleEcmaStrPropKeyTo2).ToCString()); - CString uniCharArrTo3(EcmaStringAccessor(handleEcmaStrPropKeyTo3).ToCString()); - CString uniCharArrTo4(EcmaStringAccessor(handleEcmaStrPropKeyTo4).ToCString()); + CString uniCharArrTo1(EcmaStringAccessor(handleEcmaStrPropKeyTo1).ToCString(thread)); + CString uniCharArrTo2(EcmaStringAccessor(handleEcmaStrPropKeyTo2).ToCString(thread)); + CString uniCharArrTo3(EcmaStringAccessor(handleEcmaStrPropKeyTo3).ToCString(thread)); + CString uniCharArrTo4(EcmaStringAccessor(handleEcmaStrPropKeyTo4).ToCString(thread)); EXPECT_EQ(uniCharArrTo1[0], '0'); EXPECT_EQ(uniCharArrTo1[1], 0); // "0" EXPECT_EQ(uniCharArrTo2[0], '-'); @@ -228,9 +228,10 @@ HWTEST_F_L0(JSTypedArrayTest, SetViewedArrayBufferOrByteArray) for (size_t i = 0; i < cVecJSType.size(); i++) { JSHandle handleTypedArray = CreateNumberTypedArray(thread, cVecJSType.at(i)); - EXPECT_EQ(handleTypedArray->GetViewedArrayBufferOrByteArray(), JSTaggedValue::Undefined()); + EXPECT_EQ(handleTypedArray->GetViewedArrayBufferOrByteArray(thread), JSTaggedValue::Undefined()); handleTypedArray->SetViewedArrayBufferOrByteArray(thread, handleTagValArrayBufferFrom); - EXPECT_EQ(handleTypedArray->GetViewedArrayBufferOrByteArray(), handleTagValArrayBufferFrom.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetViewedArrayBufferOrByteArray(thread), + handleTagValArrayBufferFrom.GetTaggedValue()); } } @@ -252,9 +253,9 @@ HWTEST_F_L0(JSTypedArrayTest, SetTypedArrayName) for (size_t i = 0; i < cVecJSType.size(); i++) { JSHandle handleTypedArray = CreateNumberTypedArray(thread, cVecJSType.at(i)); - EXPECT_EQ(handleTypedArray->GetTypedArrayName(), JSTaggedValue::Undefined()); + EXPECT_EQ(handleTypedArray->GetTypedArrayName(thread), JSTaggedValue::Undefined()); handleTypedArray->SetTypedArrayName(thread, handleTagValEcmaStrNameFrom); - EXPECT_EQ(handleTypedArray->GetTypedArrayName(), handleTagValEcmaStrNameFrom.GetTaggedValue()); + EXPECT_EQ(handleTypedArray->GetTypedArrayName(thread), handleTagValEcmaStrNameFrom.GetTaggedValue()); } } @@ -1276,7 +1277,7 @@ HWTEST_F_L0(JSTypedArrayTest, FastCopyElementToArray_TypedArray) } EXPECT_TRUE(JSTypedArray::FastCopyElementToArray(thread, handleTagValTypedArrayFrom, handleTagArrTo)); for (int i = 0; i < numElementsTypedArray; i++) { - EXPECT_EQ(handleTagArrTo->Get(i), handleTagValValueSet.GetTaggedValue()); + EXPECT_EQ(handleTagArrTo->Get(thread, i), handleTagValValueSet.GetTaggedValue()); } } } @@ -1413,9 +1414,9 @@ HWTEST_F_L0(JSTypedArrayTest, GetOffHeapBuffer) TestHelper::TearDownFrame(thread, prev); JSHandle typedArray(int8Array); - ASSERT_TRUE(typedArray->GetViewedArrayBufferOrByteArray().IsByteArray()); + ASSERT_TRUE(typedArray->GetViewedArrayBufferOrByteArray(thread).IsByteArray()); JSTypedArray::GetOffHeapBuffer(thread, typedArray); - ASSERT_TRUE(typedArray->GetViewedArrayBufferOrByteArray().IsArrayBuffer()); + ASSERT_TRUE(typedArray->GetViewedArrayBufferOrByteArray(thread).IsArrayBuffer()); JSTaggedValue data1 = JSTypedArray::FastGetPropertyByIndex(thread, typedArray.GetTaggedValue(), 0, JSType::JS_INT8_ARRAY); JSTaggedValue data2 = JSTypedArray::FastGetPropertyByIndex(thread, typedArray.GetTaggedValue(), diff --git a/ecmascript/tests/layout_info_test.cpp b/ecmascript/tests/layout_info_test.cpp index ec0a0cb8f1..8446e3308a 100644 --- a/ecmascript/tests/layout_info_test.cpp +++ b/ecmascript/tests/layout_info_test.cpp @@ -45,8 +45,8 @@ HWTEST_F_L0(LayoutInfoTest, SetPropertyInit) EXPECT_TRUE(*layoutInfoHandle != nullptr); layoutInfoHandle->SetPropertyInit(thread, 0, key.GetTaggedValue(), defaultAttr); - EXPECT_EQ(layoutInfoHandle->GetKey(0), key.GetTaggedValue()); - EXPECT_EQ(layoutInfoHandle->GetAttr(0).GetNormalAttr(), static_cast(infoLength)); + EXPECT_EQ(layoutInfoHandle->GetKey(thread, 0), key.GetTaggedValue()); + EXPECT_EQ(layoutInfoHandle->GetAttr(thread, 0).GetNormalAttr(), static_cast(infoLength)); } HWTEST_F_L0(LayoutInfoTest, SetSortedIndex) @@ -63,8 +63,8 @@ HWTEST_F_L0(LayoutInfoTest, SetSortedIndex) layoutInfoHandle->SetPropertyInit(thread, 0, key1.GetTaggedValue(), defaultAttr); layoutInfoHandle->SetPropertyInit(thread, 1, key2.GetTaggedValue(), defaultAttr); layoutInfoHandle->SetSortedIndex(thread, 0, infoLength - 4); - EXPECT_EQ(layoutInfoHandle->GetSortedIndex(0), 1U); - EXPECT_EQ(layoutInfoHandle->GetSortedKey(0), key2.GetTaggedValue()); + EXPECT_EQ(layoutInfoHandle->GetSortedIndex(thread, 0), 1U); + EXPECT_EQ(layoutInfoHandle->GetSortedKey(thread, 0), key2.GetTaggedValue()); } HWTEST_F_L0(LayoutInfoTest, FindElementWithCache) @@ -138,15 +138,15 @@ void GetAllKeysCommon(JSThread *thread, bool enumKeys = false) if (enumKeys) { uint32_t keys = 0; layoutInfoHandle->GetAllEnumKeys(thread, infoLength, 0, keyArray, &keys); // 0: offset - EXPECT_EQ(keyArray->Get(0), key3.GetTaggedValue()); + EXPECT_EQ(keyArray->Get(thread, 0), key3.GetTaggedValue()); EXPECT_EQ(keys, 1U); } else { layoutInfoHandle->GetAllKeys(thread, infoLength, 0, *keyArray); // 0: offset - layoutInfoHandle->GetAllKeysForSerialization(infoLength, keyVector); + layoutInfoHandle->GetAllKeysForSerialization(thread, infoLength, keyVector); EXPECT_EQ(keyArray->GetLength(), keyVector.size()); for (int i = 0;i < infoLength; i++) { - bool result = JSTaggedValue::SameValue(keyArray->Get(i), keyVector[i]); + bool result = JSTaggedValue::SameValue(thread, keyArray->Get(thread, i), keyVector[i]); EXPECT_TRUE(result); } } diff --git a/ecmascript/tests/linked_hash_table_test.cpp b/ecmascript/tests/linked_hash_table_test.cpp index fafd747def..a6a814783c 100644 --- a/ecmascript/tests/linked_hash_table_test.cpp +++ b/ecmascript/tests/linked_hash_table_test.cpp @@ -77,8 +77,8 @@ HWTEST_F_L0(LinkedHashTableTest, addKeyAndValue) // test find() int entry1 = dictHandle->FindElement(thread, key1.GetTaggedValue()); - EXPECT_EQ(key1.GetTaggedValue(), dictHandle->GetKey(entry1)); - EXPECT_EQ(value1.GetTaggedValue(), dictHandle->GetValue(entry1)); + EXPECT_EQ(key1.GetTaggedValue(), dictHandle->GetKey(thread, entry1)); + EXPECT_EQ(value1.GetTaggedValue(), dictHandle->GetValue(thread, entry1)); dictHandle = LinkedHashMap::Set(thread, dictHandle, key2, value2); EXPECT_EQ(dictHandle->NumberOfElements(), 2); @@ -90,7 +90,7 @@ HWTEST_F_L0(LinkedHashTableTest, addKeyAndValue) JSHandle undefinedKey(thread, JSTaggedValue::Undefined()); dictHandle = LinkedHashMap::Set(thread, dictHandle, undefinedKey, value1); int entry2 = dictHandle->FindElement(thread, undefinedKey.GetTaggedValue()); - EXPECT_EQ(value1.GetTaggedValue(), dictHandle->GetValue(entry2)); + EXPECT_EQ(value1.GetTaggedValue(), dictHandle->GetValue(thread, entry2)); } HWTEST_F_L0(LinkedHashTableTest, SetaddKeyAndValue) diff --git a/ecmascript/tests/locale_helper_test.cpp b/ecmascript/tests/locale_helper_test.cpp index d32e690bcf..fabac2660f 100644 --- a/ecmascript/tests/locale_helper_test.cpp +++ b/ecmascript/tests/locale_helper_test.cpp @@ -38,19 +38,19 @@ HWTEST_F_L0(LocaleHelperTest, UStringToString) { icu::UnicodeString unicodeString1("GMT-12:00"); // times JSHandle ecmaString = LocaleHelper::UStringToString(thread, unicodeString1); - EXPECT_STREQ("GMT-12:00", EcmaStringAccessor(ecmaString).ToCString().c_str()); + EXPECT_STREQ("GMT-12:00", EcmaStringAccessor(ecmaString).ToCString(thread).c_str()); icu::UnicodeString unicodeString2("周日16:00:00–周五23:00:00"); // date ecmaString = LocaleHelper::UStringToString(thread, unicodeString2); - EXPECT_STREQ("周日16:00:00–周五23:00:00", EcmaStringAccessor(ecmaString).ToCString().c_str()); + EXPECT_STREQ("周日16:00:00–周五23:00:00", EcmaStringAccessor(ecmaString).ToCString(thread).c_str()); icu::UnicodeString unicodeString3("$654K"); // money ecmaString = LocaleHelper::UStringToString(thread, unicodeString3); - EXPECT_STREQ("$654K", EcmaStringAccessor(ecmaString).ToCString().c_str()); + EXPECT_STREQ("$654K", EcmaStringAccessor(ecmaString).ToCString(thread).c_str()); icu::UnicodeString unicodeString4("1 minute ago"); // moment ecmaString = LocaleHelper::UStringToString(thread, unicodeString4, 0, 2); - EXPECT_STREQ("1 ", EcmaStringAccessor(ecmaString).ToCString().c_str()); + EXPECT_STREQ("1 ", EcmaStringAccessor(ecmaString).ToCString(thread).c_str()); } /** @@ -73,8 +73,8 @@ HWTEST_F_L0(LocaleHelperTest, CanonicalizeLocaleList) // test locale is jslocale JSHandle localeArr = LocaleHelper::CanonicalizeLocaleList(thread, JSHandle(jsLocale)); EXPECT_EQ(localeArr->GetLength(), 1U); - JSHandle handleEcmaStr(thread, localeArr->Get(0)); - EXPECT_STREQ("fr-Latn-FR", EcmaStringAccessor(handleEcmaStr).ToCString().c_str()); + JSHandle handleEcmaStr(thread, localeArr->Get(thread, 0)); + EXPECT_STREQ("fr-Latn-FR", EcmaStringAccessor(handleEcmaStr).ToCString(thread).c_str()); // test locale is object JSArray *arr = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetObject(); JSHandle localeObj(thread, arr); @@ -91,10 +91,10 @@ HWTEST_F_L0(LocaleHelperTest, CanonicalizeLocaleList) // check canonicalized string localeArr = LocaleHelper::CanonicalizeLocaleList(thread, localeObj); EXPECT_EQ(localeArr->GetLength(), 2U); - JSHandle resultEcmaStr1(thread, localeArr->Get(0)); - EXPECT_STREQ("en-US", EcmaStringAccessor(resultEcmaStr1).ToCString().c_str()); - JSHandle resultEcmaStr2(thread, localeArr->Get(1)); - EXPECT_STREQ("en-GB", EcmaStringAccessor(resultEcmaStr2).ToCString().c_str()); + JSHandle resultEcmaStr1(thread, localeArr->Get(thread, 0)); + EXPECT_STREQ("en-US", EcmaStringAccessor(resultEcmaStr1).ToCString(thread).c_str()); + JSHandle resultEcmaStr2(thread, localeArr->Get(thread, 1)); + EXPECT_STREQ("en-GB", EcmaStringAccessor(resultEcmaStr2).ToCString(thread).c_str()); } /** @@ -111,15 +111,15 @@ HWTEST_F_L0(LocaleHelperTest, CanonicalizeUnicodeLocaleId) JSHandle locale = factory-> NewFromStdString("en-Us"); JSHandle canonicalizeLocaleId = LocaleHelper::CanonicalizeUnicodeLocaleId(thread, locale); - EXPECT_STREQ("en-US", EcmaStringAccessor(canonicalizeLocaleId).ToCString().c_str()); + EXPECT_STREQ("en-US", EcmaStringAccessor(canonicalizeLocaleId).ToCString(thread).c_str()); locale = factory-> NewFromStdString("kO-kore-kr"); canonicalizeLocaleId = LocaleHelper::CanonicalizeUnicodeLocaleId(thread, locale); - EXPECT_STREQ("ko-Kore-KR", EcmaStringAccessor(canonicalizeLocaleId).ToCString().c_str()); + EXPECT_STREQ("ko-Kore-KR", EcmaStringAccessor(canonicalizeLocaleId).ToCString(thread).c_str()); locale = factory-> NewFromStdString("id-u-co-pinyin-de-ID"); canonicalizeLocaleId = LocaleHelper::CanonicalizeUnicodeLocaleId(thread, locale); - EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(canonicalizeLocaleId).ToCString().c_str()); + EXPECT_STREQ("id-u-co-pinyin-de-id", EcmaStringAccessor(canonicalizeLocaleId).ToCString(thread).c_str()); // invalid locale uint16_t localeArr[] = {0x122, 0x104, 0x45, 0x72, 0x97, 0x110, 0x115, 0x45, 0x67, 0x78}; // zh-Hans-CN uint32_t localeArrLength = sizeof(localeArr) / sizeof(localeArr[0]); @@ -140,31 +140,31 @@ HWTEST_F_L0(LocaleHelperTest, ToLanguageTag) { icu::Locale icuLocale1("en", "Latn", "US", "collation=phonebk;currency=euro"); JSHandle languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale1); - EXPECT_STREQ("en-Latn-US-u-co-phonebk-cu-euro", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("en-Latn-US-u-co-phonebk-cu-euro", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); icu::Locale icuLocale2("zh", "Hans", "CN", "collation=phonebk;kn=true"); languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale2); - EXPECT_STREQ("zh-Hans-CN-u-co-phonebk-kn", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("zh-Hans-CN-u-co-phonebk-kn", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); icu::Locale icuLocale3("ja", "Jpan", "JP", "collation=phonebk;co=yes"); languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale3); - EXPECT_STREQ("ja-Jpan-JP-u-co", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("ja-Jpan-JP-u-co", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); icu::Locale icuLocale4("z", "CN"); // language is fault languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale4); - EXPECT_STREQ("und-CN", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("und-CN", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); icu::Locale icuLocale5("zh", "c"); // script is fault languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale5); - EXPECT_STREQ("zh-x-lvariant-c", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("zh-x-lvariant-c", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); icu::Locale icuLocale6("en", "Latn", "E"); // region is fault languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale6); - EXPECT_STREQ("en-Latn-x-lvariant-e", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("en-Latn-x-lvariant-e", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); icu::Locale icuLocale7("en", "Latn", "EG", "kf=yes"); // key value is fault languageTag = LocaleHelper::ToLanguageTag(thread, icuLocale7); - EXPECT_STREQ("en-Latn-EG-u-kf", EcmaStringAccessor(languageTag).ToCString().c_str()); + EXPECT_STREQ("en-Latn-EG-u-kf", EcmaStringAccessor(languageTag).ToCString(thread).c_str()); } /** @@ -179,22 +179,22 @@ HWTEST_F_L0(LocaleHelperTest, IsStructurallyValidLanguageTag) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // number-language JSHandle handleEcmaStr = factory->NewFromStdString("123-de"); - EXPECT_FALSE(LocaleHelper::IsStructurallyValidLanguageTag(handleEcmaStr)); + EXPECT_FALSE(LocaleHelper::IsStructurallyValidLanguageTag(thread, handleEcmaStr)); // only language(zh) handleEcmaStr = factory-> NewFromStdString("zh"); - EXPECT_TRUE(LocaleHelper::IsStructurallyValidLanguageTag(handleEcmaStr)); + EXPECT_TRUE(LocaleHelper::IsStructurallyValidLanguageTag(thread, handleEcmaStr)); // only language and script, region handleEcmaStr = factory-> NewFromStdString("zh-Hans-Cn"); - EXPECT_TRUE(LocaleHelper::IsStructurallyValidLanguageTag(handleEcmaStr)); + EXPECT_TRUE(LocaleHelper::IsStructurallyValidLanguageTag(thread, handleEcmaStr)); handleEcmaStr = factory-> NewFromStdString("ja-JP-u-ca-japanese"); - EXPECT_TRUE(LocaleHelper::IsStructurallyValidLanguageTag(handleEcmaStr)); + EXPECT_TRUE(LocaleHelper::IsStructurallyValidLanguageTag(thread, handleEcmaStr)); handleEcmaStr = factory-> NewFromStdString("语言脚本地区"); - EXPECT_FALSE(LocaleHelper::IsStructurallyValidLanguageTag(handleEcmaStr)); + EXPECT_FALSE(LocaleHelper::IsStructurallyValidLanguageTag(thread, handleEcmaStr)); handleEcmaStr = factory-> NewFromStdString("e-US"); - EXPECT_FALSE(LocaleHelper::IsStructurallyValidLanguageTag(handleEcmaStr)); + EXPECT_FALSE(LocaleHelper::IsStructurallyValidLanguageTag(thread, handleEcmaStr)); } /** @@ -208,19 +208,19 @@ HWTEST_F_L0(LocaleHelperTest, ConvertToStdString) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle handleEcmaStr = factory-> NewFromStdString("一二三四"); - std::string stdString = LocaleHelper::ConvertToStdString(handleEcmaStr); + std::string stdString = LocaleHelper::ConvertToStdString(thread, handleEcmaStr); EXPECT_STREQ(stdString.c_str(), "一二三四"); handleEcmaStr = factory-> NewFromStdString("#%!\0@$"); - stdString = LocaleHelper::ConvertToStdString(handleEcmaStr); + stdString = LocaleHelper::ConvertToStdString(thread, handleEcmaStr); EXPECT_STREQ(stdString.c_str(), "#%!\0@$"); handleEcmaStr = factory-> NewFromStdString("123456"); - stdString = LocaleHelper::ConvertToStdString(handleEcmaStr); + stdString = LocaleHelper::ConvertToStdString(thread, handleEcmaStr); EXPECT_STREQ(stdString.c_str(), "123456"); handleEcmaStr = factory-> NewFromStdString("zhde"); - stdString = LocaleHelper::ConvertToStdString(handleEcmaStr); + stdString = LocaleHelper::ConvertToStdString(thread, handleEcmaStr); EXPECT_STREQ(stdString.c_str(), "zhde"); } @@ -257,23 +257,23 @@ HWTEST_F_L0(LocaleHelperTest, HandleLocale) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // no "u" or "x" JSHandle localeString = factory->NewFromASCII("en-Latn-US"); - LocaleHelper::ParsedLocale parsedResult = LocaleHelper::HandleLocale(localeString); + LocaleHelper::ParsedLocale parsedResult = LocaleHelper::HandleLocale(thread, localeString); EXPECT_STREQ(parsedResult.base.c_str(), "en-Latn-US"); // only "x" localeString = factory->NewFromASCII("zh-CN-x-ca-pinyin"); - parsedResult = LocaleHelper::HandleLocale(localeString); + parsedResult = LocaleHelper::HandleLocale(thread, localeString); EXPECT_STREQ(parsedResult.base.c_str(), "zh-CN-x-ca-pinyin"); // only "u" localeString = factory->NewFromASCII("ko-Kore-KR-u-co-phonebk"); - parsedResult = LocaleHelper::HandleLocale(localeString); + parsedResult = LocaleHelper::HandleLocale(thread, localeString); EXPECT_STREQ(parsedResult.base.c_str(), "ko-Kore-KR"); // both "x" and "u" localeString = factory->NewFromASCII("en-Latn-US-u-x-co-phonebk-kn-true"); - parsedResult = LocaleHelper::HandleLocale(localeString); + parsedResult = LocaleHelper::HandleLocale(thread, localeString); EXPECT_STREQ(parsedResult.base.c_str(), "en-Latn-US-x-co-phonebk-kn-true"); localeString = factory->NewFromASCII("en-Latn-US-x-u-ca-pinyin-co-compat"); - parsedResult = LocaleHelper::HandleLocale(localeString); + parsedResult = LocaleHelper::HandleLocale(thread, localeString); EXPECT_STREQ(parsedResult.base.c_str(), "en-Latn-US-x-u-ca-pinyin-co-compat"); } diff --git a/ecmascript/tests/machine_code_test.cpp b/ecmascript/tests/machine_code_test.cpp index 391889a98a..b0a6e0dbb9 100644 --- a/ecmascript/tests/machine_code_test.cpp +++ b/ecmascript/tests/machine_code_test.cpp @@ -49,7 +49,7 @@ HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest001) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); RelocMap relocInfo; MachineCodeDesc desc; desc.codeType = MachineCodeType::BASELINE_CODE; @@ -64,7 +64,7 @@ HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest004) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); RelocMap relocInfo; MachineCodeDesc desc; desc.codeType = MachineCodeType::FAST_JIT_CODE; @@ -85,7 +85,7 @@ HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest006) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); RelocMap relocInfo; MachineCodeDesc desc; desc.codeType = MachineCodeType::FAST_JIT_CODE; @@ -107,14 +107,14 @@ HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest006) desc.stackMapOrOffsetTableAddr = reinterpret_cast(src); desc.funcEntryDesAddr = reinterpret_cast(src2); desc.funcEntryDesSize = 100; - ASSERT_EQ(code->SetData(desc, method, 100, relocInfo), true); + ASSERT_EQ(code->SetData(thread, desc, method, 100, relocInfo), true); } HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest007) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); MachineCodeDesc desc; RelocMap relocInfo; desc.codeType = MachineCodeType::FAST_JIT_CODE; @@ -136,14 +136,14 @@ HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest007) desc.stackMapOrOffsetTableAddr = reinterpret_cast(src); desc.funcEntryDesAddr = reinterpret_cast(src2); desc.funcEntryDesSize = 100; - ASSERT_EQ(code->SetData(desc, method, -100, relocInfo), true); + ASSERT_EQ(code->SetData(thread, desc, method, -100, relocInfo), true); } HWTEST_F_L0(MachineCodeTest, SetText001) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); MachineCodeDesc desc; desc.codeType = MachineCodeType::FAST_JIT_CODE; desc.instructionsSize = 100; @@ -169,7 +169,7 @@ HWTEST_F_L0(MachineCodeTest, SetText002) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); MachineCodeDesc desc; desc.codeType = MachineCodeType::FAST_JIT_CODE; desc.instructionsSize = 100; @@ -195,7 +195,7 @@ HWTEST_F_L0(MachineCodeTest, SetText003) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction()); - JSHandle method(thread, func->GetMethod()); + JSHandle method(thread, func->GetMethod(thread)); MachineCodeDesc desc; desc.codeType = MachineCodeType::FAST_JIT_CODE; desc.instructionsSize = 100; diff --git a/ecmascript/tests/native_pointer_test.cpp b/ecmascript/tests/native_pointer_test.cpp index 2ed12d8eb3..0e98cbe44c 100644 --- a/ecmascript/tests/native_pointer_test.cpp +++ b/ecmascript/tests/native_pointer_test.cpp @@ -46,7 +46,7 @@ HWTEST_F_L0(NativePointerTest, Print) jsFunction->SetMethod(thread, target.GetTaggedValue()); // run cpp methed 'Print' - ASSERT_EQ(Method::Cast(target.GetTaggedValue().GetTaggedObject()), jsFunction->GetCallTarget()); + ASSERT_EQ(Method::Cast(target.GetTaggedValue().GetTaggedObject()), jsFunction->GetCallTarget(thread)); } HWTEST_F_L0(NativePointerTest, ToString) @@ -64,6 +64,6 @@ HWTEST_F_L0(NativePointerTest, ToString) factory->NewJSNativePointer(formBuffer, nullptr, reinterpret_cast(data)); expected << "[External: " << std::hex << formBuffer << "]"; EcmaStringAccessor actual = EcmaStringAccessor(fromNativePointer->ToString(thread)); - EXPECT_EQ(actual.ToCString().c_str(), expected.str()); + EXPECT_EQ(actual.ToCString(thread).c_str(), expected.str()); } } // namespace panda::test diff --git a/ecmascript/tests/object_factory_test.cpp b/ecmascript/tests/object_factory_test.cpp index 2f7acdcc4c..bf781e9c89 100644 --- a/ecmascript/tests/object_factory_test.cpp +++ b/ecmascript/tests/object_factory_test.cpp @@ -53,25 +53,25 @@ HWTEST_F_L0(ObjectFactoryTest, NewJSObjectByConstructor) EXPECT_TRUE(*newObjCls != nullptr); // check feild - EXPECT_EQ(newObj->GetProperties(), thread->GlobalConstants()->GetEmptyArray()); - EXPECT_EQ(newObj->GetElements(), thread->GlobalConstants()->GetEmptyArray()); + EXPECT_EQ(newObj->GetProperties(thread), thread->GlobalConstants()->GetEmptyArray()); + EXPECT_EQ(newObj->GetElements(thread), thread->GlobalConstants()->GetEmptyArray()); EXPECT_TRUE(JSTaggedValue(*newObj).IsECMAObject()); // check jshclass JSHClass *cls = *newObjCls; EXPECT_TRUE(cls->GetObjectSize() == JSObject::SIZE + JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS * JSTaggedValue::TaggedTypeSize()); - EXPECT_TRUE(cls->GetPrototype() == GetGlobal(thread)->GetObjectFunctionPrototype().GetTaggedValue()); + EXPECT_TRUE(cls->GetPrototype(thread) == GetGlobal(thread)->GetObjectFunctionPrototype().GetTaggedValue()); EXPECT_TRUE(cls->GetObjectType() == JSType::JS_OBJECT); // check gc handle update - auto *prototype = cls->GetPrototype().GetTaggedObject(); + auto *prototype = cls->GetPrototype(thread).GetTaggedObject(); thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC); // After FullGC if (thread->GetEcmaVM()->GetJSOptions().EnableSnapshotDeserialize()) { - EXPECT_TRUE(prototype == newObjCls->GetPrototype().GetTaggedObject()); + EXPECT_TRUE(prototype == newObjCls->GetPrototype(thread).GetTaggedObject()); } else { - EXPECT_TRUE(prototype != newObjCls->GetPrototype().GetTaggedObject()); + EXPECT_TRUE(prototype != newObjCls->GetPrototype(thread).GetTaggedObject()); } thread->GetEcmaVM()->SetEnableForceGC(true); } @@ -88,17 +88,17 @@ HWTEST_F_L0(ObjectFactoryTest, NewJSFunction) EXPECT_TRUE(*newFunCls != nullptr); // check feild - EXPECT_EQ(newFun->GetProperties(), thread->GlobalConstants()->GetEmptyArray()); - EXPECT_EQ(newFun->GetElements(), thread->GlobalConstants()->GetEmptyArray()); - EXPECT_EQ(newFun->GetProtoOrHClass(), JSTaggedValue::Hole()); - EXPECT_EQ(newFun->GetHomeObject(), JSTaggedValue::Undefined()); + EXPECT_EQ(newFun->GetProperties(thread), thread->GlobalConstants()->GetEmptyArray()); + EXPECT_EQ(newFun->GetElements(thread), thread->GlobalConstants()->GetEmptyArray()); + EXPECT_EQ(newFun->GetProtoOrHClass(thread), JSTaggedValue::Hole()); + EXPECT_EQ(newFun->GetHomeObject(thread), JSTaggedValue::Undefined()); EXPECT_TRUE(JSTaggedValue(*newFun).IsJSFunction()); // check jshclass JSHClass *cls = *newFunCls; EXPECT_TRUE(cls->GetObjectSize() == JSFunction::SIZE + JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS * JSTaggedValue::TaggedTypeSize()); - EXPECT_TRUE(cls->GetPrototype() == GetGlobal(thread)->GetFunctionPrototype().GetTaggedValue()); + EXPECT_TRUE(cls->GetPrototype(thread) == GetGlobal(thread)->GetFunctionPrototype().GetTaggedValue()); EXPECT_TRUE(cls->GetObjectType() == JSType::JS_FUNCTION); EXPECT_TRUE(cls->IsCallable()); EXPECT_TRUE(cls->IsExtensible()); @@ -136,7 +136,7 @@ HWTEST_F_L0(ObjectFactoryTest, NewJSPrimitiveRef) EXPECT_TRUE(*newPrimitive != nullptr); EXPECT_TRUE(*newPrimitiveCls != nullptr); - EXPECT_TRUE(newPrimitive->GetValue() == JSTaggedValue(1)); + EXPECT_TRUE(newPrimitive->GetValue(thread) == JSTaggedValue(1)); } HWTEST_F_L0(ObjectFactoryTest, NewLexicalEnv) diff --git a/ecmascript/tests/object_operator_first_test.cpp b/ecmascript/tests/object_operator_first_test.cpp index e015d9e815..bf10d011bf 100644 --- a/ecmascript/tests/object_operator_first_test.cpp +++ b/ecmascript/tests/object_operator_first_test.cpp @@ -285,10 +285,10 @@ HWTEST_F_L0(ObjectOperatorTest, handleKey) ObjectOperator objectOperator6(thread, handleKey6); JSHandle handleEcmaStrTo1(objectOperator1.GetKey()); - EXPECT_STREQ("-1", EcmaStringAccessor(handleEcmaStrTo1).ToCString().c_str()); + EXPECT_STREQ("-1", EcmaStringAccessor(handleEcmaStrTo1).ToCString(thread).c_str()); JSHandle handleEcmaStrTo2(objectOperator2.GetKey()); - EXPECT_STREQ("-1.11", EcmaStringAccessor(handleEcmaStrTo2).ToCString().c_str()); + EXPECT_STREQ("-1.11", EcmaStringAccessor(handleEcmaStrTo2).ToCString(thread).c_str()); EcmaString *str1 = EcmaString::Cast(objectOperator3.GetKey()->GetTaggedObject()); EXPECT_TRUE(EcmaStringAccessor(str1).IsInternString()); @@ -299,7 +299,7 @@ HWTEST_F_L0(ObjectOperatorTest, handleKey) EXPECT_TRUE(EcmaStringAccessor(str2).IsInternString()); JSHandle handleEcmaStrTo3(objectOperator6.GetKey()); - EXPECT_STREQ("1.11", EcmaStringAccessor(handleEcmaStrTo3).ToCString().c_str()); + EXPECT_STREQ("1.11", EcmaStringAccessor(handleEcmaStrTo3).ToCString(thread).c_str()); } HWTEST_F_L0(ObjectOperatorTest, FastGetValue) @@ -391,7 +391,7 @@ HWTEST_F_L0(ObjectOperatorTest, ReLookupPropertyInReceiver_002) EXPECT_EQ(objectOperator1.GetAttr().GetPropertyMetaData(), 0); EXPECT_FALSE(objectOperator1.IsFastMode()); // Receiver is JSGlobalObject(properties) - JSMutableHandle receiverDict(thread, handleReceiver->GetProperties()); + JSMutableHandle receiverDict(thread, handleReceiver->GetProperties(thread)); JSHandle handleDict = GlobalDictionary::Create(thread, 4); // numberofElements = 4 receiverDict.Update(handleDict.GetTaggedValue()); JSHandle cellHandle = factory->NewPropertyBox(handleKey); @@ -399,7 +399,7 @@ HWTEST_F_L0(ObjectOperatorTest, ReLookupPropertyInReceiver_002) JSHandle handleProperties = GlobalDictionary::PutIfAbsent(thread, receiverDict, handleKey, JSHandle(cellHandle), handleAttr); handleReceiver->SetProperties(thread, handleProperties.GetTaggedValue()); - int keyEntry = handleProperties->FindEntry(handleKey.GetTaggedValue()); + int keyEntry = handleProperties->FindEntry(thread, handleKey.GetTaggedValue()); ObjectOperator objectOperator2(thread, handleHolder, JSHandle(handleReceiver), handleKey); objectOperator2.ReLookupPropertyInReceiver(); EXPECT_EQ(objectOperator2.GetIndex(), static_cast(keyEntry)); diff --git a/ecmascript/tests/object_operator_second_test.cpp b/ecmascript/tests/object_operator_second_test.cpp index 5f0fade4b8..5fc6533a06 100644 --- a/ecmascript/tests/object_operator_second_test.cpp +++ b/ecmascript/tests/object_operator_second_test.cpp @@ -175,15 +175,15 @@ HWTEST_F_L0(ObjectOperatorTest, UpdateDateValue_001) JSObject::SetProperty(thread, JSHandle(handleObject), newKey, newKey); } EXPECT_TRUE(objectOperator1.UpdateDataValue(handleObject, handleValue, false)); - auto *resultElements =TaggedArray::Cast(handleObject->GetElements().GetTaggedObject()); - EXPECT_EQ(resultElements->Get(objectOperator1.GetIndex()).GetInt(), 4); + auto *resultElements =TaggedArray::Cast(handleObject->GetElements(thread).GetTaggedObject()); + EXPECT_EQ(resultElements->Get(thread, objectOperator1.GetIndex()).GetInt(), 4); // object is DictionaryMode JSObject::SetProperty(thread, JSHandle(handleObject), handleKey3, handleKey); JSObject::DeleteProperty(thread, handleObject, handleKey3); EXPECT_TRUE(objectOperator1.UpdateDataValue(handleObject, handleValue1, false)); - auto *resultDict = NumberDictionary::Cast(handleObject->GetElements().GetTaggedObject()); - EXPECT_EQ(resultDict->GetValue(objectOperator1.GetIndex()).GetInt(), 5); + auto *resultDict = NumberDictionary::Cast(handleObject->GetElements(thread).GetTaggedObject()); + EXPECT_EQ(resultDict->GetValue(thread, objectOperator1.GetIndex()).GetInt(), 5); // object value is InternalAccessor JSHandle handleAccessorData = factory->NewInternalAccessor( @@ -206,7 +206,7 @@ HWTEST_F_L0(ObjectOperatorTest, UpdateDataValue_002) JSHandle globalObj = env->GetJSGlobalObject(); JSHandle handleGlobalObject(globalObj); - JSMutableHandle holderDict(thread, handleGlobalObject->GetProperties()); + JSMutableHandle holderDict(thread, handleGlobalObject->GetProperties(thread)); JSHandle handleDict = GlobalDictionary::Create(thread, 4); // numberofElements = 4 holderDict.Update(handleDict.GetTaggedValue()); JSHandle cellHandle = factory->NewPropertyBox(handleKey); @@ -215,14 +215,14 @@ HWTEST_F_L0(ObjectOperatorTest, UpdateDataValue_002) GlobalDictionary::PutIfAbsent(thread, holderDict, handleKey, JSHandle(cellHandle), PropertyAttributes(4)); handleGlobalObject->SetProperties(thread, handleProperties.GetTaggedValue()); // Set Properties - int keyEntry = handleProperties->FindEntry(handleKey.GetTaggedValue()); + int keyEntry = handleProperties->FindEntry(thread, handleKey.GetTaggedValue()); ObjectOperator objectOperator(thread, handleGlobalObject, handleKey); objectOperator.SetIndex(keyEntry); EXPECT_TRUE(objectOperator.UpdateDataValue(handleGlobalObject, handleValue, false)); - auto *resultDict = GlobalDictionary::Cast(handleGlobalObject->GetProperties().GetTaggedObject()); - PropertyBox *resultCell = resultDict->GetBox(objectOperator.GetIndex()); - EXPECT_EQ(resultCell->GetValue().GetInt(), 100); + auto *resultDict = GlobalDictionary::Cast(handleGlobalObject->GetProperties(thread).GetTaggedObject()); + PropertyBox *resultCell = resultDict->GetBox(thread, objectOperator.GetIndex()); + EXPECT_EQ(resultCell->GetValue(thread).GetInt(), 100); } HWTEST_F_L0(ObjectOperatorTest, UpdateDataValue_003) @@ -252,13 +252,13 @@ HWTEST_F_L0(ObjectOperatorTest, UpdateDataValue_003) JSObject::SetProperty(thread, JSHandle(handleObject), newKey, newValue); } EXPECT_TRUE(objectOperator.UpdateDataValue(handleObject, handleValue1, false)); - EXPECT_EQ(handleObject->GetPropertyInlinedProps(objectOperator.GetIndex()).GetInt(), 3); + EXPECT_EQ(handleObject->GetPropertyInlinedProps(thread, objectOperator.GetIndex()).GetInt(), 3); // object is DictionaryMode JSObject::DeleteProperty(thread, handleObject, handleKey2); EXPECT_TRUE(objectOperator.UpdateDataValue(handleObject, handleValue, false)); - TaggedArray *resultElements2 = TaggedArray::Cast(handleObject->GetProperties().GetTaggedObject()); + TaggedArray *resultElements2 = TaggedArray::Cast(handleObject->GetProperties(thread).GetTaggedObject()); auto *resultDict = NumberDictionary::Cast(resultElements2); - EXPECT_EQ(resultDict->GetValue(objectOperator.GetIndex()).GetInt(), 4); + EXPECT_EQ(resultDict->GetValue(thread, objectOperator.GetIndex()).GetInt(), 4); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/object_operator_third_test.cpp b/ecmascript/tests/object_operator_third_test.cpp index 3a06a9d54a..f8025e810e 100644 --- a/ecmascript/tests/object_operator_third_test.cpp +++ b/ecmascript/tests/object_operator_third_test.cpp @@ -61,9 +61,9 @@ HWTEST_F_L0(ObjectOperatorTest, WriteDataProperty_001) JSObject::SetProperty(thread, JSHandle(handleObject), newKey, newKey); } EXPECT_TRUE(objectOperator.WriteDataProperty(handleObject, handleDesc)); - auto resultDict = NumberDictionary::Cast(handleObject->GetElements().GetTaggedObject()); - int resultEntry = resultDict->FindEntry(JSTaggedValue(index)); - int resultAttrValue = resultDict->GetAttributes(resultEntry).GetPropertyMetaData(); + auto resultDict = NumberDictionary::Cast(handleObject->GetElements(thread).GetTaggedObject()); + int resultEntry = resultDict->FindEntry(thread, JSTaggedValue(index)); + int resultAttrValue = resultDict->GetAttributes(thread, resultEntry).GetPropertyMetaData(); EXPECT_EQ(objectOperator.GetAttr().GetPropertyMetaData(), resultAttrValue); EXPECT_EQ(objectOperator.GetAttr().GetDictionaryOrder(), 1U); @@ -91,7 +91,7 @@ HWTEST_F_L0(ObjectOperatorTest, WriteDataProperty_002) JSHandle handleGlobalObject(globalObj); ObjectOperator objectOperator(thread, handleGlobalObject, handleKey); - JSMutableHandle globalDict(thread, handleGlobalObject->GetProperties()); + JSMutableHandle globalDict(thread, handleGlobalObject->GetProperties(thread)); JSHandle handleDict = GlobalDictionary::Create(thread, 4); globalDict.Update(handleDict.GetTaggedValue()); JSHandle handleProperties = GlobalDictionary::PutIfAbsent( @@ -99,16 +99,16 @@ HWTEST_F_L0(ObjectOperatorTest, WriteDataProperty_002) handleProperties->SetAttributes(thread, handleAttr.GetDictionaryOrder(), handleAttr); handleProperties->SetValue(thread, handleAttr.GetDictionaryOrder(), cellHandle2.GetTaggedValue()); handleGlobalObject->SetProperties(thread, handleProperties.GetTaggedValue()); - int resultEntry = handleProperties->FindEntry(handleKey.GetTaggedValue()); + int resultEntry = handleProperties->FindEntry(thread, handleKey.GetTaggedValue()); objectOperator.SetIndex(resultEntry); EXPECT_TRUE(objectOperator.WriteDataProperty(handleGlobalObject, handleDesc)); - auto resultDict = GlobalDictionary::Cast(handleGlobalObject->GetProperties().GetTaggedObject()); - EXPECT_EQ(resultDict->GetAttributes(objectOperator.GetIndex()).GetPropertyMetaData(), 4); - EXPECT_TRUE(resultDict->GetAttributes(objectOperator.GetIndex()).IsConfigurable()); + auto resultDict = GlobalDictionary::Cast(handleGlobalObject->GetProperties(thread).GetTaggedObject()); + EXPECT_EQ(resultDict->GetAttributes(thread, objectOperator.GetIndex()).GetPropertyMetaData(), 4); + EXPECT_TRUE(resultDict->GetAttributes(thread, objectOperator.GetIndex()).IsConfigurable()); - EXPECT_EQ(resultDict->GetAttributes(resultEntry).GetBoxType(), PropertyBoxType::MUTABLE); - EXPECT_EQ(resultDict->GetValue(resultEntry).GetInt(), 1); + EXPECT_EQ(resultDict->GetAttributes(thread, resultEntry).GetBoxType(), PropertyBoxType::MUTABLE); + EXPECT_EQ(resultDict->GetValue(thread, resultEntry).GetInt(), 1); } HWTEST_F_L0(ObjectOperatorTest, WriteDataProperty_003) @@ -131,10 +131,10 @@ HWTEST_F_L0(ObjectOperatorTest, WriteDataProperty_003) objectOperator1.SetAttr(PropertyAttributes(1)); EXPECT_TRUE(objectOperator1.WriteDataProperty(handleObject, handleDesc)); - auto resultDict = NameDictionary::Cast(handleObject->GetProperties().GetTaggedObject()); - int resultEntry = resultDict->FindEntry(handleKey.GetTaggedValue()); - EXPECT_TRUE(resultDict->GetValue(resultEntry).IsAccessorData()); - EXPECT_EQ(resultDict->GetAttributes(resultEntry).GetValue(), objectOperator1.GetAttr().GetValue()); + auto resultDict = NameDictionary::Cast(handleObject->GetProperties(thread).GetTaggedObject()); + int resultEntry = resultDict->FindEntry(thread, handleKey.GetTaggedValue()); + EXPECT_TRUE(resultDict->GetValue(thread, resultEntry).IsAccessorData()); + EXPECT_EQ(resultDict->GetAttributes(thread, resultEntry).GetValue(), objectOperator1.GetAttr().GetValue()); // object is DictionaryMode and not Element JSObject::DeleteProperty(thread, (handleObject), handleKey); JSHandle handleSetter(factory->NewJSNativePointer(reinterpret_cast(TestDefinedSetter))); @@ -145,8 +145,8 @@ HWTEST_F_L0(ObjectOperatorTest, WriteDataProperty_003) objectOperator2.SetValue(handleAccessorData.GetTaggedValue()); EXPECT_TRUE(objectOperator2.WriteDataProperty(handleObject, handleDesc)); JSHandle resultAccessorData(thread, objectOperator2.GetValue()); - EXPECT_EQ(resultAccessorData->GetGetter().GetInt(), 2); - EXPECT_TRUE(resultAccessorData->GetSetter().IsJSNativePointer()); + EXPECT_EQ(resultAccessorData->GetGetter(thread).GetInt(), 2); + EXPECT_TRUE(resultAccessorData->GetSetter(thread).IsJSNativePointer()); } HWTEST_F_L0(ObjectOperatorTest, Property_Add_001) @@ -173,10 +173,10 @@ HWTEST_F_L0(ObjectOperatorTest, Property_Add_001) JSObject::DeleteProperty(thread, (handleObject), handleKey); // Delete key2 ObjectOperator objectOperator2(thread, JSHandle(handleObject), elementIndex); EXPECT_TRUE(objectOperator2.AddProperty(handleObject, handleValue, handleAttr)); - auto resultDict = NumberDictionary::Cast(handleObject->GetElements().GetTaggedObject()); - int resultEntry = resultDict->FindEntry(JSTaggedValue(static_cast(elementIndex))); - EXPECT_EQ(resultDict->GetKey(resultEntry).GetInt(), elementIndex); - EXPECT_EQ(resultDict->GetValue(resultEntry).GetInt(), 3); + auto resultDict = NumberDictionary::Cast(handleObject->GetElements(thread).GetTaggedObject()); + int resultEntry = resultDict->FindEntry(thread, JSTaggedValue(static_cast(elementIndex))); + EXPECT_EQ(resultDict->GetKey(thread, resultEntry).GetInt(), elementIndex); + EXPECT_EQ(resultDict->GetValue(thread, resultEntry).GetInt(), 3); } HWTEST_F_L0(ObjectOperatorTest, Property_Add_002) @@ -197,8 +197,8 @@ HWTEST_F_L0(ObjectOperatorTest, Property_Add_002) } ObjectOperator objectOperator(thread, JSHandle(handleObject1), elementIndex); EXPECT_TRUE(objectOperator.AddProperty(handleObject1, handleValue, handleDefaultAttr)); - TaggedArray *resultArray = TaggedArray::Cast(handleObject1->GetElements().GetTaggedObject()); - EXPECT_EQ(resultArray->Get(elementIndex).GetInt(), 3); + TaggedArray *resultArray = TaggedArray::Cast(handleObject1->GetElements(thread).GetTaggedObject()); + EXPECT_EQ(resultArray->Get(thread, elementIndex).GetInt(), 3); EXPECT_EQ(resultArray->GetLength(), 7U); // object is not DictionaryMode and not DefaultAttr JSHandle handleObject2 = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); @@ -207,10 +207,10 @@ HWTEST_F_L0(ObjectOperatorTest, Property_Add_002) JSObject::SetProperty(thread, JSHandle(handleObject2), newKey, newKey); } EXPECT_TRUE(objectOperator.AddProperty(handleObject2, handleString, handleAttr)); - auto resultDict = NumberDictionary::Cast(handleObject2->GetElements().GetTaggedObject()); - int resultEntry = resultDict->FindEntry(JSTaggedValue(static_cast(elementIndex))); - EXPECT_EQ(resultDict->GetKey(resultEntry).GetInt(), elementIndex); - EXPECT_TRUE(resultDict->GetValue(resultEntry).IsString()); + auto resultDict = NumberDictionary::Cast(handleObject2->GetElements(thread).GetTaggedObject()); + int resultEntry = resultDict->FindEntry(thread, JSTaggedValue(static_cast(elementIndex))); + EXPECT_EQ(resultDict->GetKey(thread, resultEntry).GetInt(), elementIndex); + EXPECT_TRUE(resultDict->GetValue(thread, resultEntry).IsString()); } HWTEST_F_L0(ObjectOperatorTest, Property_Add_003) @@ -287,16 +287,16 @@ HWTEST_F_L0(ObjectOperatorTest, Property_DeleteElement1) factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); JSObject::SetProperty(thread, JSHandle(handleObject1), handleKey0, handleKey0); JSObject::SetProperty(thread, JSHandle(handleObject1), handleKey1, handleKey1); - TaggedArray *handleElements = TaggedArray::Cast(handleObject1->GetElements().GetTaggedObject()); - EXPECT_EQ(handleElements->Get(index).GetInt(), 1); + TaggedArray *handleElements = TaggedArray::Cast(handleObject1->GetElements(thread).GetTaggedObject()); + EXPECT_EQ(handleElements->Get(thread, index).GetInt(), 1); JSObject::SetProperty(thread, JSHandle(handleObject1), handleKey, handleKey); ObjectOperator objectOperator1(thread, JSHandle(handleObject1), index2); objectOperator1.DeletePropertyInHolder(); - TaggedArray *resultElements = TaggedArray::Cast(handleObject1->GetElements().GetTaggedObject()); - EXPECT_EQ(resultElements->Get(index).GetInt(), 1); - auto resultDict1 = NumberDictionary::Cast(handleObject1->GetElements().GetTaggedObject()); + TaggedArray *resultElements = TaggedArray::Cast(handleObject1->GetElements(thread).GetTaggedObject()); + EXPECT_EQ(resultElements->Get(thread, index).GetInt(), 1); + auto resultDict1 = NumberDictionary::Cast(handleObject1->GetElements(thread).GetTaggedObject()); EXPECT_TRUE(resultDict1->IsDictionaryMode()); EXPECT_TRUE(JSObject::GetProperty(thread, handleObject1, handleKey).GetValue()->IsUndefined()); // object is DictionaryMode @@ -309,9 +309,9 @@ HWTEST_F_L0(ObjectOperatorTest, Property_DeleteElement1) JSObject::DeleteProperty(thread, (handleObject2), handleKey1); ObjectOperator objectOperator2(thread, JSHandle(handleObject2), index - 1); objectOperator2.DeletePropertyInHolder(); - auto resultDict2 = NumberDictionary::Cast(handleObject2->GetElements().GetTaggedObject()); - EXPECT_TRUE(resultDict2->GetKey(index - 1U).IsUndefined()); - EXPECT_TRUE(resultDict2->GetValue(index - 1U).IsUndefined()); + auto resultDict2 = NumberDictionary::Cast(handleObject2->GetElements(thread).GetTaggedObject()); + EXPECT_TRUE(resultDict2->GetKey(thread, index - 1U).IsUndefined()); + EXPECT_TRUE(resultDict2->GetValue(thread, index - 1U).IsUndefined()); EXPECT_TRUE(JSObject::GetProperty(thread, handleObject2, handleKey0).GetValue()->IsUndefined()); EXPECT_TRUE(JSObject::GetProperty(thread, handleObject2, handleKey1).GetValue()->IsUndefined()); } @@ -330,7 +330,7 @@ HWTEST_F_L0(ObjectOperatorTest, Property_DeleteElement2) JSObject::SetProperty(thread, globalObj, handleKey, handleValue); JSObject::DeleteProperty(thread, handleGlobalObject, handleKey); } - auto resultDict = NumberDictionary::Cast(handleGlobalObject->GetElements().GetTaggedObject()); + auto resultDict = NumberDictionary::Cast(handleGlobalObject->GetElements(thread).GetTaggedObject()); EXPECT_EQ(resultDict->Size(), 4); } @@ -346,7 +346,7 @@ HWTEST_F_L0(ObjectOperatorTest, Property_DeleteProperty) // object is JSGlobalObject JSHandle globalObj = env->GetJSGlobalObject(); JSHandle handleGlobalObject(globalObj); - JSMutableHandle globalDict(thread, handleGlobalObject->GetProperties()); + JSMutableHandle globalDict(thread, handleGlobalObject->GetProperties(thread)); JSHandle handleDict = GlobalDictionary::Create(thread, 4); globalDict.Update(handleDict.GetTaggedValue()); JSHandle cellHandle = factory->NewPropertyBox(handleKey); @@ -357,10 +357,10 @@ HWTEST_F_L0(ObjectOperatorTest, Property_DeleteProperty) ObjectOperator objectOperator1(thread, handleGlobalObject, handleKey); objectOperator1.DeletePropertyInHolder(); - auto resultDict = GlobalDictionary::Cast(handleGlobalObject->GetProperties().GetTaggedObject()); + auto resultDict = GlobalDictionary::Cast(handleGlobalObject->GetProperties(thread).GetTaggedObject()); // key not found - EXPECT_EQ(resultDict->FindEntry(handleKey.GetTaggedValue()), -1); - EXPECT_EQ(resultDict->GetAttributes(objectOperator1.GetIndex()).GetValue(), 0U); + EXPECT_EQ(resultDict->FindEntry(thread, handleKey.GetTaggedValue()), -1); + EXPECT_EQ(resultDict->GetAttributes(thread, objectOperator1.GetIndex()).GetValue(), 0U); // object is not DictionaryMode JSHandle handleObject = factory->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); @@ -369,9 +369,9 @@ HWTEST_F_L0(ObjectOperatorTest, Property_DeleteProperty) JSObject::SetProperty(thread, JSHandle(handleObject), handleKey1, handleKey1); ObjectOperator objectOperator2(thread, handleObject, handleKey); objectOperator2.DeletePropertyInHolder(); - auto resultDict1 = NameDictionary::Cast(handleObject->GetProperties().GetTaggedObject()); + auto resultDict1 = NameDictionary::Cast(handleObject->GetProperties(thread).GetTaggedObject()); // key not found - EXPECT_EQ(resultDict1->FindEntry(handleKey.GetTaggedValue()), -1); + EXPECT_EQ(resultDict1->FindEntry(thread, handleKey.GetTaggedValue()), -1); } HWTEST_F_L0(ObjectOperatorTest, Define_SetterAndGettetr) @@ -406,18 +406,18 @@ HWTEST_F_L0(ObjectOperatorTest, Define_SetterAndGettetr) objectOperator.DefineGetter(handleValue); JSHandle resultObj1(objectOperator.GetReceiver()); - TaggedArray *properties = TaggedArray::Cast(resultObj1->GetProperties().GetTaggedObject()); - JSHandle resultAccessorData1(thread, properties->Get(objectOperator.GetIndex())); - EXPECT_EQ(resultAccessorData1->GetGetter().GetInt(), 0); - EXPECT_EQ(resultAccessorData1->GetSetter().GetInt(), 2); + TaggedArray *properties = TaggedArray::Cast(resultObj1->GetProperties(thread).GetTaggedObject()); + JSHandle resultAccessorData1(thread, properties->Get(thread, objectOperator.GetIndex())); + EXPECT_EQ(resultAccessorData1->GetGetter(thread).GetInt(), 0); + EXPECT_EQ(resultAccessorData1->GetSetter(thread).GetInt(), 2); // object is DictionaryMode JSObject::DeleteProperty(thread, handleObject, handleKey2); objectOperator.DefineSetter(handleValue); objectOperator.DefineGetter(handleValue1); JSHandle resultObj2(objectOperator.GetReceiver()); - auto resultDict = NameDictionary::Cast(resultObj2->GetProperties().GetTaggedObject()); - JSHandle resultAccessorData2(thread, resultDict->GetValue(objectOperator.GetIndex())); - EXPECT_EQ(resultAccessorData2->GetGetter().GetInt(), 2); - EXPECT_EQ(resultAccessorData2->GetSetter().GetInt(), 0); + auto resultDict = NameDictionary::Cast(resultObj2->GetProperties(thread).GetTaggedObject()); + JSHandle resultAccessorData2(thread, resultDict->GetValue(thread, objectOperator.GetIndex())); + EXPECT_EQ(resultAccessorData2->GetGetter(thread).GetInt(), 2); + EXPECT_EQ(resultAccessorData2->GetSetter(thread).GetInt(), 0); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/rb_tree_node_test.cpp b/ecmascript/tests/rb_tree_node_test.cpp index 6afb117da2..7b43138a36 100644 --- a/ecmascript/tests/rb_tree_node_test.cpp +++ b/ecmascript/tests/rb_tree_node_test.cpp @@ -47,7 +47,7 @@ public: JSHandle value(thread, factory->NewFromStdString(iValue).GetTaggedValue()); int hash = TaggedNode::Hash(thread, factory->NewFromStdString(iKey).GetTaggedValue()); rootNode = RBTreeNode::Set(thread, rootNode, hash, key, value); - rootNode->SetIsRed(thread, JSTaggedValue(false)); + rootNode->SetIsRed(false); } } @@ -63,7 +63,7 @@ public: int hash = TaggedNode::Hash(thread, key.GetTaggedValue()); JSHandle rootNodeVa(thread, rootNode.GetTaggedValue()); JSTaggedValue gValue = RBTreeNode::GetTreeNode(thread, rootNodeVa, hash, key); - JSTaggedValue resValue = RBTreeNode::Cast(gValue.GetTaggedObject())->GetValue(); + JSTaggedValue resValue = RBTreeNode::Cast(gValue.GetTaggedObject())->GetValue(thread); EXPECT_EQ(resValue, value.GetTaggedValue()); } } @@ -142,24 +142,24 @@ HWTEST_F_L0(RBTreeNodeTest, RBTreeNodeDivide) TaggedHashArray::Create(thread, TaggedHashArray::DEFAULT_INITIAL_CAPACITY * 2)); JSHandle rootNodeVa = JSHandle::Cast(rootNode); RBTreeNode::Divide(thread, newTab, rootNodeVa, 0, TaggedHashArray::DEFAULT_INITIAL_CAPACITY); - JSTaggedValue loNode = newTab->Get(0); + JSTaggedValue loNode = newTab->Get(thread, 0); uint32_t loCount = 0; uint32_t hiCount = 0; if (loNode.IsLinkedNode()) { for (JSHandle node = JSHandle(thread, loNode); !node.GetTaggedValue().IsHole(); - node = JSHandle(thread, node->GetNext())) { + node = JSHandle(thread, node->GetNext(thread))) { loCount++; } } else { JSHandle node = JSHandle(thread, loNode); loCount = node->GetCount(); } - JSTaggedValue hiNode = newTab->Get(TaggedHashArray::DEFAULT_INITIAL_CAPACITY); + JSTaggedValue hiNode = newTab->Get(thread, TaggedHashArray::DEFAULT_INITIAL_CAPACITY); if (hiNode.IsLinkedNode()) { for (JSHandle node = JSHandle(thread, hiNode); !node.GetTaggedValue().IsHole(); - node = JSHandle(thread, node->GetNext())) { + node = JSHandle(thread, node->GetNext(thread))) { hiCount++; } } else { @@ -181,7 +181,7 @@ HWTEST_F_L0(RBTreeNodeTest, RBTreeNodeUntreeify) JSHandle head = RBTreeNode::Detreeing(thread, rootNode); uint32_t count = 0; - for (; !head.GetTaggedValue().IsHole(); head = JSHandle(thread, head->GetNext())) { + for (; !head.GetTaggedValue().IsHole(); head = JSHandle(thread, head->GetNext(thread))) { count++; } @@ -199,11 +199,11 @@ HWTEST_F_L0(RBTreeNodeTest, RBTreeNodeCompare) JSHandle b(thread, factory->NewFromStdString(value2).GetTaggedValue()); JSHandle c(thread, factory->NewFromStdString(value3).GetTaggedValue()); JSHandle d(thread, factory->NewFromStdString(value4).GetTaggedValue()); - int rvalue = RBTreeNode::Compare(12345, a.GetTaggedValue(), 12345, b.GetTaggedValue()); + int rvalue = RBTreeNode::Compare(thread, 12345, a.GetTaggedValue(), 12345, b.GetTaggedValue()); EXPECT_TRUE(rvalue != 0); - rvalue = RBTreeNode::Compare(54321, a.GetTaggedValue(), 54321, c.GetTaggedValue()); + rvalue = RBTreeNode::Compare(thread, 54321, a.GetTaggedValue(), 54321, c.GetTaggedValue()); EXPECT_EQ(rvalue, 0); - rvalue = RBTreeNode::Compare(3373707, d.GetTaggedValue(), 3373707, JSTaggedValue(38754584)); + rvalue = RBTreeNode::Compare(thread, 3373707, d.GetTaggedValue(), 3373707, JSTaggedValue(38754584)); EXPECT_EQ(rvalue, 1); } } diff --git a/ecmascript/tests/shared_object_factory_test.cpp b/ecmascript/tests/shared_object_factory_test.cpp index 77089ce535..942d8520e7 100644 --- a/ecmascript/tests/shared_object_factory_test.cpp +++ b/ecmascript/tests/shared_object_factory_test.cpp @@ -51,8 +51,8 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSImportEntryTest001) JSHandle entry = factory->NewSImportEntry(requestIndex, JSHandle::Cast(importName), JSHandle::Cast(localName)); - ASSERT_EQ(entry->GetImportName().GetRawData(), JSHandle::Cast(importName)->GetRawData()); - ASSERT_EQ(entry->GetLocalName().GetRawData(), JSHandle::Cast(localName)->GetRawData()); + ASSERT_EQ(entry->GetImportName(thread).GetRawData(), JSHandle::Cast(importName)->GetRawData()); + ASSERT_EQ(entry->GetLocalName(thread).GetRawData(), JSHandle::Cast(localName)->GetRawData()); ASSERT_EQ(entry->GetModuleRequestIndex(), 1); } @@ -62,9 +62,9 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSLocalExportEntryTest001) JSHandle entry = factory->NewSLocalExportEntry(JSHandle::Cast(factory->NewFromASCII("exportName")), JSHandle::Cast(factory->NewFromASCII("localName")), 1); - ASSERT_EQ(entry->GetExportName().GetRawData(), + ASSERT_EQ(entry->GetExportName(thread).GetRawData(), JSHandle::Cast(factory->NewFromASCII("exportName"))->GetRawData()); - ASSERT_EQ(entry->GetLocalName().GetRawData(), + ASSERT_EQ(entry->GetLocalName(thread).GetRawData(), JSHandle::Cast(factory->NewFromASCII("localName"))->GetRawData()); } @@ -74,9 +74,9 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSIndirectExportEntryTest001) JSHandle entry = factory->NewSIndirectExportEntry( JSHandle::Cast(factory->NewFromASCII("exportName")), 0, JSHandle::Cast(factory->NewFromASCII("importName"))); - ASSERT_EQ(entry->GetExportName().GetRawData(), + ASSERT_EQ(entry->GetExportName(thread).GetRawData(), JSHandle::Cast(factory->NewFromASCII("exportName"))->GetRawData()); - ASSERT_EQ(entry->GetImportName().GetRawData(), + ASSERT_EQ(entry->GetImportName(thread).GetRawData(), JSHandle::Cast(factory->NewFromASCII("importName"))->GetRawData()); ASSERT_EQ(entry->GetModuleRequestIndex(), 0); } @@ -93,7 +93,7 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedIndexBindingRecordTest001) { ObjectFactory *factory = instance->GetFactory(); JSHandle record = factory->NewSResolvedIndexBindingRecord(); - ASSERT_NE(record->GetModule().GetRawData(), JSTaggedValue::Exception().GetRawData()); + ASSERT_NE(record->GetModule(thread).GetRawData(), JSTaggedValue::Exception().GetRawData()); } HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedIndexBindingRecordTest002) @@ -102,7 +102,7 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedIndexBindingRecordTest002) JSHandle undefinedValue = thread->GlobalConstants()->GetHandledUndefined(); JSHandle ecmaModule(undefinedValue); JSHandle record = factory->NewSResolvedIndexBindingRecord(ecmaModule, 2); - ASSERT_NE(record->GetModule().GetRawData(), JSTaggedValue::Exception().GetRawData()); + ASSERT_NE(record->GetModule(thread).GetRawData(), JSTaggedValue::Exception().GetRawData()); } HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedBindingRecordTest001) @@ -110,7 +110,7 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedBindingRecordTest001) ObjectFactory *factory = instance->GetFactory(); JSHandle record = factory->NewSResolvedRecordBindingRecord(); JSHandle undefinedValue = thread->GlobalConstants()->GetHandledUndefined(); - ASSERT_EQ(record->GetBindingName().GetRawData(), undefinedValue->GetRawData()); + ASSERT_EQ(record->GetBindingName(thread).GetRawData(), undefinedValue->GetRawData()); } HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedBindingRecordTest002) @@ -119,7 +119,7 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSResolvedBindingRecordTest002) JSHandle record = factory->NewSResolvedRecordBindingRecord( factory->NewFromASCII("moduleRecord"), JSHandle::Cast(factory->NewFromASCII("bindName"))); - ASSERT_EQ(record->GetBindingName().GetRawData(), + ASSERT_EQ(record->GetBindingName(thread).GetRawData(), JSHandle::Cast(factory->NewFromASCII("bindName"))->GetRawData()); } @@ -130,11 +130,11 @@ HWTEST_F_L0(SharedObjectFactoryTest, CopySArrayTest001) JSHandle result = factory->CopySArray(array, 5, 10); for (size_t i = 0; i < 5; i++) { - ASSERT_EQ(array->Get(i).GetRawData(), result->Get(i).GetRawData()); + ASSERT_EQ(array->Get(thread, i).GetRawData(), result->Get(thread, i).GetRawData()); } for (size_t i = 5; i < 10; i++) { - ASSERT_EQ(result->Get(i).GetRawData(), JSTaggedValue::Hole().GetRawData()); + ASSERT_EQ(result->Get(thread, i).GetRawData(), JSTaggedValue::Hole().GetRawData()); } } @@ -145,7 +145,7 @@ HWTEST_F_L0(SharedObjectFactoryTest, CopySArrayTest002) JSHandle result = factory->CopySArray(array, 10, 5); for (size_t i = 0; i < 5; i++) { - ASSERT_EQ(array->Get(i).GetRawData(), result->Get(i).GetRawData()); + ASSERT_EQ(array->Get(thread, i).GetRawData(), result->Get(thread, i).GetRawData()); } } @@ -162,7 +162,7 @@ HWTEST_F_L0(SharedObjectFactoryTest, NewSClassInfoExtractorTest001) ObjectFactory *factory = instance->GetFactory(); JSHandle info = factory->NewSClassInfoExtractor(JSHandle::Cast(factory->NewFromASCII("method"))); - ASSERT_EQ(info->GetConstructorMethod().GetRawData(), + ASSERT_EQ(info->GetConstructorMethod(thread).GetRawData(), JSHandle::Cast(factory->NewFromASCII("method"))->GetRawData()); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/symbol_table_test.cpp b/ecmascript/tests/symbol_table_test.cpp index 2f3b993dbf..ee67b4e2b6 100644 --- a/ecmascript/tests/symbol_table_test.cpp +++ b/ecmascript/tests/symbol_table_test.cpp @@ -66,13 +66,13 @@ HWTEST_F_L0(SymbolTableTest, IsMatch) JSTaggedValue symbolTableOther = symbolTableString.GetTaggedValue(); JSTaggedValue symbolTableName1 = JSTaggedValue::Hole(); - EXPECT_EQ(SymbolTable::IsMatch(symbolTableName1, symbolTableOther), false); + EXPECT_EQ(SymbolTable::IsMatch(thread, symbolTableName1, symbolTableOther), false); JSTaggedValue symbolTableName2 = JSTaggedValue::Undefined(); - EXPECT_EQ(SymbolTable::IsMatch(symbolTableName2, symbolTableOther), false); + EXPECT_EQ(SymbolTable::IsMatch(thread, symbolTableName2, symbolTableOther), false); JSTaggedValue symbolTableName3 = symbolTableString.GetTaggedValue(); - EXPECT_EQ(SymbolTable::IsMatch(symbolTableName3, symbolTableOther), true); + EXPECT_EQ(SymbolTable::IsMatch(thread, symbolTableName3, symbolTableOther), true); } /* @@ -89,12 +89,13 @@ HWTEST_F_L0(SymbolTableTest, Hash_Utf8) uint8_t utf8ArrayName1[4] = {1, 2, 3}; // The last element is "\0" uint32_t utf8ArrayNameLen1 = sizeof(utf8ArrayName1) - 1; JSHandle nameStringUtf8Obj1 = factory->NewFromUtf8(utf8ArrayName1, utf8ArrayNameLen1); - EXPECT_EQ(SymbolTable::Hash(nameStringUtf8Obj1.GetTaggedValue()), 1026U); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 + EXPECT_EQ(SymbolTable::Hash(thread, + nameStringUtf8Obj1.GetTaggedValue()), 1026U); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 uint8_t utf8ArrayName2[] = "key"; uint32_t utf8ArrayNameLen2 = sizeof(utf8ArrayName2) - 1; JSHandle nameStringUtf8Obj2 = factory->NewFromUtf8(utf8ArrayName2, utf8ArrayNameLen2); - EXPECT_EQ(SymbolTable::Hash(nameStringUtf8Obj2.GetTaggedValue()), 106079U); + EXPECT_EQ(SymbolTable::Hash(thread, nameStringUtf8Obj2.GetTaggedValue()), 106079U); } /* @@ -112,12 +113,14 @@ HWTEST_F_L0(SymbolTableTest, Hash_Utf16) uint16_t utf16ArrayName1[] = {1, 2, 3}; uint32_t utf16ArrayNameLen1 = sizeof(utf16ArrayName1) / sizeof(utf16ArrayName1[0]); JSHandle nameStringUtf16Obj1 = factory->NewFromUtf16(utf16ArrayName1, utf16ArrayNameLen1); - EXPECT_EQ(SymbolTable::Hash(nameStringUtf16Obj1.GetTaggedValue()), 1026U); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 + EXPECT_EQ(SymbolTable::Hash(thread, + nameStringUtf16Obj1.GetTaggedValue()), 1026U); // 1026 = (1 << 5 - 1 + 2) << 5 - 2 + 3 uint16_t utf16ArrayName2[] = {0, 1, 2}; uint32_t utf16ArrayNameLen2 = sizeof(utf16ArrayName2) / sizeof(utf16ArrayName2[0]); JSHandle nameStringUtf16Obj2 = factory->NewFromUtf16(utf16ArrayName2, utf16ArrayNameLen2); - EXPECT_EQ(SymbolTable::Hash(nameStringUtf16Obj2.GetTaggedValue()), 33U); // 33 = (0 << 5 - 0 + 1) << 5 - 1 + 2 + EXPECT_EQ(SymbolTable::Hash(thread, + nameStringUtf16Obj2.GetTaggedValue()), 33U); // 33 = (0 << 5 - 0 + 1) << 5 - 1 + 2 } /* @@ -154,23 +157,23 @@ HWTEST_F_L0(SymbolTableTest, ContainsKey) int numberOfElements = 2; JSHandle symbolTable = SymbolTable::Create(thread, numberOfElements); - EXPECT_EQ(symbolTable->ContainsKey(symbolTableStringKey1.GetTaggedValue()), false); + EXPECT_EQ(symbolTable->ContainsKey(thread, symbolTableStringKey1.GetTaggedValue()), false); symbolTable->SetKey(thread, 1, JSTaggedValue::Hole()); - EXPECT_EQ(symbolTable->ContainsKey(symbolTableStringKey1.GetTaggedValue()), false); + EXPECT_EQ(symbolTable->ContainsKey(thread, symbolTableStringKey1.GetTaggedValue()), false); symbolTable->SetKey(thread, 1, JSTaggedValue::Undefined()); - EXPECT_EQ(symbolTable->ContainsKey(symbolTableStringKey1.GetTaggedValue()), false); + EXPECT_EQ(symbolTable->ContainsKey(thread, symbolTableStringKey1.GetTaggedValue()), false); symbolTable->SetKey(thread, 1, symbolTableStringKey1.GetTaggedValue()); - EXPECT_EQ(symbolTable->ContainsKey(symbolTableStringKey1.GetTaggedValue()), true); + EXPECT_EQ(symbolTable->ContainsKey(thread, symbolTableStringKey1.GetTaggedValue()), true); // the key value has numbers symbolTable->SetKey(thread, 1, symbolTableStringKey2.GetTaggedValue()); - EXPECT_EQ(symbolTable->ContainsKey(symbolTableStringKey2.GetTaggedValue()), false); + EXPECT_EQ(symbolTable->ContainsKey(thread, symbolTableStringKey2.GetTaggedValue()), false); symbolTable->SetKey(thread, 1, symbolTableStringKey3.GetTaggedValue()); - EXPECT_EQ(symbolTable->ContainsKey(symbolTableStringKey3.GetTaggedValue()), true); + EXPECT_EQ(symbolTable->ContainsKey(thread, symbolTableStringKey3.GetTaggedValue()), true); } /* @@ -190,13 +193,13 @@ HWTEST_F_L0(SymbolTableTest, GetSymbol) JSHandle symbolTable = SymbolTable::Create(thread, numberOfElements); symbolTable->SetKey(thread, 1, symbolTableStringKey.GetTaggedValue()); - EXPECT_EQ(symbolTable->GetSymbol(symbolTableStringKey.GetTaggedValue()), JSTaggedValue::Undefined()); + EXPECT_EQ(symbolTable->GetSymbol(thread, symbolTableStringKey.GetTaggedValue()), JSTaggedValue::Undefined()); symbolTable->SetValue(thread, 0, JSTaggedValue(1)); - EXPECT_EQ(symbolTable->GetSymbol(symbolTableStringKey.GetTaggedValue()), JSTaggedValue::Undefined()); + EXPECT_EQ(symbolTable->GetSymbol(thread, symbolTableStringKey.GetTaggedValue()), JSTaggedValue::Undefined()); symbolTable->SetValue(thread, 1, JSTaggedValue(1)); - EXPECT_EQ(symbolTable->GetSymbol(symbolTableStringKey.GetTaggedValue()).GetInt(), 1); + EXPECT_EQ(symbolTable->GetSymbol(thread, symbolTableStringKey.GetTaggedValue()).GetInt(), 1); } /* @@ -219,19 +222,19 @@ HWTEST_F_L0(SymbolTableTest, FindSymbol) JSHandle handleSymbol = factory->NewJSSymbol(); JSHandle symbolTable = SymbolTable::Create(thread, numberOfElements); - JSTaggedValue resultValue1 = symbolTable->FindSymbol(handleSymbol.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(resultValue1, JSTaggedValue::Undefined()), true); + JSTaggedValue resultValue1 = symbolTable->FindSymbol(thread, handleSymbol.GetTaggedValue()); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resultValue1, JSTaggedValue::Undefined()), true); handleSymbol->SetDescription(thread, symbolTableStringKey1.GetTaggedValue()); - JSTaggedValue resultValue2 = symbolTable->FindSymbol(handleSymbol.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(resultValue2, JSTaggedValue::Undefined()), true); + JSTaggedValue resultValue2 = symbolTable->FindSymbol(thread, handleSymbol.GetTaggedValue()); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resultValue2, JSTaggedValue::Undefined()), true); symbolTable->SetKey(thread, 1, symbolTableStringKey1.GetTaggedValue()); - JSTaggedValue resultValue3 = symbolTable->FindSymbol(handleSymbol.GetTaggedValue()); + JSTaggedValue resultValue3 = symbolTable->FindSymbol(thread, handleSymbol.GetTaggedValue()); EXPECT_EQ(resultValue3.GetRawData() == symbolTableStringKey1.GetTaggedValue().GetRawData(), true); symbolTable->SetKey(thread, 1, symbolTableStringKey2.GetTaggedValue()); - JSTaggedValue resultValue4 = symbolTable->FindSymbol(handleSymbol.GetTaggedValue()); - EXPECT_EQ(JSTaggedValue::SameValue(resultValue4, JSTaggedValue::Undefined()), true); + JSTaggedValue resultValue4 = symbolTable->FindSymbol(thread, handleSymbol.GetTaggedValue()); + EXPECT_EQ(JSTaggedValue::SameValue(thread, resultValue4, JSTaggedValue::Undefined()), true); } } // namespace panda::test diff --git a/ecmascript/tests/tagged_array_test.cpp b/ecmascript/tests/tagged_array_test.cpp index b71b50f359..6ae75275a4 100644 --- a/ecmascript/tests/tagged_array_test.cpp +++ b/ecmascript/tests/tagged_array_test.cpp @@ -42,7 +42,7 @@ HWTEST_F_L0(TaggedArrayTest, Create) EXPECT_TRUE(*taggedArray != nullptr); // every element of the taggedarray is JSTaggedValue::Hole() for (uint32_t i = 0; i < arrayLength; i++) { - EXPECT_TRUE(taggedArray->Get(i).IsHole()); + EXPECT_TRUE(taggedArray->Get(thread, i).IsHole()); } } @@ -59,14 +59,14 @@ HWTEST_F_L0(TaggedArrayTest, SetAndGetIdx) taggedArray->Set(thread, 0, newObj1); taggedArray->Set(thread, 1, objValue); - EXPECT_EQ(taggedArray->GetIdx(newObj1.GetTaggedValue()), 0U); - EXPECT_EQ(taggedArray->GetIdx(objValue), 1U); + EXPECT_EQ(taggedArray->GetIdx(thread, newObj1.GetTaggedValue()), 0U); + EXPECT_EQ(taggedArray->GetIdx(thread, objValue), 1U); // trigger gc ecmaVM->CollectGarbage(TriggerGCType::OLD_GC); - EXPECT_EQ(taggedArray->GetIdx(newObj1.GetTaggedValue()), 0U); + EXPECT_EQ(taggedArray->GetIdx(thread, newObj1.GetTaggedValue()), 0U); #ifndef USE_CMC_GC // cmc gc may not evacuate tl region. - EXPECT_EQ(taggedArray->GetIdx(objValue), TaggedArray::MAX_ARRAY_INDEX); + EXPECT_EQ(taggedArray->GetIdx(thread, objValue), TaggedArray::MAX_ARRAY_INDEX); #endif } @@ -90,9 +90,9 @@ HWTEST_F_L0(TaggedArrayTest, Append) // append two taggedarray JSHandle appendArray = TaggedArray::Append(thread, taggedArray1, taggedArray2); EXPECT_EQ(appendArray->GetLength(), arrayLength * 2); - EXPECT_EQ(appendArray->Get(0), newObj1.GetTaggedValue()); - EXPECT_EQ(appendArray->Get(2), objValue); // 2: the second index - EXPECT_EQ(appendArray->Get(1), appendArray->Get(3)); // 3: the third index + EXPECT_EQ(appendArray->Get(thread, 0), newObj1.GetTaggedValue()); + EXPECT_EQ(appendArray->Get(thread, 2), objValue); // 2: the second index + EXPECT_EQ(appendArray->Get(thread, 1), appendArray->Get(thread, 3)); // 3: the third index ecmaVM->SetEnableForceGC(true); // turn on GC } @@ -113,10 +113,10 @@ HWTEST_F_L0(TaggedArrayTest, AppendSkipHole) // append two taggedarray JSHandle appendArray = TaggedArray::AppendSkipHole(thread, taggedArray1, taggedArray2, twoArrayLength); EXPECT_EQ(appendArray->GetLength(), twoArrayLength); - EXPECT_EQ(appendArray->Get(0), appendArray->Get(1)); - EXPECT_TRUE(appendArray->Get(2).IsUndefined()); // 2: the second index - EXPECT_TRUE(appendArray->Get(3).IsHole()); // 3: the third index - EXPECT_TRUE(appendArray->Get(4).IsHole()); // 4: the fourth index + EXPECT_EQ(appendArray->Get(thread, 0), appendArray->Get(thread, 1)); + EXPECT_TRUE(appendArray->Get(thread, 2).IsUndefined()); // 2: the second index + EXPECT_TRUE(appendArray->Get(thread, 3).IsHole()); // 3: the third index + EXPECT_TRUE(appendArray->Get(thread, 4).IsHole()); // 4: the fourth index } HWTEST_F_L0(TaggedArrayTest, HasDuplicateEntry) @@ -135,15 +135,15 @@ HWTEST_F_L0(TaggedArrayTest, HasDuplicateEntry) JSHandle arrayValue(thread, JSTaggedValue(i)); taggedArray->Set(thread, i, arrayValue.GetTaggedValue()); } - EXPECT_FALSE(taggedArray->HasDuplicateEntry()); + EXPECT_FALSE(taggedArray->HasDuplicateEntry(thread)); // set value that is the same as the thrid index taggedArray->Set(thread, 1, value3.GetTaggedValue()); - EXPECT_TRUE(taggedArray->HasDuplicateEntry()); + EXPECT_TRUE(taggedArray->HasDuplicateEntry(thread)); // resert value in the second index taggedArray->Set(thread, 1, value1.GetTaggedValue()); taggedArray->Set(thread, 5, newObj1); // 5: the fifth index taggedArray->Set(thread, 6, newObj1.GetTaggedValue()); // 6: the sixth index - EXPECT_TRUE(taggedArray->HasDuplicateEntry()); + EXPECT_TRUE(taggedArray->HasDuplicateEntry(thread)); } HWTEST_F_L0(TaggedArrayTest, Trim) @@ -169,7 +169,7 @@ HWTEST_F_L0(TaggedArrayTest, Trim) taggedArray->Trim(thread, newArrayLength); for (uint32_t i = 0; i < newArrayLength; i++) { JSHandle arrayValue(thread, JSTaggedValue(i)); - EXPECT_EQ(taggedArray->Get(i), arrayValue.GetTaggedValue()); + EXPECT_EQ(taggedArray->Get(thread, i), arrayValue.GetTaggedValue()); } EXPECT_EQ(taggedArray->GetLength(), newArrayLength); EXPECT_EQ(JSObject::GetProperty(thread, TaggedArrayObj, indexValue).GetValue(), undefinedValue); diff --git a/ecmascript/tests/tagged_dictionary_test.cpp b/ecmascript/tests/tagged_dictionary_test.cpp index d50f86e19d..27d62eea0e 100644 --- a/ecmascript/tests/tagged_dictionary_test.cpp +++ b/ecmascript/tests/tagged_dictionary_test.cpp @@ -82,15 +82,15 @@ HWTEST_F_L0(TaggedDictionaryTest, NameDictionary_addKeyAndValue) EXPECT_EQ(dict->EntriesCount(), 1); // test find() and lookup() - int entry1 = dict->FindEntry(key1.GetTaggedValue()); - EXPECT_EQ(key1.GetTaggedValue(), JSTaggedValue(dict->GetKey(entry1).GetRawData())); - EXPECT_EQ(value1.GetTaggedValue(), JSTaggedValue(dict->GetValue(entry1).GetRawData())); + int entry1 = dict->FindEntry(thread, key1.GetTaggedValue()); + EXPECT_EQ(key1.GetTaggedValue(), JSTaggedValue(dict->GetKey(thread, entry1).GetRawData())); + EXPECT_EQ(value1.GetTaggedValue(), JSTaggedValue(dict->GetValue(thread, entry1).GetRawData())); JSHandle dict2(NameDictionary::PutIfAbsent(thread, dictHandle, key2, value2, metaData2)); EXPECT_EQ(dict2->EntriesCount(), 2); // test remove() dict = NameDictionary::Remove(thread, dictHandle, entry1); - EXPECT_EQ(-1, dict->FindEntry(key1.GetTaggedValue())); + EXPECT_EQ(-1, dict->FindEntry(thread, key1.GetTaggedValue())); EXPECT_EQ(dict->EntriesCount(), 1); } @@ -158,7 +158,7 @@ HWTEST_F_L0(TaggedDictionaryTest, NameDictionary_ShrinkCapacity) keyArray[6] = 0; JSHandle arrayHandle( thread, stringTable->GetOrInternString(instance, keyArray, utf::Mutf8Size(keyArray), true)); - int entry = dictHandle->FindEntry(arrayHandle.GetTaggedValue()); + int entry = dictHandle->FindEntry(thread, arrayHandle.GetTaggedValue()); EXPECT_NE(entry, -1); JSHandle newDict1 = NameDictionary::Remove(thread, dictHandle, entry); @@ -213,15 +213,15 @@ HWTEST_F_L0(TaggedDictionaryTest, NumberDictionary_addKeyAndValue) EXPECT_EQ(dict->EntriesCount(), 1); // test find() and lookup() - int entry1 = dict->FindEntry(key1.GetTaggedValue()); - EXPECT_EQ(key1.GetTaggedValue(), JSTaggedValue(dict->GetKey(entry1).GetRawData())); - EXPECT_EQ(value1.GetTaggedValue(), JSTaggedValue(dict->GetValue(entry1).GetRawData())); + int entry1 = dict->FindEntry(thread, key1.GetTaggedValue()); + EXPECT_EQ(key1.GetTaggedValue(), JSTaggedValue(dict->GetKey(thread, entry1).GetRawData())); + EXPECT_EQ(value1.GetTaggedValue(), JSTaggedValue(dict->GetValue(thread, entry1).GetRawData())); JSHandle dict2 = NumberDictionary::PutIfAbsent(thread, dictHandle, key2, value2, metaData2); EXPECT_EQ(dict2->EntriesCount(), 2); // test remove() dict = NumberDictionary::Remove(thread, dictHandle, entry1); - EXPECT_EQ(-1, dict->FindEntry(key1.GetTaggedValue())); + EXPECT_EQ(-1, dict->FindEntry(thread, key1.GetTaggedValue())); EXPECT_EQ(dict->EntriesCount(), 1); } @@ -254,9 +254,9 @@ HWTEST_F_L0(TaggedDictionaryTest, NumberDictionary_GetAllKey) for (int i = 1; i < keyNumbers; i++) { JSHandle numberKey(thread, JSTaggedValue(i-1)); JSHandle stringKey(JSTaggedValue::ToString(thread, numberKey)); - EXPECT_EQ(storeKeyArray->Get(i), stringKey.GetTaggedValue()); + EXPECT_EQ(storeKeyArray->Get(thread, i), stringKey.GetTaggedValue()); } - EXPECT_TRUE(storeKeyArray->Get(0).IsHole()); + EXPECT_TRUE(storeKeyArray->Get(thread, 0).IsHole()); } /** @@ -309,7 +309,7 @@ HWTEST_F_L0(TaggedDictionaryTest, NumberDictionary_ShrinkCapacity) } JSHandle arrayHandle(thread, JSTaggedValue(9)); - int entry = dictHandle->FindEntry(arrayHandle.GetTaggedValue()); + int entry = dictHandle->FindEntry(thread, arrayHandle.GetTaggedValue()); EXPECT_NE(entry, -1); JSHandle newDict1 = NumberDictionary::Remove(thread, dictHandle, entry); @@ -331,10 +331,10 @@ HWTEST_F_L0(TaggedDictionaryTest, NumberDictionary_IsMatch) JSTaggedValue numberKey2(1); bool result = false; // key must be integer - result = NumberDictionary::IsMatch(numberKey1, numberKey2); + result = NumberDictionary::IsMatch(thread, numberKey1, numberKey2); EXPECT_TRUE(!result); - result = NumberDictionary::IsMatch(numberKey1, numberKey1); + result = NumberDictionary::IsMatch(thread, numberKey1, numberKey1); EXPECT_TRUE(result); } } // namespace panda::test diff --git a/ecmascript/tests/tagged_hash_array_test.cpp b/ecmascript/tests/tagged_hash_array_test.cpp index ecf1e38773..5268d782a0 100644 --- a/ecmascript/tests/tagged_hash_array_test.cpp +++ b/ecmascript/tests/tagged_hash_array_test.cpp @@ -39,7 +39,7 @@ HWTEST_F_L0(TaggedHashArrayTest, CreateTaggedHashArray) JSHandle taggedArray(taggedHashArray); EXPECT_EQ(taggedHashArray->GetLength(), static_cast(numOfElement)); for (int i = 0; i < numOfElement; i++) { - EXPECT_TRUE(taggedArray->Get(i).IsHole()); + EXPECT_TRUE(taggedArray->Get(thread, i).IsHole()); } } @@ -58,10 +58,10 @@ HWTEST_F_L0(TaggedHashArrayTest, NewLinkedNode) JSHandle linkedNode = TaggedHashArray::NewLinkedNode(thread, keyHash, hashKey, hashKeyValue); EXPECT_TRUE(*linkedNode != nullptr); - EXPECT_TRUE(linkedNode->GetNext().IsHole()); - EXPECT_EQ(linkedNode->GetKey(), hashKey.GetTaggedValue()); - EXPECT_EQ(linkedNode->GetValue(), hashKeyValue.GetTaggedValue()); - EXPECT_EQ(linkedNode->GetHash().GetInt(), keyHash); + EXPECT_TRUE(linkedNode->GetNext(thread).IsHole()); + EXPECT_EQ(linkedNode->GetKey(thread), hashKey.GetTaggedValue()); + EXPECT_EQ(linkedNode->GetValue(thread), hashKeyValue.GetTaggedValue()); + EXPECT_EQ(linkedNode->GetHash(thread).GetInt(), keyHash); } /** @@ -79,9 +79,9 @@ HWTEST_F_L0(TaggedHashArrayTest, NewTreeNode) JSHandle treeNode = TaggedHashArray::NewTreeNode(thread, keyHash, hashKey, hashKeyValue); EXPECT_TRUE(*treeNode != nullptr); - EXPECT_TRUE(treeNode->GetIsRed().ToBoolean()); - EXPECT_TRUE(treeNode->GetLeft().IsHole()); - EXPECT_TRUE(treeNode->GetRight().IsHole()); + EXPECT_TRUE(treeNode->GetIsRed()); + EXPECT_TRUE(treeNode->GetLeft(thread).IsHole()); + EXPECT_TRUE(treeNode->GetRight(thread).IsHole()); } void HashCommon1(JSThread *thread, JSHandle& taggedHashArray, std::string& myKey, @@ -147,8 +147,8 @@ HWTEST_F_L0(TaggedHashArrayTest, SetValAndGetLinkNode) JSTaggedValue hashNodeVal = taggedHashArray->GetNode(thread, keyHash, myKey4.GetTaggedValue()); EXPECT_TRUE(hashNodeVal.IsLinkedNode()); JSHandle hashNode(thread, hashNodeVal); - EXPECT_EQ(hashNode->GetValue(), myKey4Value.GetTaggedValue()); - EXPECT_TRUE(hashNode->GetNext().IsLinkedNode()); + EXPECT_EQ(hashNode->GetValue(thread), myKey4Value.GetTaggedValue()); + EXPECT_TRUE(hashNode->GetNext(thread).IsLinkedNode()); } /** @@ -182,9 +182,9 @@ HWTEST_F_L0(TaggedHashArrayTest, SetValAndGetTreeNode) JSTaggedValue hashNodeVal = taggedHashArray->GetNode(thread, keyHash, myKey5.GetTaggedValue()); EXPECT_TRUE(hashNodeVal.IsRBTreeNode()); JSHandle hashNode(thread, hashNodeVal); - EXPECT_EQ(hashNode->GetValue(), myKey5Value.GetTaggedValue()); - EXPECT_TRUE(hashNode->GetLeft().IsHole()); - EXPECT_TRUE(hashNode->GetRight().IsHole()); + EXPECT_EQ(hashNode->GetValue(thread), myKey5Value.GetTaggedValue()); + EXPECT_TRUE(hashNode->GetLeft(thread).IsHole()); + EXPECT_TRUE(hashNode->GetRight(thread).IsHole()); } /** @@ -246,28 +246,29 @@ HWTEST_F_L0(TaggedHashArrayTest, RemoveTreeNode) auto keyHash = TaggedNode::Hash(thread, myKey5.GetTaggedValue()); TaggedHashArray::SetVal(thread, taggedHashArray, keyHash, myKey8, myKey8Value); uint32_t keyHashIndex = static_cast(numOfElement - 1) & keyHash; - JSHandle hashTreeNode(thread, taggedHashArray->Get(keyHashIndex)); + JSHandle hashTreeNode(thread, taggedHashArray->Get(thread, keyHashIndex)); EXPECT_EQ(hashTreeNode->GetCount(), 2U); // test Remove() taggedHashArray->RemoveNode(thread, keyHash, myKey5.GetTaggedValue()); EXPECT_EQ(hashTreeNode->GetCount(), 1U); } -bool HasNode(JSTaggedValue hashTreeNodeVa, JSTaggedValue key) +bool HasNode(const JSThread *thread, JSTaggedValue hashTreeNodeVa, JSTaggedValue key) { if (hashTreeNodeVa.IsHole()) { return false; } RBTreeNode *hashTreeNode = RBTreeNode::Cast(hashTreeNodeVa.GetTaggedObject()); - JSTaggedValue rootKey = hashTreeNode->GetKey(); - if (JSTaggedValue::SameValue(rootKey, key)) { + JSTaggedValue rootKey = hashTreeNode->GetKey(thread); + if (JSTaggedValue::SameValue(thread, rootKey, key)) { return true; } - return HasNode(hashTreeNode->GetLeft(), key) || HasNode(hashTreeNode->GetRight(), key); + return HasNode(thread, hashTreeNode->GetLeft(thread), key) || + HasNode(thread, hashTreeNode->GetRight(thread), key); } -int CheckRBTreeNodeNums(JSTaggedValue hashTreeNodeVa, int count) +int CheckRBTreeNodeNums(const JSThread *thread, JSTaggedValue hashTreeNodeVa, int count) { if (hashTreeNodeVa.IsHole()) { return count; @@ -276,12 +277,13 @@ int CheckRBTreeNodeNums(JSTaggedValue hashTreeNodeVa, int count) count++; int temp = count; RBTreeNode *hashTreeNode = RBTreeNode::Cast(hashTreeNodeVa.GetTaggedObject()); - return CheckRBTreeNodeNums(hashTreeNode->GetLeft(), count) + - CheckRBTreeNodeNums(hashTreeNode->GetRight(), count) - temp; + return CheckRBTreeNodeNums(thread, hashTreeNode->GetLeft(thread), count) + + CheckRBTreeNodeNums(thread, hashTreeNode->GetRight(thread), count) - temp; } template -bool CheckRBTreeOfAllPaths(JSHandle &tree, int numsOfBlack, JSTaggedValue hashTreeNodeVa, int count) +bool CheckRBTreeOfAllPaths(const JSThread *thread, JSHandle &tree, int numsOfBlack, + JSTaggedValue hashTreeNodeVa, int count) { if (hashTreeNodeVa.IsHole()) { return count == numsOfBlack; @@ -290,22 +292,22 @@ bool CheckRBTreeOfAllPaths(JSHandle &tree, int numsOfBlack, JSTaggedValue has count++; } RBTreeNode *hashTreeNode = RBTreeNode::Cast(hashTreeNodeVa.GetTaggedObject()); - if (CheckRBTreeOfAllPaths(tree, numsOfBlack, hashTreeNode->GetLeft(), count) && - CheckRBTreeOfAllPaths(tree, numsOfBlack, hashTreeNode->GetRight(), count)) { + if (CheckRBTreeOfAllPaths(thread, tree, numsOfBlack, hashTreeNode->GetLeft(thread), count) && + CheckRBTreeOfAllPaths(thread, tree, numsOfBlack, hashTreeNode->GetRight(thread), count)) { return true; } return false; } -bool CheckRedNode(JSTaggedValue hashTreeNodeva) +bool CheckRedNode(const JSThread *thread, JSTaggedValue hashTreeNodeva) { if (hashTreeNodeva.IsHole()) { return true; } RBTreeNode *hashTreeNode = RBTreeNode::Cast(hashTreeNodeva.GetTaggedObject()); - JSTaggedValue leftChildVa = hashTreeNode->GetLeft(); - JSTaggedValue rightChildVa = hashTreeNode->GetRight(); - if (hashTreeNode->GetIsRed().ToBoolean()) { + JSTaggedValue leftChildVa = hashTreeNode->GetLeft(thread); + JSTaggedValue rightChildVa = hashTreeNode->GetRight(thread); + if (hashTreeNode->GetIsRed()) { if (!leftChildVa.IsHole() && RBTreeNode::IsRed(leftChildVa)) { return false; } @@ -313,11 +315,11 @@ bool CheckRedNode(JSTaggedValue hashTreeNodeva) return false; } } - return CheckRedNode(leftChildVa) && CheckRedNode(rightChildVa); + return CheckRedNode(thread, leftChildVa) && CheckRedNode(thread, rightChildVa); } template -bool CheckBlackNodeNumbers(JSHandle &tree, JSHandle hashTreeNode) +bool CheckBlackNodeNumbers(const JSThread *thread, JSHandle &tree, JSHandle hashTreeNode) { int numsOfBlack = 0; JSTaggedValue ChildVa = hashTreeNode.GetTaggedValue(); @@ -325,13 +327,13 @@ bool CheckBlackNodeNumbers(JSHandle &tree, JSHandle hashTreeNode) if (!RBTreeNode::IsRed(ChildVa)) { numsOfBlack++; } - ChildVa = RBTreeNode::Cast(ChildVa.GetTaggedObject())->GetLeft(); + ChildVa = RBTreeNode::Cast(ChildVa.GetTaggedObject())->GetLeft(thread); if (ChildVa.IsHole()) { break; } } - return CheckRBTreeOfAllPaths(tree, numsOfBlack, hashTreeNode.GetTaggedValue(), 0); + return CheckRBTreeOfAllPaths(thread, tree, numsOfBlack, hashTreeNode.GetTaggedValue(), 0); } template @@ -341,35 +343,37 @@ bool IsVaildRBTree(JSThread *thread, JSHandle &tree, JSHandle has return true; } - if (hashTreeNode->GetIsRed().ToBoolean()) { + if (hashTreeNode->GetIsRed()) { return false; } - JSTaggedValue leftChildVa = hashTreeNode->GetLeft(); - JSTaggedValue rightChildVa = hashTreeNode->GetRight(); - JSTaggedValue treeNodeKey = hashTreeNode->GetKey(); - int hash = hashTreeNode->GetHash().GetInt(); + JSTaggedValue leftChildVa = hashTreeNode->GetLeft(thread); + JSTaggedValue rightChildVa = hashTreeNode->GetRight(thread); + JSTaggedValue treeNodeKey = hashTreeNode->GetKey(thread); + int hash = hashTreeNode->GetHash(thread).GetInt(); if (!leftChildVa.IsHole()) { RBTreeNode *leftTreeNode = RBTreeNode::Cast(leftChildVa.GetTaggedObject()); - int cmp = RBTreeNode::Compare(leftTreeNode->GetHash().GetInt(), leftTreeNode->GetKey(), hash, treeNodeKey); + int cmp = RBTreeNode::Compare(thread, leftTreeNode->GetHash(thread).GetInt(), + leftTreeNode->GetKey(thread), hash, treeNodeKey); if (cmp > 0) { return false; } } if (!rightChildVa.IsHole()) { RBTreeNode *rightTreeNode = RBTreeNode::Cast(rightChildVa.GetTaggedObject()); - int cmp = RBTreeNode::Compare(rightTreeNode->GetHash().GetInt(), rightTreeNode->GetKey(), hash, treeNodeKey); + int cmp = RBTreeNode::Compare(thread, rightTreeNode->GetHash(thread).GetInt(), + rightTreeNode->GetKey(thread), hash, treeNodeKey); if (cmp < 0) { return false; } } // check red node - if (!CheckRedNode(leftChildVa) || !CheckRedNode(rightChildVa)) { + if (!CheckRedNode(thread, leftChildVa) || !CheckRedNode(thread, rightChildVa)) { return false; } // check black node - if (!CheckBlackNodeNumbers(tree, hashTreeNode)) { + if (!CheckBlackNodeNumbers(thread, tree, hashTreeNode)) { return false; } @@ -398,7 +402,7 @@ HWTEST_F_L0(TaggedHashArrayTest, RemoveRBTreeNode) auto keyHash = TaggedNode::Hash(thread, myKey1.GetTaggedValue()); TaggedHashArray::SetVal(thread, taggedHashArray, keyHash, myKey1, myKey1Value); uint32_t keyHashIndex = static_cast(numOfElement - 1) & keyHash; - JSHandle hashTreeNode(thread, taggedHashArray->Get(keyHashIndex)); + JSHandle hashTreeNode(thread, taggedHashArray->Get(thread, keyHashIndex)); EXPECT_TRUE(IsVaildRBTree(thread, taggedHashArray, hashTreeNode)); } std::random_device rd; @@ -409,27 +413,27 @@ HWTEST_F_L0(TaggedHashArrayTest, RemoveRBTreeNode) JSHandle myKey1(factory->NewFromStdString(myKey + std::to_string(index))); auto keyHash = TaggedNode::Hash(thread, myKey1.GetTaggedValue()); uint32_t keyHashIndex = static_cast(numOfElement - 1) & keyHash; - JSHandle hashTreeNode(thread, taggedHashArray->Get(keyHashIndex)); + JSHandle hashTreeNode(thread, taggedHashArray->Get(thread, keyHashIndex)); EXPECT_EQ(taggedHashArray->GetLength(), numOfElement); - int beforeNum = CheckRBTreeNodeNums(taggedHashArray->Get(keyHashIndex), 0); + int beforeNum = CheckRBTreeNodeNums(thread, taggedHashArray->Get(thread, keyHashIndex), 0); taggedHashArray->RemoveNode(thread, keyHash, myKey1.GetTaggedValue()); - if (HasNode(taggedHashArray->Get(keyHashIndex), myKey1.GetTaggedValue())) { - EXPECT_EQ(beforeNum - 1, CheckRBTreeNodeNums(taggedHashArray->Get(keyHashIndex), 0)); + if (HasNode(thread, taggedHashArray->Get(thread, keyHashIndex), myKey1.GetTaggedValue())) { + EXPECT_EQ(beforeNum - 1, CheckRBTreeNodeNums(thread, taggedHashArray->Get(thread, keyHashIndex), 0)); } - EXPECT_TRUE(!HasNode(taggedHashArray->Get(keyHashIndex), myKey1.GetTaggedValue())); - JSHandle hashTreeNode1(thread, taggedHashArray->Get(keyHashIndex)); + EXPECT_TRUE(!HasNode(thread, taggedHashArray->Get(thread, keyHashIndex), myKey1.GetTaggedValue())); + JSHandle hashTreeNode1(thread, taggedHashArray->Get(thread, keyHashIndex)); EXPECT_TRUE(IsVaildRBTree(thread, taggedHashArray, hashTreeNode1)); JSHandle myKey2(factory->NewFromStdString(myKey + std::to_string(index + 100))); JSHandle myKey2Value(factory->NewFromStdString(myValue + std::to_string(index + 100))); auto keyHash1 = TaggedNode::Hash(thread, myKey2.GetTaggedValue()); uint32_t keyHashIndex1 = static_cast(numOfElement - 1) & keyHash1; - beforeNum = CheckRBTreeNodeNums(taggedHashArray->Get(keyHashIndex1), 0); + beforeNum = CheckRBTreeNodeNums(thread, taggedHashArray->Get(thread, keyHashIndex1), 0); TaggedHashArray::SetVal(thread, taggedHashArray, keyHash1, myKey2, myKey2Value); - if (!HasNode(taggedHashArray->Get(keyHashIndex1), myKey2.GetTaggedValue())) { - EXPECT_EQ(beforeNum + 1, CheckRBTreeNodeNums(taggedHashArray->Get(keyHashIndex1), 0)); + if (!HasNode(thread, taggedHashArray->Get(thread, keyHashIndex1), myKey2.GetTaggedValue())) { + EXPECT_EQ(beforeNum + 1, CheckRBTreeNodeNums(thread, taggedHashArray->Get(thread, keyHashIndex1), 0)); } - EXPECT_TRUE(HasNode(taggedHashArray->Get(keyHashIndex1), myKey2.GetTaggedValue())); - JSHandle hashTreeNode2(thread, taggedHashArray->Get(keyHashIndex1)); + EXPECT_TRUE(HasNode(thread, taggedHashArray->Get(thread, keyHashIndex1), myKey2.GetTaggedValue())); + JSHandle hashTreeNode2(thread, taggedHashArray->Get(thread, keyHashIndex1)); EXPECT_TRUE(IsVaildRBTree(thread, taggedHashArray, hashTreeNode2)); } } @@ -454,21 +458,21 @@ HWTEST_F_L0(TaggedHashArrayTest, RemoveRBTreeRootNode) JSHandle myKey0(factory->NewFromStdString(myKey + std::to_string(0))); auto keyHash = TaggedNode::Hash(thread, myKey0.GetTaggedValue()); uint32_t keyHashIndex = static_cast(numOfElement - 1) & keyHash; - JSHandle hashTreeNode(thread, taggedHashArray->Get(keyHashIndex)); + JSHandle hashTreeNode(thread, taggedHashArray->Get(thread, keyHashIndex)); EXPECT_EQ(taggedHashArray->GetLength(), numOfElement); // before remove the root node, there is one non-hole node in the tree - int treeNodeNumber = CheckRBTreeNodeNums(taggedHashArray->Get(keyHashIndex), 0); + int treeNodeNumber = CheckRBTreeNodeNums(thread, taggedHashArray->Get(thread, keyHashIndex), 0); EXPECT_EQ(treeNodeNumber, numOfElement); - CString value = EcmaStringAccessor(hashTreeNode->GetValue()).ToCString(); + CString value = EcmaStringAccessor(hashTreeNode->GetValue(thread)).ToCString(thread); std::string myVlaue0("myvalue0"); EXPECT_EQ(value, myVlaue0.c_str()); // after remove the root node, the tree is empty and there is a hole node in the hash array. taggedHashArray->RemoveNode(thread, keyHash, myKey0.GetTaggedValue()); - treeNodeNumber = CheckRBTreeNodeNums(taggedHashArray->Get(keyHashIndex), 0); + treeNodeNumber = CheckRBTreeNodeNums(thread, taggedHashArray->Get(thread, keyHashIndex), 0); EXPECT_EQ(treeNodeNumber, 0); - EXPECT_TRUE(taggedHashArray->Get(keyHashIndex).IsHole()); + EXPECT_TRUE(taggedHashArray->Get(thread, keyHashIndex).IsHole()); } /** @@ -509,12 +513,12 @@ HWTEST_F_L0(TaggedHashArrayTest, ResetLinkNodeSize) keyHash = TaggedNode::Hash(thread, myKey4.GetTaggedValue()); uint32_t hashArrayIndex = static_cast(numOfElement - 1) & keyHash; - EXPECT_TRUE(taggedHashArray->Get(hashArrayIndex).IsHole()); + EXPECT_TRUE(taggedHashArray->Get(thread, hashArrayIndex).IsHole()); keyHash = TaggedNode::Hash(thread, myKey5.GetTaggedValue()); hashArrayIndex = static_cast(numOfElement - 1) & keyHash; - JSHandle hashNode(thread, taggedHashArray->Get(hashArrayIndex)); - EXPECT_EQ(hashNode->GetValue(), myKey8Value.GetTaggedValue()); + JSHandle hashNode(thread, taggedHashArray->Get(thread, hashArrayIndex)); + EXPECT_EQ(hashNode->GetValue(thread), myKey8Value.GetTaggedValue()); } /** @@ -549,7 +553,7 @@ HWTEST_F_L0(TaggedHashArrayTest, GetCurrentNode) EXPECT_TRUE(currentNode->IsRBTreeNode()); // Pop queue JSHandle storeStartTreeNode(thread, taggedQueue->Pop(thread)); - EXPECT_EQ(storeStartTreeNode->GetValue(), myKey5Value.GetTaggedValue()); + EXPECT_EQ(storeStartTreeNode->GetValue(thread), myKey5Value.GetTaggedValue()); EXPECT_TRUE(taggedQueue->Pop(thread).IsHole()); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/tagged_tree_test.cpp b/ecmascript/tests/tagged_tree_test.cpp index 09ca8b351d..51fd4d9bc5 100644 --- a/ecmascript/tests/tagged_tree_test.cpp +++ b/ecmascript/tests/tagged_tree_test.cpp @@ -90,9 +90,9 @@ bool IsVaildRBTree(JSThread *thread, JSHandle &tree, int nodeIndex) } int ileft = tree->GetLeftChildIndex(index); - JSHandle indexKey(thread, tree->GetKey(index)); + JSHandle indexKey(thread, tree->GetKey(thread, index)); if (ileft >= 0) { - JSHandle leftKey(thread, tree->GetKey(ileft)); + JSHandle leftKey(thread, tree->GetKey(thread, ileft)); ComparisonResult result = TaggedTree::EntryCompare(thread, leftKey, indexKey, tree); if (tree->GetParent(ileft) != index || result != ComparisonResult::LESS) { return false; @@ -101,7 +101,7 @@ bool IsVaildRBTree(JSThread *thread, JSHandle &tree, int nodeIndex) } int iright = tree->GetRightChildIndex(index); if (iright >= 0) { - JSHandle rightKey(thread, tree->GetKey(iright)); + JSHandle rightKey(thread, tree->GetKey(thread, iright)); ComparisonResult result = TaggedTree::EntryCompare(thread, rightKey, indexKey, tree); if (tree->GetParent(iright) != index || result != ComparisonResult::GREAT) { return false; @@ -411,7 +411,7 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeMapGetFirsKey) auto tmap = KeyValueCommon(thread, myKey, myValue, keyValue, static_cast(NODE_NUMBERS)); std::string ckey = myKey + std::to_string(0); keyValue[0].Update(factory->NewFromStdString(ckey).GetTaggedValue()); - JSTaggedValue firstKey = tmap->GetFirstKey(); + JSTaggedValue firstKey = tmap->GetFirstKey(thread); EXPECT_EQ(firstKey, keyValue[0].GetTaggedValue()); for (int i = 0; i < NODE_NUMBERS; i++) { @@ -419,7 +419,7 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeMapGetFirsKey) keyValue[1].Update(JSTaggedValue(i)); tmap.Update(TaggedTreeMap::Set(thread, tmap, keyValue[0], keyValue[1])); } - firstKey = tmap->GetFirstKey(); + firstKey = tmap->GetFirstKey(thread); EXPECT_EQ(firstKey, JSTaggedValue(0)); } @@ -430,7 +430,7 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeMapGetLastKey) std::vector> keyValue; auto tmap = KeyValueCommon(thread, keyValue, NODE_NUMBERS); - JSTaggedValue lastKey = tmap->GetLastKey(); + JSTaggedValue lastKey = tmap->GetLastKey(thread); EXPECT_EQ(lastKey, JSTaggedValue(NODE_NUMBERS - 1)); std::string myKey("mykey"); @@ -439,7 +439,7 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeMapGetLastKey) KeyValueUpdate(thread, tmap, strKeyValue, keyValue, NODE_NUMBERS); std::string ckey = myKey + std::to_string(NODE_NUMBERS - 1); keyValue[0].Update(factory->NewFromStdString(ckey).GetTaggedValue()); - lastKey = tmap->GetLastKey(); + lastKey = tmap->GetLastKey(thread); EXPECT_EQ(lastKey, keyValue[0].GetTaggedValue()); } @@ -501,12 +501,12 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeMapGetArrayFromMap) EXPECT_EQ(static_cast(arr->GetLength()), NODE_NUMBERS * 2); for (int i = 0; i < NODE_NUMBERS; i++) { - EXPECT_EQ(tmap->GetKey(arr->Get(i).GetInt()), JSTaggedValue(i)); + EXPECT_EQ(tmap->GetKey(thread, arr->Get(thread, i).GetInt()), JSTaggedValue(i)); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); keyValue[0].Update(factory->NewFromStdString(ikey).GetTaggedValue()); - EXPECT_EQ(tmap->GetKey(arr->Get(NODE_NUMBERS + i).GetInt()), keyValue[0].GetTaggedValue()); + EXPECT_EQ(tmap->GetKey(thread, arr->Get(thread, NODE_NUMBERS + i).GetInt()), keyValue[0].GetTaggedValue()); } } @@ -605,14 +605,14 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeSetGetFirsKey) SetKeyCommon(thread, tset, key, myKey, NODE_NUMBERS); std::string ckey = myKey + std::to_string(0); key.Update(factory->NewFromStdString(ckey).GetTaggedValue()); - JSTaggedValue firstKey = tset->GetFirstKey(); + JSTaggedValue firstKey = tset->GetFirstKey(thread); EXPECT_EQ(firstKey, key.GetTaggedValue()); for (int i = 0; i < NODE_NUMBERS; i++) { key.Update(JSTaggedValue(i)); tset.Update(TaggedTreeSet::Add(thread, tset, key)); } - firstKey = tset->GetFirstKey(); + firstKey = tset->GetFirstKey(thread); EXPECT_EQ(firstKey, JSTaggedValue(0)); } @@ -628,7 +628,7 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeSetGetLastKey) key.Update(JSTaggedValue(i)); tset.Update(TaggedTreeSet::Add(thread, tset, key)); } - JSTaggedValue lastKey = tset->GetLastKey(); + JSTaggedValue lastKey = tset->GetLastKey(thread); EXPECT_EQ(lastKey, JSTaggedValue(NODE_NUMBERS - 1)); std::string myKey("mykey"); @@ -639,7 +639,7 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeSetGetLastKey) } std::string ckey = myKey + std::to_string(NODE_NUMBERS - 1); key.Update(factory->NewFromStdString(ckey).GetTaggedValue()); - lastKey = tset->GetLastKey(); + lastKey = tset->GetLastKey(thread); EXPECT_EQ(lastKey, key.GetTaggedValue()); } @@ -666,12 +666,12 @@ HWTEST_F_L0(TaggedTreeTest, TestTreeSetGetArrayFromSet) EXPECT_EQ(static_cast(arr->GetLength()), NODE_NUMBERS * 2); for (int i = 0; i < NODE_NUMBERS; i++) { - EXPECT_EQ(tset->GetKey(arr->Get(i).GetInt()), JSTaggedValue(i)); + EXPECT_EQ(tset->GetKey(thread, arr->Get(thread, i).GetInt()), JSTaggedValue(i)); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); - EXPECT_EQ(tset->GetKey(arr->Get(NODE_NUMBERS + i).GetInt()), key.GetTaggedValue()); + EXPECT_EQ(tset->GetKey(thread, arr->Get(thread, NODE_NUMBERS + i).GetInt()), key.GetTaggedValue()); } } @@ -898,12 +898,12 @@ HWTEST_F_L0(TaggedTreeTest, CustomCompareFunctionTest) JSHandle arr = TaggedTreeMap::GetArrayFromMap(thread, tmap); EXPECT_EQ(static_cast(arr->GetLength()), NODE_NUMBERS * 2); for (int i = NODE_NUMBERS; i < NODE_NUMBERS * 2; i++) { - EXPECT_EQ(tmap->GetKey(arr->Get(i).GetInt()).GetInt(), (NODE_NUMBERS * 2 - 1 - i)); + EXPECT_EQ(tmap->GetKey(thread, arr->Get(thread, i).GetInt()).GetInt(), (NODE_NUMBERS * 2 - 1 - i)); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(NODE_NUMBERS - 1 - i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); - EXPECT_EQ(tmap->GetKey(arr->Get(i).GetInt()), key.GetTaggedValue()); + EXPECT_EQ(tmap->GetKey(thread, arr->Get(thread, i).GetInt()), key.GetTaggedValue()); } // test TaggedTreeSet @@ -927,12 +927,12 @@ HWTEST_F_L0(TaggedTreeTest, CustomCompareFunctionTest) JSHandle sarr = TaggedTreeSet::GetArrayFromSet(thread, tset); EXPECT_EQ(static_cast(arr->GetLength()), NODE_NUMBERS * 2); for (int i = NODE_NUMBERS; i < NODE_NUMBERS * 2; i++) { - EXPECT_EQ(tset->GetKey(sarr->Get(i).GetInt()), JSTaggedValue(NODE_NUMBERS * 2 - 1 - i)); + EXPECT_EQ(tset->GetKey(thread, sarr->Get(thread, i).GetInt()), JSTaggedValue(NODE_NUMBERS * 2 - 1 - i)); } for (int i = 0; i < NODE_NUMBERS; i++) { std::string ikey = myKey + std::to_string(NODE_NUMBERS - 1 - i); key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); - EXPECT_EQ(tset->GetKey(sarr->Get(i).GetInt()), key.GetTaggedValue()); + EXPECT_EQ(tset->GetKey(thread, sarr->Get(thread, i).GetInt()), key.GetTaggedValue()); } } diff --git a/ecmascript/tests/tagged_value_test.cpp b/ecmascript/tests/tagged_value_test.cpp index 7804c634e6..e6e5196137 100644 --- a/ecmascript/tests/tagged_value_test.cpp +++ b/ecmascript/tests/tagged_value_test.cpp @@ -675,7 +675,7 @@ void CheckOkString(JSThread *thread, const JSHandle &tagged, CStr { JSHandle result = JSTaggedValue::ToString(thread, tagged); JSHandle rightString = thread->GetEcmaVM()->GetFactory()->NewFromASCII(rightCStr); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(EcmaString::Cast(result.GetObject()), + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, EcmaString::Cast(result.GetObject()), EcmaString::Cast(rightString.GetObject()))); } @@ -747,22 +747,22 @@ HWTEST_F_L0(JSTaggedValueTest, ToObject) JSHandle value1(thread, JSTaggedValue(2)); JSTaggedValue tagged1 = - JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value1))->GetValue()); + JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value1))->GetValue(thread)); EXPECT_EQ(tagged1.GetRawData(), JSTaggedValue(2).GetRawData()); JSHandle value2(thread, JSTaggedValue(2.2)); JSTaggedValue tagged2 = - JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value2))->GetValue()); + JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value2))->GetValue(thread)); EXPECT_EQ(tagged2.GetRawData(), JSTaggedValue(static_cast(2.2)).GetRawData()); JSHandle value3(thread, JSTaggedValue::True()); JSTaggedValue tagged3 = - JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value3))->GetValue()); + JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value3))->GetValue(thread)); EXPECT_EQ(tagged3.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle value4(factory->NewFromASCII("aaa")); JSTaggedValue tagged4 = - JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value4))->GetValue()); + JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value4))->GetValue(thread)); EXPECT_TRUE(tagged4.IsString()); EXPECT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(thread, tagged4), JSHandle(value4)), 0); @@ -771,9 +771,9 @@ HWTEST_F_L0(JSTaggedValueTest, ToObject) JSHandle str = factory->NewFromASCII("bbb"); JSHandle value5(symbol); JSTaggedValue tagged5 = - JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value5))->GetValue()); + JSTaggedValue(JSHandle::Cast(JSTaggedValue::ToObject(thread, value5))->GetValue(thread)); EXPECT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(thread, - EcmaString::Cast(reinterpret_cast(tagged5.GetRawData())->GetDescription())), str), + EcmaString::Cast(reinterpret_cast(tagged5.GetRawData())->GetDescription(thread))), str), 0); EXPECT_TRUE(tagged5.IsSymbol()); @@ -926,52 +926,53 @@ HWTEST_F_L0(JSTaggedValueTest, SameValue) JSHandle jsObj = ecma->GetFactory()->NewJSObjectByConstructor(JSHandle(objectFun), objectFun); // not same type - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue::False())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1.0), JSTaggedValue::True())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1), + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(1), JSTaggedValue::False())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(1.0), JSTaggedValue::True())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(1), ecma->GetFactory()->NewFromASCII("test").GetTaggedValue())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue(*jsObj))); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(1), JSTaggedValue(*jsObj))); JSHandle test(ecma->GetFactory()->NewFromASCII("test")); - ASSERT_FALSE(JSTaggedValue::SameValue(test.GetTaggedValue(), JSTaggedValue(*jsObj))); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, test.GetTaggedValue(), JSTaggedValue(*jsObj))); // number compare - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue(1))); - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue(1), JSTaggedValue(1.0))); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1.0), JSTaggedValue(2.0))); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(std::numeric_limits::quiet_NaN()), JSTaggedValue(2.0))); - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue(std::numeric_limits::quiet_NaN()), + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue(1), JSTaggedValue(1))); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue(1), JSTaggedValue(1.0))); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(1.0), JSTaggedValue(2.0))); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, + JSTaggedValue(std::numeric_limits::quiet_NaN()), JSTaggedValue(2.0))); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue(std::numeric_limits::quiet_NaN()), JSTaggedValue(std::numeric_limits::quiet_NaN()))); - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue(std::numeric_limits::quiet_NaN()), + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue(std::numeric_limits::quiet_NaN()), JSTaggedValue(std::numeric_limits::quiet_NaN()))); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(0.0), JSTaggedValue(-0.0))); - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue(0), JSTaggedValue(-0))); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue(1.0), JSTaggedValue(-1.0))); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(0.0), JSTaggedValue(-0.0))); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue(0), JSTaggedValue(-0))); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue(1.0), JSTaggedValue(-1.0))); // string compare JSHandle test1(ecma->GetFactory()->NewFromASCII("test1")); - ASSERT_FALSE(JSTaggedValue::SameValue(test.GetTaggedValue(), test1.GetTaggedValue())); - ASSERT_TRUE(JSTaggedValue::SameValue(test.GetTaggedValue(), test.GetTaggedValue())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, test.GetTaggedValue(), test1.GetTaggedValue())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, test.GetTaggedValue(), test.GetTaggedValue())); // bool compare - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue::True(), JSTaggedValue::True())); - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue::False(), JSTaggedValue::False())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue::False(), JSTaggedValue::True())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue::True(), JSTaggedValue::False())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue::True(), JSTaggedValue::True())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue::False(), JSTaggedValue::False())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue::False(), JSTaggedValue::True())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue::True(), JSTaggedValue::False())); // js object compare - ASSERT_TRUE(JSTaggedValue::SameValue(jsObj.GetTaggedValue(), jsObj.GetTaggedValue())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, jsObj.GetTaggedValue(), jsObj.GetTaggedValue())); // undefined or null compare - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue::Undefined(), JSTaggedValue::Undefined())); - ASSERT_TRUE(JSTaggedValue::SameValue(JSTaggedValue::Null(), JSTaggedValue::Null())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue::Undefined(), JSTaggedValue::Null())); - ASSERT_FALSE(JSTaggedValue::SameValue(JSTaggedValue::Null(), JSTaggedValue::Undefined())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue::Undefined(), JSTaggedValue::Undefined())); + ASSERT_TRUE(JSTaggedValue::SameValue(thread, JSTaggedValue::Null(), JSTaggedValue::Null())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue::Undefined(), JSTaggedValue::Null())); + ASSERT_FALSE(JSTaggedValue::SameValue(thread, JSTaggedValue::Null(), JSTaggedValue::Undefined())); } HWTEST_F_L0(JSTaggedValueTest, SameValueZero) { // SameValueZero differs from SameValue only in its treatment of +0 and -0. - ASSERT_TRUE(JSTaggedValue::SameValueZero(JSTaggedValue(0.0), JSTaggedValue(-0.0))); + ASSERT_TRUE(JSTaggedValue::SameValueZero(thread, JSTaggedValue(0.0), JSTaggedValue(-0.0))); } HWTEST_F_L0(JSTaggedValueTest, Less) diff --git a/ecmascript/tests/template_map_test.cpp b/ecmascript/tests/template_map_test.cpp index 84c2d9cd8c..1b2c82d16b 100644 --- a/ecmascript/tests/template_map_test.cpp +++ b/ecmascript/tests/template_map_test.cpp @@ -48,8 +48,8 @@ HWTEST_F_L0(TemplateMapTest, CreateTemplateMap) EXPECT_EQ(templateMap->HoleEntriesCount(), 0); EXPECT_EQ(templateMap->Size(), numElementsTempMap); for (int32_t i = 0; i < numElementsTempMap; i++) { - EXPECT_EQ(templateMap->GetKey(i), JSTaggedValue::Undefined()); - EXPECT_EQ(templateMap->GetValue(i), JSTaggedValue::Undefined()); + EXPECT_EQ(templateMap->GetKey(thread, i), JSTaggedValue::Undefined()); + EXPECT_EQ(templateMap->GetValue(thread, i), JSTaggedValue::Undefined()); } } @@ -73,22 +73,22 @@ HWTEST_F_L0(TemplateMapTest, Insert) JSHandle templateArrVal1(factory->NewFromASCII("key1")); TemplateMap::Insert(thread, templateMap, tempMapKey, templateArrVal); - int keyEntry = templateMap->FindEntry(tempMapKey.GetTaggedValue()); - EXPECT_EQ(templateMap->GetKey(keyEntry), tempMapKey.GetTaggedValue()); - EXPECT_EQ(templateMap->GetValue(keyEntry), templateArrVal.GetTaggedValue()); + int keyEntry = templateMap->FindEntry(thread, tempMapKey.GetTaggedValue()); + EXPECT_EQ(templateMap->GetKey(thread, keyEntry), tempMapKey.GetTaggedValue()); + EXPECT_EQ(templateMap->GetValue(thread, keyEntry), templateArrVal.GetTaggedValue()); TemplateMap::Insert(thread, templateMap, tempMapKey, templateArrVal1); - int keyEntry1 = templateMap->FindEntry(tempMapKey.GetTaggedValue()); + int keyEntry1 = templateMap->FindEntry(thread, tempMapKey.GetTaggedValue()); EXPECT_EQ(keyEntry, keyEntry1); - EXPECT_EQ(templateMap->GetKey(keyEntry1), tempMapKey.GetTaggedValue()); - EXPECT_EQ(templateMap->GetValue(keyEntry1), templateArrVal1.GetTaggedValue()); + EXPECT_EQ(templateMap->GetKey(thread, keyEntry1), tempMapKey.GetTaggedValue()); + EXPECT_EQ(templateMap->GetValue(thread, keyEntry1), templateArrVal1.GetTaggedValue()); TemplateMap::Insert(thread, templateMap, tempMapKey1, templateArrVal1); - int keyEntry2 = templateMap->FindEntry(tempMapKey1.GetTaggedValue()); + int keyEntry2 = templateMap->FindEntry(thread, tempMapKey1.GetTaggedValue()); EXPECT_NE(keyEntry1, keyEntry2); - EXPECT_EQ(templateMap->GetKey(keyEntry2), tempMapKey1.GetTaggedValue()); - EXPECT_EQ(templateMap->GetValue(keyEntry2), templateArrVal1.GetTaggedValue()); - EXPECT_EQ(templateMap->GetValue(keyEntry), templateArrVal1.GetTaggedValue()); + EXPECT_EQ(templateMap->GetKey(thread, keyEntry2), tempMapKey1.GetTaggedValue()); + EXPECT_EQ(templateMap->GetValue(thread, keyEntry2), templateArrVal1.GetTaggedValue()); + EXPECT_EQ(templateMap->GetValue(thread, keyEntry), templateArrVal1.GetTaggedValue()); } /* @@ -278,9 +278,9 @@ HWTEST_F_L0(TemplateMapTest, GetAllKeys) JSHandle storeKeyArray = factory->NewTaggedArray(55); // 55 : means the length of array templateMap->GetAllKeys(thread, 5, *storeKeyArray); // 5: means the index of array for (int32_t i = 0; i < numElements; i++) { - EXPECT_NE(templateMap->GetKey(i), JSTaggedValue::Undefined()); + EXPECT_NE(templateMap->GetKey(thread, i), JSTaggedValue::Undefined()); // 5: get value from subscript five - EXPECT_EQ(templateMap->GetKey(i), storeKeyArray->Get(i + 5)); + EXPECT_EQ(templateMap->GetKey(thread, i), storeKeyArray->Get(thread, i + 5)); } } @@ -304,10 +304,10 @@ HWTEST_F_L0(TemplateMapTest, GetAllKeysIntoVector) templateMap = TemplateMap::Insert(thread, templateMap, tempMapKey, tempMapValue); } std::vector storeKeyVector = {}; - templateMap->GetAllKeysIntoVector(storeKeyVector); + templateMap->GetAllKeysIntoVector(thread, storeKeyVector); for (int32_t i = 0; i < numElements; i++) { - EXPECT_NE(templateMap->GetKey(i), JSTaggedValue::Undefined()); - EXPECT_EQ(templateMap->GetKey(i), storeKeyVector[i]); + EXPECT_NE(templateMap->GetKey(thread, i), JSTaggedValue::Undefined()); + EXPECT_EQ(templateMap->GetKey(thread, i), storeKeyVector[i]); } } @@ -333,9 +333,10 @@ HWTEST_F_L0(TemplateMapTest, FindInsertIndex) for (int i = 0; i < numElements; i++) { JSHandle tempMapKey(JSArray::ArrayCreate(thread, JSTaggedNumber(i))); - uint32_t hashValue = static_cast(TemplateMap::Hash(tempMapKey.GetTaggedValue())); + uint32_t hashValue = static_cast(TemplateMap::Hash(thread, tempMapKey.GetTaggedValue())); EXPECT_EQ(JSTaggedValue::Undefined(), templateMap->GetKey( - templateMap->FindInsertIndex(hashValue))); + thread, + templateMap->FindInsertIndex(thread, hashValue))); } } } // namespace panda::test diff --git a/ecmascript/tests/template_string_test.cpp b/ecmascript/tests/template_string_test.cpp index 4683b53656..0fba8ff513 100644 --- a/ecmascript/tests/template_string_test.cpp +++ b/ecmascript/tests/template_string_test.cpp @@ -73,7 +73,7 @@ HWTEST_F_L0(TemplateStringTest, GetTemplateObject) // call "GetTemplateObject" function JSHandle templateObject = TemplateString::GetTemplateObject(thread, templateLiteral); // find jsArray in templateMap - int resultEntry = templateMap->FindEntry(jsArrayObj.GetTaggedValue()); + int resultEntry = templateMap->FindEntry(thread, jsArrayObj.GetTaggedValue()); EXPECT_NE(resultEntry, -1); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); @@ -87,6 +87,6 @@ HWTEST_F_L0(TemplateStringTest, GetTemplateObject) TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); - EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(reinterpret_cast(result.GetRawData()), *testString)); + EXPECT_TRUE(EcmaStringAccessor::StringsAreEqual(thread, reinterpret_cast(result.GetRawData()), *testString)); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/transitions_dictionary_test.cpp b/ecmascript/tests/transitions_dictionary_test.cpp index 3a5e75b7b4..35f1db8950 100644 --- a/ecmascript/tests/transitions_dictionary_test.cpp +++ b/ecmascript/tests/transitions_dictionary_test.cpp @@ -50,12 +50,12 @@ HWTEST_F_L0(TransitionsDictionaryTest, Hash) // test when key is string. JSHandle key1(factory->NewFromStdString("k")); JSHandle metaData1(thread, JSTaggedValue(1)); // test metaData : 1 - int hash = TransitionsDictionary::Hash(key1.GetTaggedValue(), metaData1.GetTaggedValue()); + int hash = TransitionsDictionary::Hash(thread, key1.GetTaggedValue(), metaData1.GetTaggedValue()); // "k" : 107, hashSeed : 0, shift : 5, metaData : 1 EXPECT_EQ(hash, 108); // 108 : (0 << 5) - 0 + 107 + 1 JSHandle key2(factory->NewFromStdString("key")); - hash = TransitionsDictionary::Hash(key2.GetTaggedValue(), metaData1.GetTaggedValue()); + hash = TransitionsDictionary::Hash(thread, key2.GetTaggedValue(), metaData1.GetTaggedValue()); EXPECT_EQ(hash, 106080); // test when key is symbol. @@ -63,7 +63,7 @@ HWTEST_F_L0(TransitionsDictionaryTest, Hash) JSHandle privateNameSymbol = factory->NewPrivateNameSymbol(symbolName); JSHandle symbolValue = JSHandle::Cast(privateNameSymbol); JSHandle metaData2(thread, JSTaggedValue(2)); // test metaData : 2 - hash = TransitionsDictionary::Hash(symbolValue.GetTaggedValue(), metaData2.GetTaggedValue()); + hash = TransitionsDictionary::Hash(thread, symbolValue.GetTaggedValue(), metaData2.GetTaggedValue()); EXPECT_EQ(hash, 117); // 117 : 115 + 2 } @@ -125,7 +125,7 @@ HWTEST_F_L0(TransitionsDictionaryTest, Get_Set_Attributes) for (int index = 0; index < numberOfElements; index++) { transDic->SetAttributes(thread, index, JSTaggedValue(index)); - JSTaggedValue value = transDic->GetAttributes(index); + JSTaggedValue value = transDic->GetAttributes(thread, index); EXPECT_EQ(value, JSTaggedValue(index)); } } @@ -154,7 +154,7 @@ HWTEST_F_L0(TransitionsDictionaryTest, SetEntry) [&](JSThread *thread, int index, JSHandle &key, JSHandle &value) { transDic->SetEntry(thread, index, key.GetTaggedValue(), value.GetTaggedValue(), metaData.GetTaggedValue()); - EXPECT_EQ(transDic->GetKey(index), key.GetTaggedValue()); + EXPECT_EQ(transDic->GetKey(thread, index), key.GetTaggedValue()); }); } @@ -167,7 +167,7 @@ HWTEST_F_L0(TransitionsDictionaryTest, FindEntry) TestCommon(thread, numberOfElements, [&](JSThread *thread, int index, JSHandle &key, JSHandle &value) { transDic = TransitionsDictionary::PutIfAbsent(thread, transDic, key, value, metaData); - int foundEntry = transDic->FindEntry(key.GetTaggedValue(), metaData.GetTaggedValue()); + int foundEntry = transDic->FindEntry(thread, key.GetTaggedValue(), metaData.GetTaggedValue()); EXPECT_EQ(index + 3, foundEntry); // 3 : table header size }); } @@ -183,12 +183,12 @@ HWTEST_F_L0(TransitionsDictionaryTest, RemoveElement) }); auto factory = thread->GetEcmaVM()->GetFactory(); JSHandle key7(factory->NewFromStdString("key7")); // test remove element by "key7" - int foundEntry = transDic->FindEntry(key7.GetTaggedValue(), metaData.GetTaggedValue()); + int foundEntry = transDic->FindEntry(thread, key7.GetTaggedValue(), metaData.GetTaggedValue()); EXPECT_EQ(foundEntry, 7 + 3); EXPECT_EQ(transDic->EntriesCount(), 8); transDic->RemoveElement(thread, foundEntry); - foundEntry = transDic->FindEntry(key7.GetTaggedValue(), metaData.GetTaggedValue()); + foundEntry = transDic->FindEntry(thread, key7.GetTaggedValue(), metaData.GetTaggedValue()); EXPECT_EQ(foundEntry, -1); // -1 : not found entry EXPECT_EQ(transDic->EntriesCount(), 7); } @@ -206,10 +206,10 @@ HWTEST_F_L0(TransitionsDictionaryTest, PutIfAbsent) JSHandle key(factory->NewFromStdString(keyStr)); JSHandle value(factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_OBJECT)); transDic = TransitionsDictionary::PutIfAbsent(thread, transDic, key, value, metaData); - int foundEntry = transDic->FindEntry(key.GetTaggedValue(), metaData.GetTaggedValue()); + int foundEntry = transDic->FindEntry(thread, key.GetTaggedValue(), metaData.GetTaggedValue()); EXPECT_EQ(foundEntry, index + 3); - JSTaggedValue foundValue = transDic->GetValue(foundEntry); + JSTaggedValue foundValue = transDic->GetValue(thread, foundEntry); JSTaggedValue weakValue = value->CreateAndGetWeakRef(); EXPECT_EQ(foundValue, weakValue); } diff --git a/ecmascript/tests/weak_ref_old_gc_test.cpp b/ecmascript/tests/weak_ref_old_gc_test.cpp index 569ab23a35..9d85ec1d03 100644 --- a/ecmascript/tests/weak_ref_old_gc_test.cpp +++ b/ecmascript/tests/weak_ref_old_gc_test.cpp @@ -72,11 +72,11 @@ HWTEST_F_L0(WeakRefOldGCTest, ArrayNonMovable) JSTaggedValue value(newObj2); value.CreateWeakRef(); array->Set(thread, 1, value); - EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(0)); - EXPECT_EQ(value, array->Get(1)); + EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(thread, 0)); + EXPECT_EQ(value, array->Get(thread, 1)); vm->CollectGarbage(TriggerGCType::OLD_GC); - EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(0)); - EXPECT_EQ(JSTaggedValue::Undefined(), array->Get(1)); + EXPECT_EQ(newObj1.GetTaggedValue(), array->Get(thread, 0)); + EXPECT_EQ(JSTaggedValue::Undefined(), array->Get(thread, 1)); } HWTEST_F_L0(WeakRefOldGCTest, ArrayUndefined) @@ -95,9 +95,9 @@ HWTEST_F_L0(WeakRefOldGCTest, ObjectUndefined) JSTaggedValue array(ArrayTestCreate(thread)); array.CreateWeakRef(); newObj1->SetElements(thread, array); - EXPECT_EQ(newObj1->GetElements(), array); + EXPECT_EQ(newObj1->GetElements(thread), array); thread->GetEcmaVM()->CollectGarbage(TriggerGCType::OLD_GC); - EXPECT_EQ(newObj1->GetElements(), JSTaggedValue::Undefined()); + EXPECT_EQ(newObj1->GetElements(thread), JSTaggedValue::Undefined()); } HWTEST_F_L0(WeakRefOldGCTest, ObjectKeep) @@ -107,11 +107,11 @@ HWTEST_F_L0(WeakRefOldGCTest, ObjectKeep) JSTaggedValue value = array.GetTaggedValue(); value.CreateWeakRef(); newObj1->SetElements(thread, value); - EXPECT_EQ(newObj1->GetElements(), value); + EXPECT_EQ(newObj1->GetElements(thread), value); thread->GetEcmaVM()->CollectGarbage(TriggerGCType::OLD_GC); value = array.GetTaggedValue(); value.CreateWeakRef(); - EXPECT_EQ(newObj1->GetElements(), value); + EXPECT_EQ(newObj1->GetElements(thread), value); } HWTEST_F_L0(WeakRefOldGCTest, WeakRefTest) @@ -180,7 +180,7 @@ HWTEST_F_L0(WeakRefOldGCTest, WeakRefTest) } for (auto it : srcArrayHandleRecord) { for (uint32_t i = 0; i < 40; i++) { - EXPECT_TRUE(it->Get(i) != JSTaggedValue::Undefined()); + EXPECT_TRUE(it->Get(thread, i) != JSTaggedValue::Undefined()); } } } diff --git a/ecmascript/tests/weak_ref_semi_gc_test.cpp b/ecmascript/tests/weak_ref_semi_gc_test.cpp index 1be28436dd..6df4faf028 100644 --- a/ecmascript/tests/weak_ref_semi_gc_test.cpp +++ b/ecmascript/tests/weak_ref_semi_gc_test.cpp @@ -50,9 +50,9 @@ HWTEST_F_L0(WeakRefSemiGCTest, ObjectUndefined) JSTaggedValue array(ArrayTestCreate(thread)); array.CreateWeakRef(); newObj1->SetElements(thread, array); - EXPECT_EQ(newObj1->GetElements(), array); + EXPECT_EQ(newObj1->GetElements(thread), array); thread->GetEcmaVM()->CollectGarbage(TriggerGCType::YOUNG_GC); - EXPECT_EQ(newObj1->GetElements(), JSTaggedValue::Undefined()); + EXPECT_EQ(newObj1->GetElements(thread), JSTaggedValue::Undefined()); } HWTEST_F_L0(WeakRefSemiGCTest, ObjectKeep) @@ -62,10 +62,10 @@ HWTEST_F_L0(WeakRefSemiGCTest, ObjectKeep) JSTaggedValue value = array.GetTaggedValue(); value.CreateWeakRef(); newObj1->SetElements(thread, value); - EXPECT_EQ(newObj1->GetElements(), value); + EXPECT_EQ(newObj1->GetElements(thread), value); thread->GetEcmaVM()->CollectGarbage(TriggerGCType::YOUNG_GC); value = array.GetTaggedValue(); value.CreateWeakRef(); - EXPECT_EQ(newObj1->GetElements(), value); + EXPECT_EQ(newObj1->GetElements(thread), value); } } // namespace panda::test diff --git a/ecmascript/tests/weak_vector_test.cpp b/ecmascript/tests/weak_vector_test.cpp index 81cc60ab2a..dcee13e3f2 100644 --- a/ecmascript/tests/weak_vector_test.cpp +++ b/ecmascript/tests/weak_vector_test.cpp @@ -63,7 +63,7 @@ HWTEST_F_L0(WeakVectorTest, SetAndGet) // set weak value for (uint32_t i = 0; i < weakVectorCapacity; i++) { weakVector->Set(thread, i, weakValue); - EXPECT_EQ(weakVector->Get(i), weakValue); + EXPECT_EQ(weakVector->Get(thread, i), weakValue); } } @@ -100,7 +100,7 @@ HWTEST_F_L0(WeakVectorTest, Grow) newWeakVector = newWeakVector->Grow(thread, newWeakVector, newWeakVectorCapacity); EXPECT_EQ(newWeakVector->GetCapacity(), newWeakVectorCapacity); for (uint32_t i = 0; i < oldWeakVectorCapacity; i++) { - EXPECT_EQ(newWeakVector->Get(i), weakValue); + EXPECT_EQ(newWeakVector->Get(thread, i), weakValue); } EXPECT_EQ(newWeakVector->GetEnd(), 0U); thread->GetEcmaVM()->SetEnableForceGC(true); // turn on gc @@ -136,10 +136,10 @@ HWTEST_F_L0(WeakVectorTest, PushBack) EXPECT_EQ(weakVector->GetEnd(), pushWeakVectorCapacity); for (uint32_t i = 0; i < pushWeakVectorCapacity; i++) { - EXPECT_TRUE(weakVector->Get(i).IsHole()); + EXPECT_TRUE(weakVector->Get(thread, i).IsHole()); } for (uint32_t i = pushWeakVectorCapacity; i < weakVectorCapacity; i++) { - EXPECT_EQ(weakVector->Get(i), weakValue); + EXPECT_EQ(weakVector->Get(thread, i), weakValue); } } @@ -170,7 +170,7 @@ HWTEST_F_L0(WeakVectorTest, Delete) for (uint32_t i = 0; i < weakVectorCapacity; i++) { EXPECT_TRUE(weakVector->Delete(thread, i)); - EXPECT_TRUE(weakVector->Get(i).IsHole()); + EXPECT_TRUE(weakVector->Get(thread, i).IsHole()); } EXPECT_FALSE(weakVector->Empty()); EXPECT_EQ(weakVector->GetCapacity(), weakVectorCapacity); diff --git a/ecmascript/transitions_dictionary.h b/ecmascript/transitions_dictionary.h index a2e37d4524..9b471ecaa5 100644 --- a/ecmascript/transitions_dictionary.h +++ b/ecmascript/transitions_dictionary.h @@ -25,7 +25,8 @@ namespace panda::ecmascript { class TransitionsDictionary : public TaggedHashTable { public: using HashTableT = TaggedHashTable; - static inline bool IsMatch([[maybe_unused]] const JSTaggedValue &key, + static inline bool IsMatch([[maybe_unused]] const JSThread *thread, + [[maybe_unused]] const JSTaggedValue &key, [[maybe_unused]] const JSTaggedValue &otherKey) { LOG_ECMA(FATAL) << "this branch is unreachable"; @@ -43,13 +44,13 @@ public: return key == otherKey && metaData == otherDetails; } - static inline int Hash(const JSTaggedValue &key, const JSTaggedValue &metaData) + static inline int Hash(const JSThread *thread, const JSTaggedValue &key, const JSTaggedValue &metaData) { ASSERT(key.IsStringOrSymbol()); uint32_t hash = 0; if (key.IsString()) { - hash = EcmaStringAccessor(key).GetHashcode(); + hash = EcmaStringAccessor(key).GetHashcode(thread); } else if (key.IsSymbol()) { hash = JSSymbol::Cast(key.GetTaggedObject())->GetHashField(); } @@ -93,10 +94,10 @@ public: return HashTableT::Shrink(thread, dictionary, 0); } - inline JSTaggedValue GetAttributes(int entry) const + inline JSTaggedValue GetAttributes(const JSThread *thread, int entry) const { int index = GetEntryIndex(entry) + ENTRY_DETAILS_INDEX; - return HashTableT::Get(index); + return HashTableT::Get(thread, index); } inline void SetAttributes(const JSThread *thread, int entry, JSTaggedValue metaData) @@ -127,15 +128,15 @@ public: IncreaseHoleEntriesCount(thread); } - int FindEntry(const JSTaggedValue &key, const JSTaggedValue &metaData); + int FindEntry(const JSThread *thread, const JSTaggedValue &key, const JSTaggedValue &metaData); template - void IterateEntryValue(Callback callback) + void IterateEntryValue(const JSThread *thread, Callback callback) { auto number = EntriesCount(); int size = Size(); int hasIteratedNum = 0; for (int entry = 0; entry < size; entry++) { - JSTaggedValue ret = GetValue(entry); + JSTaggedValue ret = GetValue(thread, entry); if (ret.IsWeak()) { auto next = ret.GetTaggedWeakRef(); callback(JSHClass::Cast(next)); @@ -164,13 +165,13 @@ public: return true; } - static int ComputeCompactSize(const JSHandle &table, int computeHashTableSize, + static int ComputeCompactSize(const JSThread *thread, const JSHandle &table, int computeHashTableSize, int tableSize, int addedElements) { int realEntryCount = 0; for (int i = 0; i < tableSize; i++) { // value is weak reference, if not use will be set undefined. - if (TransitionsDictionary::CheckWeakExist(table->GetValue(i))) { + if (TransitionsDictionary::CheckWeakExist(table->GetValue(thread, i))) { realEntryCount++; } } diff --git a/ecmascript/vtable.cpp b/ecmascript/vtable.cpp index 7a03cb54b5..1ddb627dda 100644 --- a/ecmascript/vtable.cpp +++ b/ecmascript/vtable.cpp @@ -22,12 +22,12 @@ VTable::Tuple VTable::CreateTuple(const JSThread *thread, JSTaggedValue phc, { DISALLOW_GARBAGE_COLLECTION; JSHClass *phcPoint = JSHClass::Cast(phc.GetTaggedObject()); - LayoutInfo *layoutInfo = LayoutInfo::Cast(phcPoint->GetLayout().GetTaggedObject()); - JSHandle name(thread, layoutInfo->GetKey(propIndex)); + LayoutInfo *layoutInfo = LayoutInfo::Cast(phcPoint->GetLayout(thread).GetTaggedObject()); + JSHandle name(thread, layoutInfo->GetKey(thread, propIndex)); // get type JSTaggedValue typeVal; - PropertyAttributes attr = layoutInfo->GetAttr(propIndex); + PropertyAttributes attr = layoutInfo->GetAttr(thread, propIndex); if (attr.IsAccessor()) { typeVal = JSTaggedValue(VTable::TypeKind::ACCESSOR); } else { @@ -50,7 +50,7 @@ VTable::Tuple VTable::GetTuple(const JSThread *thread, uint32_t tupleIdx) const { CVector> vec; for (uint32_t loc = 0; loc < ITEM_NUM; ++loc) { - JSTaggedValue val = Get(tupleIdx * TUPLE_SIZE + loc); + JSTaggedValue val = Get(thread, tupleIdx * TUPLE_SIZE + loc); vec.emplace_back(JSHandle(thread, val)); } return Tuple(vec); @@ -71,7 +71,7 @@ void VTable::Trim(const JSThread *thread, uint32_t newLength) TaggedArray::Trim(thread, newLength * VTable::TUPLE_SIZE); } -int VTable::GetTupleIndexByName(JSTaggedValue name) const +int VTable::GetTupleIndexByName(const JSThread *thread, JSTaggedValue name) const { DISALLOW_GARBAGE_COLLECTION; uint32_t len = GetNumberOfTuples(); @@ -83,7 +83,7 @@ int VTable::GetTupleIndexByName(JSTaggedValue name) const ASSERT_PRINT(EcmaStringAccessor(str).IsInternString(), "The name of the property is not an intern string"); for (uint32_t index = 0; index < len; ++index) { - JSTaggedValue nameVal = GetTupleItem(index, VTable::TupleItem::NAME); + JSTaggedValue nameVal = GetTupleItem(thread, index, VTable::TupleItem::NAME); if (nameVal == name) { return index; } @@ -92,9 +92,9 @@ int VTable::GetTupleIndexByName(JSTaggedValue name) const return -1; } -bool VTable::Find(JSTaggedValue name) const +bool VTable::Find(const JSThread *thread, JSTaggedValue name) const { - return GetTupleIndexByName(name) != -1; + return GetTupleIndexByName(thread, name) != -1; } JSHandle VTable::Copy(const JSThread *thread, const JSHandle &vtable) diff --git a/ecmascript/vtable.h b/ecmascript/vtable.h index 2f72e8d5c4..3eec35d2ba 100644 --- a/ecmascript/vtable.h +++ b/ecmascript/vtable.h @@ -68,14 +68,14 @@ public: return GetLength() / TUPLE_SIZE; } - JSTaggedValue GetTupleItem(uint32_t tupleIdx, TupleItem kind) const + JSTaggedValue GetTupleItem(const JSThread *thread, uint32_t tupleIdx, TupleItem kind) const { - return Get(tupleIdx * TUPLE_SIZE + kind); + return Get(thread, tupleIdx * TUPLE_SIZE + kind); } - bool IsAccessor(uint32_t tupleIdx) const + bool IsAccessor(const JSThread *thread, uint32_t tupleIdx) const { - TypeKind type = static_cast(GetTupleItem(tupleIdx, TupleItem::TYPE).GetInt()); + TypeKind type = static_cast(GetTupleItem(thread, tupleIdx, TupleItem::TYPE).GetInt()); return type == TypeKind::ACCESSOR; } @@ -85,9 +85,9 @@ public: void Trim(const JSThread *thread, uint32_t newLength); - int GetTupleIndexByName(JSTaggedValue val) const; + int GetTupleIndexByName(const JSThread *thread, JSTaggedValue val) const; - bool Find(JSTaggedValue val) const; + bool Find(const JSThread *thread, JSTaggedValue val) const; DECL_DUMP() }; diff --git a/ecmascript/weak_vector.cpp b/ecmascript/weak_vector.cpp index 97563c4a30..1054ab10a2 100644 --- a/ecmascript/weak_vector.cpp +++ b/ecmascript/weak_vector.cpp @@ -86,7 +86,7 @@ JSHandle WeakVector::FillOrAppend(const JSThread *thread, const JSHa } // if exist hole, use it. - uint32_t holeIndex = CheckHole(vec); + uint32_t holeIndex = CheckHole(thread, vec); if (holeIndex != TaggedArray::MAX_ARRAY_INDEX) { JSTaggedValue storeVal = GetStoreVal(value, type); vec->Set(thread, holeIndex, storeVal); @@ -133,10 +133,10 @@ JSHandle WeakVector::Copy(const JSThread *thread, const JSHandle(newVec); } -uint32_t WeakVector::CheckHole(const JSHandle &vec) +uint32_t WeakVector::CheckHole(const JSThread *thread, const JSHandle &vec) { for (uint32_t i = 0; i < vec->GetEnd(); i++) { - JSTaggedValue value = vec->Get(i); + JSTaggedValue value = vec->Get(thread, i); if (value.IsHole()) { return i; } diff --git a/ecmascript/weak_vector.h b/ecmascript/weak_vector.h index 5acdc3d10e..474520b76d 100644 --- a/ecmascript/weak_vector.h +++ b/ecmascript/weak_vector.h @@ -68,10 +68,10 @@ public: return TaggedArray::GetLength(); } - inline JSTaggedValue Get(uint32_t index) const + inline JSTaggedValue Get(const JSThread *thread, uint32_t index) const { ASSERT(index < GetCapacity()); - return TaggedArray::Get(VectorToArrayIndex(index)); + return TaggedArray::Get(thread, VectorToArrayIndex(index)); } inline void Set(const JSThread *thread, uint32_t index, JSTaggedValue value) @@ -81,11 +81,11 @@ public: } template - void Iterate(const Callback &cb) + void Iterate(const JSThread *thread, const Callback &cb) { uint32_t end = GetEnd(); for (uint32_t index = 0; index < end; ++index) { - cb(Get(index)); + cb(Get(thread, index)); } } @@ -106,7 +106,7 @@ private: static JSTaggedValue GetStoreVal(const JSHandle &value, ElementType type); - static uint32_t CheckHole(const JSHandle &vec); + static uint32_t CheckHole(const JSThread *thread, const JSHandle &vec); static JSHandle AppendToFullVec(const JSThread *thread, const JSHandle &vec, const JSHandle &value, ElementType type); diff --git a/test/fuzztest/arraylist_fuzzer/arraylist_fuzzer.cpp b/test/fuzztest/arraylist_fuzzer/arraylist_fuzzer.cpp index 7052f172e0..58957faad6 100644 --- a/test/fuzztest/arraylist_fuzzer/arraylist_fuzzer.cpp +++ b/test/fuzztest/arraylist_fuzzer/arraylist_fuzzer.cpp @@ -91,14 +91,15 @@ namespace OHOS { static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle value = argv->GetCallArg(0); JSHandle key = argv->GetCallArg(1); JSHandle arrayList = argv->GetCallArg(2); // 2 means the secode arg if (!arrayList->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIArrayList::Cast(arrayList.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - [[maybe_unused]] JSTaggedValue result = elements->Get(key->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + [[maybe_unused]] JSTaggedValue result = elements->Get(thread, key->GetInt()); } } return JSTaggedValue::Undefined(); diff --git a/test/fuzztest/containersvectorcommon_fuzzer/containersvectorcommon_fuzzer.h b/test/fuzztest/containersvectorcommon_fuzzer/containersvectorcommon_fuzzer.h index 2dff0406bd..cccdcb06bb 100644 --- a/test/fuzztest/containersvectorcommon_fuzzer/containersvectorcommon_fuzzer.h +++ b/test/fuzztest/containersvectorcommon_fuzzer/containersvectorcommon_fuzzer.h @@ -471,14 +471,15 @@ public: public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { + JSThread *thread = argv->GetThread(); JSHandle value = GetCallArg(argv, 0); JSHandle key = GetCallArg(argv, 1); JSHandle vector = GetCallArg(argv, 2); // 2 means the secode arg if (!vector->IsUndefined()) { if (value->IsNumber()) { TaggedArray *elements = TaggedArray::Cast(JSAPIVector::Cast(vector.GetTaggedValue(). - GetTaggedObject())->GetElements().GetTaggedObject()); - elements->Get(key->GetInt()); + GetTaggedObject())->GetElements(thread).GetTaggedObject()); + elements->Get(thread, key->GetInt()); } } return JSTaggedValue::Undefined(); diff --git a/test/fuzztest/functionrefinherit_fuzzer/functionrefinherit_fuzzer.cpp b/test/fuzztest/functionrefinherit_fuzzer/functionrefinherit_fuzzer.cpp index d2b584e452..b04a1c0eab 100644 --- a/test/fuzztest/functionrefinherit_fuzzer/functionrefinherit_fuzzer.cpp +++ b/test/fuzztest/functionrefinherit_fuzzer/functionrefinherit_fuzzer.cpp @@ -42,10 +42,10 @@ void FunctionRefInheritFuzzTest([[maybe_unused]]const uint8_t *data, size_t size Local setLocal = JSNApiHelper::ToLocal(set); JSHandle map = env->GetBuiltinsMapFunction(); Local mapLocal = JSNApiHelper::ToLocal(map); - JSHandle setPrototype(thread, JSHandle::Cast(set)->GetFunctionPrototype()); - JSHandle mapPrototype(thread, JSHandle::Cast(map)->GetFunctionPrototype()); + JSHandle setPrototype(thread, JSHandle::Cast(set)->GetFunctionPrototype(thread)); + JSHandle mapPrototype(thread, JSHandle::Cast(map)->GetFunctionPrototype(thread)); JSHandle mapPrototypeProto(thread, JSTaggedValue::GetPrototype(thread, mapPrototype)); - JSTaggedValue::SameValue(setPrototype, mapPrototypeProto); + JSTaggedValue::SameValue(thread, setPrototype, mapPrototypeProto); mapLocal->Inherit(vm, setLocal); } JSNApi::DestroyJSVM(vm); diff --git a/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp b/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp index 62f523dd35..0530f4a406 100644 --- a/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp +++ b/test/fuzztest/jsvaluerefismodulenamespace_fuzzer/jsvaluerefismodulenamespace_fuzzer.cpp @@ -50,7 +50,7 @@ void IsModuleNamespaceObjectFuzztest([[maybe_unused]]const uint8_t *data, size_t SourceTextModule::AddLocalExportEntry(vm->GetJSThread(), module, localExportEntry1, 0, ERROR_TYPE_LEN); JSHandle localExportEntry2 = objectFactory->NewLocalExportEntry(); SourceTextModule::AddLocalExportEntry(vm->GetJSThread(), module, localExportEntry2, 1, ERROR_TYPE_LEN); - JSHandle localExportEntries(vm->GetJSThread(), module->GetLocalExportEntries()); + JSHandle localExportEntries(vm->GetJSThread(), module->GetLocalExportEntries(vm->GetJSThread())); CString baseFileName = "a.abc"; module->SetEcmaModuleFilenameString(baseFileName); ModuleManager *moduleManager = vm->GetJSThread()->GetModuleManager(); diff --git a/test/fuzztest/setiteratorrefget_fuzzer/setiteratorrefget_fuzzer.cpp b/test/fuzztest/setiteratorrefget_fuzzer/setiteratorrefget_fuzzer.cpp index 961d334b7b..a276dd7de6 100644 --- a/test/fuzztest/setiteratorrefget_fuzzer/setiteratorrefget_fuzzer.cpp +++ b/test/fuzztest/setiteratorrefget_fuzzer/setiteratorrefget_fuzzer.cpp @@ -59,7 +59,7 @@ void SetIteratorRefGetFuzzTest([[maybe_unused]]const uint8_t *data, size_t size) JSHandle jsTagSetIterator = JSSetIterator::CreateSetIterator(thread, JSHandle(jsSet), IterationKind::KEY); JSHandle jsSetIterator1(jsTagSetIterator); - JSTaggedValue::SameValue(jsSetIterator1->GetIteratedSet(), jsSet->GetLinkedSet()); + JSTaggedValue::SameValue(thread, jsSetIterator1->GetIteratedSet(thread), jsSet->GetLinkedSet(thread)); Local setIterator = JSNApiHelper::ToLocal(jsTagSetIterator); Local setIterator1 = setIterator; setIterator1->IsSetIterator(vm); -- Gitee