!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/base/error_type.h"
#include "ecmascript/base/number_helper.h"
#include "ecmascript/builtins/builtins_ark_tools.h"
#include "ecmascript/builtins/builtins_array.h"
#include "ecmascript/builtins/builtins_arraybuffer.h"
@ -50,11 +48,9 @@
#include "ecmascript/builtins/builtins_proxy.h"
#include "ecmascript/builtins/builtins_reflect.h"
#include "ecmascript/builtins/builtins_regexp.h"
#include "ecmascript/builtins/builtins_regexp-inl.h"
#include "ecmascript/builtins/builtins_set.h"
#include "ecmascript/builtins/builtins_sharedarraybuffer.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_symbol.h"
#include "ecmascript/builtins/builtins_typedarray.h"
@ -63,48 +59,28 @@
#include "ecmascript/builtins/builtins_weak_set.h"
#include "ecmascript/containers/containers_private.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_array_iterator.h"
#include "ecmascript/js_async_function.h"
#include "ecmascript/js_async_generator_object.h"
#include "ecmascript/js_dataview.h"
#include "ecmascript/js_for_in_iterator.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_iterator.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_runtime_options.h"
#include "ecmascript/js_set.h"
#include "ecmascript/js_set_iterator.h"
#include "ecmascript/js_string_iterator.h"
#include "ecmascript/js_symbol.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_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_require.h"
#include "ecmascript/require/js_cjs_exports.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_set_iterator.h"
#include "ecmascript/symbol_table.h"
#include "ecmascript/marker_cell.h"
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/runtime.h"
#ifdef ARK_SUPPORT_INTL
#include "ecmascript/builtins/builtins_collator.h"
@ -123,11 +99,8 @@
#include "ecmascript/js_date_time_format.h"
#include "ecmascript/js_displaynames.h"
#include "ecmascript/js_list_format.h"
#include "ecmascript/js_locale.h"
#include "ecmascript/js_number_format.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_segment_iterator.h"
#endif

View File

@ -19,14 +19,6 @@
#include <sys/stat.h>
#include <fcntl.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/property_detector-inl.h"
#include "ecmascript/js_arraybuffer.h"

View File

