!8495 optimize compiler(一期)

Merge pull request !8495 from fangting/master
This commit is contained in:
openharmony_ci 2024-08-07 09:50:17 +00:00 committed by Gitee
commit 98d2dc88d6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
63 changed files with 1964 additions and 2386 deletions

View File

@ -15,8 +15,6 @@
#include "ecmascript/builtins/builtins.h" #include "ecmascript/builtins/builtins.h"
#include "ecmascript/base/error_type.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/builtins/builtins_ark_tools.h" #include "ecmascript/builtins/builtins_ark_tools.h"
#include "ecmascript/builtins/builtins_array.h" #include "ecmascript/builtins/builtins_array.h"
#include "ecmascript/builtins/builtins_arraybuffer.h" #include "ecmascript/builtins/builtins_arraybuffer.h"
@ -50,11 +48,9 @@
#include "ecmascript/builtins/builtins_proxy.h" #include "ecmascript/builtins/builtins_proxy.h"
#include "ecmascript/builtins/builtins_reflect.h" #include "ecmascript/builtins/builtins_reflect.h"
#include "ecmascript/builtins/builtins_regexp.h" #include "ecmascript/builtins/builtins_regexp.h"
#include "ecmascript/builtins/builtins_regexp-inl.h"
#include "ecmascript/builtins/builtins_set.h" #include "ecmascript/builtins/builtins_set.h"
#include "ecmascript/builtins/builtins_sharedarraybuffer.h" #include "ecmascript/builtins/builtins_sharedarraybuffer.h"
#include "ecmascript/builtins/builtins_shared_typedarray.h" #include "ecmascript/builtins/builtins_shared_typedarray.h"
#include "ecmascript/builtins/builtins_string.h"
#include "ecmascript/builtins/builtins_string_iterator.h" #include "ecmascript/builtins/builtins_string_iterator.h"
#include "ecmascript/builtins/builtins_symbol.h" #include "ecmascript/builtins/builtins_symbol.h"
#include "ecmascript/builtins/builtins_typedarray.h" #include "ecmascript/builtins/builtins_typedarray.h"
@ -63,48 +59,28 @@
#include "ecmascript/builtins/builtins_weak_set.h" #include "ecmascript/builtins/builtins_weak_set.h"
#include "ecmascript/containers/containers_private.h" #include "ecmascript/containers/containers_private.h"
#include "ecmascript/dfx/native_module_failure_info.h" #include "ecmascript/dfx/native_module_failure_info.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/global_index.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_arraybuffer.h" #include "ecmascript/js_arraybuffer.h"
#include "ecmascript/js_array_iterator.h" #include "ecmascript/js_array_iterator.h"
#include "ecmascript/js_async_function.h" #include "ecmascript/js_async_function.h"
#include "ecmascript/js_async_generator_object.h" #include "ecmascript/js_async_generator_object.h"
#include "ecmascript/js_dataview.h"
#include "ecmascript/js_for_in_iterator.h" #include "ecmascript/js_for_in_iterator.h"
#include "ecmascript/js_finalization_registry.h" #include "ecmascript/js_finalization_registry.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_hclass.h"
#include "ecmascript/js_map.h" #include "ecmascript/js_map.h"
#include "ecmascript/js_map_iterator.h" #include "ecmascript/js_map_iterator.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_promise.h"
#include "ecmascript/js_regexp.h"
#include "ecmascript/js_regexp_iterator.h" #include "ecmascript/js_regexp_iterator.h"
#include "ecmascript/js_runtime_options.h"
#include "ecmascript/js_set.h" #include "ecmascript/js_set.h"
#include "ecmascript/js_set_iterator.h" #include "ecmascript/js_set_iterator.h"
#include "ecmascript/js_string_iterator.h" #include "ecmascript/js_string_iterator.h"
#include "ecmascript/js_symbol.h"
#include "ecmascript/js_async_from_sync_iterator.h" #include "ecmascript/js_async_from_sync_iterator.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/js_typed_array.h"
#include "ecmascript/js_weak_container.h" #include "ecmascript/js_weak_container.h"
#include "ecmascript/js_weak_ref.h" #include "ecmascript/js_weak_ref.h"
#include "ecmascript/mem/mem.h"
#include "ecmascript/module/js_module_namespace.h"
#include "ecmascript/require/js_cjs_module.h"
#include "ecmascript/require/js_cjs_module_cache.h" #include "ecmascript/require/js_cjs_module_cache.h"
#include "ecmascript/require/js_cjs_require.h" #include "ecmascript/require/js_cjs_require.h"
#include "ecmascript/require/js_cjs_exports.h"
#include "ecmascript/shared_objects/js_shared_array_iterator.h" #include "ecmascript/shared_objects/js_shared_array_iterator.h"
#include "ecmascript/shared_objects/js_shared_map_iterator.h" #include "ecmascript/shared_objects/js_shared_map_iterator.h"
#include "ecmascript/shared_objects/js_shared_set_iterator.h" #include "ecmascript/shared_objects/js_shared_set_iterator.h"
#include "ecmascript/symbol_table.h"
#include "ecmascript/marker_cell.h" #include "ecmascript/marker_cell.h"
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/runtime.h" #include "ecmascript/runtime.h"
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
#include "ecmascript/builtins/builtins_collator.h" #include "ecmascript/builtins/builtins_collator.h"
@ -123,11 +99,8 @@
#include "ecmascript/js_date_time_format.h" #include "ecmascript/js_date_time_format.h"
#include "ecmascript/js_displaynames.h" #include "ecmascript/js_displaynames.h"
#include "ecmascript/js_list_format.h" #include "ecmascript/js_list_format.h"
#include "ecmascript/js_locale.h"
#include "ecmascript/js_number_format.h" #include "ecmascript/js_number_format.h"
#include "ecmascript/js_plural_rules.h" #include "ecmascript/js_plural_rules.h"
#include "ecmascript/js_relative_time_format.h"
#include "ecmascript/js_segmenter.h"
#include "ecmascript/js_segments.h" #include "ecmascript/js_segments.h"
#include "ecmascript/js_segment_iterator.h" #include "ecmascript/js_segment_iterator.h"
#endif #endif

View File

@ -19,14 +19,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "ecmascript/dfx/vmstat/opt_code_profiler.h" #include "ecmascript/dfx/vmstat/opt_code_profiler.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/element_accessor-inl.h"
#include "ecmascript/js_function.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/mem/tagged_object-inl.h"
#include "ecmascript/napi/include/dfx_jsnapi.h"
#include "ecmascript/mem/clock_scope.h"
#include "ecmascript/module/js_module_source_text.h" #include "ecmascript/module/js_module_source_text.h"
#include "ecmascript/property_detector-inl.h" #include "ecmascript/property_detector-inl.h"
#include "ecmascript/js_arraybuffer.h" #include "ecmascript/js_arraybuffer.h"

View File

@ -17,27 +17,11 @@
#include <cmath> #include <cmath>
#include "ecmascript/base/array_helper.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/base/typed_array_helper-inl.h" #include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_string.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_array_iterator.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_map_iterator.h" #include "ecmascript/js_map_iterator.h"
#include "ecmascript/js_stable_array.h" #include "ecmascript/js_stable_array.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/builtins/builtins_string.h" #include "ecmascript/builtins/builtins_string.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -17,24 +17,11 @@
#include <typeinfo> #include <typeinfo>
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/builtins/builtins_bigint.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_arraybuffer.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_object-inl.h" #include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/base/typed_array_helper-inl.h" #include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "securec.h"
#include "cstdio" #include "cstdio"
#include "cstring" #include "cstring"

View File

@ -14,18 +14,11 @@
*/ */
#include "ecmascript/builtins/builtins_async_from_sync_iterator.h" #include "ecmascript/builtins/builtins_async_from_sync_iterator.h"
#include "ecmascript/builtins/builtins_promise.h"
#include "ecmascript/builtins/builtins_promise_handler.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/js_async_from_sync_iterator.h" #include "ecmascript/js_async_from_sync_iterator.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_iterator.h" #include "ecmascript/js_iterator.h"
#include "ecmascript/js_promise.h" #include "ecmascript/js_promise.h"
#include "ecmascript/js_function.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -15,8 +15,6 @@
#include "ecmascript/builtins/builtins_async_function.h" #include "ecmascript/builtins/builtins_async_function.h"
#include "ecmascript/ecma_macros.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// ecma2017 25.5.1.1 AsyncFunction (p1, p2, ... , pn, body) // ecma2017 25.5.1.1 AsyncFunction (p1, p2, ... , pn, body)
JSTaggedValue BuiltinsAsyncFunction::AsyncFunctionConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsAsyncFunction::AsyncFunctionConstructor(EcmaRuntimeCallInfo *argv)

View File

@ -14,10 +14,7 @@
*/ */
#include "ecmascript/builtins/builtins_async_generator.h" #include "ecmascript/builtins/builtins_async_generator.h"
#include "ecmascript/accessor_data.h"
#include "ecmascript/js_async_generator_object.h" #include "ecmascript/js_async_generator_object.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_tagged_value-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// ecma 27.6.1.1 // ecma 27.6.1.1

View File

@ -14,8 +14,6 @@
*/ */
#include "ecmascript/builtins/builtins_async_iterator.h" #include "ecmascript/builtins/builtins_async_iterator.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_iterator.h" #include "ecmascript/js_iterator.h"

View File

@ -17,7 +17,6 @@
#include "ecmascript/base/atomic_helper.h" #include "ecmascript/base/atomic_helper.h"
#include "ecmascript/base/typed_array_helper-inl.h" #include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/ecma_context.h"
#include "libpandabase/utils/time.h" #include "libpandabase/utils/time.h"
#include "ecmascript/checkpoint/thread_state_transition.h" #include "ecmascript/checkpoint/thread_state_transition.h"

View File

@ -15,7 +15,6 @@
#include "ecmascript/builtins/builtins_bigint.h" #include "ecmascript/builtins/builtins_bigint.h"
#include "ecmascript/js_bigint.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
#include "ecmascript/js_number_format.h" #include "ecmascript/js_number_format.h"

View File

