mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 01:59:58 +00:00
optimize compiler
Issue:#IALVU8 Signed-off-by: fangting <fangting12@huawei.com>
This commit is contained in:
parent
5be332038b
commit
cdbfa4340e
@ -38,7 +38,6 @@
|
||||
#include "ecmascript/mem/shared_heap/shared_concurrent_marker.h"
|
||||
#include "ecmascript/module/module_logger.h"
|
||||
#include "ecmascript/pgo_profiler/pgo_trace.h"
|
||||
#include "ecmascript/runtime.h"
|
||||
#include "ecmascript/snapshot/mem/snapshot.h"
|
||||
#include "ecmascript/stubs/runtime_stubs.h"
|
||||
#include "ecmascript/ohos/jit_tools.h"
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
JSHandle<JSObject> GeneratorHelper::Next(JSThread *thread, const JSHandle<GeneratorContext> &genContext,
|
||||
|
@ -15,19 +15,10 @@
|
||||
|
||||
#include "ecmascript/global_env_constants.h"
|
||||
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/builtins/builtins.h"
|
||||
#include "ecmascript/builtins/builtins_global.h"
|
||||
#include "ecmascript/ecma_string-inl.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/free_object.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/ic/ic_handler.h"
|
||||
#include "ecmascript/ic/property_box.h"
|
||||
#include "ecmascript/ic/proto_change_details.h"
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
#include "ecmascript/jobs/pending_job.h"
|
||||
#include "ecmascript/js_api/js_api_arraylist_iterator.h"
|
||||
#include "ecmascript/js_api/js_api_bitvector_iterator.h"
|
||||
@ -45,43 +36,20 @@
|
||||
#include "ecmascript/js_api/js_api_tree_set_iterator.h"
|
||||
#include "ecmascript/js_api/js_api_vector_iterator.h"
|
||||
#include "ecmascript/js_async_generator_object.h"
|
||||
#include "ecmascript/jspandafile/class_info_extractor.h"
|
||||
#include "ecmascript/jspandafile/class_literal.h"
|
||||
#include "ecmascript/jspandafile/program_object.h"
|
||||
#include "ecmascript/js_arguments.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_array_iterator.h"
|
||||
#include "ecmascript/js_arraybuffer.h"
|
||||
#include "ecmascript/js_finalization_registry.h"
|
||||
#include "ecmascript/js_for_in_iterator.h"
|
||||
#include "ecmascript/js_generator_object.h"
|
||||
#include "ecmascript/js_hclass.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_map.h"
|
||||
#include "ecmascript/js_map_iterator.h"
|
||||
#include "ecmascript/js_primitive_ref.h"
|
||||
#include "ecmascript/js_promise.h"
|
||||
#include "ecmascript/js_proxy.h"
|
||||
#include "ecmascript/js_realm.h"
|
||||
#include "ecmascript/js_regexp.h"
|
||||
#include "ecmascript/js_regexp_iterator.h"
|
||||
#include "ecmascript/js_set.h"
|
||||
#include "ecmascript/js_set_iterator.h"
|
||||
#include "ecmascript/js_symbol.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/marker_cell.h"
|
||||
#include "ecmascript/method.h"
|
||||
#include "ecmascript/module/js_module_source_text.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/runtime.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array_iterator.h"
|
||||
#include "ecmascript/shared_objects/js_shared_map.h"
|
||||
#include "ecmascript/shared_objects/js_shared_map_iterator.h"
|
||||
#include "ecmascript/shared_objects/js_shared_set.h"
|
||||
#include "ecmascript/shared_objects/js_shared_set_iterator.h"
|
||||
#include "ecmascript/tagged_node.h"
|
||||
#include "ecmascript/vtable.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,13 +15,9 @@
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "ecmascript/checkpoint/thread_state_transition.h"
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/checkpoint/thread_state_transition.h"
|
||||
|
||||
#if defined(__clang__)
|
||||
|
@ -17,13 +17,8 @@
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_api/js_api_arraylist_iterator.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ContainerError = containers::ContainerError;
|
||||
|
@ -15,13 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_arraylist_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_arraylist.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -15,17 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_bitvector.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_tagged_number.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/shared_objects/concurrent_api_scope.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,11 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_bitvector_iterator.h"
|
||||
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_bitvector.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/shared_objects/concurrent_api_scope.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,13 +16,7 @@
|
||||
#include "ecmascript/js_api/js_api_deque.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/js_object.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,16 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_deque_iterator.h"
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/js_api/js_api_deque.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -16,11 +16,7 @@
|
||||
#include "ecmascript/js_api/js_api_hashmap.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_hash_array.h"
|
||||
#include "ecmascript/tagged_node.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ContainerError = containers::ContainerError;
|
||||
|
@ -15,13 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_hashmap_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_api/js_api_hashmap.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_node.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/tagged_hash_array.h"
|
||||
#include "ecmascript/tagged_node.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ContainerError = containers::ContainerError;
|
||||
|
@ -15,14 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_hashset_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_api/js_api_hashset.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_node.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
using ContainerError = containers::ContainerError;
|
||||
|
@ -16,13 +16,7 @@
|
||||
#include "ecmascript/js_api/js_api_lightweightmap.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/js_tagged_number.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
#include <codecvt>
|
||||
|
||||
|
@ -15,14 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_lightweightmap_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_lightweightmap.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -17,11 +17,8 @@
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_api/js_api_lightweightset_iterator.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
#include <codecvt>
|
||||
|
||||
|
@ -16,13 +16,9 @@
|
||||
#include "ecmascript/js_api/js_api_lightweightset_iterator.h"
|
||||
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_lightweightset.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -16,12 +16,6 @@
|
||||
#include "ecmascript/js_api/js_api_linked_list.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_api/js_api_linked_list_iterator.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
#include "ecmascript/tagged_list.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ContainerError = containers::ContainerError;
|
||||
using ErrorFlag = containers::ErrorFlag;
|
||||
|
@ -15,14 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_linked_list_iterator.h"
|
||||
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_linked_list.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_list.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,14 +16,6 @@
|
||||
#include "ecmascript/js_api/js_api_list.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_api/js_api_list_iterator.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_tagged_number.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_list.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ContainerError = containers::ContainerError;
|
||||
|
@ -15,14 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_list_iterator.h"
|
||||
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_list.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_list.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -17,10 +17,7 @@
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_api/js_api_plain_array_iterator.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include <codecvt>
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,14 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_plain_array_iterator.h"
|
||||
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_plain_array.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -14,12 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_api/js_api_queue.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/interpreter/fast_runtime_stub-inl.h"
|
||||
#include "ecmascript/js_object.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ContainerError = containers::ContainerError;
|
||||
|
@ -15,11 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_queue_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_queue.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "ecmascript/js_api/js_api_stack.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,14 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_stack_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_stack.h"
|
||||
#include "ecmascript/js_hclass.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "ecmascript/js_api/js_api_tree_map.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/tagged_tree.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,12 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_tree_map_iterator.h"
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_api/js_api_tree_map.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/tagged_tree.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "ecmascript/js_api/js_api_tree_set.h"
|
||||
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/tagged_tree.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,12 +15,9 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_tree_set_iterator.h"
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/containers/containers_errors.h"
|
||||
#include "ecmascript/js_api/js_api_tree_set.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
#include "ecmascript/tagged_tree.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -17,13 +17,7 @@
|
||||
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_api/js_api_vector_iterator.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_tagged_number.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
|
@ -15,11 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_api/js_api_vector_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_api/js_api_vector.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -16,10 +16,7 @@
|
||||
#include "ecmascript/js_arguments.h"
|
||||
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
bool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle<JSArguments> &args,
|
||||
|
@ -15,14 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_array.h"
|
||||
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/base/array_helper.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/message_string.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,10 +16,7 @@
|
||||
#include "ecmascript/js_array_iterator.h"
|
||||
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/base/typed_array_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -15,16 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_arraybuffer.h"
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/mem/barriers-inl.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/platform/os.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void JSArrayBuffer::CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue fromBlock, int32_t fromIndex, int32_t count)
|
||||
|
@ -15,19 +15,11 @@
|
||||
|
||||
#include "ecmascript/js_async_from_sync_iterator.h"
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/builtins/builtins_promise.h"
|
||||
#include "ecmascript/builtins/builtins_promise_handler.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_promise.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
#include "libpandabase/macros.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
JSHandle<JSTaggedValue> JSAsyncFromSyncIterator::CreateAsyncFromSyncIterator(JSThread *thread,
|
||||
|
@ -18,14 +18,10 @@
|
||||
#include "ecmascript/async_generator_helper.h"
|
||||
#include "ecmascript/builtins/builtins_promise.h"
|
||||
#include "ecmascript/builtins/builtins_promise_handler.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/generator_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_async_generator_object.h"
|
||||
#include "ecmascript/js_promise.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler;
|
||||
|
@ -15,19 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_async_generator_object.h"
|
||||
#include "ecmascript/async_generator_helper.h"
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/builtins/builtins_promise.h"
|
||||
#include "ecmascript/ecma_string.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_promise.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
#include "ecmascript/generator_helper.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "ecmascript/js_bigint.h"
|
||||
|
||||
#include "ecmascript/base/bit_helper.h"
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_tagged_number.h"
|
||||
|
@ -18,13 +18,7 @@
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/mem/c_string.h"
|
||||
#include "ecmascript/mem/barriers-inl.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
#include "ecmascript/ecma_string-inl.h"
|
||||
|
||||
#include "unicode/udata.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
// NOLINTNEXTLINE (readability-identifier-naming, fuchsia-statically-constructed-objects)
|
||||
const CString JSCollator::uIcuDataColl = U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll";
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
#include "ecmascript/js_dataview.h"
|
||||
|
||||
#include "libpandabase/macros.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
uint32_t JSDataView::GetElementSize(DataViewType type)
|
||||
{
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <regex>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/date_parse.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
#include "ecmascript/platform/time.h"
|
||||
|
@ -17,14 +17,10 @@
|
||||
|
||||
#include "ecmascript/checkpoint/thread_state_transition.h"
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_date.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_intl.h"
|
||||
#include "ecmascript/js_locale.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,11 +16,8 @@
|
||||
#include "ecmascript/js_finalization_registry.h"
|
||||
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/ic/proto_change_details.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -15,30 +15,14 @@
|
||||
|
||||
#include "ecmascript/js_function.h"
|
||||
|
||||
#include "ecmascript/base/error_type.h"
|
||||
#include "ecmascript/debugger/js_debugger_manager.h"
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/ecma_runtime_call_info.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_hclass.h"
|
||||
#include "ecmascript/js_object.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/jspandafile/class_info_extractor.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_promise.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/jspandafile/js_pandafile.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/mem/c_containers.h"
|
||||
#include "ecmascript/module/js_module_source_text.h"
|
||||
#include "ecmascript/module/js_module_manager.h"
|
||||
#include "ecmascript/module/js_shared_module.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
#include "ecmascript/pgo_profiler/pgo_profiler.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/require/js_require_manager.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -13,27 +13,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/elements.h"
|
||||
#include "ecmascript/js_hclass-inl.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "ecmascript/base/config.h"
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/pgo_profiler/pgo_profiler.h"
|
||||
#include "ecmascript/pgo_profiler/pgo_profiler_layout.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/vtable.h"
|
||||
#include "ecmascript/ic/proto_change_details.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/js_symbol.h"
|
||||
#include "ecmascript/mem/c_containers.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
#include "ecmascript/tagged_dictionary.h"
|
||||
#include "ecmascript/weak_vector.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using ProfileType = pgo::ProfileType;
|
||||
|
@ -15,14 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_iterator.h"
|
||||
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_symbol.h"
|
||||
#include "ecmascript/js_async_from_sync_iterator.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -1,434 +1,422 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_list_format.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/global_env_constants.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_locale.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
#include "unicode/fieldpos.h"
|
||||
#include "unicode/fpositer.h"
|
||||
#include "unicode/formattedvalue.h"
|
||||
#include "unicode/stringpiece.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/utf8.h"
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/ustring.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
icu::ListFormatter *JSListFormat::GetIcuListFormatter() const
|
||||
{
|
||||
ASSERT(GetIcuLF().IsJSNativePointer());
|
||||
auto result = JSNativePointer::Cast(GetIcuLF().GetTaggedObject())->GetExternalPointer();
|
||||
return reinterpret_cast<icu::ListFormatter *>(result);
|
||||
}
|
||||
|
||||
void JSListFormat::FreeIcuListFormatter([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
|
||||
{
|
||||
if (pointer == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto icuListFormat = reinterpret_cast<icu::ListFormatter *>(pointer);
|
||||
icuListFormat->~ListFormatter();
|
||||
delete icuListFormat;
|
||||
}
|
||||
|
||||
void JSListFormat::SetIcuListFormatter(JSThread *thread, const JSHandle<JSListFormat> listFormat,
|
||||
icu::ListFormatter *icuListFormatter, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
ASSERT(icuListFormatter != nullptr);
|
||||
JSTaggedValue data = listFormat->GetIcuLF();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuListFormatter);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuListFormatter, callback);
|
||||
listFormat->SetIcuLF(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> JSListFormat::GetAvailableLocales(JSThread *thread)
|
||||
{
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSTaggedValue> listFormatLocales = env->GetListFormatLocales();
|
||||
if (!listFormatLocales->IsUndefined()) {
|
||||
return JSHandle<TaggedArray>::Cast(listFormatLocales);
|
||||
}
|
||||
const char *key = "listPattern";
|
||||
const char *path = nullptr;
|
||||
std::vector<std::string> availableStringLocales = intl::LocaleHelper::GetAvailableLocales(thread, key, path);
|
||||
JSHandle<TaggedArray> availableLocales = JSLocale::ConstructLocaleList(thread, availableStringLocales);
|
||||
env->SetListFormatLocales(thread, availableLocales);
|
||||
return availableLocales;
|
||||
}
|
||||
|
||||
// 13. InitializeListFormat ( listformat, locales, options )
|
||||
JSHandle<JSListFormat> JSListFormat::InitializeListFormat(JSThread *thread,
|
||||
const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSTaggedValue> &locales,
|
||||
const JSHandle<JSTaggedValue> &options)
|
||||
{
|
||||
[[maybe_unused]] EcmaHandleScope scope(thread);
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
|
||||
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 4. Let options be ? GetOptionsObject(options).
|
||||
JSHandle<JSObject> optionsObject;
|
||||
if (options->IsUndefined()) {
|
||||
optionsObject = factory->CreateNullJSObject();
|
||||
} else if (!options->IsJSObject()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "options is not Object", listFormat);
|
||||
} else {
|
||||
optionsObject = JSTaggedValue::ToObject(thread, options);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
}
|
||||
|
||||
// 5. Let opt be a new Record.
|
||||
// 6. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||
JSHandle<JSTaggedValue> property = globalConst->GetHandledLocaleMatcherString();
|
||||
auto matcher = JSLocale::GetOptionOfString<LocaleMatcherOption>(
|
||||
thread, optionsObject, property, {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT},
|
||||
{"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 8. Let localeData be %ListFormat%.[[LocaleData]].
|
||||
JSHandle<TaggedArray> availableLocales;
|
||||
if (requestedLocales->GetLength() == 0) {
|
||||
availableLocales = factory->EmptyArray();
|
||||
} else {
|
||||
availableLocales = GetAvailableLocales(thread);
|
||||
}
|
||||
|
||||
// 9. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]], requestedLocales,
|
||||
// opt, %ListFormat%.[[RelevantExtensionKeys]], localeData).
|
||||
std::set<std::string> relevantExtensionKeys {""};
|
||||
ResolvedLocale r =
|
||||
JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 10. Set listFormat.[[Locale]] to r.[[locale]].
|
||||
icu::Locale icuLocale = r.localeData;
|
||||
JSHandle<EcmaString> localeStr = intl::LocaleHelper::ToLanguageTag(thread, icuLocale);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
listFormat->SetLocale(thread, localeStr.GetTaggedValue());
|
||||
|
||||
// 11. Let type be ? GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction").
|
||||
property = globalConst->GetHandledTypeString();
|
||||
auto type = JSLocale::GetOptionOfString<ListTypeOption>(thread, optionsObject, property,
|
||||
{ListTypeOption::CONJUNCTION, ListTypeOption::DISJUNCTION,
|
||||
ListTypeOption::UNIT},
|
||||
{"conjunction", "disjunction", "unit"},
|
||||
ListTypeOption::CONJUNCTION);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 12. Set listFormat.[[Type]] to type.
|
||||
listFormat->SetType(type);
|
||||
|
||||
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
|
||||
property = globalConst->GetHandledStyleString();
|
||||
auto style = JSLocale::GetOptionOfString<ListStyleOption>(thread, optionsObject, property,
|
||||
{ListStyleOption::LONG, ListStyleOption::SHORT,
|
||||
ListStyleOption::NARROW},
|
||||
{"long", "short", "narrow"}, ListStyleOption::LONG);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 14. Set listFormat.[[Style]] to style.
|
||||
listFormat->SetStyle(style);
|
||||
|
||||
// 15. Let dataLocale be r.[[dataLocale]].
|
||||
// 16. Let dataLocaleData be localeData.[[<dataLocale>]].
|
||||
// 17. Let dataLocaleTypes be dataLocaleData.[[<type>]].
|
||||
// 18. Set listFormat.[[Templates]] to dataLocaleTypes.[[<style>]].
|
||||
// 19. Return listFormat.
|
||||
|
||||
// Trans typeOption to ICU type
|
||||
UListFormatterType uType;
|
||||
switch (type) {
|
||||
case ListTypeOption::CONJUNCTION:
|
||||
uType = ULISTFMT_TYPE_AND;
|
||||
break;
|
||||
case ListTypeOption::DISJUNCTION:
|
||||
uType = ULISTFMT_TYPE_OR;
|
||||
break;
|
||||
case ListTypeOption::UNIT:
|
||||
uType = ULISTFMT_TYPE_UNITS;
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
// Trans StyleOption to ICU Style
|
||||
UListFormatterWidth uStyle;
|
||||
switch (style) {
|
||||
case ListStyleOption::LONG:
|
||||
uStyle = ULISTFMT_WIDTH_WIDE;
|
||||
break;
|
||||
case ListStyleOption::SHORT:
|
||||
uStyle = ULISTFMT_WIDTH_SHORT;
|
||||
break;
|
||||
case ListStyleOption::NARROW:
|
||||
uStyle = ULISTFMT_WIDTH_NARROW;
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::ListFormatter *icuListFormatter = icu::ListFormatter::createInstance(icuLocale, uType, uStyle, status);
|
||||
if (U_FAILURE(status) || icuListFormatter == nullptr) {
|
||||
delete icuListFormatter;
|
||||
if (status == UErrorCode::U_MISSING_RESOURCE_ERROR) {
|
||||
THROW_REFERENCE_ERROR_AND_RETURN(thread, "can not find icu data resources", listFormat);
|
||||
}
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "create icu::ListFormatter failed", listFormat);
|
||||
}
|
||||
SetIcuListFormatter(thread, listFormat, icuListFormatter, JSListFormat::FreeIcuListFormatter);
|
||||
return listFormat;
|
||||
}
|
||||
|
||||
// 13.1.5 StringListFromIterable ( iterable )
|
||||
JSHandle<JSTaggedValue> JSListFormat::StringListFromIterable(JSThread *thread, const JSHandle<JSTaggedValue> &iterable)
|
||||
{
|
||||
JSHandle<JSArray> array = JSHandle<JSArray>::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
JSHandle<JSTaggedValue> arrayList = JSHandle<JSTaggedValue>::Cast(array);
|
||||
// 1. If iterable is undefined, then
|
||||
// a. Return a new empty List.
|
||||
if (iterable->IsUndefined()) {
|
||||
return arrayList;
|
||||
}
|
||||
// 2. Let iteratorRecord be ? GetIterator(iterable).
|
||||
JSHandle<JSTaggedValue> iteratorRecord(JSIterator::GetIterator(thread, iterable));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
// 3. Let list be a new empty List.
|
||||
// 4. Let next be true.
|
||||
JSHandle<JSTaggedValue> next(thread, JSTaggedValue::True());
|
||||
// 5. Repeat, while next is not false,
|
||||
// a. Set next to ? IteratorStep(iteratorRecord).
|
||||
// b. If next is not false, then
|
||||
// i. Let nextValue be ? IteratorValue(next).
|
||||
// ii. If Type(nextValue) is not String, then
|
||||
// 1. Let error be ThrowCompletion(a newly created TypeError object).
|
||||
// 2. Return ? IteratorClose(iteratorRecord, error).
|
||||
// iii. Append nextValue to the end of the List list.
|
||||
uint32_t k = 0;
|
||||
while (!next->IsFalse()) {
|
||||
next = JSIterator::IteratorStep(thread, iteratorRecord);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
if (!next->IsFalse()) {
|
||||
JSHandle<JSTaggedValue> nextValue(JSIterator::IteratorValue(thread, next));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
if (!nextValue->IsString()) {
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSObject> typeError =
|
||||
factory->GetJSError(ErrorType::TYPE_ERROR, "nextValue is not string", StackCheck::NO);
|
||||
JSHandle<JSTaggedValue> error(
|
||||
factory->NewCompletionRecord(CompletionRecordType::THROW, JSHandle<JSTaggedValue>(typeError)));
|
||||
JSTaggedValue result = JSIterator::IteratorClose(thread, iteratorRecord, error).GetTaggedValue();
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "type error", JSHandle<JSTaggedValue>(thread, result));
|
||||
}
|
||||
JSArray::FastSetPropertyByValue(thread, arrayList, k, nextValue);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
// 6. Return list.
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::vector<icu::UnicodeString> ToUnicodeStringArray(JSThread *thread, const JSHandle<JSArray> &array)
|
||||
{
|
||||
uint32_t length = array->GetArrayLength();
|
||||
std::vector<icu::UnicodeString> result;
|
||||
for (uint32_t k = 0; k < length; k++) {
|
||||
JSHandle<JSTaggedValue> listArray = JSHandle<JSTaggedValue>::Cast(array);
|
||||
JSHandle<JSTaggedValue> kValue = JSArray::FastGetPropertyByValue(thread, listArray, k);
|
||||
ASSERT(kValue->IsString());
|
||||
JSHandle<EcmaString> kValueString = JSTaggedValue::ToString(thread, kValue);
|
||||
std::string stdString = intl::LocaleHelper::ConvertToStdString(kValueString);
|
||||
icu::StringPiece sp(stdString);
|
||||
icu::UnicodeString uString = icu::UnicodeString::fromUTF8(sp);
|
||||
result.push_back(uString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
icu::FormattedList GetIcuFormatted(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSArray> &listArray)
|
||||
{
|
||||
icu::ListFormatter *icuListFormat = listFormat->GetIcuListFormatter();
|
||||
ASSERT(icuListFormat != nullptr);
|
||||
std::vector<icu::UnicodeString> usArray = ToUnicodeStringArray(thread, listArray);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::FormattedList formatted = icuListFormat->formatStringsToValue(usArray.data(),
|
||||
static_cast<int32_t>(usArray.size()),
|
||||
status);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
void FormatListToArray(JSThread *thread, const icu::FormattedList &formatted, const JSHandle<JSArray> &receiver,
|
||||
UErrorCode &status, icu::UnicodeString &listString)
|
||||
{
|
||||
icu::ConstrainedFieldPosition cfpo;
|
||||
cfpo.constrainCategory(UFIELD_CATEGORY_LIST);
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
JSMutableHandle<JSTaggedValue> typeString(thread, JSTaggedValue::Undefined());
|
||||
int index = 0;
|
||||
while (formatted.nextPosition(cfpo, status) && U_SUCCESS(status)) {
|
||||
int32_t fieldId = cfpo.getField();
|
||||
int32_t start = cfpo.getStart();
|
||||
int32_t limit = cfpo.getLimit();
|
||||
if (static_cast<UListFormatterField>(fieldId) == ULISTFMT_ELEMENT_FIELD) {
|
||||
JSHandle<EcmaString> substring = intl::LocaleHelper::UStringToString(thread, listString, start, limit);
|
||||
typeString.Update(globalConst->GetElementString());
|
||||
JSLocale::PutElement(thread, index, receiver, typeString, JSHandle<JSTaggedValue>::Cast(substring));
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
index++;
|
||||
} else {
|
||||
JSHandle<EcmaString> substring = intl::LocaleHelper::UStringToString(thread, listString, start, limit);
|
||||
typeString.Update(globalConst->GetLiteralString());
|
||||
JSLocale::PutElement(thread, index, receiver, typeString, JSHandle<JSTaggedValue>::Cast(substring));
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ListOptionStyleToEcmaString(JSThread *thread, ListStyleOption style)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
switch (style) {
|
||||
case ListStyleOption::LONG:
|
||||
result.Update(globalConst->GetHandledLongString().GetTaggedValue());
|
||||
break;
|
||||
case ListStyleOption::SHORT:
|
||||
result.Update(globalConst->GetHandledShortString().GetTaggedValue());
|
||||
break;
|
||||
case ListStyleOption::NARROW:
|
||||
result.Update(globalConst->GetHandledNarrowString().GetTaggedValue());
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ListOptionTypeToEcmaString(JSThread *thread, ListTypeOption type)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
switch (type) {
|
||||
case ListTypeOption::CONJUNCTION:
|
||||
result.Update(globalConst->GetHandledConjunctionString().GetTaggedValue());
|
||||
break;
|
||||
case ListTypeOption::DISJUNCTION:
|
||||
result.Update(globalConst->GetHandledDisjunctionString().GetTaggedValue());
|
||||
break;
|
||||
case ListTypeOption::UNIT:
|
||||
result.Update(globalConst->GetHandledUnitString().GetTaggedValue());
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// 13.1.3 FormatList ( listFormat, list )
|
||||
JSHandle<EcmaString> JSListFormat::FormatList(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSArray> &listArray)
|
||||
{
|
||||
JSHandle<EcmaString> stringValue;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::FormattedList formatted = GetIcuFormatted(thread, listFormat, listArray);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "icu listformat failed", stringValue);
|
||||
}
|
||||
icu::UnicodeString result = formatted.toString(status);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "formatted list toString failed", stringValue);
|
||||
}
|
||||
stringValue = intl::LocaleHelper::UStringToString(thread, result);
|
||||
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, stringValue);
|
||||
// 4. Return result
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
// 13.1.4 FormatListToParts ( listFormat, list )
|
||||
JSHandle<JSArray> JSListFormat::FormatListToParts(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSArray> &listArray)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::FormattedList formatted = GetIcuFormatted(thread, listFormat, listArray);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "icu listformat failed", listArray);
|
||||
}
|
||||
icu::UnicodeString result = formatted.toString(status);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "formatted list toString failed", listArray);
|
||||
}
|
||||
JSHandle<JSArray> array = JSHandle<JSArray>::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread);
|
||||
FormatListToArray(thread, formatted, array, status, result);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread);
|
||||
return array;
|
||||
}
|
||||
|
||||
void JSListFormat::ResolvedOptions(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSObject> &options)
|
||||
{
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
|
||||
// [[Locale]]
|
||||
JSHandle<JSTaggedValue> propertyKey = globalConst->GetHandledLocaleString();
|
||||
JSHandle<JSTaggedValue> locale(thread, listFormat->GetLocale());
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// [[type]]
|
||||
ListTypeOption type = listFormat->GetType();
|
||||
propertyKey = globalConst->GetHandledTypeString();
|
||||
JSHandle<JSTaggedValue> typeString = ListOptionTypeToEcmaString(thread, type);
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, typeString);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// [[Style]]
|
||||
ListStyleOption style = listFormat->GetStyle();
|
||||
propertyKey = globalConst->GetHandledStyleString();
|
||||
JSHandle<JSTaggedValue> styleString = ListOptionStyleToEcmaString(thread, style);
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, styleString);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_list_format.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
|
||||
namespace panda::ecmascript {
|
||||
icu::ListFormatter *JSListFormat::GetIcuListFormatter() const
|
||||
{
|
||||
ASSERT(GetIcuLF().IsJSNativePointer());
|
||||
auto result = JSNativePointer::Cast(GetIcuLF().GetTaggedObject())->GetExternalPointer();
|
||||
return reinterpret_cast<icu::ListFormatter *>(result);
|
||||
}
|
||||
|
||||
void JSListFormat::FreeIcuListFormatter([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
|
||||
{
|
||||
if (pointer == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto icuListFormat = reinterpret_cast<icu::ListFormatter *>(pointer);
|
||||
icuListFormat->~ListFormatter();
|
||||
delete icuListFormat;
|
||||
}
|
||||
|
||||
void JSListFormat::SetIcuListFormatter(JSThread *thread, const JSHandle<JSListFormat> listFormat,
|
||||
icu::ListFormatter *icuListFormatter, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
ASSERT(icuListFormatter != nullptr);
|
||||
JSTaggedValue data = listFormat->GetIcuLF();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuListFormatter);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuListFormatter, callback);
|
||||
listFormat->SetIcuLF(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> JSListFormat::GetAvailableLocales(JSThread *thread)
|
||||
{
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSTaggedValue> listFormatLocales = env->GetListFormatLocales();
|
||||
if (!listFormatLocales->IsUndefined()) {
|
||||
return JSHandle<TaggedArray>::Cast(listFormatLocales);
|
||||
}
|
||||
const char *key = "listPattern";
|
||||
const char *path = nullptr;
|
||||
std::vector<std::string> availableStringLocales = intl::LocaleHelper::GetAvailableLocales(thread, key, path);
|
||||
JSHandle<TaggedArray> availableLocales = JSLocale::ConstructLocaleList(thread, availableStringLocales);
|
||||
env->SetListFormatLocales(thread, availableLocales);
|
||||
return availableLocales;
|
||||
}
|
||||
|
||||
// 13. InitializeListFormat ( listformat, locales, options )
|
||||
JSHandle<JSListFormat> JSListFormat::InitializeListFormat(JSThread *thread,
|
||||
const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSTaggedValue> &locales,
|
||||
const JSHandle<JSTaggedValue> &options)
|
||||
{
|
||||
[[maybe_unused]] EcmaHandleScope scope(thread);
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
|
||||
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 4. Let options be ? GetOptionsObject(options).
|
||||
JSHandle<JSObject> optionsObject;
|
||||
if (options->IsUndefined()) {
|
||||
optionsObject = factory->CreateNullJSObject();
|
||||
} else if (!options->IsJSObject()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "options is not Object", listFormat);
|
||||
} else {
|
||||
optionsObject = JSTaggedValue::ToObject(thread, options);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
}
|
||||
|
||||
// 5. Let opt be a new Record.
|
||||
// 6. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
|
||||
JSHandle<JSTaggedValue> property = globalConst->GetHandledLocaleMatcherString();
|
||||
auto matcher = JSLocale::GetOptionOfString<LocaleMatcherOption>(
|
||||
thread, optionsObject, property, {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT},
|
||||
{"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 8. Let localeData be %ListFormat%.[[LocaleData]].
|
||||
JSHandle<TaggedArray> availableLocales;
|
||||
if (requestedLocales->GetLength() == 0) {
|
||||
availableLocales = factory->EmptyArray();
|
||||
} else {
|
||||
availableLocales = GetAvailableLocales(thread);
|
||||
}
|
||||
|
||||
// 9. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]], requestedLocales,
|
||||
// opt, %ListFormat%.[[RelevantExtensionKeys]], localeData).
|
||||
std::set<std::string> relevantExtensionKeys {""};
|
||||
ResolvedLocale r =
|
||||
JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 10. Set listFormat.[[Locale]] to r.[[locale]].
|
||||
icu::Locale icuLocale = r.localeData;
|
||||
JSHandle<EcmaString> localeStr = intl::LocaleHelper::ToLanguageTag(thread, icuLocale);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
listFormat->SetLocale(thread, localeStr.GetTaggedValue());
|
||||
|
||||
// 11. Let type be ? GetOption(options, "type", "string", « "conjunction", "disjunction", "unit" », "conjunction").
|
||||
property = globalConst->GetHandledTypeString();
|
||||
auto type = JSLocale::GetOptionOfString<ListTypeOption>(thread, optionsObject, property,
|
||||
{ListTypeOption::CONJUNCTION, ListTypeOption::DISJUNCTION,
|
||||
ListTypeOption::UNIT},
|
||||
{"conjunction", "disjunction", "unit"},
|
||||
ListTypeOption::CONJUNCTION);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 12. Set listFormat.[[Type]] to type.
|
||||
listFormat->SetType(type);
|
||||
|
||||
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow" », "long").
|
||||
property = globalConst->GetHandledStyleString();
|
||||
auto style = JSLocale::GetOptionOfString<ListStyleOption>(thread, optionsObject, property,
|
||||
{ListStyleOption::LONG, ListStyleOption::SHORT,
|
||||
ListStyleOption::NARROW},
|
||||
{"long", "short", "narrow"}, ListStyleOption::LONG);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSListFormat, thread);
|
||||
|
||||
// 14. Set listFormat.[[Style]] to style.
|
||||
listFormat->SetStyle(style);
|
||||
|
||||
// 15. Let dataLocale be r.[[dataLocale]].
|
||||
// 16. Let dataLocaleData be localeData.[[<dataLocale>]].
|
||||
// 17. Let dataLocaleTypes be dataLocaleData.[[<type>]].
|
||||
// 18. Set listFormat.[[Templates]] to dataLocaleTypes.[[<style>]].
|
||||
// 19. Return listFormat.
|
||||
|
||||
// Trans typeOption to ICU type
|
||||
UListFormatterType uType;
|
||||
switch (type) {
|
||||
case ListTypeOption::CONJUNCTION:
|
||||
uType = ULISTFMT_TYPE_AND;
|
||||
break;
|
||||
case ListTypeOption::DISJUNCTION:
|
||||
uType = ULISTFMT_TYPE_OR;
|
||||
break;
|
||||
case ListTypeOption::UNIT:
|
||||
uType = ULISTFMT_TYPE_UNITS;
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
// Trans StyleOption to ICU Style
|
||||
UListFormatterWidth uStyle;
|
||||
switch (style) {
|
||||
case ListStyleOption::LONG:
|
||||
uStyle = ULISTFMT_WIDTH_WIDE;
|
||||
break;
|
||||
case ListStyleOption::SHORT:
|
||||
uStyle = ULISTFMT_WIDTH_SHORT;
|
||||
break;
|
||||
case ListStyleOption::NARROW:
|
||||
uStyle = ULISTFMT_WIDTH_NARROW;
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::ListFormatter *icuListFormatter = icu::ListFormatter::createInstance(icuLocale, uType, uStyle, status);
|
||||
if (U_FAILURE(status) || icuListFormatter == nullptr) {
|
||||
delete icuListFormatter;
|
||||
if (status == UErrorCode::U_MISSING_RESOURCE_ERROR) {
|
||||
THROW_REFERENCE_ERROR_AND_RETURN(thread, "can not find icu data resources", listFormat);
|
||||
}
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "create icu::ListFormatter failed", listFormat);
|
||||
}
|
||||
SetIcuListFormatter(thread, listFormat, icuListFormatter, JSListFormat::FreeIcuListFormatter);
|
||||
return listFormat;
|
||||
}
|
||||
|
||||
// 13.1.5 StringListFromIterable ( iterable )
|
||||
JSHandle<JSTaggedValue> JSListFormat::StringListFromIterable(JSThread *thread, const JSHandle<JSTaggedValue> &iterable)
|
||||
{
|
||||
JSHandle<JSArray> array = JSHandle<JSArray>::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
JSHandle<JSTaggedValue> arrayList = JSHandle<JSTaggedValue>::Cast(array);
|
||||
// 1. If iterable is undefined, then
|
||||
// a. Return a new empty List.
|
||||
if (iterable->IsUndefined()) {
|
||||
return arrayList;
|
||||
}
|
||||
// 2. Let iteratorRecord be ? GetIterator(iterable).
|
||||
JSHandle<JSTaggedValue> iteratorRecord(JSIterator::GetIterator(thread, iterable));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
// 3. Let list be a new empty List.
|
||||
// 4. Let next be true.
|
||||
JSHandle<JSTaggedValue> next(thread, JSTaggedValue::True());
|
||||
// 5. Repeat, while next is not false,
|
||||
// a. Set next to ? IteratorStep(iteratorRecord).
|
||||
// b. If next is not false, then
|
||||
// i. Let nextValue be ? IteratorValue(next).
|
||||
// ii. If Type(nextValue) is not String, then
|
||||
// 1. Let error be ThrowCompletion(a newly created TypeError object).
|
||||
// 2. Return ? IteratorClose(iteratorRecord, error).
|
||||
// iii. Append nextValue to the end of the List list.
|
||||
uint32_t k = 0;
|
||||
while (!next->IsFalse()) {
|
||||
next = JSIterator::IteratorStep(thread, iteratorRecord);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
if (!next->IsFalse()) {
|
||||
JSHandle<JSTaggedValue> nextValue(JSIterator::IteratorValue(thread, next));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
if (!nextValue->IsString()) {
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSObject> typeError =
|
||||
factory->GetJSError(ErrorType::TYPE_ERROR, "nextValue is not string", StackCheck::NO);
|
||||
JSHandle<JSTaggedValue> error(
|
||||
factory->NewCompletionRecord(CompletionRecordType::THROW, JSHandle<JSTaggedValue>(typeError)));
|
||||
JSTaggedValue result = JSIterator::IteratorClose(thread, iteratorRecord, error).GetTaggedValue();
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "type error", JSHandle<JSTaggedValue>(thread, result));
|
||||
}
|
||||
JSArray::FastSetPropertyByValue(thread, arrayList, k, nextValue);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
// 6. Return list.
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
namespace {
|
||||
std::vector<icu::UnicodeString> ToUnicodeStringArray(JSThread *thread, const JSHandle<JSArray> &array)
|
||||
{
|
||||
uint32_t length = array->GetArrayLength();
|
||||
std::vector<icu::UnicodeString> result;
|
||||
for (uint32_t k = 0; k < length; k++) {
|
||||
JSHandle<JSTaggedValue> listArray = JSHandle<JSTaggedValue>::Cast(array);
|
||||
JSHandle<JSTaggedValue> kValue = JSArray::FastGetPropertyByValue(thread, listArray, k);
|
||||
ASSERT(kValue->IsString());
|
||||
JSHandle<EcmaString> kValueString = JSTaggedValue::ToString(thread, kValue);
|
||||
std::string stdString = intl::LocaleHelper::ConvertToStdString(kValueString);
|
||||
icu::StringPiece sp(stdString);
|
||||
icu::UnicodeString uString = icu::UnicodeString::fromUTF8(sp);
|
||||
result.push_back(uString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
icu::FormattedList GetIcuFormatted(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSArray> &listArray)
|
||||
{
|
||||
icu::ListFormatter *icuListFormat = listFormat->GetIcuListFormatter();
|
||||
ASSERT(icuListFormat != nullptr);
|
||||
std::vector<icu::UnicodeString> usArray = ToUnicodeStringArray(thread, listArray);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::FormattedList formatted = icuListFormat->formatStringsToValue(usArray.data(),
|
||||
static_cast<int32_t>(usArray.size()),
|
||||
status);
|
||||
return formatted;
|
||||
}
|
||||
|
||||
void FormatListToArray(JSThread *thread, const icu::FormattedList &formatted, const JSHandle<JSArray> &receiver,
|
||||
UErrorCode &status, icu::UnicodeString &listString)
|
||||
{
|
||||
icu::ConstrainedFieldPosition cfpo;
|
||||
cfpo.constrainCategory(UFIELD_CATEGORY_LIST);
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
JSMutableHandle<JSTaggedValue> typeString(thread, JSTaggedValue::Undefined());
|
||||
int index = 0;
|
||||
while (formatted.nextPosition(cfpo, status) && U_SUCCESS(status)) {
|
||||
int32_t fieldId = cfpo.getField();
|
||||
int32_t start = cfpo.getStart();
|
||||
int32_t limit = cfpo.getLimit();
|
||||
if (static_cast<UListFormatterField>(fieldId) == ULISTFMT_ELEMENT_FIELD) {
|
||||
JSHandle<EcmaString> substring = intl::LocaleHelper::UStringToString(thread, listString, start, limit);
|
||||
typeString.Update(globalConst->GetElementString());
|
||||
JSLocale::PutElement(thread, index, receiver, typeString, JSHandle<JSTaggedValue>::Cast(substring));
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
index++;
|
||||
} else {
|
||||
JSHandle<EcmaString> substring = intl::LocaleHelper::UStringToString(thread, listString, start, limit);
|
||||
typeString.Update(globalConst->GetLiteralString());
|
||||
JSLocale::PutElement(thread, index, receiver, typeString, JSHandle<JSTaggedValue>::Cast(substring));
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ListOptionStyleToEcmaString(JSThread *thread, ListStyleOption style)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
switch (style) {
|
||||
case ListStyleOption::LONG:
|
||||
result.Update(globalConst->GetHandledLongString().GetTaggedValue());
|
||||
break;
|
||||
case ListStyleOption::SHORT:
|
||||
result.Update(globalConst->GetHandledShortString().GetTaggedValue());
|
||||
break;
|
||||
case ListStyleOption::NARROW:
|
||||
result.Update(globalConst->GetHandledNarrowString().GetTaggedValue());
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ListOptionTypeToEcmaString(JSThread *thread, ListTypeOption type)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
switch (type) {
|
||||
case ListTypeOption::CONJUNCTION:
|
||||
result.Update(globalConst->GetHandledConjunctionString().GetTaggedValue());
|
||||
break;
|
||||
case ListTypeOption::DISJUNCTION:
|
||||
result.Update(globalConst->GetHandledDisjunctionString().GetTaggedValue());
|
||||
break;
|
||||
case ListTypeOption::UNIT:
|
||||
result.Update(globalConst->GetHandledUnitString().GetTaggedValue());
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// 13.1.3 FormatList ( listFormat, list )
|
||||
JSHandle<EcmaString> JSListFormat::FormatList(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSArray> &listArray)
|
||||
{
|
||||
JSHandle<EcmaString> stringValue;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::FormattedList formatted = GetIcuFormatted(thread, listFormat, listArray);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "icu listformat failed", stringValue);
|
||||
}
|
||||
icu::UnicodeString result = formatted.toString(status);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "formatted list toString failed", stringValue);
|
||||
}
|
||||
stringValue = intl::LocaleHelper::UStringToString(thread, result);
|
||||
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, stringValue);
|
||||
// 4. Return result
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
// 13.1.4 FormatListToParts ( listFormat, list )
|
||||
JSHandle<JSArray> JSListFormat::FormatListToParts(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSArray> &listArray)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
icu::FormattedList formatted = GetIcuFormatted(thread, listFormat, listArray);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "icu listformat failed", listArray);
|
||||
}
|
||||
icu::UnicodeString result = formatted.toString(status);
|
||||
if (U_FAILURE(status)) {
|
||||
THROW_RANGE_ERROR_AND_RETURN(thread, "formatted list toString failed", listArray);
|
||||
}
|
||||
JSHandle<JSArray> array = JSHandle<JSArray>::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)));
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread);
|
||||
FormatListToArray(thread, formatted, array, status, result);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread);
|
||||
return array;
|
||||
}
|
||||
|
||||
void JSListFormat::ResolvedOptions(JSThread *thread, const JSHandle<JSListFormat> &listFormat,
|
||||
const JSHandle<JSObject> &options)
|
||||
{
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
|
||||
// [[Locale]]
|
||||
JSHandle<JSTaggedValue> propertyKey = globalConst->GetHandledLocaleString();
|
||||
JSHandle<JSTaggedValue> locale(thread, listFormat->GetLocale());
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// [[type]]
|
||||
ListTypeOption type = listFormat->GetType();
|
||||
propertyKey = globalConst->GetHandledTypeString();
|
||||
JSHandle<JSTaggedValue> typeString = ListOptionTypeToEcmaString(thread, type);
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, typeString);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// [[Style]]
|
||||
ListStyleOption style = listFormat->GetStyle();
|
||||
propertyKey = globalConst->GetHandledStyleString();
|
||||
JSHandle<JSTaggedValue> styleString = ListOptionStyleToEcmaString(thread, style);
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, styleString);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -16,10 +16,6 @@
|
||||
#include "ecmascript/js_locale.h"
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
#include "ecmascript/checkpoint/thread_state_transition.h"
|
||||
|
||||
@ -37,8 +33,6 @@
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "unicode/localematcher.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
const std::string LATN_STRING = "latn";
|
||||
// 6.4.1 IsValidTimeZoneName ( timeZone )
|
||||
|
@ -15,9 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_map.h"
|
||||
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void JSMap::Set(JSThread *thread, const JSHandle<JSMap> &map, const JSHandle<JSTaggedValue> &key,
|
||||
|
@ -18,9 +18,7 @@
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/element_accessor-inl.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_map.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -14,34 +14,15 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_object.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/dfx/native_module_failure_info.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/element_accessor-inl.h"
|
||||
#include "ecmascript/filter_helper.h"
|
||||
#include "ecmascript/global_dictionary-inl.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/ic/proto_change_details.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_for_in_iterator.h"
|
||||
#include "ecmascript/js_hclass.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_object_resizing_strategy.h"
|
||||
#include "ecmascript/js_primitive_ref.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
#include "ecmascript/pgo_profiler/pgo_profiler.h"
|
||||
#include "ecmascript/property_accessor.h"
|
||||
#include "ecmascript/property_attributes.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
#include "ecmascript/jspandafile/debug_info_extractor.h"
|
||||
#include "ecmascript/jspandafile/js_pandafile_manager.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,10 +15,6 @@
|
||||
|
||||
#include "ecmascript/js_plural_rules.h"
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/global_env_constants.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
#include "ecmascript/js_number_format.h"
|
||||
#include "ecmascript/checkpoint/thread_state_transition.h"
|
||||
|
@ -15,11 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_primitive_ref.h"
|
||||
|
||||
#include "ecmascript/ecma_string-inl.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/mem/assert_scope.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
// ES6 9.4.3.4 StringCreate( value, prototype)
|
||||
|
@ -15,18 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_promise.h"
|
||||
|
||||
#include "ecmascript/base/error_type.h"
|
||||
#include "ecmascript/builtins/builtins_promise_handler.h"
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler;
|
||||
|
@ -15,14 +15,10 @@
|
||||
|
||||
#include "ecmascript/js_proxy.h"
|
||||
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
// ES6 9.5.15 ProxyCreate(target, handler)
|
||||
|
@ -15,10 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_regexp_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/builtins/builtins_regexp.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
|
||||
|
||||
|
@ -17,10 +17,6 @@
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
#include "unicode/decimfmt.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/unum.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
// 14.1.1 InitializeRelativeTimeFormat ( relativeTimeFormat, locales, options )
|
||||
JSHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::InitializeRelativeTimeFormat(
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "ecmascript/compiler/aot_file/an_file_data_manager.h"
|
||||
#include "ecmascript/mem/mem_common.h"
|
||||
#include "ecmascript/compiler/ecma_opcode_des.h"
|
||||
#include "ecmascript/platform/os.h"
|
||||
|
||||
|
@ -1,124 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_segment_iterator.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/global_env_constants.h"
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_segments.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
#include "unicode/errorcode.h"
|
||||
#include "unicode/locdspnm.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/uscript.h"
|
||||
#include "unicode/ustring.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
void JSSegmentIterator::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
|
||||
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuBreakIterator != nullptr);
|
||||
JSTaggedValue data = iterator->GetIcuField();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuBreakIterator);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
|
||||
iterator->SetIcuField(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
void JSSegmentIterator::SetUString(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
|
||||
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuUnicodeString != nullptr);
|
||||
JSTaggedValue data = iterator->GetUnicodeString();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuUnicodeString);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuUnicodeString, callback);
|
||||
iterator->SetUnicodeString(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
JSHandle<JSSegmentIterator> JSSegmentIterator::CreateSegmentIterator(JSThread *thread,
|
||||
icu::BreakIterator* icuBreakIterator, const JSHandle<EcmaString> &string, GranularityOption granularity)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]],
|
||||
// [[IteratedStringNextSegmentCodeUnitIndex]] ».
|
||||
// 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSFunction> segIterCtor(env->GetSegmentIterator());
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSSegmentIterator> iterator(factory->NewJSObjectByConstructor(segIterCtor));
|
||||
icuBreakIterator = icuBreakIterator->clone();
|
||||
// 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
|
||||
icuBreakIterator->first();
|
||||
icu::UnicodeString* uString = new icu::UnicodeString();
|
||||
icuBreakIterator->getText().getText(*uString);
|
||||
// 3. Set iterator.[[IteratingSegmenter]] to segmenter.
|
||||
SetIcuBreakIterator(thread, iterator, icuBreakIterator, JSSegmentIterator::FreeIcuBreakIterator);
|
||||
iterator->SetGranularity(granularity);
|
||||
// 4. Set iterator.[[IteratedString]] to string.
|
||||
iterator->SetIteratedString(thread, string);
|
||||
SetUString(thread, iterator, uString, JSSegmentIterator::FreeUString);
|
||||
// 6. Return iterator.
|
||||
return iterator;
|
||||
}
|
||||
|
||||
JSTaggedValue JSSegmentIterator::Next(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator)
|
||||
{
|
||||
icu::BreakIterator* icuBreakIterator = iterator->GetIcuBreakIterator();
|
||||
// 5. Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]].
|
||||
int32_t startIndex = icuBreakIterator->current();
|
||||
// 6. Let endIndex be ! FindBoundary(segmenter, string, startIndex, after).
|
||||
int32_t endIndex = icuBreakIterator->next();
|
||||
// 7. If endIndex is not finite, then
|
||||
if (endIndex == icu::BreakIterator::DONE) {
|
||||
// a. Return CreateIterResultObject(undefined, true).
|
||||
JSHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
return JSIterator::CreateIterResultObject(thread, result, true).GetTaggedValue();
|
||||
}
|
||||
|
||||
// 8. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to endIndex.
|
||||
// 9. Let segmentData be ! CreateSegmentDataObject(segmenter, string, startIndex, endIndex).
|
||||
icu::UnicodeString unicodeString;
|
||||
icuBreakIterator->getText().getText(unicodeString);
|
||||
JSHandle<JSObject> segmentData = JSSegments::CreateSegmentDataObject(thread, iterator->GetGranularity(),
|
||||
icuBreakIterator, JSHandle<EcmaString>(thread, iterator->GetIteratedString()),
|
||||
unicodeString, startIndex, endIndex);
|
||||
|
||||
// 10. Return CreateIterResultObject(segmentData, false).
|
||||
return JSIterator::CreateIterResultObject(thread, JSHandle<JSTaggedValue>::Cast(segmentData), false)
|
||||
.GetTaggedValue();
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
/*
|
||||
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_segment_iterator.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ecmascript/js_iterator.h"
|
||||
#include "ecmascript/js_segments.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
void JSSegmentIterator::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
|
||||
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuBreakIterator != nullptr);
|
||||
JSTaggedValue data = iterator->GetIcuField();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuBreakIterator);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
|
||||
iterator->SetIcuField(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
void JSSegmentIterator::SetUString(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
|
||||
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuUnicodeString != nullptr);
|
||||
JSTaggedValue data = iterator->GetUnicodeString();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuUnicodeString);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuUnicodeString, callback);
|
||||
iterator->SetUnicodeString(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
JSHandle<JSSegmentIterator> JSSegmentIterator::CreateSegmentIterator(JSThread *thread,
|
||||
icu::BreakIterator* icuBreakIterator, const JSHandle<EcmaString> &string, GranularityOption granularity)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]],
|
||||
// [[IteratedStringNextSegmentCodeUnitIndex]] ».
|
||||
// 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSFunction> segIterCtor(env->GetSegmentIterator());
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSSegmentIterator> iterator(factory->NewJSObjectByConstructor(segIterCtor));
|
||||
icuBreakIterator = icuBreakIterator->clone();
|
||||
// 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
|
||||
icuBreakIterator->first();
|
||||
icu::UnicodeString* uString = new icu::UnicodeString();
|
||||
icuBreakIterator->getText().getText(*uString);
|
||||
// 3. Set iterator.[[IteratingSegmenter]] to segmenter.
|
||||
SetIcuBreakIterator(thread, iterator, icuBreakIterator, JSSegmentIterator::FreeIcuBreakIterator);
|
||||
iterator->SetGranularity(granularity);
|
||||
// 4. Set iterator.[[IteratedString]] to string.
|
||||
iterator->SetIteratedString(thread, string);
|
||||
SetUString(thread, iterator, uString, JSSegmentIterator::FreeUString);
|
||||
// 6. Return iterator.
|
||||
return iterator;
|
||||
}
|
||||
|
||||
JSTaggedValue JSSegmentIterator::Next(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator)
|
||||
{
|
||||
icu::BreakIterator* icuBreakIterator = iterator->GetIcuBreakIterator();
|
||||
// 5. Let startIndex be iterator.[[IteratedStringNextSegmentCodeUnitIndex]].
|
||||
int32_t startIndex = icuBreakIterator->current();
|
||||
// 6. Let endIndex be ! FindBoundary(segmenter, string, startIndex, after).
|
||||
int32_t endIndex = icuBreakIterator->next();
|
||||
// 7. If endIndex is not finite, then
|
||||
if (endIndex == icu::BreakIterator::DONE) {
|
||||
// a. Return CreateIterResultObject(undefined, true).
|
||||
JSHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
return JSIterator::CreateIterResultObject(thread, result, true).GetTaggedValue();
|
||||
}
|
||||
|
||||
// 8. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to endIndex.
|
||||
// 9. Let segmentData be ! CreateSegmentDataObject(segmenter, string, startIndex, endIndex).
|
||||
icu::UnicodeString unicodeString;
|
||||
icuBreakIterator->getText().getText(unicodeString);
|
||||
JSHandle<JSObject> segmentData = JSSegments::CreateSegmentDataObject(thread, iterator->GetGranularity(),
|
||||
icuBreakIterator, JSHandle<EcmaString>(thread, iterator->GetIteratedString()),
|
||||
unicodeString, startIndex, endIndex);
|
||||
|
||||
// 10. Return CreateIterResultObject(segmentData, false).
|
||||
return JSIterator::CreateIterResultObject(thread, JSHandle<JSTaggedValue>::Cast(segmentData), false)
|
||||
.GetTaggedValue();
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -1,197 +1,186 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_segmenter.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/global_env_constants.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
#include "unicode/errorcode.h"
|
||||
#include "unicode/locdspnm.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/uscript.h"
|
||||
#include "unicode/ustring.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
void JSSegmenter::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
|
||||
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuBreakIterator != nullptr);
|
||||
JSTaggedValue data = segmenter->GetIcuField();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuBreakIterator);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
|
||||
segmenter->SetIcuField(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> JSSegmenter::GetAvailableLocales(JSThread *thread)
|
||||
{
|
||||
std::vector<std::string> availableStringLocales = intl::LocaleHelper::GetAvailableLocales(thread, nullptr, nullptr);
|
||||
JSHandle<TaggedArray> availableLocales = JSLocale::ConstructLocaleList(thread, availableStringLocales);
|
||||
return availableLocales;
|
||||
}
|
||||
|
||||
void JSSegmenter::InitializeIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
|
||||
const icu::Locale &icuLocale, GranularityOption granularity)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
std::unique_ptr<icu::BreakIterator> icuBreakIterator;
|
||||
|
||||
switch (granularity) {
|
||||
case GranularityOption::GRAPHEME:
|
||||
icuBreakIterator.reset(icu::BreakIterator::createCharacterInstance(icuLocale, status));
|
||||
break;
|
||||
case GranularityOption::WORD:
|
||||
icuBreakIterator.reset(icu::BreakIterator::createWordInstance(icuLocale, status));
|
||||
break;
|
||||
case GranularityOption::SENTENCE:
|
||||
icuBreakIterator.reset(icu::BreakIterator::createSentenceInstance(icuLocale, status));
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (U_FAILURE(status) || icuBreakIterator == nullptr) {
|
||||
if (status == UErrorCode::U_MISSING_RESOURCE_ERROR) {
|
||||
THROW_ERROR(thread, ErrorType::REFERENCE_ERROR, "can not find icu data resources");
|
||||
}
|
||||
THROW_ERROR(thread, ErrorType::RANGE_ERROR, "create icu::BreakIterator failed");
|
||||
}
|
||||
|
||||
SetIcuBreakIterator(thread, segmenter, icuBreakIterator.release(), JSSegmenter::FreeIcuBreakIterator);
|
||||
}
|
||||
|
||||
JSHandle<JSSegmenter> JSSegmenter::InitializeSegmenter(JSThread *thread,
|
||||
const JSHandle<JSSegmenter> &segmenter,
|
||||
const JSHandle<JSTaggedValue> &locales,
|
||||
const JSHandle<JSTaggedValue> &options)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
// 4. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 5. Let options be ? GetOptionsObject(options).
|
||||
JSHandle<JSObject> optionsObject;
|
||||
if (options->IsUndefined()) {
|
||||
optionsObject = factory->CreateNullJSObject();
|
||||
} else if (!options->IsJSObject()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "options is not Object", segmenter);
|
||||
} else {
|
||||
optionsObject = JSTaggedValue::ToObject(thread, options);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
}
|
||||
|
||||
// 6. Let opt be a new Record.
|
||||
// 7. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit").
|
||||
JSHandle<JSTaggedValue> property = globalConst->GetHandledLocaleMatcherString();
|
||||
auto matcher = JSLocale::GetOptionOfString<LocaleMatcherOption>(
|
||||
thread, optionsObject, property, {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT},
|
||||
{"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 9. Let localeData be %Segmenter%.[[LocaleData]].
|
||||
// 10. Let r be ResolveLocale(%Segmenter%.[[AvailableLocales]], requestedLocales, opt,
|
||||
// %Segmenter%.[[RelevantExtensionKeys]], localeData).
|
||||
JSHandle<TaggedArray> availableLocales;
|
||||
if (requestedLocales->GetLength() == 0) {
|
||||
availableLocales = factory->EmptyArray();
|
||||
} else {
|
||||
availableLocales = JSSegmenter::GetAvailableLocales(thread);
|
||||
}
|
||||
std::set<std::string> relevantExtensionKeys {""};
|
||||
ResolvedLocale r =
|
||||
JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 11. Set segmenter.[[Locale]] to r.[[locale]].
|
||||
icu::Locale icuLocale = r.localeData;
|
||||
JSHandle<EcmaString> localeStr = intl::LocaleHelper::ToLanguageTag(thread, icuLocale);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
segmenter->SetLocale(thread, localeStr.GetTaggedValue());
|
||||
|
||||
// 12. Let granularity be ? GetOption(options, "granularity", string, « "grapheme", "word", "sentence" »,
|
||||
// "grapheme").
|
||||
property = globalConst->GetHandledGranularityString();
|
||||
auto granularity = JSLocale::GetOptionOfString<GranularityOption>(thread, optionsObject, property,
|
||||
{GranularityOption::GRAPHEME,
|
||||
GranularityOption::WORD,
|
||||
GranularityOption::SENTENCE},
|
||||
{"grapheme", "word", "sentence"},
|
||||
GranularityOption::GRAPHEME);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 13. Set segmenter.[[SegmenterGranularity]] to granularity.
|
||||
segmenter->SetGranularity(granularity);
|
||||
InitializeIcuBreakIterator(thread, segmenter, icuLocale, granularity);
|
||||
// 14. Return segmenter.
|
||||
return segmenter;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> JSSegmenter::GranularityOptionToEcmaString(JSThread *thread, GranularityOption granularity)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
switch (granularity) {
|
||||
case GranularityOption::GRAPHEME:
|
||||
result.Update(globalConst->GetHandledGraphemeString().GetTaggedValue());
|
||||
break;
|
||||
case GranularityOption::WORD:
|
||||
result.Update(globalConst->GetHandledWordString().GetTaggedValue());
|
||||
break;
|
||||
case GranularityOption::SENTENCE:
|
||||
result.Update(globalConst->GetHandledSentenceString().GetTaggedValue());
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void JSSegmenter::ResolvedOptions(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
|
||||
const JSHandle<JSObject> &options)
|
||||
{
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
|
||||
// [[Locale]]
|
||||
JSHandle<JSTaggedValue> propertyKey = globalConst->GetHandledLocaleString();
|
||||
JSHandle<JSTaggedValue> locale(thread, segmenter->GetLocale());
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// [[SegmenterGranularity]]
|
||||
GranularityOption granularity = segmenter->GetGranularity();
|
||||
propertyKey = globalConst->GetHandledGranularityString();
|
||||
JSHandle<JSTaggedValue> granularityString = GranularityOptionToEcmaString(thread, granularity);
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, granularityString);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
/*
|
||||
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_segmenter.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
void JSSegmenter::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
|
||||
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuBreakIterator != nullptr);
|
||||
JSTaggedValue data = segmenter->GetIcuField();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuBreakIterator);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
|
||||
segmenter->SetIcuField(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> JSSegmenter::GetAvailableLocales(JSThread *thread)
|
||||
{
|
||||
std::vector<std::string> availableStringLocales = intl::LocaleHelper::GetAvailableLocales(thread, nullptr, nullptr);
|
||||
JSHandle<TaggedArray> availableLocales = JSLocale::ConstructLocaleList(thread, availableStringLocales);
|
||||
return availableLocales;
|
||||
}
|
||||
|
||||
void JSSegmenter::InitializeIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
|
||||
const icu::Locale &icuLocale, GranularityOption granularity)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
std::unique_ptr<icu::BreakIterator> icuBreakIterator;
|
||||
|
||||
switch (granularity) {
|
||||
case GranularityOption::GRAPHEME:
|
||||
icuBreakIterator.reset(icu::BreakIterator::createCharacterInstance(icuLocale, status));
|
||||
break;
|
||||
case GranularityOption::WORD:
|
||||
icuBreakIterator.reset(icu::BreakIterator::createWordInstance(icuLocale, status));
|
||||
break;
|
||||
case GranularityOption::SENTENCE:
|
||||
icuBreakIterator.reset(icu::BreakIterator::createSentenceInstance(icuLocale, status));
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (U_FAILURE(status) || icuBreakIterator == nullptr) {
|
||||
if (status == UErrorCode::U_MISSING_RESOURCE_ERROR) {
|
||||
THROW_ERROR(thread, ErrorType::REFERENCE_ERROR, "can not find icu data resources");
|
||||
}
|
||||
THROW_ERROR(thread, ErrorType::RANGE_ERROR, "create icu::BreakIterator failed");
|
||||
}
|
||||
|
||||
SetIcuBreakIterator(thread, segmenter, icuBreakIterator.release(), JSSegmenter::FreeIcuBreakIterator);
|
||||
}
|
||||
|
||||
JSHandle<JSSegmenter> JSSegmenter::InitializeSegmenter(JSThread *thread,
|
||||
const JSHandle<JSSegmenter> &segmenter,
|
||||
const JSHandle<JSTaggedValue> &locales,
|
||||
const JSHandle<JSTaggedValue> &options)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
// 4. Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 5. Let options be ? GetOptionsObject(options).
|
||||
JSHandle<JSObject> optionsObject;
|
||||
if (options->IsUndefined()) {
|
||||
optionsObject = factory->CreateNullJSObject();
|
||||
} else if (!options->IsJSObject()) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread, "options is not Object", segmenter);
|
||||
} else {
|
||||
optionsObject = JSTaggedValue::ToObject(thread, options);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
}
|
||||
|
||||
// 6. Let opt be a new Record.
|
||||
// 7. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit").
|
||||
JSHandle<JSTaggedValue> property = globalConst->GetHandledLocaleMatcherString();
|
||||
auto matcher = JSLocale::GetOptionOfString<LocaleMatcherOption>(
|
||||
thread, optionsObject, property, {LocaleMatcherOption::LOOKUP, LocaleMatcherOption::BEST_FIT},
|
||||
{"lookup", "best fit"}, LocaleMatcherOption::BEST_FIT);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 9. Let localeData be %Segmenter%.[[LocaleData]].
|
||||
// 10. Let r be ResolveLocale(%Segmenter%.[[AvailableLocales]], requestedLocales, opt,
|
||||
// %Segmenter%.[[RelevantExtensionKeys]], localeData).
|
||||
JSHandle<TaggedArray> availableLocales;
|
||||
if (requestedLocales->GetLength() == 0) {
|
||||
availableLocales = factory->EmptyArray();
|
||||
} else {
|
||||
availableLocales = JSSegmenter::GetAvailableLocales(thread);
|
||||
}
|
||||
std::set<std::string> relevantExtensionKeys {""};
|
||||
ResolvedLocale r =
|
||||
JSLocale::ResolveLocale(thread, availableLocales, requestedLocales, matcher, relevantExtensionKeys);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 11. Set segmenter.[[Locale]] to r.[[locale]].
|
||||
icu::Locale icuLocale = r.localeData;
|
||||
JSHandle<EcmaString> localeStr = intl::LocaleHelper::ToLanguageTag(thread, icuLocale);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
segmenter->SetLocale(thread, localeStr.GetTaggedValue());
|
||||
|
||||
// 12. Let granularity be ? GetOption(options, "granularity", string, « "grapheme", "word", "sentence" »,
|
||||
// "grapheme").
|
||||
property = globalConst->GetHandledGranularityString();
|
||||
auto granularity = JSLocale::GetOptionOfString<GranularityOption>(thread, optionsObject, property,
|
||||
{GranularityOption::GRAPHEME,
|
||||
GranularityOption::WORD,
|
||||
GranularityOption::SENTENCE},
|
||||
{"grapheme", "word", "sentence"},
|
||||
GranularityOption::GRAPHEME);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSSegmenter, thread);
|
||||
|
||||
// 13. Set segmenter.[[SegmenterGranularity]] to granularity.
|
||||
segmenter->SetGranularity(granularity);
|
||||
InitializeIcuBreakIterator(thread, segmenter, icuLocale, granularity);
|
||||
// 14. Return segmenter.
|
||||
return segmenter;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> JSSegmenter::GranularityOptionToEcmaString(JSThread *thread, GranularityOption granularity)
|
||||
{
|
||||
JSMutableHandle<JSTaggedValue> result(thread, JSTaggedValue::Undefined());
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
switch (granularity) {
|
||||
case GranularityOption::GRAPHEME:
|
||||
result.Update(globalConst->GetHandledGraphemeString().GetTaggedValue());
|
||||
break;
|
||||
case GranularityOption::WORD:
|
||||
result.Update(globalConst->GetHandledWordString().GetTaggedValue());
|
||||
break;
|
||||
case GranularityOption::SENTENCE:
|
||||
result.Update(globalConst->GetHandledSentenceString().GetTaggedValue());
|
||||
break;
|
||||
default:
|
||||
LOG_ECMA(FATAL) << "this branch is unreachable";
|
||||
UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void JSSegmenter::ResolvedOptions(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
|
||||
const JSHandle<JSObject> &options)
|
||||
{
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
|
||||
// [[Locale]]
|
||||
JSHandle<JSTaggedValue> propertyKey = globalConst->GetHandledLocaleString();
|
||||
JSHandle<JSTaggedValue> locale(thread, segmenter->GetLocale());
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, locale);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
// [[SegmenterGranularity]]
|
||||
GranularityOption granularity = segmenter->GetGranularity();
|
||||
propertyKey = globalConst->GetHandledGranularityString();
|
||||
JSHandle<JSTaggedValue> granularityString = GranularityOptionToEcmaString(thread, granularity);
|
||||
JSObject::CreateDataPropertyOrThrow(thread, options, propertyKey, granularityString);
|
||||
RETURN_IF_ABRUPT_COMPLETION(thread);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -1,182 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_segments.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/global_env_constants.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
#include "unicode/errorcode.h"
|
||||
#include "unicode/locdspnm.h"
|
||||
#include "unicode/locid.h"
|
||||
#include "unicode/udisplaycontext.h"
|
||||
#include "unicode/uloc.h"
|
||||
#include "unicode/unistr.h"
|
||||
#include "unicode/uscript.h"
|
||||
#include "unicode/ustring.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
void JSSegments::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegments> &segments,
|
||||
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuBreakIterator != nullptr);
|
||||
JSTaggedValue data = segments->GetIcuField();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuBreakIterator);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
|
||||
segments->SetIcuField(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
void JSSegments::SetUString(JSThread *thread, const JSHandle<JSSegments> &segments,
|
||||
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuUnicodeString != nullptr);
|
||||
JSTaggedValue data = segments->GetUnicodeString();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuUnicodeString);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuUnicodeString, callback);
|
||||
segments->SetUnicodeString(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
void SetTextToBreakIterator(JSThread *thread, const JSHandle<JSSegments> &segments,
|
||||
JSHandle<EcmaString> text, icu::BreakIterator* breakIterator)
|
||||
{
|
||||
std::u16string u16str = EcmaStringAccessor(text).ToU16String();
|
||||
icu::UnicodeString src(u16str.data(), u16str.size());
|
||||
icu::UnicodeString* uText = static_cast<icu::UnicodeString*>(src.clone());
|
||||
breakIterator->setText(*uText);
|
||||
JSSegments::SetUString(thread, segments, uText, JSSegments::FreeUString);
|
||||
}
|
||||
|
||||
JSHandle<JSSegments> JSSegments::CreateSegmentsObject(JSThread *thread,
|
||||
const JSHandle<JSSegmenter> &segmenter,
|
||||
const JSHandle<EcmaString> &string)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
|
||||
// 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSFunction> segmentsCtor(env->GetSegmentsFunction());
|
||||
JSHandle<JSSegments> segments(factory->NewJSObjectByConstructor(segmentsCtor));
|
||||
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
|
||||
icu::BreakIterator* icuBreakIterator = segmenter->GetIcuBreakIterator()->clone();
|
||||
SetIcuBreakIterator(thread, segments, icuBreakIterator, JSSegments::FreeIcuBreakIterator);
|
||||
segments->SetGranularity(segmenter->GetGranularity());
|
||||
// 4. Set segments.[[SegmentsString]] to string.
|
||||
segments->SetSegmentsString(thread, string);
|
||||
SetTextToBreakIterator(thread, segments, string, icuBreakIterator);
|
||||
return segments;
|
||||
}
|
||||
|
||||
JSTaggedValue JSSegments::Containing(JSThread *thread, const JSHandle<JSSegments> &segments, double index)
|
||||
{
|
||||
icu::UnicodeString* unicodeString = segments->GetUString();
|
||||
// 5. Let len be the length of string.
|
||||
int32_t len = unicodeString->length();
|
||||
// 7. If n < 0 or n ≥ len, return undefined.
|
||||
if (index < 0 || index >= len) {
|
||||
return JSTaggedValue::Undefined();
|
||||
}
|
||||
int32_t n = static_cast<int32_t>(index);
|
||||
// n may point to the surrogate tail- adjust it back to the lead.
|
||||
n = unicodeString->getChar32Start(n);
|
||||
icu::BreakIterator* breakIterator = segments->GetIcuBreakIterator();
|
||||
// 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<EcmaString>(thread, segments->GetSegmentsString()),
|
||||
*unicodeString, startIndex, endIndex).GetTaggedValue();
|
||||
}
|
||||
|
||||
bool CurrentSegmentIsWordLike(icu::BreakIterator* breakIterator)
|
||||
{
|
||||
int32_t rule_status = breakIterator->getRuleStatus();
|
||||
return (rule_status >= UBRK_WORD_NUMBER &&
|
||||
rule_status < UBRK_WORD_NUMBER_LIMIT) ||
|
||||
(rule_status >= UBRK_WORD_LETTER &&
|
||||
rule_status < UBRK_WORD_LETTER_LIMIT) ||
|
||||
(rule_status >= UBRK_WORD_KANA &&
|
||||
rule_status < UBRK_WORD_KANA_LIMIT) ||
|
||||
(rule_status >= UBRK_WORD_IDEO && rule_status < UBRK_WORD_IDEO_LIMIT);
|
||||
}
|
||||
|
||||
// 18.7.1 CreateSegmentDataObject ( segmenter, string, startIndex, endIndex )
|
||||
JSHandle<JSObject> JSSegments::CreateSegmentDataObject(JSThread *thread, GranularityOption granularity,
|
||||
icu::BreakIterator* breakIterator, const JSHandle<EcmaString> &inputString,
|
||||
const icu::UnicodeString& unicodeString, int32_t startIndex, int32_t endIndex)
|
||||
{
|
||||
// 1. Let len be the length of string.
|
||||
// 2. Assert: startIndex ≥ 0.
|
||||
ASSERT(startIndex >= 0);
|
||||
// 3. Assert: endIndex ≤ len.
|
||||
ASSERT(endIndex <= unicodeString.length());
|
||||
// 4. Assert: startIndex < endIndex.
|
||||
ASSERT(startIndex < endIndex);
|
||||
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto ecmaVm = thread->GetEcmaVM();
|
||||
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
JSHandle<JSFunction> ctor(env->GetObjectFunction());
|
||||
JSHandle<JSObject> result(factory->NewJSObjectByConstructor(ctor));
|
||||
// 6. Let segment be the substring of string from startIndex to endIndex.
|
||||
JSHandle<EcmaString> segment =
|
||||
intl::LocaleHelper::UStringToString(thread, unicodeString, startIndex, endIndex);
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
// 7. Perform ! CreateDataPropertyOrThrow(result, "segment", segment).
|
||||
JSHandle<JSTaggedValue> segmentKey = globalConst->GetHandledSegmentString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, segmentKey, JSHandle<JSTaggedValue>::Cast(segment));
|
||||
// 8. Perform ! CreateDataPropertyOrThrow(result, "index", 𝔽(startIndex)).
|
||||
JSHandle<JSTaggedValue> indexKey = globalConst->GetHandledIndexString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, indexKey, JSHandle<JSTaggedValue>(thread,
|
||||
base::BuiltinsBase::GetTaggedInt(startIndex)));
|
||||
// 9. Perform ! CreateDataPropertyOrThrow(result, "input", string).
|
||||
JSHandle<JSTaggedValue> inputKey = globalConst->GetHandledInputString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, inputKey, JSHandle<JSTaggedValue>::Cast(inputString));
|
||||
// 10. Let granularity be segmenter.[[SegmenterGranularity]].
|
||||
// 11. If granularity is "word", then
|
||||
// a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like"
|
||||
// according to locale segmenter.[[Locale]].
|
||||
// b. Perform ! CreateDataPropertyOrThrow(result, "isWordLike", isWordLike).
|
||||
if (granularity == GranularityOption::WORD) {
|
||||
bool isWordLike = CurrentSegmentIsWordLike(breakIterator);
|
||||
JSHandle<JSTaggedValue> isWordLikeKey = globalConst->GetHandledIsWordLikeString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, isWordLikeKey, JSHandle<JSTaggedValue>(thread,
|
||||
base::BuiltinsBase::GetTaggedBoolean(isWordLike)));
|
||||
}
|
||||
// 12. Return result.
|
||||
return result;
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
/*
|
||||
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_segments.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/intl/locale_helper.h"
|
||||
#include "ecmascript/object_factory-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
void JSSegments::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegments> &segments,
|
||||
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuBreakIterator != nullptr);
|
||||
JSTaggedValue data = segments->GetIcuField();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuBreakIterator);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
|
||||
segments->SetIcuField(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
void JSSegments::SetUString(JSThread *thread, const JSHandle<JSSegments> &segments,
|
||||
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
ASSERT(icuUnicodeString != nullptr);
|
||||
JSTaggedValue data = segments->GetUnicodeString();
|
||||
if (data.IsJSNativePointer()) {
|
||||
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
|
||||
native->ResetExternalPointer(thread, icuUnicodeString);
|
||||
return;
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuUnicodeString, callback);
|
||||
segments->SetUnicodeString(thread, pointer.GetTaggedValue());
|
||||
}
|
||||
|
||||
void SetTextToBreakIterator(JSThread *thread, const JSHandle<JSSegments> &segments,
|
||||
JSHandle<EcmaString> text, icu::BreakIterator* breakIterator)
|
||||
{
|
||||
std::u16string u16str = EcmaStringAccessor(text).ToU16String();
|
||||
icu::UnicodeString src(u16str.data(), u16str.size());
|
||||
icu::UnicodeString* uText = static_cast<icu::UnicodeString*>(src.clone());
|
||||
breakIterator->setText(*uText);
|
||||
JSSegments::SetUString(thread, segments, uText, JSSegments::FreeUString);
|
||||
}
|
||||
|
||||
JSHandle<JSSegments> JSSegments::CreateSegmentsObject(JSThread *thread,
|
||||
const JSHandle<JSSegmenter> &segmenter,
|
||||
const JSHandle<EcmaString> &string)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
|
||||
// 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSFunction> segmentsCtor(env->GetSegmentsFunction());
|
||||
JSHandle<JSSegments> segments(factory->NewJSObjectByConstructor(segmentsCtor));
|
||||
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
|
||||
icu::BreakIterator* icuBreakIterator = segmenter->GetIcuBreakIterator()->clone();
|
||||
SetIcuBreakIterator(thread, segments, icuBreakIterator, JSSegments::FreeIcuBreakIterator);
|
||||
segments->SetGranularity(segmenter->GetGranularity());
|
||||
// 4. Set segments.[[SegmentsString]] to string.
|
||||
segments->SetSegmentsString(thread, string);
|
||||
SetTextToBreakIterator(thread, segments, string, icuBreakIterator);
|
||||
return segments;
|
||||
}
|
||||
|
||||
JSTaggedValue JSSegments::Containing(JSThread *thread, const JSHandle<JSSegments> &segments, double index)
|
||||
{
|
||||
icu::UnicodeString* unicodeString = segments->GetUString();
|
||||
// 5. Let len be the length of string.
|
||||
int32_t len = unicodeString->length();
|
||||
// 7. If n < 0 or n ≥ len, return undefined.
|
||||
if (index < 0 || index >= len) {
|
||||
return JSTaggedValue::Undefined();
|
||||
}
|
||||
int32_t n = static_cast<int32_t>(index);
|
||||
// n may point to the surrogate tail- adjust it back to the lead.
|
||||
n = unicodeString->getChar32Start(n);
|
||||
icu::BreakIterator* breakIterator = segments->GetIcuBreakIterator();
|
||||
// 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<EcmaString>(thread, segments->GetSegmentsString()),
|
||||
*unicodeString, startIndex, endIndex).GetTaggedValue();
|
||||
}
|
||||
|
||||
bool CurrentSegmentIsWordLike(icu::BreakIterator* breakIterator)
|
||||
{
|
||||
int32_t rule_status = breakIterator->getRuleStatus();
|
||||
return (rule_status >= UBRK_WORD_NUMBER &&
|
||||
rule_status < UBRK_WORD_NUMBER_LIMIT) ||
|
||||
(rule_status >= UBRK_WORD_LETTER &&
|
||||
rule_status < UBRK_WORD_LETTER_LIMIT) ||
|
||||
(rule_status >= UBRK_WORD_KANA &&
|
||||
rule_status < UBRK_WORD_KANA_LIMIT) ||
|
||||
(rule_status >= UBRK_WORD_IDEO && rule_status < UBRK_WORD_IDEO_LIMIT);
|
||||
}
|
||||
|
||||
// 18.7.1 CreateSegmentDataObject ( segmenter, string, startIndex, endIndex )
|
||||
JSHandle<JSObject> JSSegments::CreateSegmentDataObject(JSThread *thread, GranularityOption granularity,
|
||||
icu::BreakIterator* breakIterator, const JSHandle<EcmaString> &inputString,
|
||||
const icu::UnicodeString& unicodeString, int32_t startIndex, int32_t endIndex)
|
||||
{
|
||||
// 1. Let len be the length of string.
|
||||
// 2. Assert: startIndex ≥ 0.
|
||||
ASSERT(startIndex >= 0);
|
||||
// 3. Assert: endIndex ≤ len.
|
||||
ASSERT(endIndex <= unicodeString.length());
|
||||
// 4. Assert: startIndex < endIndex.
|
||||
ASSERT(startIndex < endIndex);
|
||||
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto ecmaVm = thread->GetEcmaVM();
|
||||
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
JSHandle<JSFunction> ctor(env->GetObjectFunction());
|
||||
JSHandle<JSObject> result(factory->NewJSObjectByConstructor(ctor));
|
||||
// 6. Let segment be the substring of string from startIndex to endIndex.
|
||||
JSHandle<EcmaString> segment =
|
||||
intl::LocaleHelper::UStringToString(thread, unicodeString, startIndex, endIndex);
|
||||
auto globalConst = thread->GlobalConstants();
|
||||
// 7. Perform ! CreateDataPropertyOrThrow(result, "segment", segment).
|
||||
JSHandle<JSTaggedValue> segmentKey = globalConst->GetHandledSegmentString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, segmentKey, JSHandle<JSTaggedValue>::Cast(segment));
|
||||
// 8. Perform ! CreateDataPropertyOrThrow(result, "index", 𝔽(startIndex)).
|
||||
JSHandle<JSTaggedValue> indexKey = globalConst->GetHandledIndexString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, indexKey, JSHandle<JSTaggedValue>(thread,
|
||||
base::BuiltinsBase::GetTaggedInt(startIndex)));
|
||||
// 9. Perform ! CreateDataPropertyOrThrow(result, "input", string).
|
||||
JSHandle<JSTaggedValue> inputKey = globalConst->GetHandledInputString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, inputKey, JSHandle<JSTaggedValue>::Cast(inputString));
|
||||
// 10. Let granularity be segmenter.[[SegmenterGranularity]].
|
||||
// 11. If granularity is "word", then
|
||||
// a. Let isWordLike be a Boolean value indicating whether the segment in string is "word-like"
|
||||
// according to locale segmenter.[[Locale]].
|
||||
// b. Perform ! CreateDataPropertyOrThrow(result, "isWordLike", isWordLike).
|
||||
if (granularity == GranularityOption::WORD) {
|
||||
bool isWordLike = CurrentSegmentIsWordLike(breakIterator);
|
||||
JSHandle<JSTaggedValue> isWordLikeKey = globalConst->GetHandledIsWordLikeString();
|
||||
JSObject::CreateDataPropertyOrThrow(thread, result, isWordLikeKey, JSHandle<JSTaggedValue>(thread,
|
||||
base::BuiltinsBase::GetTaggedBoolean(isWordLike)));
|
||||
}
|
||||
// 12. Return result.
|
||||
return result;
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -14,10 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_set.h"
|
||||
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void JSSet::Add(JSThread *thread, const JSHandle<JSSet> &set, const JSHandle<JSTaggedValue> &value)
|
||||
|
@ -16,11 +16,8 @@
|
||||
#include "ecmascript/js_set_iterator.h"
|
||||
|
||||
#include "ecmascript/builtins/builtins_errors.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_set.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using BuiltinsBase = base::BuiltinsBase;
|
||||
|
@ -15,27 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_stable_array.h"
|
||||
|
||||
#include "ecmascript/base/array_helper.h"
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/builtins/builtins_arraybuffer.h"
|
||||
#include "ecmascript/builtins/builtins_sendable_arraybuffer.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/ecma_string-inl.h"
|
||||
#include "ecmascript/element_accessor.h"
|
||||
#include "ecmascript/element_accessor-inl.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/fast_runtime_stub-inl.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_hclass.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "macros.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using TypedArrayHelper = base::TypedArrayHelper;
|
||||
|
@ -14,13 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/js_string_iterator.h"
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
#include "libpandabase/macros.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
JSHandle<JSStringIterator> JSStringIterator::CreateStringIterator(const JSThread *thread,
|
||||
|
@ -15,37 +15,23 @@
|
||||
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/ecma_string-inl.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_api/js_api_arraylist.h"
|
||||
#include "ecmascript/js_api/js_api_bitvector.h"
|
||||
#include "ecmascript/js_api/js_api_deque.h"
|
||||
#include "ecmascript/js_api/js_api_lightweightset.h"
|
||||
#include "ecmascript/js_api/js_api_lightweightmap.h"
|
||||
#include "ecmascript/js_api/js_api_linked_list.h"
|
||||
#include "ecmascript/js_api/js_api_list.h"
|
||||
#include "ecmascript/js_api/js_api_plain_array.h"
|
||||
#include "ecmascript/js_api/js_api_queue.h"
|
||||
#include "ecmascript/js_api/js_api_stack.h"
|
||||
#include "ecmascript/js_api/js_api_vector.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_date.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/js_object.h"
|
||||
#include "ecmascript/js_primitive_ref.h"
|
||||
#include "ecmascript/js_proxy.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/js_typed_array.h"
|
||||
#include "ecmascript/message_string.h"
|
||||
#include "ecmascript/module/js_module_namespace.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/symbol_table.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,15 +16,10 @@
|
||||
#include "ecmascript/js_thread.h"
|
||||
|
||||
#include "ecmascript/runtime.h"
|
||||
#include "ecmascript/builtin_entries.h"
|
||||
#include "ecmascript/debugger/js_debugger_manager.h"
|
||||
#include "ecmascript/ecma_context.h"
|
||||
#include "ecmascript/enum_conversion.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
#include "ecmascript/ts_types/builtin_type_id.h"
|
||||
|
||||
#if !defined(PANDA_TARGET_WINDOWS) && !defined(PANDA_TARGET_MACOS) && !defined(PANDA_TARGET_IOS)
|
||||
#include <sys/resource.h>
|
||||
@ -38,17 +33,10 @@
|
||||
#endif
|
||||
#include "ecmascript/dfx/vm_thread_control.h"
|
||||
#include "ecmascript/ecma_global_storage.h"
|
||||
#include "ecmascript/ecma_param_configuration.h"
|
||||
#include "ecmascript/global_env_constants-inl.h"
|
||||
#include "ecmascript/ic/properties_cache.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/mark_word.h"
|
||||
#include "ecmascript/napi/include/dfx_jsnapi.h"
|
||||
#include "ecmascript/platform/file.h"
|
||||
#include "ecmascript/stackmap/llvm/llvm_stackmap_parser.h"
|
||||
#include "ecmascript/builtin_entries.h"
|
||||
#include "ecmascript/jit/jit.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,11 +15,7 @@
|
||||
|
||||
#include "ecmascript/js_typed_array.h"
|
||||
|
||||
#include "ecmascript/accessor_data.h"
|
||||
#include "ecmascript/base/typed_array_helper-inl.h"
|
||||
#include "ecmascript/builtins/builtins_arraybuffer.h"
|
||||
#include "ecmascript/builtins/builtins_sendable_arraybuffer.h"
|
||||
#include "ecmascript/js_object-inl.h"
|
||||
#include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,10 +15,8 @@
|
||||
|
||||
#include "ecmascript/js_weak_container.h"
|
||||
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void JSWeakMap::Set(JSThread *thread, const JSHandle<JSWeakMap> &map, const JSHandle<JSTaggedValue> &key,
|
||||
|
@ -14,12 +14,8 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/jsnapi_sendable.h"
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/napi/jsnapi_helper.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_dictionary.h"
|
||||
#include "js_function.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
#include "ecmascript/base/number_helper.h"
|
||||
#include "ecmascript/dfx/hprof/heap_sampling.h"
|
||||
#include "ecmascript/mem/assert_scope.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void AllocationInspector::Step([[maybe_unused]] Address object, [[maybe_unused]] size_t size)
|
||||
|
@ -12,10 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/mem/barriers-inl.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/runtime.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -20,9 +20,6 @@
|
||||
|
||||
#include "ecmascript/ecma_string-inl.h"
|
||||
#include "ecmascript/js_symbol.h"
|
||||
#include "ecmascript/mem/c_containers.h"
|
||||
|
||||
#include "libpandabase/macros.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
long CStringToL(const CString &str)
|
||||
|
@ -15,18 +15,7 @@
|
||||
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
|
||||
#include "ecmascript/mem/allocator-inl.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mark_word.h"
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/sparse_space.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -14,12 +14,8 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/mem/concurrent_sweeper.h"
|
||||
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/mem/region-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,10 +16,7 @@
|
||||
#include "ecmascript/mem/free_object_list.h"
|
||||
|
||||
#include "ecmascript/free_object.h"
|
||||
#include "ecmascript/mem/free_object_set.h"
|
||||
#include "ecmascript/mem/free_object_list.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
#include "ecmascript/mem/region.h"
|
||||
#include "ecmascript/mem/jit_fort.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -15,9 +15,7 @@
|
||||
|
||||
#include "ecmascript/mem/free_object_set.h"
|
||||
|
||||
#include "ecmascript/base/asan_interface.h"
|
||||
#include "ecmascript/free_object.h"
|
||||
#include "ecmascript/mem/free_object_list.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
template <typename T>
|
||||
|
@ -15,20 +15,10 @@
|
||||
|
||||
#include "ecmascript/mem/full_gc.h"
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/mem/clock_scope.h"
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/concurrent_sweeper.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/incremental_marker.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -25,10 +25,7 @@
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,10 +16,7 @@
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include "ecmascript/common.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
|
||||
constexpr int DESCRIPTION_LENGTH = 25;
|
||||
constexpr int DATA_LENGTH = 8;
|
||||
|
@ -12,9 +12,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
@ -23,22 +20,8 @@
|
||||
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
|
||||
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
|
||||
#endif
|
||||
#include "ecmascript/daemon/daemon_thread.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/free_object.h"
|
||||
#include "ecmascript/js_finalization_registry.h"
|
||||
#include "ecmascript/js_native_pointer.h"
|
||||
#include "ecmascript/mem/assert_scope.h"
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/concurrent_sweeper.h"
|
||||
#include "ecmascript/mem/full_gc.h"
|
||||
|
||||
#include "ecmascript/mem/incremental_marker.h"
|
||||
#include "ecmascript/mem/linear_space.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mem_controller.h"
|
||||
#include "ecmascript/mem/shared_mem_controller.h"
|
||||
#include "ecmascript/mem/native_area_allocator.h"
|
||||
#include "ecmascript/mem/partial_gc.h"
|
||||
#include "ecmascript/mem/parallel_evacuator.h"
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
@ -49,11 +32,7 @@
|
||||
#include "ecmascript/mem/shared_heap/shared_concurrent_marker.h"
|
||||
#include "ecmascript/mem/stw_young_gc.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/mem/work_manager.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/mem/gc_key_stats.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
#include "ecmascript/runtime_lock.h"
|
||||
#include "ecmascript/jit/jit.h"
|
||||
#include "ecmascript/ohos/ohos_params.h"
|
||||
#if !WIN_OR_MAC_OR_IOS_PLATFORM
|
||||
|
@ -15,14 +15,8 @@
|
||||
|
||||
#include "ecmascript/mem/heap_region_allocator.h"
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/jit/jit.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mem_map_allocator.h"
|
||||
#include "ecmascript/mem/region.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/platform/map.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
constexpr size_t PANDA_POOL_ALIGNMENT_IN_BYTES = 256_KB;
|
||||
|
@ -19,19 +19,8 @@
|
||||
#include <regex>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ecmascript/mem/allocator-inl.h"
|
||||
#include "ecmascript/mem/clock_scope.h"
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mark_word.h"
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/mem/free_object_set.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/jit_fort.h"
|
||||
#include "ecmascript/jit/jit.h"
|
||||
|
@ -15,11 +15,8 @@
|
||||
|
||||
#include "ecmascript/mem/linear_space.h"
|
||||
|
||||
#include "ecmascript/free_object.h"
|
||||
#include "ecmascript/js_hclass-inl.h"
|
||||
#include "ecmascript/mem/allocator-inl.h"
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
#include "ecmascript/mem/mem_controller.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -14,11 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/mem/machine_code.h"
|
||||
#include "ecmascript/mem/assert_scope.h"
|
||||
#include "ecmascript/compiler/aot_file/func_entry_des.h"
|
||||
#include "ecmascript/stackmap/ark_stackmap.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
#include "ecmascript/jit/jit.h"
|
||||
#ifdef CODE_SIGN_ENABLE
|
||||
#include "jit_buffer_integrity.h"
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "ecmascript/mem/mem_controller.h"
|
||||
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/parallel_evacuator.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -14,8 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/mem/mem_map_allocator.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/platform/map.h"
|
||||
#include "ecmascript/platform/os.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "ecmascript/mem/native_area_allocator.h"
|
||||
|
||||
#include "ecmascript/platform/os.h"
|
||||
#include "libpandabase/os/mem.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
Area *NativeAreaAllocator::AllocateArea(size_t capacity)
|
||||
|
@ -15,18 +15,7 @@
|
||||
|
||||
#include "ecmascript/mem/parallel_evacuator-inl.h"
|
||||
|
||||
#include "ecmascript/js_hclass-inl.h"
|
||||
#include "ecmascript/mem/barriers-inl.h"
|
||||
#include "ecmascript/mem/clock_scope.h"
|
||||
#include "ecmascript/mem/concurrent_sweeper.h"
|
||||
#include "ecmascript/mem/gc_bitset.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/tlab_allocator-inl.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -12,11 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/mem/incremental_marker.h"
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
Marker::Marker(Heap *heap) : heap_(heap), workManager_(heap->GetWorkManager()) {}
|
||||
|
@ -15,20 +15,10 @@
|
||||
|
||||
#include "ecmascript/mem/partial_gc.h"
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/mem/barriers-inl.h"
|
||||
#include "ecmascript/mem/clock_scope.h"
|
||||
#include "ecmascript/mem/concurrent_marker.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/incremental_marker.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
#include "ecmascript/mem/parallel_evacuator.h"
|
||||
#include "ecmascript/mem/parallel_marker-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/runtime_call_id.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "ecmascript/mem/regexp_cached_chunk.h"
|
||||
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/mem/heap.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
@ -16,20 +16,9 @@
|
||||
#include "ecmascript/mem/shared_heap/shared_concurrent_marker.h"
|
||||
|
||||
#include "ecmascript/checkpoint/thread_state_transition.h"
|
||||
#include "ecmascript/ecma_string_table.h"
|
||||
#include "ecmascript/mem/allocator-inl.h"
|
||||
#include "ecmascript/mem/clock_scope.h"
|
||||
#include "ecmascript/mem/heap-inl.h"
|
||||
#include "ecmascript/mem/mark_stack.h"
|
||||
#include "ecmascript/mem/mark_word.h"
|
||||
#include "ecmascript/mem/shared_heap/shared_gc_marker-inl.h"
|
||||
#include "ecmascript/mem/space-inl.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/mem/visitor.h"
|
||||
#include "ecmascript/mem/gc_stats.h"
|
||||
#include "ecmascript/mem/verification.h"
|
||||
#include "ecmascript/mem/shared_heap/shared_concurrent_sweeper.h"
|
||||
#include "ecmascript/taskpool/taskpool.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
SharedConcurrentMarker::SharedConcurrentMarker(EnableConcurrentMarkType type)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user