@ -17,27 +17,11 @@
#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/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/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_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/tagged_array-inl.h"
#include "ecmascript/builtins/builtins_string.h"
namespace panda::ecmascript::builtins {

View File

@ -17,24 +17,11 @@
#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/js_arraybuffer.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 "ecmascript/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "securec.h"
#include "cstdio"
#include "cstring"

View File

@ -14,18 +14,11 @@
*/
#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/js_tagged_value.h"
#include "ecmascript/js_async_from_sync_iterator.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_iterator.h"
#include "ecmascript/js_promise.h"
#include "ecmascript/js_function.h"
namespace panda::ecmascript::builtins {

View File

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

View File

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

View File

@ -14,8 +14,6 @@
*/
#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/interpreter/interpreter.h"
#include "ecmascript/js_iterator.h"

View File

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

View File

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

View File

@ -14,10 +14,6 @@
*/
#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"
namespace panda::ecmascript::builtins {

View File

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

View File

@ -15,12 +15,8 @@
#include "ecmascript/builtins/builtins_cjs_module.h"
#include "ecmascript/base/builtins_base.h"
#include "ecmascript/interpreter/interpreter-inl.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 {

View File

@ -15,14 +15,6 @@
#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 {
JSTaggedValue BuiltinsCjsRequire::CjsRequireConstructor(EcmaRuntimeCallInfo *argv)
{

View File

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

View File

@ -14,15 +14,9 @@
*/
#include "ecmascript/builtins/builtins_dataview.h"
#include "ecmascript/base/number_helper.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_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
namespace panda::ecmascript::builtins {
// 24.2.2.1

View File

@ -15,15 +15,10 @@
#include "ecmascript/builtins/builtins_date.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.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
#include "ecmascript/js_date.h"
#include "ecmascript/js_date_time_format.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,18 +20,11 @@
#include <string>
#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/js_function.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/module_path_helper.h"
#include "ecmascript/stubs/runtime_stubs.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/containers/containers_errors.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/module/js_module_manager.h"

View File

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

View File

@ -14,10 +14,6 @@
*/
#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"
namespace panda::ecmascript::builtins {

View File

@ -15,20 +15,8 @@
#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_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 {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,20 +15,8 @@
#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_handle.h"
#include "ecmascript/js_hclass.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
#include "ecmascript/js_number_format.h"
#else

View File

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

View File

@ -16,17 +16,8 @@
#include "ecmascript/builtins/builtins_object.h"
#include "ecmascript/builtins/builtins_map.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_object.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"
namespace panda::ecmascript::builtins {

View File

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

View File

@ -14,25 +14,12 @@
*/
#include "ecmascript/builtins/builtins_promise.h"
#include "ecmascript/builtins/builtins_promise_handler.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/interpreter/interpreter.h"
#include "ecmascript/jobs/micro_job_queue.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_function.h"
#include "ecmascript/js_handle.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 {
using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob;

View File

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

View File

@ -15,22 +15,14 @@
#include "ecmascript/builtins/builtins_promise_job.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/global_env.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_manager.h"
#include "ecmascript/js_promise.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/module/js_dynamic_import.h"
#include "ecmascript/module/js_module_deregister.h"
#include "ecmascript/module/js_module_manager.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 {
using JSRecordInfo = ecmascript::JSPandaFile::JSRecordInfo;

View File

@ -14,13 +14,8 @@
*/
#include "ecmascript/builtins/builtins_proxy.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.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 {
// 26.2.1.1 Proxy( [ value ] )

View File

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

View File

@ -19,20 +19,10 @@
#include <cmath>
#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/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_iterator.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/property_detector-inl.h"
#include "ecmascript/regexp/regexp_executor.h"

View File

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

View File

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

View File

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

View File

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

View File

@ -17,27 +17,11 @@
#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/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_arraybuffer.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/base/typed_array_helper-inl.h"
#include "ecmascript/base/typed_array_helper.h"
#include "securec.h"
#include "cstdio"
#include "cstring"

View File

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

View File

@ -17,35 +17,12 @@
#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_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/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_object.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/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 {

View File

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

View File

@ -15,12 +15,9 @@
#include "ecmascript/builtins/builtins_shared_map.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_function.h"
#include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/shared_objects/concurrent_api_scope.h"
#include "ecmascript/shared_objects/js_shared_map.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/ecma_vm.h"
namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsSharedObject::SharedObjectConstructor(EcmaRuntimeCallInfo *argv)
{

View File

@ -15,17 +15,12 @@
#include "ecmascript/builtins/builtins_shared_set.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/js_function.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.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/tagged_array-inl.h"
namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsSharedSet::Constructor(EcmaRuntimeCallInfo *argv)

View File

@ -17,27 +17,12 @@
#include <cmath>
#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_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/element_accessor-inl.h"
#include "ecmascript/global_env.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_tagged_number.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/object_fast_operator-inl.h"
#include "ecmascript/shared_objects/js_shared_typed_array.h"
namespace panda::ecmascript::builtins {
using TypedArrayHelper = base::TypedArrayHelper;

View File

@ -15,19 +15,10 @@
#include "ecmascript/builtins/builtins_sharedarraybuffer.h"
#include "ecmascript/ecma_macros.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_arraybuffer.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 {
// 25.2.2.1 SharedArrayBuffer ( [ length ] )

View File

@ -20,33 +20,14 @@
#include <map>
#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_regexp.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/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_regexp.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/shared_objects/js_shared_array.h"
#include "ecmascript/tagged_array-inl.h"
#include "ecmascript/tagged_array.h"
#ifdef ARK_SUPPORT_INTL
#include "ecmascript/js_collator.h"
#include "ecmascript/js_locale.h"

View File

@ -14,16 +14,9 @@
*/
#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/js_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 {
JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv)

View File

@ -15,13 +15,8 @@
#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/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"
namespace panda::ecmascript::builtins {

View File

@ -16,24 +16,10 @@
#include "ecmascript/builtins/builtins_typedarray.h"
#include <cmath>
#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_arraybuffer.h"
#include "ecmascript/ecma_runtime_call_info.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/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_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"
namespace panda::ecmascript::builtins {

View File

@ -16,15 +16,9 @@
#include "ecmascript/builtins/builtins_weak_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_weak_container.h"
#include "ecmascript/linked_hash_table.h"
#include "ecmascript/object_factory.h"
namespace panda::ecmascript::builtins {
JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv)
{

View File

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

View File

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

View File

@ -28,14 +28,10 @@
#include "ecmascript/shared_objects/js_shared_array.h"
#include "ecmascript/shared_objects/js_sendable_arraybuffer.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_typed_array.h"
#include "ecmascript/js_async_function.h"
#include "ecmascript/js_handle.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/builtins/builtins_shared_array.h"