@ -14,10 +14,6 @@
*/ */
#include "ecmascript/builtins/builtins_boolean.h" #include "ecmascript/builtins/builtins_boolean.h"
#include "ecmascript/builtins/builtins_errors.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -15,9 +15,6 @@
#include "ecmascript/builtins/builtins_cjs_exports.h" #include "ecmascript/builtins/builtins_cjs_exports.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/require/js_cjs_exports.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsCjsExports::CjsExportsConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsCjsExports::CjsExportsConstructor(EcmaRuntimeCallInfo *argv)
{ {

View File

@ -15,12 +15,8 @@
#include "ecmascript/builtins/builtins_cjs_module.h" #include "ecmascript/builtins/builtins_cjs_module.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/interpreter/interpreter-inl.h" #include "ecmascript/interpreter/interpreter-inl.h"
#include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/module_path_helper.h"
#include "ecmascript/platform/file.h"
#include "ecmascript/require/js_cjs_module.h"
#include "ecmascript/require/js_require_manager.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -15,14 +15,6 @@
#include "ecmascript/builtins/builtins_cjs_require.h" #include "ecmascript/builtins/builtins_cjs_require.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_thread.h"
#include "ecmascript/require/js_cjs_module.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsCjsRequire::CjsRequireConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsCjsRequire::CjsRequireConstructor(EcmaRuntimeCallInfo *argv)
{ {

View File

@ -1,161 +1,157 @@
/* /*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "builtins_collator.h" #include "builtins_collator.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/js_collator.h"
#include "ecmascript/global_env.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_collator.h"
#include "ecmascript/js_function.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_intl.h" constexpr uint32_t FUNCTION_LENGTH_TWO = 2;
#include "ecmascript/mem/barriers-inl.h"
// 11.1.2 Intl.Collator ( [ locales [ , options ] ] )
namespace panda::ecmascript::builtins { JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv)
constexpr uint32_t FUNCTION_LENGTH_TWO = 2; {
JSThread *thread = argv->GetThread();
// 11.1.2 Intl.Collator ( [ locales [ , options ] ] ) BUILTINS_API_TRACE(thread, Collator, CollatorConstructor);
JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread);
{ EcmaVM *ecmaVm = thread->GetEcmaVM();
JSThread *thread = argv->GetThread(); ObjectFactory *factory = ecmaVm->GetFactory();
BUILTINS_API_TRACE(thread, Collator, CollatorConstructor);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
EcmaVM *ecmaVm = thread->GetEcmaVM(); JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
if (newTarget->IsUndefined()) {
// 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. newTarget = constructor;
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); }
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); // 2. Let internalSlotsList be « [[InitializedCollator]], [[Locale]], [[Usage]], [[Sensitivity]],
if (newTarget->IsUndefined()) { // [[IgnorePunctuation]], [[Collation]], [[BoundCompare]] ».
newTarget = constructor; // 3. If %Collator%.[[RelevantExtensionKeys]] contains "kn", then
} // a. Append [[Numeric]] as the last element of internalSlotsList.
// 2. Let internalSlotsList be « [[InitializedCollator]], [[Locale]], [[Usage]], [[Sensitivity]], // 4. If %Collator%.[[RelevantExtensionKeys]] contains "kf", then
// [[IgnorePunctuation]], [[Collation]], [[BoundCompare]] ». // a. Append [[CaseFirst]] as the last element of internalSlotsList.
// 3. If %Collator%.[[RelevantExtensionKeys]] contains "kn", then
// a. Append [[Numeric]] as the last element of internalSlotsList. // 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%CollatorPrototype%", internalSlotsList).
// 4. If %Collator%.[[RelevantExtensionKeys]] contains "kf", then JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
// a. Append [[CaseFirst]] as the last element of internalSlotsList. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSCollator> collator = JSHandle<JSCollator>::Cast(newObject);
// 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%CollatorPrototype%", internalSlotsList).
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); // 6. Return ? InitializeCollator(collator, locales, options).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<JSCollator> collator = JSHandle<JSCollator>::Cast(newObject); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSCollator> result = JSCollator::InitializeCollator(thread, collator, locales, options);
// 6. Return ? InitializeCollator(collator, locales, options). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); return result.GetTaggedValue();
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); }
JSHandle<JSCollator> result = JSCollator::InitializeCollator(thread, collator, locales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] )
return result.GetTaggedValue(); JSTaggedValue BuiltinsCollator::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
// 11.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] ) BUILTINS_API_TRACE(thread, Collator, SupportedLocalesOf);
JSTaggedValue BuiltinsCollator::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread);
{ // 1. Let availableLocales be %Collator%.[[AvailableLocales]].
JSThread *thread = argv->GetThread(); JSHandle<TaggedArray> availableLocales = JSCollator::GetAvailableLocales(thread);
BUILTINS_API_TRACE(thread, Collator, SupportedLocalesOf);
[[maybe_unused]] EcmaHandleScope scope(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
// 1. Let availableLocales be %Collator%.[[AvailableLocales]]. JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<TaggedArray> availableLocales = JSCollator::GetAvailableLocales(thread); JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). return result.GetTaggedValue();
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); }
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11.3.3 get Intl.Collator.prototype.compare
return result.GetTaggedValue(); JSTaggedValue BuiltinsCollator::Compare(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
// 11.3.3 get Intl.Collator.prototype.compare BUILTINS_API_TRACE(thread, Collator, Compare);
JSTaggedValue BuiltinsCollator::Compare(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread);
{ // 1. Let collator be this value.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
BUILTINS_API_TRACE(thread, Collator, Compare);
[[maybe_unused]] EcmaHandleScope scope(thread); // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
// 1. Let collator be this value. if (!thisValue->IsJSCollator()) {
JSHandle<JSTaggedValue> thisValue = GetThis(argv); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not collator", JSTaggedValue::Exception());
}
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). // 3. If collator.[[BoundCompare]] is undefined, then
if (!thisValue->IsJSCollator()) { // a. Let F be a new built-in function object as defined in 11.3.3.1.
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not collator", JSTaggedValue::Exception()); // b. Set F.[[Collator]] to collator.
} // c. Set collator.[[BoundCompare]] to F.
// 3. If collator.[[BoundCompare]] is undefined, then // 4. Return collator.[[BoundCompare]].
// a. Let F be a new built-in function object as defined in 11.3.3.1. JSHandle<JSCollator> collator = JSHandle<JSCollator>::Cast(thisValue);
// b. Set F.[[Collator]] to collator. JSHandle<JSTaggedValue> boundCompare(thread, collator->GetBoundCompare());
// c. Set collator.[[BoundCompare]] to F. if (boundCompare->IsUndefined()) {
// 4. Return collator.[[BoundCompare]]. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSCollator> collator = JSHandle<JSCollator>::Cast(thisValue); JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction(
JSHandle<JSTaggedValue> boundCompare(thread, collator->GetBoundCompare()); MethodIndex::BUILTINS_COLLATOR_ANONYMOUS_COLLATOR, FUNCTION_LENGTH_TWO);
if (boundCompare->IsUndefined()) { intlBoundFunc->SetCollator(thread, collator);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); collator->SetBoundCompare(thread, intlBoundFunc);
JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction( }
MethodIndex::BUILTINS_COLLATOR_ANONYMOUS_COLLATOR, FUNCTION_LENGTH_TWO); return collator->GetBoundCompare();
intlBoundFunc->SetCollator(thread, collator); }
collator->SetBoundCompare(thread, intlBoundFunc);
} // 11.3.3.1 Collator Compare Functions
return collator->GetBoundCompare(); JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv)
} {
// A Collator compare function is an anonymous built-in function that has a [[Collator]] internal slot.
// 11.3.3.1 Collator Compare Functions // When a Collator compare function F is called with arguments x and y, the following steps are taken:
JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Collator, AnonymousCollator);
// A Collator compare function is an anonymous built-in function that has a [[Collator]] internal slot. [[maybe_unused]] EcmaHandleScope scope(thread);
// When a Collator compare function F is called with arguments x and y, the following steps are taken: JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::Cast(GetConstructor(argv));
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, Collator, AnonymousCollator); // 1. Let collator be F.[[Collator]].
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> collator(thread, intlBoundFunc->GetCollator());
JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::Cast(GetConstructor(argv));
// 2. Assert: Type(collator) is Object and collator has an [[InitializedCollator]] internal slot.
// 1. Let collator be F.[[Collator]]. ASSERT_PRINT(collator->IsJSObject() && collator->IsJSCollator(), "collator is not object or JSCollator");
JSHandle<JSTaggedValue> collator(thread, intlBoundFunc->GetCollator());
// 3. If x is not provided, let x be undefined.
// 2. Assert: Type(collator) is Object and collator has an [[InitializedCollator]] internal slot. JSHandle<JSTaggedValue> x = GetCallArg(argv, 0);
ASSERT_PRINT(collator->IsJSObject() && collator->IsJSCollator(), "collator is not object or JSCollator");
// 4. If y is not provided, let y be undefined.
// 3. If x is not provided, let x be undefined. JSHandle<JSTaggedValue> y = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> x = GetCallArg(argv, 0);
// 5. Let X be ? ToString(x).
// 4. If y is not provided, let y be undefined. JSHandle<EcmaString> xValue = JSTaggedValue::ToString(thread, x);
JSHandle<JSTaggedValue> y = GetCallArg(argv, 1); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined());
// 6. Let Y be ? ToString(y).
// 5. Let X be ? ToString(x). JSHandle<EcmaString> yValue = JSTaggedValue::ToString(thread, y);
JSHandle<EcmaString> xValue = JSTaggedValue::ToString(thread, x); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined());
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); // 7. Return CompareStrings(collator, X, Y).
// 6. Let Y be ? ToString(y). icu::Collator *icuCollator = (JSHandle<JSCollator>::Cast(collator))->GetIcuCollator();
JSHandle<EcmaString> yValue = JSTaggedValue::ToString(thread, y); return JSCollator::CompareStrings(thread, icuCollator, xValue, yValue);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); }
// 7. Return CompareStrings(collator, X, Y).
icu::Collator *icuCollator = (JSHandle<JSCollator>::Cast(collator))->GetIcuCollator(); // 11.3.4 Intl.Collator.prototype.resolvedOptions ()
return JSCollator::CompareStrings(thread, icuCollator, xValue, yValue); JSTaggedValue BuiltinsCollator::ResolvedOptions(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
// 11.3.4 Intl.Collator.prototype.resolvedOptions () BUILTINS_API_TRACE(thread, Collator, ResolvedOptions);
JSTaggedValue BuiltinsCollator::ResolvedOptions(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread);
{ JSHandle<JSTaggedValue> thisValue = GetThis(argv);
JSThread *thread = argv->GetThread(); if (!thisValue->IsJSCollator()) {
BUILTINS_API_TRACE(thread, Collator, ResolvedOptions); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Collator object", JSTaggedValue::Exception());
[[maybe_unused]] EcmaHandleScope scope(thread); }
JSHandle<JSTaggedValue> thisValue = GetThis(argv); JSHandle<JSObject> options = JSCollator::ResolvedOptions(thread, JSHandle<JSCollator>::Cast(thisValue));
if (!thisValue->IsJSCollator()) { return options.GetTaggedValue();
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Collator object", JSTaggedValue::Exception()); }
}
JSHandle<JSObject> options = JSCollator::ResolvedOptions(thread, JSHandle<JSCollator>::Cast(thisValue));
return options.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -14,15 +14,9 @@
*/ */
#include "ecmascript/builtins/builtins_dataview.h" #include "ecmascript/builtins/builtins_dataview.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/builtins/builtins_arraybuffer.h" #include "ecmascript/builtins/builtins_arraybuffer.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_arraybuffer.h" #include "ecmascript/js_arraybuffer.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// 24.2.2.1 // 24.2.2.1

View File

@ -15,15 +15,10 @@
#include "ecmascript/builtins/builtins_date.h" #include "ecmascript/builtins/builtins_date.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_thread.h"
#include "ecmascript/tagged_array.h"
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
#include "ecmascript/js_date.h" #include "ecmascript/js_date.h"
#include "ecmascript/js_date_time_format.h" #include "ecmascript/js_date_time_format.h"

View File

@ -1,335 +1,333 @@
/* /*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "builtins_date_time_format.h" #include "builtins_date_time_format.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h"
#include "ecmascript/global_env.h" #include "ecmascript/js_date.h"
#include "ecmascript/js_date.h" #include "ecmascript/js_date_time_format.h"
#include "ecmascript/js_date_time_format.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_intl.h"
#include "ecmascript/js_intl.h"
#include "ecmascript/mem/barriers-inl.h" namespace panda::ecmascript::builtins {
// 13.2.1 Intl.DateTimeFormat ( [ locales [ , options ] ] )
namespace panda::ecmascript::builtins { JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallInfo *argv)
// 13.2.1 Intl.DateTimeFormat ( [ locales [ , options ] ] ) {
JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, Constructor);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, Constructor); EcmaVM *ecmaVm = thread->GetEcmaVM();
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
// 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); if (newTarget->IsUndefined()) {
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); newTarget = constructor;
if (newTarget->IsUndefined()) { }
newTarget = constructor;
} // 2. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%DateTimeFormatPrototype%", «
// [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]],
// 2. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%DateTimeFormatPrototype%", « // [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]],
// [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], // [[Pattern]], [[BoundFormat]] »).
// [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
// [[Pattern]], [[BoundFormat]] »). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); JSHandle<JSDateTimeFormat> dateTimeFormat = JSHandle<JSDateTimeFormat>::Cast(newObject);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSDateTimeFormat> dateTimeFormat = JSHandle<JSDateTimeFormat>::Cast(newObject); // 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
// 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options). JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); JSHandle<JSDateTimeFormat> dtf =
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); JSDateTimeFormat::InitializeDateTimeFormat(thread, dateTimeFormat, locales, options);
JSHandle<JSDateTimeFormat> dtf = RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSDateTimeFormat::InitializeDateTimeFormat(thread, dateTimeFormat, locales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 4. Let this be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %DateTimeFormat%) is true,
// then
// 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %DateTimeFormat%) is true, // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]:
// then // dateTimeFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
// a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: // b. Return this.
// dateTimeFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }). if (GetNewTarget(argv)->IsUndefined() && thisValue->IsJSObject()) {
// b. Return this. bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), thisValue);
if (GetNewTarget(argv)->IsUndefined() && thisValue->IsJSObject()) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), thisValue); if (isInstanceOf) {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PropertyDescriptor descriptor(thread, JSHandle<JSTaggedValue>::Cast(dtf), false, false, false);
if (isInstanceOf) { JSHandle<JSTaggedValue> key(thread, JSHandle<JSIntl>::Cast(env->GetIntlFunction())->GetFallbackSymbol());
PropertyDescriptor descriptor(thread, JSHandle<JSTaggedValue>::Cast(dtf), false, false, false); JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor);
JSHandle<JSTaggedValue> key(thread, JSHandle<JSIntl>::Cast(env->GetIntlFunction())->GetFallbackSymbol()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); return thisValue.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return thisValue.GetTaggedValue(); }
}
} // 6. Return dateTimeFormat.
return dtf.GetTaggedValue();
// 6. Return dateTimeFormat. }
return dtf.GetTaggedValue();
} // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] )
JSTaggedValue BuiltinsDateTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
// 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) {
JSTaggedValue BuiltinsDateTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, SupportedLocalesOf);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, SupportedLocalesOf); // 1. Let availableLocales be %DateTimeFormat%.[[AvailableLocales]].
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<TaggedArray> availableLocales = JSDateTimeFormat::GainAvailableLocales(thread);
// 1. Let availableLocales be %DateTimeFormat%.[[AvailableLocales]].
JSHandle<TaggedArray> availableLocales = JSDateTimeFormat::GainAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} // 13.4.3 get Intl.DateTimeFormat.prototype.format
JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv)
// 13.4.3 get Intl.DateTimeFormat.prototype.format {
JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, Format);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, Format);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let dtf be this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception.
if (!thisValue->IsJSObject()) {
// 2. If Type(dtf) is not Object, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "dtf is not object", JSTaggedValue::Exception());
if (!thisValue->IsJSObject()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "dtf is not object", JSTaggedValue::Exception());
} // 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
JSHandle<JSTaggedValue> dtfValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue);
// 3. Let dtf be ? UnwrapDateTimeFormat(dtf). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> dtfValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue); if (dtfValue->IsUndefined()) {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "dtfValue is not object", JSTaggedValue::Exception());
if (dtfValue->IsUndefined()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "dtfValue is not object", JSTaggedValue::Exception());
} // 4. If dtf.[[BoundFormat]] is undefined, then
// a. Let F be a new built-in function object as defined in DateTime Format Functions (13.1.5).
// 4. If dtf.[[BoundFormat]] is undefined, then // b. Set F.[[DateTimeFormat]] to dtf.
// a. Let F be a new built-in function object as defined in DateTime Format Functions (13.1.5). // c. Set dtf.[[BoundFormat]] to F.
// b. Set F.[[DateTimeFormat]] to dtf. // 5. Return dtf.[[BoundFormat]].
// c. Set dtf.[[BoundFormat]] to F. JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(dtfValue);
// 5. Return dtf.[[BoundFormat]]. JSHandle<JSTaggedValue> boundFormat(thread, dtf->GetBoundFormat());
JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(dtfValue); if (boundFormat->IsUndefined()) {
JSHandle<JSTaggedValue> boundFormat(thread, dtf->GetBoundFormat()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
if (boundFormat->IsUndefined()) { JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction(
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); MethodIndex::BUILTINS_DATE_TIME_FORMAT_ANONYMOUS_DATE_TIME_FORMAT);
JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction( intlBoundFunc->SetDateTimeFormat(thread, dtf);
MethodIndex::BUILTINS_DATE_TIME_FORMAT_ANONYMOUS_DATE_TIME_FORMAT); dtf->SetBoundFormat(thread, intlBoundFunc);
intlBoundFunc->SetDateTimeFormat(thread, dtf); }
dtf->SetBoundFormat(thread, intlBoundFunc); return dtf->GetBoundFormat();
} }
return dtf->GetBoundFormat();
} // 13.1.5 DateTime Format Functions
JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv)
// 13.1.5 DateTime Format Functions {
JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv) // A DateTime format function is an anonymous built-in function that has a [[DateTimeFormat]] internal slot.
{ // When a DateTime format function F is called with optional argument date, the following steps are taken:
// A DateTime format function is an anonymous built-in function that has a [[DateTimeFormat]] internal slot. JSThread *thread = argv->GetThread();
// When a DateTime format function F is called with optional argument date, the following steps are taken: BUILTINS_API_TRACE(thread, DateTimeFormat, AnonymousDateTimeFormat);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, AnonymousDateTimeFormat); JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::Cast(GetConstructor(argv));
[[maybe_unused]] EcmaHandleScope scope(thread);
JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::Cast(GetConstructor(argv)); // 1. Let dtf be F.[[DateTimeFormat]].
JSHandle<JSTaggedValue> dtf(thread, intlBoundFunc->GetDateTimeFormat());
// 1. Let dtf be F.[[DateTimeFormat]].
JSHandle<JSTaggedValue> dtf(thread, intlBoundFunc->GetDateTimeFormat()); // 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]] internal slot.
ASSERT_PRINT(dtf->IsJSObject() && dtf->IsJSDateTimeFormat(), "dtf is not object or JSDateTimeFormat");
// 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]] internal slot.
ASSERT_PRINT(dtf->IsJSObject() && dtf->IsJSDateTimeFormat(), "dtf is not object or JSDateTimeFormat"); // 3. If date is not provided or is undefined, then
// a. Let x be Call(%Date_now%, undefined).
// 3. If date is not provided or is undefined, then // 4. Else,
// a. Let x be Call(%Date_now%, undefined). // a. Let x be ? ToNumber(date).
// 4. Else, JSHandle<JSTaggedValue> date = GetCallArg(argv, 0);
// a. Let x be ? ToNumber(date). double x = 0.0;
JSHandle<JSTaggedValue> date = GetCallArg(argv, 0); if (date->IsUndefined()) {
double x = 0.0; x = JSDate::Now().GetNumber();
if (date->IsUndefined()) { } else {
x = JSDate::Now().GetNumber(); JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date);
} else { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date); x = xNumber.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
x = xNumber.GetNumber();
} // 5. Return ? FormatDateTime(dtf, x).
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, JSHandle<JSDateTimeFormat>::Cast(dtf), x);
// 5. Return ? FormatDateTime(dtf, x). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> result = JSDateTimeFormat::FormatDateTime(thread, JSHandle<JSDateTimeFormat>::Cast(dtf), x); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} // 13.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date )
JSTaggedValue BuiltinsDateTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv)
// 13.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date ) {
JSTaggedValue BuiltinsDateTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, FormatToParts);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, FormatToParts); // 1. Let dtf be this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> dtf = GetThis(argv);
// 1. Let dtf be this value. // 2. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
JSHandle<JSTaggedValue> dtf = GetThis(argv); if (!dtf->IsJSDateTimeFormat()) {
// 2. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]). THROW_TYPE_ERROR_AND_RETURN(thread, "is not JSDateTimeFormat", JSTaggedValue::Exception());
if (!dtf->IsJSDateTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "is not JSDateTimeFormat", JSTaggedValue::Exception());
} // 3. If date is undefined, then
// a. Let x be Call(%Date_now%, undefined).
// 3. If date is undefined, then // 4. Else,
// a. Let x be Call(%Date_now%, undefined). // a. Let x be ? ToNumber(date).
// 4. Else, JSHandle<JSTaggedValue> date = GetCallArg(argv, 0);
// a. Let x be ? ToNumber(date). double x = 0.0;
JSHandle<JSTaggedValue> date = GetCallArg(argv, 0); if (date->IsUndefined()) {
double x = 0.0; x = JSDate::Now().GetNumber();
if (date->IsUndefined()) { } else {
x = JSDate::Now().GetNumber(); JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date);
} else { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date); x = xNumber.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
x = xNumber.GetNumber();
} double xValue = JSDate::TimeClip(x);
if (std::isnan(xValue)) {
double xValue = JSDate::TimeClip(x); THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid time value", JSTaggedValue::Exception());
if (std::isnan(xValue)) { }
THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid time value", JSTaggedValue::Exception());
} // 5. Return ? FormatDateTimeToParts(dtf, x).
JSHandle<JSArray> result =
// 5. Return ? FormatDateTimeToParts(dtf, x). JSDateTimeFormat::FormatDateTimeToParts(thread, JSHandle<JSDateTimeFormat>::Cast(dtf), xValue);
JSHandle<JSArray> result = RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSDateTimeFormat::FormatDateTimeToParts(thread, JSHandle<JSDateTimeFormat>::Cast(dtf), xValue); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions ()
JSTaggedValue BuiltinsDateTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv)
// 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () {
JSTaggedValue BuiltinsDateTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, ResolvedOptions);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, ResolvedOptions); // 1. Let dtf be this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let dtf be this value. // 2. If Type(dtf) is not Object, throw a TypeError exception.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); if (!thisValue->IsJSObject()) {
// 2. If Type(dtf) is not Object, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception());
if (!thisValue->IsJSObject()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); // 3. Let dtf be ? UnwrapDateTimeFormat(dtf).
} thisValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue);
// 3. Let dtf be ? UnwrapDateTimeFormat(dtf). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
thisValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
if (!thisValue->IsJSDateTimeFormat()) {
// Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]). THROW_TYPE_ERROR_AND_RETURN(thread, "dtf is not JSDateTimeFormat", JSTaggedValue::Exception());
if (!thisValue->IsJSDateTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "dtf is not JSDateTimeFormat", JSTaggedValue::Exception());
} auto ecmaVm = thread->GetEcmaVM();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
auto ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); JSHandle<JSFunction> ctor(env->GetObjectFunction());
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
JSHandle<JSFunction> ctor(env->GetObjectFunction()); JSDateTimeFormat::ResolvedOptions(thread, JSHandle<JSDateTimeFormat>::Cast(thisValue), options);
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); // 6. Return options.
JSDateTimeFormat::ResolvedOptions(thread, JSHandle<JSDateTimeFormat>::Cast(thisValue), options); return options.GetTaggedValue();
// 6. Return options. }
return options.GetTaggedValue();
} // Intl.DateTimeFormat.prototype.formatRange
JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv)
// Intl.DateTimeFormat.prototype.formatRange {
JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, FormatRange);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, FormatRange);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let dtf be this value. // 2. If Type(dtf) is not Object, throw a TypeError exception.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); if (!thisValue->IsJSObject()) {
// 2. If Type(dtf) is not Object, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception());
if (!thisValue->IsJSObject()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception());
} // 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception.
if (!thisValue->IsJSDateTimeFormat()) {
// 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception());
if (!thisValue->IsJSDateTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception());
} // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception.
JSHandle<JSTaggedValue> startDate = GetCallArg(argv, 0);
// 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. JSHandle<JSTaggedValue> endDate = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> startDate = GetCallArg(argv, 0); if (startDate->IsUndefined() || endDate->IsUndefined()) {
JSHandle<JSTaggedValue> endDate = GetCallArg(argv, 1); THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception());
if (startDate->IsUndefined() || endDate->IsUndefined()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception());
} // 5. Let x be ? ToNumber(startDate).
JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate);
// 5. Let x be ? ToNumber(startDate). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate); double x = valueX.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double x = valueX.GetNumber(); // 6. Let y be ? ToNumber(endDate).
JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate);
// 6. Let y be ? ToNumber(endDate). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); double y = valueY.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double y = valueY.GetNumber(); // 8. Return ? FormatDateTimeRange(dtf, x, y)
JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(thisValue);
// 8. Return ? FormatDateTimeRange(dtf, x, y) JSHandle<EcmaString> result = JSDateTimeFormat::NormDateTimeRange(thread, dtf, x, y);
JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> result = JSDateTimeFormat::NormDateTimeRange(thread, dtf, x, y); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} // Intl.DateTimeFormat.prototype.formatRangeToParts
JSTaggedValue BuiltinsDateTimeFormat::FormatRangeToParts(EcmaRuntimeCallInfo *argv)
// Intl.DateTimeFormat.prototype.formatRangeToParts {
JSTaggedValue BuiltinsDateTimeFormat::FormatRangeToParts(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, DateTimeFormat, FormatRangeToParts);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, DateTimeFormat, FormatRangeToParts); // 1. Let dtf be this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let dtf be this value. // 2. If Type(dtf) is not Object, throw a TypeError exception.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); if (!thisValue->IsJSObject()) {
// 2. If Type(dtf) is not Object, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception());
if (!thisValue->IsJSObject()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception());
} // 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot,
// throw a TypeError exception.
// 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, if (!thisValue->IsJSDateTimeFormat()) {
// throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception());
if (!thisValue->IsJSDateTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception());
} // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception.
JSHandle<JSTaggedValue> startDate = GetCallArg(argv, 0);
// 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. JSHandle<JSTaggedValue> endDate = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> startDate = GetCallArg(argv, 0); if (startDate->IsUndefined() || endDate->IsUndefined()) {
JSHandle<JSTaggedValue> endDate = GetCallArg(argv, 1); THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception());
if (startDate->IsUndefined() || endDate->IsUndefined()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception());
} // 5. Let x be ? ToNumber(startDate).
JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate);
// 5. Let x be ? ToNumber(startDate). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate); double x = valueX.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double x = valueX.GetNumber(); // 6. Let y be ? ToNumber(endDate).
JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate);
// 6. Let y be ? ToNumber(endDate). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); double y = valueY.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double y = valueY.GetNumber(); // 8. Return ? FormatDateTimeRangeToParts(dtf, x, y)
JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(thisValue);
// 8. Return ? FormatDateTimeRangeToParts(dtf, x, y) JSHandle<JSArray> result = JSDateTimeFormat::NormDateTimeRangeToParts(thread, dtf, x, y);
JSHandle<JSDateTimeFormat> dtf = JSHandle<JSDateTimeFormat>::Cast(thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSArray> result = JSDateTimeFormat::NormDateTimeRangeToParts(thread, dtf, x, y); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -1,156 +1,149 @@
/* /*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "builtins_displaynames.h" #include "builtins_displaynames.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/js_displaynames.h"
#include "ecmascript/global_env.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_displaynames.h" // 12.2.1 Intl.DisplayNames ( [ locales [ , options ] ] )
#include "ecmascript/js_intl.h" JSTaggedValue BuiltinsDisplayNames::DisplayNamesConstructor(EcmaRuntimeCallInfo *argv)
#include "ecmascript/js_locale.h" {
#include "ecmascript/js_object.h" JSThread *thread = argv->GetThread();
#include "ecmascript/object_factory.h" BUILTINS_API_TRACE(thread, DisplayNames, Constructor);
[[maybe_unused]] EcmaHandleScope scope(thread);
namespace panda::ecmascript::builtins { EcmaVM *ecmaVm = thread->GetEcmaVM();
// 12.2.1 Intl.DisplayNames ( [ locales [ , options ] ] ) ObjectFactory *factory = ecmaVm->GetFactory();
JSTaggedValue BuiltinsDisplayNames::DisplayNamesConstructor(EcmaRuntimeCallInfo *argv)
{ // 1. If NewTarget is undefined, throw a TypeError exception.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
BUILTINS_API_TRACE(thread, DisplayNames, Constructor); if (newTarget->IsUndefined()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
EcmaVM *ecmaVm = thread->GetEcmaVM(); }
ObjectFactory *factory = ecmaVm->GetFactory();
// 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%",
// 1. If NewTarget is undefined, throw a TypeError exception. // « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
if (newTarget->IsUndefined()) { JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
} JSHandle<JSDisplayNames> displayNames = JSHandle<JSDisplayNames>::Cast(newObject);
// 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", // 3. Perform ? InitializeDisplayNames(displayNames, locales, options).
// « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); JSDisplayNames::InitializeDisplayNames(thread, displayNames, locales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSDisplayNames> displayNames = JSHandle<JSDisplayNames>::Cast(newObject); return displayNames.GetTaggedValue();
}
// 3. Perform ? InitializeDisplayNames(displayNames, locales, options).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); // 12.3.2 Intl.DisplayNames.supportedLocalesOf ( locales [ , options ] )
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); JSTaggedValue BuiltinsDisplayNames::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
JSDisplayNames::InitializeDisplayNames(thread, displayNames, locales, options); {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSThread *thread = argv->GetThread();
return displayNames.GetTaggedValue(); BUILTINS_API_TRACE(thread, DisplayNames, SupportedLocalesOf);
} [[maybe_unused]] EcmaHandleScope scope(thread);
// 12.3.2 Intl.DisplayNames.supportedLocalesOf ( locales [ , options ] ) // 1. Let availableLocales be %DisplayNames%.[[AvailableLocales]].
JSTaggedValue BuiltinsDisplayNames::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSHandle<TaggedArray> availableLocales = JSDisplayNames::GetAvailableLocales(thread);
{
JSThread *thread = argv->GetThread(); // 2. Let requestedLocales be ? CanonicaliezLocaleList(locales).
BUILTINS_API_TRACE(thread, DisplayNames, SupportedLocalesOf); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 1. Let availableLocales be %DisplayNames%.[[AvailableLocales]].
JSHandle<TaggedArray> availableLocales = JSDisplayNames::GetAvailableLocales(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// 2. Let requestedLocales be ? CanonicaliezLocaleList(locales). JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). // 12.4.3 get Intl.DisplayNames.prototype.of
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); JSTaggedValue BuiltinsDisplayNames::Of(EcmaRuntimeCallInfo *argv)
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSThread *thread = argv->GetThread();
return result.GetTaggedValue(); BUILTINS_API_TRACE(thread, DisplayNames, Of);
} [[maybe_unused]] EcmaHandleScope scope(thread);
// 1. Let displayNames be this value.
// 12.4.3 get Intl.DisplayNames.prototype.of JSHandle<JSTaggedValue> thisValue = GetThis(argv);
JSTaggedValue BuiltinsDisplayNames::Of(EcmaRuntimeCallInfo *argv)
{ // 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
JSThread *thread = argv->GetThread(); if (!thisValue->IsJSDisplayNames()) {
BUILTINS_API_TRACE(thread, DisplayNames, Of); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not dn object", JSTaggedValue::Exception());
[[maybe_unused]] EcmaHandleScope scope(thread); }
// 1. Let displayNames be this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 3. Let code be ? ToString(code).
JSHandle<JSTaggedValue> codeValue = GetCallArg(argv, 0);
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]). JSHandle<EcmaString> codeTemp = JSTaggedValue::ToString(thread, codeValue);
if (!thisValue->IsJSDisplayNames()) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not dn object", JSTaggedValue::Exception());
} // 4. Let code be ? CanonicalCodeForDisplayNames(displayNames.[[Type]], code).
// 5. Let fields be displayNames.[[Fields]].
// 3. Let code be ? ToString(code). // 6. If fields has a field [[<code>]], return fields.[[<code>]].
JSHandle<JSTaggedValue> codeValue = GetCallArg(argv, 0); JSHandle<JSDisplayNames> displayNames = JSHandle<JSDisplayNames>::Cast(thisValue);
JSHandle<EcmaString> codeTemp = JSTaggedValue::ToString(thread, codeValue); TypednsOption typeOpt = displayNames->GetType();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<EcmaString> code = JSDisplayNames::CanonicalCodeForDisplayNames(thread, displayNames, typeOpt, codeTemp);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 4. Let code be ? CanonicalCodeForDisplayNames(displayNames.[[Type]], code). std::string codeString = intl::LocaleHelper::ConvertToStdString(code);
// 5. Let fields be displayNames.[[Fields]]. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 6. If fields has a field [[<code>]], return fields.[[<code>]]. if (codeString.size()) {
JSHandle<JSDisplayNames> displayNames = JSHandle<JSDisplayNames>::Cast(thisValue); JSHandle<JSTaggedValue> codeStr = JSHandle<JSTaggedValue>::Cast(code);
TypednsOption typeOpt = displayNames->GetType(); return codeStr.GetTaggedValue();
JSHandle<EcmaString> code = JSDisplayNames::CanonicalCodeForDisplayNames(thread, displayNames, typeOpt, codeTemp); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
std::string codeString = intl::LocaleHelper::ConvertToStdString(code); // 7. If displayNames.[[Fallback]] is "code", return code.
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); FallbackOption fallback = displayNames->GetFallback();
if (codeString.size()) { if (fallback == FallbackOption::CODE) {
JSHandle<JSTaggedValue> codeStr = JSHandle<JSTaggedValue>::Cast(code); return codeValue.GetTaggedValue();
return codeStr.GetTaggedValue(); }
} // 8. Return undefined.
return JSTaggedValue::Undefined();
// 7. If displayNames.[[Fallback]] is "code", return code. }
FallbackOption fallback = displayNames->GetFallback();
if (fallback == FallbackOption::CODE) { // 12.4.4 Intl.DisplayNames.prototype.resolvedOptions ()
return codeValue.GetTaggedValue(); JSTaggedValue BuiltinsDisplayNames::ResolvedOptions(EcmaRuntimeCallInfo *argv)
} {
// 8. Return undefined. JSThread *thread = argv->GetThread();
return JSTaggedValue::Undefined(); BUILTINS_API_TRACE(thread, DisplayNames, ResolvedOptions);
} [[maybe_unused]] EcmaHandleScope scope(thread);
// 12.4.4 Intl.DisplayNames.prototype.resolvedOptions () // 1. Let DisplayNames be the this value.
JSTaggedValue BuiltinsDisplayNames::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSHandle<JSTaggedValue> thisValue = GetThis(argv);
{
JSThread *thread = argv->GetThread(); // 2. Perform ? RequireInternalSlot(DisplayNames, [[InitializedDisplayNames]]).
BUILTINS_API_TRACE(thread, DisplayNames, ResolvedOptions); if (!thisValue->IsJSDisplayNames()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not dn object", JSTaggedValue::Exception());
}
// 1. Let DisplayNames be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 3. Let options be ! OrdinaryObjectCreate(%ObjectPrototype%).
auto ecmaVm = thread->GetEcmaVM();
// 2. Perform ? RequireInternalSlot(DisplayNames, [[InitializedDisplayNames]]). JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
if (!thisValue->IsJSDisplayNames()) { ObjectFactory *factory = ecmaVm->GetFactory();
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not dn object", JSTaggedValue::Exception()); JSHandle<JSFunction> ctor(env->GetObjectFunction());
} JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
// 3. Let options be ! OrdinaryObjectCreate(%ObjectPrototype%). // 4. For each row of Table 8, except the header row, in table order, do
auto ecmaVm = thread->GetEcmaVM(); // Let p be the Property value of the current row.
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); // Let v be the value of displayNames's internal slot whose name is the Internal Slot value of the current row.
ObjectFactory *factory = ecmaVm->GetFactory(); // Assert: v is not undefined.
JSHandle<JSFunction> ctor(env->GetObjectFunction()); // Perform ! CreateDataPropertyOrThrow(options, p, v).
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); JSHandle<JSDisplayNames> displayNames = JSHandle<JSDisplayNames>::Cast(thisValue);
JSDisplayNames::ResolvedOptions(thread, displayNames, options);
// 4. For each row of Table 8, except the header row, in table order, do RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// Let p be the Property value of the current row.
// Let v be the value of displayNames's internal slot whose name is the Internal Slot value of the current row. // 5. Return options.
// Assert: v is not undefined. return options.GetTaggedValue();
// Perform ! CreateDataPropertyOrThrow(options, p, v). }
JSHandle<JSDisplayNames> displayNames = JSHandle<JSDisplayNames>::Cast(thisValue);
JSDisplayNames::ResolvedOptions(thread, displayNames, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 5. Return options.
return options.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -14,14 +14,7 @@
*/ */
#include "ecmascript/builtins/builtins_errors.h" #include "ecmascript/builtins/builtins_errors.h"
#include "ecmascript/base/error_helper.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_array.h" #include "ecmascript/js_array.h"
#include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_iterator.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
using ErrorHelper = base::ErrorHelper; using ErrorHelper = base::ErrorHelper;

View File

@ -14,12 +14,9 @@
*/ */
#include "ecmascript/builtins/builtins_finalization_registry.h" #include "ecmascript/builtins/builtins_finalization_registry.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/js_finalization_registry.h" #include "ecmascript/js_finalization_registry.h"
#include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// 26.2.1.1 // 26.2.1.1

View File

@ -15,14 +15,10 @@
#include "ecmascript/builtins/builtins_function.h" #include "ecmascript/builtins/builtins_function.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h" #include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/js_arguments.h" #include "ecmascript/js_arguments.h"
#include "ecmascript/js_stable_array.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/tagged_array-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// ecma 19.2.1 Function (p1, p2, ... , pn, body) // ecma 19.2.1 Function (p1, p2, ... , pn, body)

View File

@ -15,7 +15,6 @@
#include "builtins_generator.h" #include "builtins_generator.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_generator_object.h" #include "ecmascript/js_generator_object.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -20,18 +20,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ecmascript/base/number_helper.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_object-inl.h" #include "ecmascript/js_object-inl.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/module_path_helper.h"
#include "ecmascript/stubs/runtime_stubs.h" #include "ecmascript/stubs/runtime_stubs.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/containers/containers_errors.h" #include "ecmascript/containers/containers_errors.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h" #include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/module/js_module_manager.h" #include "ecmascript/module/js_module_manager.h"

View File

@ -1,40 +1,37 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ecmascript/builtins/builtins_intl.h" #include "ecmascript/builtins/builtins_intl.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_locale.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_tagged_value.h" // 8.2.1 Intl.getCanonicalLocales ( locales )
JSTaggedValue BuiltinsIntl::GetCanonicalLocales(EcmaRuntimeCallInfo *argv)
namespace panda::ecmascript::builtins { {
// 8.2.1 Intl.getCanonicalLocales ( locales ) JSThread *thread = argv->GetThread();
JSTaggedValue BuiltinsIntl::GetCanonicalLocales(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, Intl, GetCanonicalLocales);
{ [[maybe_unused]] EcmaHandleScope scope(thread);
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, Intl, GetCanonicalLocales); // 1.Let ll be ? CanonicalizeLocaleList(locales).
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<TaggedArray> elements = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
// 1.Let ll be ? CanonicalizeLocaleList(locales). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<TaggedArray> elements = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); // 2.Return CreateArrayFromList(ll).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<JSArray> result = JSArray::CreateArrayFromList(thread, elements);
return result.GetTaggedValue();
// 2.Return CreateArrayFromList(ll). }
JSHandle<JSArray> result = JSArray::CreateArrayFromList(thread, elements);
return result.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -14,10 +14,6 @@
*/ */
#include "ecmascript/builtins/builtins_iterator.h" #include "ecmascript/builtins/builtins_iterator.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_iterator.h" #include "ecmascript/js_iterator.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -15,20 +15,8 @@
#include "ecmascript/builtins/builtins_json.h" #include "ecmascript/builtins/builtins_json.h"
#include "ecmascript/base/fast_json_stringifier.h"
#include "ecmascript/base/json_helper.h"
#include "ecmascript/base/json_parser.h" #include "ecmascript/base/json_parser.h"
#include "ecmascript/base/json_stringifier.h" #include "ecmascript/base/json_stringifier.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/slow_runtime_stub.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_object.h"
#include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
namespace { namespace {

View File

@ -16,10 +16,7 @@
#include "ecmascript/builtins/builtins_lazy_callback.h" #include "ecmascript/builtins/builtins_lazy_callback.h"
#include "ecmascript/builtins/builtins.h" #include "ecmascript/builtins/builtins.h"
#include "ecmascript/global_dictionary-inl.h"
#include "ecmascript/layout_info-inl.h" #include "ecmascript/layout_info-inl.h"
#include "ecmascript/tagged_dictionary.h"
#include "ecmascript/ecma_macros.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsLazyCallback::Date(JSThread *thread, const JSHandle<JSObject> &obj) JSTaggedValue BuiltinsLazyCallback::Date(JSThread *thread, const JSHandle<JSObject> &obj)

View File

@ -1,171 +1,166 @@
/* /*
* Copyright (c) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ecmascript/builtins/builtins_list_format.h" #include "ecmascript/builtins/builtins_list_format.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h"
#include "ecmascript/global_env.h" #include "ecmascript/js_list_format.h"
#include "ecmascript/js_list_format.h"
#include "ecmascript/js_intl.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_locale.h" JSTaggedValue BuiltinsListFormat::ListFormatConstructor(EcmaRuntimeCallInfo *argv)
#include "ecmascript/js_object.h" {
#include "ecmascript/object_factory.h" JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, ListFormat, Constructor);
namespace panda::ecmascript::builtins { [[maybe_unused]] EcmaHandleScope scope(thread);
JSTaggedValue BuiltinsListFormat::ListFormatConstructor(EcmaRuntimeCallInfo *argv) EcmaVM *ecmaVm = thread->GetEcmaVM();
{ ObjectFactory *factory = ecmaVm->GetFactory();
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, ListFormat, Constructor); // 1. If NewTarget is undefined, throw a TypeError exception.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
EcmaVM *ecmaVm = thread->GetEcmaVM(); if (newTarget->IsUndefined()) {
ObjectFactory *factory = ecmaVm->GetFactory(); THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
}
// 1. If NewTarget is undefined, throw a TypeError exception.
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); // 2. Let listFormat be ? OrdinaryCreateFromConstructor
if (newTarget->IsUndefined()) { // (NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]],
THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception()); // [[Type]], [[Style]], [[Templates]] »).
}
JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
// 2. Let listFormat be ? OrdinaryCreateFromConstructor JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
// (NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]], RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// [[Type]], [[Style]], [[Templates]] »). JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(newObject);
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); // 3. Perform ? InitializeListFormat(listFormat, locales, options).
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(newObject); listFormat = JSListFormat::InitializeListFormat(thread, listFormat, locales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 3. Perform ? InitializeListFormat(listFormat, locales, options). return listFormat.GetTaggedValue();
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); }
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
listFormat = JSListFormat::InitializeListFormat(thread, listFormat, locales, options); // 13.3.2 Intl.ListFormat.supportedLocalesOf ( locales [ , options ] )
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue BuiltinsListFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
return listFormat.GetTaggedValue(); {
} JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, ListFormat, SupportedLocalesOf);
// 13.3.2 Intl.ListFormat.supportedLocalesOf ( locales [ , options ] ) [[maybe_unused]] EcmaHandleScope scope(thread);
JSTaggedValue BuiltinsListFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
{ // 1. Let availableLocales be %ListFormat%.[[AvailableLocales]].
JSThread *thread = argv->GetThread(); JSHandle<TaggedArray> availableLocales = JSListFormat::GetAvailableLocales(thread);
BUILTINS_API_TRACE(thread, ListFormat, SupportedLocalesOf);
[[maybe_unused]] EcmaHandleScope scope(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
// 1. Let availableLocales be %ListFormat%.[[AvailableLocales]]. JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
JSHandle<TaggedArray> availableLocales = JSListFormat::GetAvailableLocales(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
return result.GetTaggedValue();
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). }
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); // 13.4.3 Intl.ListFormat.prototype.format( list )
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue BuiltinsListFormat::Format(EcmaRuntimeCallInfo *argv)
return result.GetTaggedValue(); {
} JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, ListFormat, Format);
// 13.4.3 Intl.ListFormat.prototype.format( list ) [[maybe_unused]] EcmaHandleScope scope(thread);
JSTaggedValue BuiltinsListFormat::Format(EcmaRuntimeCallInfo *argv)
{ // 1. Let lf be the this value.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
BUILTINS_API_TRACE(thread, ListFormat, Format);
[[maybe_unused]] EcmaHandleScope scope(thread); // 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
if (!thisValue->IsJSListFormat()) {
// 1. Let lf be the this value. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSListFormat", JSTaggedValue::Exception());
JSHandle<JSTaggedValue> thisValue = GetThis(argv); }
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]). // 3. Let stringList be ? StringListFromIterable(list).
if (!thisValue->IsJSListFormat()) { JSHandle<JSTaggedValue> list = GetCallArg(argv, 0);
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSListFormat", JSTaggedValue::Exception()); JSHandle<JSTaggedValue> listArray = JSListFormat::StringListFromIterable(thread, list);
} RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 3. Let stringList be ? StringListFromIterable(list). // 4. Return FormatList(lf, stringList).
JSHandle<JSTaggedValue> list = GetCallArg(argv, 0); JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(thisValue);
JSHandle<JSTaggedValue> listArray = JSListFormat::StringListFromIterable(thread, list); JSHandle<JSArray> array = JSHandle<JSArray>::Cast(listArray);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<EcmaString> result = JSListFormat::FormatList(thread, listFormat, array);
return result.GetTaggedValue();
// 4. Return FormatList(lf, stringList). }
JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(thisValue);
JSHandle<JSArray> array = JSHandle<JSArray>::Cast(listArray); // 13.4.4 Intl.ListFormat.prototype.formatToParts ( list )
JSHandle<EcmaString> result = JSListFormat::FormatList(thread, listFormat, array); JSTaggedValue BuiltinsListFormat::FormatToParts(EcmaRuntimeCallInfo *argv)
return result.GetTaggedValue(); {
} JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, ListFormat, FormatToParts);
// 13.4.4 Intl.ListFormat.prototype.formatToParts ( list ) [[maybe_unused]] EcmaHandleScope scope(thread);
JSTaggedValue BuiltinsListFormat::FormatToParts(EcmaRuntimeCallInfo *argv)
{ // 1. Let lf be the this value.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
BUILTINS_API_TRACE(thread, ListFormat, FormatToParts);
[[maybe_unused]] EcmaHandleScope scope(thread); // 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
if (!thisValue->IsJSListFormat()) {
// 1. Let lf be the this value. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSListFormat", JSTaggedValue::Exception());
JSHandle<JSTaggedValue> thisValue = GetThis(argv); }
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]). // 3. Let stringList be ? StringListFromIterable(list).
if (!thisValue->IsJSListFormat()) { JSHandle<JSTaggedValue> list = GetCallArg(argv, 0);
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSListFormat", JSTaggedValue::Exception()); JSHandle<JSTaggedValue> listArray = JSListFormat::StringListFromIterable(thread, list);
} RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 3. Let stringList be ? StringListFromIterable(list). // 4 Return FormatListToParts(lf, stringList).
JSHandle<JSTaggedValue> list = GetCallArg(argv, 0); JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(thisValue);
JSHandle<JSTaggedValue> listArray = JSListFormat::StringListFromIterable(thread, list); JSHandle<JSArray> array = JSHandle<JSArray>::Cast(listArray);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSArray> result = JSListFormat::FormatListToParts(thread, listFormat, array);
// 4 Return FormatListToParts(lf, stringList). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(thisValue); return result.GetTaggedValue();
JSHandle<JSArray> array = JSHandle<JSArray>::Cast(listArray); }
JSHandle<JSArray> result = JSListFormat::FormatListToParts(thread, listFormat, array); // 13.4.5 Intl.ListFormat.prototype.resolvedOptions()
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue BuiltinsListFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv)
return result.GetTaggedValue(); {
} JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, ListFormat, ResolvedOptions);
// 13.4.5 Intl.ListFormat.prototype.resolvedOptions() [[maybe_unused]] EcmaHandleScope scope(thread);
JSTaggedValue BuiltinsListFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv)
{ // 1. Let lf be the this value.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
BUILTINS_API_TRACE(thread, ListFormat, ResolvedOptions);
[[maybe_unused]] EcmaHandleScope scope(thread); // 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
if (!thisValue->IsJSListFormat()) {
// 1. Let lf be the this value. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSListFormat", JSTaggedValue::Exception());
JSHandle<JSTaggedValue> thisValue = GetThis(argv); }
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]). // 3 .Let options be ! OrdinaryObjectCreate(%Object.prototype%).
if (!thisValue->IsJSListFormat()) { auto ecmaVm = thread->GetEcmaVM();
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSListFormat", JSTaggedValue::Exception()); JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
} ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<JSFunction> ctor(env->GetObjectFunction());
// 3 .Let options be ! OrdinaryObjectCreate(%Object.prototype%). JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
auto ecmaVm = thread->GetEcmaVM();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); // 4. For each row of Table 9, except the header row, in table order, do
ObjectFactory *factory = ecmaVm->GetFactory(); // Let p be the Property value of the current row.
JSHandle<JSFunction> ctor(env->GetObjectFunction()); // Let v be the value of lf's internal slot whose name is the Internal Slot value of the current row.
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); // Assert: v is not undefined.
// Perform ! CreateDataPropertyOrThrow(options, p, v).
// 4. For each row of Table 9, except the header row, in table order, do JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(thisValue);
// Let p be the Property value of the current row. JSListFormat::ResolvedOptions(thread, listFormat, options);
// Let v be the value of lf's internal slot whose name is the Internal Slot value of the current row. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// Assert: v is not undefined.
// Perform ! CreateDataPropertyOrThrow(options, p, v). // 5. Return options.
JSHandle<JSListFormat> listFormat = JSHandle<JSListFormat>::Cast(thisValue); return options.GetTaggedValue();
JSListFormat::ResolvedOptions(thread, listFormat, options); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 5. Return options.
return options.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -1,375 +1,373 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ecmascript/builtins/builtins_locale.h" #include "ecmascript/builtins/builtins_locale.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h"
#include "ecmascript/global_env.h" #include "ecmascript/object_factory-inl.h"
#include "ecmascript/js_locale.h"
#include "ecmascript/object_factory-inl.h" namespace panda::ecmascript::builtins {
// 10.1.3 Intl.Locale( tag [, options] )
namespace panda::ecmascript::builtins { JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv)
// 10.1.3 Intl.Locale( tag [, options] ) {
JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, Constructor);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, Constructor); EcmaVM *ecmaVm = thread->GetEcmaVM();
[[maybe_unused]] EcmaHandleScope scope(thread); ObjectFactory *factory = ecmaVm->GetFactory();
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception.
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
// 1. If NewTarget is undefined, throw a TypeError exception. if (newTarget->IsUndefined()) {
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
if (newTarget->IsUndefined()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
} // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList).
JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
// 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList). JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); JSHandle<JSLocale> locale =JSHandle<JSLocale>::Cast(newObject);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSLocale> locale =JSHandle<JSLocale>::Cast(newObject); // 7. If Type(tag) is not String or Object, throw a TypeError exception.
JSHandle<JSTaggedValue> tag = GetCallArg(argv, 0);
// 7. If Type(tag) is not String or Object, throw a TypeError exception. if (!tag->IsString() && !tag->IsJSObject()) {
JSHandle<JSTaggedValue> tag = GetCallArg(argv, 0); THROW_TYPE_ERROR_AND_RETURN(thread, "tag is not String or Object", JSTaggedValue::Exception());
if (!tag->IsString() && !tag->IsJSObject()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "tag is not String or Object", JSTaggedValue::Exception());
} // 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal slot, then
// a.Let tag be tag.[[Locale]].
// 8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal slot, then // 9. Else,
// a.Let tag be tag.[[Locale]]. // a.Let tag be ? ToString(tag).
// 9. Else, JSHandle<EcmaString> localeString = factory->GetEmptyString();
// a.Let tag be ? ToString(tag). if (!tag->IsJSLocale()) {
JSHandle<EcmaString> localeString = factory->GetEmptyString(); localeString = JSTaggedValue::ToString(thread, tag);
if (!tag->IsJSLocale()) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
localeString = JSTaggedValue::ToString(thread, tag); } else {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); icu::Locale *icuLocale = (JSHandle<JSLocale>::Cast(tag))->GetIcuLocale();
} else { localeString = intl::LocaleHelper::ToLanguageTag(thread, *icuLocale);
icu::Locale *icuLocale = (JSHandle<JSLocale>::Cast(tag))->GetIcuLocale(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
localeString = intl::LocaleHelper::ToLanguageTag(thread, *icuLocale); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If options is undefined, then
} // a.Let options be ! ObjectCreate(null).
// 10. If options is undefined, then // 11. Else
// a.Let options be ! ObjectCreate(null). // a.Let options be ? ToObject(options).
// 11. Else JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// a.Let options be ? ToObject(options). JSHandle<JSObject> optionsObj;
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); if (options->IsUndefined()) {
JSHandle<JSObject> optionsObj; optionsObj = factory->CreateNullJSObject();
if (options->IsUndefined()) { } else {
optionsObj = factory->CreateNullJSObject(); optionsObj = JSTaggedValue::ToObject(thread, options);
} else { }
optionsObj = JSTaggedValue::ToObject(thread, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
}
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<JSLocale> result = JSLocale::InitializeLocale(thread, locale, localeString, optionsObj);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSLocale> result = JSLocale::InitializeLocale(thread, locale, localeString, optionsObj); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::Maximize(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::Maximize(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, Maximize);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, Maximize); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value.
JSHandle<JSTaggedValue> loc = GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is
} // signaled, set maximal to loc.[[Locale]].
// 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. If an error is JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// signaled, set maximal to loc.[[Locale]]. icu::Locale source(*(locale->GetIcuLocale()));
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); UErrorCode status = U_ZERO_ERROR;
icu::Locale source(*(locale->GetIcuLocale())); source.addLikelySubtags(status);
UErrorCode status = U_ZERO_ERROR; ASSERT(U_SUCCESS(status));
source.addLikelySubtags(status); ASSERT(!source.isBogus());
ASSERT(U_SUCCESS(status));
ASSERT(!source.isBogus()); // 4. Return ! Construct(%Locale%, maximal).
EcmaVM *ecmaVm = thread->GetEcmaVM();
// 4. Return ! Construct(%Locale%, maximal). JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSFunction> ctor(env->GetLocaleFunction());
JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor);
JSHandle<JSFunction> ctor(env->GetLocaleFunction()); factory->NewJSIntlIcuData(JSHandle<JSLocale>::Cast(obj), source, JSLocale::FreeIcuLocale);
JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor); return obj.GetTaggedValue();
factory->NewJSIntlIcuData(JSHandle<JSLocale>::Cast(obj), source, JSLocale::FreeIcuLocale); }
return obj.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::Minimize(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::Minimize(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, Minimize);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, Minimize); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value.
JSHandle<JSTaggedValue> loc = GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
} // 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]].
// If an error is signaled, set minimal to loc.[[Locale]].
// 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// If an error is signaled, set minimal to loc.[[Locale]]. icu::Locale source(*(locale->GetIcuLocale()));
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); UErrorCode status = U_ZERO_ERROR;
icu::Locale source(*(locale->GetIcuLocale())); source.minimizeSubtags(status);
UErrorCode status = U_ZERO_ERROR; ASSERT(U_SUCCESS(status));
source.minimizeSubtags(status); ASSERT(!source.isBogus());
ASSERT(U_SUCCESS(status));
ASSERT(!source.isBogus()); [[maybe_unused]] auto res = source.toLanguageTag<CString>(status);
[[maybe_unused]] auto res = source.toLanguageTag<CString>(status); // 4. Return ! Construct(%Locale%, minimal).
EcmaVM *ecmaVm = thread->GetEcmaVM();
// 4. Return ! Construct(%Locale%, minimal). JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSFunction> ctor(env->GetLocaleFunction());
JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor);
JSHandle<JSFunction> ctor(env->GetLocaleFunction()); factory->NewJSIntlIcuData(JSHandle<JSLocale>::Cast(obj), source, JSLocale::FreeIcuLocale);
JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor); return obj.GetTaggedValue();
factory->NewJSIntlIcuData(JSHandle<JSLocale>::Cast(obj), source, JSLocale::FreeIcuLocale); }
return obj.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::ToString(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::ToString(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, ToString);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, ToString); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[Locale]].
} JSHandle<EcmaString> result = JSLocale::ToString(thread, JSHandle<JSLocale>::Cast(loc));
// 3. Return loc.[[Locale]]. return result.GetTaggedValue();
JSHandle<EcmaString> result = JSLocale::ToString(thread, JSHandle<JSLocale>::Cast(loc)); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::GetBaseName(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetBaseName(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetBaseName);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetBaseName); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Let locale be loc.[[Locale]].
} // 4. Return the substring of locale corresponding to the unicode_language_id production.
// 3. Let locale be loc.[[Locale]]. JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 4. Return the substring of locale corresponding to the unicode_language_id production. icu::Locale icuLocale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName());
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); JSHandle<EcmaString> baseName = intl::LocaleHelper::ToLanguageTag(thread, icuLocale);
icu::Locale icuLocale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> baseName = intl::LocaleHelper::ToLanguageTag(thread, icuLocale); return baseName.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return baseName.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::GetCalendar(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetCalendar(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetCalendar);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetCalendar); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[Calendar]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Return loc.[[Calendar]]. JSTaggedValue calendar = JSLocale::NormalizeKeywordValue(thread, locale, "ca");
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); return calendar;
JSTaggedValue calendar = JSLocale::NormalizeKeywordValue(thread, locale, "ca"); }
return calendar;
} JSTaggedValue BuiltinsLocale::GetCaseFirst(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetCaseFirst(EcmaRuntimeCallInfo *argv) // This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kf".
{ JSThread *thread = argv->GetThread();
// This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kf". BUILTINS_API_TRACE(thread, Locale, GetCaseFirst);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetCaseFirst); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[CaseFirst]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Return loc.[[CaseFirst]]. JSTaggedValue caseFirst = JSLocale::NormalizeKeywordValue(thread, locale, "kf");
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); return caseFirst;
JSTaggedValue caseFirst = JSLocale::NormalizeKeywordValue(thread, locale, "kf"); }
return caseFirst;
} JSTaggedValue BuiltinsLocale::GetCollation(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetCollation(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetCollation);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetCollation); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[Collation]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Return loc.[[Collation]]. JSTaggedValue collation = JSLocale::NormalizeKeywordValue(thread, locale, "co");
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); return collation;
JSTaggedValue collation = JSLocale::NormalizeKeywordValue(thread, locale, "co"); }
return collation;
} JSTaggedValue BuiltinsLocale::GetHourCycle(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetHourCycle(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetHourCycle);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetHourCycle); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[HourCycle]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Return loc.[[HourCycle]]. JSTaggedValue hourCycle = JSLocale::NormalizeKeywordValue(thread, locale, "hc");
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); return hourCycle;
JSTaggedValue hourCycle = JSLocale::NormalizeKeywordValue(thread, locale, "hc"); }
return hourCycle;
} JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv) // This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kn".
{ JSThread *thread = argv->GetThread();
// This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kn". BUILTINS_API_TRACE(thread, Locale, GetNumeric);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetNumeric); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[Numeric]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Return loc.[[Numeric]]. icu::Locale *icuLocale = locale->GetIcuLocale();
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); UErrorCode status = U_ZERO_ERROR;
icu::Locale *icuLocale = locale->GetIcuLocale(); auto numeric = icuLocale->getUnicodeKeywordValue<CString>("kn", status);
UErrorCode status = U_ZERO_ERROR; JSTaggedValue result = (numeric == "true") ? JSTaggedValue::True() : JSTaggedValue::False();
auto numeric = icuLocale->getUnicodeKeywordValue<CString>("kn", status); return result;
JSTaggedValue result = (numeric == "true") ? JSTaggedValue::True() : JSTaggedValue::False(); }
return result;
} JSTaggedValue BuiltinsLocale::GetNumberingSystem(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetNumberingSystem(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetNumberingSystem);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetNumberingSystem); // 1. Let loc be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Return loc.[[NumberingSystem]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Return loc.[[NumberingSystem]]. JSTaggedValue numberingSystem = JSLocale::NormalizeKeywordValue(thread, locale, "nu");
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); return numberingSystem;
JSTaggedValue numberingSystem = JSLocale::NormalizeKeywordValue(thread, locale, "nu"); }
return numberingSystem;
} JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetLanguage);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetLanguage); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value.
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Let locale be loc.[[Locale]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Let locale be loc.[[Locale]]. // 4. Assert: locale matches the unicode_locale_id production.
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); // 5. Return the substring of locale corresponding to the unicode_language_subtag production of the
// 4. Assert: locale matches the unicode_locale_id production. // unicode_language_id.
// 5. Return the substring of locale corresponding to the unicode_language_subtag production of the JSHandle<EcmaString> result = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledUndefinedString());
// unicode_language_id. CString language = locale->GetIcuLocale()->getLanguage();
JSHandle<EcmaString> result = JSHandle<EcmaString>::Cast(thread->GlobalConstants()->GetHandledUndefinedString()); if (language.empty()) {
CString language = locale->GetIcuLocale()->getLanguage(); return result.GetTaggedValue();
if (language.empty()) { }
return result.GetTaggedValue(); result = factory->NewFromUtf8(language);
} return result.GetTaggedValue();
result = factory->NewFromUtf8(language); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::GetScript(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetScript(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetScript);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetScript); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value.
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Let locale be loc.[[Locale]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Let locale be loc.[[Locale]].
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); // 4. Assert: locale matches the unicode_locale_id production.
// 5. If the unicode_language_id production of locale does not contain the ["-" unicode_script_subtag] sequence,
// 4. Assert: locale matches the unicode_locale_id production. // return undefined.
// 5. If the unicode_language_id production of locale does not contain the ["-" unicode_script_subtag] sequence, // 6. Return the substring of locale corresponding to the unicode_script_subtag production of the
// return undefined. // unicode_language_id.
// 6. Return the substring of locale corresponding to the unicode_script_subtag production of the JSHandle<EcmaString> result(thread, JSTaggedValue::Undefined());
// unicode_language_id. CString script = locale->GetIcuLocale()->getScript();
JSHandle<EcmaString> result(thread, JSTaggedValue::Undefined()); if (script.empty()) {
CString script = locale->GetIcuLocale()->getScript(); return result.GetTaggedValue();
if (script.empty()) { }
return result.GetTaggedValue(); result = factory->NewFromUtf8(script);
} return result.GetTaggedValue();
result = factory->NewFromUtf8(script); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, Locale, GetRegion);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, Locale, GetRegion); EcmaVM *ecmaVm = thread->GetEcmaVM();
[[maybe_unused]] EcmaHandleScope scope(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants();
EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
const GlobalEnvConstants *globalConst = thread->GlobalConstants(); // 1. Let loc be the this value.
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSTaggedValue> loc = GetThis(argv);
// 1. Let loc be the this value. // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
JSHandle<JSTaggedValue> loc = GetThis(argv); if (!loc->IsJSLocale()) {
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception());
if (!loc->IsJSLocale()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); // 3. Let locale be loc.[[Locale]].
} JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc);
// 3. Let locale be loc.[[Locale]]. // 4. Assert: locale matches the unicode_locale_id production.
JSHandle<JSLocale> locale = JSHandle<JSLocale>::Cast(loc); // 5. If the unicode_language_id production of locale does not contain the ["-" unicode_region_subtag] sequence,
// 4. Assert: locale matches the unicode_locale_id production. // return undefined.
// 5. If the unicode_language_id production of locale does not contain the ["-" unicode_region_subtag] sequence, // 6. Return the substring of locale corresponding to the unicode_region_subtag production of the
// return undefined. // unicode_language_id.
// 6. Return the substring of locale corresponding to the unicode_region_subtag production of the CString region = locale->GetIcuLocale()->getCountry();
// unicode_language_id. if (region.empty()) {
CString region = locale->GetIcuLocale()->getCountry(); return globalConst->GetUndefined();
if (region.empty()) { }
return globalConst->GetUndefined(); return factory->NewFromUtf8(region).GetTaggedValue();
} }
return factory->NewFromUtf8(region).GetTaggedValue(); } // namespace panda::ecmascript::builtins
}
} // namespace panda::ecmascript::builtins

View File

@ -14,15 +14,11 @@
*/ */
#include "ecmascript/builtins/builtins_map.h" #include "ecmascript/builtins/builtins_map.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_map.h" #include "ecmascript/js_map.h"
#include "ecmascript/js_map_iterator.h" #include "ecmascript/js_map_iterator.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv)

View File

@ -16,9 +16,6 @@
#include "ecmascript/builtins/builtins_math.h" #include "ecmascript/builtins/builtins_math.h"
#include <random> #include <random>
#include <sys/time.h> #include <sys/time.h>
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/js_tagged_value-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -15,20 +15,8 @@
#include "ecmascript/builtins/builtins_number.h" #include "ecmascript/builtins/builtins_number.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_hclass.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/tagged_hash_table.h"
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
#include "ecmascript/js_number_format.h" #include "ecmascript/js_number_format.h"
#else #else

View File

@ -1,220 +1,212 @@
/* /*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ecmascript/builtins/builtins_number_format.h" #include "ecmascript/builtins/builtins_number_format.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/js_function.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/js_number_format.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_array.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_intl.h" // 13.2.1 Intl.NumberFormat ( [ locales [ , options ] ] )
#include "ecmascript/js_function.h" JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo *argv)
#include "ecmascript/js_locale.h" {
#include "ecmascript/js_number_format.h" JSThread *thread = argv->GetThread();
#include "ecmascript/js_tagged_value.h" BUILTINS_API_TRACE(thread, NumberFormat, Constructor);
#include "ecmascript/object_factory.h" [[maybe_unused]] EcmaHandleScope scope(thread);
EcmaVM *ecmaVm = thread->GetEcmaVM();
namespace panda::ecmascript::builtins { JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
// 13.2.1 Intl.NumberFormat ( [ locales [ , options ] ] ) ObjectFactory *factory = ecmaVm->GetFactory();
JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo *argv)
{ // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
BUILTINS_API_TRACE(thread, NumberFormat, Constructor); JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
[[maybe_unused]] EcmaHandleScope scope(thread); if (newTarget->IsUndefined()) {
EcmaVM *ecmaVm = thread->GetEcmaVM(); newTarget = constructor;
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); }
ObjectFactory *factory = ecmaVm->GetFactory();
// Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormatPrototype%",
// 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. // « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]],
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); // [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]],
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); // [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]],
if (newTarget->IsUndefined()) { // [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »).
newTarget = constructor; JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
} RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSNumberFormat> numberFormat = JSHandle<JSNumberFormat>::Cast(newObject);
// Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormatPrototype%",
// « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options).
// [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
// [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »). JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSNumberFormat> numberFormat = JSHandle<JSNumberFormat>::Cast(newObject); // 4. Let this be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 3. Perform ? InitializeNumberFormat(numberFormat, locales, options).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); // 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %NumberFormat%) is true,
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); // then
JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // [[Value]]: numberFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }).
// b. Return this.
// 4. Let this be the this value. if (GetNewTarget(argv)->IsUndefined() && thisValue->IsJSObject()) {
JSHandle<JSTaggedValue> thisValue = GetThis(argv); bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetNumberFormatFunction(), thisValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %NumberFormat%) is true, if (isInstanceOf) {
// then PropertyDescriptor descriptor(thread, JSHandle<JSTaggedValue>::Cast(numberFormat), false, false, false);
// a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ JSHandle<JSTaggedValue> key(thread, JSHandle<JSIntl>::Cast(env->GetIntlFunction())->GetFallbackSymbol());
// [[Value]]: numberFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }). JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor);
// b. Return this. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (GetNewTarget(argv)->IsUndefined() && thisValue->IsJSObject()) { return thisValue.GetTaggedValue();
bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetNumberFormatFunction(), thisValue); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
if (isInstanceOf) {
PropertyDescriptor descriptor(thread, JSHandle<JSTaggedValue>::Cast(numberFormat), false, false, false); // 6. Return numberFormat.
JSHandle<JSTaggedValue> key(thread, JSHandle<JSIntl>::Cast(env->GetIntlFunction())->GetFallbackSymbol()); return numberFormat.GetTaggedValue();
JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
return thisValue.GetTaggedValue(); // 13.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] )
} JSTaggedValue BuiltinsNumberFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
// 6. Return numberFormat. BUILTINS_API_TRACE(thread, NumberFormat, SupportedLocalesOf);
return numberFormat.GetTaggedValue(); [[maybe_unused]] EcmaHandleScope scope(thread);
} // 1. Let availableLocales be %NumberFormat%.[[AvailableLocales]].
JSHandle<TaggedArray> availableLocales = JSNumberFormat::GetAvailableLocales(thread);
// 13.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] )
JSTaggedValue BuiltinsNumberFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
{ JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSThread *thread = argv->GetThread(); JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
BUILTINS_API_TRACE(thread, NumberFormat, SupportedLocalesOf); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
[[maybe_unused]] EcmaHandleScope scope(thread);
// 1. Let availableLocales be %NumberFormat%.[[AvailableLocales]]. // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<TaggedArray> availableLocales = JSNumberFormat::GetAvailableLocales(thread); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); return result.GetTaggedValue();
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 13.4.3 get Intl.NumberFormat.prototype.format
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); {
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); JSThread *thread = argv->GetThread();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); BUILTINS_API_TRACE(thread, NumberFormat, Format);
return result.GetTaggedValue(); [[maybe_unused]] EcmaHandleScope scope(thread);
}
// 1. Let nf be this value.
// 13.4.3 get Intl.NumberFormat.prototype.format JSHandle<JSTaggedValue> thisValue = GetThis(argv);
JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) // 2. If Type(nf) is not Object, throw a TypeError exception.
{ if (!thisValue->IsJSObject()) {
JSThread *thread = argv->GetThread(); THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception());
BUILTINS_API_TRACE(thread, NumberFormat, Format); }
[[maybe_unused]] EcmaHandleScope scope(thread); // 3. Let nf be ? UnwrapNumberFormat(nf).
JSHandle<JSTaggedValue> nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue);
// 1. Let nf be this value. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> thisValue = GetThis(argv); if (nf->IsUndefined()) {
// 2. If Type(nf) is not Object, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception());
if (!thisValue->IsJSObject()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception());
} JSHandle<JSNumberFormat> typpedNf = JSHandle<JSNumberFormat>::Cast(nf);
// 3. Let nf be ? UnwrapNumberFormat(nf). JSHandle<JSTaggedValue> boundFunc(thread, typpedNf->GetBoundFormat());
JSHandle<JSTaggedValue> nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue); // 4. If nf.[[BoundFormat]] is undefined, then
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // a. Let F be a new built-in function object as defined in Number Format Functions (12.1.4).
if (nf->IsUndefined()) { // b. Set F.[[NumberFormat]] to nf.
THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception()); // c. Set nf.[[BoundFormat]] to F.
} if (boundFunc->IsUndefined()) {
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSNumberFormat> typpedNf = JSHandle<JSNumberFormat>::Cast(nf); JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction(
JSHandle<JSTaggedValue> boundFunc(thread, typpedNf->GetBoundFormat()); MethodIndex::BUILTINS_NUMBER_FORMAT_NUMBER_FORMAT_INTERNAL_FORMAT_NUMBER);
// 4. If nf.[[BoundFormat]] is undefined, then intlBoundFunc->SetNumberFormat(thread, typpedNf);
// a. Let F be a new built-in function object as defined in Number Format Functions (12.1.4). typpedNf->SetBoundFormat(thread, intlBoundFunc);
// b. Set F.[[NumberFormat]] to nf. }
// c. Set nf.[[BoundFormat]] to F. return typpedNf->GetBoundFormat();
if (boundFunc->IsUndefined()) { }
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction( // 13.4.4 Intl.NumberFormat.prototype.formatToParts ( date )
MethodIndex::BUILTINS_NUMBER_FORMAT_NUMBER_FORMAT_INTERNAL_FORMAT_NUMBER); JSTaggedValue BuiltinsNumberFormat::FormatToParts(EcmaRuntimeCallInfo *argv)
intlBoundFunc->SetNumberFormat(thread, typpedNf); {
typpedNf->SetBoundFormat(thread, intlBoundFunc); JSThread *thread = argv->GetThread();
} BUILTINS_API_TRACE(thread, NumberFormat, FormatToParts);
return typpedNf->GetBoundFormat(); [[maybe_unused]] EcmaHandleScope scope(thread);
} // 1. Let nf be the this value.
JSHandle<JSTaggedValue> nf = GetThis(argv);
// 13.4.4 Intl.NumberFormat.prototype.formatToParts ( date ) // 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
JSTaggedValue BuiltinsNumberFormat::FormatToParts(EcmaRuntimeCallInfo *argv) if (!nf->IsJSNumberFormat()) {
{ THROW_TYPE_ERROR_AND_RETURN(thread, "Is not JSNumberFormat", JSTaggedValue::Exception());
JSThread *thread = argv->GetThread(); }
BUILTINS_API_TRACE(thread, NumberFormat, FormatToParts); // 3. Let x be ? ToNumeric(value).
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
// 1. Let nf be the this value. JSHandle<JSTaggedValue> x = JSTaggedValue::ToNumeric(thread, value);
JSHandle<JSTaggedValue> nf = GetThis(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]). JSHandle<JSArray> result =
if (!nf->IsJSNumberFormat()) { JSNumberFormat::FormatNumericToParts(thread, JSHandle<JSNumberFormat>::Cast(nf), x.GetTaggedValue());
THROW_TYPE_ERROR_AND_RETURN(thread, "Is not JSNumberFormat", JSTaggedValue::Exception()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
} return result.GetTaggedValue();
// 3. Let x be ? ToNumeric(value). }
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0); // 13.4.5 Intl.NumberFormat.prototype.resolvedOptions ()
JSHandle<JSTaggedValue> x = JSTaggedValue::ToNumeric(thread, value); JSTaggedValue BuiltinsNumberFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); {
JSHandle<JSArray> result = JSThread *thread = argv->GetThread();
JSNumberFormat::FormatNumericToParts(thread, JSHandle<JSNumberFormat>::Cast(nf), x.GetTaggedValue()); BUILTINS_API_TRACE(thread, NumberFormat, ResolvedOptions);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); [[maybe_unused]] EcmaHandleScope scope(thread);
return result.GetTaggedValue(); // 1. Let nf be this value.
} JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 13.4.5 Intl.NumberFormat.prototype.resolvedOptions () // 2. If Type(nf) is not Object, throw a TypeError exception.
JSTaggedValue BuiltinsNumberFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) if (!thisValue->IsJSObject()) {
{ THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception());
JSThread *thread = argv->GetThread(); }
BUILTINS_API_TRACE(thread, NumberFormat, ResolvedOptions); // 3. Let nf be ? UnwrapNumberFormat(nf).
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue);
// 1. Let nf be this value. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
// 2. If Type(nf) is not Object, throw a TypeError exception. if (!nf->IsJSNumberFormat()) {
if (!thisValue->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not JSNumberFormat", JSTaggedValue::Exception());
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); }
} // 4. Let options be ! ObjectCreate(%ObjectPrototype%).
// 3. Let nf be ? UnwrapNumberFormat(nf). auto ecmaVm = thread->GetEcmaVM();
JSHandle<JSTaggedValue> nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue); JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); ObjectFactory *factory = ecmaVm->GetFactory();
// Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]). JSHandle<JSFunction> ctor(env->GetObjectFunction());
if (!nf->IsJSNumberFormat()) { JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not JSNumberFormat", JSTaggedValue::Exception());
} // 5. For each row of Table 5, except the header row, in table order, do
// 4. Let options be ! ObjectCreate(%ObjectPrototype%). // Let p be the Property value of the current row.
auto ecmaVm = thread->GetEcmaVM(); // Let v be the value of nf's internal slot whose name is the Internal Slot value of the current row.
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); // If v is not undefined, then
ObjectFactory *factory = ecmaVm->GetFactory(); // Perform ! CreateDataPropertyOrThrow(options, p, v).
JSHandle<JSFunction> ctor(env->GetObjectFunction()); JSNumberFormat::ResolvedOptions(thread, JSHandle<JSNumberFormat>::Cast(nf), options);
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); return options.GetTaggedValue();
}
// 5. For each row of Table 5, except the header row, in table order, do
// Let p be the Property value of the current row. JSTaggedValue BuiltinsNumberFormat::NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv)
// Let v be the value of nf's internal slot whose name is the Internal Slot value of the current row. {
// If v is not undefined, then JSThread *thread = argv->GetThread();
// Perform ! CreateDataPropertyOrThrow(options, p, v). [[maybe_unused]] EcmaHandleScope scope(thread);
JSNumberFormat::ResolvedOptions(thread, JSHandle<JSNumberFormat>::Cast(nf), options); JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::Cast(GetConstructor(argv));
return options.GetTaggedValue();
} // 1. Let nf be F.[[NumberFormat]].
JSHandle<JSTaggedValue> nf(thread, intlBoundFunc->GetNumberFormat());
JSTaggedValue BuiltinsNumberFormat::NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv) // 2. Assert: Type(nf) is Object and nf has an [[InitializedNumberFormat]] internal slot.
{ ASSERT(nf->IsJSObject() && nf->IsJSNumberFormat());
JSThread *thread = argv->GetThread(); // 3. If value is not provided, let value be undefined.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
JSHandle<JSIntlBoundFunction> intlBoundFunc = JSHandle<JSIntlBoundFunction>::Cast(GetConstructor(argv)); // 4 Let x be ? ToNumeric(value).
JSHandle<JSTaggedValue> x = JSTaggedValue::ToNumeric(thread, value);
// 1. Let nf be F.[[NumberFormat]]. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> nf(thread, intlBoundFunc->GetNumberFormat()); // 5 Return ? FormatNumeric(nf, x).
// 2. Assert: Type(nf) is Object and nf has an [[InitializedNumberFormat]] internal slot. JSHandle<JSTaggedValue> result =
ASSERT(nf->IsJSObject() && nf->IsJSNumberFormat()); JSNumberFormat::FormatNumeric(thread, JSHandle<JSNumberFormat>::Cast(nf), x.GetTaggedValue());
// 3. If value is not provided, let value be undefined. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0); return result.GetTaggedValue();
// 4 Let x be ? ToNumeric(value). }
JSHandle<JSTaggedValue> x = JSTaggedValue::ToNumeric(thread, value);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 5 Return ? FormatNumeric(nf, x).
JSHandle<JSTaggedValue> result =
JSNumberFormat::FormatNumeric(thread, JSHandle<JSNumberFormat>::Cast(nf), x.GetTaggedValue());
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
return result.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -16,17 +16,8 @@
#include "ecmascript/builtins/builtins_object.h" #include "ecmascript/builtins/builtins_object.h"
#include "ecmascript/builtins/builtins_map.h" #include "ecmascript/builtins/builtins_map.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.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.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_realm.h"
#include "ecmascript/message_string.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -1,135 +1,132 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ecmascript/builtins/builtins_plural_rules.h" #include "ecmascript/builtins/builtins_plural_rules.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/js_locale.h" #include "ecmascript/js_plural_rules.h"
#include "ecmascript/js_object.h"
#include "ecmascript/js_plural_rules.h" namespace panda::ecmascript::builtins {
#include "ecmascript/object_factory.h" JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *argv)
{
namespace panda::ecmascript::builtins { JSThread *thread = argv->GetThread();
JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PluralRules, Constructor);
{ [[maybe_unused]] EcmaHandleScope scope(thread);
JSThread *thread = argv->GetThread(); EcmaVM *ecmaVm = thread->GetEcmaVM();
BUILTINS_API_TRACE(thread, PluralRules, Constructor); ObjectFactory *factory = ecmaVm->GetFactory();
[[maybe_unused]] EcmaHandleScope scope(thread);
EcmaVM *ecmaVm = thread->GetEcmaVM(); // 1. If NewTarget is undefined, throw a TypeError exception.
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
// 1. If NewTarget is undefined, throw a TypeError exception. if (newTarget->IsUndefined()) {
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); }
if (newTarget->IsUndefined()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception()); // 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRulesPrototype%",
} // « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]],
// [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »).
// 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRulesPrototype%", JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
// « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »). JSHandle<JSPluralRules> pluralRules = JSHandle<JSPluralRules>::Cast(newObject);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? InitializePluralRules(pluralRules, locales, options).
JSHandle<JSPluralRules> pluralRules = JSHandle<JSPluralRules>::Cast(newObject); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// 3. Return ? InitializePluralRules(pluralRules, locales, options). JSPluralRules::InitializePluralRules(thread, pluralRules, locales, options);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSPluralRules::InitializePluralRules(thread, pluralRules, locales, options); return pluralRules.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return pluralRules.GetTaggedValue(); JSTaggedValue BuiltinsPluralRules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
JSTaggedValue BuiltinsPluralRules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PluralRules, SupportedLocalesOf);
{ [[maybe_unused]] EcmaHandleScope scope(thread);
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, PluralRules, SupportedLocalesOf); // 1. Let availableLocales be %PluralRules%.[[AvailableLocales]].
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<TaggedArray> availableLocales = JSPluralRules::GetAvailableLocales(thread);
// 1. Let availableLocales be %PluralRules%.[[AvailableLocales]]. // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
JSHandle<TaggedArray> availableLocales = JSPluralRules::GetAvailableLocales(thread); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); return result.GetTaggedValue();
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
return result.GetTaggedValue(); JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PluralRules, Select);
{ [[maybe_unused]] EcmaHandleScope scope(thread);
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, PluralRules, Select); // 1. Let pr be the this value.
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let pr be the this value. // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
JSHandle<JSTaggedValue> thisValue = GetThis(argv); if (!thisValue->IsJSPluralRules()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception());
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). }
if (!thisValue->IsJSPluralRules()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception()); // 3. Let n be ? ToNumber(value).
} double x = 0.0;
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
// 3. Let n be ? ToNumber(value). JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value);
double x = 0.0; RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0); x = temp.GetNumber();
JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Return ? ResolvePlural(pr, n).
x = temp.GetNumber(); JSHandle<JSPluralRules> pluralRules = JSHandle<JSPluralRules>::Cast(thisValue);
JSHandle<EcmaString> result = JSPluralRules::ResolvePlural(thread, pluralRules, x);
// 4. Return ? ResolvePlural(pr, n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSPluralRules> pluralRules = JSHandle<JSPluralRules>::Cast(thisValue); return result.GetTaggedValue();
JSHandle<EcmaString> result = JSPluralRules::ResolvePlural(thread, pluralRules, x); }
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
return result.GetTaggedValue(); JSTaggedValue BuiltinsPluralRules::ResolvedOptions(EcmaRuntimeCallInfo *argv)
} {
JSThread *thread = argv->GetThread();
JSTaggedValue BuiltinsPluralRules::ResolvedOptions(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(thread, PluralRules, ResolvedOptions);
{ [[maybe_unused]] EcmaHandleScope scope(thread);
JSThread *thread = argv->GetThread();
BUILTINS_API_TRACE(thread, PluralRules, ResolvedOptions); // 1. Let thisValue be the this value;
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let thisValue be the this value; // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
JSHandle<JSTaggedValue> thisValue = GetThis(argv); if (!thisValue->IsJSPluralRules()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception());
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). }
if (!thisValue->IsJSPluralRules()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception()); // 3. Let options be ! ObjectCreate(%ObjectPrototype%).
} auto ecmaVm = thread->GetEcmaVM();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
// 3. Let options be ! ObjectCreate(%ObjectPrototype%). ObjectFactory *factory = ecmaVm->GetFactory();
auto ecmaVm = thread->GetEcmaVM(); JSHandle<JSFunction> ctor(env->GetObjectFunction());
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<JSFunction> ctor(env->GetObjectFunction()); // 4. Perform resolvedOptions
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); JSHandle<JSPluralRules> pluralRules = JSHandle<JSPluralRules>::Cast(thisValue);
JSPluralRules::ResolvedOptions(thread, pluralRules, options);
// 4. Perform resolvedOptions RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSPluralRules> pluralRules = JSHandle<JSPluralRules>::Cast(thisValue);
JSPluralRules::ResolvedOptions(thread, pluralRules, options); // 5. Return options.
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return options.GetTaggedValue();
}
// 5. Return options.
return options.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -14,25 +14,12 @@
*/ */
#include "ecmascript/builtins/builtins_promise.h" #include "ecmascript/builtins/builtins_promise.h"
#include "ecmascript/builtins/builtins_promise_handler.h"
#include "ecmascript/builtins/builtins_promise_job.h" #include "ecmascript/builtins/builtins_promise_job.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/jobs/micro_job_queue.h" #include "ecmascript/jobs/micro_job_queue.h"
#include "ecmascript/js_array.h" #include "ecmascript/js_array.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_iterator.h" #include "ecmascript/js_iterator.h"
#include "ecmascript/js_promise.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_thread.h"
#include "ecmascript/mem/assert_scope.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob; using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob;

View File

@ -14,17 +14,12 @@
*/ */
#include "ecmascript/builtins/builtins_promise_handler.h" #include "ecmascript/builtins/builtins_promise_handler.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/jobs/micro_job_queue.h" #include "ecmascript/jobs/micro_job_queue.h"
#include "ecmascript/js_array.h" #include "ecmascript/js_array.h"
#include "ecmascript/js_async_function.h" #include "ecmascript/js_async_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_promise.h" #include "ecmascript/js_promise.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/mem/assert_scope.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// es6 25.4.1.3.2 Promise Resolve Functions // es6 25.4.1.3.2 Promise Resolve Functions

View File

@ -15,22 +15,14 @@
#include "ecmascript/builtins/builtins_promise_job.h" #include "ecmascript/builtins/builtins_promise_job.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/jspandafile/js_pandafile_executor.h" #include "ecmascript/jspandafile/js_pandafile_executor.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h" #include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/js_promise.h" #include "ecmascript/js_promise.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/module/js_dynamic_import.h" #include "ecmascript/module/js_dynamic_import.h"
#include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/js_module_manager.h" #include "ecmascript/module/js_module_manager.h"
#include "ecmascript/module/module_path_helper.h" #include "ecmascript/module/module_path_helper.h"
#include "ecmascript/platform/file.h"
#include "ecmascript/require/js_cjs_module.h"
#include "libpandabase/macros.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
using JSRecordInfo = ecmascript::JSPandaFile::JSRecordInfo; using JSRecordInfo = ecmascript::JSPandaFile::JSRecordInfo;

View File

@ -14,13 +14,8 @@
*/ */
#include "ecmascript/builtins/builtins_proxy.h" #include "ecmascript/builtins/builtins_proxy.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/tagged_array-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// 26.2.1.1 Proxy( [ value ] ) // 26.2.1.1 Proxy( [ value ] )

View File

@ -17,7 +17,6 @@
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_object-inl.h" #include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_value-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// ecma 26.1.1 Reflect.apply (target, thisArgument, argumentsList) // ecma 26.1.1 Reflect.apply (target, thisArgument, argumentsList)

View File

@ -19,20 +19,10 @@
#include <cmath> #include <cmath>
#include "ecmascript/ecma_string-inl.h" #include "ecmascript/ecma_string-inl.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_hclass.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_regexp.h" #include "ecmascript/js_regexp.h"
#include "ecmascript/js_regexp_iterator.h" #include "ecmascript/js_regexp_iterator.h"
#include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/mem/assert_scope.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/property_detector-inl.h" #include "ecmascript/property_detector-inl.h"
#include "ecmascript/regexp/regexp_executor.h" #include "ecmascript/regexp/regexp_executor.h"

View File

@ -1,183 +1,181 @@
/* /*
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ecmascript/builtins/builtins_relative_time_format.h" #include "ecmascript/builtins/builtins_relative_time_format.h"
#include "ecmascript/intl/locale_helper.h" namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRuntimeCallInfo *argv)
namespace panda::ecmascript::builtins { {
JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, RelativeTimeFormat, Constructor);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, RelativeTimeFormat, Constructor); EcmaVM *ecmaVm = thread->GetEcmaVM();
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
EcmaVM *ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
ObjectFactory *factory = ecmaVm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception.
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
// 1. If NewTarget is undefined, throw a TypeError exception. if (newTarget->IsUndefined()) {
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
if (newTarget->IsUndefined()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
} // 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor
// (NewTarget, "%RelativeTimeFormatPrototype%", « [[InitializedRelativeTimeFormat]],
// 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor // [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »).
// (NewTarget, "%RelativeTimeFormatPrototype%", « [[InitializedRelativeTimeFormat]], JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
// [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(newObject);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(newObject); // 3. Perform ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
// 3. Perform ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options). JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relativeTimeFormat, locales, options);
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relativeTimeFormat, locales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Intl.RelativeTimeFormat.prototype[ @@toStringTag ]
// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
// 4. Intl.RelativeTimeFormat.prototype[ @@toStringTag ] JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetRelativeTimeFormatFunction());
JSHandle<JSTaggedValue> thisValue = GetThis(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetRelativeTimeFormatFunction()); if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PropertyDescriptor descriptor(thread, JSHandle<JSTaggedValue>::Cast(relativeTimeFormat), false, false, true);
if (newTarget->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { JSHandle<JSTaggedValue> key(thread, JSHandle<JSIntl>::Cast(env->GetIntlFunction())->GetFallbackSymbol());
PropertyDescriptor descriptor(thread, JSHandle<JSTaggedValue>::Cast(relativeTimeFormat), false, false, true); JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor);
JSHandle<JSTaggedValue> key(thread, JSHandle<JSIntl>::Cast(env->GetIntlFunction())->GetFallbackSymbol()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); return thisValue.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return thisValue.GetTaggedValue();
} return relativeTimeFormat.GetTaggedValue();
}
return relativeTimeFormat.GetTaggedValue();
} JSTaggedValue BuiltinsRelativeTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsRelativeTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, RelativeTimeFormat, SupportedLocalesOf);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, RelativeTimeFormat, SupportedLocalesOf);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %RelativeTimeFormat%.[[AvailableLocales]].
std::vector<std::string> availableStringLocales =
// 1. Let availableLocales be %RelativeTimeFormat%.[[AvailableLocales]]. intl::LocaleHelper::GetAvailableLocales(thread, "calendar", nullptr);
std::vector<std::string> availableStringLocales = JSHandle<TaggedArray> availableLocales = JSLocale::ConstructLocaleList(thread, availableStringLocales);
intl::LocaleHelper::GetAvailableLocales(thread, "calendar", nullptr);
JSHandle<TaggedArray> availableLocales = JSLocale::ConstructLocaleList(thread, availableStringLocales); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, RelativeTimeFormat, Format);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, RelativeTimeFormat, Format);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let relativeTimeFormat be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
if (!thisValue->IsJSRelativeTimeFormat()) {
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception());
if (!thisValue->IsJSRelativeTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception());
} // 3. Let value be ? ToNumber(value).
double x = 0.0;
// 3. Let value be ? ToNumber(value). JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
double x = 0.0; JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value); x = temp.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
x = temp.GetNumber(); // 4. Let unit be ? ToString(unit).
JSHandle<JSTaggedValue> unitValue = GetCallArg(argv, 1);
// 4. Let unit be ? ToString(unit). JSHandle<EcmaString> unit = JSTaggedValue::ToString(thread, unitValue);
JSHandle<JSTaggedValue> unitValue = GetCallArg(argv, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> unit = JSTaggedValue::ToString(thread, unitValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit).
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(thisValue);
// 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit). JSHandle<EcmaString> result = JSRelativeTimeFormat::Format(thread, x, unit, relativeTimeFormat);
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> result = JSRelativeTimeFormat::Format(thread, x, unit, relativeTimeFormat); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, RelativeTimeFormat, FormatToParts);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, RelativeTimeFormat, FormatToParts);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let relativeTimeFormat be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
if (!thisValue->IsJSRelativeTimeFormat()) {
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception());
if (!thisValue->IsJSRelativeTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception());
} // 3. Let value be ? ToNumber(value).
double x = 0.0;
// 3. Let value be ? ToNumber(value). JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
double x = 0.0; JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value);
JSHandle<JSTaggedValue> value = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value); x = temp.GetNumber();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
x = temp.GetNumber(); // 4. Let unit be ? ToString(unit).
JSHandle<JSTaggedValue> unitValue = GetCallArg(argv, 1);
// 4. Let unit be ? ToString(unit). JSHandle<EcmaString> unit = JSTaggedValue::ToString(thread, unitValue);
JSHandle<JSTaggedValue> unitValue = GetCallArg(argv, 1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<EcmaString> unit = JSTaggedValue::ToString(thread, unitValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit).
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(thisValue);
// 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit). JSHandle<JSArray> result = JSRelativeTimeFormat::FormatToParts(thread, x, unit, relativeTimeFormat);
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSArray> result = JSRelativeTimeFormat::FormatToParts(thread, x, unit, relativeTimeFormat); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
return result.GetTaggedValue();
} JSTaggedValue BuiltinsRelativeTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv)
{
JSTaggedValue BuiltinsRelativeTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread();
{ BUILTINS_API_TRACE(thread, RelativeTimeFormat, ResolvedOptions);
JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread);
BUILTINS_API_TRACE(thread, RelativeTimeFormat, ResolvedOptions);
[[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv);
// 1. Let relativeTimeFormat be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
if (!thisValue->IsJSRelativeTimeFormat()) {
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception());
if (!thisValue->IsJSRelativeTimeFormat()) { }
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception());
} // 3. Let options be ! ObjectCreate(%ObjectPrototype%).
auto ecmaVm = thread->GetEcmaVM();
// 3. Let options be ! ObjectCreate(%ObjectPrototype%). JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
auto ecmaVm = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVm->GetFactory();
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); JSHandle<JSFunction> ctor(env->GetObjectFunction());
ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
JSHandle<JSFunction> ctor(env->GetObjectFunction());
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); // 4. perform resolvedOptions
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(thisValue);
// 4. perform resolvedOptions JSRelativeTimeFormat::ResolvedOptions(thread, relativeTimeFormat, options);
JSHandle<JSRelativeTimeFormat> relativeTimeFormat = JSHandle<JSRelativeTimeFormat>::Cast(thisValue); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSRelativeTimeFormat::ResolvedOptions(thread, relativeTimeFormat, options); // 5. Return options.
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return options.GetTaggedValue();
// 5. Return options. }
return options.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -1,46 +1,39 @@
/* /*
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "builtins_segment_iterator.h" #include "builtins_segment_iterator.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/js_segment_iterator.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_intl.h" // %SegmentIteratorPrototype%.next ( )
#include "ecmascript/js_locale.h" JSTaggedValue BuiltinsSegmentIterator::Next(EcmaRuntimeCallInfo *argv)
#include "ecmascript/js_object.h" {
#include "ecmascript/js_segment_iterator.h" JSThread *thread = argv->GetThread();
#include "ecmascript/object_factory.h" BUILTINS_API_TRACE(thread, SegmentIterator, Next);
[[maybe_unused]] EcmaHandleScope scope(thread);
namespace panda::ecmascript::builtins {
// %SegmentIteratorPrototype%.next ( ) // 1. Let iterator be the this value.
JSTaggedValue BuiltinsSegmentIterator::Next(EcmaRuntimeCallInfo *argv) JSHandle<JSTaggedValue> thisValue = GetThis(argv);
{
JSThread *thread = argv->GetThread(); // 2. Perform ? RequireInternalSlot(iterator, [[IteratingSegmenter]]).
BUILTINS_API_TRACE(thread, SegmentIterator, Next); if (!thisValue->IsJSSegmentIterator()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not SegmentIterator object", JSTaggedValue::Exception());
}
// 1. Let iterator be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); JSHandle<JSSegmentIterator> iterator = JSHandle<JSSegmentIterator>::Cast(thisValue);
return JSSegmentIterator::Next(thread, iterator);
// 2. Perform ? RequireInternalSlot(iterator, [[IteratingSegmenter]]). }
if (!thisValue->IsJSSegmentIterator()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not SegmentIterator object", JSTaggedValue::Exception());
}
JSHandle<JSSegmentIterator> iterator = JSHandle<JSSegmentIterator>::Cast(thisValue);
return JSSegmentIterator::Next(thread, iterator);
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -1,135 +1,128 @@
/* /*
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "builtins_segmenter.h" #include "builtins_segmenter.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/js_segments.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_intl.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_locale.h" // 18.1.1 Intl.Segmenter ( [ locales [ , options ] ] )
#include "ecmascript/js_object.h" JSTaggedValue BuiltinsSegmenter::SegmenterConstructor(EcmaRuntimeCallInfo *argv)
#include "ecmascript/js_segmenter.h" {
#include "ecmascript/js_segments.h" JSThread *thread = argv->GetThread();
#include "ecmascript/object_factory.h" BUILTINS_API_TRACE(thread, Segmenter, Constructor);
[[maybe_unused]] EcmaHandleScope scope(thread);
namespace panda::ecmascript::builtins { EcmaVM *ecmaVm = thread->GetEcmaVM();
// 18.1.1 Intl.Segmenter ( [ locales [ , options ] ] ) ObjectFactory *factory = ecmaVm->GetFactory();
JSTaggedValue BuiltinsSegmenter::SegmenterConstructor(EcmaRuntimeCallInfo *argv)
{ // 1. If NewTarget is undefined, throw a TypeError exception.
JSThread *thread = argv->GetThread(); JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
BUILTINS_API_TRACE(thread, Segmenter, Constructor); if (newTarget->IsUndefined()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception());
EcmaVM *ecmaVm = thread->GetEcmaVM(); }
ObjectFactory *factory = ecmaVm->GetFactory();
// 2. Let internalSlotsList be « [[InitializedSegmenter]], [[Locale]], [[SegmenterGranularity]] ».
// 1. If NewTarget is undefined, throw a TypeError exception. // 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv); JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
if (newTarget->IsUndefined()) { JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
} JSHandle<JSSegmenter> segmenter = JSHandle<JSSegmenter>::Cast(newObject);
// 2. Let internalSlotsList be « [[InitializedSegmenter]], [[Locale]], [[SegmenterGranularity]] ». // 3. Perform ? InitializeSegmenter(segmenter, locales, options).
// 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList). JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
JSHandle<JSTaggedValue> constructor = GetConstructor(argv); JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
JSHandle<JSObject> newObject = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget); JSSegmenter::InitializeSegmenter(thread, segmenter, locales, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSSegmenter> segmenter = JSHandle<JSSegmenter>::Cast(newObject); return segmenter.GetTaggedValue();
}
// 3. Perform ? InitializeSegmenter(segmenter, locales, options).
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); // 18.2.2 Intl.Segmenter.supportedLocalesOf ( locales [ , options ] )
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); JSTaggedValue BuiltinsSegmenter::SupportedLocalesOf(EcmaRuntimeCallInfo *argv)
JSSegmenter::InitializeSegmenter(thread, segmenter, locales, options); {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSThread *thread = argv->GetThread();
return segmenter.GetTaggedValue(); BUILTINS_API_TRACE(thread, Segmenter, SupportedLocalesOf);
} [[maybe_unused]] EcmaHandleScope scope(thread);
// 18.2.2 Intl.Segmenter.supportedLocalesOf ( locales [ , options ] ) // 1. Let availableLocales be %Segmenter%.[[AvailableLocales]].
JSTaggedValue BuiltinsSegmenter::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSHandle<TaggedArray> availableLocales = JSSegmenter::GetAvailableLocales(thread);
{
JSThread *thread = argv->GetThread(); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
BUILTINS_API_TRACE(thread, Segmenter, SupportedLocalesOf); JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0);
[[maybe_unused]] EcmaHandleScope scope(thread); JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 1. Let availableLocales be %Segmenter%.[[AvailableLocales]].
JSHandle<TaggedArray> availableLocales = JSSegmenter::GetAvailableLocales(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1);
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options);
JSHandle<JSTaggedValue> locales = GetCallArg(argv, 0); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<TaggedArray> requestedLocales = intl::LocaleHelper::CanonicalizeLocaleList(thread, locales); return result.GetTaggedValue();
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); }
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). // 18.3.3 Intl.Segmenter.prototype.segment ( string )
JSHandle<JSTaggedValue> options = GetCallArg(argv, 1); JSTaggedValue BuiltinsSegmenter::Segment(EcmaRuntimeCallInfo *argv)
JSHandle<JSArray> result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); {
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSThread *thread = argv->GetThread();
return result.GetTaggedValue(); BUILTINS_API_TRACE(thread, Segmenter, Segment);
} [[maybe_unused]] EcmaHandleScope scope(thread);
// 18.3.3 Intl.Segmenter.prototype.segment ( string ) // 1. Let segmenter be the this value.
JSTaggedValue BuiltinsSegmenter::Segment(EcmaRuntimeCallInfo *argv) JSHandle<JSTaggedValue> thisValue = GetThis(argv);
{
JSThread *thread = argv->GetThread(); // 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
BUILTINS_API_TRACE(thread, Segmenter, Segment); if (!thisValue->IsJSSegmenter()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not segmenter object", JSTaggedValue::Exception());
}
// 1. Let segmenter be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 3. Let string be ? ToString(string).
JSHandle<JSTaggedValue> stringValue = GetCallArg(argv, 0);
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]). JSHandle<EcmaString> string = JSTaggedValue::ToString(thread, stringValue);
if (!thisValue->IsJSSegmenter()) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not segmenter object", JSTaggedValue::Exception()); // 4. Return ! CreateSegmentsObject(segmenter, string).
} JSHandle<JSSegments> segments =
JSSegments::CreateSegmentsObject(thread, JSHandle<JSSegmenter>::Cast(thisValue), string);
// 3. Let string be ? ToString(string). return segments.GetTaggedValue();
JSHandle<JSTaggedValue> stringValue = GetCallArg(argv, 0); }
JSHandle<EcmaString> string = JSTaggedValue::ToString(thread, stringValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( )
// 4. Return ! CreateSegmentsObject(segmenter, string). JSTaggedValue BuiltinsSegmenter::ResolvedOptions(EcmaRuntimeCallInfo *argv)
JSHandle<JSSegments> segments = {
JSSegments::CreateSegmentsObject(thread, JSHandle<JSSegmenter>::Cast(thisValue), string); JSThread *thread = argv->GetThread();
return segments.GetTaggedValue(); BUILTINS_API_TRACE(thread, Segmenter, ResolvedOptions);
} [[maybe_unused]] EcmaHandleScope scope(thread);
// 18.3.4 Intl.Segmenter.prototype.resolvedOptions ( ) // 1. Let segmenter be the this value.
JSTaggedValue BuiltinsSegmenter::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSHandle<JSTaggedValue> thisValue = GetThis(argv);
{
JSThread *thread = argv->GetThread(); // 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
BUILTINS_API_TRACE(thread, Segmenter, ResolvedOptions); if (!thisValue->IsJSSegmenter()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not segmenter object", JSTaggedValue::Exception());
}
// 1. Let segmenter be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto ecmaVm = thread->GetEcmaVM();
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]). JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
if (!thisValue->IsJSSegmenter()) { ObjectFactory *factory = ecmaVm->GetFactory();
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not segmenter object", JSTaggedValue::Exception()); JSHandle<JSFunction> ctor(env->GetObjectFunction());
} JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%). // 4. perform resolvedOptions
auto ecmaVm = thread->GetEcmaVM(); JSHandle<JSSegmenter> segmenter = JSHandle<JSSegmenter>::Cast(thisValue);
JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv(); JSSegmenter::ResolvedOptions(thread, segmenter, options);
ObjectFactory *factory = ecmaVm->GetFactory(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSFunction> ctor(env->GetObjectFunction()); // 5. Return options.
JSHandle<JSObject> options(factory->NewJSObjectByConstructor(ctor)); return options.GetTaggedValue();
}
// 4. perform resolvedOptions
JSHandle<JSSegmenter> segmenter = JSHandle<JSSegmenter>::Cast(thisValue);
JSSegmenter::ResolvedOptions(thread, segmenter, options);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 5. Return options.
return options.GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -1,73 +1,66 @@
/* /*
* Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd. * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "builtins_segments.h" #include "builtins_segments.h"
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/js_segment_iterator.h"
#include "ecmascript/ecma_vm.h" #include "ecmascript/js_segments.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_intl.h" namespace panda::ecmascript::builtins {
#include "ecmascript/js_locale.h" // %SegmentsPrototype%.containing ( index )
#include "ecmascript/js_object.h" JSTaggedValue BuiltinsSegments::Containing(EcmaRuntimeCallInfo *argv)
#include "ecmascript/js_segment_iterator.h" {
#include "ecmascript/js_segments.h" JSThread *thread = argv->GetThread();
#include "ecmascript/object_factory.h" BUILTINS_API_TRACE(thread, Segments, Containing);
[[maybe_unused]] EcmaHandleScope scope(thread);
namespace panda::ecmascript::builtins {
// %SegmentsPrototype%.containing ( index ) // 1. Let segments be the this value.
JSTaggedValue BuiltinsSegments::Containing(EcmaRuntimeCallInfo *argv) JSHandle<JSTaggedValue> thisValue = GetThis(argv);
{
JSThread *thread = argv->GetThread(); // 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
BUILTINS_API_TRACE(thread, Segments, Containing); if (!thisValue->IsJSSegments()) {
[[maybe_unused]] EcmaHandleScope scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Segments object", JSTaggedValue::Exception());
}
// 1. Let segments be the this value.
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 6. Let n be ? ToIntegerOrInfinity(index).
JSHandle<JSTaggedValue> indexTag = GetCallArg(argv, 0);
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]). JSTaggedNumber indexVal = JSTaggedValue::ToInteger(thread, indexTag);
if (!thisValue->IsJSSegments()) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Segments object", JSTaggedValue::Exception()); JSHandle<JSSegments> segments = JSHandle<JSSegments>::Cast(thisValue);
} return JSSegments::Containing(thread, segments, indexVal.GetNumber());
}
// 6. Let n be ? ToIntegerOrInfinity(index).
JSHandle<JSTaggedValue> indexTag = GetCallArg(argv, 0); // %SegmentsPrototype% [ @@iterator ] ( )
JSTaggedNumber indexVal = JSTaggedValue::ToInteger(thread, indexTag); JSTaggedValue BuiltinsSegments::GetSegmentIterator(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); {
JSHandle<JSSegments> segments = JSHandle<JSSegments>::Cast(thisValue); JSThread *thread = argv->GetThread();
return JSSegments::Containing(thread, segments, indexVal.GetNumber()); BUILTINS_API_TRACE(thread, Segments, GetSegmentIterator);
} [[maybe_unused]] EcmaHandleScope handleScope(thread);
// 1. Let segments be the this value.
// %SegmentsPrototype% [ @@iterator ] ( ) JSHandle<JSTaggedValue> thisValue = GetThis(argv);
JSTaggedValue BuiltinsSegments::GetSegmentIterator(EcmaRuntimeCallInfo *argv)
{ // 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
JSThread *thread = argv->GetThread(); if (!thisValue->IsJSSegments()) {
BUILTINS_API_TRACE(thread, Segments, GetSegmentIterator); THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Segments object", JSTaggedValue::Exception());
[[maybe_unused]] EcmaHandleScope handleScope(thread); }
// 1. Let segments be the this value. JSHandle<JSSegments> segments = JSHandle<JSSegments>::Cast(thisValue);
JSHandle<JSTaggedValue> thisValue = GetThis(argv); // 3. Let segmenter be segments.[[SegmentsSegmenter]].
// 4. Let string be segments.[[SegmentsString]].
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]). JSHandle<EcmaString> string(thread, segments->GetSegmentsString());
if (!thisValue->IsJSSegments()) { // 5. Return ! CreateSegmentIterator(segmenter, string).
THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Segments object", JSTaggedValue::Exception()); return JSSegmentIterator::CreateSegmentIterator(thread, segments->GetIcuBreakIterator(), string,
} segments->GetGranularity()).GetTaggedValue();
JSHandle<JSSegments> segments = JSHandle<JSSegments>::Cast(thisValue); }
// 3. Let segmenter be segments.[[SegmentsSegmenter]].
// 4. Let string be segments.[[SegmentsString]].
JSHandle<EcmaString> string(thread, segments->GetSegmentsString());
// 5. Return ! CreateSegmentIterator(segmenter, string).
return JSSegmentIterator::CreateSegmentIterator(thread, segments->GetIcuBreakIterator(), string,
segments->GetGranularity()).GetTaggedValue();
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -17,27 +17,11 @@
#include <typeinfo> #include <typeinfo>
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/builtins/builtins_bigint.h"
#include "ecmascript/containers/containers_errors.h" #include "ecmascript/containers/containers_errors.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_arraybuffer.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/mem/heap.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/shared_objects/js_sendable_arraybuffer.h" #include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
#include "ecmascript/base/typed_array_helper-inl.h" #include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "securec.h"
#include "cstdio" #include "cstdio"
#include "cstring" #include "cstring"

View File

@ -14,17 +14,11 @@
*/ */
#include "builtins_set.h" #include "builtins_set.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_set.h" #include "ecmascript/js_set.h"
#include "ecmascript/js_set_iterator.h" #include "ecmascript/js_set_iterator.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/tagged_array-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv)
{ {

View File

@ -17,35 +17,12 @@
#include <cmath> #include <cmath>
#include "ecmascript/base/array_helper.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "ecmascript/builtins/builtins_array.h" #include "ecmascript/builtins/builtins_array.h"
#include "ecmascript/builtins/builtins_string.h" #include "ecmascript/builtins/builtins_string.h"
#include "ecmascript/containers/containers_errors.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_string.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_hclass.h"
#include "ecmascript/js_map_iterator.h" #include "ecmascript/js_map_iterator.h"
#include "ecmascript/js_object.h"
#include "ecmascript/js_stable_array.h" #include "ecmascript/js_stable_array.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/mem/tagged_object.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/shared_objects/concurrent_api_scope.h"
#include "ecmascript/shared_objects/js_shared_array.h"
#include "ecmascript/shared_objects/js_shared_array_iterator.h"
#include "ecmascript/tagged_array-inl.h"
#include "jsnapi_expo.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
namespace { namespace {

View File

@ -15,8 +15,6 @@
#include "ecmascript/builtins/builtins_shared_async_function.h" #include "ecmascript/builtins/builtins_shared_async_function.h"
#include "ecmascript/ecma_macros.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// ecma2017 25.5.1.1 AsyncFunction (p1, p2, ... , pn, body) // ecma2017 25.5.1.1 AsyncFunction (p1, p2, ... , pn, body)
JSTaggedValue BuiltinsSharedAsyncFunction::SharedAsyncFunctionConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsSharedAsyncFunction::SharedAsyncFunctionConstructor(EcmaRuntimeCallInfo *argv)

View File

@ -15,12 +15,9 @@
#include "ecmascript/builtins/builtins_shared_map.h" #include "ecmascript/builtins/builtins_shared_map.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/shared_objects/concurrent_api_scope.h" #include "ecmascript/shared_objects/concurrent_api_scope.h"
#include "ecmascript/shared_objects/js_shared_map.h" #include "ecmascript/shared_objects/js_shared_map.h"
#include "ecmascript/shared_objects/js_shared_map_iterator.h" #include "ecmascript/shared_objects/js_shared_map_iterator.h"

View File

@ -15,8 +15,6 @@
#include "ecmascript/builtins/builtins_shared_object.h" #include "ecmascript/builtins/builtins_shared_object.h"
#include "ecmascript/ecma_vm.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsSharedObject::SharedObjectConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsSharedObject::SharedObjectConstructor(EcmaRuntimeCallInfo *argv)
{ {

View File

@ -15,17 +15,12 @@
#include "ecmascript/builtins/builtins_shared_set.h" #include "ecmascript/builtins/builtins_shared_set.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/shared_objects/concurrent_api_scope.h" #include "ecmascript/shared_objects/concurrent_api_scope.h"
#include "ecmascript/shared_objects/js_shared_set.h"
#include "ecmascript/shared_objects/js_shared_set_iterator.h" #include "ecmascript/shared_objects/js_shared_set_iterator.h"
#include "ecmascript/tagged_array-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsSharedSet::Constructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsSharedSet::Constructor(EcmaRuntimeCallInfo *argv)

View File

@ -17,27 +17,12 @@
#include <cmath> #include <cmath>
#include "ecmascript/base/typed_array_helper-inl.h" #include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "ecmascript/builtins/builtins_array.h" #include "ecmascript/builtins/builtins_array.h"
#include "ecmascript/builtins/builtins_arraybuffer.h"
#include "ecmascript/builtins/builtins_sendable_arraybuffer.h"
#include "ecmascript/containers/containers_errors.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_string-inl.h" #include "ecmascript/ecma_string-inl.h"
#include "ecmascript/element_accessor-inl.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_array_iterator.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_iterator.h"
#include "ecmascript/js_stable_array.h" #include "ecmascript/js_stable_array.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/shared_objects/js_shared_typed_array.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
using TypedArrayHelper = base::TypedArrayHelper; using TypedArrayHelper = base::TypedArrayHelper;

View File

@ -15,19 +15,10 @@
#include "ecmascript/builtins/builtins_sharedarraybuffer.h" #include "ecmascript/builtins/builtins_sharedarraybuffer.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_arraybuffer.h" #include "ecmascript/js_arraybuffer.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory.h"
#include "securec.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
// 25.2.2.1 SharedArrayBuffer ( [ length ] ) // 25.2.2.1 SharedArrayBuffer ( [ length ] )

View File

@ -20,33 +20,14 @@
#include <map> #include <map>
#include "ecmascript/intl/locale_helper.h" #include "ecmascript/intl/locale_helper.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/builtins/builtins_json.h"
#include "ecmascript/builtins/builtins_number.h" #include "ecmascript/builtins/builtins_number.h"
#include "ecmascript/builtins/builtins_regexp.h" #include "ecmascript/builtins/builtins_regexp.h"
#include "ecmascript/builtins/builtins_symbol.h" #include "ecmascript/builtins/builtins_symbol.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_string-inl.h"
#include "ecmascript/ecma_context.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/fast_runtime_stub-inl.h" #include "ecmascript/interpreter/fast_runtime_stub-inl.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_hclass.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_regexp.h" #include "ecmascript/js_regexp.h"
#include "ecmascript/js_string_iterator.h" #include "ecmascript/js_string_iterator.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/property_detector-inl.h" #include "ecmascript/property_detector-inl.h"
#include "ecmascript/shared_objects/js_shared_array.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/tagged_array.h"
#ifdef ARK_SUPPORT_INTL #ifdef ARK_SUPPORT_INTL
#include "ecmascript/js_collator.h" #include "ecmascript/js_collator.h"
#include "ecmascript/js_locale.h" #include "ecmascript/js_locale.h"

View File

@ -14,16 +14,9 @@
*/ */
#include "ecmascript/builtins/builtins_string_iterator.h" #include "ecmascript/builtins/builtins_string_iterator.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_string_table.h" #include "ecmascript/ecma_string_table.h"
#include "ecmascript/js_iterator.h" #include "ecmascript/js_iterator.h"
#include "ecmascript/js_string_iterator.h" #include "ecmascript/js_string_iterator.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/tagged_array-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv)

View File

@ -15,13 +15,8 @@
#include "ecmascript/builtins/builtins_symbol.h" #include "ecmascript/builtins/builtins_symbol.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_string.h"
#include "ecmascript/global_env.h" #include "ecmascript/global_env.h"
#include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_primitive_ref.h"
#include "ecmascript/js_symbol.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/symbol_table.h" #include "ecmascript/symbol_table.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -16,24 +16,10 @@
#include "ecmascript/builtins/builtins_typedarray.h" #include "ecmascript/builtins/builtins_typedarray.h"
#include <cmath> #include <cmath>
#include "ecmascript/base/typed_array_helper-inl.h" #include "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "ecmascript/builtins/builtins_array.h" #include "ecmascript/builtins/builtins_array.h"
#include "ecmascript/builtins/builtins_arraybuffer.h"
#include "ecmascript/ecma_runtime_call_info.h"
#include "ecmascript/ecma_string-inl.h" #include "ecmascript/ecma_string-inl.h"
#include "ecmascript/element_accessor-inl.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_array_iterator.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_iterator.h"
#include "ecmascript/js_stable_array.h" #include "ecmascript/js_stable_array.h"
#include "ecmascript/js_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_typed_array.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h" #include "ecmascript/object_fast_operator-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {

View File

@ -16,15 +16,9 @@
#include "ecmascript/builtins/builtins_weak_map.h" #include "ecmascript/builtins/builtins_weak_map.h"
#include "ecmascript/builtins/builtins_map.h" #include "ecmascript/builtins/builtins_map.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_map_iterator.h"
#include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_weak_container.h" #include "ecmascript/js_weak_container.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv)
{ {

View File

@ -14,10 +14,7 @@
*/ */
#include "ecmascript/builtins/builtins_weak_ref.h" #include "ecmascript/builtins/builtins_weak_ref.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/js_weak_ref.h" #include "ecmascript/js_weak_ref.h"
#include "ecmascript/object_factory-inl.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsWeakRef::WeakRefConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsWeakRef::WeakRefConstructor(EcmaRuntimeCallInfo *argv)

View File

@ -14,16 +14,11 @@
*/ */
#include "ecmascript/builtins/builtins_weak_set.h" #include "ecmascript/builtins/builtins_weak_set.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h" #include "ecmascript/js_function.h"
#include "ecmascript/js_set_iterator.h" #include "ecmascript/js_set_iterator.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_weak_container.h" #include "ecmascript/js_weak_container.h"
#include "ecmascript/linked_hash_table.h" #include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins { namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv)

View File

@ -28,14 +28,10 @@
#include "ecmascript/shared_objects/js_shared_array.h" #include "ecmascript/shared_objects/js_shared_array.h"
#include "ecmascript/shared_objects/js_sendable_arraybuffer.h" #include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
#include "ecmascript/shared_objects/js_shared_map.h" #include "ecmascript/shared_objects/js_shared_map.h"
#include "ecmascript/shared_objects/js_shared_object.h"
#include "ecmascript/shared_objects/js_shared_set.h" #include "ecmascript/shared_objects/js_shared_set.h"
#include "ecmascript/shared_objects/js_shared_typed_array.h" #include "ecmascript/shared_objects/js_shared_typed_array.h"
#include "ecmascript/js_async_function.h" #include "ecmascript/js_async_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_object-inl.h" #include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/layout_info.h"
#include "ecmascript/symbol_table.h" #include "ecmascript/symbol_table.h"
#include "ecmascript/builtins/builtins_shared_array.h" #include "ecmascript/builtins/builtins_shared_array.h"