diff --git a/BUILD.gn b/BUILD.gn index df42a4f8c19531a32e8d96bd8ed65f4f8f059a59..e68d3d57c16ccf4158b8ac61fef71b6e81bcdf63 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -134,3 +134,17 @@ ark_isa_gen("isa_gen_ecma_compiler") { sources = "$ark_root/plugins/ecmascript/compiler/templates/" destination = "$target_gen_dir/" } + +ark_gen("ecma_builtins_gen") { + data = "$ark_root/plugins/ecmascript/runtime/builtins/templates/builtins.yaml" + template_files = [ + "builtins_initializers_gen.h.erb", + "builtins_declaration_gen.h.erb", + ] + sources = "$ark_root/plugins/ecmascript/runtime/builtins/templates" + destination = "$target_gen_dir/runtime/builtins/generated" + requires = [ + "$ark_root/templates/common.rb", + "$ark_root/plugins/ecmascript/runtime/builtins/templates/builtins.rb", + ] +} diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index d866c18729dff7138bdace0b974f70c7120b86d7..e0b1d8120e4aa61549fe58334c3dcea57489dacc 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -27,6 +27,7 @@ panda_isa_gen( ) add_dependencies(arkcompiler isa_gen_${PROJECT_NAME}) +add_dependencies(arkcompiler runtime_options_gen) set(COMPILER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/optimizer/code_generator/compiler_base_types.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index be90d0c3c14d69c643a7f3dc6f4d74049ec3866d..96b140cabc29d9e462bb19877e5721c495c9ebfa 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -15,6 +15,8 @@ panda_promote_to_definitions(PANDA_ECMASCRIPT_ENABLE_RUNTIME_STAT) option(PANDA_LINK_ICU "Enable linking with icu third party library" true) +add_subdirectory(builtins) + set(ECMA_SRC_DIR ${PANDA_ECMASCRIPT_PLUGIN_SOURCE}/runtime) if(PANDA_TARGET_ARM32) diff --git a/runtime/base/builtins_base.cpp b/runtime/base/builtins_base.cpp index 3f06afaa408d160d9b021edd3e16d8372b7de566..0a32f1e3d306619e5301e42eb2404148cd807392 100644 --- a/runtime/base/builtins_base.cpp +++ b/runtime/base/builtins_base.cpp @@ -17,16 +17,16 @@ #include "plugins/ecmascript/runtime/js_tagged_value-inl.h" #include "plugins/ecmascript/runtime/tagged_array-inl.h" -namespace panda::ecmascript::base { -JSHandle BuiltinsBase::GetArgsArray(EcmaRuntimeCallInfo *msg) +namespace panda::ecmascript { +JSHandle builtins_common::GetArgsArray(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t length = msg->GetArgsNumber(); JSHandle array = factory->NewTaggedArray(length); for (uint32_t i = 0; i < length; ++i) { - array->Set(thread, i, GetCallArg(msg, i).GetTaggedValue()); + array->Set(thread, i, builtins_common::GetCallArg(msg, i).GetTaggedValue()); } return array; } -} // namespace panda::ecmascript::base +} // namespace panda::ecmascript diff --git a/runtime/base/builtins_base.h b/runtime/base/builtins_base.h index 36ac84387f2982c9a4cc15d4ea865f8d93c91206..5d825304b81b59b27d593033fc8a6dd7545410a2 100644 --- a/runtime/base/builtins_base.h +++ b/runtime/base/builtins_base.h @@ -21,6 +21,7 @@ #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env_constants-inl.h" +#include "plugins/ecmascript/runtime/js_dataview.h" #include "plugins/ecmascript/runtime/js_symbol.h" #include "plugins/ecmascript/runtime/js_tagged_value.h" #include "plugins/ecmascript/runtime/object_factory.h" @@ -29,57 +30,60 @@ #include "plugins/ecmascript/runtime/vmstat/runtime_stat.h" namespace panda::ecmascript { -class JSArray; -namespace base { -class BuiltinsBase { -public: - enum ArgsPosition : uint32_t { FIRST = 0, SECOND, THIRD, FOURTH, FIFTH }; - static JSHandle GetArgsArray(EcmaRuntimeCallInfo *msg); - static inline JSHandle GetConstructor(EcmaRuntimeCallInfo *msg) - { - return msg->GetFunction(); - } - static inline JSHandle GetThis(EcmaRuntimeCallInfo *msg) - { - return msg->GetThis(); - } +namespace builtins { +#include "plugins/ecmascript/runtime/builtins/generated/builtins_declaration_gen.h" +} // namespace builtins - static inline JSHandle GetNewTarget(EcmaRuntimeCallInfo *msg) - { - return msg->GetNewTarget(); - } +namespace builtins_common { - static inline JSHandle GetCallArg(EcmaRuntimeCallInfo *msg, uint32_t position) - { - if (position >= msg->GetArgsNumber()) { - JSThread *thread = msg->GetThread(); - return thread->GlobalConstants()->GetHandledUndefined(); - } - return msg->GetCallArg(position); - } +enum ArgsPosition : uint32_t { FIRST = 0, SECOND, THIRD, FOURTH, FIFTH }; +JSHandle GetArgsArray(EcmaRuntimeCallInfo *msg); +inline JSHandle GetConstructor(EcmaRuntimeCallInfo *msg) +{ + return msg->GetFunction(); +} - static inline JSTaggedValue GetTaggedInt(int32_t value) - { - return JSTaggedValue(value); - } +inline JSHandle GetThis(EcmaRuntimeCallInfo *msg) +{ + return msg->GetThis(); +} - static inline JSTaggedValue GetTaggedDouble(double value) - { - return JSTaggedValue(value); - } +inline JSHandle GetNewTarget(EcmaRuntimeCallInfo *msg) +{ + return msg->GetNewTarget(); +} - static inline JSTaggedValue GetTaggedBoolean(bool value) - { - return JSTaggedValue(value); +inline JSHandle GetCallArg(EcmaRuntimeCallInfo *msg, uint32_t position) +{ + if (position >= msg->GetArgsNumber()) { + JSThread *thread = msg->GetThread(); + return thread->GlobalConstants()->GetHandledUndefined(); } + return msg->GetCallArg(position); +} + +inline JSTaggedValue GetTaggedInt(int32_t value) +{ + return JSTaggedValue(value); +} + +inline JSTaggedValue GetTaggedDouble(double value) +{ + return JSTaggedValue(value); +} + +inline JSTaggedValue GetTaggedBoolean(bool value) +{ + return JSTaggedValue(value); +} + +inline JSTaggedValue GetTaggedString(JSThread *thread, const char *str) +{ + return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str).GetTaggedValue(); +} +} // namespace builtins_common - static inline JSTaggedValue GetTaggedString(JSThread *thread, const char *str) - { - return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString(str).GetTaggedValue(); - } -}; -} // namespace base } // namespace panda::ecmascript #endif // ECMASCRIPT_BASE_BUILTINS_BASE_H diff --git a/runtime/base/error_helper.cpp b/runtime/base/error_helper.cpp index dda5c028aa555dc3706a1d6dcfd3ea20d0aa1e8a..6b527bdbf6c4877a2dd186949942b2e0af33edc3 100644 --- a/runtime/base/error_helper.cpp +++ b/runtime/base/error_helper.cpp @@ -37,7 +37,7 @@ JSTaggedValue ErrorHelper::ErrorCommonToString(EcmaRuntimeCallInfo *argv, const // 1. Let O be the this value. // 2. If Type(O) is not Object, throw a TypeError exception - JSHandle this_value = BuiltinsBase::GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "ErrorToString:not an object", JSTaggedValue::Exception()); } @@ -122,12 +122,12 @@ JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. auto ecma_vm = thread->GetEcmaVM(); ObjectFactory *factory = ecma_vm->GetFactory(); - JSHandle ctor = BuiltinsBase::GetConstructor(argv); - JSMutableHandle new_target(BuiltinsBase::GetNewTarget(argv)); + JSHandle ctor = builtins_common::GetConstructor(argv); + JSMutableHandle new_target(builtins_common::GetNewTarget(argv)); if (new_target->IsUndefined()) { new_target.Update(ctor.GetTaggedValue()); } - JSHandle message = BuiltinsBase::GetCallArg(argv, 0); + JSHandle message = builtins_common::GetCallArg(argv, 0); // 2. Let O be OrdinaryCreateFromConstructor(new_target, "%ErrorPrototype%", «[[ErrorData]]»). JSHandle native_instance_obj = factory->NewJSObjectByConstructor(JSHandle(ctor), new_target); diff --git a/runtime/base/json_stringifier.cpp b/runtime/base/json_stringifier.cpp index dbfcdad99f021977d7c71a1e9b6567c88562587c..b3e2a9cbe2b1610623f2ecaeea95f7f8205ba0ce 100644 --- a/runtime/base/json_stringifier.cpp +++ b/runtime/base/json_stringifier.cpp @@ -19,7 +19,6 @@ #include #include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/number_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string-inl.h" #include "plugins/ecmascript/runtime/ecma_vm.h" diff --git a/runtime/base/number_helper.cpp b/runtime/base/number_helper.cpp index cf38bc14d6394b47a44b6ce845b795c228c4b97a..61b8cc99ed0fc8856fa7c16658cf59315b794c4b 100644 --- a/runtime/base/number_helper.cpp +++ b/runtime/base/number_helper.cpp @@ -127,7 +127,7 @@ JSTaggedValue NumberHelper::DoubleToString(JSThread *thread, double number, int result = "-" + result; } - return BuiltinsBase::GetTaggedString(thread, result.c_str()); + return builtins_common::GetTaggedString(thread, result.c_str()); } JSTaggedValue NumberHelper::DoubleToExponential(JSThread *thread, double number, int digit) @@ -157,14 +157,14 @@ JSTaggedValue NumberHelper::DoubleToExponential(JSThread *thread, double number, result.erase(found + 1, end - found - 1); } } - return BuiltinsBase::GetTaggedString(thread, result.c_str()); + return builtins_common::GetTaggedString(thread, result.c_str()); } JSTaggedValue NumberHelper::DoubleToFixed(JSThread *thread, double number, int digit) { PandaStringStream ss; ss << std::setiosflags(std::ios::fixed) << std::setprecision(digit) << number; - return BuiltinsBase::GetTaggedString(thread, ss.str().c_str()); + return builtins_common::GetTaggedString(thread, ss.str().c_str()); } JSTaggedValue NumberHelper::DoubleToPrecision(JSThread *thread, double number, int digit) @@ -186,7 +186,7 @@ JSTaggedValue NumberHelper::DoubleToPrecision(JSThread *thread, double number, i JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const uint8_t *end, int radix) { auto p = const_cast(start); - JSTaggedValue nan_result = BuiltinsBase::GetTaggedDouble(NAN_VALUE); + JSTaggedValue nan_result = builtins_common::GetTaggedDouble(NAN_VALUE); // 1. skip space and line terminal if (!NumberHelper::GotoNonspace(&p, end)) { return nan_result; @@ -261,7 +261,7 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const if (negative) { result = -result; } - return BuiltinsBase::GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } char NumberHelper::Carry(char current, int radix) diff --git a/runtime/base/object_helper.cpp b/runtime/base/object_helper.cpp index f3a8c78a1e9c4df5f7929684df6aa1d8ac905e85..0949c1681cf70592a6202f4d70b4efc6f0db7c97 100644 --- a/runtime/base/object_helper.cpp +++ b/runtime/base/object_helper.cpp @@ -17,7 +17,7 @@ JSTaggedValue ObjectHelper::CreateDataPropertyOnObject(EcmaRuntimeCallInfo *argv JSThread *thread = argv->GetThread(); // 1. Let O be the this value. - JSHandle object = BuiltinsBase::GetThis(argv); + JSHandle object = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object. ASSERT(object->IsObject()); @@ -26,13 +26,13 @@ JSTaggedValue ObjectHelper::CreateDataPropertyOnObject(EcmaRuntimeCallInfo *argv ASSERT(object->IsExtensible(thread)); // 4. Let propertyKey be ? ToPropertyKey(key). - JSHandle key = BuiltinsBase::GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle property_key = JSTaggedValue::ToPropertyKey(thread, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Perform ! CreateDataPropertyOrThrow(O, propertyKey, value). - JSHandle value = BuiltinsBase::GetCallArg(argv, 1); + JSHandle value = builtins_common::GetCallArg(argv, 1); JSObject::CreateDataPropertyOrThrow(thread, JSTaggedValue::ToObject(thread, object), property_key, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/runtime/base/typed_array_helper-inl.h b/runtime/base/typed_array_helper-inl.h index 695f02f46e55f693dd82841a0f856a0896319357..cf8224650cf0a3ee928760c004dfedffc6ef4282 100644 --- a/runtime/base/typed_array_helper-inl.h +++ b/runtime/base/typed_array_helper-inl.h @@ -16,7 +16,6 @@ #ifndef ECMASCRIPT_BASE_TYPED_ARRAY_HELPER_INL_H #define ECMASCRIPT_BASE_TYPED_ARRAY_HELPER_INL_H -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" #include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/typed_array_helper.h" #include "plugins/ecmascript/runtime/js_tagged_value.h" diff --git a/runtime/base/typed_array_helper.cpp b/runtime/base/typed_array_helper.cpp index 91e234922ca86cfd0e51c09a0dadbae2c13ba29a..de31a0797347064ee068b8b5a1397f8f301b5960 100644 --- a/runtime/base/typed_array_helper.cpp +++ b/runtime/base/typed_array_helper.cpp @@ -18,7 +18,6 @@ #include "plugins/ecmascript/runtime/base/error_helper.h" #include "plugins/ecmascript/runtime/base/error_type.h" #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -33,7 +32,6 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::base { -using BuiltinsArrayBuffer = builtins::BuiltinsArrayBuffer; // es11 22.2.4 The TypedArray Constructors JSTaggedValue TypedArrayHelper::TypedArrayConstructor(EcmaRuntimeCallInfo *argv, @@ -43,7 +41,7 @@ JSTaggedValue TypedArrayHelper::TypedArrayConstructor(EcmaRuntimeCallInfo *argv, JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); EcmaVM *ecma_vm = thread->GetEcmaVM(); - JSHandle new_target = BuiltinsBase::GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); // 2. If NewTarget is undefined, throw a TypeError exception. if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "The NewTarget is undefined.", JSTaggedValue::Exception()); @@ -52,7 +50,7 @@ JSTaggedValue TypedArrayHelper::TypedArrayConstructor(EcmaRuntimeCallInfo *argv, // TypedArray constructor. // 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, "%TypedArray.prototype%"). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle first_arg = BuiltinsBase::GetCallArg(argv, 0); + JSHandle first_arg = builtins_common::GetCallArg(argv, 0); if (!first_arg->IsECMAObject()) { // es11 22.2.4.1 TypedArray ( ) double element_length = 0; @@ -86,7 +84,7 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar [[maybe_unused]] EcmaHandleScope handle_scope(thread); EcmaVM *ecma_vm = thread->GetEcmaVM(); JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle object_arg = BuiltinsBase::GetCallArg(argv, 0); + JSHandle object_arg = builtins_common::GetCallArg(argv, 0); JSHandle object(object_arg); // 5. Let usingIterator be ? GetMethod(object, @@iterator). JSHandle iterator_symbol = env->GetIteratorSymbol(); @@ -177,12 +175,12 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 5. Let srcArray be typedArray. - JSHandle src_array = BuiltinsBase::GetCallArg(argv, 0); + JSHandle src_array = builtins_common::GetCallArg(argv, 0); JSHandle src_obj(src_array); // 6. Let srcData be srcArray.[[ViewedArrayBuffer]]. JSHandle src_data(thread, JSTypedArray::Cast(*src_obj)->GetViewedArrayBuffer()); // 7. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(src_data.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(src_data.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 8. Let elementType be the Element Type value in Table 61 for constructorName. @@ -208,8 +206,8 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, // 18. If elementType is the same as srcType, then // a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor). if (element_type == src_type) { - data.Update(BuiltinsArrayBuffer::CloneArrayBuffer(thread, src_data, src_byte_offset, - global_const->GetHandledUndefined())); + data.Update(builtins::array_buffer::CloneArrayBuffer(thread, src_data, src_byte_offset, + global_const->GetHandledUndefined())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { // 19. Else, @@ -217,10 +215,10 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, JSHandle buffer_constructor = JSObject::SpeciesConstructor(thread, JSHandle(src_data), env->GetArrayBufferFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - data.Update(BuiltinsArrayBuffer::AllocateArrayBuffer(thread, buffer_constructor, byte_length)); + data.Update(builtins::array_buffer::AllocateArrayBuffer(thread, buffer_constructor, byte_length)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(src_data.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(src_data.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // d. Let srcByteIndex be srcByteOffset. @@ -233,10 +231,10 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, for (int32_t count = element_length; count > 0; count--) { // i. Let value be GetValueFromBuffer(srcData, srcByteIndex, srcType, true, Unordered). JSTaggedValue tagged_data = - BuiltinsArrayBuffer::GetValueFromBuffer(thread, src_data, src_byte_index, src_type, true); + builtins::array_buffer::GetValueFromBuffer(thread, src_data, src_byte_index, src_type, true); value.Update(tagged_data); // ii. Perform SetValueInBuffer(data, targetByteIndex, elementType, value, true, Unordered). - BuiltinsArrayBuffer::SetValueInBuffer(thread, data, target_byte_index, element_type, value, true); + builtins::array_buffer::SetValueInBuffer(thread, data, target_byte_index, element_type, value, true); // iii. Set srcByteIndex to srcByteIndex + srcElementSize. // iv. Set targetByteIndex to targetByteIndex + elementSize. // v. Set count to count - 1. @@ -266,7 +264,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, // 5. Let elementSize be the Element Size value specified in Table 61 for constructorName. // 6. Let offset be ? ToIndex(byteOffset). int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); - JSHandle byte_offset = BuiltinsBase::GetCallArg(argv, 1); + JSHandle byte_offset = builtins_common::GetCallArg(argv, 1); JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byte_offset); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto offset = static_cast(index.GetNumber()); @@ -277,7 +275,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, } // 8. If length is not undefined, then // a. Let new_length be ? ToIndex(length). - JSHandle length = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle length = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); int32_t new_length = 0; if (!length->IsUndefined()) { index = JSTaggedValue::ToIndex(thread, length); @@ -285,8 +283,8 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, new_length = static_cast(index.GetNumber()); } // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - JSHandle buffer = BuiltinsBase::GetCallArg(argv, 0); - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + JSHandle buffer = builtins_common::GetCallArg(argv, 0); + if (builtins::array_buffer::IsDetachedBuffer(buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]. @@ -411,7 +409,7 @@ JSHandle TypedArrayHelper::AllocateTypedArrayBuffer(JSThread *thread, double byte_length = element_size * length; // 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). JSHandle constructor = env->GetArrayBufferFunction(); - JSTaggedValue data = BuiltinsArrayBuffer::AllocateArrayBuffer(thread, constructor, byte_length); + JSTaggedValue data = builtins::array_buffer::AllocateArrayBuffer(thread, constructor, byte_length); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, exception); JSTypedArray *js_typed_array = JSTypedArray::Cast(*obj); if (JSTaggedValue::SameValue(constructor_name, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || @@ -496,7 +494,7 @@ JSTaggedValue TypedArrayHelper::ValidateTypedArray(JSThread *thread, const JSHan // 3. Let buffer be O.[[ViewedArrayBuffer]]. // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. JSTaggedValue buffer = JSHandle::Cast(value)->GetViewedArrayBuffer(); - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ViewedArrayBuffer of O is detached buffer.", JSTaggedValue::Exception()); } @@ -525,7 +523,7 @@ int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandleSetCallArgs(first_value, second_value); JSTaggedValue call_result = JSFunction::Call(info.Get()); // 2: two args RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The buffer is detached buffer.", 0); } JSHandle test_result(thread, call_result); diff --git a/runtime/builtins.cpp b/runtime/builtins.cpp index 74e82f9babee986141aa9405a87900ce61d12501..845cefa3bd1fa9c53ad8d18e2fd5bf32b1423aff 100644 --- a/runtime/builtins.cpp +++ b/runtime/builtins.cpp @@ -19,50 +19,6 @@ #include "init_icu.h" #include "plugins/ecmascript/runtime/base/error_type.h" #include "plugins/ecmascript/runtime/base/number_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_ark_tools.h" -#include "plugins/ecmascript/runtime/builtins/builtins_array.h" -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" -#include "plugins/ecmascript/runtime/builtins/builtins_async_from_sync_iterator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_async_function.h" -#include "plugins/ecmascript/runtime/builtins/builtins_async_generator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_async_iterator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_bigint.h" -#include "plugins/ecmascript/runtime/builtins/builtins_boolean.h" -#include "plugins/ecmascript/runtime/builtins/builtins_collator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_dataview.h" -#include "plugins/ecmascript/runtime/builtins/builtins_date.h" -#include "plugins/ecmascript/runtime/builtins/builtins_date_time_format.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" -#include "plugins/ecmascript/runtime/builtins/builtins_function.h" -#include "plugins/ecmascript/runtime/builtins/builtins_generator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_global.h" -#include "plugins/ecmascript/runtime/builtins/builtins_intl.h" -#include "plugins/ecmascript/runtime/builtins/builtins_iterator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_json.h" -#include "plugins/ecmascript/runtime/builtins/builtins_locale.h" -#include "plugins/ecmascript/runtime/builtins/builtins_map.h" -#include "plugins/ecmascript/runtime/builtins/builtins_math.h" -#include "plugins/ecmascript/runtime/builtins/builtins_number.h" -#include "plugins/ecmascript/runtime/builtins/builtins_number_format.h" -#include "plugins/ecmascript/runtime/builtins/builtins_object.h" -#include "plugins/ecmascript/runtime/builtins/builtins_plural_rules.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_handler.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_job.h" -#include "plugins/ecmascript/runtime/builtins/builtins_proxy.h" -#include "plugins/ecmascript/runtime/builtins/builtins_reflect.h" -#include "plugins/ecmascript/runtime/builtins/builtins_regexp.h" -#include "plugins/ecmascript/runtime/builtins/builtins_relative_time_format.h" -#include "plugins/ecmascript/runtime/builtins/builtins_runtime_testing.h" -#include "plugins/ecmascript/runtime/builtins/builtins_set.h" -#include "plugins/ecmascript/runtime/builtins/builtins_string.h" -#include "plugins/ecmascript/runtime/builtins/builtins_string_iterator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_symbol.h" -#include "plugins/ecmascript/runtime/builtins/builtins_typedarray.h" -#include "plugins/ecmascript/runtime/builtins/builtins_weak_ref.h" -#include "plugins/ecmascript/runtime/builtins/builtins_weak_map.h" -#include "plugins/ecmascript/runtime/builtins/builtins_weak_set.h" -#include "plugins/ecmascript/runtime/builtins/builtins_finalization_registry.h" #include "plugins/ecmascript/runtime/containers/containers_private.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/js_array.h" @@ -100,59 +56,10 @@ #include "plugins/ecmascript/runtime/mem/mem.h" #include "plugins/ecmascript/runtime/object_factory.h" -namespace panda::ecmascript { -using Number = builtins::BuiltinsNumber; -using Object = builtins::BuiltinsObject; -using Date = builtins::BuiltinsDate; -using Symbol = builtins::BuiltinsSymbol; -using BuiltinsBigInt = builtins::BuiltinsBigInt; -using Boolean = builtins::BuiltinsBoolean; -using BuiltinsMap = builtins::BuiltinsMap; -using BuiltinsSet = builtins::BuiltinsSet; -using BuiltinsWeakRef = builtins::BuiltinsWeakRef; -using BuiltinsWeakMap = builtins::BuiltinsWeakMap; -using BuiltinsWeakSet = builtins::BuiltinsWeakSet; -using BuiltinsArray = builtins::BuiltinsArray; -using BuiltinsTypedArray = builtins::BuiltinsTypedArray; -using BuiltinsIterator = builtins::BuiltinsIterator; -using BuiltinsAsyncIterator = builtins::BuiltinsAsyncIterator; - -using Error = builtins::BuiltinsError; -using RangeError = builtins::BuiltinsRangeError; -using ReferenceError = builtins::BuiltinsReferenceError; -using TypeError = builtins::BuiltinsTypeError; -using URIError = builtins::BuiltinsURIError; -using SyntaxError = builtins::BuiltinsSyntaxError; -using EvalError = builtins::BuiltinsEvalError; -using ErrorType = base::ErrorType; -using Global = builtins::BuiltinsGlobal; -using BuiltinsString = builtins::BuiltinsString; -using StringIterator = builtins::BuiltinsStringIterator; -using RegExp = builtins::BuiltinsRegExp; -using Function = builtins::BuiltinsFunction; -using Math = builtins::BuiltinsMath; -using ArrayBuffer = builtins::BuiltinsArrayBuffer; -using Json = builtins::BuiltinsJson; -using Proxy = builtins::BuiltinsProxy; -using Reflect = builtins::BuiltinsReflect; -using AsyncFunction = builtins::BuiltinsAsyncFunction; -using GeneratorObject = builtins::BuiltinsGenerator; -using AsyncGeneratorObject = builtins::BuiltinsAsyncGenerator; -using AsyncFromSyncIterator = builtins::BuiltinsAsyncFromSyncIterator; -using Promise = builtins::BuiltinsPromise; -using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler; -using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob; +namespace panda::ecmascript::builtins { + using ErrorType = base::ErrorType; -using DataView = builtins::BuiltinsDataView; -using Intl = builtins::BuiltinsIntl; -using Locale = builtins::BuiltinsLocale; -using DateTimeFormat = builtins::BuiltinsDateTimeFormat; -using RelativeTimeFormat = builtins::BuiltinsRelativeTimeFormat; -using NumberFormat = builtins::BuiltinsNumberFormat; -using Collator = builtins::BuiltinsCollator; -using PluralRules = builtins::BuiltinsPluralRules; using ContainersPrivate = containers::ContainersPrivate; -using BuiltinsFinalizationRegistry = builtins::BuiltinsFinalizationRegistry; void Builtins::Initialize(const JSHandle &env, JSThread *thread) { @@ -242,7 +149,7 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) // Object = new Function() JSHandle object_function( - NewBuiltinConstructor(env, obj_func_prototype, Object::ObjectConstructor, "Object", FunctionLength::ONE)); + NewBuiltinConstructor(env, obj_func_prototype, object::ObjectConstructor, "Object", FunctionLength::ONE)); object_function.GetObject()->SetFunctionPrototype(thread_, obj_func_dynclass.GetTaggedValue()); // initialize object method. env->SetObjectFunction(thread_, object_function); @@ -267,7 +174,7 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) InitializeSymbolWithRealm(env, prim_ref_obj_dynclass); } - InitializeNumber(env, global_object, prim_ref_obj_dynclass); + InitializeNumber(env, prim_ref_obj_dynclass); InitializeBigInt(env, obj_func_dynclass); InitializeDate(env, obj_func_dynclass); InitializeObject(env, obj_func_prototype, object_function); @@ -341,30 +248,8 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa { [[maybe_unused]] EcmaHandleScope scope(thread_); - // Global object test - SetFunction(env, global_object, "print", Global::PrintEntrypoint, 0); - SetFunction(env, global_object, "gc", Global::GCEntrypoint, 0); - - // Intrusice GC testing framework - SetFunction(env, global_object, "startGC", Global::SpecifiedGCEntrypoint, 2); - SetFunction(env, global_object, "waitForFinishGC", Global::WaitForFinishGC, 1); - SetFunction(env, global_object, "scheduleGcAfterNthAlloc", Global::ScheduleGCAfterNthAlloc, 2); - SetFunction(env, global_object, "isScheduledGcTriggered", Global::IsScheduledGCTriggered, 0); - SetFunction(env, global_object, "allocateArrayObject", Global::AllocateArrayObject, 1); - SetFunction(env, global_object, "markObject", Global::MarkObject, 1); - SetFunction(env, global_object, "getMarkQueue", Global::GetMarkQueue, 0); - SetFunction(env, global_object, "clearMarkQueue", Global::ClearMarkQueue, 0); - SetFunction(env, global_object, "getObjectSpaceType", Global::GCObjectSpaceType, 1); - SetFunction(env, global_object, "pinObject", Global::PinObject, 1); - SetFunction(env, global_object, "unpinObject", Global::UnpinObject, 1); - SetFunction(env, global_object, "getObjectAddress", Global::GetObjectAddress, 1); InitializeGcMarker(env); -#if ECMASCRIPT_ENABLE_RUNTIME_STAT - SetFunction(env, global_object, "startRuntimeStat", Global::StartRuntimeStat, 0); - SetFunction(env, global_object, "stopRuntimeStat", Global::StopRuntimeStat, 0); -#endif - // TODO(ivagin): Remove ArkTools? if (vm_->GetJSOptions().IsEnableArkTools()) { JSHandle ark_tools(InitializeArkTools(env)); @@ -382,22 +267,13 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa SetConstantObject(global_object, "ArkPrivate", ark_private); #endif - // Global object function - SetFunction(env, global_object, "eval", Global::Eval, FunctionLength::ONE); - SetFunction(env, global_object, "isFinite", Global::IsFinite, FunctionLength::ONE); - SetFunction(env, global_object, "isNaN", Global::IsNaN, FunctionLength::ONE); - SetFunction(env, global_object, "unescape", Global::Unescape, FunctionLength::ONE); - SetFunction(env, global_object, "escape", Global::Escape, FunctionLength::ONE); - SetFunction(env, global_object, "decodeURI", Global::DecodeURI, FunctionLength::ONE); - SetFunction(env, global_object, "encodeURI", Global::EncodeURI, FunctionLength::ONE); - SetFunction(env, global_object, "decodeURIComponent", Global::DecodeURIComponent, FunctionLength::ONE); - SetFunction(env, global_object, "encodeURIComponent", Global::EncodeURIComponent, FunctionLength::ONE); - // Global object property SetGlobalThis(global_object, "globalThis", JSHandle::Cast(global_object)); SetConstant(global_object, "Infinity", JSTaggedValue(base::POSITIVE_INFINITY)); SetConstant(global_object, "NaN", JSTaggedValue(base::NAN_VALUE)); SetConstant(global_object, "undefined", JSTaggedValue::Undefined()); + + SetFunctionsGenGlobal(env, global_object); } void Builtins::InitializeFunction(const JSHandle &env, const JSHandle &empty_func_dynclass) const @@ -405,7 +281,7 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle [[maybe_unused]] EcmaHandleScope scope(thread_); // Initialize Function.prototype JSMethod *invoke_self = - vm_->GetMethodForNativeFunction(reinterpret_cast(Function::FunctionPrototypeInvokeSelf)); + vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionPrototypeInvokeSelf)); JSHandle func_func_prototype = factory_->NewJSFunctionByDynClass(invoke_self, empty_func_dynclass); // ecma 19.2.3 The value of the name property of the Function prototype object is the empty String. JSHandle empty_string(thread_->GlobalConstants()->GetHandledEmptyString()); @@ -421,7 +297,7 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle func_func_intance_dynclass->SetConstructor(true); // Function = new Function() (forbidden use NewBuiltinConstructor) - JSMethod *ctor = vm_->GetMethodForNativeFunction(reinterpret_cast(Function::FunctionConstructor)); + JSMethod *ctor = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionConstructor)); JSHandle func_func = factory_->NewJSFunctionByDynClass(ctor, func_func_intance_dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); @@ -447,97 +323,16 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle StrictModeForbiddenAccessCallerArguments(env, func_func_prototype_obj); - // Function.prototype method - // 19.2.3.1 Function.prototype.apply ( thisArg, argArray ) - SetFunction(env, func_func_prototype_obj, "apply", Function::FunctionPrototypeApply, FunctionLength::TWO); - // 19.2.3.2 Function.prototype.bind ( thisArg , ...args) - SetFunction(env, func_func_prototype_obj, "bind", Function::FunctionPrototypeBind, FunctionLength::ONE); - // 19.2.3.3 Function.prototype.call (thisArg , ...args) - SetFunction(env, func_func_prototype_obj, "call", Function::FunctionPrototypeCall, FunctionLength::ONE); - // 19.2.3.5 Function.prototype.toString ( ) - SetFunction(env, func_func_prototype_obj, thread_->GlobalConstants()->GetHandledToStringString(), - Function::FunctionPrototypeToString, FunctionLength::ZERO); + SetFunctionsGenFunctionProto(env, func_func_prototype_obj); } void Builtins::InitializeObject(const JSHandle &env, const JSHandle &obj_func_prototype, const JSHandle &obj_func) { [[maybe_unused]] EcmaHandleScope scope(thread_); - // Object method. - // 19.1.2.1Object.assign ( target, ...sources ) - SetFunction(env, obj_func, "assign", Object::Assign, FunctionLength::TWO); - // 19.1.2.2Object.create ( O [ , Properties ] ) - SetFunction(env, obj_func, "create", Object::Create, FunctionLength::TWO); - // 19.1.2.3Object.defineProperties ( O, Properties ) - SetFunction(env, obj_func, "defineProperties", Object::DefineProperties, FunctionLength::TWO); - // 19.1.2.4Object.defineProperty ( O, P, Attributes ) - SetFunction(env, obj_func, "defineProperty", Object::DefineProperty, FunctionLength::THREE); - // 19.1.2.5Object.freeze ( O ) - SetFunction(env, obj_func, "freeze", Object::Freeze, FunctionLength::ONE); - // ES2021 20.1.2.7Object.fromEntries ( iterable ) - SetFunction(env, obj_func, "fromEntries", Object::FromEntries, FunctionLength::ONE); - // 19.1.2.6Object.getOwnPropertyDescriptor ( O, P ) - SetFunction(env, obj_func, "getOwnPropertyDescriptor", Object::GetOwnPropertyDesciptor, FunctionLength::TWO); - // ES2021 20.1.2.9 Object.getOwnPropertyDescriptors ( O ) - SetFunction(env, obj_func, "getOwnPropertyDescriptors", Object::GetOwnPropertyDesciptors, FunctionLength::ONE); - // 19.1.2.7Object.getOwnPropertyNames ( O ) - SetFunction(env, obj_func, "getOwnPropertyNames", Object::GetOwnPropertyNames, FunctionLength::ONE); - // 19.1.2.8Object.getOwnPropertySymbols ( O ) - SetFunction(env, obj_func, "getOwnPropertySymbols", Object::GetOwnPropertySymbols, FunctionLength::ONE); - // 19.1.2.9Object.getPrototypeOf ( O ) - SetFunction(env, obj_func, "getPrototypeOf", Object::GetPrototypeOf, FunctionLength::ONE); - // 19.1.2.10Object.is ( value1, value2 ) - SetFunction(env, obj_func, "is", Object::Is, 2); - // 19.1.2.11Object.isExtensible ( O ) - SetFunction(env, obj_func, "isExtensible", Object::IsExtensible, FunctionLength::ONE); - // 19.1.2.12Object.isFrozen ( O ) - SetFunction(env, obj_func, "isFrozen", Object::IsFrozen, FunctionLength::ONE); - // 19.1.2.13Object.isSealed ( O ) - SetFunction(env, obj_func, "isSealed", Object::IsSealed, FunctionLength::ONE); - // 19.1.2.14 Object.keys(O) - SetFunction(env, obj_func, "keys", Object::Keys, FunctionLength::ONE); - // 19.1.2.15 Object.preventExtensions(O) - SetFunction(env, obj_func, "preventExtensions", Object::PreventExtensions, FunctionLength::ONE); - // 19.1.2.17 Object.seal(O) - SetFunction(env, obj_func, "seal", Object::Seal, FunctionLength::ONE); - // 19.1.2.18 Object.setPrototypeOf(O, proto) - SetFunction(env, obj_func, "setPrototypeOf", Object::SetPrototypeOf, FunctionLength::TWO); - // 20.1.2.5 Object.entries ( O ) - SetFunction(env, obj_func, "entries", Object::Entries, FunctionLength::ONE); - // ES2021 20.1.2.22 Object.values ( O ) - SetFunction(env, obj_func, "values", Object::Values, FunctionLength::ONE); - - // Object.property method - // 19.1.3.2 Object.prototype.hasOwnProperty(V) - SetFunction(env, obj_func_prototype, "hasOwnProperty", Object::HasOwnProperty, FunctionLength::ONE); - // 19.1.3.3 Object.prototype.isPrototypeOf(V) - SetFunction(env, obj_func_prototype, "isPrototypeOf", Object::IsPrototypeOf, FunctionLength::ONE); - // 19.1.3.4 Object.prototype.propertyIsEnumerable(V) - SetFunction(env, obj_func_prototype, "propertyIsEnumerable", Object::PropertyIsEnumerable, FunctionLength::ONE); - // 19.1.3.5 Object.prototype.toLocaleString([reserved1[, reserved2]]) - SetFunction(env, obj_func_prototype, "toLocaleString", Object::ToLocaleString, FunctionLength::ZERO); - // 19.1.3.6 Object.prototype.toString() - SetFunction(env, obj_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Object::ToString, - FunctionLength::ZERO); - // 19.1.3.7 Object.prototype.valueOf() - SetFunction(env, obj_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Object::ValueOf, - FunctionLength::ZERO); - - SetFunction(env, obj_func_prototype, "createRealm", Object::CreateRealm, FunctionLength::ZERO); - - // B.2.2.1 Object.prototype.__proto__ - JSHandle proto_key(factory_->NewFromCanBeCompressString("__proto__")); - JSHandle proto_getter = CreateGetter(env, Object::ProtoGetter, "__proto__", FunctionLength::ZERO); - JSHandle proto_setter = CreateSetter(env, Object::ProtoSetter, "__proto__", FunctionLength::ONE); - SetAccessor(obj_func_prototype, proto_key, proto_getter, proto_setter); - // B.2.2.2 Object.prototype.__defineGetter__ ( P, getter ) - SetFunction(env, obj_func_prototype, "__defineGetter__", Object::DefineGetter, FunctionLength::TWO); - // B.2.2.3 Object.prototype.__defineSetter__ ( P, setter ) - SetFunction(env, obj_func_prototype, "__defineSetter__", Object::DefineSetter, FunctionLength::TWO); - // B.2.2.4 Object.prototype.__lookupGetter__ ( P ) - SetFunction(env, obj_func_prototype, "__lookupGetter__", Object::LookupGetter, FunctionLength::ONE); - // B.2.2.5 Object.prototype.__lookupSetter__ ( P ) - SetFunction(env, obj_func_prototype, "__lookupSetter__", Object::LookupSetter, FunctionLength::ONE); + SetFunctionsGenObject(env, obj_func); + + SetFunctionsGenObjectProto(env, obj_func_prototype); } void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -553,8 +348,8 @@ void Builtins::InitializeSymbol(const JSHandle &env, const JSHandleCreateDynClass(JSType::JS_PRIMITIVE_REF, symbol_func_prototype_value); // Symbol = new Function() - JSHandle symbol_function( - NewBuiltinConstructor(env, symbol_func_prototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); + JSHandle symbol_function(NewBuiltinConstructor( + env, symbol_func_prototype, builtins::symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); JSHandle(symbol_function) ->SetFunctionPrototype(thread_, symbol_func_instance_dynclass.GetTaggedValue()); @@ -563,9 +358,6 @@ void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle::Cast(symbol_function), true, false, true); JSObject::DefineOwnProperty(thread_, symbol_func_prototype, constructor_key, descriptor); - SetFunction(env, symbol_function, "for", Symbol::For, FunctionLength::ONE); - SetFunction(env, symbol_function, "keyFor", Symbol::KeyFor, FunctionLength::ONE); - // Symbol attribute JSHandle has_instance_symbol(factory_->NewWellKnownSymbolWithChar("Symbol.hasInstance")); SetNoneAttributeProperty(symbol_function, "hasInstance", has_instance_symbol); @@ -595,22 +387,6 @@ void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle unscopables_symbol(factory_->NewPublicSymbolWithChar("Symbol.unscopables")); SetNoneAttributeProperty(symbol_function, "unscopables", unscopables_symbol); - // symbol.prototype.description - PropertyDescriptor description_desc(thread_); - JSHandle getter_key(factory_->NewFromCanBeCompressString("description")); - JSHandle getter(factory_->NewJSFunction(env, reinterpret_cast(Symbol::DescriptionGetter))); - SetGetter(symbol_func_prototype, getter_key, getter); - - // Setup symbol.prototype[@@toPrimitive] - SetFunctionAtSymbol(env, symbol_func_prototype, to_primitive_symbol, - "[Symbol.toPrimitive]", Symbol::ToPrimitive, - FunctionLength::ONE); - // install the Symbol.prototype methods - SetFunction(env, symbol_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Symbol::ToString, - FunctionLength::ZERO); - SetFunction(env, symbol_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Symbol::ValueOf, - FunctionLength::ZERO); - env->SetSymbolFunction(thread_, symbol_function); env->SetHasInstanceSymbol(thread_, has_instance_symbol); env->SetIsConcatSpreadableSymbol(thread_, is_concat_spreadable_symbol); @@ -636,9 +412,12 @@ void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle func_func_prototype_obj = JSHandle(env->GetFunctionPrototype()); - SetFunctionAtSymbol( + SetFunctionAtSymbol( env, func_func_prototype_obj, env->GetHasInstanceSymbol(), "[Symbol.hasInstance]", - Function::FunctionPrototypeHasInstance, FunctionLength::ONE); + builtins::function::proto::HasInstance, FunctionLength::ONE); + + SetFunctionsGenSymbol(env, symbol_function); + SetFunctionsGenSymbolProto(env, symbol_func_prototype); } void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, @@ -655,8 +434,8 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbol_func_prototype_value); // Symbol = new Function() - JSHandle symbol_function( - NewBuiltinConstructor(realm, symbol_func_prototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); + JSHandle symbol_function(NewBuiltinConstructor( + realm, symbol_func_prototype, builtins::symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); JSHandle(symbol_function) ->SetFunctionPrototype(thread_, symbol_func_instance_dynclass.GetTaggedValue()); @@ -665,9 +444,6 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbol_function), true, false, true); JSObject::DefineOwnProperty(thread_, symbol_func_prototype, constructor_key, descriptor); - SetFunction(realm, symbol_function, "for", Symbol::For, FunctionLength::ONE); - SetFunction(realm, symbol_function, "keyFor", Symbol::KeyFor, FunctionLength::ONE); - // Symbol attribute SetNoneAttributeProperty(symbol_function, "hasInstance", env->GetHasInstanceSymbol()); SetNoneAttributeProperty(symbol_function, "isConcatSpreadable", env->GetIsConcatSpreadableSymbol()); @@ -683,22 +459,6 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, SetNoneAttributeProperty(symbol_function, "toPrimitive", env->GetToPrimitiveSymbol()); SetNoneAttributeProperty(symbol_function, "unscopables", env->GetUnscopablesSymbol()); - // symbol.prototype.description - PropertyDescriptor description_desc(thread_); - JSHandle getter_key(factory_->NewFromCanBeCompressString("description")); - JSHandle getter(factory_->NewJSFunction(realm, reinterpret_cast(Symbol::DescriptionGetter))); - SetGetter(symbol_func_prototype, getter_key, getter); - - // Setup symbol.prototype[@@toPrimitive] - SetFunctionAtSymbol(realm, symbol_func_prototype, env->GetToPrimitiveSymbol(), - "[Symbol.toPrimitive]", Symbol::ToPrimitive, - FunctionLength::ONE); - // install the Symbol.prototype methods - SetFunction(realm, symbol_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Symbol::ToString, - FunctionLength::ZERO); - SetFunction(realm, symbol_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Symbol::ValueOf, - FunctionLength::ZERO); - realm->SetSymbolFunction(thread_, symbol_function); realm->SetHasInstanceSymbol(thread_, env->GetHasInstanceSymbol()); realm->SetIsConcatSpreadableSymbol(thread_, env->GetIsConcatSpreadableSymbol()); @@ -724,13 +484,15 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, // ecma 19.2.3.6 Function.prototype[@@hasInstance] ( V ) JSHandle func_func_prototype_obj = JSHandle(realm->GetFunctionPrototype()); - SetFunctionAtSymbol( + SetFunctionAtSymbol( realm, func_func_prototype_obj, realm->GetHasInstanceSymbol(), "[Symbol.hasInstance]", - Function::FunctionPrototypeHasInstance, FunctionLength::ONE); + builtins::function::proto::HasInstance, FunctionLength::ONE); + + SetFunctionsGenSymbol(realm, symbol_function); + SetFunctionsGenSymbolProto(realm, symbol_func_prototype); } -void Builtins::InitializeNumber(const JSHandle &env, const JSHandle &global_object, - const JSHandle &prim_ref_obj_dynclass) +void Builtins::InitializeNumber(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Number.prototype @@ -744,27 +506,13 @@ void Builtins::InitializeNumber(const JSHandle &env, const JSHandleCreateDynClass(JSType::JS_PRIMITIVE_REF, num_func_prototype_value); // Number = new Function() - JSHandle num_function( - NewBuiltinConstructor(env, num_func_prototype, Number::NumberConstructor, "Number", FunctionLength::ONE)); + JSHandle num_function(NewBuiltinConstructor(env, num_func_prototype, builtins::number::NumberConstructor, + "Number", FunctionLength::ONE)); num_function.GetObject()->SetFunctionPrototype(thread_, num_func_instance_class.GetTaggedValue()); - // Number.prototype method - SetFunction(env, num_func_prototype, "toExponential", Number::ToExponential, FunctionLength::ONE); - SetFunction(env, num_func_prototype, "toFixed", Number::ToFixed, FunctionLength::ONE); - SetFunction(env, num_func_prototype, "toLocaleString", Number::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, num_func_prototype, "toPrecision", Number::ToPrecision, FunctionLength::ONE); - SetFunction(env, num_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Number::ToString, - FunctionLength::ONE); - SetFunction(env, num_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Number::ValueOf, - FunctionLength::ZERO); + env->SetNumberFunction(thread_, num_function); // Number method - SetFunction(env, num_function, "isFinite", Number::IsFinite, FunctionLength::ONE); - SetFunction(env, num_function, "isInteger", Number::IsInteger, FunctionLength::ONE); - SetFunction(env, num_function, "isNaN", Number::IsNaN, FunctionLength::ONE); - SetFunction(env, num_function, "isSafeInteger", Number::IsSafeInteger, FunctionLength::ONE); - SetFuncToObjAndGlobal(env, global_object, num_function, "parseFloat", Number::ParseFloat, FunctionLength::ONE); - SetFuncToObjAndGlobal(env, global_object, num_function, "parseInt", Number::ParseInt, FunctionLength::TWO); // Number constant const double epsilon = 2.220446049250313e-16; @@ -781,7 +529,9 @@ void Builtins::InitializeNumber(const JSHandle &env, const JSHandleSetNumberFunction(thread_, num_function); + SetFunctionsGenNumberProto(env, num_func_prototype); + + SetFunctionsGenNumber(env, num_function); } void Builtins::InitializeBigInt(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -796,22 +546,16 @@ void Builtins::InitializeBigInt(const JSHandle &env, const JSHandleCreateDynClass(JSType::JS_PRIMITIVE_REF, big_int_func_prototype_value); // BigInt = new Function() JSHandle big_int_function(NewBuiltinConstructor( - env, big_int_func_prototype, BuiltinsBigInt::BigIntConstructor, "BigInt", FunctionLength::ONE)); + env, big_int_func_prototype, builtins::big_int::BigIntConstructor, "BigInt", FunctionLength::ONE)); JSHandle(big_int_function) ->SetFunctionPrototype(thread_, big_int_func_instance_dynclass.GetTaggedValue()); - // BigInt.prototype method - SetFunction(env, big_int_func_prototype, "toLocaleString", BuiltinsBigInt::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, big_int_func_prototype, "toString", BuiltinsBigInt::ToString, FunctionLength::ZERO); - SetFunction(env, big_int_func_prototype, "valueOf", BuiltinsBigInt::ValueOf, FunctionLength::ZERO); - - // BigInt method - SetFunction(env, big_int_function, "asUintN", BuiltinsBigInt::AsUintN, FunctionLength::TWO); - SetFunction(env, big_int_function, "asIntN", BuiltinsBigInt::AsIntN, FunctionLength::TWO); + env->SetBigIntFunction(thread_, big_int_function); // @@ToStringTag SetStringTagSymbol(env, big_int_func_prototype, "BigInt"); - env->SetBigIntFunction(thread_, big_int_function); + SetFunctionsGenBigIntProto(env, big_int_func_prototype); + SetFunctionsGenBigInt(env, big_int_function); } void Builtins::InitializeDate(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -828,71 +572,16 @@ void Builtins::InitializeDate(const JSHandle &env, const JSHandle date_function( - NewBuiltinConstructor(env, date_func_prototype, Date::DateConstructor, "Date", FunctionLength::ONE)); + NewBuiltinConstructor(env, date_func_prototype, builtins::date::DateConstructor, "Date", FunctionLength::ONE)); JSHandle(date_function)->SetFunctionPrototype(thread_, date_func_instance_dynclass.GetTaggedValue()); - // Date.prototype method - SetFunction(env, date_func_prototype, "getDate", Date::GetDate, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getDay", Date::GetDay, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getFullYear", Date::GetFullYear, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getYear", Date::GetYear, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getHours", Date::GetHours, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getMilliseconds", Date::GetMilliseconds, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getMinutes", Date::GetMinutes, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getMonth", Date::GetMonth, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getSeconds", Date::GetSeconds, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getTime", Date::GetTime, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getTimezoneOffset", Date::GetTimezoneOffset, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCDate", Date::GetUTCDate, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCDay", Date::GetUTCDay, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCFullYear", Date::GetUTCFullYear, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCHours", Date::GetUTCHours, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCMilliseconds", Date::GetUTCMilliseconds, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCMinutes", Date::GetUTCMinutes, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCMonth", Date::GetUTCMonth, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "getUTCSeconds", Date::GetUTCSeconds, FunctionLength::ZERO); - - SetFunction(env, date_func_prototype, "setDate", Date::SetDate, FunctionLength::ONE); - SetFunction(env, date_func_prototype, "setFullYear", Date::SetFullYear, FunctionLength::THREE); - SetFunction(env, date_func_prototype, "setHours", Date::SetHours, FunctionLength::FOUR); - SetFunction(env, date_func_prototype, "setMilliseconds", Date::SetMilliseconds, FunctionLength::ONE); - SetFunction(env, date_func_prototype, "setMinutes", Date::SetMinutes, FunctionLength::THREE); - SetFunction(env, date_func_prototype, "setMonth", Date::SetMonth, FunctionLength::TWO); - SetFunction(env, date_func_prototype, "setSeconds", Date::SetSeconds, FunctionLength::TWO); - SetFunction(env, date_func_prototype, "setTime", Date::SetTime, FunctionLength::ONE); - SetFunction(env, date_func_prototype, "setUTCDate", Date::SetUTCDate, FunctionLength::ONE); - SetFunction(env, date_func_prototype, "setUTCFullYear", Date::SetUTCFullYear, FunctionLength::THREE); - SetFunction(env, date_func_prototype, "setUTCHours", Date::SetUTCHours, FunctionLength::FOUR); - SetFunction(env, date_func_prototype, "setUTCMilliseconds", Date::SetUTCMilliseconds, FunctionLength::ONE); - SetFunction(env, date_func_prototype, "setUTCMinutes", Date::SetUTCMinutes, FunctionLength::THREE); - SetFunction(env, date_func_prototype, "setUTCMonth", Date::SetUTCMonth, FunctionLength::TWO); - SetFunction(env, date_func_prototype, "setUTCSeconds", Date::SetUTCSeconds, FunctionLength::TWO); - - SetFunction(env, date_func_prototype, "toDateString", Date::ToDateString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "toISOString", Date::ToISOString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "toJSON", Date::ToJSON, FunctionLength::ONE); - SetFunction(env, date_func_prototype, "toLocaleDateString", Date::ToLocaleDateString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "toLocaleString", Date::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "toLocaleTimeString", Date::ToLocaleTimeString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Date::ToString, - FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "toTimeString", Date::ToTimeString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, "toUTCString", Date::ToUTCString, FunctionLength::ZERO); - SetFunction(env, date_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Date::ValueOf, - FunctionLength::ZERO); - - SetFunctionAtSymbol(env, date_func_prototype, env->GetToPrimitiveSymbol(), "[Symbol.toPrimitive]", - Date::ToPrimitive, FunctionLength::ONE); - - // Date method - SetFunction(env, date_function, "now", Date::Now, FunctionLength::ZERO); - SetFunction(env, date_function, "parse", Date::Parse, FunctionLength::ONE); - SetFunction(env, date_function, "UTC", Date::UTC, utc_length); + env->SetDateFunction(thread_, date_function); // Date.length SetConstant(date_function, "length", JSTaggedValue(utc_length)); + SetFunctionsGenDateProto(env, date_func_prototype); - env->SetDateFunction(thread_, date_function); + SetFunctionsGenDate(env, date_function); } void Builtins::InitializeBoolean(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const @@ -910,25 +599,18 @@ void Builtins::InitializeBoolean(const JSHandle &env, const JSHandle< // new Boolean Function() JSHandle boolean_function(NewBuiltinConstructor( - env, boolean_func_prototype, Boolean::BooleanConstructor, "Boolean", FunctionLength::ONE)); + env, boolean_func_prototype, builtins::boolean::BooleanConstructor, "Boolean", FunctionLength::ONE)); boolean_function->SetFunctionPrototype(thread_, boolean_func_instance_dynclass.GetTaggedValue()); - // Boolean.prototype method - SetFunction(env, boolean_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), - Boolean::BooleanPrototypeToString, FunctionLength::ZERO); - SetFunction(env, boolean_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), - Boolean::BooleanPrototypeValueOf, FunctionLength::ZERO); - env->SetBooleanFunction(thread_, boolean_function); + SetFunctionsGenBooleanProto(env, boolean_func_prototype); } void Builtins::InitializeProxy(const JSHandle &env) { - JSHandle proxy_function(InitializeExoticConstructor(env, Proxy::ProxyConstructor, "Proxy", 2)); - - // Proxy method - SetFunction(env, proxy_function, "revocable", Proxy::Revocable, FunctionLength::TWO); + JSHandle proxy_function(InitializeExoticConstructor(env, builtins::proxy::ProxyConstructor, "Proxy", 2)); env->SetProxyFunction(thread_, proxy_function); + SetFunctionsGenProxy(env, proxy_function); } JSHandle Builtins::InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctor_func, @@ -963,8 +645,9 @@ void Builtins::InitializeAsyncFunction(const JSHandle &env, factory_->CreateDynClass(JSType::JS_ASYNC_FUNCTION, async_func_prototype_value); // AsyncFunction = new Function() - JSHandle async_function = NewBuiltinConstructor( - env, async_func_prototype, AsyncFunction::AsyncFunctionConstructor, "AsyncFunction", FunctionLength::ONE); + JSHandle async_function = + NewBuiltinConstructor(env, async_func_prototype, builtins::async_function::AsyncFunctionConstructor, + "AsyncFunction", FunctionLength::ONE); JSObject::SetPrototype(thread_, JSHandle::Cast(async_function), env->GetFunctionFunction()); JSHandle constructor_key = global_const->GetHandledConstructorString(); PropertyDescriptor async_desc(thread_, JSHandle::Cast(async_function), false, false, true); @@ -986,18 +669,16 @@ void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHa JSHandle error_func_instance_dynclass = factory_->CreateDynClass(JSType::JS_ERROR, error_func_prototype_value); // Error() = new Function() - JSHandle error_function( - NewBuiltinConstructor(env, error_func_prototype, Error::ErrorConstructor, "Error", FunctionLength::ONE)); + JSHandle error_function(NewBuiltinConstructor( + env, error_func_prototype, builtins::error::ErrorConstructor, "Error", FunctionLength::ONE)); error_function->SetFunctionPrototype(thread_, error_func_instance_dynclass.GetTaggedValue()); - - // Error.prototype method - SetFunction(env, error_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Error::ToString, - FunctionLength::ZERO); + env->SetErrorFunction(thread_, error_function); // Error.prototype Attribute SetAttribute(error_func_prototype, "name", "Error"); SetAttribute(error_func_prototype, "message", ""); - env->SetErrorFunction(thread_, error_function); + + SetFunctionsGenErrorProto(env, error_func_prototype); JSHandle native_error_func_class = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetErrorFunction(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); @@ -1083,6 +764,8 @@ void Builtins::GeneralUpdateError(ErrorParameter *error, EcmaEntrypoint construc error->native_jstype = type; } +// TODO(dkofanov): Split errors initialization, use `SetFunctionsGenRangeErrorProto` from `builtins_initializers_gen.h` +// and etc. void Builtins::InitializeError(const JSHandle &env, const JSHandle &obj_func_dynclass, const JSType &error_tag) const { @@ -1090,32 +773,33 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandle native_error_func_prototype = factory_->NewJSObject(obj_func_dynclass); JSHandle native_error_func_prototype_value(native_error_func_prototype); - ErrorParameter error_parameter {RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", - JSType::JS_RANGE_ERROR}; + ErrorParameter error_parameter {builtins::range_error::RangeErrorConstructor, + builtins::range_error::proto::ToString, "RangeError", JSType::JS_RANGE_ERROR}; switch (error_tag) { case JSType::JS_RANGE_ERROR: - GeneralUpdateError(&error_parameter, RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", - JSType::JS_RANGE_ERROR); + GeneralUpdateError(&error_parameter, builtins::range_error::RangeErrorConstructor, + builtins::range_error::proto::ToString, "RangeError", JSType::JS_RANGE_ERROR); break; case JSType::JS_EVAL_ERROR: - GeneralUpdateError(&error_parameter, EvalError::EvalErrorConstructor, EvalError::ToString, "EvalError", - JSType::JS_EVAL_ERROR); + GeneralUpdateError(&error_parameter, builtins::eval_error::EvalErrorConstructor, + builtins::eval_error::proto::ToString, "EvalError", JSType::JS_EVAL_ERROR); break; case JSType::JS_REFERENCE_ERROR: - GeneralUpdateError(&error_parameter, ReferenceError::ReferenceErrorConstructor, ReferenceError::ToString, - "ReferenceError", JSType::JS_REFERENCE_ERROR); + GeneralUpdateError(&error_parameter, builtins::reference_error::ReferenceErrorConstructor, + builtins::reference_error::proto::ToString, "ReferenceError", + JSType::JS_REFERENCE_ERROR); break; case JSType::JS_TYPE_ERROR: - GeneralUpdateError(&error_parameter, TypeError::TypeErrorConstructor, TypeError::ToString, "TypeError", - JSType::JS_TYPE_ERROR); + GeneralUpdateError(&error_parameter, builtins::type_error::TypeErrorConstructor, + builtins::type_error::proto::ToString, "TypeError", JSType::JS_TYPE_ERROR); break; case JSType::JS_URI_ERROR: - GeneralUpdateError(&error_parameter, URIError::URIErrorConstructor, URIError::ToString, "URIError", - JSType::JS_URI_ERROR); + GeneralUpdateError(&error_parameter, builtins::uri_error::URIErrorConstructor, + builtins::uri_error::proto::ToString, "URIError", JSType::JS_URI_ERROR); break; case JSType::JS_SYNTAX_ERROR: - GeneralUpdateError(&error_parameter, SyntaxError::SyntaxErrorConstructor, SyntaxError::ToString, - "SyntaxError", JSType::JS_SYNTAX_ERROR); + GeneralUpdateError(&error_parameter, builtins::syntax_error::SyntaxErrorConstructor, + builtins::syntax_error::proto::ToString, "SyntaxError", JSType::JS_SYNTAX_ERROR); break; default: break; @@ -1148,7 +832,7 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandleSetTypeErrorFunction(thread_, native_error_function); JSHandle throw_type_error_function = - factory_->NewJSFunction(env, reinterpret_cast(TypeError::ThrowTypeError)); + factory_->NewJSFunction(env, reinterpret_cast(type_error::ThrowTypeError)); JSFunction::SetFunctionLength(thread_, throw_type_error_function, JSTaggedValue(1), false); JSObject::PreventExtensions(thread_, JSHandle::Cast(throw_type_error_function)); env->SetThrowTypeError(thread_, throw_type_error_function); @@ -1195,53 +879,22 @@ void Builtins::InitializeSet(const JSHandle &env, const JSHandleCreateDynClass(JSType::JS_SET, set_func_prototype_value); // Set() = new Function() JSHandle set_function( - NewBuiltinConstructor(env, set_func_prototype, BuiltinsSet::SetConstructor, "Set", FunctionLength::ZERO)); + NewBuiltinConstructor(env, set_func_prototype, builtins::set::SetConstructor, "Set", FunctionLength::ZERO)); JSHandle(set_function)->SetFunctionPrototype(thread_, set_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype JSHandle constructor_key = global_const->GetHandledConstructorString(); JSObject::SetProperty(thread_, JSHandle(set_func_prototype), constructor_key, set_function); - // set.prototype.add() - SetFunction(env, set_func_prototype, "add", BuiltinsSet::Add, FunctionLength::ONE); - // set.prototype.clear() - SetFunction(env, set_func_prototype, "clear", BuiltinsSet::Clear, FunctionLength::ZERO); - // set.prototype.delete() - SetFunction(env, set_func_prototype, "delete", BuiltinsSet::Delete, FunctionLength::ONE); - // set.prototype.has() - SetFunction(env, set_func_prototype, "has", BuiltinsSet::Has, FunctionLength::ONE); - // set.prototype.forEach() - SetFunction(env, set_func_prototype, "forEach", BuiltinsSet::ForEach, FunctionLength::ONE); - // set.prototype.entries() - SetFunction(env, set_func_prototype, "entries", BuiltinsSet::Entries, FunctionLength::ZERO); - // set.prototype.keys() - SetFunction(env, set_func_prototype, "values", BuiltinsSet::Values, FunctionLength::ZERO); - // set.prototype.values() - JSHandle keys(factory_->NewFromCanBeCompressString("keys")); - JSHandle values(factory_->NewFromCanBeCompressString("values")); - JSHandle values_func = - JSObject::GetMethod(thread_, JSHandle::Cast(set_func_prototype), values); - PropertyDescriptor descriptor(thread_, values_func, true, false, true); - JSObject::DefineOwnProperty(thread_, set_func_prototype, keys, descriptor); + + env->SetSetFunction(thread_, set_function); + env->SetSetPrototype(thread_, set_func_prototype); // @@ToStringTag SetStringTagSymbol(env, set_func_prototype, "Set"); - // 23.1.3.10get Set.prototype.size - JSHandle size_getter = CreateGetter(env, BuiltinsSet::GetSize, "size", FunctionLength::ZERO); - JSHandle size_key(factory_->NewFromCanBeCompressString("size")); - SetGetter(set_func_prototype, size_key, size_getter); - - // 23.1.2.2get Set [ @@species ] - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_getter = - CreateGetter(env, BuiltinsSet::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(set_function), species_symbol, species_getter); + SetFunctionsGenSetProto(env, set_func_prototype); - // %SetPrototype% [ @@iterator ] - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSObject::DefineOwnProperty(thread_, set_func_prototype, iterator_symbol, descriptor); - - env->SetBuiltinsSetFunction(thread_, set_function); + SetFunctionsGenSet(env, JSHandle(set_function)); } void Builtins::InitializeMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -1251,12 +904,13 @@ void Builtins::InitializeMap(const JSHandle &env, const JSHandle map_func_prototype = factory_->NewJSObject(obj_func_dynclass); JSHandle map_func_prototype_value(map_func_prototype); + // Map.prototype_or_dynclass JSHandle map_func_instance_dynclass = factory_->CreateDynClass(JSType::JS_MAP, map_func_prototype_value); // Map() = new Function() JSHandle map_function( - NewBuiltinConstructor(env, map_func_prototype, BuiltinsMap::MapConstructor, "Map", FunctionLength::ZERO)); + NewBuiltinConstructor(env, map_func_prototype, map::MapConstructor, "Map", FunctionLength::ZERO)); // Map().prototype = Map.Prototype & Map.prototype.constructor = Map() JSFunction::Cast(map_function->GetTaggedObject()) ->SetFunctionPrototype(thread_, map_func_instance_dynclass.GetTaggedValue()); @@ -1264,49 +918,14 @@ void Builtins::InitializeMap(const JSHandle &env, const JSHandle constructor_key = global_const->GetHandledConstructorString(); JSObject::SetProperty(thread_, JSHandle(map_func_prototype), constructor_key, map_function); - // map.prototype.set() - SetFunction(env, map_func_prototype, global_const->GetHandledSetString(), BuiltinsMap::Set, FunctionLength::TWO); - // map.prototype.clear() - SetFunction(env, map_func_prototype, "clear", BuiltinsMap::Clear, FunctionLength::ZERO); - // map.prototype.delete() - SetFunction(env, map_func_prototype, "delete", BuiltinsMap::Delete, FunctionLength::ONE); - // map.prototype.has() - SetFunction(env, map_func_prototype, "has", BuiltinsMap::Has, FunctionLength::ONE); - // map.prototype.get() - SetFunction(env, map_func_prototype, thread_->GlobalConstants()->GetHandledGetString(), BuiltinsMap::Get, - FunctionLength::ONE); - // map.prototype.forEach() - SetFunction(env, map_func_prototype, "forEach", BuiltinsMap::ForEach, FunctionLength::ONE); - // map.prototype.keys() - SetFunction(env, map_func_prototype, "keys", BuiltinsMap::Keys, FunctionLength::ZERO); - // map.prototype.values() - SetFunction(env, map_func_prototype, "values", BuiltinsMap::Values, FunctionLength::ZERO); - // map.prototype.entries() - SetFunction(env, map_func_prototype, "entries", BuiltinsMap::Entries, FunctionLength::ZERO); - // @@ToStringTag - SetStringTagSymbol(env, map_func_prototype, "Map"); - // 23.1.3.10get Map.prototype.size - JSHandle size_getter = CreateGetter(env, BuiltinsMap::GetSize, "size", FunctionLength::ZERO); - JSHandle size_key(factory_->NewFromCanBeCompressString("size")); - SetGetter(map_func_prototype, size_key, size_getter); - - // 23.1.2.2get Map [ @@species ] - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_getter = - CreateGetter(env, BuiltinsMap::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(map_function), species_symbol, species_getter); - - // %MapPrototype% [ @@iterator ] - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle entries(factory_->NewFromCanBeCompressString("entries")); - JSHandle entries_func = - JSObject::GetMethod(thread_, JSHandle::Cast(map_func_prototype), entries); - PropertyDescriptor descriptor(thread_, entries_func, true, false, true); - JSObject::DefineOwnProperty(thread_, map_func_prototype, iterator_symbol, descriptor); - - env->SetBuiltinsMapFunction(thread_, map_function); + env->SetMapFunction(thread_, map_function); env->SetMapPrototype(thread_, map_func_prototype); + SetFunctionsGenMapProto(env, map_func_prototype); + SetFunctionsGenMap(env, JSHandle(map_function)); + + // @@ToStringTag + SetStringTagSymbol(env, map_func_prototype, "Map"); } void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -1321,8 +940,8 @@ void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle< factory_->CreateDynClass(JSType::JS_WEAK_REF, weak_ref_func_prototype_value); weak_ref_func_instance_dynclass->SetWeakContainer(true); // WeakRef() = new Function() - JSHandle weak_ref_function(NewBuiltinConstructor( - env, weak_ref_func_prototype, BuiltinsWeakRef::Constructor, "WeakRef", FunctionLength::ONE)); + JSHandle weak_ref_function( + NewBuiltinConstructor(env, weak_ref_func_prototype, weak_ref::Constructor, "WeakRef", FunctionLength::ONE)); // WeakRef().prototype = WeakRef.Prototype & WeakRef.prototype.constructor = WeakRef() JSFunction::Cast(weak_ref_function->GetTaggedObject()) ->SetProtoOrDynClass(thread_, weak_ref_func_instance_dynclass.GetTaggedValue()); @@ -1331,8 +950,7 @@ void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle< JSHandle constructor_key = global_const->GetHandledConstructorString(); JSObject::SetProperty(thread_, JSHandle(weak_ref_func_prototype), constructor_key, weak_ref_function); - // weakref.prototype.deref() - SetFunction(env, weak_ref_func_prototype, "deref", BuiltinsWeakRef::Deref, FunctionLength::ZERO); + SetFunctionsGenWeakRefProto(env, weak_ref_func_prototype); // @@ToStringTag SetStringTagSymbol(env, weak_ref_func_prototype, "WeakRef"); } @@ -1349,7 +967,7 @@ void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle< factory_->CreateDynClass(JSType::JS_WEAK_MAP, weak_map_func_prototype_value); // WeakMap() = new Function() JSHandle weak_map_function(NewBuiltinConstructor( - env, weak_map_func_prototype, BuiltinsWeakMap::WeakMapConstructor, "WeakMap", FunctionLength::ZERO)); + env, weak_map_func_prototype, weak_map::WeakMapConstructor, "WeakMap", FunctionLength::ZERO)); // WeakMap().prototype = WeakMap.Prototype & WeakMap.prototype.constructor = WeakMap() JSFunction::Cast(weak_map_function->GetTaggedObject()) ->SetProtoOrDynClass(thread_, weak_map_func_instance_dynclass.GetTaggedValue()); @@ -1358,20 +976,10 @@ void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle< JSHandle constructor_key = global_const->GetHandledConstructorString(); JSObject::SetProperty(thread_, JSHandle(weak_map_func_prototype), constructor_key, weak_map_function); - // weakmap.prototype.set() - SetFunction(env, weak_map_func_prototype, global_const->GetHandledSetString(), BuiltinsWeakMap::Set, - FunctionLength::TWO); - // weakmap.prototype.delete() - SetFunction(env, weak_map_func_prototype, "delete", BuiltinsWeakMap::Delete, FunctionLength::ONE); - // weakmap.prototype.has() - SetFunction(env, weak_map_func_prototype, "has", BuiltinsWeakMap::Has, FunctionLength::ONE); - // weakmap.prototype.get() - SetFunction(env, weak_map_func_prototype, thread_->GlobalConstants()->GetHandledGetString(), BuiltinsWeakMap::Get, - FunctionLength::ONE); + env->SetWeakMapFunction(thread_, weak_map_function); + SetFunctionsGenWeakMapProto(env, weak_map_func_prototype); // @@ToStringTag SetStringTagSymbol(env, weak_map_func_prototype, "WeakMap"); - - env->SetBuiltinsWeakMapFunction(thread_, weak_map_function); } void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -1386,7 +994,7 @@ void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle< factory_->CreateDynClass(JSType::JS_WEAK_SET, weak_set_func_prototype_value); // Set() = new Function() JSHandle weak_set_function(NewBuiltinConstructor( - env, weak_set_func_prototype, BuiltinsWeakSet::WeakSetConstructor, "WeakSet", FunctionLength::ZERO)); + env, weak_set_func_prototype, weak_set::WeakSetConstructor, "WeakSet", FunctionLength::ZERO)); JSHandle(weak_set_function) ->SetProtoOrDynClass(thread_, weak_set_func_instance_dynclass.GetTaggedValue()); @@ -1394,17 +1002,11 @@ void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle< JSHandle constructor_key = global_const->GetHandledConstructorString(); JSObject::SetProperty(thread_, JSHandle(weak_set_func_prototype), constructor_key, weak_set_function); - // set.prototype.add() - SetFunction(env, weak_set_func_prototype, "add", BuiltinsWeakSet::Add, FunctionLength::ONE); - // set.prototype.delete() - SetFunction(env, weak_set_func_prototype, "delete", BuiltinsWeakSet::Delete, FunctionLength::ONE); - // set.prototype.has() - SetFunction(env, weak_set_func_prototype, "has", BuiltinsWeakSet::Has, FunctionLength::ONE); + env->SetWeakSetFunction(thread_, weak_set_function); + SetFunctionsGenWeakSetProto(env, weak_set_func_prototype); // @@ToStringTag SetStringTagSymbol(env, weak_set_func_prototype, "WeakSet"); - - env->SetBuiltinsWeakSetFunction(thread_, weak_set_function); } void Builtins::InitializeMath(const JSHandle &env, @@ -1413,50 +1015,18 @@ void Builtins::InitializeMath(const JSHandle &env, [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle math_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); JSHandle math_object = factory_->NewJSObject(math_dynclass); - SetFunction(env, math_object, "abs", Math::Abs, FunctionLength::ONE); - SetFunction(env, math_object, "acos", Math::Acos, FunctionLength::ONE); - SetFunction(env, math_object, "acosh", Math::Acosh, FunctionLength::ONE); - SetFunction(env, math_object, "asin", Math::Asin, FunctionLength::ONE); - SetFunction(env, math_object, "asinh", Math::Asinh, FunctionLength::ONE); - SetFunction(env, math_object, "atan", Math::Atan, FunctionLength::ONE); - SetFunction(env, math_object, "atanh", Math::Atanh, FunctionLength::ONE); - SetFunction(env, math_object, "atan2", Math::Atan2, FunctionLength::TWO); - SetFunction(env, math_object, "cbrt", Math::Cbrt, FunctionLength::ONE); - SetFunction(env, math_object, "ceil", Math::Ceil, FunctionLength::ONE); - SetFunction(env, math_object, "clz32", Math::Clz32, FunctionLength::ONE); - SetFunction(env, math_object, "cos", Math::Cos, FunctionLength::ONE); - SetFunction(env, math_object, "cosh", Math::Cosh, FunctionLength::ONE); - SetFunction(env, math_object, "exp", Math::Exp, FunctionLength::ONE); - SetFunction(env, math_object, "expm1", Math::Expm1, FunctionLength::ONE); - SetFunction(env, math_object, "floor", Math::Floor, FunctionLength::ONE); - SetFunction(env, math_object, "fround", Math::Fround, FunctionLength::ONE); - SetFunction(env, math_object, "hypot", Math::Hypot, FunctionLength::TWO); - SetFunction(env, math_object, "imul", Math::Imul, FunctionLength::TWO); - SetFunction(env, math_object, "log", Math::Log, FunctionLength::ONE); - SetFunction(env, math_object, "log1p", Math::Log1p, FunctionLength::ONE); - SetFunction(env, math_object, "log10", Math::Log10, FunctionLength::ONE); - SetFunction(env, math_object, "log2", Math::Log2, FunctionLength::ONE); - SetFunction(env, math_object, "max", Math::Max, FunctionLength::TWO); - SetFunction(env, math_object, "min", Math::Min, FunctionLength::TWO); - SetFunction(env, math_object, "pow", Math::Pow, FunctionLength::TWO); - SetFunction(env, math_object, "random", Math::Random, FunctionLength::ZERO); - SetFunction(env, math_object, "round", Math::Round, FunctionLength::ONE); - SetFunction(env, math_object, "sign", Math::Sign, FunctionLength::ONE); - SetFunction(env, math_object, "sin", Math::Sin, FunctionLength::ONE); - SetFunction(env, math_object, "sinh", Math::Sinh, FunctionLength::ONE); - SetFunction(env, math_object, "sqrt", Math::Sqrt, FunctionLength::ONE); - SetFunction(env, math_object, "tan", Math::Tan, FunctionLength::ONE); - SetFunction(env, math_object, "tanh", Math::Tanh, FunctionLength::ONE); - SetFunction(env, math_object, "trunc", Math::Trunc, FunctionLength::ONE); - - SetConstant(math_object, "E", JSTaggedValue(Math::E)); - SetConstant(math_object, "LN10", JSTaggedValue(Math::LN10)); - SetConstant(math_object, "LN2", JSTaggedValue(Math::LN2)); - SetConstant(math_object, "LOG10E", JSTaggedValue(Math::LOG10E)); - SetConstant(math_object, "LOG2E", JSTaggedValue(Math::LOG2E)); - SetConstant(math_object, "PI", JSTaggedValue(Math::PI)); - SetConstant(math_object, "SQRT1_2", JSTaggedValue(Math::SQRT1_2)); - SetConstant(math_object, "SQRT2", JSTaggedValue(Math::SQRT2)); + + env->SetMathFunction(thread_, math_object); + SetFunctionsGenMath(env, math_object); + + SetConstant(math_object, "E", math::GetPropE()); + SetConstant(math_object, "LN10", math::GetPropLN10()); + SetConstant(math_object, "LN2", math::GetPropLN2()); + SetConstant(math_object, "LOG10E", math::GetPropLOG10E()); + SetConstant(math_object, "LOG2E", math::GetPropLOG2E()); + SetConstant(math_object, "PI", math::GetPropPI()); + SetConstant(math_object, "SQRT1_2", math::GetPropSQRT1_2()); + SetConstant(math_object, "SQRT2", math::GetPropSQRT2()); JSHandle math_string(factory_->NewFromCanBeCompressString("Math")); JSHandle global_object(thread_, env->GetGlobalObject()); @@ -1464,7 +1034,6 @@ void Builtins::InitializeMath(const JSHandle &env, JSObject::DefineOwnProperty(thread_, global_object, math_string, math_desc); // @@ToStringTag SetStringTagSymbol(env, math_object, "Math"); - env->SetMathFunction(thread_, math_object); } void Builtins::InitializeJson(const JSHandle &env, @@ -1474,8 +1043,8 @@ void Builtins::InitializeJson(const JSHandle &env, JSHandle json_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); JSHandle json_object = factory_->NewJSObject(json_dynclass); - SetFunction(env, json_object, "parse", Json::Parse, FunctionLength::TWO); - SetFunction(env, json_object, "stringify", Json::Stringify, FunctionLength::THREE); + env->SetJsonFunction(thread_, json_object); + SetFunctionsGenJson(env, json_object); PropertyDescriptor json_desc(thread_, JSHandle::Cast(json_object), true, false, true); JSHandle json_string(factory_->NewFromCanBeCompressString("JSON")); @@ -1483,7 +1052,6 @@ void Builtins::InitializeJson(const JSHandle &env, JSObject::DefineOwnProperty(thread_, global_object, json_string, json_desc); // @@ToStringTag SetStringTagSymbol(env, json_object, "JSON"); - env->SetJsonFunction(thread_, json_object); } void Builtins::InitializeString(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const @@ -1500,80 +1068,16 @@ void Builtins::InitializeString(const JSHandle &env, const JSHandleCreateDynClass(JSType::JS_PRIMITIVE_REF, string_func_prototype_value); // String = new Function() - JSHandle string_function(NewBuiltinConstructor( - env, string_func_prototype, BuiltinsString::StringConstructor, "String", FunctionLength::ONE)); + JSHandle string_function( + NewBuiltinConstructor(env, string_func_prototype, string::StringConstructor, "String", FunctionLength::ONE)); string_function.GetObject()->SetFunctionPrototype(thread_, string_func_instance_dynclass.GetTaggedValue()); - // String.prototype method - SetFunction(env, string_func_prototype, "charAt", BuiltinsString::CharAt, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "charCodeAt", BuiltinsString::CharCodeAt, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "codePointAt", BuiltinsString::CodePointAt, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "concat", BuiltinsString::Concat, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "endsWith", BuiltinsString::EndsWith, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "includes", BuiltinsString::Includes, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "indexOf", BuiltinsString::IndexOf, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "lastIndexOf", BuiltinsString::LastIndexOf, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "localeCompare", BuiltinsString::LocaleCompare, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "match", BuiltinsString::Match, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "matchAll", BuiltinsString::MatchAll, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "normalize", BuiltinsString::Normalize, FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "padEnd", BuiltinsString::PadEnd, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "padStart", BuiltinsString::PadStart, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "repeat", BuiltinsString::Repeat, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "replace", BuiltinsString::Replace, FunctionLength::TWO); - SetFunction(env, string_func_prototype, "replaceAll", BuiltinsString::ReplaceAll, FunctionLength::TWO); - SetFunction(env, string_func_prototype, "search", BuiltinsString::Search, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "slice", BuiltinsString::Slice, FunctionLength::TWO); - SetFunction(env, string_func_prototype, "split", BuiltinsString::Split, FunctionLength::TWO); - SetFunction(env, string_func_prototype, "startsWith", BuiltinsString::StartsWith, FunctionLength::ONE); - SetFunction(env, string_func_prototype, "substring", BuiltinsString::Substring, FunctionLength::TWO); - SetFunction(env, string_func_prototype, "substr", BuiltinsString::SubStr, FunctionLength::TWO); - SetFunction(env, string_func_prototype, "toLocaleLowerCase", BuiltinsString::ToLocaleLowerCase, - FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "toLocaleUpperCase", BuiltinsString::ToLocaleUpperCase, - FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "toLowerCase", BuiltinsString::ToLowerCase, FunctionLength::ZERO); - SetFunction(env, string_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), - BuiltinsString::ToString, FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "toUpperCase", BuiltinsString::ToUpperCase, FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "trim", BuiltinsString::Trim, FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "trimEnd", BuiltinsString::TrimEnd, FunctionLength::ZERO); - SetFunction(env, string_func_prototype, "trimStart", BuiltinsString::TrimStart, FunctionLength::ZERO); - - // trimRight - JSHandle trim_right(factory_->NewFromString("trimRight")); - JSHandle trim_end(factory_->NewFromString("trimEnd")); - JSHandle trim_end_func = - JSObject::GetMethod(thread_, JSHandle::Cast(string_func_prototype), trim_end); - PropertyDescriptor trim_right_descriptor(thread_, trim_end_func, true, false, true); - JSObject::DefineOwnProperty(thread_, string_func_prototype, trim_right, trim_right_descriptor); - - // trimLeft - JSHandle trim_left(factory_->NewFromString("trimLeft")); - JSHandle trim_start(factory_->NewFromString("trimStart")); - JSHandle trim_start_func = - JSObject::GetMethod(thread_, JSHandle::Cast(string_func_prototype), trim_start); - PropertyDescriptor trim_leftdescriptor(thread_, trim_start_func, true, false, true); - JSObject::DefineOwnProperty(thread_, string_func_prototype, trim_left, trim_leftdescriptor); - - SetFunction(env, string_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), - BuiltinsString::ValueOf, FunctionLength::ZERO); - SetFunctionAtSymbol(env, string_func_prototype, env->GetIteratorSymbol(), "[Symbol.iterator]", - BuiltinsString::GetStringIterator, FunctionLength::ZERO); - - // String method - SetFunction(env, string_function, "fromCharCode", BuiltinsString::FromCharCode, FunctionLength::ONE); - SetFunction(env, string_function, "fromCodePoint", BuiltinsString::FromCodePoint, FunctionLength::ONE); - SetFunction(env, string_function, "raw", BuiltinsString::Raw, FunctionLength::ONE); - - // String.prototype.length - JSHandle length_getter = - CreateGetter(env, BuiltinsString::GetLength, "length", FunctionLength::ZERO); - JSHandle length_key(factory_->NewFromCanBeCompressString("length")); - SetGetter(string_func_prototype, length_key, length_getter); - env->SetStringFunction(thread_, string_function); + env->SetStringPrototype(thread_, string_func_prototype); + + SetFunctionsGenString(env, string_function); + SetFunctionsGenStringProto(env, string_func_prototype); } void Builtins::InitializeStringIterator(const JSHandle &env, @@ -1590,11 +1094,10 @@ void Builtins::InitializeStringIterator(const JSHandle &env, factory_->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR)); str_iter_function->SetFunctionPrototype(thread_, str_iter_func_instance_dynclass.GetTaggedValue()); - SetFunction(env, str_iter_prototype, "next", StringIterator::Next, FunctionLength::ZERO); - SetStringTagSymbol(env, str_iter_prototype, "String Iterator"); - - env->SetStringIterator(thread_, str_iter_function); + env->SetStringIteratorFunction(thread_, str_iter_function); env->SetStringIteratorPrototype(thread_, str_iter_prototype); + SetFunctionsGenStringIteratorProto(env, str_iter_prototype); + SetStringTagSymbol(env, str_iter_prototype, "String Iterator"); } void Builtins::InitializeIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -1602,16 +1105,9 @@ void Builtins::InitializeIterator(const JSHandle &env, const JSHandle [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype JSHandle iterator_prototype = factory_->NewJSObject(obj_func_dynclass); - // Iterator.prototype.next() - SetFunction(env, iterator_prototype, "next", BuiltinsIterator::Next, FunctionLength::ONE); - // Iterator.prototype.return() - SetFunction(env, iterator_prototype, "return", BuiltinsIterator::Return, FunctionLength::ONE); - // Iterator.prototype.throw() - SetFunction(env, iterator_prototype, "throw", BuiltinsIterator::Throw, FunctionLength::ONE); - // %IteratorPrototype% [ @@iterator ] - SetFunctionAtSymbol(env, iterator_prototype, env->GetIteratorSymbol(), "[Symbol.iterator]", - BuiltinsIterator::GetIteratorObj, FunctionLength::ZERO); + env->SetIteratorPrototype(thread_, iterator_prototype); + SetFunctionsGenIteratorProto(env, iterator_prototype); // Iterator.dynclass JSHandle iterator_func_dynclass = @@ -1631,9 +1127,9 @@ void Builtins::InitializeAsyncIterator(const JSHandle &env, [[maybe_unused]] EcmaHandleScope scope(thread_); // AsyncIterator.prototype JSHandle async_iterator_prototype = factory_->NewJSObject(obj_func_dynclass); - // %AsyncIteratorPrototype% [ @@asyncIterator ] - SetFunctionAtSymbol(env, async_iterator_prototype, env->GetAsyncIteratorSymbol(), "[Symbol.asyncIterator]", - BuiltinsAsyncIterator::GetAsyncIteratorObj, FunctionLength::ZERO); + + SetFunctionsGenAsyncIteratorProto(env, async_iterator_prototype); + env->SetAsyncIteratorPrototype(thread_, async_iterator_prototype); } @@ -1646,10 +1142,9 @@ void Builtins::InitializeForinIterator(const JSHandle &env, JSHandle dynclass = factory_->CreateDynClass( JSType::JS_FORIN_ITERATOR, JSHandle(forin_iterator_prototype)); - // Iterator.prototype.next() - SetFunction(env, forin_iterator_prototype, "next", JSForInIterator::Next, FunctionLength::ONE); env->SetForinIteratorPrototype(thread_, forin_iterator_prototype); env->SetForinIteratorClass(thread_, dynclass); + SetFunctionsGenForInIteratorProto(env, forin_iterator_prototype); } void Builtins::InitializeSetIterator(const JSHandle &env, @@ -1657,8 +1152,8 @@ void Builtins::InitializeSetIterator(const JSHandle &env, { // SetIterator.prototype JSHandle set_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); - // Iterator.prototype.next() - SetFunction(env, set_iterator_prototype, "next", JSSetIterator::Next, FunctionLength::ZERO); + + SetFunctionsGenSetIteratorProto(env, set_iterator_prototype); SetStringTagSymbol(env, set_iterator_prototype, "Set Iterator"); env->SetSetIteratorPrototype(thread_, set_iterator_prototype); } @@ -1668,8 +1163,8 @@ void Builtins::InitializeMapIterator(const JSHandle &env, { // MapIterator.prototype JSHandle map_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); - // Iterator.prototype.next() - SetFunction(env, map_iterator_prototype, "next", JSMapIterator::Next, FunctionLength::ZERO); + SetFunctionsGenMapIteratorProto(env, map_iterator_prototype); + SetStringTagSymbol(env, map_iterator_prototype, "Map Iterator"); env->SetMapIteratorPrototype(thread_, map_iterator_prototype); } @@ -1679,8 +1174,8 @@ void Builtins::InitializeArrayIterator(const JSHandle &env, { // ArrayIterator.prototype JSHandle array_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); - // Iterator.prototype.next() - SetFunction(env, array_iterator_prototype, "next", JSArrayIterator::Next, FunctionLength::ZERO); + + SetFunctionsGenArrayIteratorProto(env, array_iterator_prototype); SetStringTagSymbol(env, array_iterator_prototype, "Array Iterator"); env->SetArrayIteratorPrototype(thread_, array_iterator_prototype); } @@ -1690,8 +1185,8 @@ void Builtins::InitializeRegexpIterator(const JSHandle &env, { // RegExpIterator.prototype JSHandle reg_exp_iterator_prototype(factory_->NewJSObject(iterator_func_class)); - // Iterator.prototype.next() - SetFunction(env, reg_exp_iterator_prototype, "next", JSRegExpIterator::Next, FunctionLength::ZERO); + + SetFunctionsGenRegExpIteratorProto(env, reg_exp_iterator_prototype); SetStringTagSymbol(env, reg_exp_iterator_prototype, "RegExp String Iterator"); env->SetRegExpIteratorPrototype(thread_, reg_exp_iterator_prototype); } @@ -1709,72 +1204,13 @@ void Builtins::InitializeRegExp(const JSHandle &env) // RegExp = new Function() JSHandle regexp_function( - NewBuiltinConstructor(env, reg_prototype, RegExp::RegExpConstructor, "RegExp", FunctionLength::TWO)); + NewBuiltinConstructor(env, reg_prototype, reg_exp::RegExpConstructor, "RegExp", FunctionLength::TWO)); JSHandle(regexp_function) ->SetFunctionPrototype(thread_, regexp_func_instance_dynclass.GetTaggedValue()); - // RegExp.prototype method - SetFunction(env, reg_prototype, "exec", RegExp::Exec, FunctionLength::ONE); - SetFunction(env, reg_prototype, "test", RegExp::Test, FunctionLength::ONE); - SetFunction(env, reg_prototype, thread_->GlobalConstants()->GetHandledToStringString(), RegExp::ToString, - FunctionLength::ZERO); - - JSHandle flags_getter = CreateGetter(env, RegExp::GetFlags, "flags", FunctionLength::ZERO); - JSHandle flags_key(factory_->NewFromCanBeCompressString("flags")); - SetGetter(reg_prototype, flags_key, flags_getter); - - JSHandle source_getter = CreateGetter(env, RegExp::GetSource, "source", FunctionLength::ZERO); - JSHandle source_key(factory_->NewFromCanBeCompressString("source")); - SetGetter(reg_prototype, source_key, source_getter); - - JSHandle global_getter = CreateGetter(env, RegExp::GetGlobal, "global", FunctionLength::ZERO); - JSHandle global_key(factory_->NewFromCanBeCompressString("global")); - SetGetter(reg_prototype, global_key, global_getter); - - JSHandle ignore_case_getter = - CreateGetter(env, RegExp::GetIgnoreCase, "ignoreCase", FunctionLength::ZERO); - JSHandle ignore_case_key(factory_->NewFromCanBeCompressString("ignoreCase")); - SetGetter(reg_prototype, ignore_case_key, ignore_case_getter); - - JSHandle multiline_getter = - CreateGetter(env, RegExp::GetMultiline, "multiline", FunctionLength::ZERO); - JSHandle multiline_key(factory_->NewFromCanBeCompressString("multiline")); - SetGetter(reg_prototype, multiline_key, multiline_getter); - - JSHandle dot_all_getter = CreateGetter(env, RegExp::GetDotAll, "dotAll", FunctionLength::ZERO); - JSHandle dot_all_key(factory_->NewFromCanBeCompressString("dotAll")); - SetGetter(reg_prototype, dot_all_key, dot_all_getter); - - JSHandle sticky_getter = CreateGetter(env, RegExp::GetSticky, "sticky", FunctionLength::ZERO); - JSHandle sticky_key(factory_->NewFromCanBeCompressString("sticky")); - SetGetter(reg_prototype, sticky_key, sticky_getter); - - JSHandle unicode_getter = CreateGetter(env, RegExp::GetUnicode, "unicode", FunctionLength::ZERO); - JSHandle unicode_key(factory_->NewFromCanBeCompressString("unicode")); - SetGetter(reg_prototype, unicode_key, unicode_getter); - - // Set RegExp [ @@species ] - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_getter = - CreateGetter(env, BuiltinsMap::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(regexp_function), species_symbol, species_getter); - - // Set RegExp.prototype[@@split] - SetFunctionAtSymbol(env, reg_prototype, env->GetSplitSymbol(), "[Symbol.split]", RegExp::Split, - FunctionLength::TWO); - // Set RegExp.prototype[@@search] - SetFunctionAtSymbol(env, reg_prototype, env->GetSearchSymbol(), "[Symbol.search]", RegExp::Search, - FunctionLength::ONE); - // Set RegExp.prototype[@@match] - SetFunctionAtSymbol(env, reg_prototype, env->GetMatchSymbol(), "[Symbol.match]", RegExp::Match, - FunctionLength::ONE); - // Set RegExp.prototype[@@matchAll] - SetFunctionAtSymbol(env, reg_prototype, env->GetMatchAllSymbol(), "[Symbol.matchAll]", RegExp::MatchAll, - FunctionLength::ONE); - // Set RegExp.prototype[@@replace] - SetFunctionAtSymbol(env, reg_prototype, env->GetReplaceSymbol(), "[Symbol.replace]", RegExp::Replace, - FunctionLength::TWO); + SetFunctionsGenRegExpProto(env, reg_prototype); + SetFunctionsGenRegExp(env, regexp_function); env->SetRegExpFunction(thread_, regexp_function); auto global_const = const_cast(thread_->GlobalConstants()); @@ -1800,8 +1236,8 @@ void Builtins::InitializeArray(const JSHandle &env, JSHandle arr_func_instance_dynclass = factory_->CreateJSArrayInstanceClass(arr_func_prototype_value); // Array = new Function() - JSHandle array_function( - NewBuiltinConstructor(env, arr_func_prototype, BuiltinsArray::ArrayConstructor, "Array", FunctionLength::ONE)); + JSHandle array_function(NewBuiltinConstructor(env, arr_func_prototype, builtins::array::ArrayConstructor, + "Array", FunctionLength::ONE)); JSHandle array_func_function(array_function); // Set the [[Realm]] internal slot of F to the running execution context's Realm @@ -1811,59 +1247,12 @@ void Builtins::InitializeArray(const JSHandle &env, array_func_function->SetFunctionPrototype(thread_, arr_func_instance_dynclass.GetTaggedValue()); - // Array.prototype method - SetFunction(env, arr_func_prototype, "concat", BuiltinsArray::Concat, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "copyWithin", BuiltinsArray::CopyWithin, FunctionLength::TWO); - SetFunction(env, arr_func_prototype, "entries", BuiltinsArray::Entries, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "every", BuiltinsArray::Every, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "flat", BuiltinsArray::Flat, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "flatMap", BuiltinsArray::FlatMap, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "fill", BuiltinsArray::Fill, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "filter", BuiltinsArray::Filter, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "find", BuiltinsArray::Find, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "findIndex", BuiltinsArray::FindIndex, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "forEach", BuiltinsArray::ForEach, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "includes", BuiltinsArray::Includes, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "indexOf", BuiltinsArray::IndexOf, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "join", BuiltinsArray::Join, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "keys", BuiltinsArray::Keys, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "lastIndexOf", BuiltinsArray::LastIndexOf, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "map", BuiltinsArray::Map, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "pop", BuiltinsArray::Pop, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "push", BuiltinsArray::Push, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "reduce", BuiltinsArray::Reduce, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "reduceRight", BuiltinsArray::ReduceRight, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "reverse", BuiltinsArray::Reverse, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "shift", BuiltinsArray::Shift, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "slice", BuiltinsArray::Slice, FunctionLength::TWO); - SetFunction(env, arr_func_prototype, "some", BuiltinsArray::Some, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "sort", BuiltinsArray::Sort, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "splice", BuiltinsArray::Splice, FunctionLength::TWO); - SetFunction(env, arr_func_prototype, thread_->GlobalConstants()->GetHandledToLocaleStringString(), - BuiltinsArray::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), - BuiltinsArray::ToString, FunctionLength::ZERO); - SetFunction(env, arr_func_prototype, "unshift", BuiltinsArray::Unshift, FunctionLength::ONE); - SetFunction(env, arr_func_prototype, "values", BuiltinsArray::Values, FunctionLength::ZERO); - - // %ArrayPrototype% [ @@iterator ] - JSHandle values(factory_->NewFromCanBeCompressString("values")); - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle values_func = - JSObject::GetMethod(thread_, JSHandle::Cast(arr_func_prototype), values); - PropertyDescriptor iteartor_desc(thread_, values_func, true, false, true); - JSObject::DefineOwnProperty(thread_, arr_func_prototype, iterator_symbol, iteartor_desc); - - // Array method - SetFunction(env, array_function, "from", BuiltinsArray::From, FunctionLength::ONE); - SetFunction(env, array_function, "isArray", BuiltinsArray::IsArray, FunctionLength::ONE); - SetFunction(env, array_function, "of", BuiltinsArray::Of, FunctionLength::ZERO); - - // 22.1.2.5 get %Array% [ @@species ] - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_getter = - CreateGetter(env, BuiltinsArray::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(array_function), species_symbol, species_getter); + env->SetArrayFunction(thread_, array_function); + env->SetArrayPrototype(thread_, arr_func_prototype); + + SetFunctionsGenArrayProto(env, arr_func_prototype); + + SetFunctionsGenArray(env, array_function); const int arr_proto_len = 0; JSHandle key_string = thread_->GlobalConstants()->GetHandledLengthString(); @@ -1875,15 +1264,7 @@ void Builtins::InitializeArray(const JSHandle &env, PropertyDescriptor desc(thread_); JSObject::GetOwnProperty(thread_, arr_func_prototype, values_key, desc); - // Array.prototype [ @@unscopables ] - JSHandle unscopables_symbol = env->GetUnscopablesSymbol(); - JSHandle unscopables_getter = - CreateGetter(env, BuiltinsArray::Unscopables, "[Symbol.unscopables]", FunctionLength::ZERO); - SetGetter(JSHandle(arr_func_prototype), unscopables_symbol, unscopables_getter); - env->SetArrayProtoValuesFunction(thread_, desc.GetValue()); - env->SetArrayFunction(thread_, array_function); - env->SetArrayPrototype(thread_, arr_func_prototype); } void Builtins::InitializeTypedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const @@ -1898,92 +1279,12 @@ void Builtins::InitializeTypedArray(const JSHandle &env, const JSHand factory_->CreateDynClass(JSType::JS_TYPED_ARRAY, typed_arr_func_prototype_value); // TypedArray = new Function() - JSHandle typed_array_function(NewBuiltinConstructor(env, typed_arr_func_prototype, - BuiltinsTypedArray::TypedArrayBaseConstructor, - "TypedArray", FunctionLength::ZERO)); + JSHandle typed_array_function(NewBuiltinConstructor( + env, typed_arr_func_prototype, typed_array::TypedArrayBaseConstructor, "TypedArray", FunctionLength::ZERO)); JSHandle(typed_array_function) ->SetProtoOrDynClass(thread_, typed_arr_func_instance_dynclass.GetTaggedValue()); - // TypedArray.prototype method - SetFunction(env, typed_arr_func_prototype, "copyWithin", BuiltinsTypedArray::CopyWithin, FunctionLength::TWO); - SetFunction(env, typed_arr_func_prototype, "entries", BuiltinsTypedArray::Entries, FunctionLength::ZERO); - SetFunction(env, typed_arr_func_prototype, "every", BuiltinsTypedArray::Every, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "fill", BuiltinsTypedArray::Fill, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "filter", BuiltinsTypedArray::Filter, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "find", BuiltinsTypedArray::Find, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "findIndex", BuiltinsTypedArray::FindIndex, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "forEach", BuiltinsTypedArray::ForEach, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "includes", BuiltinsTypedArray::Includes, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "indexOf", BuiltinsTypedArray::IndexOf, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "join", BuiltinsTypedArray::Join, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "keys", BuiltinsTypedArray::Keys, FunctionLength::ZERO); - SetFunction(env, typed_arr_func_prototype, "lastIndexOf", BuiltinsTypedArray::LastIndexOf, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "map", BuiltinsTypedArray::Map, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "reduce", BuiltinsTypedArray::Reduce, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "reduceRight", BuiltinsTypedArray::ReduceRight, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "reverse", BuiltinsTypedArray::Reverse, FunctionLength::ZERO); - SetFunction(env, typed_arr_func_prototype, "set", BuiltinsTypedArray::Set, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "slice", BuiltinsTypedArray::Slice, FunctionLength::TWO); - SetFunction(env, typed_arr_func_prototype, "some", BuiltinsTypedArray::Some, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "sort", BuiltinsTypedArray::Sort, FunctionLength::ONE); - SetFunction(env, typed_arr_func_prototype, "subarray", BuiltinsTypedArray::Subarray, FunctionLength::TWO); - SetFunction(env, typed_arr_func_prototype, thread_->GlobalConstants()->GetHandledToLocaleStringString(), - BuiltinsTypedArray::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, typed_arr_func_prototype, "values", BuiltinsTypedArray::Values, FunctionLength::ZERO); - - JSHandle buffer_getter = - CreateGetter(env, BuiltinsTypedArray::GetBuffer, "buffer", FunctionLength::ZERO); - JSHandle buffer_key(factory_->NewFromCanBeCompressString("buffer")); - SetGetter(typed_arr_func_prototype, buffer_key, buffer_getter); - - JSHandle byte_length_getter = - CreateGetter(env, BuiltinsTypedArray::GetByteLength, "byteLength", FunctionLength::ZERO); - JSHandle byte_length_key(factory_->NewFromCanBeCompressString("byteLength")); - SetGetter(typed_arr_func_prototype, byte_length_key, byte_length_getter); - - JSHandle byte_offset_getter = - CreateGetter(env, BuiltinsTypedArray::GetByteOffset, "byteOffset", FunctionLength::ZERO); - JSHandle byte_offset_key(factory_->NewFromCanBeCompressString("byteOffset")); - SetGetter(typed_arr_func_prototype, byte_offset_key, byte_offset_getter); - - JSHandle length_getter = - CreateGetter(env, BuiltinsTypedArray::GetLength, "length", FunctionLength::ZERO); - JSHandle length_key(factory_->NewFromCanBeCompressString("length")); - SetGetter(typed_arr_func_prototype, length_key, length_getter); - - // %TypedArray%.prototype.toString() - JSHandle arr_func_prototype = env->GetArrayPrototype(); - JSHandle to_string_func = - JSObject::GetMethod(thread_, arr_func_prototype, thread_->GlobalConstants()->GetHandledToStringString()); - PropertyDescriptor to_string_desc(thread_, to_string_func, true, false, true); - JSObject::DefineOwnProperty(thread_, typed_arr_func_prototype, - thread_->GlobalConstants()->GetHandledToStringString(), to_string_desc); - - // %TypedArray%.prototype [ @@iterator ] ( ) - JSHandle values(factory_->NewFromCanBeCompressString("values")); - JSHandle iterator_symbol = env->GetIteratorSymbol(); - JSHandle values_func = - JSObject::GetMethod(thread_, JSHandle::Cast(typed_arr_func_prototype), values); - PropertyDescriptor iteartor_desc(thread_, values_func, true, false, true); - JSObject::DefineOwnProperty(thread_, typed_arr_func_prototype, iterator_symbol, iteartor_desc); - - // 22.2.3.31 get %TypedArray%.prototype [ @@toStringTag ] - JSHandle to_string_tag_symbol = env->GetToStringTagSymbol(); - JSHandle to_string_tag_getter = - CreateGetter(env, BuiltinsTypedArray::ToStringTag, "[Symbol.toStringTag]", FunctionLength::ZERO); - SetGetter(typed_arr_func_prototype, to_string_tag_symbol, to_string_tag_getter); - - // TypedArray method - SetFunction(env, typed_array_function, "from", BuiltinsTypedArray::From, FunctionLength::ONE); - SetFunction(env, typed_array_function, "of", BuiltinsTypedArray::Of, FunctionLength::ZERO); - - // 22.2.2.4 get %TypedArray% [ @@species ] - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_getter = - CreateGetter(env, BuiltinsTypedArray::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(typed_array_function), species_symbol, species_getter); - env->SetTypedArrayFunction(thread_, typed_array_function.GetTaggedValue()); env->SetTypedArrayPrototype(thread_, typed_arr_func_prototype); @@ -1992,6 +1293,10 @@ void Builtins::InitializeTypedArray(const JSHandle &env, const JSHand specific_typed_array_func_class->SetConstructor(true); env->SetSpecificTypedArrayFunctionClass(thread_, specific_typed_array_func_class); + SetFunctionsGenTypedArrayProto(env, typed_arr_func_prototype); + + SetFunctionsGenTypedArray(env, typed_array_function); + InitializeInt8Array(env, typed_arr_func_instance_dynclass); InitializeUint8Array(env, typed_arr_func_instance_dynclass); InitializeUint8ClampedArray(env, typed_arr_func_instance_dynclass); @@ -2017,8 +1322,8 @@ void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandl factory_->CreateDynClass(JSType::JS_INT8_ARRAY, int8_arr_func_prototype_value); // Int8Array = new Function() - JSHandle int8_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Int8ArrayConstructor)); + JSHandle int8_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(int8_array::Int8ArrayConstructor)); InitializeCtor(env, int8_arr_func_prototype, int8_array_function, "Int8Array", FunctionLength::THREE); int8_array_function->SetProtoOrDynClass(thread_, int8_arr_func_instance_dynclass.GetTaggedValue()); @@ -2041,8 +1346,8 @@ void Builtins::InitializeUint8Array(const JSHandle &env, const JSHand factory_->CreateDynClass(JSType::JS_UINT8_ARRAY, uint8_arr_func_prototype_value); // Uint8Array = new Function() - JSHandle uint8_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Uint8ArrayConstructor)); + JSHandle uint8_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(uint8_array::Uint8ArrayConstructor)); InitializeCtor(env, uint8_arr_func_prototype, uint8_array_function, "Uint8Array", FunctionLength::THREE); uint8_array_function->SetProtoOrDynClass(thread_, uint8_arr_func_instance_dynclass.GetTaggedValue()); @@ -2067,7 +1372,7 @@ void Builtins::InitializeUint8ClampedArray(const JSHandle &env, // Uint8ClampedArray = new Function() JSHandle uint8_clamped_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Uint8ClampedArrayConstructor)); + env, reinterpret_cast(uint8_clamped_array::Uint8ClampedArrayConstructor)); InitializeCtor(env, uint8_clamped_arr_func_prototype, uint8_clamped_array_function, "Uint8ClampedArray", FunctionLength::THREE); @@ -2093,8 +1398,8 @@ void Builtins::InitializeInt16Array(const JSHandle &env, const JSHand factory_->CreateDynClass(JSType::JS_INT16_ARRAY, int16_arr_func_prototype_value); // Int16Array = new Function() - JSHandle int16_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Int16ArrayConstructor)); + JSHandle int16_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(int16_array::Int16ArrayConstructor)); InitializeCtor(env, int16_arr_func_prototype, int16_array_function, "Int16Array", FunctionLength::THREE); int16_array_function->SetProtoOrDynClass(thread_, int16_arr_func_instance_dynclass.GetTaggedValue()); @@ -2117,8 +1422,8 @@ void Builtins::InitializeUint16Array(const JSHandle &env, const JSHan factory_->CreateDynClass(JSType::JS_UINT16_ARRAY, uint16_arr_func_prototype_value); // Uint16Array = new Function() - JSHandle uint16_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Uint16ArrayConstructor)); + JSHandle uint16_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(uint16_array::Uint16ArrayConstructor)); InitializeCtor(env, uint16_arr_func_prototype, uint16_array_function, "Uint16Array", FunctionLength::THREE); uint16_array_function->SetProtoOrDynClass(thread_, uint16_arr_func_instance_dynclass.GetTaggedValue()); @@ -2141,8 +1446,8 @@ void Builtins::InitializeInt32Array(const JSHandle &env, const JSHand factory_->CreateDynClass(JSType::JS_INT32_ARRAY, int32_arr_func_prototype_value); // Int32Array = new Function() - JSHandle int32_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Int32ArrayConstructor)); + JSHandle int32_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(int32_array::Int32ArrayConstructor)); InitializeCtor(env, int32_arr_func_prototype, int32_array_function, "Int32Array", FunctionLength::THREE); int32_array_function->SetProtoOrDynClass(thread_, int32_arr_func_instance_dynclass.GetTaggedValue()); @@ -2165,8 +1470,8 @@ void Builtins::InitializeUint32Array(const JSHandle &env, const JSHan factory_->CreateDynClass(JSType::JS_UINT32_ARRAY, uint32_arr_func_prototype_value); // Uint32Array = new Function() - JSHandle uint32_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Uint32ArrayConstructor)); + JSHandle uint32_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(uint32_array::Uint32ArrayConstructor)); InitializeCtor(env, uint32_arr_func_prototype, uint32_array_function, "Uint32Array", FunctionLength::THREE); uint32_array_function->SetProtoOrDynClass(thread_, uint32_arr_func_instance_dynclass.GetTaggedValue()); @@ -2189,8 +1494,8 @@ void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHa factory_->CreateDynClass(JSType::JS_FLOAT32_ARRAY, float32_arr_func_prototype_value); // Float32Array = new Function() - JSHandle float32_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Float32ArrayConstructor)); + JSHandle float32_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(float32_array::Float32ArrayConstructor)); InitializeCtor(env, float32_arr_func_prototype, float32_array_function, "Float32Array", FunctionLength::THREE); float32_array_function->SetProtoOrDynClass(thread_, float32_arr_func_instance_dynclass.GetTaggedValue()); @@ -2213,8 +1518,8 @@ void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHa factory_->CreateDynClass(JSType::JS_FLOAT64_ARRAY, float64_arr_func_prototype_value); // Float64Array = new Function() - JSHandle float64_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::Float64ArrayConstructor)); + JSHandle float64_array_function = + factory_->NewSpecificTypedArrayFunction(env, reinterpret_cast(float64_array::Float64ArrayConstructor)); InitializeCtor(env, float64_arr_func_prototype, float64_array_function, "Float64Array", FunctionLength::THREE); float64_array_function->SetProtoOrDynClass(thread_, float64_arr_func_instance_dynclass.GetTaggedValue()); @@ -2239,7 +1544,7 @@ void Builtins::InitializeBigInt64Array(const JSHandle &env, // BigInt64Array = new Function() JSHandle big_int64_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::BigInt64ArrayConstructor)); + env, reinterpret_cast(big_int64_array::BigInt64ArrayConstructor)); InitializeCtor(env, big_int64_arr_func_prototype, big_int64_array_function, "BigInt64Array", FunctionLength::THREE); big_int64_array_function->SetProtoOrDynClass(thread_, big_int64_arr_func_instance_dynclass.GetTaggedValue()); @@ -2264,7 +1569,7 @@ void Builtins::InitializeBigUint64Array(const JSHandle &env, // BigUint64Array = new Function() JSHandle big_uint64_array_function = factory_->NewSpecificTypedArrayFunction( - env, reinterpret_cast(BuiltinsTypedArray::BigUint64ArrayConstructor)); + env, reinterpret_cast(big_uint64_array::BigUint64ArrayConstructor)); InitializeCtor(env, big_uint64_arr_func_prototype, big_uint64_array_function, "BigUint64Array", FunctionLength::THREE); @@ -2288,29 +1593,15 @@ void Builtins::InitializeArrayBuffer(const JSHandle &env, const JSHan factory_->CreateDynClass(JSType::JS_ARRAY_BUFFER, array_buffer_func_prototype_value); // ArrayBuffer = new Function() - JSHandle array_buffer_function(NewBuiltinConstructor( - env, array_buffer_func_prototype, ArrayBuffer::ArrayBufferConstructor, "ArrayBuffer", FunctionLength::ONE)); + JSHandle array_buffer_function(NewBuiltinConstructor(env, array_buffer_func_prototype, + builtins::array_buffer::ArrayBufferConstructor, + "ArrayBuffer", FunctionLength::ONE)); JSHandle(array_buffer_function) ->SetFunctionPrototype(thread_, array_buffer_func_instance_dynclass.GetTaggedValue()); - // ArrayBuffer prototype method - SetFunction(env, array_buffer_func_prototype, "slice", ArrayBuffer::Slice, FunctionLength::TWO); - - // ArrayBuffer method - SetFunction(env, array_buffer_function, "isView", ArrayBuffer::IsView, FunctionLength::ONE); - - // 24.1.3.3 get ArrayBuffer[@@species] - JSHandle species_symbol = env->GetSpeciesSymbol(); - JSHandle species_getter = - CreateGetter(env, ArrayBuffer::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(array_buffer_function), species_symbol, species_getter); - - // 24.1.4.1 get ArrayBuffer.prototype.byteLength - JSHandle length_getter = - CreateGetter(env, ArrayBuffer::GetByteLength, "byteLength", FunctionLength::ZERO); - JSHandle length_key(factory_->NewFromCanBeCompressString("byteLength")); - SetGetter(array_buffer_func_prototype, length_key, length_getter); + SetFunctionsGenArrayBufferProto(env, array_buffer_func_prototype); + SetFunctionsGenArrayBuffer(env, array_buffer_function); // 24.1.4.4 ArrayBuffer.prototype[@@toStringTag] SetStringTagSymbol(env, array_buffer_func_prototype, "ArrayBuffer"); @@ -2325,20 +1616,7 @@ void Builtins::InitializeReflect(const JSHandle &env, JSHandle reflect_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); JSHandle reflect_object = factory_->NewJSObject(reflect_dynclass); - SetFunction(env, reflect_object, "apply", Reflect::ReflectApply, FunctionLength::THREE); - SetFunction(env, reflect_object, "construct", Reflect::ReflectConstruct, FunctionLength::TWO); - SetFunction(env, reflect_object, "defineProperty", Reflect::ReflectDefineProperty, FunctionLength::THREE); - SetFunction(env, reflect_object, "deleteProperty", Reflect::ReflectDeleteProperty, FunctionLength::TWO); - SetFunction(env, reflect_object, "get", Reflect::ReflectGet, FunctionLength::TWO); - SetFunction(env, reflect_object, "getOwnPropertyDescriptor", Reflect::ReflectGetOwnPropertyDescriptor, - FunctionLength::TWO); - SetFunction(env, reflect_object, "getPrototypeOf", Reflect::ReflectGetPrototypeOf, FunctionLength::ONE); - SetFunction(env, reflect_object, "has", Reflect::ReflectHas, FunctionLength::TWO); - SetFunction(env, reflect_object, "isExtensible", Reflect::ReflectIsExtensible, FunctionLength::ONE); - SetFunction(env, reflect_object, "ownKeys", Reflect::ReflectOwnKeys, FunctionLength::ONE); - SetFunction(env, reflect_object, "preventExtensions", Reflect::ReflectPreventExtensions, FunctionLength::ONE); - SetFunction(env, reflect_object, "set", Reflect::ReflectSet, FunctionLength::THREE); - SetFunction(env, reflect_object, "setPrototypeOf", Reflect::ReflectSetPrototypeOf, FunctionLength::TWO); + SetFunctionsGenReflect(env, reflect_object); JSHandle reflect_string(factory_->NewFromCanBeCompressString("Reflect")); JSHandle global_object(thread_, env->GetGlobalObject()); @@ -2361,39 +1639,26 @@ void Builtins::InitializePromise(const JSHandle &env, const JSHandle< JSHandle promise_func_instance_dynclass = factory_->CreateDynClass(JSType::JS_PROMISE, promise_func_prototype_value); // Promise() = new Function() - JSHandle promise_function(NewBuiltinConstructor(env, promise_func_prototype, Promise::PromiseConstructor, + JSHandle promise_function(NewBuiltinConstructor(env, promise_func_prototype, promise::PromiseConstructor, "Promise", FunctionLength::ONE)); JSHandle(promise_function) ->SetFunctionPrototype(thread_, promise_func_instance_dynclass.GetTaggedValue()); + SetFunctionsGenPromise(env, promise_function); - // Promise method - SetFunction(env, promise_function, "all", Promise::All, FunctionLength::ONE); - SetFunction(env, promise_function, "race", Promise::Race, FunctionLength::ONE); - SetFunction(env, promise_function, "resolve", Promise::Resolve, FunctionLength::ONE); - SetFunction(env, promise_function, "reject", Promise::Reject, FunctionLength::ONE); - - // promise.prototype method - SetFunction(env, promise_func_prototype, "catch", Promise::Catch, FunctionLength::ONE); - SetFunction(env, promise_func_prototype, "then", Promise::Then, FunctionLength::TWO); + SetFunctionsGenPromiseProto(env, promise_func_prototype); // Promise.prototype [ @@toStringTag ] SetStringTagSymbol(env, promise_func_prototype, "Promise"); - // Set Promise [@@species] - JSHandle species_symbol(env->GetSpeciesSymbol()); - JSHandle species_getter = - CreateGetter(env, Promise::GetSpecies, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(promise_function, species_symbol, species_getter); - env->SetPromiseFunction(thread_, promise_function); } void Builtins::InitializePromiseJob(const JSHandle &env) { JSHandle key_string(thread_->GlobalConstants()->GetHandledEmptyString()); - auto func = NewFunction(env, key_string, BuiltinsPromiseJob::PromiseReactionJob, FunctionLength::TWO); + auto func = NewFunction(env, key_string, promise_job::PromiseReactionJob, FunctionLength::TWO); env->SetPromiseReactionJob(thread_, func); - func = NewFunction(env, key_string, BuiltinsPromiseJob::PromiseResolveThenableJob, FunctionLength::THREE); + func = NewFunction(env, key_string, promise_job::PromiseResolveThenableJob, FunctionLength::THREE); env->SetPromiseResolveThenableJob(thread_, func); } @@ -2409,9 +1674,8 @@ void Builtins::InitializeFinalizationRegistry(const JSHandle &env, JSHandle registry_func_instance_dynclass = factory_->CreateDynClass(JSType::FINALIZATION_REGISTRY, registry_func_prototype_value); // FinalizationRegistry() = new Function() - JSHandle registry_function(NewBuiltinConstructor(env, registry_func_prototype, - BuiltinsFinalizationRegistry::Constructor, - "FinalizationRegistry", FunctionLength::ONE)); + JSHandle registry_function(NewBuiltinConstructor( + env, registry_func_prototype, finalization_registry::Constructor, "FinalizationRegistry", FunctionLength::ONE)); // FinalizationRegistry().prototype = FinalizationRegistry.Prototype & // FinalizationRegistry.prototype.constructor = Finalizationregistry() JSFunction::Cast(registry_function->GetTaggedObject()) @@ -2421,11 +1685,8 @@ void Builtins::InitializeFinalizationRegistry(const JSHandle &env, JSHandle constructor_key = global_const->GetHandledConstructorString(); JSObject::SetProperty(thread_, JSHandle(registry_func_prototype), constructor_key, registry_function); - // FinalizationRegistry.prototype.register() - SetFunction(env, registry_func_prototype, "register", BuiltinsFinalizationRegistry::Register, FunctionLength::TWO); - // FinalizationRegistry.prototype.unregister() - SetFunction(env, registry_func_prototype, "unregister", BuiltinsFinalizationRegistry::Unregister, - FunctionLength::ONE); + + SetFunctionsGenFinalizationRegistryProto(env, registry_func_prototype); // @@ToStringTag SetStringTagSymbol(env, registry_func_prototype, "FinalizationRegistry"); @@ -2447,43 +1708,12 @@ void Builtins::InitializeDataView(const JSHandle &env, const JSHandle // ArrayBuffer = new Function() JSHandle data_view_function(NewBuiltinConstructor( - env, data_view_func_prototype, DataView::DataViewConstructor, "DataView", FunctionLength::ONE)); + env, data_view_func_prototype, data_view::DataViewConstructor, "DataView", FunctionLength::ONE)); JSHandle(data_view_function) ->SetProtoOrDynClass(thread_, data_view_func_instance_dynclass.GetTaggedValue()); - // DataView.prototype method - SetFunction(env, data_view_func_prototype, "getFloat32", DataView::GetFloat32, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getFloat64", DataView::GetFloat64, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getInt8", DataView::GetInt8, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getInt16", DataView::GetInt16, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getInt32", DataView::GetInt32, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getUint8", DataView::GetUint8, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getUint16", DataView::GetUint16, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "getUint32", DataView::GetUint32, FunctionLength::ONE); - SetFunction(env, data_view_func_prototype, "setFloat32", DataView::SetFloat32, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setFloat64", DataView::SetFloat64, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setInt8", DataView::SetInt8, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setInt16", DataView::SetInt16, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setInt32", DataView::SetInt32, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setUint8", DataView::SetUint8, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setUint16", DataView::SetUint16, FunctionLength::TWO); - SetFunction(env, data_view_func_prototype, "setUint32", DataView::SetUint32, FunctionLength::TWO); - - // 24.2.4.1 get DataView.prototype.buffer - JSHandle buffer_getter = CreateGetter(env, DataView::GetBuffer, "buffer", FunctionLength::ZERO); - JSHandle buffer_key(factory_->NewFromCanBeCompressString("buffer")); - SetGetter(data_view_func_prototype, buffer_key, buffer_getter); - - // 24.2.4.2 get DataView.prototype.byteLength - JSHandle length_getter = - CreateGetter(env, DataView::GetByteLength, "byteLength", FunctionLength::ZERO); - JSHandle length_key(factory_->NewFromCanBeCompressString("byteLength")); - SetGetter(data_view_func_prototype, length_key, length_getter); - - // 24.2.4.3 get DataView.prototype.byteOffset - JSHandle offset_getter = CreateGetter(env, DataView::GetOffset, "byteOffset", FunctionLength::ZERO); - JSHandle offset_key(factory_->NewFromCanBeCompressString("byteOffset")); - SetGetter(data_view_func_prototype, offset_key, offset_getter); + + SetFunctionsGenDataViewProto(env, data_view_func_prototype); // 24.2.4.21 DataView.prototype[ @@toStringTag ] SetStringTagSymbol(env, data_view_func_prototype, "DataView"); @@ -2522,7 +1752,13 @@ void Builtins::SetFunction(const JSHandle &env, const JSHandle &key, EcmaEntrypoint func, int length) const { JSHandle function(NewFunction(env, key, func, length)); - PropertyDescriptor descriptor(thread_, JSHandle(function), true, false, true); + SetFunction(obj, key, JSHandle(function)); +} + +void Builtins::SetFunction(const JSHandle &obj, const JSHandle &key, + const JSHandle &func) const +{ + PropertyDescriptor descriptor(thread_, func, true, false, true); JSObject::DefineOwnProperty(thread_, obj, key, descriptor); } @@ -2535,7 +1771,7 @@ void Builtins::SetFrozenFunction(const JSHandle &env, const JSHandle< JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); } -template +template void Builtins::SetFunctionAtSymbol(const JSHandle &env, const JSHandle &obj, const JSHandle &symbol, const char *name, EcmaEntrypoint func, int length) const @@ -2546,20 +1782,27 @@ void Builtins::SetFunctionAtSymbol(const JSHandle &env, const JSHandl JSHandle base_function(function); JSHandle handle_undefine(thread_, JSTaggedValue::Undefined()); JSFunction::SetFunctionName(thread_, base_function, name_string, handle_undefine); + SetFunctionAtSymbol(obj, symbol, JSHandle::Cast(function)); +} + +template +void Builtins::SetFunctionAtSymbol(const JSHandle &obj, const JSHandle &symbol, + const JSHandle &function) const +{ // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) - if constexpr (FLAG == JSSymbol::SYMBOL_TO_PRIMITIVE_TYPE) { - PropertyDescriptor descriptor(thread_, JSHandle::Cast(function), false, false, true); + if constexpr (FLAG == JSSymbol::SymbolType::TO_PRIMITIVE) { + PropertyDescriptor descriptor(thread_, function, false, false, true); JSObject::DefineOwnProperty(thread_, obj, symbol, descriptor); return; } - if constexpr (FLAG == JSSymbol::SYMBOL_HAS_INSTANCE_TYPE) { // NOLINTE(readability-braces-around-statements) + if constexpr (FLAG == JSSymbol::SymbolType::HAS_INSTANCE) { // NOLINTE(readability-braces-around-statements) // ecma 19.2.3.6 Function.prototype[@@hasInstance] has the attributes // { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. - PropertyDescriptor descriptor(thread_, JSHandle::Cast(function), false, false, false); + PropertyDescriptor descriptor(thread_, function, false, false, false); JSObject::DefineOwnProperty(thread_, obj, symbol, descriptor); return; } - PropertyDescriptor descriptor(thread_, JSHandle::Cast(function), true, false, true); + PropertyDescriptor descriptor(thread_, function, true, false, true); JSObject::DefineOwnProperty(thread_, obj, symbol, descriptor); } @@ -2574,6 +1817,7 @@ void Builtins::SetStringTagSymbol(const JSHandle &env, const JSHandle JSHandle Builtins::CreateGetter(const JSHandle &env, EcmaEntrypoint func, const char *name, int length) const { + ASSERT(length == 0); JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); JSHandle func_name(factory_->NewFromString(name)); @@ -2583,8 +1827,9 @@ JSHandle Builtins::CreateGetter(const JSHandle &env, E } JSHandle Builtins::CreateSetter(const JSHandle &env, EcmaEntrypoint func, const char *name, - int length) + int length) const { + ASSERT(length == 1); JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); JSHandle func_name(factory_->NewFromString(name)); @@ -2631,20 +1876,6 @@ void Builtins::SetNoneAttributeProperty(const JSHandle &obj, const cha JSObject::DefineOwnProperty(thread_, obj, key_string, des); } -void Builtins::SetFuncToObjAndGlobal(const JSHandle &env, const JSHandle &global_object, - const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) -{ - JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); - JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle key_string(factory_->NewFromString(key)); - JSHandle base_function(function); - JSHandle handle_undefine(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, base_function, key_string, handle_undefine); - PropertyDescriptor descriptor(thread_, JSHandle::Cast(function), true, false, true); - JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); - JSObject::DefineOwnProperty(thread_, global_object, key_string, descriptor); -} - void Builtins::StrictModeForbiddenAccessCallerArguments(const JSHandle &env, const JSHandle &prototype) const { @@ -2673,7 +1904,7 @@ void Builtins::InitializeGeneratorFunction(const JSHandle &env, generator_func_instance_dynclass->SetExtensible(true); // GeneratorFunction = new GeneratorFunction() JSHandle generator_function = - NewBuiltinConstructor(env, generator_func_prototype, GeneratorObject::GeneratorFunctionConstructor, + NewBuiltinConstructor(env, generator_func_prototype, builtins::generator_function::GeneratorFunctionConstructor, "GeneratorFunction", FunctionLength::ONE); JSHandle constructor_key = global_const->GetHandledConstructorString(); PropertyDescriptor generator_desc(thread_, JSHandle::Cast(generator_function), false, false, true); @@ -2711,14 +1942,7 @@ void Builtins::InitializeGenerator(const JSHandle &env, const JSHandl const GlobalEnvConstants *global_const = thread_->GlobalConstants(); JSHandle generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); - // GeneratorObject.prototype method - // 26.5.1.2 Generator.prototype.next(value) - SetFunction(env, generator_func_prototype, "next", GeneratorObject::GeneratorPrototypeNext, FunctionLength::ONE); - // 26.5.1.3 Generator.prototype.return(value) - SetFunction(env, generator_func_prototype, "return", GeneratorObject::GeneratorPrototypeReturn, - FunctionLength::ONE); - // 26.5.1.4 Generator.prototype.throw(exception) - SetFunction(env, generator_func_prototype, "throw", GeneratorObject::GeneratorPrototypeThrow, FunctionLength::ONE); + SetFunctionsGenGeneratorProto(env, generator_func_prototype); // 26.5.1.5 Generator.prototype[@@toStringTag] SetStringTagSymbol(env, generator_func_prototype, "Generator"); @@ -2753,7 +1977,7 @@ void Builtins::InitializeAsyncGeneratorFunction(const JSHandle &env, // AsyncGeneratorFunction = new AsyncGeneratorFunction() JSHandle async_generator_function = NewBuiltinConstructor( - env, async_generator_func_prototype, AsyncGeneratorObject::AsyncGeneratorFunctionConstructor, + env, async_generator_func_prototype, builtins::async_generator_function::AsyncGeneratorFunctionConstructor, "AsyncGeneratorFunction", FunctionLength::ONE); JSHandle constructor_key = global_const->GetHandledConstructorString(); PropertyDescriptor async_generator_desc(thread_, JSHandle::Cast(async_generator_function), false, @@ -2794,16 +2018,7 @@ void Builtins::InitializeAsyncGenerator(const JSHandle &env, const GlobalEnvConstants *global_const = thread_->GlobalConstants(); JSHandle async_generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); - // AsyncGeneratorObject.prototype method - // 27.6.1.2 AsyncGenerator.prototype.next(value) - SetFunction(env, async_generator_func_prototype, "next", AsyncGeneratorObject::AsyncGeneratorPrototypeNext, - FunctionLength::ONE); - // 27.6.1.3 AsyncGenerator.prototype.return(value) - SetFunction(env, async_generator_func_prototype, "return", AsyncGeneratorObject::AsyncGeneratorPrototypeReturn, - FunctionLength::ONE); - // 27.6.1.4 AsyncGenerator.prototype.throw(exception) - SetFunction(env, async_generator_func_prototype, "throw", AsyncGeneratorObject::AsyncGeneratorPrototypeThrow, - FunctionLength::ONE); + SetFunctionsGenAsyncGeneratorProto(env, async_generator_func_prototype); // 27.6.1.5 AsyncGenerator.prototype[@@toStringTag] SetStringTagSymbol(env, async_generator_func_prototype, "AsyncGenerator"); @@ -2827,15 +2042,7 @@ void Builtins::InitializeAsyncFromSyncIteratorPrototypeObject(const JSHandle async_from_sync_iterator_prototype = factory_->NewJSObject(obj_func_dynclass); - // 27.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next - SetFunction(env, async_from_sync_iterator_prototype, "next", - AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext, FunctionLength::ONE); - // 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return - SetFunction(env, async_from_sync_iterator_prototype, "return", - AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeReturn, FunctionLength::ONE); - // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw - SetFunction(env, async_from_sync_iterator_prototype, "throw", - AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow, FunctionLength::ONE); + SetFunctionsGenAsyncFromSyncIteratorProto(env, async_from_sync_iterator_prototype); JSObject::SetPrototype(thread_, async_from_sync_iterator_prototype, env->GetAsyncIteratorPrototype()); env->SetAsyncFromSyncIteratorPrototype(thread_, async_from_sync_iterator_prototype); @@ -2915,7 +2122,7 @@ void Builtins::InitializeIntl(const JSHandle &env, const JSHandle init_intl_symbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol")); SetNoneAttributeProperty(intl_object, "fallbackSymbol", init_intl_symbol); - SetFunction(env, intl_object, "getCanonicalLocales", Intl::GetCanonicalLocales, FunctionLength::ONE); + SetFunctionsGenIntl(env, intl_object); // initial value of the "Intl" property of the global object. JSHandle intl_string(factory_->NewFromString("Intl")); @@ -2942,32 +2149,18 @@ void Builtins::InitializeDateTimeFormat(const JSHandle &env) // DateTimeFormat = new Function() // 13.4.1 Intl.DateTimeFormat.prototype.constructor - JSHandle dtf_function(NewIntlConstructor(env, dtf_prototype, DateTimeFormat::DateTimeFormatConstructor, + JSHandle dtf_function(NewIntlConstructor(env, dtf_prototype, date_time_format::DateTimeFormatConstructor, "DateTimeFormat", FunctionLength::ZERO)); JSHandle(dtf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*dtf_func_instance_dynclass)); - // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, dtf_function, "supportedLocalesOf", DateTimeFormat::SupportedLocalesOf, FunctionLength::ONE); + SetFunctionsGenDateTimeFormat(env, dtf_function); // DateTimeFormat.prototype method // 13.4.2 Intl.DateTimeFormat.prototype [ @@toStringTag ] SetStringTagSymbol(env, dtf_prototype, "Intl.DateTimeFormat"); env->SetDateTimeFormatFunction(thread_, dtf_function); - // 13.4.3 get Intl.DateTimeFormat.prototype.format - JSHandle format_getter = CreateGetter(env, DateTimeFormat::Format, "format", FunctionLength::ZERO); - JSHandle format_setter(thread_, JSTaggedValue::Undefined()); - SetAccessor(dtf_prototype, thread_->GlobalConstants()->GetHandledFormatString(), format_getter, format_setter); - - // 13.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date ) - SetFunction(env, dtf_prototype, "formatToParts", DateTimeFormat::FormatToParts, FunctionLength::ONE); - - // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () - SetFunction(env, dtf_prototype, "resolvedOptions", DateTimeFormat::ResolvedOptions, FunctionLength::ZERO); - - SetFunction(env, dtf_prototype, "formatRange", DateTimeFormat::FormatRange, FunctionLength::TWO); - - SetFunction(env, dtf_prototype, "formatRangeToParts", DateTimeFormat::FormatRangeToParts, FunctionLength::TWO); + SetFunctionsGenDateTimeFormatProto(env, dtf_prototype); } void Builtins::InitializeRelativeTimeFormat(const JSHandle &env) @@ -2985,26 +2178,17 @@ void Builtins::InitializeRelativeTimeFormat(const JSHandle &env) // RelativeTimeFormat = new Function() // 14.2.1 Intl.RelativeTimeFormat.prototype.constructor JSHandle rtf_function(NewIntlConstructor(env, rtf_prototype, - RelativeTimeFormat::RelativeTimeFormatConstructor, + relative_time_format::RelativeTimeFormatConstructor, "RelativeTimeFormat", FunctionLength::ZERO)); JSHandle(rtf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*rtf_func_instance_dynclass)); - - // 14.3.2 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, rtf_function, "supportedLocalesOf", RelativeTimeFormat::SupportedLocalesOf, FunctionLength::ONE); + SetFunctionsGenRelativeTimeFormat(env, rtf_function); // RelativeTimeFormat.prototype method // 14.4.2 Intl.RelativeTimeFormat.prototype [ @@toStringTag ] SetStringTagSymbol(env, rtf_prototype, "Intl.RelativeTimeFormat"); env->SetRelativeTimeFormatFunction(thread_, rtf_function); - // 14.4.3 get Intl.RelativeTimeFormat.prototype.format - SetFunction(env, rtf_prototype, "format", RelativeTimeFormat::Format, FunctionLength::TWO); - - // 14.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit ) - SetFunction(env, rtf_prototype, "formatToParts", RelativeTimeFormat::FormatToParts, FunctionLength::TWO); - - // 14.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions () - SetFunction(env, rtf_prototype, "resolvedOptions", RelativeTimeFormat::ResolvedOptions, FunctionLength::ZERO); + SetFunctionsGenRelativeTimeFormatProto(env, rtf_prototype); } void Builtins::InitializeNumberFormat(const JSHandle &env) @@ -3021,28 +2205,17 @@ void Builtins::InitializeNumberFormat(const JSHandle &env) // NumberFormat = new Function() // 12.4.1 Intl.NumberFormat.prototype.constructor - JSHandle nf_function(NewIntlConstructor(env, nf_prototype, NumberFormat::NumberFormatConstructor, + JSHandle nf_function(NewIntlConstructor(env, nf_prototype, number_format::NumberFormatConstructor, "NumberFormat", FunctionLength::ZERO)); JSHandle(nf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*nf_func_instance_dynclass)); - // 12.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, nf_function, "supportedLocalesOf", NumberFormat::SupportedLocalesOf, FunctionLength::ONE); - + SetFunctionsGenNumberFormat(env, nf_function); // NumberFormat.prototype method // 12.4.2 Intl.NumberFormat.prototype [ @@toStringTag ] SetStringTagSymbol(env, nf_prototype, "Intl.NumberFormat"); env->SetNumberFormatFunction(thread_, nf_function); - // 12.4.3 get Intl.NumberFormat.prototype.format - JSHandle format_getter = CreateGetter(env, NumberFormat::Format, "format", FunctionLength::ZERO); - JSHandle format_setter(thread_, JSTaggedValue::Undefined()); - SetAccessor(nf_prototype, thread_->GlobalConstants()->GetHandledFormatString(), format_getter, format_setter); - - // 12.4.4 Intl.NumberFormat.prototype.formatToParts ( date ) - SetFunction(env, nf_prototype, "formatToParts", NumberFormat::FormatToParts, FunctionLength::ONE); - - // 12.4.5 Intl.NumberFormat.prototype.resolvedOptions () - SetFunction(env, nf_prototype, "resolvedOptions", NumberFormat::ResolvedOptions, FunctionLength::ZERO); + SetFunctionsGenNumberFormatProto(env, nf_prototype); } void Builtins::InitializeLocale(const JSHandle &env) @@ -3059,47 +2232,9 @@ void Builtins::InitializeLocale(const JSHandle &env) // Locale = new Function() JSHandle locale_function( - NewIntlConstructor(env, locale_prototype, Locale::LocaleConstructor, "Locale", FunctionLength::ONE)); + NewIntlConstructor(env, locale_prototype, locale::LocaleConstructor, "Locale", FunctionLength::ONE)); JSHandle(locale_function)->SetFunctionPrototype(thread_, JSTaggedValue(*locale_func_instance_dynclass)); - - // Locale.prototype method - SetFunction(env, locale_prototype, "maximize", Locale::Maximize, FunctionLength::ZERO); - SetFunction(env, locale_prototype, "minimize", Locale::Minimize, FunctionLength::ZERO); - SetFunction(env, locale_prototype, "toString", Locale::ToString, FunctionLength::ZERO); - - JSHandle base_name_getter = CreateGetter(env, Locale::GetBaseName, "baseName", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledBaseNameString(), base_name_getter); - - JSHandle calendar_getter = CreateGetter(env, Locale::GetCalendar, "calendar", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledCalendarString(), calendar_getter); - - JSHandle case_first_getter = - CreateGetter(env, Locale::GetCaseFirst, "caseFirst", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledCaseFirstString(), case_first_getter); - - JSHandle collation_getter = - CreateGetter(env, Locale::GetCollation, "collation", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledCollationString(), collation_getter); - - JSHandle hour_cycle_getter = - CreateGetter(env, Locale::GetHourCycle, "hourCycle", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledHourCycleString(), hour_cycle_getter); - - JSHandle numeric_getter = CreateGetter(env, Locale::GetNumeric, "numeric", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledNumericString(), numeric_getter); - - JSHandle numbering_system_getter = - CreateGetter(env, Locale::GetNumberingSystem, "numberingSystem", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledNumberingSystemString(), numbering_system_getter); - - JSHandle language_getter = CreateGetter(env, Locale::GetLanguage, "language", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledLanguageString(), language_getter); - - JSHandle script_getter = CreateGetter(env, Locale::GetScript, "script", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledScriptString(), script_getter); - - JSHandle region_getter = CreateGetter(env, Locale::GetRegion, "region", FunctionLength::ZERO); - SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledRegionString(), region_getter); + SetFunctionsGenLocaleProto(env, locale_prototype); // 10.3.2 Intl.Locale.prototype[ @@toStringTag ] SetStringTagSymbol(env, locale_prototype, "Intl.Locale"); @@ -3121,26 +2256,18 @@ void Builtins::InitializeCollator(const JSHandle &env) // Collator = new Function() // 11.1.2 Intl.Collator.prototype.constructor JSHandle collator_function( - NewIntlConstructor(env, collator_prototype, Collator::CollatorConstructor, "Collator", FunctionLength::ZERO)); + NewIntlConstructor(env, collator_prototype, collator::CollatorConstructor, "Collator", FunctionLength::ZERO)); JSHandle(collator_function) ->SetFunctionPrototype(thread_, JSTaggedValue(*collator_func_instance_dynclass)); - // 11.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, collator_function, "supportedLocalesOf", Collator::SupportedLocalesOf, FunctionLength::ONE); + SetFunctionsGenCollator(env, collator_function); // Collator.prototype method // 11.3.2 Intl.Collator.prototype [ @@toStringTag ] SetStringTagSymbol(env, collator_prototype, "Intl.Collator"); env->SetCollatorFunction(thread_, collator_function); - // 11.3.3 get Intl.Collator.prototype.compare - JSHandle compare_getter = CreateGetter(env, Collator::Compare, "compare", FunctionLength::ZERO); - JSHandle compare_setter(thread_, JSTaggedValue::Undefined()); - SetAccessor(collator_prototype, thread_->GlobalConstants()->GetHandledCompareString(), compare_getter, - compare_setter); - - // 11.3.4 Intl.Collator.prototype.resolvedOptions () - SetFunction(env, collator_prototype, "resolvedOptions", Collator::ResolvedOptions, FunctionLength::ZERO); + SetFunctionsGenCollatorProto(env, collator_prototype); } void Builtins::InitializePluralRules(const JSHandle &env) @@ -3157,36 +2284,31 @@ void Builtins::InitializePluralRules(const JSHandle &env) // PluralRules = new Function() // 15.2.1 Intl.PluralRules.prototype.constructor - JSHandle pr_function(NewIntlConstructor(env, pr_prototype, PluralRules::PluralRulesConstructor, + JSHandle pr_function(NewIntlConstructor(env, pr_prototype, plural_rules::PluralRulesConstructor, "PluralRules", FunctionLength::ZERO)); JSHandle(pr_function)->SetFunctionPrototype(thread_, JSTaggedValue(*pr_func_instance_dynclass)); - // 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, pr_function, "supportedLocalesOf", PluralRules::SupportedLocalesOf, FunctionLength::ONE); + env->SetPluralRulesFunction(thread_, pr_function); + SetFunctionsGenPluralRules(env, pr_function); // PluralRules.prototype method // 15.4.2 Intl.PluralRules.prototype [ @@toStringTag ] SetStringTagSymbol(env, pr_prototype, "Intl.PluralRules"); - env->SetPluralRulesFunction(thread_, pr_function); - - // 15.4.3 get Intl.PluralRules.prototype.select - SetFunction(env, pr_prototype, "select", PluralRules::Select, FunctionLength::ONE); - // 15.4.5 Intl.PluralRules.prototype.resolvedOptions () - SetFunction(env, pr_prototype, "resolvedOptions", PluralRules::ResolvedOptions, FunctionLength::ZERO); + SetFunctionsGenPluralRulesProto(env, pr_prototype); } void Builtins::InitializeGcMarker(const JSHandle &env) const { JSHandle marker = factory_->NewEmptyJSObject(); - SetFunction(env, marker, "markObjectRecursively", Global::MarkObjectRecursively, FunctionLength::ONE); env->SetGcMarker(thread_, marker.GetTaggedValue()); + SetFunctionsGenGCMarker(env, marker); } JSHandle Builtins::InitializeArkTools(const JSHandle &env) const { JSHandle tools = factory_->NewEmptyJSObject(); - SetFunction(env, tools, "print", builtins::BuiltinsArkTools::ObjectDump, FunctionLength::ZERO); + SetFunctionsGenArkTools(env, tools); return tools; } @@ -3217,69 +2339,7 @@ JSHandle Builtins::InitializeArkPrivate(const JSHandle &env JSHandle Builtins::InitializeRuntimeTesting(const JSHandle &env) const { JSHandle runtime_testing = factory_->NewEmptyJSObject(); - SetFunction(env, runtime_testing, "GetOptimizationStatus", builtins::BuiltinsRuntimeTesting::GetOptimizationStatus, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "PrepareFunctionForOptimization", - builtins::BuiltinsRuntimeTesting::PrepareFunctionForOptimization, FunctionLength::ONE); - SetFunction(env, runtime_testing, "OptimizeFunctionOnNextCall", - builtins::BuiltinsRuntimeTesting::OptimizeFunctionOnNextCall, FunctionLength::TWO); - SetFunction(env, runtime_testing, "Exit", builtins::BuiltinsRuntimeTesting::Exit, FunctionLength::ONE); - - // Not implemented: - SetFunction(env, runtime_testing, "IsBeingInterpreted", builtins::BuiltinsRuntimeTesting::IsBeingInterpreted, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "DeoptimizeFunction", builtins::BuiltinsRuntimeTesting::DeoptimizeFunction, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "NeverOptimizeFunction", builtins::BuiltinsRuntimeTesting::NeverOptimizeFunction, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "DeoptimizeNow", builtins::BuiltinsRuntimeTesting::DeoptimizeNow, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "_DeoptimizeNow", builtins::BuiltinsRuntimeTesting::_DeoptimizeNow, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "ClearFunctionFeedback", builtins::BuiltinsRuntimeTesting::ClearFunctionFeedback, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "OptimizeOsr", builtins::BuiltinsRuntimeTesting::OptimizeOsr, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "CompleteInobjectSlackTracking", - builtins::BuiltinsRuntimeTesting::CompleteInobjectSlackTracking, FunctionLength::ONE); - SetFunction(env, runtime_testing, "IsDictPropertyConstTrackingEnbled", - builtins::BuiltinsRuntimeTesting::IsDictPropertyConstTrackingEnbled, FunctionLength::ONE); - SetFunction(env, runtime_testing, "StringMaxLength", builtins::BuiltinsRuntimeTesting::StringMaxLength, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "TypedArrayMaxLength", builtins::BuiltinsRuntimeTesting::TypedArrayMaxLength, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "DisableOptimizationFinalization", - builtins::BuiltinsRuntimeTesting::DisableOptimizationFinalization, FunctionLength::ONE); - SetFunction(env, runtime_testing, "WaitForBackgroundOptimization", - builtins::BuiltinsRuntimeTesting::WaitForBackgroundOptimization, FunctionLength::ONE); - SetFunction(env, runtime_testing, "FinalizeOptimization", builtins::BuiltinsRuntimeTesting::FinalizeOptimization, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "ArrayBufferDetach", builtins::BuiltinsRuntimeTesting::ArrayBufferDetach, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "EnsureFeedbackVectorForFunction", - builtins::BuiltinsRuntimeTesting::EnsureFeedbackVectorForFunction, FunctionLength::ONE); - SetFunction(env, runtime_testing, "SimulateNewspaceFull", builtins::BuiltinsRuntimeTesting::SimulateNewspaceFull, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "VerifyType", builtins::BuiltinsRuntimeTesting::VerifyType, FunctionLength::ONE); - SetFunction(env, runtime_testing, "ToFastProperties", builtins::BuiltinsRuntimeTesting::ToFastProperties, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "IsConcurrentRecompilationSupported", - builtins::BuiltinsRuntimeTesting::IsConcurrentRecompilationSupported, FunctionLength::ONE); - SetFunction(env, runtime_testing, "GetUndetectable", builtins::BuiltinsRuntimeTesting::GetUndetectable, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "ToLength", builtins::BuiltinsRuntimeTesting::ToLength, FunctionLength::ONE); - SetFunction(env, runtime_testing, "RunningInSimulator", builtins::BuiltinsRuntimeTesting::RunningInSimulator, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "AllocateHeapNumber", builtins::BuiltinsRuntimeTesting::AllocateHeapNumber, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "PretenureAllocationSite", - builtins::BuiltinsRuntimeTesting::PretenureAllocationSite, FunctionLength::ONE); - SetFunction(env, runtime_testing, "MaxSmi", builtins::BuiltinsRuntimeTesting::MaxSmi, FunctionLength::ONE); - SetFunction(env, runtime_testing, "CreatePrivateSymbol", builtins::BuiltinsRuntimeTesting::CreatePrivateSymbol, - FunctionLength::ONE); - SetFunction(env, runtime_testing, "CreatePrivateNameSymbol", - builtins::BuiltinsRuntimeTesting::CreatePrivateNameSymbol, FunctionLength::ONE); - SetFunction(env, runtime_testing, "Is64Bit", builtins::BuiltinsRuntimeTesting::Is64Bit, FunctionLength::ONE); + SetFunctionsGenRuntimeTesting(env, runtime_testing); return runtime_testing; } #endif // PANDA_PRODUCT_BUILD @@ -3287,7 +2347,7 @@ JSHandle Builtins::InitializeRuntimeTesting(const JSHandle #ifdef FUZZING_FUZZILLI_BUILTIN void Builtins::InitializeFuzzilli(const JSHandle &env, const JSHandle &objFuncDynclass) { - class BuiltinsFuzzilli : public ecmascript::base::BuiltinsBase { + class BuiltinsFuzzilli : { public: static JSTaggedValue FuzzilliConstructor(EcmaRuntimeCallInfo *argv) { @@ -3296,11 +2356,11 @@ void Builtins::InitializeFuzzilli(const JSHandle &env, const JSHandle JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - auto value = GetCallArg(argv, 0); + auto value = builtins_common::GetCallArg(argv, 0); JSHandle command = JSTaggedValue::ToString(thread, value); auto commandVal = base::StringHelper::ToStdString(*command); if (commandVal == "FUZZILLI_CRASH") { - JSTaggedNumber num = JSTaggedValue::ToNumber(thread, GetCallArg(argv, 1)); + JSTaggedNumber num = JSTaggedValue::ToNumber(thread, builtins_common::GetCallArg(argv, 1)); auto numVal = base::NumberHelper::DoubleInRangeInt32(num.GetNumber()); switch (numVal) { case 0: @@ -3314,7 +2374,7 @@ void Builtins::InitializeFuzzilli(const JSHandle &env, const JSHandle break; } } else if (commandVal == "FUZZILLI_PRINT") { - JSHandle arg = JSTaggedValue::ToString(thread, GetCallArg(argv, 1)); + JSHandle arg = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 1)); auto stringVal = base::StringHelper::ToStdString(*arg); // REPRL_DWFD for fuzzilli FILE *fzliout = fdopen(103, "w"); @@ -3344,4 +2404,4 @@ void Builtins::InitializeFuzzilli(const JSHandle &env, const JSHandle ->SetFunctionPrototype(thread_, fuzzilliFuncInstanceDynclass.GetTaggedValue()); } #endif -} // namespace panda::ecmascript +} // namespace panda::ecmascript::builtins diff --git a/runtime/builtins.h b/runtime/builtins.h index ff28cb9625e9e18f0ba40a6a05ff1aab3ca4df22..bf08fcb45f0e7c4b637dc8c624e4ed25e7eb6a50 100644 --- a/runtime/builtins.h +++ b/runtime/builtins.h @@ -23,8 +23,18 @@ #include "plugins/ecmascript/runtime/js_thread.h" #include "object_factory.h" #include "plugins/ecmascript/runtime/object_factory.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" + +#include "plugins/ecmascript/runtime/js_map_iterator.h" +#include "plugins/ecmascript/runtime/js_array_iterator.h" +#include "plugins/ecmascript/runtime/js_for_in_iterator.h" +#include "plugins/ecmascript/runtime/js_regexp_iterator.h" +#include "plugins/ecmascript/runtime/js_set_iterator.h" +#include "plugins/ecmascript/runtime/js_string_iterator.h" + +namespace panda::ecmascript::builtins { +using ErrorType = base::ErrorType; -namespace panda::ecmascript { struct ErrorParameter { EcmaEntrypoint native_constructor {nullptr}; EcmaEntrypoint native_method {nullptr}; @@ -32,7 +42,7 @@ struct ErrorParameter { JSType native_jstype {JSType::INVALID}; }; -enum FunctionLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR }; +enum FunctionLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN }; class Builtins { public: @@ -64,8 +74,7 @@ private: void InitializeObject(const JSHandle &env, const JSHandle &obj_func_prototype, const JSHandle &obj_func); - void InitializeNumber(const JSHandle &env, const JSHandle &global_object, - const JSHandle &prim_ref_obj_dynclass); + void InitializeNumber(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass); void InitializeBigInt(const JSHandle &env, const JSHandle &obj_func_dynclass) const; @@ -204,13 +213,16 @@ private: void SetFunction(const JSHandle &env, const JSHandle &obj, const JSHandle &key, EcmaEntrypoint func, int length) const; - void SetFuncToObjAndGlobal(const JSHandle &env, const JSHandle &global_object, - const JSHandle &obj, const char *key, EcmaEntrypoint func, int length); + void SetFunction(const JSHandle &obj, const JSHandle &key, + const JSHandle &func) const; - template + template void SetFunctionAtSymbol(const JSHandle &env, const JSHandle &obj, const JSHandle &symbol, const char *name, EcmaEntrypoint func, int length) const; + template + void SetFunctionAtSymbol(const JSHandle &obj, const JSHandle &symbol, + const JSHandle &function) const; void SetStringTagSymbol(const JSHandle &env, const JSHandle &obj, const char *key) const; JSHandle CreateGetter(const JSHandle &env, EcmaEntrypoint func, const char *name, @@ -229,7 +241,7 @@ private: const JSHandle &prototype) const; JSHandle CreateSetter(const JSHandle &env, EcmaEntrypoint func, const char *name, - int length); + int length) const; void SetArgumentsSharedAccessor(const JSHandle &env); void SetAccessor(const JSHandle &obj, const JSHandle &key, const JSHandle &getter, const JSHandle &setter) const; @@ -245,6 +257,8 @@ private: #ifdef FUZZING_FUZZILLI_BUILTIN void InitializeFuzzilli(const JSHandle &env, const JSHandle &objFuncDynclass); #endif + +#include "plugins/ecmascript/runtime/builtins/generated/builtins_initializers_gen.h" }; -} // namespace panda::ecmascript +} // namespace panda::ecmascript::builtins #endif // ECMASCRIPT_BUILTINS_H diff --git a/runtime/builtins/CMakeLists.txt b/runtime/builtins/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4499b9dff9758c1cf4135d8996d5337e2159100d --- /dev/null +++ b/runtime/builtins/CMakeLists.txt @@ -0,0 +1,16 @@ +set(BUILTIN_TEMPLATES + builtins_initializers_gen.h.erb + builtins_declaration_gen.h.erb +) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated) +panda_gen( + DATA ${CMAKE_CURRENT_SOURCE_DIR}/templates/builtins.yaml + TARGET_NAME ecma_builtins_gen + TEMPLATES ${BUILTIN_TEMPLATES} + REQUIRES ${PANDA_ROOT}/templates/common.rb ${CMAKE_CURRENT_SOURCE_DIR}/templates/builtins.rb + SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/templates + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/generated +) + +add_dependencies(intrinsics_gen_arkruntime ecma_builtins_gen) diff --git a/runtime/builtins/builtins_ark_tools.cpp b/runtime/builtins/builtins_ark_tools.cpp index d9d1a365b362415669565487ea06beba0f308069..c31b62f91f193a5e4c84734991cc755dcaee1fc5 100644 --- a/runtime/builtins/builtins_ark_tools.cpp +++ b/runtime/builtins/builtins_ark_tools.cpp @@ -13,25 +13,27 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_ark_tools.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/string_helper.h" namespace panda::ecmascript::builtins { using StringHelper = base::StringHelper; -JSTaggedValue BuiltinsArkTools::ObjectDump(EcmaRuntimeCallInfo *msg) +// Make sure the ECMASCRIPT_OBJECT_DUMP in config.h has been opened before use it +// Use through ArkTools.print(msg, [obj1, obj2, ... objn]) in js +JSTaggedValue ark_tools::Print(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + JSHandle str = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); // The default log level of ace_engine and js_runtime is error LOG(ERROR, RUNTIME) << ": " << base::StringHelper::ToStdString(*str); - uint32_t num_args = msg->GetArgsNumber(); + uint32_t num_args = argv->GetArgsNumber(); for (uint32_t i = 1; i < num_args; i++) { - JSHandle obj = GetCallArg(msg, i); + JSHandle obj = builtins_common::GetCallArg(argv, i); std::ostringstream oss; obj->Dump(thread, oss); diff --git a/runtime/builtins/builtins_ark_tools.h b/runtime/builtins/builtins_ark_tools.h deleted file mode 100644 index ada9ebed8c33955c6f4887163d12bb7290660e8f..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_ark_tools.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_ARK_TOOLS_H -#define ECMASCRIPT_BUILTINS_BUILTINS_ARK_TOOLS_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_thread.h" - -namespace panda::ecmascript::builtins { -class BuiltinsArkTools : public base::BuiltinsBase { -public: - // Make sure the ECMASCRIPT_OBJECT_DUMP in config.h has been opened before use it - // Use through ArkTools.print(msg, [obj1, obj2, ... objn]) in js - static JSTaggedValue ObjectDump(EcmaRuntimeCallInfo *msg); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ARK_TOOLS_H diff --git a/runtime/builtins/builtins_array.cpp b/runtime/builtins/builtins_array.cpp index 5066515fec23d5ba97f7631ee5da562e4b3e97d3..579ce0c896ba903c700bba5f432747d229e333a3 100644 --- a/runtime/builtins/builtins_array.cpp +++ b/runtime/builtins/builtins_array.cpp @@ -13,10 +13,9 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_array.h" - #include +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/array_helper.h" #include "plugins/ecmascript/runtime/base/number_helper.h" #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" @@ -39,8 +38,10 @@ namespace panda::ecmascript::builtins { using ArrayHelper = ecmascript::base::ArrayHelper; using TypedArrayHelper = ecmascript::base::TypedArrayHelper; +constexpr uint8_t INDEX_TWO = 2; + // 22.1.1 -JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Constructor); @@ -52,8 +53,8 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 3. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. - JSHandle constructor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { new_target = constructor; } @@ -73,7 +74,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 6. Let array be ArrayCreate(0, proto). uint32_t new_len = 0; JSHandle new_array_handle(JSArray::ArrayCreate(thread, JSTaggedNumber(new_len), new_target)); - JSHandle len = GetCallArg(argv, 0); + JSHandle len = builtins_common::GetCallArg(argv, 0); // 7. If Type(len) is not Number, then // a. Let defineStatus be CreateDataProperty(array, "0", len). // b. Assert: defineStatus is true. @@ -118,7 +119,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); - JSHandle item_k = GetCallArg(argv, k); + JSHandle item_k = builtins_common::GetCallArg(argv, k); JSObject::CreateDataProperty(thread, new_array_handle, key, item_k); } @@ -130,7 +131,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::From(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, From); @@ -139,15 +140,15 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); // 1. Let C be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If mapfn is undefined, let mapping be false. bool mapping = false; // 3. else // a. If IsCallable(mapfn) is false, throw a TypeError exception. // b. If thisArg was supplied, let T be thisArg; else let T be undefined. // c. Let mapping be true - JSHandle this_arg_handle = GetCallArg(argv, INDEX_TWO); - JSHandle mapfn = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, INDEX_TWO); + JSHandle mapfn = builtins_common::GetCallArg(argv, 1); if (!mapfn->IsUndefined()) { if (!mapfn->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the mapfn is not callable.", JSTaggedValue::Exception()); @@ -155,7 +156,7 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) mapping = true; } // 4. Let usingIterator be GetMethod(items, @@iterator). - JSHandle items = GetCallArg(argv, 0); + JSHandle items = builtins_common::GetCallArg(argv, 0); if (items->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "The items is null.", JSTaggedValue::Exception()); } @@ -308,19 +309,19 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) } // 22.1.2.2 Array.isArray ( arg ) -JSTaggedValue BuiltinsArray::IsArray(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::IsArray(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, IsArray); // 1. Return IsArray(arg). - if (GetCallArg(argv, 0)->IsArray(argv->GetThread())) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->IsArray(argv->GetThread())) { + return builtins_common::GetTaggedBoolean(true); } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 22.1.2.3 Array.of ( ...items ) -JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::Of(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Of); @@ -333,7 +334,7 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 3. Let C be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 4. If IsConstructor(C) is true, then // a. Let A be Construct(C, «len»). // 5. Else, @@ -367,7 +368,7 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); - JSHandle k_value = GetCallArg(argv, k); + JSHandle k_value = builtins_common::GetCallArg(argv, k); JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, key, k_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -380,15 +381,15 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) } // 22.1.2.5 get Array [ @@species ] -JSTaggedValue BuiltinsArray::Species([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::GetSpecies([[maybe_unused]] EcmaRuntimeCallInfo *argv) { ASSERT(argv); // 1. Return the this value. - return GetThis(argv).GetTaggedValue(); + return builtins_common::GetThis(argv).GetTaggedValue(); } // 22.1.3.1 Array.prototype.concat ( ...arguments ) -JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Concat(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Concat); @@ -397,7 +398,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -449,7 +450,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) // 7. Repeat, while items is not empty for (uint32_t i = 0; i < argc; i++) { // a. Remove the first element from items and let E be the value of the element - JSHandle add_handle = GetCallArg(argv, i); + JSHandle add_handle = builtins_common::GetCallArg(argv, i); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle add_obj_handle(add_handle); @@ -519,7 +520,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) } // 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) -JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::CopyWithin(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, CopyWithin); @@ -527,7 +528,7 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle this_obj_val(this_obj_handle); @@ -542,7 +543,7 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) double copy_end; // 5. Let relativeTarget be ToInteger(target). - JSTaggedNumber target_temp = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); + JSTaggedNumber target_temp = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); // 6. ReturnIfAbrupt(relativeTarget). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double target = target_temp.GetNumber(); @@ -554,7 +555,7 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) } // 8. Let relativeStart be ToInteger(start). - JSTaggedNumber start_t = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 1)); + JSTaggedNumber start_t = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 1)); // 9. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double start = start_t.GetNumber(); @@ -567,7 +568,7 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) // 11. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). double end = len; - JSHandle msg3 = GetCallArg(argv, INDEX_TWO); + JSHandle msg3 = builtins_common::GetCallArg(argv, INDEX_TWO); if (!msg3->IsUndefined()) { JSTaggedNumber temp = JSTaggedValue::ToInteger(thread, msg3); // 12. ReturnIfAbrupt(relativeEnd). @@ -643,7 +644,7 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) } // 22.1.3.4 Array.prototype.entries ( ) -JSTaggedValue BuiltinsArray::Entries(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Entries(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Entries); @@ -652,7 +653,7 @@ JSTaggedValue BuiltinsArray::Entries(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). - JSHandle self = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle self = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayIterator(O, "key+value"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::KEY_AND_VALUE)); @@ -660,14 +661,14 @@ JSTaggedValue BuiltinsArray::Entries(EcmaRuntimeCallInfo *argv) } // 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg] ) -JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Every(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -679,13 +680,13 @@ JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -715,14 +716,14 @@ JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool bool_result = call_result.ToBoolean(); if (!bool_result) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } } k++; } // 9. Return true. - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // ES2019 22.1.3.10.1 FlattenIntoArray(target, source, sourceLen, start, depth, [, mapperFunction, thisArg]) @@ -805,7 +806,7 @@ static JSTaggedValue FlattenIntoArray(JSThread *thread, const JSHandle } // ES2019 22.1.3.10 Array.prototype.flat( [ depth ] ) -JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Flat(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Flat); @@ -813,7 +814,7 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ? ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -825,7 +826,7 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv) // 4. If depth is not undefined, then // a. Set depthNum to ? ToInteger(depth) double depth_num = 1; - JSHandle msg1 = GetCallArg(argv, 0); + JSHandle msg1 = builtins_common::GetCallArg(argv, 0); if (!msg1->IsUndefined()) { JSTaggedValue depth = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -846,7 +847,7 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv) } // ES2019 22.1.3.11 Array.prototype.flatMap(mapperFunction [ , thisArg ]]) -JSTaggedValue BuiltinsArray::FlatMap(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::FlatMap(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, FlatMap); @@ -855,7 +856,7 @@ JSTaggedValue BuiltinsArray::FlatMap(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ? ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. Let sourceLen be ? ToLength(? Get(O, "length")). @@ -863,14 +864,14 @@ JSTaggedValue BuiltinsArray::FlatMap(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If IsCallable(mapperFunction) is false, throw a TypeError exception. - JSHandle mapper_function = GetCallArg(argv, 0); + JSHandle mapper_function = builtins_common::GetCallArg(argv, 0); if (!mapper_function->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Object is not callable", JSTaggedValue::Exception()); } // 4. If thisArg is present, let T be thisArg; else let T be undefined. JSMutableHandle this_arg(thread, JSTaggedValue::Undefined()); if (argc > 1) { - this_arg.Update(GetCallArg(argv, 1).GetTaggedValue()); + this_arg.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); } // 5. Let A be ? ArraySpeciesCreate(O, 0). JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(0)); @@ -886,7 +887,7 @@ JSTaggedValue BuiltinsArray::FlatMap(EcmaRuntimeCallInfo *argv) } // 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) -JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Fill(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Fill); @@ -894,13 +895,13 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle this_obj_val(this_obj_handle); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); if (this_handle->IsTypedArray()) { ContentType content_type = JSHandle::Cast(this_handle)->GetContentType(); if (content_type == ContentType::BIG_INT) { @@ -918,7 +919,7 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) // 5. Let relativeStart be ToInteger(start). double start; - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg1); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -932,7 +933,7 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). double arg_end = len; - JSHandle msg2 = GetCallArg(argv, INDEX_TWO); + JSHandle msg2 = builtins_common::GetCallArg(argv, INDEX_TWO); if (!msg2->IsUndefined()) { JSTaggedNumber arg_end_temp = JSTaggedValue::ToInteger(thread, msg2); // 9. ReturnIfAbrupt(relativeEnd). @@ -967,14 +968,14 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) } // 22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] ) -JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Filter(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -986,13 +987,13 @@ JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let A be ArraySpeciesCreate(O, 0). int32_t array_len = 0; @@ -1049,7 +1050,7 @@ JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) } // 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) -JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Find(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Find); @@ -1057,7 +1058,7 @@ JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1069,13 +1070,13 @@ JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(predicate) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the predicate is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1109,7 +1110,7 @@ JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) } // 22.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] ) -JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::FindIndex(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, FindIndex); @@ -1117,7 +1118,7 @@ JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1129,13 +1130,13 @@ JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(predicate) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the predicate is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1159,24 +1160,24 @@ JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) bool bool_result = call_result.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (bool_result) { - return GetTaggedDouble(k); + return builtins_common::GetTaggedDouble(k); } k++; } // 9. Return -1. - return GetTaggedDouble(-1); + return builtins_common::GetTaggedDouble(-1); } // 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) -JSTaggedValue BuiltinsArray::ForEach(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1188,13 +1189,13 @@ JSTaggedValue BuiltinsArray::ForEach(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1230,7 +1231,7 @@ JSTaggedValue BuiltinsArray::ForEach(EcmaRuntimeCallInfo *argv) } // ES2021 23.1.3.13 Array.prototype.includes ( searchElement [ , fromIndex ] ) -JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Includes(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Includes); @@ -1238,7 +1239,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1250,7 +1251,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) // 3. If len is 0, return false. if (len == 0) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } ArraySizeT argc = argv->GetArgsNumber(); @@ -1258,7 +1259,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) if (argc > 1) { // 4-5. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1267,7 +1268,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) // 6. If n is positiveInfinity, return false. if (JSTaggedValue::Equal(thread, msg1, JSHandle(thread, JSTaggedValue(base::POSITIVE_INFINITY)))) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 7. Else if n is negativeInfinity, set n to 0. @@ -1285,7 +1286,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); // 10. - const JSHandle search_element = GetCallArg(argv, 0); + const JSHandle search_element = builtins_common::GetCallArg(argv, 0); while (from < len) { // a) JSHandle index_handle(thread, JSTaggedValue(from)); @@ -1295,18 +1296,18 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) // b) if (JSTaggedValue::SameValueZero(search_element.GetTaggedValue(), element.GetTaggedValue())) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // c) from++; } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 22.1.3.11 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) -JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::IndexOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, IndexOf); @@ -1316,13 +1317,13 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle this_obj_val(this_obj_handle); - JSHandle search_element = GetCallArg(argv, 0); + JSHandle search_element = builtins_common::GetCallArg(argv, 0); // 3. Let len be ToLength(Get(O, "length")). double len = ArrayHelper::GetLength(thread, this_obj_val); @@ -1331,13 +1332,13 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) // 5. If len is 0, return −1. if (len == 0) { - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } // 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. double from_index = 0; if (argc > 1) { - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); // 7. ReturnIfAbrupt(n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1346,7 +1347,7 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) // 8. If n ≥ len, return −1. if (from_index >= len) { - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } // 9. If n ≥ 0, then @@ -1374,29 +1375,29 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (JSTaggedValue::StrictEqual(thread, search_element, k_value_handle)) { - return GetTaggedDouble(from); + return builtins_common::GetTaggedDouble(from); } } from++; } // 12. Return -1. - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } // 22.1.3.12 Array.prototype.join (separator) -JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Join(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Join); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // Prevent inifinity joining of recursive arrays static std::vector visited_stack = {}; if (std::find(visited_stack.begin(), visited_stack.end(), this_handle->GetRawData()) != visited_stack.end()) { - return GetTaggedString(thread, ""); + return builtins_common::GetTaggedString(thread, ""); } visited_stack.push_back(this_handle->GetRawData()); auto unvisit = std::unique_ptr>( @@ -1421,10 +1422,10 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) // 5. If separator is undefined, let separator be the single-element String ",". // 6. Let sep be ToString(separator). JSHandle sep_handle; - if ((GetCallArg(argv, 0)->IsUndefined())) { + if ((builtins_common::GetCallArg(argv, 0)->IsUndefined())) { sep_handle = JSHandle::Cast(factory->NewFromCanBeCompressString(",")); } else { - sep_handle = GetCallArg(argv, 0); + sep_handle = builtins_common::GetCallArg(argv, 0); } JSHandle sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); @@ -1440,7 +1441,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) // 8. If len is zero, return the empty String. if (len == 0) { - return GetTaggedString(thread, ""); + return builtins_common::GetTaggedString(thread, ""); } // 9. Let element0 be Get(O, "0"). @@ -1488,7 +1489,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) } // 22.1.3.13 Array.prototype.keys ( ) -JSTaggedValue BuiltinsArray::Keys(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Keys(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Keys); @@ -1497,7 +1498,7 @@ JSTaggedValue BuiltinsArray::Keys(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). - JSHandle self = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle self = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayIterator(O, "key"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::KEY)); @@ -1505,7 +1506,7 @@ JSTaggedValue BuiltinsArray::Keys(EcmaRuntimeCallInfo *argv) } // 22.1.3.14 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) -JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, LastIndexOf); @@ -1515,13 +1516,13 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle this_obj_val(this_obj_handle); - JSHandle search_element = GetCallArg(argv, 0); + JSHandle search_element = builtins_common::GetCallArg(argv, 0); // 3. Let len be ToLength(Get(O, "length")). double len = ArrayHelper::GetLength(thread, this_obj_val); @@ -1530,13 +1531,13 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) // 5. If len is 0, return −1. if (len == 0) { - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } // 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be len-1. double from_index = len - 1; if (argc > 1) { - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); // 7. ReturnIfAbrupt(n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1566,18 +1567,18 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (JSTaggedValue::StrictEqual(thread, search_element, k_value_handle)) { - return GetTaggedDouble(from); + return builtins_common::GetTaggedDouble(from); } } from--; } // 11. Return -1. - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } // 22.1.3.15 Array.prototype.map ( callbackfn [ , thisArg ] ) -JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Map(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Map); @@ -1585,7 +1586,7 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1597,13 +1598,13 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let A be ArraySpeciesCreate(O, len). JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(len)); @@ -1654,7 +1655,7 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) } // 22.1.3.16 Array.prototype.pop ( ) -JSTaggedValue BuiltinsArray::Pop(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Pop(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Pop); @@ -1662,7 +1663,7 @@ JSTaggedValue BuiltinsArray::Pop(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (this_handle->IsStableJSArray(thread)) { return JSStableArray::Pop(JSHandle::Cast(this_handle), argv); } @@ -1710,13 +1711,13 @@ JSTaggedValue BuiltinsArray::Pop(EcmaRuntimeCallInfo *argv) } // 22.1.3.17 Array.prototype.push ( ...items ) -JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Push(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Push); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (this_handle->IsStableJSArray(thread)) { return JSStableArray::Push(JSHandle::Cast(this_handle), argv); } @@ -1747,7 +1748,7 @@ JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (k < argc) { key.Update(JSTaggedValue(len)); - JSHandle k_value = GetCallArg(argv, k); + JSHandle k_value = builtins_common::GetCallArg(argv, k); JSArray::FastSetPropertyByValue(thread, this_obj_val, key, k_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; @@ -1762,11 +1763,11 @@ JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Return len. - return GetTaggedDouble(len); + return builtins_common::GetTaggedDouble(len); } // 22.1.3.18 Array.prototype.reduce ( callbackfn [ , initialValue ] ) -JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Reduce(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Reduce); @@ -1776,7 +1777,7 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1788,7 +1789,7 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } @@ -1815,7 +1816,7 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) uint32_t k = 0; JSMutableHandle accumulator(thread, JSTaggedValue::Undefined()); if (argc == 2) { // 2:2 means the number of parameters - accumulator.Update(GetCallArg(argv, 1).GetTaggedValue()); + accumulator.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); } else { bool k_present = false; while (!k_present && k < len) { @@ -1867,7 +1868,7 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) } // 22.1.3.19 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) -JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::ReduceRight(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ReduceRight); @@ -1878,7 +1879,7 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1890,7 +1891,7 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } @@ -1917,7 +1918,7 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) // c. If kPresent is false, throw a TypeError exception. JSMutableHandle accumulator(thread, JSTaggedValue::Undefined()); if (argc == 2) { // 2:2 means the number of parameters - accumulator.Update(GetCallArg(argv, 1).GetTaggedValue()); + accumulator.Update(builtins_common::GetCallArg(argv, 1).GetTaggedValue()); } else { bool k_present = false; while (!k_present && k >= 0) { @@ -1969,7 +1970,7 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) } // 22.1.3.20 Array.prototype.reverse ( ) -JSTaggedValue BuiltinsArray::Reverse(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Reverse(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Reverse); @@ -1977,7 +1978,7 @@ JSTaggedValue BuiltinsArray::Reverse(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2071,7 +2072,7 @@ JSTaggedValue BuiltinsArray::Reverse(EcmaRuntimeCallInfo *argv) } // 22.1.3.21 Array.prototype.shift ( ) -JSTaggedValue BuiltinsArray::Shift(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Shift(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Shift); @@ -2079,7 +2080,7 @@ JSTaggedValue BuiltinsArray::Shift(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (this_handle->IsStableJSArray(thread)) { return JSStableArray::Shift(JSHandle::Cast(this_handle), argv); } @@ -2159,7 +2160,7 @@ JSTaggedValue BuiltinsArray::Shift(EcmaRuntimeCallInfo *argv) } // 22.1.3.22 Array.prototype.slice (start, end) -JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Slice(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Array, Slice); ASSERT(argv); @@ -2167,7 +2168,7 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2179,7 +2180,7 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). - JSHandle msg0 = GetCallArg(argv, 0); + JSHandle msg0 = builtins_common::GetCallArg(argv, 0); JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg0); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2195,7 +2196,7 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). // 9. ReturnIfAbrupt(relativeEnd). // 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); double arg_end = len; if (!msg1->IsUndefined()) { JSTaggedNumber arg_end_temp = JSTaggedValue::ToInteger(thread, msg1); @@ -2277,7 +2278,7 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) } // 22.1.3.23 Array.prototype.some ( callbackfn [ , thisArg ] ) -JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Some(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Some); @@ -2285,7 +2286,7 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2297,13 +2298,13 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -2333,18 +2334,18 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) bool bool_result = call_result.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (bool_result) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } } k++; } // 9. Return false. - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 22.1.3.24 Array.prototype.sort (comparefn) -JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Sort(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Sort); @@ -2352,11 +2353,11 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsUndefined() && !callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Callable is false", JSTaggedValue::Exception()); } @@ -2409,7 +2410,7 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) // 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Splice(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Splice); @@ -2417,7 +2418,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2433,7 +2434,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) double end = len; double arg_start = 0; if (argc > 0) { - JSHandle msg0 = GetCallArg(argv, 0); + JSHandle msg0 = builtins_common::GetCallArg(argv, 0); JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg0); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2460,7 +2461,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) // d. Let actualDeleteCount be min(max(dc,0), len – actualStart). if (argc > 1) { insert_count = argc - 2; // 2:2 means there are two arguments before the insert items. - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber arg_delete_count = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double delete_count = arg_delete_count.GetNumber(); @@ -2597,7 +2598,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) // 23. Repeat, while items is not empty JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t i = 2; i < argc; i++) { - JSHandle item_value = GetCallArg(argv, i); + JSHandle item_value = builtins_common::GetCallArg(argv, i); key.Update(JSTaggedValue(k)); JSArray::FastSetPropertyByValue(thread, this_obj_val, key, item_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2614,7 +2615,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) } // 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) -JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ToLocaleString); @@ -2624,7 +2625,7 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2638,22 +2639,22 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) // 5. Let separator be the String value for the list-separator String appropriate for the host environment’s // current locale (this is derived in an implementation-defined way). JSHandle sep_handle; - if ((GetCallArg(argv, 0)->IsUndefined())) { + if ((builtins_common::GetCallArg(argv, 0)->IsUndefined())) { sep_handle = JSHandle::Cast(ecma_vm->GetFactory()->NewFromCanBeCompressString(",")); } else { - sep_handle = GetCallArg(argv, 0); + sep_handle = builtins_common::GetCallArg(argv, 0); } JSHandle sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PandaString sep_string = ConvertToPandaString(*sep_string_handle); // 6. If len is zero, return the empty String. if (len == 0) { - return GetTaggedString(thread, ""); + return builtins_common::GetTaggedString(thread, ""); } // Inject locales and options argument into a taggedArray - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); PandaString concat_str; // 7. Let firstElement be Get(array, "0"). @@ -2709,7 +2710,7 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) } // 22.1.3.27 Array.prototype.toString ( ) -JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ToString); @@ -2719,7 +2720,7 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let array be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(array). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2751,7 +2752,7 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv) } // 22.1.3.28 Array.prototype.unshift ( ...items ) -JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Unshift(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Unshift); @@ -2762,7 +2763,7 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2824,7 +2825,7 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) double j = 0; while (j < argc) { to_key.Update(JSTaggedValue(j)); - JSHandle to_value = GetCallArg(argv, j); + JSHandle to_value = builtins_common::GetCallArg(argv, j); JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, to_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); j++; @@ -2840,11 +2841,11 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. Return len+argCount. - return GetTaggedDouble(new_len); + return builtins_common::GetTaggedDouble(new_len); } // 22.1.3.29 Array.prototype.values ( ) -JSTaggedValue BuiltinsArray::Values(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::Values(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Values); @@ -2853,14 +2854,14 @@ JSTaggedValue BuiltinsArray::Values(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). - JSHandle self = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle self = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayIterator(O, "value"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::VALUE)); return iter.GetTaggedValue(); } // 22.1.3.31 Array.prototype [ @@unscopables ] -JSTaggedValue BuiltinsArray::Unscopables(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array::proto::GetUnscopables(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); diff --git a/runtime/builtins/builtins_array.h b/runtime/builtins/builtins_array.h deleted file mode 100644 index 51d9e996451dfe5bc487cb20972cd22db4a75f22..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_array.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_ARRAY_H -#define ECMASCRIPT_BUILTINS_BUILTINS_ARRAY_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -static constexpr uint8_t INDEX_TWO = 2; -static constexpr uint8_t INDEX_THREE = 3; -class BuiltinsArray : public ecmascript::base::BuiltinsBase { -public: - // 22.1.1 - static JSTaggedValue ArrayConstructor(EcmaRuntimeCallInfo *argv); - - // 22.1.2.1 - static JSTaggedValue From(EcmaRuntimeCallInfo *argv); - // 22.1.2.2 - static JSTaggedValue IsArray(EcmaRuntimeCallInfo *argv); - // 22.1.2.3 - static JSTaggedValue Of(EcmaRuntimeCallInfo *argv); - // 22.1.2.5 - static JSTaggedValue Species(EcmaRuntimeCallInfo *argv); - - // prototype - // 22.1.3.1 - static JSTaggedValue Concat(EcmaRuntimeCallInfo *argv); - // 22.1.3.3 - static JSTaggedValue CopyWithin(EcmaRuntimeCallInfo *argv); - // 22.1.3.4 - static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); - // 22.1.3.5 - static JSTaggedValue Every(EcmaRuntimeCallInfo *argv); - // ES2019 22.1.3.10 - static JSTaggedValue Flat(EcmaRuntimeCallInfo *argv); - // ES2019 22.1.3.11 - static JSTaggedValue FlatMap(EcmaRuntimeCallInfo *argv); - // 22.1.3.6 - static JSTaggedValue Fill(EcmaRuntimeCallInfo *argv); - // 22.1.3.7 - static JSTaggedValue Filter(EcmaRuntimeCallInfo *argv); - // 22.1.3.8 - static JSTaggedValue Find(EcmaRuntimeCallInfo *argv); - // 22.1.3.9 - static JSTaggedValue FindIndex(EcmaRuntimeCallInfo *argv); - // 22.1.3.10 - static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); - // ES2021 23.1.3.13 - static JSTaggedValue Includes(EcmaRuntimeCallInfo *argv); - // 22.1.3.11 - static JSTaggedValue IndexOf(EcmaRuntimeCallInfo *argv); - // 22.1.3.12 - static JSTaggedValue Join(EcmaRuntimeCallInfo *argv); - // 22.1.3.13 - static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); - // 22.1.3.14 - static JSTaggedValue LastIndexOf(EcmaRuntimeCallInfo *argv); - // 22.1.3.15 - static JSTaggedValue Map(EcmaRuntimeCallInfo *argv); - // 22.1.3.16 - static JSTaggedValue Pop(EcmaRuntimeCallInfo *argv); - // 22.1.3.17 - static JSTaggedValue Push(EcmaRuntimeCallInfo *argv); - // 22.1.3.18 - static JSTaggedValue Reduce(EcmaRuntimeCallInfo *argv); - // 22.1.3.19 - static JSTaggedValue ReduceRight(EcmaRuntimeCallInfo *argv); - // 22.1.3.20 - static JSTaggedValue Reverse(EcmaRuntimeCallInfo *argv); - // 22.1.3.21 - static JSTaggedValue Shift(EcmaRuntimeCallInfo *argv); - // 22.1.3.22 - static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); - // 22.1.3.23 - static JSTaggedValue Some(EcmaRuntimeCallInfo *argv); - // 22.1.3.24 - static JSTaggedValue Sort(EcmaRuntimeCallInfo *argv); - // 22.1.3.25 - static JSTaggedValue Splice(EcmaRuntimeCallInfo *argv); - // 22.1.3.26 - static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); - // 22.1.3.27 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 22.1.3.28 - static JSTaggedValue Unshift(EcmaRuntimeCallInfo *argv); - // 22.1.3.29 - static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); - // 22.1.3.31 - static JSTaggedValue Unscopables(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ARRAY_H diff --git a/runtime/builtins/builtins_arraybuffer.cpp b/runtime/builtins/builtins_arraybuffer.cpp index 4111ab24baf5ca79daba94138b7974e8eaae18fd..1fd5525c27305d12e285014fdfce524e3fd6915b 100644 --- a/runtime/builtins/builtins_arraybuffer.cpp +++ b/runtime/builtins/builtins_arraybuffer.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" - #include #include "plugins/ecmascript/runtime/base/builtins_base.h" @@ -32,19 +30,38 @@ #include "securec.h" namespace panda::ecmascript::builtins { +enum NumberSize : uint8_t { + UINT16 = 2, + INT16 = 2, + UINT32 = 4, + INT32 = 4, + FLOAT32 = 4, + FLOAT64 = 8, + BIGINT64 = 8, + BIGUINT64 = 8 +}; +union UnionType32 { + uint32_t u_value; + float value; +} __attribute__((packed, may_alias)); +union UnionType64 { + uint64_t u_value; + double value; +} __attribute__((packed, may_alias)); + // 24.1.2.1 ArrayBuffer(length) -JSTaggedValue BuiltinsArrayBuffer::ArrayBufferConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array_buffer::ArrayBufferConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayBuffer, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); // 1. If NewTarget is undefined, throw a TypeError exception. if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "newtarget is undefined", JSTaggedValue::Exception()); } - JSHandle length_handle = GetCallArg(argv, 0); + JSHandle length_handle = builtins_common::GetCallArg(argv, 0); JSTaggedNumber len_num = JSTaggedValue::ToIndex(thread, length_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double length = len_num.GetNumber(); @@ -52,38 +69,38 @@ JSTaggedValue BuiltinsArrayBuffer::ArrayBufferConstructor(EcmaRuntimeCallInfo *a } // 24.1.3.1 ArrayBuffer.isView(arg) -JSTaggedValue BuiltinsArrayBuffer::IsView(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array_buffer::IsView(EcmaRuntimeCallInfo *argv) { ASSERT(argv); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); - JSHandle arg = GetCallArg(argv, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); // 1. If Type(arg) is not Object, return false. if (!arg->IsECMAObject()) { - return BuiltinsArrayBuffer::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. if (arg->IsDataView() || arg->IsTypedArray()) { - return BuiltinsArrayBuffer::GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // 3. Return false. - return BuiltinsArrayBuffer::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 24.1.3.3 get ArrayBuffer [ @@species ] -JSTaggedValue BuiltinsArrayBuffer::Species(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array_buffer::GetSpecies(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - return GetThis(argv).GetTaggedValue(); + return builtins_common::GetThis(argv).GetTaggedValue(); } // 24.1.4.1 get ArrayBuffer.prototype.byteLength -JSTaggedValue BuiltinsArrayBuffer::GetByteLength(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array_buffer::proto::GetByteLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSThread *thread = argv->GetThread(); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an object", JSTaggedValue::Exception()); @@ -104,7 +121,7 @@ JSTaggedValue BuiltinsArrayBuffer::GetByteLength(EcmaRuntimeCallInfo *argv) } // 24.1.4.3 ArrayBuffer.prototype.slice(start, end) -JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::array_buffer::proto::Slice(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayBuffer, Slice); @@ -113,7 +130,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an object", JSTaggedValue::Exception()); @@ -130,7 +147,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) // 5. Let len be the value of O’s [[ArrayBufferByteLength]] internal slot. JSTaggedNumber length_num = JSTaggedNumber::FromIntOrDouble(thread, arr_buf->GetArrayBufferByteLength()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle start_handle = GetCallArg(argv, 0); + JSHandle start_handle = builtins_common::GetCallArg(argv, 0); // 6. Let relativeStart be ToInteger(start). JSTaggedNumber relative_start = JSTaggedValue::ToInteger(thread, start_handle); // 7. ReturnIfAbrupt(relativeStart). @@ -147,7 +164,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) first = std::min(start, len); } // 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). - JSHandle end_handle = GetCallArg(argv, 1); + JSHandle end_handle = builtins_common::GetCallArg(argv, 1); if (end_handle->IsUndefined()) { end = len; } else { @@ -216,8 +233,8 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) } // 24.1.1.1 AllocateArrayBuffer(constructor, byteLength) -JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, - double byte_length) +JSTaggedValue builtins::array_buffer::AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, + double byte_length) { BUILTINS_API_TRACE(thread, ArrayBuffer, AllocateArrayBuffer); /** @@ -257,7 +274,7 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J } // 24.1.1.2 IsDetachedBuffer() -bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue array_buffer) +bool builtins::array_buffer::IsDetachedBuffer(JSTaggedValue array_buffer) { // 1. Assert: Type(arrayBuffer) is Object and it has an [[ArrayBufferData]] internal slot. ASSERT(array_buffer.IsArrayBuffer()); @@ -269,8 +286,8 @@ bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue array_buffer) } // 24.1.1.4 -JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHandle &src_buffer, - int32_t src_byte_offset, JSHandle constructor) +JSTaggedValue builtins::array_buffer::CloneArrayBuffer(JSThread *thread, const JSHandle &src_buffer, + int32_t src_byte_offset, JSHandle constructor) { BUILTINS_API_TRACE(thread, ArrayBuffer, CloneArrayBuffer); // 1. Assert: Type(srcBuffer) is Object and it has an [[ArrayBufferData]] internal slot. @@ -319,133 +336,9 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa return tagged_buf; } -// 24.1.1.5 -// NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, - int32_t byte_index, DataViewType type, bool little_endian) -{ - JSArrayBuffer *js_array_buffer = JSArrayBuffer::Cast(arr_buf->GetTaggedObject()); - JSTaggedValue data = js_array_buffer->GetArrayBufferData(); - void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); - auto *block = reinterpret_cast(pointer); - switch (type) { - case DataViewType::UINT8: - case DataViewType::UINT8_CLAMPED: { - uint8_t res = block[byte_index]; // NOLINT - return GetTaggedInt(res); - } - case DataViewType::INT8: { - uint8_t res = block[byte_index]; // NOLINT - auto int8_res = static_cast(res); - return GetTaggedInt(int8_res); - } - case DataViewType::UINT16: - return GetValueFromBufferForInteger(block, byte_index, little_endian); - case DataViewType::INT16: - return GetValueFromBufferForInteger(block, byte_index, little_endian); - case DataViewType::UINT32: - return GetValueFromBufferForInteger(block, byte_index, little_endian); - case DataViewType::INT32: - return GetValueFromBufferForInteger(block, byte_index, little_endian); - case DataViewType::FLOAT32: - return GetValueFromBufferForFloat(block, byte_index, - little_endian); - case DataViewType::FLOAT64: - return GetValueFromBufferForFloat(block, byte_index, - little_endian); - case DataViewType::BIGINT64: - return GetValueFromBufferForBigInt(thread, block, byte_index, little_endian); - case DataViewType::BIGUINT64: - return GetValueFromBufferForBigInt(thread, block, byte_index, - little_endian); - default: - break; - } - - UNREACHABLE(); -} - -// 24.1.1.6 -JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSThread *thread, JSHandle arr_buf, - int32_t byte_index, DataViewType type, - const JSHandle &value, bool little_endian) -{ - JSArrayBuffer *js_array_buffer = JSArrayBuffer::Cast(arr_buf->GetTaggedObject()); - JSTaggedValue data = js_array_buffer->GetArrayBufferData(); - void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); - auto *block = reinterpret_cast(pointer); - - if (IsBigIntElementType(type)) { - switch (type) { - case DataViewType::BIGINT64: - SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - break; - case DataViewType::BIGUINT64: - SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - break; - default: - UNREACHABLE(); - } - return JSTaggedValue::Undefined(); - } - - double val = value->GetNumber(); - - switch (type) { - case DataViewType::UINT8: - SetValueInBufferForByte(val, block, byte_index); - break; - case DataViewType::UINT8_CLAMPED: - SetValueInBufferForUint8Clamped(val, block, byte_index); - break; - case DataViewType::INT8: - SetValueInBufferForByte(val, block, byte_index); - break; - case DataViewType::UINT16: - SetValueInBufferForInteger(val, block, byte_index, little_endian); - break; - case DataViewType::INT16: - SetValueInBufferForInteger(val, block, byte_index, little_endian); - break; - case DataViewType::UINT32: - SetValueInBufferForInteger(val, block, byte_index, little_endian); - break; - case DataViewType::INT32: - SetValueInBufferForInteger(val, block, byte_index, little_endian); - break; - case DataViewType::FLOAT32: - SetValueInBufferForFloat(val, block, byte_index, little_endian); - break; - case DataViewType::FLOAT64: - SetValueInBufferForFloat(val, block, byte_index, little_endian); - break; - default: - UNREACHABLE(); - } - return JSTaggedValue::Undefined(); -} - -// es12 25.1.2.7 IsBigIntElementType ( type ) -bool BuiltinsArrayBuffer::IsBigIntElementType(DataViewType type) -{ - return type == DataViewType::BIGINT64 || type == DataViewType::BIGUINT64; -} - -template -void BuiltinsArrayBuffer::SetTypeData(uint8_t *block, T value, int32_t index) -{ - int32_t size_count = sizeof(T); - auto *res = reinterpret_cast(&value); - for (int i = 0; i < size_count; i++) { - *(block + index + i) = *(res + i); // NOLINT - } -} - -template +template // NOLINTNEXTLINE(readability-non-const-parameter) -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, bool little_endian) +JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, bool little_endian) { static_assert(std::is_integral_v, "T must be integral"); static_assert(sizeof(T) == SIZE, "Invalid number size"); @@ -465,15 +358,32 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForInteger(uint8_t *block, if constexpr (std::is_same_v) { // NOLINTNEXTLINE(clang-diagnostic-sign-compare) if (res > static_cast(std::numeric_limits::max())) { - return GetTaggedDouble(static_cast(res)); + return builtins_common::GetTaggedDouble(static_cast(res)); } } - return GetTaggedInt(res); + return builtins_common::GetTaggedInt(res); } -template +template +JSTaggedValue GetValueFromBufferForBigInt(JSThread *thread, const uint8_t *block, uint32_t byte_index, + bool little_endian) +{ + static_assert(std::is_same_v || std::is_same_v, "T must be uint64_t/int64_t"); + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + auto p_tmp = UnalignedLoad(reinterpret_cast(block + byte_index)); + if (!little_endian) { + p_tmp = BSWAP(p_tmp); + } + // NOLINTNEXTLINE(readability-braces-around-statements,bugprone-suspicious-semicolon) + if constexpr (std::is_same_v) { + return BigInt::Uint64ToBigInt(thread, p_tmp).GetTaggedValue(); + } + return BigInt::Int64ToBigInt(thread, p_tmp).GetTaggedValue(); +} + +template // NOLINTNEXTLINE(readability-non-const-parameter) -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, int32_t byte_index, bool little_endian) +JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, int32_t byte_index, bool little_endian) { static_assert(std::is_same_v || std::is_same_v, "T must be float type"); static_assert(sizeof(T) == SIZE, "Invalid number size"); @@ -486,11 +396,11 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, in // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) if (std::isnan(union_value.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(union_value.value); + return builtins_common::GetTaggedDouble(union_value.value); } if (!little_endian) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); + return builtins_common::GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); } // NOLINTNEXTLINE(readability-misleading-indentation) } else if constexpr (std::is_same_v) { @@ -499,36 +409,75 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, in // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) if (std::isnan(union_value.value) && !JSTaggedValue::IsImpureNaN(union_value.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(union_value.value); + return builtins_common::GetTaggedDouble(union_value.value); } if (!little_endian) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); + return builtins_common::GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); } } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(union_value.value); + return builtins_common::GetTaggedDouble(union_value.value); } -template -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForBigInt(JSThread *thread, const uint8_t *block, - uint32_t byte_index, bool little_endian) +// 24.1.1.5 +// NOLINTNEXTLINE(readability-function-size) +JSTaggedValue builtins::array_buffer::GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, + int32_t byte_index, DataViewType type, bool little_endian) { - static_assert(std::is_same_v || std::is_same_v, "T must be uint64_t/int64_t"); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto p_tmp = UnalignedLoad(reinterpret_cast(block + byte_index)); - if (!little_endian) { - p_tmp = BSWAP(p_tmp); + JSArrayBuffer *js_array_buffer = JSArrayBuffer::Cast(arr_buf->GetTaggedObject()); + JSTaggedValue data = js_array_buffer->GetArrayBufferData(); + void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); + auto *block = reinterpret_cast(pointer); + switch (type) { + case DataViewType::UINT8: + case DataViewType::UINT8_CLAMPED: { + uint8_t res = block[byte_index]; // NOLINT + return builtins_common::GetTaggedInt(res); + } + case DataViewType::INT8: { + uint8_t res = block[byte_index]; // NOLINT + auto int8_res = static_cast(res); + return builtins_common::GetTaggedInt(int8_res); + } + case DataViewType::UINT16: + return GetValueFromBufferForInteger(block, byte_index, little_endian); + case DataViewType::INT16: + return GetValueFromBufferForInteger(block, byte_index, little_endian); + case DataViewType::UINT32: + return GetValueFromBufferForInteger(block, byte_index, little_endian); + case DataViewType::INT32: + return GetValueFromBufferForInteger(block, byte_index, little_endian); + case DataViewType::FLOAT32: + return GetValueFromBufferForFloat(block, byte_index, + little_endian); + case DataViewType::FLOAT64: + return GetValueFromBufferForFloat(block, byte_index, + little_endian); + case DataViewType::BIGINT64: + return GetValueFromBufferForBigInt(thread, block, byte_index, little_endian); + case DataViewType::BIGUINT64: + return GetValueFromBufferForBigInt(thread, block, byte_index, + little_endian); + default: + break; } - // NOLINTNEXTLINE(readability-braces-around-statements,bugprone-suspicious-semicolon) - if constexpr (std::is_same_v) { - return BigInt::Uint64ToBigInt(thread, p_tmp).GetTaggedValue(); + + UNREACHABLE(); +} + +template +void SetTypeData(uint8_t *block, T value, int32_t index) +{ + int32_t size_count = sizeof(T); + auto *res = reinterpret_cast(&value); + for (int i = 0; i < size_count; i++) { + *(block + index + i) = *(res + i); // NOLINT } - return BigInt::Int64ToBigInt(thread, p_tmp).GetTaggedValue(); } template -void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, int32_t byte_index) +void SetValueInBufferForByte(double val, uint8_t *block, int32_t byte_index) { static_assert(std::is_same_v || std::is_same_v, "T must be int8/uint8"); T res; @@ -542,7 +491,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, in SetTypeData(block, res, byte_index); } -void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byte_index) +void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byte_index) { uint8_t res; if (std::isnan(val) || val <= 0) { @@ -558,7 +507,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *b } template -void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, int32_t byte_index, bool little_endian) +void SetValueInBufferForInteger(double val, uint8_t *block, int32_t byte_index, bool little_endian) { static_assert(std::is_integral_v, "T must be integral"); static_assert(sizeof(T) >= sizeof(uint16_t), "T must have a size more than uint8"); @@ -584,7 +533,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, } template -void BuiltinsArrayBuffer::SetValueInBufferForFloat(double val, uint8_t *block, int32_t byte_index, bool little_endian) +void SetValueInBufferForFloat(double val, uint8_t *block, int32_t byte_index, bool little_endian) { static_assert(std::is_same_v || std::is_same_v, "T must be float type"); auto data = static_cast(val); @@ -606,8 +555,8 @@ void BuiltinsArrayBuffer::SetValueInBufferForFloat(double val, uint8_t *block, i } template -void BuiltinsArrayBuffer::SetValueInBufferForBigInt(JSThread *thread, const JSHandle &val, - uint8_t *block, uint32_t byte_index, bool little_endian) +void SetValueInBufferForBigInt(JSThread *thread, const JSHandle &val, uint8_t *block, + uint32_t byte_index, bool little_endian) { static_assert(std::is_same_v || std::is_same_v, "T must be int64_t/uint64_t"); T value = 0; @@ -625,4 +574,73 @@ void BuiltinsArrayBuffer::SetValueInBufferForBigInt(JSThread *thread, const JSHa } SetTypeData(block, value, byte_index); } + +// es12 25.1.2.7 IsBigIntElementType ( type ) +bool IsBigIntElementType(DataViewType type) +{ + return type == DataViewType::BIGINT64 || type == DataViewType::BIGUINT64; +} + +// 24.1.1.6 +JSTaggedValue builtins::array_buffer::SetValueInBuffer(JSThread *thread, JSHandle arr_buf, + int32_t byte_index, DataViewType type, + const JSHandle &value, bool little_endian) +{ + JSArrayBuffer *js_array_buffer = JSArrayBuffer::Cast(arr_buf->GetTaggedObject()); + JSTaggedValue data = js_array_buffer->GetArrayBufferData(); + void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); + auto *block = reinterpret_cast(pointer); + + if (IsBigIntElementType(type)) { + switch (type) { + case DataViewType::BIGINT64: + SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + break; + case DataViewType::BIGUINT64: + SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + break; + default: + UNREACHABLE(); + } + return JSTaggedValue::Undefined(); + } + + double val = value->GetNumber(); + + switch (type) { + case DataViewType::UINT8: + SetValueInBufferForByte(val, block, byte_index); + break; + case DataViewType::UINT8_CLAMPED: + SetValueInBufferForUint8Clamped(val, block, byte_index); + break; + case DataViewType::INT8: + SetValueInBufferForByte(val, block, byte_index); + break; + case DataViewType::UINT16: + SetValueInBufferForInteger(val, block, byte_index, little_endian); + break; + case DataViewType::INT16: + SetValueInBufferForInteger(val, block, byte_index, little_endian); + break; + case DataViewType::UINT32: + SetValueInBufferForInteger(val, block, byte_index, little_endian); + break; + case DataViewType::INT32: + SetValueInBufferForInteger(val, block, byte_index, little_endian); + break; + case DataViewType::FLOAT32: + SetValueInBufferForFloat(val, block, byte_index, little_endian); + break; + case DataViewType::FLOAT64: + SetValueInBufferForFloat(val, block, byte_index, little_endian); + break; + default: + UNREACHABLE(); + } + return JSTaggedValue::Undefined(); +} + } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_arraybuffer.h b/runtime/builtins/builtins_arraybuffer.h deleted file mode 100644 index 055431a7d9415405a72fa5d0abffa9560a57c8f1..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_arraybuffer.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_ARRAYBUFFER_H -#define ECMASCRIPT_BUILTINS_BUILTINS_ARRAYBUFFER_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/base/number_helper.h" -#include "plugins/ecmascript/runtime/js_dataview.h" - -namespace panda::ecmascript::builtins { -static constexpr double NUMBER_HALF = 0.5; -static constexpr uint32_t BITS_EIGHT = 8; -static constexpr uint32_t BITS_TWENTY_FOUR = 24; -static constexpr uint32_t BITS_FORTY = 40; -static constexpr uint32_t BITS_FIFTY_SIX = 56; -using DataViewType = ecmascript::DataViewType; -union UnionType32 { - uint32_t u_value; - float value; -} __attribute__((packed, may_alias)); -union UnionType64 { - uint64_t u_value; - double value; -} __attribute__((packed, may_alias)); -class BuiltinsArrayBuffer : public ecmascript::base::BuiltinsBase { -public: - enum NumberSize : uint8_t { - UINT16 = 2, - INT16 = 2, - UINT32 = 4, - INT32 = 4, - FLOAT32 = 4, - FLOAT64 = 8, - BIGINT64 = 8, - BIGUINT64 = 8 - }; - - // 24.1.2.1 ArrayBuffer(length) - static JSTaggedValue ArrayBufferConstructor(EcmaRuntimeCallInfo *argv); - // 24.1.3.1 ArrayBuffer.isView(arg) - static JSTaggedValue IsView(EcmaRuntimeCallInfo *argv); - // 24.1.3.3 get ArrayBuffer[@@species] - static JSTaggedValue Species(EcmaRuntimeCallInfo *argv); - // 24.1.4.1 get ArrayBuffer.prototype.byteLength - static JSTaggedValue GetByteLength(EcmaRuntimeCallInfo *argv); - // 24.1.4.3 ArrayBuffer.prototype.slice() - static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); - // 24.1.1.2 IsDetachedBuffer(arrayBuffer) - static bool IsDetachedBuffer(JSTaggedValue array_buffer); - // 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian ) - static JSTaggedValue GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, int32_t byte_index, - DataViewType type, bool little_endian); - // 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isLittleEndian ) - static JSTaggedValue SetValueInBuffer(JSThread *thread, JSHandle arr_buf, int32_t byte_index, - DataViewType type, const JSHandle &value, bool little_endian); - // 24.1.1.4 CloneArrayBuffer( srcBuffer, srcByteOffset [, cloneConstructor] ) - static JSTaggedValue CloneArrayBuffer(JSThread *thread, const JSHandle &src_buffer, - int32_t src_byte_offset, JSHandle constructor); - // 24.1.1.1 AllocateArrayBuffer(constructor, byteLength) - static JSTaggedValue AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, - double byte_length); - // es12 25.1.2.7 IsBigIntElementType ( type ) - static bool IsBigIntElementType(DataViewType type); - -private: - template - static T LittleEndianToBigEndian(T li_value); - - template - static T LittleEndianToBigEndian64Bit(T li_value); - - template - static void SetTypeData(uint8_t *block, T value, int32_t index); - - template - static JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, bool little_endian); - - template - static JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, int32_t byte_index, bool little_endian); - - template - static JSTaggedValue GetValueFromBufferForBigInt(JSThread *thread, const uint8_t *block, uint32_t byte_index, - bool little_endian); - - template - static void SetValueInBufferForByte(double val, uint8_t *block, int32_t byte_index); - - static void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byte_index); - - template - static void SetValueInBufferForInteger(double val, uint8_t *block, int32_t byte_index, bool little_endian); - - template - static void SetValueInBufferForFloat(double val, uint8_t *block, int32_t byte_index, bool little_endian); - - template - static void SetValueInBufferForBigInt(JSThread *thread, const JSHandle &val, uint8_t *block, - uint32_t byte_index, bool little_endian); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ARRAYBUFFER_H diff --git a/runtime/builtins/builtins_async_from_sync_iterator.cpp b/runtime/builtins/builtins_async_from_sync_iterator.cpp index 32c12b34ba9848029ecdffc07102365d50dcb0f9..ab63e56c65487da6a603b54e163ba9c99b1263dc 100644 --- a/runtime/builtins/builtins_async_from_sync_iterator.cpp +++ b/runtime/builtins/builtins_async_from_sync_iterator.cpp @@ -3,7 +3,7 @@ * Description: */ -#include "plugins/ecmascript/runtime/builtins/builtins_async_from_sync_iterator.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" #include "plugins/ecmascript/runtime/js_promise.h" @@ -12,7 +12,7 @@ namespace panda::ecmascript::builtins { // 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.next(value) -JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::async_from_sync_iterator::proto::Next(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), AsyncFromSyncIteratorPrototype, Next); @@ -22,7 +22,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext( [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_object = GetThis(argv); + JSHandle this_object = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. JSHandle async_from_sync_iterator_object( thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); @@ -41,7 +41,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext( // 5. If value is present, then if (argv->GetArgsNumber() > 0) { // a. Let result be IteratorNext(syncIteratorRecord, value). - result.Update(JSIterator::IteratorNext(thread, iterator, next_method, GetCallArg(argv, 0))); + result.Update(JSIterator::IteratorNext(thread, iterator, next_method, builtins_common::GetCallArg(argv, 0))); } else { // 6. Else, // a. Let result be IteratorNext(syncIteratorRecord). @@ -59,7 +59,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext( } // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.return(value) -JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeReturn(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::async_from_sync_iterator::proto::Return(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), AsyncFromSyncIteratorPrototype, Return); @@ -70,7 +70,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeRetur [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_object = GetThis(argv); + JSHandle this_object = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. JSHandle async_from_sync_iterator_object( thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); @@ -93,7 +93,8 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeRetur // 7. If return is undefined, then if (return_method->IsUndefined()) { // a. Let iterResult be ! CreateIterResultObject(value, true). - JSHandle iter_result = JSIterator::CreateIterResultObject(thread, GetCallArg(argv, 0), true); + JSHandle iter_result = + JSIterator::CreateIterResultObject(thread, builtins_common::GetCallArg(argv, 0), true); // b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »). JSHandle resolve(thread, promise_capability->GetResolve()); @@ -113,7 +114,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeRetur if (argv->GetArgsNumber() > 0) { // a. Let result be Call(return, syncIterator, « value »). info = NewRuntimeCallInfo(thread, return_method, iterator, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(GetCallArg(argv, 0)); + info->SetCallArgs(builtins_common::GetCallArg(argv, 0)); } else { // 9. Else, // a. Let result be Call(return, syncIterator). @@ -148,7 +149,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeRetur } // 27.1.4.2.4 %AsyncFromSyncIteratorPrototype%.throw(exception) -JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::async_from_sync_iterator::proto::Throw(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), AsyncFromSyncIteratorPrototype, Throw); @@ -160,7 +161,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_object = GetThis(argv); + JSHandle this_object = builtins_common::GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. JSHandle async_from_sync_iterator_object( thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); @@ -187,7 +188,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow ScopedCallInfo info; if (argv->GetArgsNumber() > 0) { info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(GetCallArg(argv, 0)); + info->SetCallArgs(builtins_common::GetCallArg(argv, 0)); } else { info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); } @@ -205,7 +206,7 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow if (argv->GetArgsNumber() > 0) { // a. Let result be Call(throw, syncIterator, « value »). info = NewRuntimeCallInfo(thread, throw_method, iterator, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(GetCallArg(argv, 0)); + info->SetCallArgs(builtins_common::GetCallArg(argv, 0)); } else { // 9. Else, // a. Let result be Call(throw, syncIterator). diff --git a/runtime/builtins/builtins_async_from_sync_iterator.h b/runtime/builtins/builtins_async_from_sync_iterator.h deleted file mode 100644 index dd3bfe5f6fd7dca8377e130f2d8ed4a54f695d11..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_async_from_sync_iterator.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. - * Description: - */ - -#ifndef ECMASCRIPT_BUILTINS_ASYNC_FROM_SYNC_ITERATOR_H -#define ECMASCRIPT_BUILTINS_ASYNC_FROM_SYNC_ITERATOR_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsAsyncFromSyncIterator : public ecmascript::base::BuiltinsBase { -public: - // 27.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next - static JSTaggedValue AsyncFromSyncIteratorPrototypeNext(EcmaRuntimeCallInfo *argv); - - // 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return - static JSTaggedValue AsyncFromSyncIteratorPrototypeReturn(EcmaRuntimeCallInfo *argv); - - // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw - static JSTaggedValue AsyncFromSyncIteratorPrototypeThrow(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_ASYNC_FROM_SYNC_ITERATOR_H diff --git a/runtime/builtins/builtins_async_function.cpp b/runtime/builtins/builtins_async_function.cpp index 53ba1fa777d083e072de4dda7b3925757694dd8b..49157f003a26f45fc92c659aa29a4a1fd3ff6c2f 100644 --- a/runtime/builtins/builtins_async_function.cpp +++ b/runtime/builtins/builtins_async_function.cpp @@ -13,14 +13,14 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_async_function.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/js_eval.h" -namespace panda::ecmascript::builtins { +namespace panda::ecmascript { // ecma2017 25.5.1.1 AsyncFunction (p1, p2, ... , pn, body) -JSTaggedValue BuiltinsAsyncFunction::AsyncFunctionConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::async_function::AsyncFunctionConstructor(EcmaRuntimeCallInfo *argv) { return EvalUtils::CreateDynamicFunction(argv, EvalUtils::DynamicFunctionKind::ASYNC); } -} // namespace panda::ecmascript::builtins +} // namespace panda::ecmascript diff --git a/runtime/builtins/builtins_async_function.h b/runtime/builtins/builtins_async_function.h deleted file mode 100644 index 26ee04e0cca4571f4687a43ca7c5d5748e5e3d98..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_async_function.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_ASYNC_FUNCTION_H -#define ECMASCRIPT_BUILTINS_BUILTINS_ASYNC_FUNCTION_H - -#include "plugins/ecmascript/runtime/js_tagged_value-inl.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsAsyncFunction : public ecmascript::base::BuiltinsBase { -public: - // ecma2020 25.5.1.1 AsyncFunction (p1, p2, ... , pn, body) - static JSTaggedValue AsyncFunctionConstructor(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ASYNC_FUNCTION_H diff --git a/runtime/builtins/builtins_async_generator.cpp b/runtime/builtins/builtins_async_generator.cpp index f239ac69c6e7af113eb2fc6a8607a283de5d458a..c4372adf4c9f4d14c0a11d0d1994f9119d281d78 100644 --- a/runtime/builtins/builtins_async_generator.cpp +++ b/runtime/builtins/builtins_async_generator.cpp @@ -3,29 +3,29 @@ * Description: */ -#include "plugins/ecmascript/runtime/builtins/builtins_async_generator.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/js_eval.h" #include "plugins/ecmascript/runtime/js_function.h" #include "plugins/ecmascript/runtime/js_async_generator_object.h" namespace panda::ecmascript::builtins { // 27.4.1.1 AsyncGeneratorFunction (p1, p2, ... , pn, body) -JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue async_generator_function::AsyncGeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv) { return EvalUtils::CreateDynamicFunction(argv, EvalUtils::DynamicFunctionKind::ASYNC_GENERATOR); } // 27.6.1.2 AsyncGenerator.prototype.next(value) -JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeNext(EcmaRuntimeCallInfo *argv) +JSTaggedValue async_generator::proto::Next(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Next); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle generator = GetThis(argv); + JSHandle generator = builtins_common::GetThis(argv); // 2. Let completion be NormalCompletion(value). - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::NORMAL, value); @@ -37,16 +37,16 @@ JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeNext(EcmaRuntimeCal } // 27.6.1.3 AsyncGenerator.prototype.return(value) -JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeReturn(EcmaRuntimeCallInfo *argv) +JSTaggedValue async_generator::proto::Return(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Return); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle generator = GetThis(argv); + JSHandle generator = builtins_common::GetThis(argv); // 2. Let completion be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::RETURN, value); @@ -58,17 +58,17 @@ JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeReturn(EcmaRuntimeC } // 27.6.1.4 AsyncGenerator.prototype.throw(exception) -JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeThrow(EcmaRuntimeCallInfo *argv) +JSTaggedValue async_generator::proto::Throw(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Throw); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle generator = GetThis(argv); + JSHandle generator = builtins_common::GetThis(argv); // 2. Let completion be ThrowCompletion(exception). - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::THROW, value); diff --git a/runtime/builtins/builtins_async_generator.h b/runtime/builtins/builtins_async_generator.h deleted file mode 100644 index fbb91c85a3e7a74cef8604a00c1755add687a985..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_async_generator.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. - * Description: - */ - -#ifndef ECMASCRIPT_BUILTINS_ASYNC_GENERATOR_H -#define ECMASCRIPT_BUILTINS_ASYNC_GENERATOR_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsAsyncGenerator : public ecmascript::base::BuiltinsBase { -public: - // 27.4.1.1 AsyncGeneratorFunction(p1, p2, … , pn, body) - static JSTaggedValue AsyncGeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv); - - // 27.6.1.2 AsyncGenerator.prototype.next(value) - static JSTaggedValue AsyncGeneratorPrototypeNext(EcmaRuntimeCallInfo *argv); - - // 27.6.1.3 AsyncGenerator.prototype.return(value) - static JSTaggedValue AsyncGeneratorPrototypeReturn(EcmaRuntimeCallInfo *argv); - - // 27.6.1.4 AsyncGenerator.prototype.throw(exception) - static JSTaggedValue AsyncGeneratorPrototypeThrow(EcmaRuntimeCallInfo *argv); - - // 26.4.1.5 AsyncGenerator.prototype[@@toStringTag] -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_ASYNC_GENERATOR_H diff --git a/runtime/builtins/builtins_async_iterator.cpp b/runtime/builtins/builtins_async_iterator.cpp index 8aa1a8de0507641bb7b248b1fe41e8ae5671d304..20a272a182970e412795549600a16c5ba766b548 100644 --- a/runtime/builtins/builtins_async_iterator.cpp +++ b/runtime/builtins/builtins_async_iterator.cpp @@ -3,16 +3,15 @@ * Description: */ -#include "plugins/ecmascript/runtime/builtins/builtins_async_iterator.h" +#include "plugins/ecmascript/runtime/builtins.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/js_iterator.h" namespace panda::ecmascript::builtins { // 27.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( ) -JSTaggedValue BuiltinsAsyncIterator::GetAsyncIteratorObj(EcmaRuntimeCallInfo *argv) +JSTaggedValue async_iterator::proto::AsyncIterator(EcmaRuntimeCallInfo *argv) { - return ecmascript::base::BuiltinsBase::GetThis(argv).GetTaggedValue(); + return ecmascript::builtins_common::GetThis(argv).GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_async_iterator.h b/runtime/builtins/builtins_async_iterator.h deleted file mode 100644 index a726b080f3713e4e4d7eb69a5537c535df7a0d1f..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_async_iterator.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. - * Description: - */ - -#ifndef ECMASCRIPT_BUILTINS_ASYNC_ITERATOR_H -#define ECMASCRIPT_BUILTINS_ASYNC_ITERATOR_H - -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsAsyncIterator : public ecmascript::base::BuiltinsBase { -public: - // 27.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( ) - static JSTaggedValue GetAsyncIteratorObj(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_ASYNC_ITERATOR_H diff --git a/runtime/builtins/builtins_bigint.cpp b/runtime/builtins/builtins_bigint.cpp index 3f8aeb7b2478f82f4d7c79c1e2a592839c84385f..ede5baf9c8b3b4592c6346848cf1fd5b8f3ee2ef 100644 --- a/runtime/builtins/builtins_bigint.cpp +++ b/runtime/builtins/builtins_bigint.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_bigint.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/js_number_format.h" @@ -21,15 +21,40 @@ #include "plugins/ecmascript/runtime/js_bigint.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsBigInt::BigIntConstructor(EcmaRuntimeCallInfo *argv) + +static JSTaggedValue ThisBigIntValue(EcmaRuntimeCallInfo *argv); + +JSTaggedValue ThisBigIntValue(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + JSThread *thread = argv->GetThread(); + JSHandle value = builtins_common::GetThis(argv); + // 1. If Type(value) is BigInt, return value. + if (value->IsBigInt()) { + return value.GetTaggedValue(); + } + // 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then + if (value->IsJSPrimitiveRef()) { + JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(); + // a. Assert: Type(value.[[BigIntData]]) is BigInt. + if (primitive.IsBigInt()) { + // b. Return value.[[BigIntData]]. + return primitive; + } + } + // 3. Throw a TypeError exception. + THROW_TYPE_ERROR_AND_RETURN(thread, "not BigInt type", JSTaggedValue::Exception()); +} + +JSTaggedValue big_int::BigIntConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, Constructor); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); // 1. If NewTarget is not undefined, throw a TypeError exception. - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); if (!new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "BigInt is not a constructor", JSTaggedValue::Exception()); } @@ -43,14 +68,14 @@ JSTaggedValue BuiltinsBigInt::BigIntConstructor(EcmaRuntimeCallInfo *argv) return JSTaggedValue::ToBigInt(thread, value); } -JSTaggedValue BuiltinsBigInt::AsUintN(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_int::AsUintN(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, AsUintN); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle bits = GetCallArg(argv, 0); - JSHandle bigint = GetCallArg(argv, 1); + JSHandle bits = builtins_common::GetCallArg(argv, 0); + JSHandle bigint = builtins_common::GetCallArg(argv, 1); // 1. Let bits be ? ToIndex(bits). JSTaggedNumber index = JSTaggedValue::ToIndex(thread, bits); // 2. Let bigint be ? ToBigInt(bigint). @@ -61,14 +86,14 @@ JSTaggedValue BuiltinsBigInt::AsUintN(EcmaRuntimeCallInfo *argv) return BigInt::AsUintN(thread, index, js_bigint_val); } -JSTaggedValue BuiltinsBigInt::AsIntN(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_int::AsIntN(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, AsIntN); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle bits = GetCallArg(argv, 0); - JSHandle bigint = GetCallArg(argv, 1); + JSHandle bits = builtins_common::GetCallArg(argv, 0); + JSHandle bigint = builtins_common::GetCallArg(argv, 1); // 1. Let bits be ? ToIndex(bits). JSTaggedNumber index = JSTaggedValue::ToIndex(thread, bits); // 2. Let bigint be ? ToBigInt(bigint). @@ -80,7 +105,7 @@ JSTaggedValue BuiltinsBigInt::AsIntN(EcmaRuntimeCallInfo *argv) return BigInt::AsintN(thread, index, js_bigint_val); } -JSTaggedValue BuiltinsBigInt::ToLocaleString(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_int::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -96,8 +121,8 @@ JSTaggedValue BuiltinsBigInt::ToLocaleString(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); JSHandle number_format = JSHandle::Cast(obj); - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -107,7 +132,7 @@ JSTaggedValue BuiltinsBigInt::ToLocaleString(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsBigInt::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_int::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -120,7 +145,7 @@ JSTaggedValue BuiltinsBigInt::ToString(EcmaRuntimeCallInfo *argv) JSHandle this_bigint(thread, value); // 2. If radix is not present, let radixNumber be 10 double radix = base::DECIMAL; - JSHandle radix_value = GetCallArg(argv, 0); + JSHandle radix_value = builtins_common::GetCallArg(argv, 0); // 3. Else, let radixNumber be ? ToIntegerOrInfinity(radix). if (!radix_value->IsUndefined()) { JSTaggedNumber radix_number = JSTaggedValue::ToInteger(thread, radix_value); @@ -140,7 +165,7 @@ JSTaggedValue BuiltinsBigInt::ToString(EcmaRuntimeCallInfo *argv) return BigInt::ToString(thread, this_bigint, static_cast(radix)).GetTaggedValue(); } -JSTaggedValue BuiltinsBigInt::ValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_int::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -150,26 +175,4 @@ JSTaggedValue BuiltinsBigInt::ValueOf(EcmaRuntimeCallInfo *argv) return ThisBigIntValue(argv); } -JSTaggedValue BuiltinsBigInt::ThisBigIntValue(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - JSThread *thread = argv->GetThread(); - BUILTINS_API_TRACE(thread, BigInt, ThisBigIntValue); - JSHandle value = GetThis(argv); - // 1. If Type(value) is BigInt, return value. - if (value->IsBigInt()) { - return value.GetTaggedValue(); - } - // 2. If Type(value) is Object and value has a [[BigIntData]] internal slot, then - if (value->IsJSPrimitiveRef()) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(value->GetTaggedObject())->GetValue(); - // a. Assert: Type(value.[[BigIntData]]) is BigInt. - if (primitive.IsBigInt()) { - // b. Return value.[[BigIntData]]. - return primitive; - } - } - // 3. Throw a TypeError exception. - THROW_TYPE_ERROR_AND_RETURN(thread, "not BigInt type", JSTaggedValue::Exception()); -} } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_bigint.h b/runtime/builtins/builtins_bigint.h deleted file mode 100644 index c9a2f85f5b2467d069ff6d9761f5f1a5ac66ad25..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_bigint.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_BIGINT_H -#define ECMASCRIPT_BUILTINS_BUILTINS_BIGINT_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsBigInt : public ecmascript::base::BuiltinsBase { -public: - // 21.2.1.1 - static JSTaggedValue BigIntConstructor(EcmaRuntimeCallInfo *argv); - // 21.2.2.1 - static JSTaggedValue AsUintN(EcmaRuntimeCallInfo *argv); - // 21.2.2.2 - static JSTaggedValue AsIntN(EcmaRuntimeCallInfo *argv); - // 21.2.3.2 - static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); - // 21.2.3.3 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 21.2.3.4 - static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); - -private: - static JSTaggedValue ThisBigIntValue(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_BIGINT_H diff --git a/runtime/builtins/builtins_boolean.cpp b/runtime/builtins/builtins_boolean.cpp index b2bed8c1528c44808b5545e3b1605a36df258d52..1d54f4b15e05d8c294d6725c0076fc64e7c1b00b 100644 --- a/runtime/builtins/builtins_boolean.cpp +++ b/runtime/builtins/builtins_boolean.cpp @@ -13,32 +13,31 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_boolean.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_primitive_ref.h" namespace panda::ecmascript::builtins { // ecma 19.3.1.1 Boolean(value) -JSTaggedValue BuiltinsBoolean::BooleanConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue boolean::BooleanConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Boolean, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let b be ToBoolean(value). - bool bool_value = GetCallArg(argv, 0)->ToBoolean(); + bool bool_value = builtins_common::GetCallArg(argv, 0)->ToBoolean(); // 2. If NewTarget is undefined, return b. - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { - return GetTaggedBoolean(bool_value); + return builtins_common::GetTaggedBoolean(bool_value); } // 3. Let O be OrdinaryCreateFromConstructor(NewTarget, "%BooleanPrototype%", [[BooleanData]] ). // 5. Set the value of O's [[BooleanData]] internal slot to b. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle ctor = JSHandle(GetConstructor(argv)); + JSHandle ctor = JSHandle(builtins_common::GetConstructor(argv)); JSHandle result = factory->NewJSObjectByConstructor(ctor, new_target); JSTaggedValue obj_value = bool_value ? JSTaggedValue::True() : JSTaggedValue::False(); JSPrimitiveRef::Cast(*result)->SetValue(thread, obj_value); @@ -49,12 +48,13 @@ JSTaggedValue BuiltinsBoolean::BooleanConstructor(EcmaRuntimeCallInfo *argv) } // ecma 19.3.3 abstract operation thisBooleanValue(value) -JSTaggedValue BuiltinsBoolean::ThisBooleanValue(JSThread *thread, JSTaggedValue value) +static JSTaggedValue ThisBooleanValue(JSThread *thread, JSTaggedValue value) { BUILTINS_API_TRACE(thread, Boolean, ThisBooleanValue); // 1. If Type(value) is Boolean, return value if (value.IsBoolean()) { - return value == JSTaggedValue::True() ? GetTaggedBoolean(true) : GetTaggedBoolean(false); + return value == JSTaggedValue::True() ? builtins_common::GetTaggedBoolean(true) + : builtins_common::GetTaggedBoolean(false); } // 2. If Type(value) is Object and value has a [[BooleanData]] internal slot, then if (value.IsJSPrimitiveRef()) { @@ -62,7 +62,8 @@ JSTaggedValue BuiltinsBoolean::ThisBooleanValue(JSThread *thread, JSTaggedValue // a. Assert: value's [[BooleanData]] internal slot is a Boolean value. if (primitive.IsBoolean()) { // b. Return the value of value's [[BooleanData]] internal slot. - return primitive == JSTaggedValue::True() ? GetTaggedBoolean(true) : GetTaggedBoolean(false); + return primitive == JSTaggedValue::True() ? builtins_common::GetTaggedBoolean(true) + : builtins_common::GetTaggedBoolean(false); } } [[maybe_unused]] EcmaHandleScope handle_scope(thread); @@ -71,25 +72,26 @@ JSTaggedValue BuiltinsBoolean::ThisBooleanValue(JSThread *thread, JSTaggedValue } // ecma 19.3.3.2 Boolean.prototype.toString () -JSTaggedValue BuiltinsBoolean::BooleanPrototypeToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue boolean::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let b be thisBooleanValue(this value). - JSTaggedValue this_value_to_boolean = BuiltinsBoolean::ThisBooleanValue(thread, GetThis(argv).GetTaggedValue()); + JSTaggedValue this_value_to_boolean = ThisBooleanValue(thread, builtins_common::GetThis(argv).GetTaggedValue()); // 2. ReturnIfAbrupt(b) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If b is true, return "true"; else return "false". - return this_value_to_boolean.IsTrue() ? GetTaggedString(thread, "true") : GetTaggedString(thread, "false"); + return this_value_to_boolean.IsTrue() ? builtins_common::GetTaggedString(thread, "true") + : builtins_common::GetTaggedString(thread, "false"); } // ecma 19.3.3.3 Boolean.prototype.valueOf () -JSTaggedValue BuiltinsBoolean::BooleanPrototypeValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue boolean::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); // 1. Return thisBooleanValue(this value). - return BuiltinsBoolean::ThisBooleanValue(argv->GetThread(), GetThis(argv).GetTaggedValue()); + return ThisBooleanValue(argv->GetThread(), builtins_common::GetThis(argv).GetTaggedValue()); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_collator.cpp b/runtime/builtins/builtins_collator.cpp index 0a5f664b3976c6348d131ae3966e142ad6178d91..decd7dbdce408c21db0c67e8a3ae42e6277b216d 100644 --- a/runtime/builtins/builtins_collator.cpp +++ b/runtime/builtins/builtins_collator.cpp @@ -13,8 +13,7 @@ * limitations under the License. */ -#include "builtins_collator.h" - +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_collator.h" @@ -24,7 +23,7 @@ namespace panda::ecmascript::builtins { constexpr uint32_t FUNCTION_LENGTH_TWO = 2; // 11.1.2 Intl.Collator ( [ locales [ , options ] ] ) -JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue collator::CollatorConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -32,8 +31,8 @@ JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. - JSHandle constructor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { new_target = constructor; } @@ -50,15 +49,15 @@ JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Return ? InitializeCollator(collator, locales, options). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle 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) +JSTaggedValue collator::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -66,54 +65,26 @@ JSTaggedValue BuiltinsCollator::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSHandle available_locales = JSCollator::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). - JSHandle options = GetCallArg(argv, 1); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, 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(); - [[maybe_unused]] EcmaHandleScope scope(thread); - // 1. Let collator be this value. - JSHandle this_value = GetThis(argv); - - // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). - if (!this_value->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 collator = JSHandle::Cast(this_value); - JSHandle bound_compare(thread, collator->GetBoundCompare()); - if (bound_compare->IsUndefined()) { - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intl_bound_func = factory->NewJSIntlBoundFunction( - reinterpret_cast(BuiltinsCollator::AnonymousCollator), FUNCTION_LENGTH_TWO); - intl_bound_func->SetCollator(thread, collator); - collator->SetBoundCompare(thread, intl_bound_func); - } - return collator->GetBoundCompare(); -} - // 11.3.3.1 Collator Compare Functions -JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) +static JSTaggedValue 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(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle intl_bound_func = JSHandle::Cast(GetConstructor(argv)); + JSHandle intl_bound_func = + JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let collator be F.[[Collator]]. JSHandle collator(thread, intl_bound_func->GetCollator()); @@ -122,10 +93,10 @@ JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) ASSERT_PRINT(collator->IsJSObject() && collator->IsJSCollator(), "collator is not object or JSCollator"); // 3. If x is not provided, let x be undefined. - JSHandle x = GetCallArg(argv, 0); + JSHandle x = builtins_common::GetCallArg(argv, 0); // 4. If y is not provided, let y be undefined. - JSHandle y = GetCallArg(argv, 1); + JSHandle y = builtins_common::GetCallArg(argv, 1); // 5. Let X be ? ToString(x). JSHandle x_value = JSTaggedValue::ToString(thread, x); @@ -138,12 +109,41 @@ JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) return JSCollator::CompareStrings(icu_collator, x_value, y_value); } +// 11.3.3 get Intl.Collator.prototype.compare +JSTaggedValue collator::proto::GetCompare(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + [[maybe_unused]] EcmaHandleScope scope(thread); + // 1. Let collator be this value. + JSHandle this_value = builtins_common::GetThis(argv); + + // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). + if (!this_value->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 collator = JSHandle::Cast(this_value); + JSHandle bound_compare(thread, collator->GetBoundCompare()); + if (bound_compare->IsUndefined()) { + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle intl_bound_func = + factory->NewJSIntlBoundFunction(reinterpret_cast(AnonymousCollator), FUNCTION_LENGTH_TWO); + intl_bound_func->SetCollator(thread, collator); + collator->SetBoundCompare(thread, intl_bound_func); + } + return collator->GetBoundCompare(); +} + // 11.3.4 Intl.Collator.prototype.resolvedOptions () -JSTaggedValue BuiltinsCollator::ResolvedOptions(EcmaRuntimeCallInfo *argv) +JSTaggedValue collator::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); if (!this_value->IsJSCollator()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Collator object", JSTaggedValue::Exception()); } diff --git a/runtime/builtins/builtins_collator.h b/runtime/builtins/builtins_collator.h deleted file mode 100644 index 562b9e3b29cebfa6e3a9ce5cef44c116c966cd8e..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_collator.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_COLLATOR_H -#define ECMASCRIPT_BUILTINS_BUILTINS_COLLATOR_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsCollator : public base::BuiltinsBase { -public: - // 11.1.2 Intl.Collator ( [ locales [ , options ] ] ) - static JSTaggedValue CollatorConstructor(EcmaRuntimeCallInfo *argv); - - // 11.2.2 Intl.Collator.supportedLocalesOf ( locales [ , options ] ) - static JSTaggedValue SupportedLocalesOf(EcmaRuntimeCallInfo *argv); - - // 11.3.3 get Intl.Collator.prototype.compare - static JSTaggedValue Compare(EcmaRuntimeCallInfo *argv); - - // 11.3.4 Intl.Collator.prototype.resolvedOptions () - static JSTaggedValue ResolvedOptions(EcmaRuntimeCallInfo *argv); - -private: - static JSTaggedValue AnonymousCollator(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_COLLATOR_H diff --git a/runtime/builtins/builtins_dataview.cpp b/runtime/builtins/builtins_dataview.cpp index 8a4ce758f6af6213e60889f6715eac44a7125b01..879fd4855ff25930b37888c0b853d8b0e9254c51 100644 --- a/runtime/builtins/builtins_dataview.cpp +++ b/runtime/builtins/builtins_dataview.cpp @@ -13,9 +13,8 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_dataview.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/number_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_arraybuffer.h" @@ -25,19 +24,19 @@ namespace panda::ecmascript::builtins { // 24.2.2.1 -JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue data_view::DataViewConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle ctor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle ctor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); // 1. If NewTarget is undefined, throw a TypeError exception. if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "newtarget is undefined", JSTaggedValue::Exception()); } - JSHandle buffer_handle = GetCallArg(argv, 0); + JSHandle buffer_handle = builtins_common::GetCallArg(argv, 0); // 2. If Type(buffer) is not Object, throw a TypeError exception. if (!buffer_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not Object", JSTaggedValue::Exception()); @@ -46,7 +45,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) if (!buffer_handle->IsArrayBuffer()) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not ArrayBuffer", JSTaggedValue::Exception()); } - JSHandle offset_handle = GetCallArg(argv, 1); + JSHandle offset_handle = builtins_common::GetCallArg(argv, 1); // 4. Let numberOffset be ToNumber(byteOffset). JSTaggedNumber offset_number = JSTaggedValue::ToNumber(thread, offset_handle); // 6. ReturnIfAbrupt(offset). @@ -57,7 +56,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) THROW_RANGE_ERROR_AND_RETURN(thread, "Offset out of range", JSTaggedValue::Exception()); } // 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer_handle.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(buffer_handle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception()); } // 9. Let bufferByteLength be the value of buffer’s [[ArrayBufferByteLength]] internal slot. @@ -69,7 +68,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) THROW_RANGE_ERROR_AND_RETURN(thread, "offset > bufferByteLength", JSTaggedValue::Exception()); } int32_t view_byte_len; - JSHandle byte_len_handle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle byte_len_handle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); // 11. If byteLength is undefined, then Let viewByteLength be bufferByteLength – offset. if (byte_len_handle->IsUndefined()) { view_byte_len = buf_byte_len - offset; @@ -104,14 +103,14 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) } // 24.2.4.1 -JSTaggedValue BuiltinsDataView::GetBuffer(EcmaRuntimeCallInfo *argv) +JSTaggedValue data_view::proto::GetBuffer(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, GetBuffer); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. f Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception()); @@ -128,14 +127,14 @@ JSTaggedValue BuiltinsDataView::GetBuffer(EcmaRuntimeCallInfo *argv) } // 24.2.4.2 -JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv) +JSTaggedValue data_view::proto::GetByteLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, GetByteLength); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception()); @@ -148,7 +147,7 @@ JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv) // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. @@ -158,14 +157,14 @@ JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv) } // 24.2.4.3 -JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv) +JSTaggedValue data_view::proto::GetByteOffset(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, GetOffset); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception()); @@ -178,7 +177,7 @@ JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv) // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. @@ -187,150 +186,10 @@ JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv) return JSTaggedValue(offset); } -// 24.2.4.5 -JSTaggedValue BuiltinsDataView::GetFloat32(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::FLOAT32); -} - -// 24.2.4.6 -JSTaggedValue BuiltinsDataView::GetFloat64(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::FLOAT64); -} - -// 24.2.4.7 -JSTaggedValue BuiltinsDataView::GetInt8(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::INT8); -} - -// 24.2.4.8 -JSTaggedValue BuiltinsDataView::GetInt16(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::INT16); -} - -// 24.2.4.9 -JSTaggedValue BuiltinsDataView::GetInt32(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::INT32); -} - -// 24.2.4.10 -JSTaggedValue BuiltinsDataView::GetUint8(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::UINT8); -} - -// 24.2.4.11 -JSTaggedValue BuiltinsDataView::GetUint16(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::UINT16); -} - -// 24.2.4.12 -JSTaggedValue BuiltinsDataView::GetUint32(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::UINT32); -} - -// 25.3.4.5 -JSTaggedValue BuiltinsDataView::GetBigInt64(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::BIGINT64); -} - -// 25.3.4.6 -JSTaggedValue BuiltinsDataView::GetBigUint64(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return GetTypedValue(argv, DataViewType::BIGUINT64); -} - -// 24.2.4.13 -JSTaggedValue BuiltinsDataView::SetFloat32(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::FLOAT32); -} - -// 24.2.4.14 -JSTaggedValue BuiltinsDataView::SetFloat64(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::FLOAT64); -} - -// 24.2.4.15 -JSTaggedValue BuiltinsDataView::SetInt8(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::INT8); -} - -// 24.2.4.16 -JSTaggedValue BuiltinsDataView::SetInt16(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::INT16); -} - -// 24.2.4.17 -JSTaggedValue BuiltinsDataView::SetInt32(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::INT32); -} - -// 24.2.4.18 -JSTaggedValue BuiltinsDataView::SetUint8(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::UINT8); -} - -// 24.2.4.19 -JSTaggedValue BuiltinsDataView::SetUint16(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::UINT16); -} - -// 25.3.4.15 -JSTaggedValue BuiltinsDataView::SetBigInt64(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::BIGINT64); -} - -// 25.3.4.16 -JSTaggedValue BuiltinsDataView::SetBigUint64(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::BIGUINT64); -} - -// 24.2.4.20 -JSTaggedValue BuiltinsDataView::SetUint32(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - return SetTypedValue(argv, DataViewType::UINT32); -} - // 24.2.1.1 -JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &request_index, JSTaggedValue little_endian, - DataViewType type) +static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle &view, + const JSHandle &request_index, JSTaggedValue little_endian, + DataViewType type) { BUILTINS_API_TRACE(thread, DataView, GetViewValue); // 1. If Type(view) is not Object, throw a TypeError exception. @@ -364,7 +223,7 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandleGetViewedArrayBuffer(); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } } @@ -387,14 +246,14 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle buffer(thread, data_view->GetViewedArrayBuffer()); - return BuiltinsArrayBuffer::GetValueFromBuffer(thread, buffer, buffer_index, type, is_little_endian); + return builtins::array_buffer::GetValueFromBuffer(thread, buffer, buffer_index, type, is_little_endian); } } // 24.2.1.2 -JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &request_index, JSTaggedValue little_endian, - DataViewType type, const JSHandle &value) +JSTaggedValue SetViewValue(JSThread *thread, const JSHandle &view, + const JSHandle &request_index, JSTaggedValue little_endian, DataViewType type, + const JSHandle &value) { // 1. If Type(view) is not Object, throw a TypeError exception. BUILTINS_API_TRACE(thread, DataView, SetViewValue); @@ -430,7 +289,7 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandleGetViewedArrayBuffer(); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } } @@ -453,34 +312,176 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle buffer(thread, data_view->GetViewedArrayBuffer()); // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian). - return BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, buffer_index, type, num_val, is_little_endian); + return builtins::array_buffer::SetValueInBuffer(thread, buffer, buffer_index, type, num_val, is_little_endian); } } -JSTaggedValue BuiltinsDataView::GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) +JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = GetThis(argv); - JSHandle offset_handle = GetCallArg(argv, 0); + JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle offset_handle = builtins_common::GetCallArg(argv, 0); if (type == DataViewType::UINT8 || type == DataViewType::INT8) { return GetViewValue(thread, this_handle, offset_handle, JSTaggedValue::True(), type); } - JSHandle little_endian_handle = GetCallArg(argv, 1); + JSHandle little_endian_handle = builtins_common::GetCallArg(argv, 1); return GetViewValue(thread, this_handle, offset_handle, little_endian_handle.GetTaggedValue(), type); } -JSTaggedValue BuiltinsDataView::SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) +JSTaggedValue SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = GetThis(argv); - JSHandle offset_handle = GetCallArg(argv, 0); - JSHandle value = GetCallArg(argv, 1); + JSHandle this_handle = builtins_common::GetThis(argv); + JSHandle offset_handle = builtins_common::GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 1); if (type == DataViewType::UINT8 || type == DataViewType::INT8) { return SetViewValue(thread, this_handle, offset_handle, JSTaggedValue::True(), type, value); } - JSHandle little_endian_handle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle little_endian_handle = + builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); return SetViewValue(thread, this_handle, offset_handle, little_endian_handle.GetTaggedValue(), type, value); } + +// 24.2.4.5 +JSTaggedValue data_view::proto::GetFloat32(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::FLOAT32); +} + +// 24.2.4.6 +JSTaggedValue data_view::proto::GetFloat64(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::FLOAT64); +} + +// 24.2.4.7 +JSTaggedValue data_view::proto::GetInt8(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::INT8); +} + +// 24.2.4.8 +JSTaggedValue data_view::proto::GetInt16(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::INT16); +} + +// 24.2.4.9 +JSTaggedValue data_view::proto::GetInt32(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::INT32); +} + +// 24.2.4.10 +JSTaggedValue data_view::proto::GetUint8(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::UINT8); +} + +// 24.2.4.11 +JSTaggedValue data_view::proto::GetUint16(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::UINT16); +} + +// 24.2.4.12 +JSTaggedValue data_view::proto::GetUint32(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::UINT32); +} + +// 25.3.4.5 +JSTaggedValue data_view::proto::GetBigInt64(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::BIGINT64); +} + +// 25.3.4.6 +JSTaggedValue data_view::proto::GetBigUint64(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return GetTypedValue(argv, DataViewType::BIGUINT64); +} + +// 24.2.4.13 +JSTaggedValue data_view::proto::SetFloat32(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::FLOAT32); +} + +// 24.2.4.14 +JSTaggedValue data_view::proto::SetFloat64(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::FLOAT64); +} + +// 24.2.4.15 +JSTaggedValue data_view::proto::SetInt8(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::INT8); +} + +// 24.2.4.16 +JSTaggedValue data_view::proto::SetInt16(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::INT16); +} + +// 24.2.4.17 +JSTaggedValue data_view::proto::SetInt32(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::INT32); +} + +// 24.2.4.18 +JSTaggedValue data_view::proto::SetUint8(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::UINT8); +} + +// 24.2.4.19 +JSTaggedValue data_view::proto::SetUint16(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::UINT16); +} + +// 25.3.4.15 +JSTaggedValue data_view::proto::SetBigInt64(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::BIGINT64); +} + +// 25.3.4.16 +JSTaggedValue data_view::proto::SetBigUint64(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::BIGUINT64); +} + +// 24.2.4.20 +JSTaggedValue data_view::proto::SetUint32(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + return SetTypedValue(argv, DataViewType::UINT32); +} + } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_dataview.h b/runtime/builtins/builtins_dataview.h deleted file mode 100644 index 2bb89507ce03da4ce35158fe7f0d5157d981253e..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_dataview.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H -#define ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_dataview.h" - -namespace panda::ecmascript::builtins { -using DataViewType = ecmascript::DataViewType; -class BuiltinsDataView : public ecmascript::base::BuiltinsBase { -public: - // 24.2.2.1 DataView (buffer [ , byteOffset [ , byteLength ] ] ) - static JSTaggedValue DataViewConstructor(EcmaRuntimeCallInfo *argv); - // 24.2.4.1 get DataView.prototype.buffer - static JSTaggedValue GetBuffer(EcmaRuntimeCallInfo *argv); - // 24.2.4.2 get DataView.prototype.byteLength - static JSTaggedValue GetByteLength(EcmaRuntimeCallInfo *argv); - // 24.2.4.3 get DataView.prototype.byteOffset - static JSTaggedValue GetOffset(EcmaRuntimeCallInfo *argv); - // 24.2.4.5 DataView.prototype.getFloat32 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetFloat32(EcmaRuntimeCallInfo *argv); - // 24.2.4.6 DataView.prototype.getFloat64 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetFloat64(EcmaRuntimeCallInfo *argv); - // 24.2.4.7 DataView.prototype.getInt8 ( byteOffset ) - static JSTaggedValue GetInt8(EcmaRuntimeCallInfo *argv); - // 24.2.4.8 DataView.prototype.getInt16 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetInt16(EcmaRuntimeCallInfo *argv); - // 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetInt32(EcmaRuntimeCallInfo *argv); - // 24.2.4.10 DataView.prototype.getUint8 ( byteOffset ) - static JSTaggedValue GetUint8(EcmaRuntimeCallInfo *argv); - // 24.2.4.11 DataView.prototype.getUint16 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetUint16(EcmaRuntimeCallInfo *argv); - // 24.2.4.12 DataView.prototype.getUint32 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetUint32(EcmaRuntimeCallInfo *argv); - // 25.3.4.5 DataView.prototype.getBigInt64 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetBigInt64(EcmaRuntimeCallInfo *argv); - // 25.3.4.6 DataView.prototype.getBigUint64 ( byteOffset [ , littleEndian ] ) - static JSTaggedValue GetBigUint64(EcmaRuntimeCallInfo *argv); - // 24.2.4.13 DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetFloat32(EcmaRuntimeCallInfo *argv); - // 24.2.4.14 DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetFloat64(EcmaRuntimeCallInfo *argv); - // 24.2.4.15 DataView.prototype.setInt8 ( byteOffset, value ) - static JSTaggedValue SetInt8(EcmaRuntimeCallInfo *argv); - // 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetInt16(EcmaRuntimeCallInfo *argv); - // 24.2.4.17 DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetInt32(EcmaRuntimeCallInfo *argv); - // 24.2.4.18 DataView.prototype.setUint8 ( byteOffset, value ) - static JSTaggedValue SetUint8(EcmaRuntimeCallInfo *argv); - // 24.2.4.19 DataView.prototype.setUint16( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetUint16(EcmaRuntimeCallInfo *argv); - // 24.2.4.20 DataView.prototype.setUint32 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetUint32(EcmaRuntimeCallInfo *argv); - // 25.3.4.15 DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetBigInt64(EcmaRuntimeCallInfo *argv); - // 25.3.4.16 DataView.prototype.setBigUint64 ( byteOffset, value [ , littleEndian ] ) - static JSTaggedValue SetBigUint64(EcmaRuntimeCallInfo *argv); - -private: - // 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) - static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &request_index, JSTaggedValue little_endian, - DataViewType type); - static JSTaggedValue SetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &request_index, JSTaggedValue little_endian, - DataViewType type, const JSHandle &value); - - static JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type); - static JSTaggedValue SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_DATAVIEW_H diff --git a/runtime/builtins/builtins_date.cpp b/runtime/builtins/builtins_date.cpp index 5d0c2064735f686ca09c87ddc18eaa4c3b7a0f8c..86ea474be01bc58e0e61b1b353a83facbfcbaf2d 100644 --- a/runtime/builtins/builtins_date.cpp +++ b/runtime/builtins/builtins_date.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_date.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -26,17 +26,27 @@ #include "plugins/ecmascript/runtime/tagged_array.h" namespace panda::ecmascript::builtins { + +// definition for set data code. +static constexpr uint32_t CODE_SET_DATE = 0x32; +static constexpr uint32_t CODE_SET_MILLISECONDS = 0x76; +static constexpr uint32_t CODE_SET_SECONDS = 0x75; +static constexpr uint32_t CODE_SET_MINUTES = 0x74; +static constexpr uint32_t CODE_SET_HOURS = 0x73; +static constexpr uint32_t CODE_SET_MONTH = 0x31; +static constexpr uint32_t CODE_SET_FULL_YEAR = 0x30; +static constexpr uint8_t CONSTRUCTOR_MAX_LENGTH = 7; // constructor -JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::DateConstructor(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { double now = JSDate::Now().GetDouble(); PandaString str = JSDate::ToDateString(now); - return GetTaggedString(thread, str.c_str()); + return builtins_common::GetTaggedString(thread, str.c_str()); } JSTaggedValue time_value(0.0); @@ -44,7 +54,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) if (length == 0) { // no value time_value = JSDate::Now(); } else if (length == 1) { // one value - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); if (value->IsDate()) { // The value is a date object. JSHandle js_date(thread, JSDate::Cast(value->GetTaggedObject())); time_value = js_date->GetTimeValue(); @@ -69,7 +79,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) } uint32_t i = 0; for (; i < length; ++i) { - JSHandle value = GetCallArg(argv, i); + JSHandle value = builtins_common::GetCallArg(argv, i); JSTaggedNumber res = JSTaggedValue::ToNumber(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double temp = res.GetNumber(); @@ -85,7 +95,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle date_object = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -94,14 +104,14 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) } // 20.4.3.1 -JSTaggedValue BuiltinsDate::Now([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue date::Now([[maybe_unused]] EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, Now); return JSDate::Now(); } // 20.4.3.2 -JSTaggedValue BuiltinsDate::Parse(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::Parse(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, Parse); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); @@ -109,7 +119,7 @@ JSTaggedValue BuiltinsDate::Parse(EcmaRuntimeCallInfo *argv) } // 20.4.3.4 -JSTaggedValue BuiltinsDate::UTC(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::UTC(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, UTC); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); @@ -117,47 +127,47 @@ JSTaggedValue BuiltinsDate::UTC(EcmaRuntimeCallInfo *argv) } // B.2.3.1 -JSTaggedValue BuiltinsDate::GetYear(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::GetYear(EcmaRuntimeCallInfo *argv) { double result = GetFullYear(argv).GetNumber() - panda::ecmascript::JSDate::NINETEEN_HUNDRED_YEAR; - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.4.4.10 -JSTaggedValue BuiltinsDate::GetTime(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::GetTime(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, GetTime); JSThread *thread = argv->GetThread(); - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } return JSDate::Cast(msg->GetTaggedObject())->GetTime(); } -JSTaggedValue BuiltinsDate::SetTime(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::SetTime(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, SetTime); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } JSHandle js_data(thread, JSDate::Cast(msg->GetTaggedObject())); - JSTaggedNumber res = JSTaggedValue::ToNumber(thread, GetCallArg(argv, 0)); + JSTaggedNumber res = JSTaggedValue::ToNumber(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); double number = res.GetNumber(); double value = JSDate::TimeClip(number); js_data->SetTimeValue(thread, JSTaggedValue(value)); - return GetTaggedDouble(value); + return builtins_common::GetTaggedDouble(value); } // 20.4.4.37 -JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::ToJSON(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, ToJSON); @@ -165,7 +175,7 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); JSHandle object = JSTaggedValue::ToObject(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -186,12 +196,12 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) } // 20.4.4.44 -JSTaggedValue BuiltinsDate::ValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, ValueOf); JSThread *thread = argv->GetThread(); - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { [[maybe_unused]] EcmaHandleScope handle_scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); @@ -200,7 +210,7 @@ JSTaggedValue BuiltinsDate::ValueOf(EcmaRuntimeCallInfo *argv) } // 20.4.4.45 -JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::ToPrimitive(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, ToPrimitive); @@ -208,11 +218,11 @@ JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle object = GetThis(argv); + JSHandle object = builtins_common::GetThis(argv); if (!object->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a JSObject", JSTaggedValue::Exception()); } - JSHandle hint = GetCallArg(argv, 0); + JSHandle hint = builtins_common::GetCallArg(argv, 0); PreferredPrimitiveType try_first = PREFER_STRING; if (hint->IsString()) { JSHandle number_str_handle = factory->NewFromCanBeCompressString("number"); @@ -235,7 +245,7 @@ JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv) } // ecma 402 16.4.1 Date.prototype.toLocaleString ( [ locales [ , options ] ] ) -JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -245,7 +255,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let x be ? thisTimeValue(this value). - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } @@ -259,8 +269,8 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) } // Let options be ? ToDateTimeOptions(options, "any", "all"). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle date_time_options = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::ANY, DefaultsOption::ALL); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -278,7 +288,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) } // ecma 402 16.4.1 Date.prototype.toLocaleString ( [ locales [ , options ] ] ) -JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::ToLocaleDateString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -288,7 +298,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let x be ? thisTimeValue(this value). - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } @@ -302,8 +312,8 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) } // Let options be ? ToDateTimeOptions(options, "any", "all"). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle date_time_options = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::DATE, DefaultsOption::DATE); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -321,7 +331,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) } // ecma 402 16.4.1 Date.prototype.toLocaleString ( [ locales [ , options ] ] ) -JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) +JSTaggedValue date::proto::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -331,7 +341,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let x be ? thisTimeValue(this value). - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsDate()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } @@ -345,8 +355,8 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) } // Let options be ? ToDateTimeOptions(options, "any", "all"). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle date_time_options = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::TIME, DefaultsOption::TIME); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -362,4 +372,179 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) JSHandle result = JSDateTimeFormat::FormatDateTime(thread, dtf, x); return result.GetTaggedValue(); } + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define GET_DATE_VALUE(name, code, isLocal) \ + JSTaggedValue date::proto::name(EcmaRuntimeCallInfo *argv) \ + { \ + ASSERT(argv); \ + JSThread *thread = argv->GetThread(); \ + JSHandle msg = builtins_common::GetThis(argv); \ + if (!msg->IsDate()) { \ + THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ + } \ + JSHandle jsDate = JSHandle(msg); \ + double result = jsDate->GetDateValue(jsDate->GetTimeValue().GetDouble(), code, isLocal); \ + return builtins_common::GetTaggedDouble(result); \ + } + +// 20.4.4.2 Date.prototype.getDate ( ) +GET_DATE_VALUE(GetDate, DAYS, true) + +// 20.4.4.3 Date.prototype.getDay ( ) +GET_DATE_VALUE(GetDay, WEEKDAY, true) + +// 20.4.4.4 Date.prototype.getFullYear ( ) +GET_DATE_VALUE(GetFullYear, YEAR, true) + +// 20.4.4.5 Date.prototype.getHours ( ) +GET_DATE_VALUE(GetHours, HOUR, true) + +// 20.4.4.6 Date.prototype.getMilliseconds ( ) +GET_DATE_VALUE(GetMilliseconds, MS, true) + +// 20.4.4.7 Date.prototype.getMinutes ( ) +GET_DATE_VALUE(GetMinutes, MIN, true) + +// 20.4.4.8 Date.prototype.getMonth ( ) +GET_DATE_VALUE(GetMonth, MONTH, true) + +// 20.4.4.9 Date.prototype.getSeconds ( ) +GET_DATE_VALUE(GetSeconds, SEC, true) + +// 20.4.4.11 Date.prototype.getTimezoneOffset ( ) +GET_DATE_VALUE(GetTimezoneOffset, TIMEZONE, true) + +// 20.4.4.12 Date.prototype.getUTCDate ( ) +GET_DATE_VALUE(GetUTCDate, DAYS, false) + +// 20.4.4.13 Date.prototype.getUTCDay ( ) +GET_DATE_VALUE(GetUTCDay, WEEKDAY, false) + +// 20.4.4.14 Date.prototype.getUTCFullYear ( ) +GET_DATE_VALUE(GetUTCFullYear, YEAR, false) + +// 20.4.4.15 Date.prototype.getUTCHours ( ) +GET_DATE_VALUE(GetUTCHours, HOUR, false) + +// 20.4.4.16 Date.prototype.getUTCMilliseconds ( ) +GET_DATE_VALUE(GetUTCMilliseconds, MS, false) + +// 20.4.4.17 Date.prototype.getUTCMinutes ( ) +GET_DATE_VALUE(GetUTCMinutes, MIN, false) + +// 20.4.4.18 Date.prototype.getUTCMonth ( ) +GET_DATE_VALUE(GetUTCMonth, MONTH, false) + +// 20.4.4.19 Date.prototype.getUTCSeconds ( ) +GET_DATE_VALUE(GetUTCSeconds, SEC, false) +#undef GET_DATE_VALUE + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define SET_DATE_VALUE(name, code, isLocal) \ + JSTaggedValue date::proto::name(EcmaRuntimeCallInfo *argv) \ + { \ + ASSERT(argv); \ + JSThread *thread = argv->GetThread(); \ + JSHandle msg = builtins_common::GetThis(argv); \ + if (!msg->IsDate()) { \ + THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ + } \ + JSHandle jsDate = JSHandle(msg); \ + JSTaggedValue result = jsDate->SetDateValue(argv, code, isLocal); \ + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); \ + jsDate->SetTimeValue(thread, result); \ + return result; \ + } + +// 20.3.4.20 Date.prototype.setDate ( date ) +SET_DATE_VALUE(SetDate, CODE_SET_DATE, true) + +// 20.3.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ) +SET_DATE_VALUE(SetFullYear, CODE_SET_FULL_YEAR, true) + +// 20.3.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ) +SET_DATE_VALUE(SetHours, CODE_SET_HOURS, true) + +// 20.3.4.23 Date.prototype.setMilliseconds ( ms ) +SET_DATE_VALUE(SetMilliseconds, CODE_SET_MILLISECONDS, true) + +// 20.3.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ) +SET_DATE_VALUE(SetMinutes, CODE_SET_MINUTES, true) + +// 20.3.4.25 Date.prototype.setMonth ( month [ , date ] ) +SET_DATE_VALUE(SetMonth, CODE_SET_MONTH, true) + +// 20.3.4.26 Date.prototype.setSeconds ( sec [ , ms ] ) +SET_DATE_VALUE(SetSeconds, CODE_SET_SECONDS, true) + +// 20.3.4.28 Date.prototype.setUTCDate ( date ) +SET_DATE_VALUE(SetUTCDate, CODE_SET_DATE, false) + +// 20.3.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] ) +SET_DATE_VALUE(SetUTCFullYear, CODE_SET_FULL_YEAR, false) + +// 20.3.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] ) +SET_DATE_VALUE(SetUTCHours, CODE_SET_HOURS, false) + +// 20.3.4.31 Date.prototype.setUTCMilliseconds ( ms ) +SET_DATE_VALUE(SetUTCMilliseconds, CODE_SET_MILLISECONDS, false) + +// 20.3.4.32 Date.prototype.setUTCMinutes ( min [ , sec [, ms ] ] ) +SET_DATE_VALUE(SetUTCMinutes, CODE_SET_MINUTES, false) + +// 20.3.4.33 Date.prototype.setUTCMonth ( month [ , date ] ) +SET_DATE_VALUE(SetUTCMonth, CODE_SET_MONTH, false) + +// 20.3.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] ) +SET_DATE_VALUE(SetUTCSeconds, CODE_SET_SECONDS, false) + +#undef SET_DATE_VALUE + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DATE_STRING(name) \ + JSTaggedValue date::proto::name(EcmaRuntimeCallInfo *argv) \ + { \ + ASSERT(argv); \ + JSThread *thread = argv->GetThread(); \ + [[maybe_unused]] EcmaHandleScope handle_scope(thread); \ + JSHandle msg = builtins_common::GetThis(argv); \ + if (!msg->IsDate()) { \ + THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ + } \ + if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ + return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Invalid Date").GetTaggedValue(); \ + } \ + return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ + } +// 20.4.4.35 Date.prototype.toDateString ( ) +DATE_STRING(ToDateString) + +// 20.4.4.41 Date.prototype.toString ( ) +DATE_STRING(ToString) + +// 20.4.4.42 Date.prototype.toTimeString ( ) +DATE_STRING(ToTimeString) + +// 20.4.4.43 Date.prototype.toUTCString ( ) +DATE_STRING(ToUTCString) + +#undef DATE_STRING + +// 20.4.4.36 Date.prototype.toISOString ( ) +JSTaggedValue date::proto::ToISOString(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + JSThread *thread = argv->GetThread(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle msg = builtins_common::GetThis(argv); + if (!msg->IsDate()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); + } + if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { + THROW_RANGE_ERROR_AND_RETURN(thread, "range error", JSTaggedValue::Exception()); + } + return JSDate::Cast(msg->GetTaggedObject())->ToISOString(thread); +} + } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_date.h b/runtime/builtins/builtins_date.h deleted file mode 100644 index 484c68e5494bb47a4c3317bb264255e7e6b3220d..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_date.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_DATE_H -#define ECMASCRIPT_BUILTINS_BUILTINS_DATE_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_date.h" - -namespace panda::ecmascript::builtins { -class BuiltinsDate : public ecmascript::base::BuiltinsBase { -public: - // 20.4.2 The Date Constructor - static JSTaggedValue DateConstructor(EcmaRuntimeCallInfo *argv); - - // 20.4.3.1 Date.now ( ) - static JSTaggedValue Now(EcmaRuntimeCallInfo *argv); - - // 20.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] ) - static JSTaggedValue UTC(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue Parse(EcmaRuntimeCallInfo *argv); - - // 20.4.4.2 Date.prototype.getDate ( ) - GET_DATE_VALUE(GetDate, DAYS, true); - - // 20.4.4.3 Date.prototype.getDay ( ) - GET_DATE_VALUE(GetDay, WEEKDAY, true); - - // 20.4.4.4 Date.prototype.getFullYear ( ) - GET_DATE_VALUE(GetFullYear, YEAR, true); - - // B.2.3.1 Date.prototype.getYear ( ) - static JSTaggedValue GetYear(EcmaRuntimeCallInfo *argv); - - // 20.4.4.5 Date.prototype.getHours ( ) - GET_DATE_VALUE(GetHours, HOUR, true); - - // 20.4.4.6 Date.prototype.getMilliseconds ( ) - GET_DATE_VALUE(GetMilliseconds, MS, true); - - // 20.4.4.7 Date.prototype.getMinutes ( ) - GET_DATE_VALUE(GetMinutes, MIN, true); - - // 20.4.4.8 Date.prototype.getMonth ( ) - GET_DATE_VALUE(GetMonth, MONTH, true); - - // 20.4.4.9 Date.prototype.getSeconds ( ) - GET_DATE_VALUE(GetSeconds, SEC, true); - - // 20.4.4.10 Date.prototype.getTime ( ) - static JSTaggedValue GetTime(EcmaRuntimeCallInfo *argv); - - // 20.4.4.11 Date.prototype.getTimezoneOffset ( ) - GET_DATE_VALUE(GetTimezoneOffset, TIMEZONE, true); - - // 20.4.4.12 Date.prototype.getUTCDate ( ) - GET_DATE_VALUE(GetUTCDate, DAYS, false); - - // 20.4.4.13 Date.prototype.getUTCDay ( ) - GET_DATE_VALUE(GetUTCDay, WEEKDAY, false); - - // 20.4.4.14 Date.prototype.getUTCFullYear ( ) - GET_DATE_VALUE(GetUTCFullYear, YEAR, false); - - // 20.4.4.15 Date.prototype.getUTCHours ( ) - GET_DATE_VALUE(GetUTCHours, HOUR, false); - - // 20.4.4.16 Date.prototype.getUTCMilliseconds ( ) - GET_DATE_VALUE(GetUTCMilliseconds, MS, false); - - // 20.4.4.17 Date.prototype.getUTCMinutes ( ) - GET_DATE_VALUE(GetUTCMinutes, MIN, false); - - // 20.4.4.18 Date.prototype.getUTCMonth ( ) - GET_DATE_VALUE(GetUTCMonth, MONTH, false); - - // 20.4.4.19 Date.prototype.getUTCSeconds ( ) - GET_DATE_VALUE(GetUTCSeconds, SEC, false); - - // 20.3.4.20 Date.prototype.setDate ( date ) - SET_DATE_VALUE(SetDate, CODE_SET_DATE, true); - - // 20.3.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] ) - SET_DATE_VALUE(SetFullYear, CODE_SET_FULL_YEAR, true); - - // 20.3.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] ) - SET_DATE_VALUE(SetHours, CODE_SET_HOURS, true); - - // 20.3.4.23 Date.prototype.setMilliseconds ( ms ) - SET_DATE_VALUE(SetMilliseconds, CODE_SET_MILLISECONDS, true); - - // 20.3.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] ) - SET_DATE_VALUE(SetMinutes, CODE_SET_MINUTES, true); - - // 20.3.4.25 Date.prototype.setMonth ( month [ , date ] ) - SET_DATE_VALUE(SetMonth, CODE_SET_MONTH, true); - - // 20.3.4.26 Date.prototype.setSeconds ( sec [ , ms ] ) - SET_DATE_VALUE(SetSeconds, CODE_SET_SECONDS, true); - - // 20.3.4.27 Date.prototype.setTime ( time ) - static JSTaggedValue SetTime(EcmaRuntimeCallInfo *argv); - - // 20.3.4.28 Date.prototype.setUTCDate ( date ) - SET_DATE_VALUE(SetUTCDate, CODE_SET_DATE, false); - - // 20.3.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] ) - SET_DATE_VALUE(SetUTCFullYear, CODE_SET_FULL_YEAR, false); - - // 20.3.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] ) - SET_DATE_VALUE(SetUTCHours, CODE_SET_HOURS, false); - - // 20.3.4.31 Date.prototype.setUTCMilliseconds ( ms ) - SET_DATE_VALUE(SetUTCMilliseconds, CODE_SET_MILLISECONDS, false); - - // 20.3.4.32 Date.prototype.setUTCMinutes ( min [ , sec [, ms ] ] ) - SET_DATE_VALUE(SetUTCMinutes, CODE_SET_MINUTES, false); - - // 20.3.4.33 Date.prototype.setUTCMonth ( month [ , date ] ) - SET_DATE_VALUE(SetUTCMonth, CODE_SET_MONTH, false); - - // 20.3.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] ) - SET_DATE_VALUE(SetUTCSeconds, CODE_SET_SECONDS, false); - - // 20.4.4.35 Date.prototype.toDateString ( ) - DATE_STRING(ToDateString); - - // 20.4.4.36 Date.prototype.toISOString ( ) - DATE_TO_STRING(ToISOString); - - // 20.4.4.37 Date.prototype.toJSON ( key ) - static JSTaggedValue ToJSON(EcmaRuntimeCallInfo *argv); - - // 20.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] ) - static JSTaggedValue ToLocaleDateString(EcmaRuntimeCallInfo *argv); - - // 20.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) - static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); - - // 20.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ) - static JSTaggedValue ToLocaleTimeString(EcmaRuntimeCallInfo *argv); - - // 20.4.4.41 Date.prototype.toString ( ) - DATE_STRING(ToString); - - // 20.4.4.42 Date.prototype.toTimeString ( ) - DATE_STRING(ToTimeString); - - // 20.4.4.43 Date.prototype.toUTCString ( ) - DATE_STRING(ToUTCString); - - // 20.4.4.44 Date.prototype.valueOf ( ) - static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); - - // 20.4.4.45 Date.prototype [ @@toPrimitive ] - static JSTaggedValue ToPrimitive(EcmaRuntimeCallInfo *argv); - -private: - // definition for set data code. - static constexpr uint32_t CODE_SET_DATE = 0x32; - static constexpr uint32_t CODE_SET_MILLISECONDS = 0x76; - static constexpr uint32_t CODE_SET_SECONDS = 0x75; - static constexpr uint32_t CODE_SET_MINUTES = 0x74; - static constexpr uint32_t CODE_SET_HOURS = 0x73; - static constexpr uint32_t CODE_SET_MONTH = 0x31; - static constexpr uint32_t CODE_SET_FULL_YEAR = 0x30; - static constexpr uint8_t CONSTRUCTOR_MAX_LENGTH = 7; -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_DATE_H diff --git a/runtime/builtins/builtins_date_time_format.cpp b/runtime/builtins/builtins_date_time_format.cpp index 6c3216afaaf22ff8bd3c147fee3b7311e55e904f..5532455d232d23825003bb74fc10a9c7a6b3f7a3 100644 --- a/runtime/builtins/builtins_date_time_format.cpp +++ b/runtime/builtins/builtins_date_time_format.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_date_time_format.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_date.h" @@ -21,8 +21,12 @@ #include "plugins/ecmascript/runtime/js_intl.h" namespace panda::ecmascript::builtins { + +// 13.1.5 DateTime Format Functions +JSTaggedValue AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv); + // 13.2.1 Intl.DateTimeFormat ( [ locales [ , options ] ] ) -JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::DateTimeFormatConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -31,8 +35,8 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. - JSHandle constructor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { new_target = constructor; } @@ -46,14 +50,14 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle dtf = JSDateTimeFormat::InitializeDateTimeFormat(thread, date_time_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 5. If newTarget is undefined and ? OrdinaryHasInstance(%DateTimeFormat%, this) is true, then // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: @@ -74,7 +78,7 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI } // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) -JSTaggedValue BuiltinsDateTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -82,25 +86,25 @@ JSTaggedValue BuiltinsDateTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *ar JSHandle available_locales = JSDateTimeFormat::GainAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). - JSHandle options = GetCallArg(argv, 1); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } // 13.4.3 get Intl.DateTimeFormat.prototype.format -JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::proto::GetFormat(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. if (!this_value->IsJSObject()) { @@ -124,7 +128,7 @@ JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) if (bound_format->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle intl_bound_func = - factory->NewJSIntlBoundFunction(reinterpret_cast(BuiltinsDateTimeFormat::AnonymousDateTimeFormat)); + factory->NewJSIntlBoundFunction(reinterpret_cast(AnonymousDateTimeFormat)); intl_bound_func->SetDateTimeFormat(thread, dtf); dtf->SetBoundFormat(thread, intl_bound_func); } @@ -132,13 +136,14 @@ JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) } // 13.1.5 DateTime Format Functions -JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv) +JSTaggedValue 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(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle intl_bound_func = JSHandle::Cast(GetConstructor(argv)); + JSHandle intl_bound_func = + JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let dtf be F.[[DateTimeFormat]]. JSHandle dtf(thread, intl_bound_func->GetDateTimeFormat()); @@ -150,7 +155,7 @@ JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInf // a. Let x be Call(%Date_now%, undefined). // 4. Else, // a. Let x be ? ToNumber(date). - JSHandle date = GetCallArg(argv, 0); + JSHandle date = builtins_common::GetCallArg(argv, 0); double x = 0.0; if (date->IsUndefined()) { x = JSDate::Now().GetNumber(); @@ -167,12 +172,12 @@ JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInf } // 13.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date ) -JSTaggedValue BuiltinsDateTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::proto::FormatToParts(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle dtf = GetThis(argv); + JSHandle dtf = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]). if (!dtf->IsJSDateTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "is not JSDateTimeFormat", JSTaggedValue::Exception()); @@ -182,7 +187,7 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) // a. Let x be Call(%Date_now%, undefined). // 4. Else, // a. Let x be ? ToNumber(date). - JSHandle date = GetCallArg(argv, 0); + JSHandle date = builtins_common::GetCallArg(argv, 0); double x = 0.0; if (date->IsUndefined()) { x = JSDate::Now().GetNumber(); @@ -205,12 +210,12 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) } // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () -JSTaggedValue BuiltinsDateTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); @@ -230,13 +235,13 @@ JSTaggedValue BuiltinsDateTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) } // Intl.DateTimeFormat.prototype.formatRange -JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::proto::FormatRange(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); @@ -248,8 +253,8 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv) } // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. - JSHandle start_date = GetCallArg(argv, 0); - JSHandle end_date = GetCallArg(argv, 1); + JSHandle start_date = builtins_common::GetCallArg(argv, 0); + JSHandle end_date = builtins_common::GetCallArg(argv, 1); if (start_date->IsUndefined() || end_date->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception()); } @@ -276,12 +281,12 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv) } // Intl.DateTimeFormat.prototype.formatRangeToParts -JSTaggedValue BuiltinsDateTimeFormat::FormatRangeToParts(EcmaRuntimeCallInfo *argv) +JSTaggedValue date_time_format::proto::FormatRangeToParts(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); @@ -294,8 +299,8 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRangeToParts(EcmaRuntimeCallInfo *ar } // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. - JSHandle start_date = GetCallArg(argv, 0); - JSHandle end_date = GetCallArg(argv, 1); + JSHandle start_date = builtins_common::GetCallArg(argv, 0); + JSHandle end_date = builtins_common::GetCallArg(argv, 1); if (start_date->IsUndefined() || end_date->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception()); } diff --git a/runtime/builtins/builtins_date_time_format.h b/runtime/builtins/builtins_date_time_format.h deleted file mode 100644 index e539f6ef18c860084bbda4aec3551d50e5b9faad..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_date_time_format.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_DATE_TIME_FORMAT_H -#define ECMASCRIPT_BUILTINS_BUILTINS_DATE_TIME_FORMAT_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsDateTimeFormat : public ecmascript::base::BuiltinsBase { -public: - // 13.2.1 Intl.DateTimeFormat ( [ locales [ , options ] ] ) - static JSTaggedValue DateTimeFormatConstructor(EcmaRuntimeCallInfo *argv); - - // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) - static JSTaggedValue SupportedLocalesOf(EcmaRuntimeCallInfo *argv); - - // 13.4.3 get Intl.DateTimeFormat.prototype.format - static JSTaggedValue Format(EcmaRuntimeCallInfo *argv); - - // 13.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date ) - static JSTaggedValue FormatToParts(EcmaRuntimeCallInfo *argv); - - // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () - static JSTaggedValue ResolvedOptions(EcmaRuntimeCallInfo *argv); - - // Intl.DateTimeFormat.prototype.formatRange - static JSTaggedValue FormatRange(EcmaRuntimeCallInfo *argv); - - // Intl.DateTimeFormat.prototype.formatRangeToParts - static JSTaggedValue FormatRangeToParts(EcmaRuntimeCallInfo *argv); - -private: - // 13.1.5 DateTime Format Functions - static JSTaggedValue AnonymousDateTimeFormat(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_DATE_TIME_FORMAT_H_ diff --git a/runtime/builtins/builtins_errors.cpp b/runtime/builtins/builtins_errors.cpp index 6dc082e27c82e161dcbdff4190444e957e25cb4e..649d22bfcd4e2a6bd1136865b600fbe56b8e6c3f 100644 --- a/runtime/builtins/builtins_errors.cpp +++ b/runtime/builtins/builtins_errors.cpp @@ -13,91 +13,100 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/error_helper.h" #include "plugins/ecmascript/runtime/js_tagged_value-inl.h" namespace panda::ecmascript::builtins { using ErrorHelper = ecmascript::base::ErrorHelper; using ErrorType = ecmascript::base::ErrorType; + // Error -JSTaggedValue BuiltinsError::ErrorConstructor(EcmaRuntimeCallInfo *argv) +// 19.5.1.1 +JSTaggedValue error::ErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::ERROR); } -JSTaggedValue BuiltinsError::ToString(EcmaRuntimeCallInfo *argv) +// 19.5.2.4 +JSTaggedValue error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::ERROR); } +// 19.5.5.2 // RangeError -JSTaggedValue BuiltinsRangeError::RangeErrorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue range_error::RangeErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::RANGE_ERROR); } -JSTaggedValue BuiltinsRangeError::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue range_error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::RANGE_ERROR); } +// 19.5.5.3 // ReferenceError -JSTaggedValue BuiltinsReferenceError::ReferenceErrorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue reference_error::ReferenceErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::REFERENCE_ERROR); } -JSTaggedValue BuiltinsReferenceError::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue reference_error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::REFERENCE_ERROR); } +// 19.5.5.5 // TypeError -JSTaggedValue BuiltinsTypeError::TypeErrorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue type_error::TypeErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::TYPE_ERROR); } -JSTaggedValue BuiltinsTypeError::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue type_error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::TYPE_ERROR); } -JSTaggedValue BuiltinsTypeError::ThrowTypeError(EcmaRuntimeCallInfo *argv) +JSTaggedValue type_error::ThrowTypeError(EcmaRuntimeCallInfo *argv) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "type error", JSTaggedValue::Exception()); } +// 19.5.5.6 // URIError -JSTaggedValue BuiltinsURIError::URIErrorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue uri_error::URIErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::URI_ERROR); } -JSTaggedValue BuiltinsURIError::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue uri_error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::URI_ERROR); } +// 19.5.5.4 // SyntaxError -JSTaggedValue BuiltinsSyntaxError::SyntaxErrorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue syntax_error::SyntaxErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::SYNTAX_ERROR); } -JSTaggedValue BuiltinsSyntaxError::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue syntax_error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::SYNTAX_ERROR); } +// 19.5.5.1 // EvalError -JSTaggedValue BuiltinsEvalError::EvalErrorConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue eval_error::EvalErrorConstructor(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonConstructor(argv, ErrorType::EVAL_ERROR); } -JSTaggedValue BuiltinsEvalError::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue eval_error::proto::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::EVAL_ERROR); } diff --git a/runtime/builtins/builtins_errors.h b/runtime/builtins/builtins_errors.h deleted file mode 100644 index ded192b7bea2d649295a503abf54b565f1c5a296..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_errors.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_ERRORS_H -#define ECMASCRIPT_BUILTINS_BUILTINS_ERRORS_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsError : public ecmascript::base::BuiltinsBase { -public: - // 19.5.1.1 - static JSTaggedValue ErrorConstructor(EcmaRuntimeCallInfo *argv); - // 19.5.2.4 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); -}; - -// 19.5.5.2 -class BuiltinsRangeError : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue RangeErrorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); -}; - -// 19.5.5.3 -class BuiltinsReferenceError : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue ReferenceErrorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); -}; - -// 19.5.5.5 -class BuiltinsTypeError : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue TypeErrorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ThrowTypeError(EcmaRuntimeCallInfo *argv); -}; - -// 19.5.5.6 -class BuiltinsURIError : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue URIErrorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); -}; - -// 19.5.5.4 -class BuiltinsSyntaxError : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue SyntaxErrorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); -}; - -// 19.5.5.1 -class BuiltinsEvalError : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue EvalErrorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ERRORS_H diff --git a/runtime/builtins/builtins_finalization_registry.cpp b/runtime/builtins/builtins_finalization_registry.cpp index 62399c12cb71d9ac4045965072418435f6829a49..dcfe0323f96b89975be77029ac3522943c4b76c2 100644 --- a/runtime/builtins/builtins_finalization_registry.cpp +++ b/runtime/builtins/builtins_finalization_registry.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_finalization_registry.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -21,7 +21,8 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsFinalizationRegistry::Constructor(EcmaRuntimeCallInfo *argv) +// 26.2.3.1 +JSTaggedValue finalization_registry::Constructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Constructor); @@ -29,18 +30,18 @@ JSTaggedValue BuiltinsFinalizationRegistry::Constructor(EcmaRuntimeCallInfo *arg [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2. If IsCallable(cleanupCallback) is false, throw a TypeError exception. - if (!GetCallArg(argv, 0)->IsCallable()) { + if (!builtins_common::GetCallArg(argv, 0)->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "cleanupCallback is not callable", JSTaggedValue::Exception()); } // 3.Let FinalizationRegistry be OrdinaryCreateFromConstructor( // NewTarget, "%FinalizationRegistry.prototype%", «[[Realm]], [[CleanupCallback]], [[Cells]]») - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle registry = JSHandle::Cast(obj); @@ -59,13 +60,14 @@ JSTaggedValue BuiltinsFinalizationRegistry::Constructor(EcmaRuntimeCallInfo *arg return registry.GetTaggedValue(); } -JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) +// 26.2.3.2 +JSTaggedValue finalization_registry::proto::Register(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Register); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 1. Let finalizationRegistry be the this value. if (!self->IsJSFinalizationRegistry()) { THROW_TYPE_ERROR_AND_RETURN(thread, "'this' is not FinalizationRegistry.", JSTaggedValue::Exception()); @@ -73,14 +75,14 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) JSHandle registry = JSHandle::Cast(self); // 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]). // 3. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0U); + JSHandle target = builtins_common::GetCallArg(argv, 0U); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "target is not an object.", JSTaggedValue::Exception()); } // 4. If SameValue(target, heldValue) is true, throw a TypeError exception. JSMutableHandle held_value(thread, JSTaggedValue::Hole()); if (argv->GetArgsNumber() >= 2U) { - held_value.Update(GetCallArg(argv, 1U)); + held_value.Update(builtins_common::GetCallArg(argv, 1U)); if (JSTaggedValue::SameValue(target.GetTaggedValue(), held_value.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "target and heldValue are the same.", JSTaggedValue::Exception()); } @@ -88,7 +90,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) // 5. If Type(unregisterToken) is not Object, then // a. If unregisterToken is not undefined, throw a TypeError exception. // b. Set unregisterToken to empty. - JSMutableHandle unregister_token(thread, GetCallArg(argv, 2U)); + JSMutableHandle unregister_token(thread, builtins_common::GetCallArg(argv, 2U)); if (!unregister_token->IsECMAObject()) { if (!unregister_token->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "unregisterToken must be an object.", JSTaggedValue::Exception()); @@ -103,13 +105,14 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsFinalizationRegistry::Unregister(EcmaRuntimeCallInfo *argv) +// 26.2.3.3 +JSTaggedValue finalization_registry::proto::Unregister(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Unregister); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 1. Let finalizationRegistry be the this value. if (!self->IsJSFinalizationRegistry()) { THROW_TYPE_ERROR_AND_RETURN(thread, "'this' is not FinalizationRegistry.", JSTaggedValue::Exception()); @@ -117,7 +120,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Unregister(EcmaRuntimeCallInfo *argv JSHandle registry = JSHandle::Cast(self); // 2. Perform ? RequireInternalSlot(finalizationRegistry, [[Cells]]). // 3. If Type(unregisterToken) is not Object, throw a TypeError exception. - JSHandle unregister_token = GetCallArg(argv, 0U); + JSHandle unregister_token = builtins_common::GetCallArg(argv, 0U); if (!unregister_token->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "unregisterToken must be an object.", JSTaggedValue::Exception()); } diff --git a/runtime/builtins/builtins_finalization_registry.h b/runtime/builtins/builtins_finalization_registry.h deleted file mode 100644 index 1a4ee57512027dbb1578fb150aab020c062371e6..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_finalization_registry.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_FINALIZATION_REGISTRY_H -#define ECMASCRIPT_BUILTINS_BUILTINS_FINALIZATION_REGISTRY_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsFinalizationRegistry : public ecmascript::base::BuiltinsBase { -public: - // 26.2.3.1 - static JSTaggedValue Constructor(EcmaRuntimeCallInfo *argv); - // 26.2.3.2 - static JSTaggedValue Register(EcmaRuntimeCallInfo *argv); - // 26.2.3.3 - static JSTaggedValue Unregister(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_FINALIZATION_REGISTRY_H diff --git a/runtime/builtins/builtins_function.cpp b/runtime/builtins/builtins_function.cpp index e45f6a953dad567337fe24dc06d14e3548628802..4ba9201a7a9f17b98b947e183ceb19df21c24e7a 100644 --- a/runtime/builtins/builtins_function.cpp +++ b/runtime/builtins/builtins_function.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_function.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -24,14 +24,14 @@ namespace panda::ecmascript::builtins { // ecma 19.2.1 Function (p1, p2, ... , pn, body) -JSTaggedValue BuiltinsFunction::FunctionConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue function::FunctionConstructor(EcmaRuntimeCallInfo *argv) { return EvalUtils::CreateDynamicFunction(argv, EvalUtils::DynamicFunctionKind::NORMAL); } // ecma 19.2.3 The Function prototype object is itself a built-in function object. // When invoked, it accepts any arguments and returns undefined. -JSTaggedValue BuiltinsFunction::FunctionPrototypeInvokeSelf([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue function::FunctionPrototypeInvokeSelf([[maybe_unused]] EcmaRuntimeCallInfo *argv) { return JSTaggedValue::Undefined(); } @@ -85,7 +85,7 @@ std::pair BuildArgumentsListFast(JSThread *thread, const } // anonymous namespace // ecma 19.2.3.1 Function.prototype.apply (thisArg, argArray) -JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv) +JSTaggedValue function::proto::Apply(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeApply); @@ -93,21 +93,21 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsCallable(func) is false, throw a TypeError exception. - if (!GetThis(argv)->IsCallable()) { + if (!builtins_common::GetThis(argv)->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "apply target is not callable", JSTaggedValue::Exception()); } - JSHandle func = GetThis(argv); - JSHandle this_arg = GetCallArg(argv, 0); + JSHandle func = builtins_common::GetThis(argv); + JSHandle this_arg = builtins_common::GetCallArg(argv, 0); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); // 2. If argArray is null or undefined, then - if (GetCallArg(argv, 1)->IsUndefined()) { // null will also get undefined + if (builtins_common::GetCallArg(argv, 1)->IsUndefined()) { // null will also get undefined // a. Return Call(func, thisArg). auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, 0); return JSFunction::Call(info.Get()); } // 3. Let argList be CreateListFromArrayLike(argArray). - JSHandle array_obj = GetCallArg(argv, 1); + JSHandle array_obj = builtins_common::GetCallArg(argv, 1); auto [array, length] = BuildArgumentsListFast(thread, array_obj); if (array == nullptr) { auto arg_list_res = JSObject::CreateListFromArrayLike(thread, array_obj); @@ -129,7 +129,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv } // ecma 19.2.3.2 Function.prototype.bind (thisArg , ...args) -JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) +JSTaggedValue function::proto::Bind(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeBind); @@ -138,13 +138,13 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let Target be the this value. - JSHandle target = GetThis(argv); + JSHandle target = builtins_common::GetThis(argv); // 2. If IsCallable(Target) is false, throw a TypeError exception. if (!target->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "bind target is not callable", JSTaggedValue::Exception()); } - JSHandle this_arg = GetCallArg(argv, 0); + JSHandle this_arg = builtins_common::GetCallArg(argv, 0); uint32_t args_length = 0; if (argv->GetArgsNumber() > 1) { args_length = argv->GetArgsNumber() - 1; @@ -154,7 +154,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) // values provided after thisArg in order. JSHandle args_array = factory->NewTaggedArray(args_length); for (uint32_t index = 0; index < args_length; ++index) { - args_array->Set(thread, index, GetCallArg(argv, index + 1)); + args_array->Set(thread, index, builtins_common::GetCallArg(argv, index + 1)); } // 4. Let F be BoundFunctionCreate(Target, thisArg, args). JSHandle target_function = JSHandle::Cast(target); @@ -222,7 +222,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) } // ecma 19.2.3.3 Function.prototype.call (thisArg , ...args) -JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) +JSTaggedValue function::proto::Call(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeCall); @@ -230,12 +230,12 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsCallable(func) is false, throw a TypeError exception. - if (!GetThis(argv)->IsCallable()) { + if (!builtins_common::GetThis(argv)->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "call target is not callable", JSTaggedValue::Exception()); } - JSHandle func = GetThis(argv); - JSHandle this_arg = GetCallArg(argv, 0); + JSHandle func = builtins_common::GetThis(argv); + JSHandle this_arg = builtins_common::GetCallArg(argv, 0); uint32_t args_length = 0; if (argv->GetArgsNumber() > 1) { args_length = argv->GetArgsNumber() - 1; @@ -255,29 +255,31 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) } // ecma 19.2.3.5 Function.prototype.toString () -JSTaggedValue BuiltinsFunction::FunctionPrototypeToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue function::proto::ToString(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeToString); // not implement due to that runtime can not get JS Source Code now. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); if (!this_value->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "function.toString() target is not callable", JSTaggedValue::Exception()); } - return GetTaggedString(thread, "Not support function.toString() due to Runtime can not obtain Source Code yet."); + return builtins_common::GetTaggedString( + thread, "Not support function.toString() due to Runtime can not obtain Source Code yet."); } // ecma 19.2.3.6 Function.prototype[@@hasInstance] (V) -JSTaggedValue BuiltinsFunction::FunctionPrototypeHasInstance(EcmaRuntimeCallInfo *argv) +JSTaggedValue function::proto::HasInstance(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeHasInstance); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); // 1. Let F be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. Return OrdinaryHasInstance(F, V). - JSHandle arg = GetCallArg(argv, 0); - return JSFunction::OrdinaryHasInstance(argv->GetThread(), this_value, arg) ? GetTaggedBoolean(true) - : GetTaggedBoolean(false); + JSHandle arg = builtins_common::GetCallArg(argv, 0); + return JSFunction::OrdinaryHasInstance(argv->GetThread(), this_value, arg) + ? builtins_common::GetTaggedBoolean(true) + : builtins_common::GetTaggedBoolean(false); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_function.h b/runtime/builtins/builtins_function.h deleted file mode 100644 index a4e8486e3c56f04ae10c26e7e50cb47f43b605fb..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_function.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H -#define ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H - -#include "plugins/ecmascript/runtime/js_tagged_value-inl.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsFunction : public ecmascript::base::BuiltinsBase { -public: - // ecma 19.2.1 Function (p1, p2, ... , pn, body) - static JSTaggedValue FunctionConstructor(EcmaRuntimeCallInfo *argv); - - // ecma 19.2.3 The Function prototype object is itself a built-in function object. - static JSTaggedValue FunctionPrototypeInvokeSelf(EcmaRuntimeCallInfo *argv); - - // ecma 19.2.3.1 Function.prototype.apply (thisArg, argArray) - static JSTaggedValue FunctionPrototypeApply(EcmaRuntimeCallInfo *argv); - - // ecma 19.2.3.2 Function.prototype.bind (thisArg , ...args) - static JSTaggedValue FunctionPrototypeBind(EcmaRuntimeCallInfo *argv); - - // ecma 19.2.3.3 Function.prototype.call (thisArg , ...args) - static JSTaggedValue FunctionPrototypeCall(EcmaRuntimeCallInfo *argv); - - // ecma 19.2.3.5 Function.prototype.toString () - static JSTaggedValue FunctionPrototypeToString(EcmaRuntimeCallInfo *argv); - - // ecma 19.2.3.6 Function.prototype[@@hasInstance] (V) - static JSTaggedValue FunctionPrototypeHasInstance(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_FUNCTION_H diff --git a/runtime/builtins/builtins_generator.cpp b/runtime/builtins/builtins_generator.cpp index be16663ce393cd89068eba39017cdf37b86f6b5d..8f83dcf1a186eb5153a96e80ee89ffb814fc9bb4 100644 --- a/runtime/builtins/builtins_generator.cpp +++ b/runtime/builtins/builtins_generator.cpp @@ -13,31 +13,31 @@ * limitations under the License. */ -#include "builtins_generator.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/js_eval.h" #include "plugins/ecmascript/runtime/js_function.h" #include "plugins/ecmascript/runtime/js_generator_object.h" namespace panda::ecmascript::builtins { // 26.2.1.1 GeneratorFunction(p1, p2, … , pn, body) -JSTaggedValue BuiltinsGenerator::GeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue generator_function::GeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv) { return EvalUtils::CreateDynamicFunction(argv, EvalUtils::DynamicFunctionKind::GENERATOR); } // 26.4.1.2 Generator.prototype.next(value) -JSTaggedValue BuiltinsGenerator::GeneratorPrototypeNext(EcmaRuntimeCallInfo *argv) +JSTaggedValue generator::proto::Next(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Next); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); } JSHandle generator(thread, JSGeneratorObject::Cast(*JSTaggedValue::ToObject(thread, msg))); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); // 2.Return ? GeneratorResume(g, value). JSHandle result = JSGeneratorObject::GeneratorResume(thread, generator, value); @@ -46,20 +46,20 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeNext(EcmaRuntimeCallInfo *arg } // 26.4.1.3 Generator.prototype.return(value) -JSTaggedValue BuiltinsGenerator::GeneratorPrototypeReturn(EcmaRuntimeCallInfo *argv) +JSTaggedValue generator::proto::Return(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Return); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); } JSHandle generator(thread, JSGeneratorObject::Cast(*JSTaggedValue::ToObject(thread, msg))); // 2.Let C be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::RETURN, value); @@ -70,20 +70,20 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeReturn(EcmaRuntimeCallInfo *a } // 26.4.1.4 Generator.prototype.throw(exception) -JSTaggedValue BuiltinsGenerator::GeneratorPrototypeThrow(EcmaRuntimeCallInfo *argv) +JSTaggedValue generator::proto::Throw(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Throw); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); } JSHandle generator(thread, JSGeneratorObject::Cast(*JSTaggedValue::ToObject(thread, msg))); // 2.Let C be ThrowCompletion(exception). - JSHandle exception = GetCallArg(argv, 0); + JSHandle exception = builtins_common::GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::THROW, exception); diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index b94c77632aa19ac1f19d2bfa66d8e0ad04f9633c..920ffcc80e6036a33bfb5d1299598aed5b4d8778 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_global.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include #include #include @@ -32,13 +32,104 @@ #include "include/thread_scopes.h" namespace panda::ecmascript::builtins { + +static constexpr uint8_t BIT_MASK = 0x0F; +static constexpr uint8_t BIT_MASK_FF = 0xFF; +static constexpr uint16_t BIT16_MASK = 0x3FF; +static constexpr uint8_t BIT_MASK_ONE = 0x80; +static constexpr uint8_t BIT_MASK_TWO = 0xC0; +using JudgUriFunc = bool (*)(uint16_t); + using NumberHelper = ecmascript::base::NumberHelper; using StringHelper = ecmascript::base::StringHelper; +static void PrintString(JSThread *thread, EcmaString *string); +static JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set); +static JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set); + +inline bool IsAlNum(uint16_t ch) +{ + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'); +} +inline bool IsInNonEscapedSymbols(uint16_t ch) +{ + switch (ch) { + case '@': + case '*': + case '_': + case '+': + case '-': + case '.': + case '/': + return true; + default: + return false; + } +} +inline bool IsNotEscaped(uint16_t ch) +{ + return IsAlNum(ch) || IsInNonEscapedSymbols(ch); +} +bool IsUnescapedURI(uint16_t ch); +bool IsInUnescapedURISet(uint16_t ch); +bool IsInReservedURISet(uint16_t ch); +bool IsReservedURI(uint16_t ch); +bool IsInMarkURISet(uint16_t ch); +bool IsHexDigits(uint16_t ch); +inline int IsHex(uint16_t cc) +{ + constexpr uint16_t HEX_MIN_LETTER_VALUE = 10; + constexpr uint16_t HEX_MAX_LETTER_VALUE = 15; + if (cc > 'f') { + return -1; + } + cc -= '0'; + if (cc < HEX_MIN_LETTER_VALUE) { + return cc; + } + cc -= ('A' - '0'); + if (cc <= HEX_MAX_LETTER_VALUE - HEX_MIN_LETTER_VALUE) { + return cc + HEX_MIN_LETTER_VALUE; + } + cc -= ('a' - 'A'); + if (cc <= HEX_MAX_LETTER_VALUE - HEX_MIN_LETTER_VALUE) { + return cc + HEX_MIN_LETTER_VALUE; + } + return -1; +} +uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind); +JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, const JSHandle &obj_handle); + +/** + * Class tracks GC tasks already processed by GC. + * Also the class tracks concurrent mark GC phase and calls + * the callback if it specified. + */ +class GCTaskTracker : public mem::GCListener { +public: + void InitIfNeeded(mem::GC *gc); + bool IsInitialized(); + void AddTaskId(uint64_t id); + bool HasId(uint64_t id); + void SetCallbackForTask(uint32_t task_id, uintptr_t callback_handle); + void GCStarted(const GCTask &task, size_t heap_size) override; + void GCFinished(const GCTask &task, size_t heap_size_before_gc, size_t heap_size) override; + void GCPhaseStarted(mem::GCPhase phase) override; + void RemoveId(uint64_t id); + +private: + bool initialized_ = false; + std::vector task_ids_ GUARDED_BY(lock_); + uint32_t current_task_id_ = 0; + uint32_t callback_task_id_ = 0; + uintptr_t callback_handle_ = 0; + os::memory::Mutex lock_; +}; + // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) -BuiltinsGlobal::GCTaskTracker BuiltinsGlobal::g_gctask_tracker_; +GCTaskTracker G_GCTASK_TRACKER; -void BuiltinsGlobal::GCTaskTracker::InitIfNeeded(mem::GC *gc) +void GCTaskTracker::InitIfNeeded(mem::GC *gc) { if (initialized_) { return; @@ -47,30 +138,30 @@ void BuiltinsGlobal::GCTaskTracker::InitIfNeeded(mem::GC *gc) initialized_ = true; } -bool BuiltinsGlobal::GCTaskTracker::IsInitialized() +bool GCTaskTracker::IsInitialized() { return initialized_; } -void BuiltinsGlobal::GCTaskTracker::AddTaskId(uint64_t id) +void GCTaskTracker::AddTaskId(uint64_t id) { os::memory::LockHolder lock(lock_); task_ids_.push_back(id); } -bool BuiltinsGlobal::GCTaskTracker::HasId(uint64_t id) +bool GCTaskTracker::HasId(uint64_t id) { os::memory::LockHolder lock(lock_); return std::find(task_ids_.begin(), task_ids_.end(), id) != task_ids_.end(); } -void BuiltinsGlobal::GCTaskTracker::SetCallbackForTask(uint32_t task_id, uintptr_t callback_handle) +void GCTaskTracker::SetCallbackForTask(uint32_t task_id, uintptr_t callback_handle) { callback_task_id_ = task_id; callback_handle_ = callback_handle; } -void BuiltinsGlobal::GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) +void GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) { if (phase == mem::GCPhase::GC_PHASE_MARK && callback_handle_ != 0 && current_task_id_ == callback_task_id_) { JSThread *thread = JSThread::GetCurrent(); @@ -87,18 +178,18 @@ void BuiltinsGlobal::GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) } } -void BuiltinsGlobal::GCTaskTracker::GCStarted(const GCTask &task, [[maybe_unused]] size_t heap_size) +void GCTaskTracker::GCStarted(const GCTask &task, [[maybe_unused]] size_t heap_size) { current_task_id_ = task.GetId(); } -void BuiltinsGlobal::GCTaskTracker::GCFinished(const GCTask &task, [[maybe_unused]] size_t heap_size_before_gc, - [[maybe_unused]] size_t heap_size) +void GCTaskTracker::GCFinished(const GCTask &task, [[maybe_unused]] size_t heap_size_before_gc, + [[maybe_unused]] size_t heap_size) { RemoveId(task.GetId()); } -void BuiltinsGlobal::GCTaskTracker::RemoveId(uint64_t id) +void GCTaskTracker::RemoveId(uint64_t id) { current_task_id_ = 0; if (id == callback_task_id_ && callback_handle_ != 0) { @@ -116,62 +207,62 @@ void BuiltinsGlobal::GCTaskTracker::RemoveId(uint64_t id) } // 18.2.1 -JSTaggedValue BuiltinsGlobal::Eval(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::Eval(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - if (msg->GetArgsNumber() == 0) { + if (argv->GetArgsNumber() == 0) { return JSTaggedValue(JSTaggedValue::VALUE_UNDEFINED); } - return EvalUtils::Eval(thread, msg->GetCallArg(0)); + return EvalUtils::Eval(thread, argv->GetCallArg(0)); } // 18.2.2 -JSTaggedValue BuiltinsGlobal::IsFinite(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::IsFinite(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, IsFinite); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle number_input = GetCallArg(msg, 0); + JSHandle number_input = builtins_common::GetCallArg(argv, 0); // 1. Let num be ToNumber(number). JSTaggedNumber number = JSTaggedValue::ToNumber(thread, number_input); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If num is NaN, +Infinite, or -Infinite, return false. // 4. Otherwise, return true. if (std::isfinite(number.GetNumber())) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 18.2.3 -JSTaggedValue BuiltinsGlobal::IsNaN(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::IsNaN(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, IsNaN); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle number_input = GetCallArg(msg, 0); + JSHandle number_input = builtins_common::GetCallArg(argv, 0); // 1. Let num be ToNumber(number). JSTaggedNumber number = JSTaggedValue::ToNumber(thread, number_input); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If num is NaN, return true. if (std::isnan(number.GetNumber())) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // 4. Otherwise, return false. - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } -bool BuiltinsGlobal::IsUnescapedURI(uint16_t ch) +bool IsUnescapedURI(uint16_t ch) { return IsAlNum(ch) || IsInMarkURISet(ch); } -bool BuiltinsGlobal::IsInUnescapedURISet(uint16_t ch) +bool IsInUnescapedURISet(uint16_t ch) { if (ch == '#') { return true; @@ -179,7 +270,7 @@ bool BuiltinsGlobal::IsInUnescapedURISet(uint16_t ch) return IsUnescapedURI(ch) || IsReservedURI(ch); } -bool BuiltinsGlobal::IsInReservedURISet(uint16_t ch) +bool IsInReservedURISet(uint16_t ch) { if (ch == '#') { return true; @@ -187,33 +278,34 @@ bool BuiltinsGlobal::IsInReservedURISet(uint16_t ch) return IsReservedURI(ch); } -bool BuiltinsGlobal::IsReservedURI(uint16_t ch) +bool IsReservedURI(uint16_t ch) { std::u16string str(u";/?:@&=+$,"); return (str.find(ch) != std::u16string::npos); } -bool BuiltinsGlobal::IsInMarkURISet(uint16_t ch) +bool IsInMarkURISet(uint16_t ch) { std::u16string str(u"-_.!~*'()"); return (str.find(ch) != std::u16string::npos); } -bool BuiltinsGlobal::IsHexDigits(uint16_t ch) +bool IsHexDigits(uint16_t ch) { return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || ('a' <= ch && ch <= 'f'); } -JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::Unescape(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); + ASSERT(argv); constexpr uint16_t PERCENT_SIGN = 0x0025; constexpr uint16_t LATIN_SMALL_LETTER_U = 0x0075; - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, Unescape); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Set string to ? ToString(string). - [[maybe_unused]] JSHandle sstring = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle sstring = + JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); // 2. ReturnIfAbrupt(uriString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let length be the length of string. @@ -290,16 +382,17 @@ JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) return factory->NewFromUtf16Literal(rr_data, rr_size).GetTaggedValue(); } -JSTaggedValue BuiltinsGlobal::Escape(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::Escape(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); + ASSERT(argv); constexpr uint16_t MAX_DOUBLE_DIGIT = 256; static const std::u16string HEX_STR = u"0123456789ABCDEF"; - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, Escape); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Set string to ? ToString(string). - [[maybe_unused]] JSHandle sstring = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle sstring = + JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); // ReturnIfAbrupt(uriString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let length be the length of string. @@ -362,15 +455,16 @@ JSTaggedValue BuiltinsGlobal::Escape(EcmaRuntimeCallInfo *msg) } // 18.2.6 -JSTaggedValue BuiltinsGlobal::DecodeURI(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::DecodeURI(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, DecodeURI); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let uriString be ToString(encodedURI). // 2. ReturnIfAbrupt(uriString). - [[maybe_unused]] JSHandle uri_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle uri_string = + JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let reservedURISet be a String containing one instance of each code unit valid in uriReserved plus "#". @@ -378,15 +472,16 @@ JSTaggedValue BuiltinsGlobal::DecodeURI(EcmaRuntimeCallInfo *msg) return Decode(thread, uri_string, IsInReservedURISet); } -JSTaggedValue BuiltinsGlobal::EncodeURI(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::EncodeURI(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, EncodeURI); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let uriString be ToString(uri). // 2. ReturnIfAbrupt(uriString). - [[maybe_unused]] JSHandle uri_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle uri_string = + JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let unescapedURISet be a String containing one instance of @@ -395,15 +490,16 @@ JSTaggedValue BuiltinsGlobal::EncodeURI(EcmaRuntimeCallInfo *msg) return Encode(thread, uri_string, IsInUnescapedURISet); } -JSTaggedValue BuiltinsGlobal::DecodeURIComponent(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::DecodeURIComponent(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, DecodeURIComponent); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let componentString be ToString(encodedURIComponent). // 2. ReturnIfAbrupt(componentString). - [[maybe_unused]] JSHandle component_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle component_string = + JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let reservedURIComponentSet be the empty String. @@ -411,15 +507,16 @@ JSTaggedValue BuiltinsGlobal::DecodeURIComponent(EcmaRuntimeCallInfo *msg) return Decode(thread, component_string, []([[maybe_unused]] uint16_t unused) { return false; }); } -JSTaggedValue BuiltinsGlobal::EncodeURIComponent(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::EncodeURIComponent(EcmaRuntimeCallInfo *argv) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(argv); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, EncodeURIComponent); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let componentString be ToString(uriComponent). // 2. ReturnIfAbrupt(componentString). - [[maybe_unused]] JSHandle component_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle component_string = + JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let unescapedURIComponentSet be a String containing one instance of each code unit valid in uriUnescaped. @@ -428,7 +525,7 @@ JSTaggedValue BuiltinsGlobal::EncodeURIComponent(EcmaRuntimeCallInfo *msg) } // Runtime Semantics -JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) +JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) { // 1. Let strLen be the number of code units in string. uint32_t str_len = str->GetLength(); @@ -515,7 +612,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) +JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) { // 1. Let strLen be the number of code units in string. [[maybe_unused]] uint32_t str_len = str->GetLength(); @@ -700,7 +797,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandleGetThread(); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, PrintEntryPoint); - uint32_t num_args = msg->GetArgsNumber(); + uint32_t num_args = argv->GetArgsNumber(); for (uint32_t i = 0; i < num_args; i++) { - JSHandle string_content = JSTaggedValue::ToString(thread, GetCallArg(msg, i)); + JSHandle string_content = JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PrintString(thread, *string_content); @@ -733,9 +830,9 @@ JSTaggedValue BuiltinsGlobal::PrintEntrypoint(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::GCEntrypoint(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::Gc(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); ASSERT(thread != nullptr); [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, GCEntrypoint); @@ -779,23 +876,23 @@ static GCTaskCause GCCauseFromString(JSThread *thread, const JSHandleGetThread(); + JSThread *thread = argv->GetThread(); ASSERT(thread != nullptr); [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, SpecifiedGCEntrypoint); bool run_gc_in_place = Runtime::GetOptions().IsRunGcInPlace("ecmascript"); - GCTaskCause reason = GCCauseFromString(thread, GetCallArg(msg, 0)); - JSHandle callback_fn = GetCallArg(msg, 1); + GCTaskCause reason = GCCauseFromString(thread, builtins_common::GetCallArg(argv, 0)); + JSHandle callback_fn = builtins_common::GetCallArg(argv, 1); if (reason == GCTaskCause::INVALID_CAUSE) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid GC cause"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } mem::GC *gc = thread->GetEcmaVM()->GetGC(); - g_gctask_tracker_.InitIfNeeded(gc); + G_GCTASK_TRACKER.InitIfNeeded(gc); auto task = MakePandaUnique(reason); if (!callback_fn->IsUndefined()) { if (!callback_fn->IsJSFunction()) { @@ -806,7 +903,7 @@ JSTaggedValue BuiltinsGlobal::SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg) run_gc_in_place = true; uintptr_t global_handle = thread->GetEcmaGlobalStorage()->NewGlobalHandle(callback_fn.GetTaggedValue().GetRawData()); - g_gctask_tracker_.SetCallbackForTask(task->GetId(), global_handle); + G_GCTASK_TRACKER.SetCallbackForTask(task->GetId(), global_handle); } if (reason == GCTaskCause::YOUNG_GC_CAUSE) { run_gc_in_place = true; @@ -817,14 +914,14 @@ JSTaggedValue BuiltinsGlobal::SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg) if (run_gc_in_place) { task_executed = gc->WaitForGCInManaged(*task); } else { - g_gctask_tracker_.AddTaskId(id); + G_GCTASK_TRACKER.AddTaskId(id); task_executed = gc->Trigger(std::move(task)); } if (run_gc_in_place) { return task_executed ? JSTaggedValue(0) : JSTaggedValue(-1); } if (!task_executed) { - g_gctask_tracker_.RemoveId(id); + G_GCTASK_TRACKER.RemoveId(id); return JSTaggedValue(-1); } return JSTaggedValue(static_cast(id)); @@ -835,12 +932,12 @@ JSTaggedValue BuiltinsGlobal::SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg) * @param gc_id - id of the GC which is returned by startGc. * If gc_id is 0 or -1 the function returns immediately. */ -JSTaggedValue BuiltinsGlobal::WaitForFinishGC(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::WaitForFinishGC(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, WaitForFinishGC); - JSHandle arg = GetCallArg(msg, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); if (!arg->IsNumber()) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid GC id"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); @@ -849,9 +946,9 @@ JSTaggedValue BuiltinsGlobal::WaitForFinishGC(EcmaRuntimeCallInfo *msg) if (id <= 0) { return JSTaggedValue::Undefined(); } - ASSERT(g_gctask_tracker_.IsInitialized()); + ASSERT(G_GCTASK_TRACKER.IsInitialized()); ScopedNativeCodeThread s(thread); - while (g_gctask_tracker_.HasId(static_cast(id))) { + while (G_GCTASK_TRACKER.HasId(static_cast(id))) { constexpr uint64_t WAIT_TIME_MS = 10; os::thread::NativeSleep(WAIT_TIME_MS); } @@ -860,12 +957,12 @@ JSTaggedValue BuiltinsGlobal::WaitForFinishGC(EcmaRuntimeCallInfo *msg) // Function schedules GC before n-th allocation by setting counter to the specific GC trigger. // Another call may reset the counter. In this case the last counter will be used to trigger the GC. -JSTaggedValue BuiltinsGlobal::ScheduleGCAfterNthAlloc(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::ScheduleGcAfterNthAlloc(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, ScheduleGCAfterNthAlloc); - JSHandle arg = GetCallArg(msg, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); if (!arg->IsInt()) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid argument"); @@ -877,7 +974,7 @@ JSTaggedValue BuiltinsGlobal::ScheduleGCAfterNthAlloc(EcmaRuntimeCallInfo *msg) thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid argument"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - GCTaskCause reason = GCCauseFromString(thread, GetCallArg(msg, 1)); + GCTaskCause reason = GCCauseFromString(thread, builtins_common::GetCallArg(argv, 1)); if (reason == GCTaskCause::INVALID_CAUSE) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "Invalid GC cause"); @@ -897,9 +994,9 @@ JSTaggedValue BuiltinsGlobal::ScheduleGCAfterNthAlloc(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::IsScheduledGCTriggered(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::IsScheduledGcTriggered(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, IsScheduledGCTriggered); EcmaVM *vm = thread->GetEcmaVM(); @@ -911,9 +1008,9 @@ JSTaggedValue BuiltinsGlobal::IsScheduledGCTriggered(EcmaRuntimeCallInfo *msg) return JSTaggedValue(sched_trigger->IsTriggered()); } -JSTaggedValue BuiltinsGlobal::AllocateArrayObject(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::AllocateArrayObject(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); ASSERT(thread != nullptr); [[maybe_unused]] EcmaHandleScope handle_scope(thread); @@ -921,10 +1018,10 @@ JSTaggedValue BuiltinsGlobal::AllocateArrayObject(EcmaRuntimeCallInfo *msg) int64_t size_in_bytes = 0; - if (GetCallArg(msg, 0)->IsInt()) { - size_in_bytes = GetCallArg(msg, 0)->GetInt(); - } else if (GetCallArg(msg, 0)->IsDouble()) { - size_in_bytes = GetCallArg(msg, 0)->GetDouble(); + if (builtins_common::GetCallArg(argv, 0)->IsInt()) { + size_in_bytes = builtins_common::GetCallArg(argv, 0)->GetInt(); + } else if (builtins_common::GetCallArg(argv, 0)->IsDouble()) { + size_in_bytes = builtins_common::GetCallArg(argv, 0)->GetDouble(); } else { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "The value must be an integer"); @@ -960,21 +1057,21 @@ JSTaggedValue BuiltinsGlobal::AllocateArrayObject(EcmaRuntimeCallInfo *msg) return array.GetTaggedValue(); } -JSTaggedValue BuiltinsGlobal::MarkObject(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::MarkObject(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, MarkObject); EcmaVM *vm = thread->GetEcmaVM(); - JSHandle arg = GetCallArg(msg, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); if (arg->IsHeapObject()) { vm->MarkObject(arg->GetHeapObject()); } return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::GetMarkQueue(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::GetMarkQueue(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, GetMarkQueue); EcmaVM *vm = thread->GetEcmaVM(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); @@ -987,20 +1084,20 @@ JSTaggedValue BuiltinsGlobal::GetMarkQueue(EcmaRuntimeCallInfo *msg) return array.GetTaggedValue(); } -JSTaggedValue BuiltinsGlobal::ClearMarkQueue(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::ClearMarkQueue(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, ClearMarkQueue); thread->GetEcmaVM()->ClearMarkQueue(); return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::MarkObjectRecursively(EcmaRuntimeCallInfo *msg) +JSTaggedValue gc_marker::MarkObjectRecursively(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, MarkObjectRecursively); mem::GC *gc = thread->GetEcmaVM()->GetGC(); - JSHandle arg = GetCallArg(msg, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); if (!arg->IsHeapObject()) { [[maybe_unused]] EcmaHandleScope handle_scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Argument is not an object", JSTaggedValue::Exception()); @@ -1023,14 +1120,14 @@ JSTaggedValue BuiltinsGlobal::MarkObjectRecursively(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::GCObjectSpaceType(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::GetObjectSpaceType(EcmaRuntimeCallInfo *argv) { - ASSERT(msg != nullptr); - JSThread *thread = msg->GetThread(); + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); ASSERT(thread != nullptr); BUILTINS_API_TRACE(thread, Global, GCObjectSpaceType); - JSHandle obj_handle = GetCallArg(msg, 0); + JSHandle obj_handle = builtins_common::GetCallArg(argv, 0); auto global_constants = thread->GlobalConstants(); if (!obj_handle.GetTaggedValue().IsHeapObject()) { [[maybe_unused]] EcmaHandleScope handle_scope(thread); @@ -1053,8 +1150,7 @@ JSTaggedValue BuiltinsGlobal::GCObjectSpaceType(EcmaRuntimeCallInfo *msg) } } -JSHandle BuiltinsGlobal::GCSpecialisedObjectSpaceType(JSThread *thread, - const JSHandle &obj_handle) +JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, const JSHandle &obj_handle) { auto global_constants = thread->GlobalConstants(); if (!thread->GetEcmaVM()->GetGC()->IsGenerational()) { @@ -1068,12 +1164,12 @@ JSHandle BuiltinsGlobal::GCSpecialisedObjectSpaceType(JSThread *t return global_constants->GetHandledTenuredSpaceString(); } -JSTaggedValue BuiltinsGlobal::PinObject(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::PinObject(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, PinObject); EcmaVM *vm = thread->GetEcmaVM(); - JSHandle arg = GetCallArg(msg, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); if (arg->IsHeapObject()) { auto *obj_allocator = vm->GetHeapManager()->GetObjectAllocator().AsObjectAllocator(); auto *gc = vm->GetGC(); @@ -1092,12 +1188,12 @@ JSTaggedValue BuiltinsGlobal::PinObject(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::UnpinObject(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::UnpinObject(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, UnpinObject); EcmaVM *vm = thread->GetEcmaVM(); - JSHandle arg = GetCallArg(msg, 0); + JSHandle arg = builtins_common::GetCallArg(argv, 0); if (arg->IsHeapObject()) { vm->GetHeapManager()->GetObjectAllocator().AsObjectAllocator()->UnpinObject(arg->GetHeapObject()); } else { @@ -1108,57 +1204,57 @@ JSTaggedValue BuiltinsGlobal::UnpinObject(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::GetObjectAddress(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::GetObjectAddress(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, GetObjectAddress); [[maybe_unused]] EcmaHandleScope handle_scope(thread); PandaStringStream addr_stream; - addr_stream << GetCallArg(msg, 0)->GetHeapObject(); + addr_stream << builtins_common::GetCallArg(argv, 0)->GetHeapObject(); return thread->GetEcmaVM()->GetFactory()->NewFromString(addr_stream.str()).GetTaggedValue(); } -JSTaggedValue BuiltinsGlobal::CallJsBoundFunction(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::CallJsBoundFunction(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, CallJsBoundFunction); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - // msg contains jsfunc, this, arg1,... + // argv contains jsfunc, this, arg1,... - JSHandle bound_func(GetConstructor(msg)); + JSHandle bound_func(builtins_common::GetConstructor(argv)); JSHandle this_obj(thread, bound_func->GetBoundThis()); - msg->SetThis(this_obj.GetTaggedValue()); - return SlowRuntimeHelper::CallBoundFunction(msg); + argv->SetThis(this_obj.GetTaggedValue()); + return SlowRuntimeHelper::CallBoundFunction(argv); } -JSTaggedValue BuiltinsGlobal::CallJsProxy(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::CallJsProxy(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Global, CallJsProxy); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - // msg contains js_proxy, this, arg1,... - JSHandle proxy(GetConstructor(msg)); + // argv contains js_proxy, this, arg1,... + JSHandle proxy(builtins_common::GetConstructor(argv)); if (!proxy->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Proxy target is not callable", JSTaggedValue::Undefined()); } // Calling proxy directly should transfer 'undefined' as this - return JSProxy::CallInternal(msg); + return JSProxy::CallInternal(argv); } #if ECMASCRIPT_ENABLE_RUNTIME_STAT -JSTaggedValue BuiltinsGlobal::StartRuntimeStat(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::StartRuntimeStat(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // start vm runtime stat statistic thread->GetEcmaVM()->SetRuntimeStatEnable(true); return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsGlobal::StopRuntimeStat(EcmaRuntimeCallInfo *msg) +JSTaggedValue global::StopRuntimeStat(EcmaRuntimeCallInfo *argv) { - JSThread *thread = msg->GetThread(); + JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // start vm runtime stat statistic thread->GetEcmaVM()->SetRuntimeStatEnable(false); diff --git a/runtime/builtins/builtins_global.h b/runtime/builtins/builtins_global.h deleted file mode 100644 index 0e22b45d01de49c377d59474e903dd510026fa8a..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_global.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_GLOBAL_H -#define ECMASCRIPT_BUILTINS_BUILTINS_GLOBAL_H - -#include "libpandabase/os/mutex.h" -#include "runtime/mem/gc/gc.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_thread.h" - -namespace panda::ecmascript::builtins { -static constexpr uint8_t BIT_MASK = 0x0F; -static constexpr uint8_t BIT_MASK_FF = 0xFF; -static constexpr uint16_t BIT16_MASK = 0x3FF; -static constexpr uint8_t BIT_MASK_ONE = 0x80; -static constexpr uint8_t BIT_MASK_TWO = 0xC0; -using JudgUriFunc = bool (*)(uint16_t); - -class BuiltinsGlobal : public ecmascript::base::BuiltinsBase { -public: - // 18.2.1 - static JSTaggedValue Eval(EcmaRuntimeCallInfo *msg); - // 18.2.2 - static JSTaggedValue IsFinite(EcmaRuntimeCallInfo *msg); - // 18.2.3 - static JSTaggedValue IsNaN(EcmaRuntimeCallInfo *msg); - // escape / unescape - static JSTaggedValue Escape(EcmaRuntimeCallInfo *msg); - static JSTaggedValue Unescape(EcmaRuntimeCallInfo *msg); - // 18.2.6 - static JSTaggedValue DecodeURI(EcmaRuntimeCallInfo *msg); - static JSTaggedValue EncodeURI(EcmaRuntimeCallInfo *msg); - static JSTaggedValue DecodeURIComponent(EcmaRuntimeCallInfo *msg); - static JSTaggedValue EncodeURIComponent(EcmaRuntimeCallInfo *msg); - - static JSTaggedValue PrintEntrypoint(EcmaRuntimeCallInfo *msg); - static JSTaggedValue GCEntrypoint(EcmaRuntimeCallInfo *msg); - static JSTaggedValue SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg); - static JSTaggedValue WaitForFinishGC(EcmaRuntimeCallInfo *msg); - static JSTaggedValue ScheduleGCAfterNthAlloc(EcmaRuntimeCallInfo *msg); - static JSTaggedValue IsScheduledGCTriggered(EcmaRuntimeCallInfo *msg); - static JSTaggedValue AllocateArrayObject(EcmaRuntimeCallInfo *msg); - static JSTaggedValue MarkObject(EcmaRuntimeCallInfo *msg); - static JSTaggedValue GetMarkQueue(EcmaRuntimeCallInfo *msg); - static JSTaggedValue ClearMarkQueue(EcmaRuntimeCallInfo *msg); - static JSTaggedValue MarkObjectRecursively(EcmaRuntimeCallInfo *msg); - static JSTaggedValue GCObjectSpaceType(EcmaRuntimeCallInfo *msg); - static JSTaggedValue PinObject(EcmaRuntimeCallInfo *msg); - static JSTaggedValue UnpinObject(EcmaRuntimeCallInfo *msg); - static JSTaggedValue GetObjectAddress(EcmaRuntimeCallInfo *msg); - static JSTaggedValue CallJsBoundFunction(EcmaRuntimeCallInfo *msg); - static JSTaggedValue CallJsProxy(EcmaRuntimeCallInfo *msg); -#if ECMASCRIPT_ENABLE_RUNTIME_STAT - static JSTaggedValue StartRuntimeStat(EcmaRuntimeCallInfo *msg); - static JSTaggedValue StopRuntimeStat(EcmaRuntimeCallInfo *msg); -#endif - -private: - static void PrintString(JSThread *thread, EcmaString *string); - static void PrintValue(int64_t value, int64_t tag); - static JSTaggedValue Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set); - static JSTaggedValue Decode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set); - - static inline bool IsAlNum(uint16_t ch) - { - return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'); - } - static inline bool IsInNonEscapedSymbols(uint16_t ch) - { - switch (ch) { - case '@': - case '*': - case '_': - case '+': - case '-': - case '.': - case '/': - return true; - default: - return false; - } - } - static inline bool IsNotEscaped(uint16_t ch) - { - return IsAlNum(ch) || IsInNonEscapedSymbols(ch); - } - static bool IsUnescapedURI(uint16_t ch); - static bool IsInUnescapedURISet(uint16_t ch); - static bool IsInReservedURISet(uint16_t ch); - static bool IsReservedURI(uint16_t ch); - static bool IsInMarkURISet(uint16_t ch); - static bool IsHexDigits(uint16_t ch); - static inline int IsHex(uint16_t cc) - { - constexpr uint16_t HEX_MIN_LETTER_VALUE = 10; - constexpr uint16_t HEX_MAX_LETTER_VALUE = 15; - if (cc > 'f') { - return -1; - } - cc -= '0'; - if (cc < HEX_MIN_LETTER_VALUE) { - return cc; - } - cc -= ('A' - '0'); - if (cc <= HEX_MAX_LETTER_VALUE - HEX_MIN_LETTER_VALUE) { - return cc + HEX_MIN_LETTER_VALUE; - } - cc -= ('a' - 'A'); - if (cc <= HEX_MAX_LETTER_VALUE - HEX_MIN_LETTER_VALUE) { - return cc + HEX_MIN_LETTER_VALUE; - } - return -1; - } - static uint8_t GetValueFromTwoHex(uint16_t front, uint16_t behind); - static JSHandle GCSpecialisedObjectSpaceType(JSThread *thread, - const JSHandle &obj_handle); - - /** - * Class tracks GC tasks already processed by GC. - * Also the class tracks concurrent mark GC phase and calls - * the callback if it specified. - */ - class GCTaskTracker : public mem::GCListener { - public: - void InitIfNeeded(mem::GC *gc); - bool IsInitialized(); - void AddTaskId(uint64_t id); - bool HasId(uint64_t id); - void SetCallbackForTask(uint32_t task_id, uintptr_t callback_handle); - void GCStarted(const GCTask &task, size_t heap_size) override; - void GCFinished(const GCTask &task, size_t heap_size_before_gc, size_t heap_size) override; - void GCPhaseStarted(mem::GCPhase phase) override; - void RemoveId(uint64_t id); - - private: - bool initialized_ = false; - std::vector task_ids_ GUARDED_BY(lock_); - uint32_t current_task_id_ = 0; - uint32_t callback_task_id_ = 0; - uintptr_t callback_handle_ = 0; - os::memory::Mutex lock_; - }; - - static GCTaskTracker g_gctask_tracker_; -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ERROR_H diff --git a/runtime/builtins/builtins_intl.cpp b/runtime/builtins/builtins_intl.cpp index b9295f43e1e939252cd76c48e14ff1bde08ab412..632ad471dfa7720e9bc912586961f2c94bc24bc9 100644 --- a/runtime/builtins/builtins_intl.cpp +++ b/runtime/builtins/builtins_intl.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_intl.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/js_array.h" #include "plugins/ecmascript/runtime/js_locale.h" @@ -21,13 +21,13 @@ namespace panda::ecmascript::builtins { // 8.2.1 Intl.getCanonicalLocales ( locales ) -JSTaggedValue BuiltinsIntl::GetCanonicalLocales(EcmaRuntimeCallInfo *argv) +JSTaggedValue intl::GetCanonicalLocales(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1.Let ll be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle elements = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/runtime/builtins/builtins_intl.h b/runtime/builtins/builtins_intl.h deleted file mode 100644 index 12ce000f5c6e69d51d80c14893f28cf5d45b2197..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_intl.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_INTL_H -#define ECMASCRIPT_BUILTINS_BUILTINS_INTL_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsIntl : public ecmascript::base::BuiltinsBase { -public: - // 8.2.1 Intl.getCanonicalLocales ( locales ) - static JSTaggedValue GetCanonicalLocales(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_INTL_H diff --git a/runtime/builtins/builtins_iterator.cpp b/runtime/builtins/builtins_iterator.cpp index eb6f02d65c3391e8210fe8eb9e23b8f26ff38746..c2a3d7ce0b10d3538a74d2e55426d5b770ace69d 100644 --- a/runtime/builtins/builtins_iterator.cpp +++ b/runtime/builtins/builtins_iterator.cpp @@ -13,40 +13,35 @@ * limitations under the License. */ -#include "builtins_iterator.h" #include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_iterator.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsIterator::IteratorConstructor([[maybe_unused]] EcmaRuntimeCallInfo *argv) -{ - return JSTaggedValue::Undefined(); -} -JSTaggedValue BuiltinsIterator::Next([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue iterator::proto::Next([[maybe_unused]] EcmaRuntimeCallInfo *argv) { return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsIterator::Throw([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue iterator::proto::Throw([[maybe_unused]] EcmaRuntimeCallInfo *argv) { return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsIterator::Return(EcmaRuntimeCallInfo *argv) +JSTaggedValue iterator::proto::Return(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Iterator, Return); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); JSHandle iter_result = JSIterator::CreateIterResultObject(thread, value, true); return iter_result.GetTaggedValue(); } -JSTaggedValue BuiltinsIterator::GetIteratorObj(EcmaRuntimeCallInfo *argv) +JSTaggedValue iterator::proto::Iterator(EcmaRuntimeCallInfo *argv) { - return ecmascript::base::BuiltinsBase::GetThis(argv).GetTaggedValue(); + return ecmascript::builtins_common::GetThis(argv).GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_iterator.h b/runtime/builtins/builtins_iterator.h deleted file mode 100644 index 1d705b375a3ae80a102e43701c1f76bd2f1e365b..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_iterator.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_ITERATOR_H -#define ECMASCRIPT_BUILTINS_BUILTINS_ITERATOR_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsIterator : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue IteratorConstructor(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue Next(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue Throw(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue Return(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_ITERATOR_H diff --git a/runtime/builtins/builtins_json.cpp b/runtime/builtins/builtins_json.cpp index 597d21364b22e19253a67b89bf728dd5129c8dd0..0b9872e413caa618bec46ef9e5b95873e8e70b3d 100644 --- a/runtime/builtins/builtins_json.cpp +++ b/runtime/builtins/builtins_json.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_json.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/json_parser.h" #include "plugins/ecmascript/runtime/base/json_stringifier.h" #include "plugins/ecmascript/runtime/base/number_helper.h" @@ -26,7 +26,7 @@ namespace panda::ecmascript::builtins { // 24.5.1 -JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) +JSTaggedValue json::Parse(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Json, Parse); ASSERT(argv); @@ -42,7 +42,7 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), JSTaggedValue::Exception()); } - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle parse_string = JSTaggedValue::ToString(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle result; @@ -57,7 +57,7 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) JSTaggedValue reviver = JSTaggedValue::Undefined(); if (argc == 2) { // 2: 2 args - reviver = GetCallArg(argv, 1).GetTaggedValue(); + reviver = builtins_common::GetCallArg(argv, 1).GetTaggedValue(); if (reviver.IsCallable()) { JSHandle callbackfn_handle(thread, reviver); // Let root be ! OrdinaryObjectCreate(%Object.prototype%). @@ -77,7 +77,7 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) } // 24.5.2 -JSTaggedValue BuiltinsJson::Stringify(EcmaRuntimeCallInfo *argv) +JSTaggedValue json::Stringify(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Json, Parse); ASSERT(argv); @@ -85,15 +85,15 @@ JSTaggedValue BuiltinsJson::Stringify(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); - JSTaggedValue value = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue value = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); JSTaggedValue replacer = JSTaggedValue::Undefined(); JSTaggedValue gap = JSTaggedValue::Undefined(); if (argc == 2) { // 2: 2 args - replacer = GetCallArg(argv, 1).GetTaggedValue(); + replacer = builtins_common::GetCallArg(argv, 1).GetTaggedValue(); } else if (argc == 3) { // 3: 3 args - replacer = GetCallArg(argv, 1).GetTaggedValue(); - gap = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD).GetTaggedValue(); + replacer = builtins_common::GetCallArg(argv, 1).GetTaggedValue(); + gap = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD).GetTaggedValue(); } JSHandle handle_value(thread, value); diff --git a/runtime/builtins/builtins_json.h b/runtime/builtins/builtins_json.h deleted file mode 100644 index 6f83003b7c8b845f1cdf10e2b64eaf485f5cbde1..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_json.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_JSON_H -#define ECMASCRIPT_BUILTINS_BUILTINS_JSON_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -using JSTaggedValue = JSTaggedValue; - -class BuiltinsJson : public ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue Parse(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Stringify(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_JSON_H diff --git a/runtime/builtins/builtins_locale.cpp b/runtime/builtins/builtins_locale.cpp index 564b3c73410d0a12fcf6683ae3b8e5c7be1184e4..bf576daeddc2d783540fa56f7a6bba2af5e3f822 100644 --- a/runtime/builtins/builtins_locale.cpp +++ b/runtime/builtins/builtins_locale.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_locale.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -22,7 +22,7 @@ namespace panda::ecmascript::builtins { // 10.1.3 Intl.Locale( tag [, options] ) -JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue locale::LocaleConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -30,19 +30,19 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new_target is undefined", JSTaggedValue::Exception()); } // 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle locale = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. If Type(tag) is not String or Object, throw a TypeError exception. - JSHandle tag = GetCallArg(argv, 0); + JSHandle tag = builtins_common::GetCallArg(argv, 0); if (!tag->IsString() && !tag->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "tag is not String or Object", JSTaggedValue::Exception()); } @@ -62,7 +62,7 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) // a.Let options be ! ObjectCreate(null). // 11. Else // a.Let options be ? ToObject(options). - JSHandle options = GetCallArg(argv, 1); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle options_obj; if (options->IsUndefined()) { options_obj = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); @@ -76,12 +76,13 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::Maximize(EcmaRuntimeCallInfo *argv) +// 10.3.3 Intl.Locale.prototype.maximize () +JSTaggedValue locale::proto::Maximize(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { @@ -107,12 +108,13 @@ JSTaggedValue BuiltinsLocale::Maximize(EcmaRuntimeCallInfo *argv) return obj.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::Minimize(EcmaRuntimeCallInfo *argv) +// 10.3.4 Intl.Locale.prototype.minimize () +JSTaggedValue locale::proto::Minimize(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { @@ -141,12 +143,13 @@ JSTaggedValue BuiltinsLocale::Minimize(EcmaRuntimeCallInfo *argv) return obj.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::ToString(EcmaRuntimeCallInfo *argv) +// 10.3.5 Intl.Locale.prototype.toString () +JSTaggedValue locale::proto::ToString(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -156,12 +159,13 @@ JSTaggedValue BuiltinsLocale::ToString(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetBaseName(EcmaRuntimeCallInfo *argv) +// 10.3.6 get Intl.Locale.prototype.baseName +JSTaggedValue locale::proto::GetBaseName(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -174,12 +178,13 @@ JSTaggedValue BuiltinsLocale::GetBaseName(EcmaRuntimeCallInfo *argv) return base_name.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetCalendar(EcmaRuntimeCallInfo *argv) +// 10.3.7 get Intl.Locale.prototype.calendar +JSTaggedValue locale::proto::GetCalendar(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -190,13 +195,14 @@ JSTaggedValue BuiltinsLocale::GetCalendar(EcmaRuntimeCallInfo *argv) return calendar.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetCaseFirst(EcmaRuntimeCallInfo *argv) +// 10.3.8 get Intl.Locale.prototype.caseFirst +JSTaggedValue locale::proto::GetCaseFirst(EcmaRuntimeCallInfo *argv) { // This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kf". JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -207,12 +213,13 @@ JSTaggedValue BuiltinsLocale::GetCaseFirst(EcmaRuntimeCallInfo *argv) return case_first.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetCollation(EcmaRuntimeCallInfo *argv) +// 10.3.9 get Intl.Locale.prototype.collation +JSTaggedValue locale::proto::GetCollation(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -223,12 +230,13 @@ JSTaggedValue BuiltinsLocale::GetCollation(EcmaRuntimeCallInfo *argv) return collation.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetHourCycle(EcmaRuntimeCallInfo *argv) +// 10.3.10 get Intl.Locale.prototype.hourCycle +JSTaggedValue locale::proto::GetHourCycle(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -239,13 +247,14 @@ JSTaggedValue BuiltinsLocale::GetHourCycle(EcmaRuntimeCallInfo *argv) return hour_cycle.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv) +// 10.3.11 get Intl.Locale.prototype.numeric +JSTaggedValue locale::proto::GetNumeric(EcmaRuntimeCallInfo *argv) { // This property only exists if %Locale%.[[RelevantExtensionKeys]] contains "kn". JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -259,12 +268,13 @@ JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv) return result; } -JSTaggedValue BuiltinsLocale::GetNumberingSystem(EcmaRuntimeCallInfo *argv) +// 10.3.12 get Intl.Locale.prototype.numberingSystem +JSTaggedValue locale::proto::GetNumberingSystem(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -275,13 +285,14 @@ JSTaggedValue BuiltinsLocale::GetNumberingSystem(EcmaRuntimeCallInfo *argv) return numbering_system.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv) +// 10.3.13 get Intl.Locale.prototype.language +JSTaggedValue locale::proto::GetLanguage(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -300,13 +311,14 @@ JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetScript(EcmaRuntimeCallInfo *argv) +// 10.3.14 get Intl.Locale.prototype.script +JSTaggedValue locale::proto::GetScript(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); @@ -328,7 +340,8 @@ JSTaggedValue BuiltinsLocale::GetScript(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv) +// 10.3.15 get Intl.Locale.prototype.region +JSTaggedValue locale::proto::GetRegion(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -336,7 +349,7 @@ JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv) const GlobalEnvConstants *global_const = thread->GlobalConstants(); ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let loc be the this value. - JSHandle loc = GetThis(argv); + JSHandle loc = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). if (!loc->IsJSLocale()) { THROW_TYPE_ERROR_AND_RETURN(thread, "not locale", JSTaggedValue::Exception()); diff --git a/runtime/builtins/builtins_locale.h b/runtime/builtins/builtins_locale.h deleted file mode 100644 index c7b4fd37b9b769f7c232bcd286a64288851cae4a..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_locale.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_LOCALE_H -#define ECMASCRIPT_BUILTINS_BUILTINS_LOCALE_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsLocale : public ecmascript::base::BuiltinsBase { -public: - // 10.1.3 Intl.Locale( tag [, options] ) - static JSTaggedValue LocaleConstructor(EcmaRuntimeCallInfo *argv); - - // 10.3.3 Intl.Locale.prototype.maximize () - static JSTaggedValue Maximize(EcmaRuntimeCallInfo *argv); - // 10.3.4 Intl.Locale.prototype.minimize () - static JSTaggedValue Minimize(EcmaRuntimeCallInfo *argv); - // 10.3.5 Intl.Locale.prototype.toString () - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - - // 10.3.6 get Intl.Locale.prototype.baseName - static JSTaggedValue GetBaseName(EcmaRuntimeCallInfo *argv); - // 10.3.7 get Intl.Locale.prototype.calendar - static JSTaggedValue GetCalendar(EcmaRuntimeCallInfo *argv); - // 10.3.8 get Intl.Locale.prototype.caseFirst - static JSTaggedValue GetCaseFirst(EcmaRuntimeCallInfo *argv); - // 10.3.9 get Intl.Locale.prototype.collation - static JSTaggedValue GetCollation(EcmaRuntimeCallInfo *argv); - // 10.3.10 get Intl.Locale.prototype.hourCycle - static JSTaggedValue GetHourCycle(EcmaRuntimeCallInfo *argv); - // 10.3.11 get Intl.Locale.prototype.numeric - static JSTaggedValue GetNumeric(EcmaRuntimeCallInfo *argv); - // 10.3.12 get Intl.Locale.prototype.numberingSystem - static JSTaggedValue GetNumberingSystem(EcmaRuntimeCallInfo *argv); - // 10.3.13 get Intl.Locale.prototype.language - static JSTaggedValue GetLanguage(EcmaRuntimeCallInfo *argv); - // 10.3.14 get Intl.Locale.prototype.script - static JSTaggedValue GetScript(EcmaRuntimeCallInfo *argv); - // 10.3.15 get Intl.Locale.prototype.region - static JSTaggedValue GetRegion(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_LOCALE_H diff --git a/runtime/builtins/builtins_map.cpp b/runtime/builtins/builtins_map.cpp index 2e31748f917b88141989ad620269ed343edd8fd8..96e1720d68fcc98dcf80d5118743fac607f79fdb 100644 --- a/runtime/builtins/builtins_map.cpp +++ b/runtime/builtins/builtins_map.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_map.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -25,20 +25,21 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) +// 23.1.1.1 +JSTaggedValue map::MapConstructor(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let Map be OrdinaryCreateFromConstructor(NewTarget, "%MapPrototype%", «‍[[MapData]]» ). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -50,7 +51,7 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) // add data into set from iterable // 5.If iterable is not present, let iterable be undefined. // 6.If iterable is either undefined or null, let iter be undefined. - JSHandle iterable = GetCallArg(argv, 0); + JSHandle iterable = builtins_common::GetCallArg(argv, 0); // 8.If iter is undefined, return set if (iterable->IsUndefined() || iterable->IsNull()) { return map.GetTaggedValue(); @@ -69,12 +70,13 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) return result; } -JSTaggedValue BuiltinsMap::Set(EcmaRuntimeCallInfo *argv) +// 23.1.3.9 +JSTaggedValue map::proto::Set(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Set); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. @@ -82,21 +84,22 @@ JSTaggedValue BuiltinsMap::Set(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } - JSHandle key = GetCallArg(argv, 0); - JSHandle value = GetCallArg(argv, 1); + JSHandle key = builtins_common::GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 1); JSHandle map(self); JSMap::Set(thread, map, key, value); return map.GetTaggedValue(); } -JSTaggedValue BuiltinsMap::Clear(EcmaRuntimeCallInfo *argv) +// 23.1.3.1 +JSTaggedValue map::proto::Clear(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Clear); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. @@ -108,12 +111,13 @@ JSTaggedValue BuiltinsMap::Clear(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsMap::Delete(EcmaRuntimeCallInfo *argv) +// 23.1.3.3 +JSTaggedValue map::proto::Delete(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Delete); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { @@ -121,45 +125,47 @@ JSTaggedValue BuiltinsMap::Delete(EcmaRuntimeCallInfo *argv) } JSHandle map(self); - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); bool flag = JSMap::Delete(thread, map, key); - return GetTaggedBoolean(flag); + return builtins_common::GetTaggedBoolean(flag); } -JSTaggedValue BuiltinsMap::Has(EcmaRuntimeCallInfo *argv) +// 23.1.3.7 +JSTaggedValue map::proto::Has(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Has); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } JSHandle js_map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); bool flag = false; if (JSMap::IsKey(key.GetTaggedValue())) { int hash = LinkedHash::Hash(key.GetTaggedValue()); flag = js_map->Has(key.GetTaggedValue(), hash); } - return GetTaggedBoolean(flag); + return builtins_common::GetTaggedBoolean(flag); } -JSTaggedValue BuiltinsMap::Get(EcmaRuntimeCallInfo *argv) +// 23.1.3.6 +JSTaggedValue map::proto::Get(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Get); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSMap", JSTaggedValue::Exception()); } JSHandle js_map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); JSTaggedValue value = JSTaggedValue::Undefined(); if (JSMap::IsKey(key.GetTaggedValue())) { int hash = LinkedHash::Hash(key.GetTaggedValue()); @@ -168,12 +174,13 @@ JSTaggedValue BuiltinsMap::Get(EcmaRuntimeCallInfo *argv) return value; } -JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) +// 23.1.3.5 +JSTaggedValue map::proto::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { @@ -182,12 +189,12 @@ JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSHandle map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); // 4.If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle func(GetCallArg(argv, 0)); + JSHandle func(builtins_common::GetCallArg(argv, 0)); if (!func->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not Callable", JSTaggedValue::Exception()); } // 5.If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg = GetCallArg(argv, 1); + JSHandle this_arg = builtins_common::GetCallArg(argv, 1); // composed arguments JSHandle iter(factory->NewJSMapIterator(map, IterationKind::KEY_AND_VALUE)); @@ -212,17 +219,19 @@ JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsMap::Species([[maybe_unused]] EcmaRuntimeCallInfo *argv) +// 23.1.2.2 +JSTaggedValue map::GetSpecies([[maybe_unused]] EcmaRuntimeCallInfo *argv) { - return GetThis(argv).GetTaggedValue(); + return builtins_common::GetThis(argv).GetTaggedValue(); } -JSTaggedValue BuiltinsMap::GetSize(EcmaRuntimeCallInfo *argv) +// 23.1.3.10 +JSTaggedValue map::proto::GetSize(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, GetSize); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[MapData]] internal slot, throw a TypeError exception. if (!self->IsJSMap()) { @@ -233,32 +242,35 @@ JSTaggedValue BuiltinsMap::GetSize(EcmaRuntimeCallInfo *argv) return JSTaggedValue(count); } -JSTaggedValue BuiltinsMap::Entries(EcmaRuntimeCallInfo *argv) +// 23.1.3.4 +JSTaggedValue map::proto::Entries(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Entries); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::KEY_AND_VALUE); return iter.GetTaggedValue(); } -JSTaggedValue BuiltinsMap::Keys(EcmaRuntimeCallInfo *argv) +// 23.1.3.8 +JSTaggedValue map::proto::Keys(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Keys); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::KEY); return iter.GetTaggedValue(); } -JSTaggedValue BuiltinsMap::Values(EcmaRuntimeCallInfo *argv) +// 23.1.3.11 +JSTaggedValue map::proto::Values(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Values); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::VALUE); return iter.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_map.h b/runtime/builtins/builtins_map.h deleted file mode 100644 index 6c47044e7b79e462173acece240f5adec539a6a1..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_map.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_MAP_H -#define ECMASCRIPT_BUILTINS_BUILTINS_MAP_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsMap : public ecmascript::base::BuiltinsBase { -public: - // 23.1.1.1 - static JSTaggedValue MapConstructor(EcmaRuntimeCallInfo *argv); - // 23.1.2.2 - static JSTaggedValue Species(EcmaRuntimeCallInfo *argv); - // 23.1.3.1 - static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); - // 23.1.3.3 - static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv); - // 23.1.3.4 - static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); - // 23.1.3.5 - static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); - // 23.1.3.6 - static JSTaggedValue Get(EcmaRuntimeCallInfo *argv); - // 23.1.3.7 - static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); - // 23.1.3.8 - static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); - // 23.1.3.9 - static JSTaggedValue Set(EcmaRuntimeCallInfo *argv); - // 23.1.3.10 - static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv); - // 23.1.3.11 - static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_MAP_H diff --git a/runtime/builtins/builtins_math.cpp b/runtime/builtins/builtins_math.cpp index f76318f8f5b3d1ad004852042a0c5f571cd54425..31b3d41e23b36a6ccbb9e693e4112137015bcc7b 100644 --- a/runtime/builtins/builtins_math.cpp +++ b/runtime/builtins/builtins_math.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_math.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include #include #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" @@ -24,31 +24,31 @@ namespace panda::ecmascript::builtins { using NumberHelper = ecmascript::base::NumberHelper; // 20.2.2.1 -JSTaggedValue BuiltinsMath::Abs(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Abs(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Abs); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); if (number_value.IsDouble()) { // if number_value is double,NaN,Undefine, deal in this case // if number_value is a String ,which can change to double. e.g."100",deal in this case - return GetTaggedDouble(std::fabs(number_value.GetDouble())); + return builtins_common::GetTaggedDouble(std::fabs(number_value.GetDouble())); } // if number_value is int,boolean,null, deal in this case - return GetTaggedInt(std::abs(number_value.GetInt())); + return builtins_common::GetTaggedInt(std::abs(number_value.GetInt())); } // 20.2.2.2 -JSTaggedValue BuiltinsMath::Acos(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Acos(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Acos); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -56,51 +56,51 @@ JSTaggedValue BuiltinsMath::Acos(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value)) && value <= 1 && value >= -1) { result = std::acos(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.3 -JSTaggedValue BuiltinsMath::Acosh(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Acosh(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Acosh); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (value >= 1) { result = std::acosh(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.4 -JSTaggedValue BuiltinsMath::Asin(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Asin(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Asin); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (value >= -1 && value <= 1) { result = std::asin(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.5 -JSTaggedValue BuiltinsMath::Asinh(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Asinh(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Asinh); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -108,17 +108,17 @@ JSTaggedValue BuiltinsMath::Asinh(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::asinh(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.6 -JSTaggedValue BuiltinsMath::Atan(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Atan(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atan); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -126,35 +126,35 @@ JSTaggedValue BuiltinsMath::Atan(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::atan(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.7 -JSTaggedValue BuiltinsMath::Atanh(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Atanh(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atanh); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (value >= -1 && value <= 1) { result = std::atanh(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.8 -JSTaggedValue BuiltinsMath::Atan2(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Atan2(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atan2); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg_y = GetCallArg(argv, 0); - JSHandle msg_x = GetCallArg(argv, 1); + JSHandle msg_y = builtins_common::GetCallArg(argv, 0); + JSHandle msg_x = builtins_common::GetCallArg(argv, 1); double result = ecmascript::base::NAN_VALUE; JSTaggedNumber number_value_y = JSTaggedValue::ToNumber(thread, msg_y); JSTaggedNumber number_value_x = JSTaggedValue::ToNumber(thread, msg_x); @@ -172,17 +172,17 @@ JSTaggedValue BuiltinsMath::Atan2(EcmaRuntimeCallInfo *argv) // If either x or y is NaN, the result is NaN result = std::atan2(value_y, value_x); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.9 -JSTaggedValue BuiltinsMath::Cbrt(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Cbrt(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cbrt); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -190,17 +190,17 @@ JSTaggedValue BuiltinsMath::Cbrt(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::cbrt(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.10 -JSTaggedValue BuiltinsMath::Ceil(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Ceil(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Ceil); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -213,37 +213,37 @@ JSTaggedValue BuiltinsMath::Ceil(EcmaRuntimeCallInfo *argv) } else { result = std::ceil(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.11 -JSTaggedValue BuiltinsMath::Clz32(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Clz32(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Clz32); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); constexpr int DEFAULT_VALUE = 32; - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); auto tmp_value = std::abs(value); auto result = number_value.ToUint32(); if (!std::isfinite(tmp_value) || tmp_value == 0 || result == 0) { // If value is NaN or -NaN, +infinite, -infinite, 0,return 32 - return GetTaggedInt(DEFAULT_VALUE); + return builtins_common::GetTaggedInt(DEFAULT_VALUE); } - return GetTaggedInt(__builtin_clz(result)); + return builtins_common::GetTaggedInt(__builtin_clz(result)); } // 20.2.2.12 -JSTaggedValue BuiltinsMath::Cos(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Cos(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cos); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -251,17 +251,17 @@ JSTaggedValue BuiltinsMath::Cos(EcmaRuntimeCallInfo *argv) if (std::isfinite(std::abs(value))) { result = std::cos(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.13 -JSTaggedValue BuiltinsMath::Cosh(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Cosh(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cosh); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -269,17 +269,17 @@ JSTaggedValue BuiltinsMath::Cosh(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::cosh(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.14 -JSTaggedValue BuiltinsMath::Exp(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Exp(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Exp); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -287,17 +287,17 @@ JSTaggedValue BuiltinsMath::Exp(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::exp(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.15 -JSTaggedValue BuiltinsMath::Expm1(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Expm1(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Expm1); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -305,17 +305,17 @@ JSTaggedValue BuiltinsMath::Expm1(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::expm1(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.16 -JSTaggedValue BuiltinsMath::Floor(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Floor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Floor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -331,17 +331,17 @@ JSTaggedValue BuiltinsMath::Floor(EcmaRuntimeCallInfo *argv) } else { result = std::floor(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.17 -JSTaggedValue BuiltinsMath::Fround(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Fround(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Fround); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result; @@ -351,11 +351,11 @@ JSTaggedValue BuiltinsMath::Fround(EcmaRuntimeCallInfo *argv) } else { result = static_cast(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.18 -JSTaggedValue BuiltinsMath::Hypot(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Hypot(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Hypot); @@ -366,46 +366,46 @@ JSTaggedValue BuiltinsMath::Hypot(EcmaRuntimeCallInfo *argv) int arg_len = argv->GetArgsNumber(); auto number_value = JSTaggedNumber(0); for (int i = 0; i < arg_len; i++) { - JSHandle msg = GetCallArg(argv, i); + JSHandle msg = builtins_common::GetCallArg(argv, i); number_value = JSTaggedValue::ToNumber(thread, msg); value = number_value.GetNumber(); result = std::hypot(result, value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.19 -JSTaggedValue BuiltinsMath::Imul(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Imul(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Imul); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg1 = GetCallArg(argv, 0); - JSHandle msg2 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 0); + JSHandle msg2 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber number_value1 = JSTaggedValue::ToNumber(thread, msg1); JSTaggedNumber number_value2 = JSTaggedValue::ToNumber(thread, msg2); auto value1 = number_value1.GetNumber(); auto value2 = number_value2.GetNumber(); if (!std::isfinite(value1) || !std::isfinite(value2)) { // If value is NaN or -NaN, +infinite, -infinite - return GetTaggedInt(0); + return builtins_common::GetTaggedInt(0); } value1 = number_value1.ToInt32(); value2 = number_value2.ToInt32(); // purposely ignoring overflow auto result = static_cast(static_cast(value1) * static_cast(value2)); - return GetTaggedInt(result); + return builtins_common::GetTaggedInt(result); } // 20.2.2.20 -JSTaggedValue BuiltinsMath::Log(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Log(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -413,17 +413,17 @@ JSTaggedValue BuiltinsMath::Log(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value)) && value >= 0) { result = std::log(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.21 -JSTaggedValue BuiltinsMath::Log1p(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Log1p(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log1p); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -431,17 +431,17 @@ JSTaggedValue BuiltinsMath::Log1p(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value)) && value >= -1) { result = std::log1p(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.22 -JSTaggedValue BuiltinsMath::Log10(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Log10(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log10); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -449,17 +449,17 @@ JSTaggedValue BuiltinsMath::Log10(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value)) && value >= 0) { result = std::log10(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.23 -JSTaggedValue BuiltinsMath::Log2(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Log2(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log2); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -467,7 +467,7 @@ JSTaggedValue BuiltinsMath::Log2(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value)) && value >= 0) { result = std::log2(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } inline bool IsNegZero(double value) @@ -477,7 +477,7 @@ inline bool IsNegZero(double value) } // 20.2.2.24 -JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Max(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Max); @@ -490,7 +490,7 @@ JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv) auto tmp_max = -ecmascript::base::POSITIVE_INFINITY; auto value = -ecmascript::base::POSITIVE_INFINITY; for (int i = 0; i < arg_len; i++) { - JSHandle msg = GetCallArg(argv, i); + JSHandle msg = builtins_common::GetCallArg(argv, i); number_value = JSTaggedValue::ToNumber(thread, msg); value = number_value.GetNumber(); if (std::isnan(std::abs(value))) { @@ -511,7 +511,7 @@ JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv) } // 20.2.2.25 -JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Min(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Min); @@ -524,7 +524,7 @@ JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv) auto tmp_min = ecmascript::base::POSITIVE_INFINITY; auto value = ecmascript::base::POSITIVE_INFINITY; for (int i = 0; i < arg_len; i++) { - JSHandle msg = GetCallArg(argv, i); + JSHandle msg = builtins_common::GetCallArg(argv, i); number_value = JSTaggedValue::ToNumber(thread, msg); value = number_value.GetNumber(); if (std::isnan(std::abs(value))) { @@ -545,14 +545,14 @@ JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv) } // 20.2.2.26 -JSTaggedValue BuiltinsMath::Pow(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Pow(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Pow); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg_x = GetCallArg(argv, 0); - JSHandle msg_y = GetCallArg(argv, 1); + JSHandle msg_x = builtins_common::GetCallArg(argv, 0); + JSHandle msg_y = builtins_common::GetCallArg(argv, 1); JSTaggedNumber number_value_x = JSTaggedValue::ToNumber(thread, msg_x); JSTaggedNumber number_value_y = JSTaggedValue::ToNumber(thread, msg_y); double value_x = number_value_x.GetNumber(); @@ -561,24 +561,24 @@ JSTaggedValue BuiltinsMath::Pow(EcmaRuntimeCallInfo *argv) } // 20.2.2.27 -JSTaggedValue BuiltinsMath::Random([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Random([[maybe_unused]] EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Random); // result range [0,1) std::uniform_real_distribution dis(0.0, 1.0); double result = dis(argv->GetThread()->GetEcmaVM()->GetRandomEngine()); - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.28 -JSTaggedValue BuiltinsMath::Round(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Round(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Round); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); auto result = ecmascript::base::NAN_VALUE; @@ -590,54 +590,54 @@ JSTaggedValue BuiltinsMath::Round(EcmaRuntimeCallInfo *argv) // If value is NaN or -NaN, the result is default NaN, else is value result = value; } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // If x is less than 0 but greater than or equal to -0.5, the result is -0 if (value < 0 && value >= -diff) { - return GetTaggedDouble(-0.0); + return builtins_common::GetTaggedDouble(-0.0); } // If x is greater than 0 but less than 0.5, the result is +0 if (value > 0 && value < diff) { - return GetTaggedInt(0); + return builtins_common::GetTaggedInt(0); } // For huge integers result = std::ceil(value); if (result - value > diff) { result -= 1; } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.29 -JSTaggedValue BuiltinsMath::Sign(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Sign(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sign); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); if (std::isnan(std::abs(value))) { - return GetTaggedDouble(std::abs(value)); + return builtins_common::GetTaggedDouble(std::abs(value)); } if (value == 0.0) { - return GetTaggedDouble(value); + return builtins_common::GetTaggedDouble(value); } if (value < 0) { - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } - return GetTaggedInt(1); + return builtins_common::GetTaggedInt(1); } // 20.2.2.30 -JSTaggedValue BuiltinsMath::Sin(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Sin(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sin); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -645,17 +645,17 @@ JSTaggedValue BuiltinsMath::Sin(EcmaRuntimeCallInfo *argv) if (std::isfinite(std::abs(value))) { result = std::sin(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.31 -JSTaggedValue BuiltinsMath::Sinh(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Sinh(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sinh); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -663,17 +663,17 @@ JSTaggedValue BuiltinsMath::Sinh(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value))) { result = std::sinh(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.32 -JSTaggedValue BuiltinsMath::Sqrt(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Sqrt(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sqrt); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -681,17 +681,17 @@ JSTaggedValue BuiltinsMath::Sqrt(EcmaRuntimeCallInfo *argv) if (!std::isnan(std::abs(value)) && value >= 0) { result = std::sqrt(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.33 -JSTaggedValue BuiltinsMath::Tan(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Tan(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Tan); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -699,34 +699,34 @@ JSTaggedValue BuiltinsMath::Tan(EcmaRuntimeCallInfo *argv) if (std::isfinite(value)) { result = std::tan(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.34 -JSTaggedValue BuiltinsMath::Tanh(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Tanh(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Tanh); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (!std::isnan(std::abs(value))) { result = std::tanh(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } // 20.2.2.35 -JSTaggedValue BuiltinsMath::Trunc(EcmaRuntimeCallInfo *argv) +JSTaggedValue math::Trunc(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Trunc); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; @@ -739,6 +739,6 @@ JSTaggedValue BuiltinsMath::Trunc(EcmaRuntimeCallInfo *argv) } else { result = std::trunc(value); } - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_math.h b/runtime/builtins/builtins_math.h deleted file mode 100644 index ea6a53f127342991db7de2fa311a9332b3ef2381..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_math.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_MATH_H -#define ECMASCRIPT_BUILTINS_BUILTINS_MATH_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsMath : public ecmascript::base::BuiltinsBase { -public: - // 20.2.1.1 - static constexpr double E = 2.718281828459045; - // 20.2.1.2 - static constexpr double LN10 = 2.302585092994046; - // 20.2.1.3 - static constexpr double LN2 = 0.6931471805599453; - // 20.2.1.4 - static constexpr double LOG10E = 0.4342944819032518; - // 20.2.1.5 - static constexpr double LOG2E = 1.4426950408889634; - // 20.2.1.6 - static constexpr double PI = 3.141592653589793; - // 20.2.1.7 - static constexpr double SQRT1_2 = 0.7071067811865476; - // 20.2.1.8 - static constexpr double SQRT2 = 1.4142135623730951; - // 20.2.2.1 - static JSTaggedValue Abs(EcmaRuntimeCallInfo *argv); - // 20.2.2.2 - static JSTaggedValue Acos(EcmaRuntimeCallInfo *argv); - // 20.2.2.3 - static JSTaggedValue Acosh(EcmaRuntimeCallInfo *argv); - // 20.2.2.4 - static JSTaggedValue Asin(EcmaRuntimeCallInfo *argv); - // 20.2.2.5 - static JSTaggedValue Asinh(EcmaRuntimeCallInfo *argv); - // 20.2.2.6 - static JSTaggedValue Atan(EcmaRuntimeCallInfo *argv); - // 20.2.2.7 - static JSTaggedValue Atanh(EcmaRuntimeCallInfo *argv); - // 20.2.2.8 - static JSTaggedValue Atan2(EcmaRuntimeCallInfo *argv); - // 20.2.2.9 - static JSTaggedValue Cbrt(EcmaRuntimeCallInfo *argv); - // 20.2.2.10 - static JSTaggedValue Ceil(EcmaRuntimeCallInfo *argv); - // 20.2.2.11 - static JSTaggedValue Clz32(EcmaRuntimeCallInfo *argv); - // 20.2.2.12 - static JSTaggedValue Cos(EcmaRuntimeCallInfo *argv); - // 20.2.2.13 - static JSTaggedValue Cosh(EcmaRuntimeCallInfo *argv); - // 20.2.2.14 - static JSTaggedValue Exp(EcmaRuntimeCallInfo *argv); - // 20.2.2.15 - static JSTaggedValue Expm1(EcmaRuntimeCallInfo *argv); - // 20.2.2.16 - static JSTaggedValue Floor(EcmaRuntimeCallInfo *argv); - // 20.2.2.17 - static JSTaggedValue Fround(EcmaRuntimeCallInfo *argv); - // 20.2.2.18 - static JSTaggedValue Hypot(EcmaRuntimeCallInfo *argv); - // 20.2.2.19 - static JSTaggedValue Imul(EcmaRuntimeCallInfo *argv); - // 20.2.2.20 - static JSTaggedValue Log(EcmaRuntimeCallInfo *argv); - // 20.2.2.21 - static JSTaggedValue Log1p(EcmaRuntimeCallInfo *argv); - // 20.2.2.22 - static JSTaggedValue Log10(EcmaRuntimeCallInfo *argv); - // 20.2.2.23 - static JSTaggedValue Log2(EcmaRuntimeCallInfo *argv); - // 20.2.2.24 - static JSTaggedValue Max(EcmaRuntimeCallInfo *argv); - // 20.2.2.25 - static JSTaggedValue Min(EcmaRuntimeCallInfo *argv); - // 20.2.2.26 - static JSTaggedValue Pow(EcmaRuntimeCallInfo *argv); - // 20.2.2.27 - static JSTaggedValue Random(EcmaRuntimeCallInfo *argv); - // 20.2.2.28 - static JSTaggedValue Round(EcmaRuntimeCallInfo *argv); - // 20.2.2.29 - static JSTaggedValue Sign(EcmaRuntimeCallInfo *argv); - // 20.2.2.30 - static JSTaggedValue Sin(EcmaRuntimeCallInfo *argv); - // 20.2.2.31 - static JSTaggedValue Sinh(EcmaRuntimeCallInfo *argv); - // 20.2.2.32 - static JSTaggedValue Sqrt(EcmaRuntimeCallInfo *argv); - // 20.2.2.33 - static JSTaggedValue Tan(EcmaRuntimeCallInfo *argv); - // 20.2.2.34 - static JSTaggedValue Tanh(EcmaRuntimeCallInfo *argv); - // 20.2.2.35 - static JSTaggedValue Trunc(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_MATH_H diff --git a/runtime/builtins/builtins_number.cpp b/runtime/builtins/builtins_number.cpp index 528ad47c45a36ba3873cbe04148cba8ce7d1d7af..92c0d9581593eedacf577df9f8a738ce4eb2f459 100644 --- a/runtime/builtins/builtins_number.cpp +++ b/runtime/builtins/builtins_number.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_number.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/number_helper.h" #include "plugins/ecmascript/runtime/ecma_macros.h" @@ -30,18 +30,27 @@ namespace panda::ecmascript::builtins { using NumberHelper = ecmascript::base::NumberHelper; -JSTaggedValue BuiltinsNumber::NumberConstructor(EcmaRuntimeCallInfo *argv) +// 18.2.4 +// 20.1.2.12 +static JSTaggedValue ParseFloatStr(const Span &str); +// 18.2.5 +// 20.1.2.13 +static JSTaggedValue ParseIntStr(const Span &str, int32_t radix); +static JSTaggedNumber ThisNumberValue(EcmaRuntimeCallInfo *argv); + +// 20.1.1.1 +JSTaggedValue number::NumberConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); // 1. If no arguments were passed to this function invocation, let n be +0. JSTaggedNumber number_value(0); if (argv->GetArgsNumber() > 0) { // 2. Else, let n be ToNumber(value). - JSHandle number_input = GetCallArg(argv, 0); + JSHandle number_input = builtins_common::GetCallArg(argv, 0); number_value = JSTaggedValue::ToNumber(thread, number_input); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -50,7 +59,7 @@ JSTaggedValue BuiltinsNumber::NumberConstructor(EcmaRuntimeCallInfo *argv) return number_value; } // 5. Let O be OrdinaryCreateFromConstructor(NewTarget, "%NumberPrototype%", «[[NumberData]]» ). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle result = thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor( JSHandle::Cast(constructor), new_target); // 6. ReturnIfAbrupt(O). @@ -62,26 +71,26 @@ JSTaggedValue BuiltinsNumber::NumberConstructor(EcmaRuntimeCallInfo *argv) } // 20.1.2.2 -JSTaggedValue BuiltinsNumber::IsFinite(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::IsFinite(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, IsFinite); - JSTaggedValue msg = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue msg = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); // 1. If Type(number) is not Number, return false // 2. If number is NaN, +infinite, or -infinite, return false if (NumberHelper::IsFinite(msg)) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 20.1.2.3 -JSTaggedValue BuiltinsNumber::IsInteger(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::IsInteger(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, IsInteger); JSThread *thread = argv->GetThread(); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); bool result = false; // 1. If Type(number) is not Number, return false. // 2. If number is NaN, +infinite, or -infinite, return false @@ -94,31 +103,31 @@ JSTaggedValue BuiltinsNumber::IsInteger(EcmaRuntimeCallInfo *argv) // 5. Otherwise, return true. result = (value == number.GetNumber()); } - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 20.1.2.4 -JSTaggedValue BuiltinsNumber::IsNaN(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::IsNaN(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, IsNaN); - JSTaggedValue msg = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue msg = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); // 1. If Type(number) is not Number, return false. // 2. If number is NaN, return true. if (NumberHelper::IsNaN(msg)) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // 3. Otherwise, return false. - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 20.1.2.5 -JSTaggedValue BuiltinsNumber::IsSafeInteger(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::IsSafeInteger(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, IsSafeInteger); JSThread *thread = argv->GetThread(); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); bool result = false; // 1. If Type(number) is not Number, return false. // 2. If number is NaN, +infinite, or -infinite, return false @@ -131,30 +140,30 @@ JSTaggedValue BuiltinsNumber::IsSafeInteger(EcmaRuntimeCallInfo *argv) // 5. If abs(integer) ≤ 253−1, return true. result = (value == number.GetNumber()) && std::abs(value) <= ecmascript::base::MAX_SAFE_INTEGER; } - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 18.2.4 // 20.1.2.12 -JSTaggedValue BuiltinsNumber::ParseFloatStr(const Span &str) +JSTaggedValue ParseFloatStr(const Span &str) { // 4. If neither trimmedString nor any prefix of trimmedString satisfies the syntax of a StrDecimalLiteral // (see 7.1.3.1), return NaN. if (NumberHelper::IsEmptyString(str.begin(), str.end())) { - return BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + return builtins_common::GetTaggedDouble(base::NAN_VALUE); } double result = NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::IGNORE_TRAILING); - return GetTaggedDouble(result); + return builtins_common::GetTaggedDouble(result); } -JSTaggedValue BuiltinsNumber::ParseFloat(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::number::ParseFloat(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ParseFloat); JSThread *thread = argv->GetThread(); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); if (msg->IsUndefined()) { - return GetTaggedDouble(ecmascript::base::NAN_VALUE); + return builtins_common::GetTaggedDouble(ecmascript::base::NAN_VALUE); } [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let inputString be ToString(string). @@ -177,19 +186,19 @@ JSTaggedValue BuiltinsNumber::ParseFloat(EcmaRuntimeCallInfo *argv) // 18.2.5 // 20.1.2.13 -JSTaggedValue BuiltinsNumber::ParseIntStr(const Span &str, int32_t radix) +JSTaggedValue ParseIntStr(const Span &str, int32_t radix) { return NumberHelper::StringToDoubleWithRadix(str.begin(), str.end(), radix); } -JSTaggedValue BuiltinsNumber::ParseInt(EcmaRuntimeCallInfo *argv) +JSTaggedValue builtins::number::ParseInt(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ParseInt); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); - JSHandle arg2 = GetCallArg(argv, 1); + JSHandle msg = builtins_common::GetCallArg(argv, 0); + JSHandle arg2 = builtins_common::GetCallArg(argv, 1); int32_t radix = 0; if (!arg2->IsUndefined()) { @@ -216,7 +225,7 @@ JSTaggedValue BuiltinsNumber::ParseInt(EcmaRuntimeCallInfo *argv) // prototype // 20.1.3.2 -JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::proto::ToExponential(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToExponential); @@ -228,7 +237,7 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let f be ToInteger(fractionDigits). - JSHandle digits = GetCallArg(argv, 0); + JSHandle digits = builtins_common::GetCallArg(argv, 0); JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digits); // 5. ReturnIfAbrupt(f). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -236,7 +245,7 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) double values = value.GetNumber(); // 6. If x is NaN, return the String "NaN". if (std::isnan(values)) { - return GetTaggedString(thread, "NaN"); + return builtins_common::GetTaggedString(thread, "NaN"); } // 8. If x < 0, then // a. Let s be "-". @@ -245,9 +254,9 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) // a. Return the concatenation of the Strings s and "Infinity". if (!std::isfinite(values)) { if (values < 0) { - return GetTaggedString(thread, "-Infinity"); + return builtins_common::GetTaggedString(thread, "-Infinity"); } - return GetTaggedString(thread, "Infinity"); + return builtins_common::GetTaggedString(thread, "Infinity"); } // 4. Assert: f is 0, when fractionDigits is undefined. @@ -264,7 +273,7 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) } // 20.1.3.3 -JSTaggedValue BuiltinsNumber::ToFixed(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::proto::ToFixed(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToFixed); @@ -275,7 +284,7 @@ JSTaggedValue BuiltinsNumber::ToFixed(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(x). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let f be ToInteger(fractionDigits). (If fractionDigits is undefined, this step produces the value 0). - JSHandle digit_argv = GetCallArg(argv, 0); + JSHandle digit_argv = builtins_common::GetCallArg(argv, 0); JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digit_argv); if (digit_argv->IsUndefined()) { digit_int = JSTaggedNumber(0); @@ -291,7 +300,7 @@ JSTaggedValue BuiltinsNumber::ToFixed(EcmaRuntimeCallInfo *argv) // 6. If x is NaN, return the String "NaN". double value_number = value.GetNumber(); if (std::isnan(value_number)) { - return GetTaggedString(thread, "NaN"); + return builtins_common::GetTaggedString(thread, "NaN"); } // 9. If x  1021, then // a. Let m = ToString(x). @@ -304,7 +313,7 @@ JSTaggedValue BuiltinsNumber::ToFixed(EcmaRuntimeCallInfo *argv) } // 20.1.3.4 -JSTaggedValue BuiltinsNumber::ToLocaleString(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -318,8 +327,8 @@ JSTaggedValue BuiltinsNumber::ToLocaleString(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); JSHandle number_format = JSHandle::Cast(obj); - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -330,7 +339,7 @@ JSTaggedValue BuiltinsNumber::ToLocaleString(EcmaRuntimeCallInfo *argv) } // 20.1.3.5 -JSTaggedValue BuiltinsNumber::ToPrecision(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::proto::ToPrecision(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToPrecision); @@ -342,7 +351,7 @@ JSTaggedValue BuiltinsNumber::ToPrecision(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If precision is undefined, return ToString(x). - JSHandle digit_argv = GetCallArg(argv, 0); + JSHandle digit_argv = builtins_common::GetCallArg(argv, 0); if (digit_argv->IsUndefined()) { return value.ToString(thread).GetTaggedValue(); } @@ -354,15 +363,15 @@ JSTaggedValue BuiltinsNumber::ToPrecision(EcmaRuntimeCallInfo *argv) // 6. If x is NaN, return the String "NaN". double value_number = value.GetNumber(); if (std::isnan(value_number)) { - return GetTaggedString(thread, "NaN"); + return builtins_common::GetTaggedString(thread, "NaN"); } // 9. If x = +infinity, then // a. Return the String that is the concatenation of s and "Infinity". if (!std::isfinite(value_number)) { if (value_number < 0) { - return GetTaggedString(thread, "-Infinity"); + return builtins_common::GetTaggedString(thread, "-Infinity"); } - return GetTaggedString(thread, "Infinity"); + return builtins_common::GetTaggedString(thread, "Infinity"); } // If p < 1 or p > 21, throw a RangeError exception @@ -374,7 +383,7 @@ JSTaggedValue BuiltinsNumber::ToPrecision(EcmaRuntimeCallInfo *argv) } // 20.1.3.6 -JSTaggedValue BuiltinsNumber::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToString); @@ -388,7 +397,7 @@ JSTaggedValue BuiltinsNumber::ToString(EcmaRuntimeCallInfo *argv) // 3. If radix is not present, let radixNumber be 10. // 4. Else if radix is undefined, let radixNumber be 10. double radix = ecmascript::base::DECIMAL; - JSHandle radix_value = GetCallArg(argv, 0); + JSHandle radix_value = builtins_common::GetCallArg(argv, 0); // 5. Else let radixNumber be ToInteger(radix). if (!radix_value->IsUndefined()) { JSTaggedNumber radix_number = JSTaggedValue::ToInteger(thread, radix_value); @@ -409,21 +418,21 @@ JSTaggedValue BuiltinsNumber::ToString(EcmaRuntimeCallInfo *argv) double value_number = value.GetNumber(); // If x is NaN, return the String "NaN". if (std::isnan(value_number)) { - return GetTaggedString(thread, "NaN"); + return builtins_common::GetTaggedString(thread, "NaN"); } // If x = +infinity, then // Return the String that is the concatenation of s and "Infinity". if (!std::isfinite(value_number)) { if (value_number < 0) { - return GetTaggedString(thread, "-Infinity"); + return builtins_common::GetTaggedString(thread, "-Infinity"); } - return GetTaggedString(thread, "Infinity"); + return builtins_common::GetTaggedString(thread, "Infinity"); } return NumberHelper::DoubleToString(thread, value_number, static_cast(radix)); } // 20.1.3.7 -JSTaggedValue BuiltinsNumber::ValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue number::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ValueOf); @@ -434,10 +443,10 @@ JSTaggedValue BuiltinsNumber::ValueOf(EcmaRuntimeCallInfo *argv) return x; } -JSTaggedNumber BuiltinsNumber::ThisNumberValue(EcmaRuntimeCallInfo *argv) +JSTaggedNumber ThisNumberValue(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Number, ThisNumberValue); - JSHandle value = GetThis(argv); + JSHandle value = builtins_common::GetThis(argv); if (value->IsNumber()) { return JSTaggedNumber(value.GetTaggedValue()); } diff --git a/runtime/builtins/builtins_number.h b/runtime/builtins/builtins_number.h deleted file mode 100644 index 40d30e5c1ace6acfd7a46753b647f70b57033a3b..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_number.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_NUMBER_H -#define ECMASCRIPT_BUILTINS_BUILTINS_NUMBER_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_tagged_value.h" - -namespace panda::ecmascript::builtins { -class BuiltinsNumber : public ecmascript::base::BuiltinsBase { -public: - // 20.1.1.1 - static JSTaggedValue NumberConstructor(EcmaRuntimeCallInfo *argv); - - // 20.1.2.2 - static JSTaggedValue IsFinite(EcmaRuntimeCallInfo *argv); - // 20.1.2.3 - static JSTaggedValue IsInteger(EcmaRuntimeCallInfo *argv); - // 20.1.2.4 - static JSTaggedValue IsNaN(EcmaRuntimeCallInfo *argv); - // 20.1.2.5 - static JSTaggedValue IsSafeInteger(EcmaRuntimeCallInfo *argv); - // 20.1.2.12 - static JSTaggedValue ParseFloat(EcmaRuntimeCallInfo *argv); - // 20.1.2.13 - static JSTaggedValue ParseInt(EcmaRuntimeCallInfo *argv); - - // prototype - // 20.1.3.2 - static JSTaggedValue ToExponential(EcmaRuntimeCallInfo *argv); - // 20.1.3.3 - static JSTaggedValue ToFixed(EcmaRuntimeCallInfo *argv); - // 20.1.3.4 - static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); - // 20.1.3.5 - static JSTaggedValue ToPrecision(EcmaRuntimeCallInfo *argv); - // 20.1.3.6 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 20.1.3.7 - static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); - -private: - static JSTaggedValue ParseFloatStr(const Span &str); - static JSTaggedValue ParseIntStr(const Span &str, int32_t radix); - static JSTaggedNumber ThisNumberValue(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_NUBMER_H diff --git a/runtime/builtins/builtins_number_format.cpp b/runtime/builtins/builtins_number_format.cpp index 92692ffe4c050d855dff7f123b2b451d63080f38..d4a3eb5c6f0d6d45f65475f173b489523f1dd66f 100644 --- a/runtime/builtins/builtins_number_format.cpp +++ b/runtime/builtins/builtins_number_format.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_number_format.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_array.h" @@ -24,8 +24,11 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { + +static JSTaggedValue NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv); + // 13.2.1 Intl.NumberFormat ( [ locales [ , options ] ] ) -JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue number_format::NumberFormatConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -34,8 +37,8 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. - JSHandle constructor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { new_target = constructor; } @@ -50,13 +53,13 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %NumberFormat%) is true, // then @@ -78,7 +81,7 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo } // 13.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] ) -JSTaggedValue BuiltinsNumberFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue number_format::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -86,25 +89,25 @@ JSTaggedValue BuiltinsNumberFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv JSHandle available_locales = JSNumberFormat::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). - JSHandle options = GetCallArg(argv, 1); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } // 13.4.3 get Intl.NumberFormat.prototype.format -JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) +JSTaggedValue number_format::proto::GetFormat(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(nf) is not Object, throw a TypeError exception. if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception()); @@ -124,8 +127,8 @@ JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) // c. Set nf.[[BoundFormat]] to F. if (bound_func->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intl_bound_func = factory->NewJSIntlBoundFunction( - reinterpret_cast(BuiltinsNumberFormat::NumberFormatInternalFormatNumber)); + JSHandle intl_bound_func = + factory->NewJSIntlBoundFunction(reinterpret_cast(NumberFormatInternalFormatNumber)); intl_bound_func->SetNumberFormat(thread, typped_nf); typped_nf->SetBoundFormat(thread, intl_bound_func); } @@ -133,18 +136,18 @@ JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) } // 13.4.4 Intl.NumberFormat.prototype.formatToParts ( date ) -JSTaggedValue BuiltinsNumberFormat::FormatToParts(EcmaRuntimeCallInfo *argv) +JSTaggedValue number_format::proto::FormatToParts(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be the this value. - JSHandle nf = GetThis(argv); + JSHandle nf = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]). if (!nf->IsJSNumberFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "", JSTaggedValue::Exception()); } // 3. Let x be ? ToNumeric(value). - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); JSTaggedNumber x = JSTaggedValue::ToNumber(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -154,12 +157,12 @@ JSTaggedValue BuiltinsNumberFormat::FormatToParts(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } // 13.4.5 Intl.NumberFormat.prototype.resolvedOptions () -JSTaggedValue BuiltinsNumberFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) +JSTaggedValue number_format::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(nf) is not Object, throw a TypeError exception. if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); @@ -183,18 +186,19 @@ JSTaggedValue BuiltinsNumberFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) return options.GetTaggedValue(); } -JSTaggedValue BuiltinsNumberFormat::NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv) +JSTaggedValue NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle intl_bound_func = JSHandle::Cast(GetConstructor(argv)); + JSHandle intl_bound_func = + JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let nf be F.[[NumberFormat]]. JSHandle nf(thread, intl_bound_func->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 value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); // 4 Let x be ? ToNumeric(value). JSTaggedNumber x = JSTaggedValue::ToNumber(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/runtime/builtins/builtins_number_format.h b/runtime/builtins/builtins_number_format.h deleted file mode 100644 index c8ea65754fce796a5a0612a5865a425422b7ea11..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_number_format.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_NUMBER_FORMAT_H -#define ECMASCRIPT_BUILTINS_BUILTINS_NUMBER_FORMAT_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsNumberFormat : public ecmascript::base::BuiltinsBase { -public: - // 13.2.1 Intl.DateTimeFormat ( [ locales [ , options ] ] ) - static JSTaggedValue NumberFormatConstructor(EcmaRuntimeCallInfo *argv); - - // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) - static JSTaggedValue SupportedLocalesOf(EcmaRuntimeCallInfo *argv); - - // 13.4.3 get Intl.DateTimeFormat.prototype.format - static JSTaggedValue Format(EcmaRuntimeCallInfo *argv); - - // 13.4.4 Intl.DateTimeFormat.prototype.formatToParts ( date ) - static JSTaggedValue FormatToParts(EcmaRuntimeCallInfo *argv); - - // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () - static JSTaggedValue ResolvedOptions(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_NUMBER_FORMAT_H diff --git a/runtime/builtins/builtins_object.cpp b/runtime/builtins/builtins_object.cpp index d8da9324a4ac3a9d1e0dcacadb3f1c53582d90cd..7ce19a230f6c9f49f03e557ccebad03907b9c6af 100644 --- a/runtime/builtins/builtins_object.cpp +++ b/runtime/builtins/builtins_object.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_object.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/object_helper.h" #include "plugins/ecmascript/runtime/builtins.h" #include "plugins/ecmascript/runtime/ecma_macros.h" @@ -28,8 +28,18 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { + +enum class KeyType : uint8_t { + STRING_TYPE = 0, + SYMBOL_TYPE, +}; + +JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandle &obj, + const JSHandle &prop); +JSTaggedValue GetOwnPropertyKeys(JSThread *thread, const JSHandle &obj, const KeyType &type); +JSTaggedValue GetBuiltinTag(JSThread *thread, const JSHandle &object); // 19.1.1.1 Object ( [ value ] ) -JSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::ObjectConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Constructor); @@ -40,8 +50,8 @@ JSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv) // 1.If NewTarget is neither undefined nor the active function, then // a.Return OrdinaryCreateFromConstructor(NewTarget, "%ObjectPrototype%"). - JSHandle constructor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (!new_target->IsUndefined() && !(new_target.GetTaggedValue() == constructor.GetTaggedValue())) { JSHandle obj = ecma_vm->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), new_target); @@ -49,7 +59,7 @@ JSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv) } // 2.If value is null, undefined or not supplied, return ObjectCreate(%ObjectPrototype%). - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); if (value->IsNull() || value->IsUndefined()) { JSHandle obj = ecma_vm->GetFactory()->OrdinaryNewJSObjectCreate(env->GetObjectFunctionPrototype()); return obj.GetTaggedValue(); @@ -60,7 +70,7 @@ JSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv) } // 19.1.2.1 Object.assign ( target, ...sources ) -JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Assign(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Assign); @@ -69,7 +79,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) uint32_t num_args = argv->GetArgsNumber(); // 1.Let to be ToObject(target). - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); JSHandle to_assign = JSTaggedValue::ToObject(thread, target); // 2.ReturnIfAbrupt(to). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -85,7 +95,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (uint32_t i = 1; i < num_args; i++) { - JSHandle source = GetCallArg(argv, i); + JSHandle source = builtins_common::GetCallArg(argv, i); if (!source->IsNull() && !source->IsUndefined()) { JSHandle from = JSTaggedValue::ToObject(thread, source); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -128,8 +138,8 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) } // Runtime Semantics -JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSHandle &obj, - const JSHandle &prop) +JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandle &obj, + const JSHandle &prop) { BUILTINS_API_TRACE(thread, Object, DefineProperties); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -205,20 +215,20 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH } // 19.1.2.2 Object.create ( O [ , Properties ] ) -JSTaggedValue BuiltinsObject::Create(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Create(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Create); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(O) is neither Object nor Null, throw a TypeError exception. - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject() && !obj->IsNull()) { // throw a TypeError exception THROW_TYPE_ERROR_AND_RETURN(thread, "Create: O is neither Object nor Null", JSTaggedValue::Exception()); } - JSHandle properties = GetCallArg(argv, 1); + JSHandle properties = builtins_common::GetCallArg(argv, 1); // 2.Let obj be ObjectCreate(O). JSHandle obj_create = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(obj); @@ -234,18 +244,18 @@ JSTaggedValue BuiltinsObject::Create(EcmaRuntimeCallInfo *argv) } // 19.1.2.3 Object.defineProperties ( O, Properties ) -JSTaggedValue BuiltinsObject::DefineProperties(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::DefineProperties(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineProperties); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Return ObjectDefineProperties(O, Properties). - return ObjectDefineProperties(thread, GetCallArg(argv, 0), GetCallArg(argv, 1)); + return ObjectDefineProperties(thread, builtins_common::GetCallArg(argv, 0), builtins_common::GetCallArg(argv, 1)); } // 19.1.2.4 Object.defineProperty ( O, P, Attributes ) -JSTaggedValue BuiltinsObject::DefineProperty(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::DefineProperty(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineProperty); @@ -253,21 +263,22 @@ JSTaggedValue BuiltinsObject::DefineProperty(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(O) is not Object, throw a TypeError exception. - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject()) { // throw a TypeError THROW_TYPE_ERROR_AND_RETURN(thread, "DefineProperty: O is not Object", JSTaggedValue::Exception()); } // 2.Let key be ToPropertyKey(P). - JSHandle prop = GetCallArg(argv, 1); + JSHandle prop = builtins_common::GetCallArg(argv, 1); JSHandle key = JSTaggedValue::ToPropertyKey(thread, prop); // 3.ReturnIfAbrupt(key). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.Let desc be ToPropertyDescriptor(Attributes). PropertyDescriptor desc(thread); - JSObject::ToPropertyDescriptor(thread, GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD), desc); + JSObject::ToPropertyDescriptor(thread, builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD), + desc); // 5.ReturnIfAbrupt(desc). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -282,13 +293,13 @@ JSTaggedValue BuiltinsObject::DefineProperty(EcmaRuntimeCallInfo *argv) } // 19.1.2.5 Object.freeze ( O ) -JSTaggedValue BuiltinsObject::Freeze(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Freeze(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Freeze); // 1.If Type(O) is not Object, return O. - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject()) { return obj.GetTaggedValue(); } @@ -313,7 +324,7 @@ JSTaggedValue BuiltinsObject::Freeze(EcmaRuntimeCallInfo *argv) } // ES2021 20.1.2.7 Object.fromEntries ( iterable ) -JSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::FromEntries(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, SetPrototypeOf); @@ -321,7 +332,7 @@ JSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Perform ? RequireObjectCoercible(iterable). - JSHandle iterable = GetCallArg(argv, 0); + JSHandle iterable = builtins_common::GetCallArg(argv, 0); JSTaggedValue::RequireObjectCoercible(thread, iterable); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -355,22 +366,22 @@ JSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv) } // 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) -JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptor(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::GetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDesciptor); + BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let obj be ToObject(O). - JSHandle func = GetCallArg(argv, 0); + JSHandle func = builtins_common::GetCallArg(argv, 0); JSHandle handle = JSTaggedValue::ToObject(thread, func); // 2.ReturnIfAbrupt(obj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3.Let key be ToPropertyKey(P). - JSHandle prop = GetCallArg(argv, 1); + JSHandle prop = builtins_common::GetCallArg(argv, 1); JSHandle key = JSTaggedValue::ToPropertyKey(thread, prop); // 4.ReturnIfAbrupt(key). @@ -389,15 +400,15 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptor(EcmaRuntimeCallInfo *argv) } // ES2021 20.1.2.9 Object.getOwnPropertyDescriptors ( O ) -JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptors(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::GetOwnPropertyDescriptors(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDesciptor); + BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). - JSHandle func = GetCallArg(argv, 0); + JSHandle func = builtins_common::GetCallArg(argv, 0); JSHandle obj = JSTaggedValue::ToObject(thread, func); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -433,8 +444,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptors(EcmaRuntimeCallInfo *argv } // Runtime Semantics -JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandle &object, - const KeyType &type) +JSTaggedValue GetOwnPropertyKeys(JSThread *thread, const JSHandle &object, const KeyType &type) { BUILTINS_API_TRACE(thread, Object, GetOwnPropertyKeys); // 1.Let obj be ToObject(O). @@ -489,12 +499,12 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl } // 19.1.2.7 Object.getOwnPropertyNames ( O ) -JSTaggedValue BuiltinsObject::GetOwnPropertyNames(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::GetOwnPropertyNames(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyNames); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); KeyType type = KeyType::STRING_TYPE; // 1.Return GetOwnPropertyKeys(O, String). @@ -502,12 +512,12 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyNames(EcmaRuntimeCallInfo *argv) } // 19.1.2.8 Object.getOwnPropertySymbols ( O ) -JSTaggedValue BuiltinsObject::GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertySymbols); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); KeyType type = KeyType::SYMBOL_TYPE; // 1.Return GetOwnPropertyKeys(O, Symbol). @@ -515,7 +525,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv) } // 19.1.2.9 Object.getPrototypeOf ( O ) -JSTaggedValue BuiltinsObject::GetPrototypeOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::GetPrototypeOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetPrototypeOf); @@ -523,7 +533,7 @@ JSTaggedValue BuiltinsObject::GetPrototypeOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let obj be ToObject(O). - JSHandle func = GetCallArg(argv, 0); + JSHandle func = builtins_common::GetCallArg(argv, 0); JSHandle obj = JSTaggedValue::ToObject(thread, func); @@ -535,39 +545,39 @@ JSTaggedValue BuiltinsObject::GetPrototypeOf(EcmaRuntimeCallInfo *argv) } // 19.1.2.10 Object.is ( value1, value2 ) -JSTaggedValue BuiltinsObject::Is(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Is(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Is); // 1.Return SameValue(value1, value2). - bool result = JSTaggedValue::SameValue(GetCallArg(argv, 0), GetCallArg(argv, 1)); - return GetTaggedBoolean(result); + bool result = JSTaggedValue::SameValue(builtins_common::GetCallArg(argv, 0), builtins_common::GetCallArg(argv, 1)); + return builtins_common::GetTaggedBoolean(result); } // 19.1.2.11 Object.isExtensible ( O ) -JSTaggedValue BuiltinsObject::IsExtensible(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::IsExtensible(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); // 1.If Type(O) is not Object, return false. - JSTaggedValue obj = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue obj = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); if (!obj.IsObject()) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2.Return IsExtensible(O). - return GetTaggedBoolean(obj.IsExtensible(thread)); + return builtins_common::GetTaggedBoolean(obj.IsExtensible(thread)); } // 19.1.2.12 Object.isFrozen ( O ) -JSTaggedValue BuiltinsObject::IsFrozen(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::IsFrozen(EcmaRuntimeCallInfo *argv) { ASSERT(argv); // 1.If Type(O) is not Object, return true. - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject()) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } JSThread *thread = argv->GetThread(); @@ -575,18 +585,18 @@ JSTaggedValue BuiltinsObject::IsFrozen(EcmaRuntimeCallInfo *argv) // 2.Return TestIntegrityLevel(O, "frozen"). bool status = JSObject::TestIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::FROZEN); - return GetTaggedBoolean(status); + return builtins_common::GetTaggedBoolean(status); } // 19.1.2.13 Object.isSealed ( O ) -JSTaggedValue BuiltinsObject::IsSealed(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::IsSealed(EcmaRuntimeCallInfo *argv) { ASSERT(argv); // 1.If Type(O) is not Object, return true. - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject()) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } JSThread *thread = argv->GetThread(); @@ -594,11 +604,11 @@ JSTaggedValue BuiltinsObject::IsSealed(EcmaRuntimeCallInfo *argv) // 2.Return TestIntegrityLevel(O, "sealed"). bool status = JSObject::TestIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::SEALED); - return GetTaggedBoolean(status); + return builtins_common::GetTaggedBoolean(status); } // 19.1.2.14 Object.keys(O) -JSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Keys(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Keys); @@ -606,7 +616,7 @@ JSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle obj = JSTaggedValue::ToObject(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -622,12 +632,12 @@ JSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv) } // 19.1.2.15 Object.preventExtensions(O) -JSTaggedValue BuiltinsObject::PreventExtensions(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::PreventExtensions(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, PreventExtensions); // 1. If Type(O) is not Object, return O. - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); if (!obj->IsECMAObject()) { return obj.GetTaggedValue(); } @@ -651,13 +661,13 @@ JSTaggedValue BuiltinsObject::PreventExtensions(EcmaRuntimeCallInfo *argv) // 19.1.2.16 Object.prototype // 19.1.2.17 Object.seal(O) -JSTaggedValue BuiltinsObject::Seal(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Seal(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Seal); // 1. If Type(O) is not Object, return O. - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); if (!msg->IsECMAObject()) { return msg.GetTaggedValue(); } @@ -683,20 +693,21 @@ JSTaggedValue BuiltinsObject::Seal(EcmaRuntimeCallInfo *argv) } // 19.1.2.18 Object.setPrototypeOf(O, proto) -JSTaggedValue BuiltinsObject::SetPrototypeOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::SetPrototypeOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, SetPrototypeOf); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(O). - JSHandle object = JSTaggedValue::RequireObjectCoercible(thread, GetCallArg(argv, 0)); + JSHandle object = + JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetCallArg(argv, 0)); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If Type(proto) is neither Object nor Null, throw a TypeError exception. - JSHandle proto = GetCallArg(argv, 1); + JSHandle proto = builtins_common::GetCallArg(argv, 1); if (!proto->IsNull() && !proto->IsECMAObject()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "SetPrototypeOf: proto is neither Object nor Null", @@ -727,44 +738,44 @@ JSTaggedValue BuiltinsObject::SetPrototypeOf(EcmaRuntimeCallInfo *argv) // 19.1.3.1 Object.prototype.constructor // 19.1.3.2 Object.prototype.hasOwnProperty(V) -JSTaggedValue BuiltinsObject::HasOwnProperty(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::HasOwnProperty(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, HasOwnProperty); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let P be ToPropertyKey(V). - JSHandle prop = GetCallArg(argv, 0); + JSHandle prop = builtins_common::GetCallArg(argv, 0); JSHandle property = JSTaggedValue::ToPropertyKey(thread, prop); // 2. ReturnIfAbrupt(P). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let O be ToObject(this value). - JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 4. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return HasOwnProperty(O, P). bool res = JSTaggedValue::HasOwnProperty(thread, JSHandle::Cast(object), property); - return GetTaggedBoolean(res); + return builtins_common::GetTaggedBoolean(res); } // 19.1.3.3 Object.prototype.isPrototypeOf(V) -JSTaggedValue BuiltinsObject::IsPrototypeOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::IsPrototypeOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, IsPrototypeOf); JSThread *thread = argv->GetThread(); // 1. If Type(V) is not Object, return false. - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); if (!msg->IsECMAObject()) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2. Let O be ToObject(this value). - JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 3. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -775,28 +786,28 @@ JSTaggedValue BuiltinsObject::IsPrototypeOf(EcmaRuntimeCallInfo *argv) JSTaggedValue msg_value = msg.GetTaggedValue(); while (!msg_value.IsNull()) { if (JSTaggedValue::SameValue(object.GetTaggedValue(), msg_value)) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } msg_value = JSObject::Cast(msg_value)->GetPrototype(thread); } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 19.1.3.4 Object.prototype.propertyIsEnumerable(V) -JSTaggedValue BuiltinsObject::PropertyIsEnumerable(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::PropertyIsEnumerable(EcmaRuntimeCallInfo *argv) { ASSERT(argv); // 1. Let P be ToPropertyKey(V). JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle msg = GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle property = JSTaggedValue::ToPropertyKey(thread, msg); // 2. ReturnIfAbrupt(P). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let O be ToObject(this value). - JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 4. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -809,22 +820,22 @@ JSTaggedValue BuiltinsObject::PropertyIsEnumerable(EcmaRuntimeCallInfo *argv) // 7. If desc is undefined, return false. if (desc.IsEmpty()) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 8. Return the value of desc.[[Enumerable]]. - return GetTaggedBoolean(desc.IsEnumerable()); + return builtins_common::GetTaggedBoolean(desc.IsEnumerable()); } // 19.1.3.5 Object.prototype.toLocaleString([reserved1[, reserved2]]) -JSTaggedValue BuiltinsObject::ToLocaleString(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToLocaleString); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle object = GetThis(argv); + JSHandle object = builtins_common::GetThis(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); // 2. Return Invoke(O, "toString"). @@ -839,7 +850,7 @@ JSTaggedValue BuiltinsObject::ToLocaleString(EcmaRuntimeCallInfo *argv) return JSFunction::Invoke(info.Get(), callee_key); } -JSTaggedValue BuiltinsObject::GetBuiltinTag(JSThread *thread, const JSHandle &object) +JSTaggedValue GetBuiltinTag(JSThread *thread, const JSHandle &object) { BUILTINS_API_TRACE(thread, Object, GetBuiltinTag); // 4. Let isArray be IsArray(O). @@ -880,7 +891,7 @@ JSTaggedValue BuiltinsObject::GetBuiltinTag(JSThread *thread, const JSHandleGetThread(), Object, ToString); @@ -888,17 +899,17 @@ JSTaggedValue BuiltinsObject::ToString(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If the this value is undefined, return "[object Undefined]". - JSHandle msg = GetThis(argv); + JSHandle msg = builtins_common::GetThis(argv); if (msg->IsUndefined()) { - return GetTaggedString(thread, "[object Undefined]"); + return builtins_common::GetTaggedString(thread, "[object Undefined]"); } // 2. If the this value is null, return "[object Null]". if (msg->IsNull()) { - return GetTaggedString(thread, "[object Null]"); + return builtins_common::GetTaggedString(thread, "[object Null]"); } // 3. Let O be ToObject(this value). - JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle builtin_tag(thread, GetBuiltinTag(thread, object)); @@ -928,7 +939,7 @@ JSTaggedValue BuiltinsObject::ToString(EcmaRuntimeCallInfo *argv) } // 19.1.3.7 Object.prototype.valueOf() -JSTaggedValue BuiltinsObject::ValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ValueOf); @@ -936,12 +947,12 @@ JSTaggedValue BuiltinsObject::ValueOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Return ToObject(this value). - JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle object = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return object.GetTaggedValue(); } // B.2.2.1 Object.prototype.__proto__ -JSTaggedValue BuiltinsObject::ProtoGetter(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::Get__proto__(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ProtoGetter); @@ -949,7 +960,7 @@ JSTaggedValue BuiltinsObject::ProtoGetter(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let obj be ToObject(this value). - JSHandle obj = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle obj = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); // 2.ReturnIfAbrupt(obj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -958,20 +969,20 @@ JSTaggedValue BuiltinsObject::ProtoGetter(EcmaRuntimeCallInfo *argv) return obj->GetPrototype(thread); } -JSTaggedValue BuiltinsObject::ProtoSetter(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::Set__proto__(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ProtoSetter); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(this value). - JSHandle obj = JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)); + JSHandle obj = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If Type(proto) is neither Object nor Null, return undefined.. - JSHandle proto = GetCallArg(argv, 0); + JSHandle proto = builtins_common::GetCallArg(argv, 0); if (!proto->IsNull() && !proto->IsECMAObject()) { return JSTaggedValue::Undefined(); } @@ -998,7 +1009,7 @@ JSTaggedValue BuiltinsObject::ProtoSetter(EcmaRuntimeCallInfo *argv) } // B.2.2.2 Object.prototype.__defineGetter__ ( P, getter ) -JSTaggedValue BuiltinsObject::DefineGetter(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::__defineGetter__(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineGetter); @@ -1006,11 +1017,11 @@ JSTaggedValue BuiltinsObject::DefineGetter(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ? ToObject(this value). - JSHandle obj = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle obj = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. If IsCallable(getter) is false, throw a TypeError exception. - JSHandle getter = GetCallArg(argv, 1); + JSHandle getter = builtins_common::GetCallArg(argv, 1); if (!getter->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "invalid getter usage", JSTaggedValue::Exception()); } @@ -1022,7 +1033,7 @@ JSTaggedValue BuiltinsObject::DefineGetter(EcmaRuntimeCallInfo *argv) descriptor.SetConfigurable(true); // 4. Let key be ? ToPropertyKey(P). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 0)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Perform ? DefinePropertyOrThrow(O, key, desc). @@ -1034,7 +1045,7 @@ JSTaggedValue BuiltinsObject::DefineGetter(EcmaRuntimeCallInfo *argv) } // B.2.2.3 Object.prototype.__defineSetter__ ( P, setter ) -JSTaggedValue BuiltinsObject::DefineSetter(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::__defineSetter__(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineGetter); @@ -1042,11 +1053,11 @@ JSTaggedValue BuiltinsObject::DefineSetter(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ? ToObject(this value). - JSHandle obj = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle obj = JSTaggedValue::ToObject(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. If IsCallable(setter) is false, throw a TypeError exception. - JSHandle setter = GetCallArg(argv, 1); + JSHandle setter = builtins_common::GetCallArg(argv, 1); if (!setter->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "invalid setter usage", JSTaggedValue::Exception()); } @@ -1058,7 +1069,7 @@ JSTaggedValue BuiltinsObject::DefineSetter(EcmaRuntimeCallInfo *argv) descriptor.SetConfigurable(true); // 4. Let key be ? ToPropertyKey(P). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 0)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Perform ? DefinePropertyOrThrow(O, key, desc). @@ -1078,12 +1089,12 @@ static JSTaggedValue LookupDesc(EcmaRuntimeCallInfo *argv, [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ? ToObject(this value). - JSHandle obj = JSTaggedValue::ToObject(thread, ecmascript::base::BuiltinsBase::GetThis(argv)); + JSHandle obj = JSTaggedValue::ToObject(thread, ecmascript::builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let key be ? ToPropertyKey(P). JSHandle key = - JSTaggedValue::ToPropertyKey(thread, ecmascript::base::BuiltinsBase::GetCallArg(argv, 0)); + JSTaggedValue::ToPropertyKey(thread, ecmascript::builtins_common::GetCallArg(argv, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Repeat, @@ -1110,7 +1121,7 @@ static JSTaggedValue LookupDesc(EcmaRuntimeCallInfo *argv, } // B.2.2.4 Object.prototype.__lookupGetter__ ( P ) -JSTaggedValue BuiltinsObject::LookupGetter(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::__lookupGetter__(EcmaRuntimeCallInfo *argv) { return LookupDesc(argv, [](PropertyDescriptor desc) { if (desc.IsAccessorDescriptor()) { @@ -1122,7 +1133,7 @@ JSTaggedValue BuiltinsObject::LookupGetter(EcmaRuntimeCallInfo *argv) } // B.2.2.5 Object.prototype.__lookupSetter__ ( P ) -JSTaggedValue BuiltinsObject::LookupSetter(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::__lookupSetter__(EcmaRuntimeCallInfo *argv) { return LookupDesc(argv, [](PropertyDescriptor desc) { if (desc.IsAccessorDescriptor()) { @@ -1133,7 +1144,7 @@ JSTaggedValue BuiltinsObject::LookupSetter(EcmaRuntimeCallInfo *argv) }); } -JSTaggedValue BuiltinsObject::CreateRealm(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::proto::CreateRealm(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -1143,7 +1154,8 @@ JSTaggedValue BuiltinsObject::CreateRealm(EcmaRuntimeCallInfo *argv) return realm.GetTaggedValue(); } -JSTaggedValue BuiltinsObject::Entries(EcmaRuntimeCallInfo *argv) +// 20.1.2.5 Object.entries ( O ) +JSTaggedValue object::Entries(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToString); @@ -1151,7 +1163,7 @@ JSTaggedValue BuiltinsObject::Entries(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); JSHandle object = JSTaggedValue::ToObject(thread, obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key+value). @@ -1164,7 +1176,7 @@ JSTaggedValue BuiltinsObject::Entries(EcmaRuntimeCallInfo *argv) } // ES2021 20.1.2.22 -JSTaggedValue BuiltinsObject::Values(EcmaRuntimeCallInfo *argv) +JSTaggedValue object::Values(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToString); @@ -1172,7 +1184,7 @@ JSTaggedValue BuiltinsObject::Values(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). - JSHandle obj = GetCallArg(argv, 0); + JSHandle obj = builtins_common::GetCallArg(argv, 0); JSHandle object = JSTaggedValue::ToObject(thread, obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, value). diff --git a/runtime/builtins/builtins_object.h b/runtime/builtins/builtins_object.h deleted file mode 100644 index 09917073771a6b775f5bbc0136391e81c71a3699..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_object.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_OBJECT_H -#define ECMASCRIPT_BUILTINS_BUILTINS_OBJECT_H - -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_handle.h" -#include "plugins/ecmascript/runtime/js_hclass.h" - -namespace panda::ecmascript::builtins { -enum class KeyType : uint8_t { - STRING_TYPE = 0, - SYMBOL_TYPE, -}; - -class BuiltinsObject : public ecmascript::base::BuiltinsBase { -public: - // 19.1.1.1Object ( [ value ] ) - static JSTaggedValue ObjectConstructor(EcmaRuntimeCallInfo *argv); - - // 19.1.2.1Object.assign ( target, ...sources ) - static JSTaggedValue Assign(EcmaRuntimeCallInfo *argv); - // 19.1.2.2Object.create ( O [ , Properties ] ) - static JSTaggedValue Create(EcmaRuntimeCallInfo *argv); - // 19.1.2.3Object.defineProperties ( O, Properties ) - static JSTaggedValue DefineProperties(EcmaRuntimeCallInfo *argv); - // 19.1.2.4Object.defineProperty ( O, P, Attributes ) - static JSTaggedValue DefineProperty(EcmaRuntimeCallInfo *argv); - // 19.1.2.5Object.freeze ( O ) - static JSTaggedValue Freeze(EcmaRuntimeCallInfo *argv); - // ES2021 20.1.2.7Object.fromEntries ( iterable ) - static JSTaggedValue FromEntries(EcmaRuntimeCallInfo *argv); - // 19.1.2.6Object.getOwnPropertyDescriptor ( O, P ) - static JSTaggedValue GetOwnPropertyDesciptor(EcmaRuntimeCallInfo *argv); - // ES2021 20.1.2.9 Object.getOwnPropertyDescriptors ( O ) - static JSTaggedValue GetOwnPropertyDesciptors(EcmaRuntimeCallInfo *argv); - // 19.1.2.7Object.getOwnPropertyNames ( O ) - static JSTaggedValue GetOwnPropertyNames(EcmaRuntimeCallInfo *argv); - // 19.1.2.8Object.getOwnPropertySymbols ( O ) - static JSTaggedValue GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv); - // 19.1.2.9Object.getPrototypeOf ( O ) - static JSTaggedValue GetPrototypeOf(EcmaRuntimeCallInfo *argv); - // 19.1.2.10Object.is ( value1, value2 ) - static JSTaggedValue Is(EcmaRuntimeCallInfo *argv); - // 19.1.2.11Object.isExtensible ( O ) - static JSTaggedValue IsExtensible(EcmaRuntimeCallInfo *argv); - // 19.1.2.12Object.isFrozen ( O ) - static JSTaggedValue IsFrozen(EcmaRuntimeCallInfo *argv); - // 19.1.2.13Object.isSealed ( O ) - static JSTaggedValue IsSealed(EcmaRuntimeCallInfo *argv); - // 19.1.2.14 Object.keys(O) - static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); - // 19.1.2.15 Object.preventExtensions(O) - static JSTaggedValue PreventExtensions(EcmaRuntimeCallInfo *argv); - // 19.1.2.17 Object.seal(O) - static JSTaggedValue Seal(EcmaRuntimeCallInfo *argv); - // 19.1.2.18 Object.setPrototypeOf(O, proto) - static JSTaggedValue SetPrototypeOf(EcmaRuntimeCallInfo *argv); - - // 19.1.3.2 Object.prototype.hasOwnProperty(V) - static JSTaggedValue HasOwnProperty(EcmaRuntimeCallInfo *argv); - // 19.1.3.3 Object.prototype.isPrototypeOf(V) - static JSTaggedValue IsPrototypeOf(EcmaRuntimeCallInfo *argv); - // 19.1.3.4 Object.prototype.propertyIsEnumerable(V) - static JSTaggedValue PropertyIsEnumerable(EcmaRuntimeCallInfo *argv); - // 19.1.3.5 Object.prototype.toLocaleString([reserved1[, reserved2]]) - static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); - // 19.1.3.6 Object.prototype.toString() - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 19.1.3.7 Object.prototype.valueOf() - static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue CreateRealm(EcmaRuntimeCallInfo *argv); - // 20.1.2.5 Object.entries ( O ) - static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); - - // ES2021 20.1.2.22 - static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); - - // B.2.2.1 Object.prototype.__proto__ - static JSTaggedValue ProtoGetter(EcmaRuntimeCallInfo *argv); - static JSTaggedValue ProtoSetter(EcmaRuntimeCallInfo *argv); - - // B.2.2.2 Object.prototype.__defineGetter__ ( P, getter ) - static JSTaggedValue DefineGetter(EcmaRuntimeCallInfo *argv); - // B.2.2.3 Object.prototype.__defineSetter__ ( P, setter ) - static JSTaggedValue DefineSetter(EcmaRuntimeCallInfo *argv); - // B.2.2.4 Object.prototype.__lookupGetter__ ( P ) - static JSTaggedValue LookupGetter(EcmaRuntimeCallInfo *argv); - // B.2.2.5 Object.prototype.__lookupSetter__ ( P ) - static JSTaggedValue LookupSetter(EcmaRuntimeCallInfo *argv); - -private: - static JSTaggedValue ObjectDefineProperties(JSThread *thread, const JSHandle &obj, - const JSHandle &prop); - static JSTaggedValue GetOwnPropertyKeys(JSThread *thread, const JSHandle &obj, const KeyType &type); - static JSTaggedValue GetBuiltinTag(JSThread *thread, const JSHandle &object); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_OBJECT_H diff --git a/runtime/builtins/builtins_plural_rules.cpp b/runtime/builtins/builtins_plural_rules.cpp index b1a2f6965bd8d6c89f1fbf9aa55625a44b6f9233..36c80edbb837455931d95d42eeb538e0845da8f8 100644 --- a/runtime/builtins/builtins_plural_rules.cpp +++ b/runtime/builtins/builtins_plural_rules.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_plural_rules.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_locale.h" @@ -22,7 +22,8 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *argv) +// 15.2.1 Intl.PluralRules ( [ locales [ , options ] ] ) +JSTaggedValue plural_rules::PluralRulesConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -30,8 +31,8 @@ JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *a ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle constructor = GetConstructor(argv); - JSHandle new_target = GetNewTarget(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new_target is undefined", JSTaggedValue::Exception()); } @@ -44,15 +45,16 @@ JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *a RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? InitializePluralRules(pluralRules, locales, options). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSPluralRules::InitializePluralRules(thread, plural_rules, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return plural_rules.GetTaggedValue(); } -JSTaggedValue BuiltinsPluralRules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) +// 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [, options ] ) +JSTaggedValue plural_rules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -61,24 +63,25 @@ JSTaggedValue BuiltinsPluralRules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSHandle available_locales = JSPluralRules::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). - JSHandle options = GetCallArg(argv, 1); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } -JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv) +// 15.4.3 Intl.PluralRules.prototype.select( value ) +JSTaggedValue plural_rules::proto::Select(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let pr be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). if (!this_value->IsJSPluralRules()) { @@ -87,7 +90,7 @@ JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv) // 3. Let n be ? ToNumber(value). double x = 0.0; - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); JSTaggedNumber temp = JSTaggedValue::ToNumber(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); x = temp.GetNumber(); @@ -99,13 +102,14 @@ JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsPluralRules::ResolvedOptions(EcmaRuntimeCallInfo *argv) +// 15.4.4 Intl.PluralRules.prototype.resolvedOptions () +JSTaggedValue plural_rules::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let thisValue be the this value; - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). if (!this_value->IsJSPluralRules()) { diff --git a/runtime/builtins/builtins_plural_rules.h b/runtime/builtins/builtins_plural_rules.h deleted file mode 100644 index cf0e91c227978c564aa7a84f4162a6a321b07465..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_plural_rules.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_PLURAL_RULES_H -#define ECMASCRIPT_BUILTINS_BUILTINS_PLURAL_RULES_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsPluralRules : public base::BuiltinsBase { -public: - // 15.2.1 Intl.PluralRules ( [ locales [ , options ] ] ) - static JSTaggedValue PluralRulesConstructor(EcmaRuntimeCallInfo *argv); - - // 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [, options ] ) - static JSTaggedValue SupportedLocalesOf(EcmaRuntimeCallInfo *argv); - - // 15.4.3 Intl.PluralRules.prototype.select( value ) - static JSTaggedValue Select(EcmaRuntimeCallInfo *argv); - - // 15.4.4 Intl.PluralRules.prototype.resolvedOptions () - static JSTaggedValue ResolvedOptions(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_PLURAL_RULES_H diff --git a/runtime/builtins/builtins_promise.cpp b/runtime/builtins/builtins_promise.cpp index e43ae491dfec4621351587ce856de2e01186b24e..a3d3190077711a52cfa7bbcb9cc2c27423e457d1 100644 --- a/runtime/builtins/builtins_promise.cpp +++ b/runtime/builtins/builtins_promise.cpp @@ -13,9 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_promise.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_handler.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_job.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -32,9 +30,18 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob; + +static JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &it_record, + const JSHandle &ctor, + const JSHandle &capa); + +static JSHandle PerformPromiseRace(JSThread *thread, + const JSHandle &iterator_record, + const JSHandle &capability, + const JSHandle &constructor); + // 25.4.3.1 Promise ( executor ) -JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Constructor); @@ -44,12 +51,12 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa ObjectFactory *factory = ecma_vm->GetFactory(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "PromiseConstructor: NewTarget is undefined", JSTaggedValue::Exception()); } // 2. If IsCallable(executor) is false, throw a TypeError exception. - JSHandle executor = BuiltinsBase::GetCallArg(argv, 0); + JSHandle executor = builtins_common::GetCallArg(argv, 0); if (!executor->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "PromiseConstructor: executor is not callable", JSTaggedValue::Exception()); } @@ -57,7 +64,7 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa // 3. Let promise be OrdinaryCreateFromConstructor(NewTarget, "%PromisePrototype%", // «[[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]]» ). // 4. ReturnIfAbrupt(promise). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle instance_promise = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -99,7 +106,7 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa } // 25.4.4.1 Promise.all ( iterable ) -JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::All(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, All); @@ -110,7 +117,7 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let C be the this value. - JSHandle ctor = GetThis(argv); + JSHandle ctor = builtins_common::GetThis(argv); // 2. If Type(C) is not Object, throw a TypeError exception. if (!ctor->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Promise ALL: this value is not object", JSTaggedValue::Exception()); @@ -130,7 +137,7 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) // 7. ReturnIfAbrupt(promiseCapability). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, capa.GetTaggedValue()); // 8. Let iterator be GetIterator(iterable). - JSHandle itor = JSIterator::GetIterator(thread, GetCallArg(argv, 0)); + JSHandle itor = JSIterator::GetIterator(thread, builtins_common::GetCallArg(argv, 0)); // 9. IfAbruptRejectPromise(iterator, promiseCapability). if (UNLIKELY(thread->HasPendingException())) { itor = JSPromise::IfThrowGetThrowValue(thread); @@ -164,7 +171,7 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) } // 25.4.4.3 Promise.race ( iterable ) -JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::Race(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Race); @@ -175,7 +182,7 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Let C be the this value. // 2. If Type(C) is not Object, throw a TypeError exception. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Race: this value is not object", JSTaggedValue::Exception()); } @@ -196,7 +203,7 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) // 8. Let iterator be GetIterator(iterable). // 9. IfAbruptRejectPromise(iterator, promiseCapability). - JSHandle iterable = GetCallArg(argv, 0); + JSHandle iterable = builtins_common::GetCallArg(argv, 0); JSHandle iterator = JSIterator::GetIterator(thread, iterable); if (UNLIKELY(thread->HasPendingException())) { iterator = JSPromise::IfThrowGetThrowValue(thread); @@ -231,7 +238,7 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) } // 25.4.4.5 Promise.resolve ( x ) -JSTaggedValue BuiltinsPromise::Resolve(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::Resolve(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Resolve); @@ -239,18 +246,18 @@ JSTaggedValue BuiltinsPromise::Resolve(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let C be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(C) is not Object, throw a TypeError exception. if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Resolve: this value is not object", JSTaggedValue::Exception()); } - JSHandle x_value = BuiltinsBase::GetCallArg(argv, 0); + JSHandle x_value = builtins_common::GetCallArg(argv, 0); return JSPromise::PromiseResolve(thread, this_value, x_value); } // 25.4.4.4 Promise.reject ( r ) -JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::Reject(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Reject); @@ -260,7 +267,7 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) // 1. Let C be the this value. // 2. If Type(C) is not Object, throw a TypeError exception. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reject: this value is not object", JSTaggedValue::Exception()); } @@ -272,7 +279,7 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) // 5. Let rejectResult be Call(promiseCapability.[[Reject]], undefined, «r»). // 6. ReturnIfAbrupt(rejectResult). - JSHandle reason = GetCallArg(argv, 0); + JSHandle reason = builtins_common::GetCallArg(argv, 0); JSHandle reject(thread, promise_capability->GetReject()); JSHandle undefined = global_const->GetHandledUndefined(); @@ -287,14 +294,14 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) } // 25.4.4.6 get Promise [ @@species ] -JSTaggedValue BuiltinsPromise::GetSpecies([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::GetSpecies([[maybe_unused]] EcmaRuntimeCallInfo *argv) { ASSERT(argv); - return JSTaggedValue(GetThis(argv).GetTaggedValue()); + return JSTaggedValue(builtins_common::GetThis(argv).GetTaggedValue()); } // 25.4.5.1 Promise.prototype.catch ( onRejected ) -JSTaggedValue BuiltinsPromise::Catch(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::proto::Catch(EcmaRuntimeCallInfo *argv) { // 1. Let promise be the this value. // 2. Return Invoke(promise, "then", «undefined, onRejected»). @@ -303,9 +310,9 @@ JSTaggedValue BuiltinsPromise::Catch(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle promise = GetThis(argv); + JSHandle promise = builtins_common::GetThis(argv); JSHandle then_key = global_const->GetHandledPromiseThenString(); - JSHandle reject = GetCallArg(argv, 0); + JSHandle reject = builtins_common::GetCallArg(argv, 0); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), promise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(JSTaggedValue::Undefined(), reject); @@ -313,7 +320,7 @@ JSTaggedValue BuiltinsPromise::Catch(EcmaRuntimeCallInfo *argv) } // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected ) -JSTaggedValue BuiltinsPromise::Then(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise::proto::Then(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Then); @@ -323,7 +330,7 @@ JSTaggedValue BuiltinsPromise::Then(EcmaRuntimeCallInfo *argv) JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Let promise be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If IsPromise(promise) is false, throw a TypeError exception. if (!this_value->IsJSPromise()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Then: thisValue is not promise!", JSTaggedValue::Exception()); @@ -340,18 +347,18 @@ JSTaggedValue BuiltinsPromise::Then(EcmaRuntimeCallInfo *argv) JSHandle result_capability = JSPromise::NewPromiseCapability(thread, constructor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle on_fulfilled = BuiltinsBase::GetCallArg(argv, 0); - JSHandle on_rejected = BuiltinsBase::GetCallArg(argv, 1); + JSHandle on_fulfilled = builtins_common::GetCallArg(argv, 0); + JSHandle on_rejected = builtins_common::GetCallArg(argv, 1); // 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability). - return PerformPromiseThen(thread, JSHandle::Cast(promise), on_fulfilled, on_rejected, - JSHandle::Cast(result_capability)); + return promise::PerformPromiseThen(thread, JSHandle::Cast(promise), on_fulfilled, on_rejected, + JSHandle::Cast(result_capability)); } -JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHandle &promise, - const JSHandle &on_fulfilled, - const JSHandle &on_rejected, - const JSHandle &capability) +JSTaggedValue promise::PerformPromiseThen(JSThread *thread, const JSHandle &promise, + const JSHandle &on_fulfilled, + const JSHandle &on_rejected, + const JSHandle &capability) { auto ecma_vm = thread->GetEcmaVM(); JSHandle job = ecma_vm->GetMicroJobQueue(); @@ -416,10 +423,9 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand return PromiseCapability::Cast(capability->GetHeapObject())->GetPromise(); } -JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, - const JSHandle &it_record, - const JSHandle &ctor, - const JSHandle &capa) +JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &it_record, + const JSHandle &ctor, + const JSHandle &capa) { auto ecma_vm = thread->GetEcmaVM(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); @@ -512,7 +518,7 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, // k. Let resolveElement be a new built-in function object as defined in Promise.all // Resolve Element Functions. JSHandle resoleve_element = factory->NewJSPromiseAllResolveElementFunction( - reinterpret_cast(BuiltinsPromiseHandler::ResolveElementFunction)); + reinterpret_cast(promise_handler::ResolveElementFunction)); // l. Set the [[AlreadyCalled]] internal slot of resolveElement to a new Record {[[value]]: false }. JSHandle false_record = factory->NewPromiseRecord(); false_record->SetValue(thread, JSTaggedValue::False()); @@ -545,10 +551,9 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, } } -JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, - const JSHandle &iterator_record, - const JSHandle &capability, - const JSHandle &constructor) +JSHandle PerformPromiseRace(JSThread *thread, const JSHandle &iterator_record, + const JSHandle &capability, + const JSHandle &constructor) { // 1. Repeat // a. Let next be IteratorStep(iteratorRecord.[[iterator]]). diff --git a/runtime/builtins/builtins_promise.h b/runtime/builtins/builtins_promise.h deleted file mode 100644 index 21a634ae3251ead11baa81b5218d1e7ee98b0352..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_promise.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H -#define ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H - -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_handle.h" -#include "plugins/ecmascript/runtime/js_promise.h" -#include "plugins/ecmascript/runtime/js_tagged_value.h" -#include "plugins/ecmascript/runtime/object_factory.h" - -namespace panda::ecmascript::builtins { -class BuiltinsPromise : public ecmascript::base::BuiltinsBase { -public: - // 25.4.3.1 Promise ( executor ) - static JSTaggedValue PromiseConstructor(EcmaRuntimeCallInfo *argv); - // 25.4.4.1 Promise.all ( iterable ) - static JSTaggedValue All(EcmaRuntimeCallInfo *argv); - // 25.4.4.3 Promise.race ( iterable ) - static JSTaggedValue Race(EcmaRuntimeCallInfo *argv); - // 25.4.4.4 Promise.reject ( r ) - static JSTaggedValue Reject(EcmaRuntimeCallInfo *argv); - // 25.4.4.5 Promise.resolve ( x ) - static JSTaggedValue Resolve(EcmaRuntimeCallInfo *argv); - // 25.4.4.6 get Promise [ @@species ] - static JSTaggedValue GetSpecies(EcmaRuntimeCallInfo *argv); - // 25.4.5.1 Promise.prototype.catch ( onRejected ) - static JSTaggedValue Catch(EcmaRuntimeCallInfo *argv); - // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected ) - static JSTaggedValue Then(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue PerformPromiseThen(JSThread *thread, const JSHandle &promise, - const JSHandle &on_fulfilled, - const JSHandle &on_rejected, - const JSHandle &capability); - -private: - static JSHandle PerformPromiseAll(JSThread *thread, - const JSHandle &it_record, - const JSHandle &ctor, - const JSHandle &capa); - - static JSHandle PerformPromiseRace(JSThread *thread, - const JSHandle &iterator_record, - const JSHandle &capability, - const JSHandle &constructor); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H diff --git a/runtime/builtins/builtins_promise_handler.cpp b/runtime/builtins/builtins_promise_handler.cpp index 8f8c2ea09dac813aa870b251f37d1c1cb4e60ae5..8ba094ee9502f2a147608443312aa41491fc4d78 100644 --- a/runtime/builtins/builtins_promise_handler.cpp +++ b/runtime/builtins/builtins_promise_handler.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_promise_handler.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -26,7 +26,7 @@ namespace panda::ecmascript::builtins { // es6 25.4.1.3.2 Promise Resolve Functions -JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise_handler::Resolve(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Resolve); @@ -37,7 +37,8 @@ JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. - JSHandle resolve = JSHandle::Cast(GetConstructor(argv)); + JSHandle resolve = + JSHandle::Cast(builtins_common::GetConstructor(argv)); ASSERT_PRINT(resolve->GetPromise().IsECMAObject(), "Resolve: promise must be js object"); // 2. Let promise be the value of F's [[Promise]] internal slot. @@ -54,7 +55,7 @@ JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) // 6. If SameValue(resolution, promise) is true, then // a. Let selfResolutionError be a newly created TypeError object. // b. Return RejectPromise(promise, selfResolutionError). - JSHandle resolution = BuiltinsBase::GetCallArg(argv, 0); + JSHandle resolution = builtins_common::GetCallArg(argv, 0); if (JSTaggedValue::SameValue(resolution.GetTaggedValue(), resolve_promise.GetTaggedValue())) { JSHandle resolution_error = factory->GetJSError(ErrorType::TYPE_ERROR, "Resolve: The promise and resolution cannot be the same."); @@ -107,7 +108,7 @@ JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) } // es6 25.4.1.3.1 Promise Reject Functions -JSTaggedValue BuiltinsPromiseHandler::Reject(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise_handler::Reject(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Reject); @@ -115,7 +116,8 @@ JSTaggedValue BuiltinsPromiseHandler::Reject(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. - JSHandle reject = JSHandle::Cast(GetConstructor(argv)); + JSHandle reject = + JSHandle::Cast(builtins_common::GetConstructor(argv)); ASSERT_PRINT(reject->GetPromise().IsECMAObject(), "Reject: promise must be js object"); // 2. Let promise be the value of F's [[Promise]] internal slot. @@ -130,13 +132,13 @@ JSTaggedValue BuiltinsPromiseHandler::Reject(EcmaRuntimeCallInfo *argv) already_resolved->SetValue(thread, JSTaggedValue::True()); // 6. Return RejectPromise(promise, reason). - JSHandle reason = GetCallArg(argv, 0); + JSHandle reason = builtins_common::GetCallArg(argv, 0); JSHandle result(thread, JSPromise::RejectPromise(thread, reject_promise, reason)); return result.GetTaggedValue(); } // es6 25.4.1.5.1 GetCapabilitiesExecutor Functions -JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise_handler::Executor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Executor); @@ -144,7 +146,8 @@ JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Assert: F has a [[Capability]] internal slot whose value is a PromiseCapability Record. - JSHandle executor = JSHandle::Cast(GetConstructor(argv)); + JSHandle executor = + JSHandle::Cast(builtins_common::GetConstructor(argv)); ASSERT_PRINT(executor->GetCapability().IsRecord(), "Executor: F has a [[Capability]] internal slot whose value is a PromiseCapability Record."); @@ -160,8 +163,8 @@ JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) } // 5. Set promiseCapability.[[Resolve]] to resolve. // 6. Set promiseCapability.[[Reject]] to reject. - JSHandle resolve = GetCallArg(argv, 0); - JSHandle reject = GetCallArg(argv, 1); + JSHandle resolve = builtins_common::GetCallArg(argv, 0); + JSHandle reject = builtins_common::GetCallArg(argv, 1); promise_capability->SetResolve(thread, resolve); promise_capability->SetReject(thread, reject); // 7. Return undefined. @@ -169,7 +172,7 @@ JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) } // es6 25.4.4.1.2 Promise.all Resolve Element Functions -JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise_handler::ResolveElementFunction(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, ResolveElementFunction); @@ -177,7 +180,7 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo [[maybe_unused]] EcmaHandleScope handle_scope(thread); const GlobalEnvConstants *global_const = thread->GlobalConstants(); JSHandle func = - JSHandle::Cast(GetConstructor(argv)); + JSHandle::Cast(builtins_common::GetConstructor(argv)); // 1. Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot. JSHandle already_called = JSHandle::Cast(JSHandle(thread, func->GetAlreadyCalled())); @@ -200,7 +203,7 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo JSHandle array_values = JSHandle::Cast(JSHandle(thread, values->GetValue())); auto index = JSTaggedValue::ToUint32(thread, JSHandle(thread, func->GetIndex())); - array_values->Set(thread, index, GetCallArg(argv, 0).GetTaggedValue()); + array_values->Set(thread, index, builtins_common::GetCallArg(argv, 0).GetTaggedValue()); // 9. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] - 1. remain_cnt->SetValue(thread, --JSTaggedNumber(remain_cnt->GetValue())); // 10. If remainingElementsCount.[[value]] is 0, @@ -219,25 +222,27 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsPromiseHandler::AsyncAwaitFulfilled(EcmaRuntimeCallInfo *argv) +// es2017 25.5.5.4 AsyncFunction Awaited Fulfilled +JSTaggedValue promise_handler::AsyncAwaitFulfilled(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, AsyncAwaitFulfilled); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); - JSHandle value = GetCallArg(argv, 0); - JSHandle func(GetConstructor(argv)); + JSHandle value = builtins_common::GetCallArg(argv, 0); + JSHandle func(builtins_common::GetConstructor(argv)); return JSAsyncAwaitStatusFunction::AsyncFunctionAwaitFulfilled(argv->GetThread(), func, value).GetTaggedValue(); } -JSTaggedValue BuiltinsPromiseHandler::AsyncAwaitRejected(EcmaRuntimeCallInfo *argv) +// es2017 25.5.5.5 AsyncFunction Awaited Rejected +JSTaggedValue promise_handler::AsyncAwaitRejected(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, AsyncAwaitRejected); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); - JSHandle reason = GetCallArg(argv, 0); - JSHandle func(GetConstructor(argv)); + JSHandle reason = builtins_common::GetCallArg(argv, 0); + JSHandle func(builtins_common::GetConstructor(argv)); return JSAsyncAwaitStatusFunction::AsyncFunctionAwaitRejected(argv->GetThread(), func, reason).GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_promise_handler.h b/runtime/builtins/builtins_promise_handler.h deleted file mode 100644 index 7707f8cc31e65faa87a6084cfeb52ec501d502af..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_promise_handler.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_HANDLER_H -#define ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_HANDLER_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsPromiseHandler : public ecmascript::base::BuiltinsBase { -public: - // es6 26.6.1.3.1 Promise Resolve Functions - static JSTaggedValue Resolve(EcmaRuntimeCallInfo *argv); - - // es6 26.6.1.3.2 Promise Reject Functions - static JSTaggedValue Reject(EcmaRuntimeCallInfo *argv); - - // es6 26.6.1.5.1 GetCapabilitiesExecutor Functions - static JSTaggedValue Executor(EcmaRuntimeCallInfo *argv); - - // es2017 25.5.5.4 AsyncFunction Awaited Fulfilled - static JSTaggedValue AsyncAwaitFulfilled(EcmaRuntimeCallInfo *argv); - - // es2017 25.5.5.5 AsyncFunction Awaited Rejected - static JSTaggedValue AsyncAwaitRejected(EcmaRuntimeCallInfo *argv); - - // es6 25.4.4.1.2 Promise.all Resolve Element Functions - static JSTaggedValue ResolveElementFunction(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_HANDLER_H diff --git a/runtime/builtins/builtins_promise_job.cpp b/runtime/builtins/builtins_promise_job.cpp index 7d5aec9b88b615f21b4c27eb7dbe4a9cb2efa878..1bd9ac4fcddb8edc507da60a1471d952e4f21ddb 100644 --- a/runtime/builtins/builtins_promise_job.cpp +++ b/runtime/builtins/builtins_promise_job.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_promise_job.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -24,17 +24,17 @@ #include "libpandabase/macros.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise_job::PromiseReactionJob(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseJob, Reaction); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Assert: reaction is a PromiseReaction Record. - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); ASSERT(value->IsPromiseReaction()); JSHandle reaction = JSHandle::Cast(value); - JSHandle argument = GetCallArg(argv, 1); + JSHandle argument = builtins_common::GetCallArg(argv, 1); const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 2. Let promiseCapability be reaction.[[Capabilities]]. @@ -81,20 +81,20 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) return JSFunction::Call(info.Get()); } -JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) +JSTaggedValue promise_job::PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseJob, ResolveThenableJob); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle promise = GetCallArg(argv, 0); + JSHandle promise = builtins_common::GetCallArg(argv, 0); ASSERT(promise->IsJSPromise()); // 1. Let resolvingFunctions be CreateResolvingFunctions(promiseToResolve). JSHandle resolving_functions = JSPromise::CreateResolvingFunctions(thread, JSHandle::Cast(promise)); - JSHandle thenable = GetCallArg(argv, 1); - JSHandle then = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle thenable = builtins_common::GetCallArg(argv, 1); + JSHandle then = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); // 2. Let thenCallResult be Call(then, thenable, «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). diff --git a/runtime/builtins/builtins_promise_job.h b/runtime/builtins/builtins_promise_job.h deleted file mode 100644 index 32b9196c905b8b8575ebea5a2f406a218374137b..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_promise_job.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_JS_PROMISE_JOB_H -#define ECMASCRIPT_JS_PROMISE_JOB_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsPromiseJob : ecmascript::base::BuiltinsBase { -public: - static JSTaggedValue PromiseReactionJob(EcmaRuntimeCallInfo *argv); - static JSTaggedValue PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_JS_PROMISE_JOB_H diff --git a/runtime/builtins/builtins_proxy.cpp b/runtime/builtins/builtins_proxy.cpp index 4b78993025ce4e805213ac8e327b025eaac7c4b6..78db8dc833c86304557cbd1c941d0f6ab6496645 100644 --- a/runtime/builtins/builtins_proxy.cpp +++ b/runtime/builtins/builtins_proxy.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_proxy.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_function.h" @@ -21,28 +21,32 @@ #include "plugins/ecmascript/runtime/tagged_array-inl.h" namespace panda::ecmascript::builtins { + +static JSTaggedValue InvalidateProxyFunction(EcmaRuntimeCallInfo *argv); + // 26.2.1.1 Proxy( [ value ] ) -JSTaggedValue BuiltinsProxy::ProxyConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue proxy::ProxyConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, Constructor); [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); // 1.If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "ProxyConstructor: NewTarget is undefined", JSTaggedValue::Exception()); } // 2.Return ProxyCreate(target, handler). - JSHandle proxy = JSProxy::ProxyCreate(argv->GetThread(), GetCallArg(argv, 0), GetCallArg(argv, 1)); + JSHandle proxy = JSProxy::ProxyCreate(argv->GetThread(), builtins_common::GetCallArg(argv, 0), + builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); return proxy.GetTaggedValue(); } // 26.2.2.1 Proxy.revocable ( target, handler ) -JSTaggedValue BuiltinsProxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue proxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, Revocable); @@ -50,7 +54,8 @@ JSTaggedValue BuiltinsProxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *arg [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let p be ProxyCreate(target, handler). - JSHandle proxy = JSProxy::ProxyCreate(thread, GetCallArg(argv, 0), GetCallArg(argv, 1)); + JSHandle proxy = + JSProxy::ProxyCreate(thread, builtins_common::GetCallArg(argv, 0), builtins_common::GetCallArg(argv, 1)); // 2.ReturnIfAbrupt(p). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -78,14 +83,14 @@ JSTaggedValue BuiltinsProxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *arg } // A Proxy revocation function to invalidate a specific Proxy object -JSTaggedValue BuiltinsProxy::InvalidateProxyFunction(EcmaRuntimeCallInfo *argv) +JSTaggedValue InvalidateProxyFunction(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, InvalidateProxyFunction); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle revoke_obj(GetThis(argv)); + JSHandle revoke_obj(builtins_common::GetThis(argv)); JSHandle revoke_key = thread->GlobalConstants()->GetHandledRevokeString(); PropertyDescriptor desc(thread); diff --git a/runtime/builtins/builtins_proxy.h b/runtime/builtins/builtins_proxy.h deleted file mode 100644 index 38434543f57b9f39e8c75326c66577cb3f09229f..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_proxy.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_PROXY_H -#define ECMASCRIPT_BUILTINS_BUILTINS_PROXY_H - -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_handle.h" -#include "plugins/ecmascript/runtime/js_hclass.h" - -namespace panda::ecmascript::builtins { -class BuiltinsProxy : public ecmascript::base::BuiltinsBase { -public: - // 26.2.1.1 Proxy( [ value ] ) - static JSTaggedValue ProxyConstructor(EcmaRuntimeCallInfo *argv); - - // 26.2.2.1 Proxy.revocable ( target, handler ) - static JSTaggedValue Revocable(EcmaRuntimeCallInfo *argv); - - // A Proxy revocation function to invalidate a specific Proxy object - static JSTaggedValue InvalidateProxyFunction(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_PROXYH diff --git a/runtime/builtins/builtins_reflect.cpp b/runtime/builtins/builtins_reflect.cpp index a11ec2fbb4645c4a35939d74e374f80ab0310fe1..d7974a6d0912413ef1480d3a484a325e21491ff5 100644 --- a/runtime/builtins/builtins_reflect.cpp +++ b/runtime/builtins/builtins_reflect.cpp @@ -13,26 +13,27 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_reflect.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" +#include "plugins/ecmascript/runtime/js_array.h" #include "plugins/ecmascript/runtime/internal_call_params.h" #include "plugins/ecmascript/runtime/js_tagged_value-inl.h" namespace panda::ecmascript::builtins { // ecma 26.1.1 Reflect.apply (target, thisArgument, argumentsList) -JSTaggedValue BuiltinsReflect::ReflectApply(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::Apply(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Apply); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsCallable(target) is false, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.apply target is not callable", JSTaggedValue::Exception()); } // 2. Let args be ? CreateListFromArrayLike(argumentsList). - JSHandle this_argument = GetCallArg(argv, 1); - JSHandle arguments_list = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle this_argument = builtins_common::GetCallArg(argv, 1); + JSHandle arguments_list = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); JSHandle arg_or_abrupt = JSObject::CreateListFromArrayLike(thread, arguments_list); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle args = JSHandle::Cast(arg_or_abrupt); @@ -48,27 +49,28 @@ JSTaggedValue BuiltinsReflect::ReflectApply(EcmaRuntimeCallInfo *argv) } // ecma 26.1.2 Reflect.construct (target, argumentsList [ , new_target]) -JSTaggedValue BuiltinsReflect::ReflectConstruct(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::Construct(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsConstructor(target) is false, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.construct target is not constructor", JSTaggedValue::Exception()); } // 2. If new_target is not present, set new_target to target. - JSHandle new_target = - argv->GetArgsNumber() > 2 ? GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD) : target; // 2: num args + JSHandle new_target = argv->GetArgsNumber() > 2 + ? builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD) + : target; // 2: num args // 3. Else if IsConstructor(new_target) is false, throw a TypeError exception. if (!new_target->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.construct new_target is present, but not constructor", JSTaggedValue::Exception()); } // 4. Let args be ? CreateListFromArrayLike(argumentsList). - JSHandle arguments_list = GetCallArg(argv, 1); + JSHandle arguments_list = builtins_common::GetCallArg(argv, 1); JSHandle arg_or_abrupt = JSObject::CreateListFromArrayLike(thread, arguments_list); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle args = JSHandle::Cast(arg_or_abrupt); @@ -81,63 +83,63 @@ JSTaggedValue BuiltinsReflect::ReflectConstruct(EcmaRuntimeCallInfo *argv) } // ecma 26.1.3 Reflect.defineProperty (target, propertyKey, attributes) -JSTaggedValue BuiltinsReflect::ReflectDefineProperty(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::DefineProperty(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, DefineProperty); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.defineProperty target is not object", JSTaggedValue::Exception()); } // 2. Let key be ? ToPropertyKey(propertyKey). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let desc be ? ToPropertyDescriptor(attributes). - JSHandle attributes = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle attributes = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); PropertyDescriptor desc(thread); JSObject::ToPropertyDescriptor(thread, attributes, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Return ? target.[[DefineOwnProperty]](key, desc). - return GetTaggedBoolean(JSTaggedValue::DefineOwnProperty(thread, target, key, desc)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::DefineOwnProperty(thread, target, key, desc)); } // ecma 21.1.4 Reflect.deleteProperty (target, propertyKey) -JSTaggedValue BuiltinsReflect::ReflectDeleteProperty(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::DeleteProperty(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, DeleteProperty); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.deleteProperty target is not object", JSTaggedValue::Exception()); } // 2. Let key be ? ToPropertyKey(propertyKey). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? target.[[Delete]](key). - return GetTaggedBoolean(JSTaggedValue::DeleteProperty(thread, target, key)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::DeleteProperty(thread, target, key)); } // ecma 26.1.5 Reflect.get (target, propertyKey [ , receiver]) -JSTaggedValue BuiltinsReflect::ReflectGet(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::Get(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Get); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle val = GetCallArg(argv, 0); + JSHandle val = builtins_common::GetCallArg(argv, 0); if (!val->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.get target is not object", JSTaggedValue::Exception()); } JSHandle target = JSHandle::Cast(val); // 2. Let key be ? ToPropertyKey(propertyKey). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If receiver is not present, then // a. Set receiver to target. @@ -145,25 +147,25 @@ JSTaggedValue BuiltinsReflect::ReflectGet(EcmaRuntimeCallInfo *argv) if (argv->GetArgsNumber() == 2) { // 2: 2 means that there are 2 args in total return JSObject::GetProperty(thread, target, key).GetValue().GetTaggedValue(); } - JSHandle receiver = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle receiver = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); return JSObject::GetProperty(thread, val, key, receiver).GetValue().GetTaggedValue(); } // ecma 26.1.6 Reflect.getOwnPropertyDescriptor ( target, propertyKey ) -JSTaggedValue BuiltinsReflect::ReflectGetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::GetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.getOwnPropertyDescriptor target is not object", JSTaggedValue::Exception()); } // 2. Let key be ? ToPropertyKey(propertyKey). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let desc be ? target.[[GetOwnProperty]](key). PropertyDescriptor desc(thread); @@ -176,14 +178,14 @@ JSTaggedValue BuiltinsReflect::ReflectGetOwnPropertyDescriptor(EcmaRuntimeCallIn } // ecma 21.1.7 Reflect.getPrototypeOf (target) -JSTaggedValue BuiltinsReflect::ReflectGetPrototypeOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::GetPrototypeOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, GetPrototypeOf); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle val = GetCallArg(argv, 0); + JSHandle val = builtins_common::GetCallArg(argv, 0); if (!val->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.getPrototypeOf target is not object", JSTaggedValue::Exception()); } @@ -193,48 +195,48 @@ JSTaggedValue BuiltinsReflect::ReflectGetPrototypeOf(EcmaRuntimeCallInfo *argv) } // ecma 26.1.8 Reflect.has (target, propertyKey) -JSTaggedValue BuiltinsReflect::ReflectHas(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::Has(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Has); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.has target is not object", JSTaggedValue::Exception()); } // 2. Let key be ? ToPropertyKey(propertyKey). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? target.[[HasProperty]](key). - return GetTaggedBoolean(JSTaggedValue::HasProperty(thread, target, key)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::HasProperty(thread, target, key)); } // ecma 26.1.9 Reflect.isExtensible (target) -JSTaggedValue BuiltinsReflect::ReflectIsExtensible(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::IsExtensible(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.isExtensible target is not object", JSTaggedValue::Exception()); } // 2. Return ? target.[[IsExtensible]](). - return GetTaggedBoolean(target->IsExtensible(thread)); + return builtins_common::GetTaggedBoolean(target->IsExtensible(thread)); } // ecma 26.1.10 Reflect.ownKeys (target) -JSTaggedValue BuiltinsReflect::ReflectOwnKeys(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::OwnKeys(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, OwnKeys); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.ownKeys target is not object", JSTaggedValue::Exception()); } @@ -247,67 +249,67 @@ JSTaggedValue BuiltinsReflect::ReflectOwnKeys(EcmaRuntimeCallInfo *argv) } // ecma 26.1.11 Reflect.preventExtensions (target) -JSTaggedValue BuiltinsReflect::ReflectPreventExtensions(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::PreventExtensions(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, PreventExtensions); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.preventExtensions target is not object", JSTaggedValue::Exception()); } // 2. Return ? target.[[PreventExtensions]](). - return GetTaggedBoolean(JSTaggedValue::PreventExtensions(thread, target)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::PreventExtensions(thread, target)); } // ecma 26.1.12 Reflect.set (target, propertyKey, V [ , receiver]) -JSTaggedValue BuiltinsReflect::ReflectSet(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::Set(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Set); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target_val = GetCallArg(argv, 0); + JSHandle target_val = builtins_common::GetCallArg(argv, 0); if (!target_val->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.get target is not object", JSTaggedValue::Exception()); } // 2. Let key be ? ToPropertyKey(propertyKey). - JSHandle key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1)); + JSHandle key = JSTaggedValue::ToPropertyKey(thread, builtins_common::GetCallArg(argv, 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle value = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle value = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); // 3. If receiver is not present, then // a. Set receiver to target. // 4. Return ? target.[[Set]](key, receiver). if (argv->GetArgsNumber() == 3) { // 3: 3 means that there are three args in total - return GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value)); } - JSHandle receiver = GetCallArg(argv, 3); // 3: 3 means the third arg - return GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value, receiver)); + JSHandle receiver = builtins_common::GetCallArg(argv, 3); // 3: 3 means the third arg + return builtins_common::GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value, receiver)); } // ecma 26.1.13 Reflect.setPrototypeOf (target, proto) -JSTaggedValue BuiltinsReflect::ReflectSetPrototypeOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue reflect::SetPrototypeOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, SetPrototypeOf); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.setPrototypeOf target is not object", JSTaggedValue::Exception()); } // 2. If Type(proto) is not Object and proto is not null, throw a TypeError exception. - JSHandle proto = GetCallArg(argv, 1); + JSHandle proto = builtins_common::GetCallArg(argv, 1); if (!proto->IsECMAObject() && !proto->IsNull()) { THROW_TYPE_ERROR_AND_RETURN(thread, "SetPrototypeOf: proto is neither Object nor Null", JSTaggedValue::Exception()); } // 3. Return ? target.[[SetPrototypeOf]](proto). - return GetTaggedBoolean(JSTaggedValue::SetPrototype(thread, target, proto)); + return builtins_common::GetTaggedBoolean(JSTaggedValue::SetPrototype(thread, target, proto)); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_reflect.h b/runtime/builtins/builtins_reflect.h deleted file mode 100644 index b3e203e209d4fac8b4408425593eb278b79bd2c0..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_reflect.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_REFLECT_H -#define ECMASCRIPT_BUILTINS_BUILTINS_REFLECT_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_function.h" -#include "plugins/ecmascript/runtime/js_array.h" - -namespace panda::ecmascript::builtins { -class BuiltinsReflect : public ecmascript::base::BuiltinsBase { -public: - // ecma 26.1.1 - static JSTaggedValue ReflectApply(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.2 - static JSTaggedValue ReflectConstruct(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.3 - static JSTaggedValue ReflectDefineProperty(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.4 - static JSTaggedValue ReflectDeleteProperty(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.5 - static JSTaggedValue ReflectGet(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.6 - static JSTaggedValue ReflectGetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.7 - static JSTaggedValue ReflectGetPrototypeOf(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.8 - static JSTaggedValue ReflectHas(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.9 - static JSTaggedValue ReflectIsExtensible(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.10 - static JSTaggedValue ReflectOwnKeys(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.11 - static JSTaggedValue ReflectPreventExtensions(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.12 - static JSTaggedValue ReflectSet(EcmaRuntimeCallInfo *argv); - - // ecma 26.1.13 - static JSTaggedValue ReflectSetPrototypeOf(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_REFLECT_H diff --git a/runtime/builtins/builtins_regexp.cpp b/runtime/builtins/builtins_regexp.cpp index 781d91fbbefee7ce459d402545c702c5068e3f9a..ea3237ead726955ae9c6654c5498e0bbdf16b087 100644 --- a/runtime/builtins/builtins_regexp.cpp +++ b/runtime/builtins/builtins_regexp.cpp @@ -33,16 +33,41 @@ #include "plugins/ecmascript/runtime/tagged_array-inl.h" namespace panda::ecmascript::builtins { + +constexpr uint32_t MIN_REPLACE_STRING_LENGTH = 1000; +constexpr uint32_t MAX_SPLIT_LIMIT = 0xFFFFFFFFU; +static RegExpExecutor::MatchResult Matcher(JSThread *thread, const JSHandle ®exp, + const uint8_t *buffer, size_t length, int32_t last_index, bool is_utf16); +static bool GetFlagsInternal(JSThread *thread, const JSHandle &obj, uint8_t mask); + +// 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) +static JSTaggedValue RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, + const JSHandle &input_str, bool use_cache); + +// 21.2.3.2.1 Runtime Semantics: RegExpAlloc ( new_target ) +static JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &new_target); + +static uint32_t UpdateExpressionFlags(JSThread *thread, const PandaString &check_str); + +// 21.2.3.2.2 Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) +static JSTaggedValue RegExpInitialize(JSThread *thread, const JSHandle &obj, + const JSHandle &pattern, const JSHandle &flags); +// 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern ( P, F ) +static EcmaString *EscapeRegExpPattern(JSThread *thread, const JSHandle &src, + const JSHandle &flags); +static JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, + JSHandle input_string, uint32_t input_length); + // 21.2.3.1 -JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::RegExpConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle new_target_temp = GetNewTarget(argv); - JSHandle pattern = GetCallArg(argv, 0); - JSHandle flags = GetCallArg(argv, 1); + JSHandle new_target_temp = builtins_common::GetNewTarget(argv); + JSHandle pattern = builtins_common::GetCallArg(argv, 0); + JSHandle flags = builtins_common::GetCallArg(argv, 1); // 1. Let patternIsRegExp be IsRegExp(pattern). bool pattern_is_reg_exp = JSObject::IsRegExp(thread, pattern); // 2. ReturnIfAbrupt(patternIsRegExp). @@ -153,16 +178,16 @@ static bool ExecCachingAllowed(JSThread *thread, JSHandle &this_v // prototype // 20.2.5.2 -JSTaggedValue BuiltinsRegExp::Exec(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::Exec(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Exec); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); // 4. Let S be ToString(string). - JSHandle input_str = GetCallArg(argv, 0); + JSHandle input_str = builtins_common::GetCallArg(argv, 0); JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); // 5. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -190,15 +215,15 @@ JSTaggedValue BuiltinsRegExp::Exec(EcmaRuntimeCallInfo *argv) } // 20.2.5.13 -JSTaggedValue BuiltinsRegExp::Test(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::Test(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Test); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle this_obj = GetThis(argv); - JSHandle input_str = GetCallArg(argv, 0); + JSHandle this_obj = builtins_common::GetThis(argv); + JSHandle input_str = builtins_common::GetCallArg(argv, 0); // 3. Let string be ToString(S). // 4. ReturnIfAbrupt(string). JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); @@ -211,22 +236,22 @@ JSTaggedValue BuiltinsRegExp::Test(EcmaRuntimeCallInfo *argv) } // 5. Let match be RegExpExec(R, string). - JSTaggedValue match_result = RegExpExec(thread, this_obj, string, false); + JSTaggedValue match_result = reg_exp::RegExpExec(thread, this_obj, string, false); // 6. ReturnIfAbrupt(match). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. If match is not null, return true; else return false. - return GetTaggedBoolean(!match_result.IsNull()); + return builtins_common::GetTaggedBoolean(!match_result.IsNull()); } // 20.2.5.14 -JSTaggedValue BuiltinsRegExp::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, ToString); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); auto ecma_vm = thread->GetEcmaVM(); // 2. If Type(R) is not Object, throw a TypeError exception. if (!this_obj->IsECMAObject()) { @@ -254,14 +279,14 @@ JSTaggedValue BuiltinsRegExp::ToString(EcmaRuntimeCallInfo *argv) } // 20.2.5.3 -JSTaggedValue BuiltinsRegExp::GetFlags(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetFlags(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, GetFlags); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); // 2. If Type(R) is not Object, throw a TypeError exception. if (!this_obj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); @@ -272,7 +297,7 @@ JSTaggedValue BuiltinsRegExp::GetFlags(EcmaRuntimeCallInfo *argv) if (JSHandle::Cast(this_obj)->IsJSRegExp()) { uint8_t flags_bits = static_cast(JSRegExp::Cast(this_obj->GetTaggedObject())->GetOriginalFlags().GetInt()); - return FlagsBitsToString(thread, flags_bits); + return reg_exp::FlagsBitsToString(thread, flags_bits); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -304,56 +329,56 @@ JSTaggedValue BuiltinsRegExp::GetFlags(EcmaRuntimeCallInfo *argv) } // 20.2.5.4 -JSTaggedValue BuiltinsRegExp::GetGlobal(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetGlobal(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_GLOBAL); - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 20.2.5.5 -JSTaggedValue BuiltinsRegExp::GetIgnoreCase(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetIgnoreCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_IGNORECASE); - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 20.2.5.7 -JSTaggedValue BuiltinsRegExp::GetMultiline(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetMultiline(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_MULTILINE); - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } -JSTaggedValue BuiltinsRegExp::GetDotAll(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetDotAll(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_DOTALL); - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 20.2.5.10 -JSTaggedValue BuiltinsRegExp::GetSource(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetSource(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); // 2. If Type(R) is not Object, throw a TypeError exception. // 3. If R does not have an [[OriginalSource]] internal slot, throw a TypeError exception. // 4. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError exception. @@ -370,51 +395,51 @@ JSTaggedValue BuiltinsRegExp::GetSource(EcmaRuntimeCallInfo *argv) JSHandle source(thread, regexp_obj->GetOriginalSource()); // 6. Let flags be the value of R’s [[OriginalFlags]] internal slot. uint8_t flags_bits = static_cast(regexp_obj->GetOriginalFlags().GetInt()); - JSHandle flags(thread, FlagsBitsToString(thread, flags_bits)); + JSHandle flags(thread, reg_exp::FlagsBitsToString(thread, flags_bits)); // 7. Return EscapeRegExpPattern(src, flags). return JSTaggedValue(EscapeRegExpPattern(thread, source, flags)); } // 20.2.5.12 -JSTaggedValue BuiltinsRegExp::GetSticky(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetSticky(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_STICKY); - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 20.2.5.15 -JSTaggedValue BuiltinsRegExp::GetUnicode(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::GetUnicode(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_UTF16); - return GetTaggedBoolean(result); + return builtins_common::GetTaggedBoolean(result); } // 21.2.4.2 -JSTaggedValue BuiltinsRegExp::GetSpecies(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::GetSpecies(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - return GetThis(argv).GetTaggedValue(); + return builtins_common::GetThis(argv).GetTaggedValue(); } // 21.2.5.6 -JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::Match(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Match); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let rx be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); // 3. Let S be ToString(string) - JSHandle input_string = GetCallArg(argv, 0); + JSHandle input_string = builtins_common::GetCallArg(argv, 0); JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); bool use_cache = true; JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); @@ -456,7 +481,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) return cache_result; } } - JSTaggedValue result = RegExpExec(thread, this_obj, string, use_cache); + JSTaggedValue result = reg_exp::RegExpExec(thread, this_obj, string, use_cache); return JSTaggedValue(result); } @@ -490,7 +515,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // g. Repeat, while (true) { // i. Let result be RegExpExec(rx, S). - result.Update(RegExpExec(thread, this_obj, string, use_cache)); + result.Update(reg_exp::RegExpExec(thread, this_obj, string, use_cache)); // ii. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -540,7 +565,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) } } -JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::MatchAll(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -549,14 +574,14 @@ JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); auto ecma_vm = thread->GetEcmaVM(); if (!this_obj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } // 3. Let S be ? ToString(string). - JSHandle input_string = GetCallArg(argv, 0); + JSHandle input_string = builtins_common::GetCallArg(argv, 0); JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -614,8 +639,8 @@ JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) .GetTaggedValue(); } -JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle ®exp, - JSHandle input_string, uint32_t input_length) +JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, JSHandle input_string, + uint32_t input_length) { ASSERT(regexp->IsJSRegExp()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -723,7 +748,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandleIsUtf16() && ((flags & RegExpParser::FLAG_UTF16) != 0); - end_index = AdvanceStringIndex(tag_input_string, end_index, unicode); + end_index = reg_exp::AdvanceStringIndex(tag_input_string, end_index, unicode); } last_index = end_index; } @@ -739,21 +764,21 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandleGetThread(), RegExp, Replace); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let rx be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); if (!this_obj->IsECMAObject()) { // 2. If Type(rx) is not Object, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } // 3. Let S be ToString(string). - JSHandle string = GetCallArg(argv, 0); - JSHandle input_replace_value = GetCallArg(argv, 1); + JSHandle string = builtins_common::GetCallArg(argv, 0); + JSHandle input_replace_value = builtins_common::GetCallArg(argv, 1); JSHandle sr_panda_string = JSTaggedValue::ToString(thread, string); const GlobalEnvConstants *global_const = thread->GlobalConstants(); @@ -1003,8 +1028,8 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) named_captures = JSHandle::Cast(named_captures_obj); } JSHandle replacement_handle( - thread, BuiltinsString::GetSubstitution(thread, match_string, sr_panda_string, position, captures_list, - named_captures, replace_value_handle)); + thread, string::GetSubstitution(thread, match_string, sr_panda_string, position, captures_list, + named_captures, replace_value_handle)); replacement = ConvertToPandaString(EcmaString::Cast(replacement_handle->GetTaggedObject()), StringConvertedUsage::LOGICOPERATION); } @@ -1044,16 +1069,16 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) } // 21.2.5.9 -JSTaggedValue BuiltinsRegExp::Search(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::Search(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Search); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let rx be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); // 3. Let S be ToString(string). - JSHandle input_str = GetCallArg(argv, 0); + JSHandle input_str = builtins_common::GetCallArg(argv, 0); JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1096,7 +1121,7 @@ JSTaggedValue BuiltinsRegExp::Search(EcmaRuntimeCallInfo *argv) // 21.2.5.11 // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) +JSTaggedValue reg_exp::proto::Split(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Split); @@ -1104,11 +1129,11 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); bool use_cache = false; // 1. Let rx be the this value. - JSHandle this_obj = GetThis(argv); + JSHandle this_obj = builtins_common::GetThis(argv); auto ecma_vm = thread->GetEcmaVM(); // 3. Let S be ToString(string). - JSHandle input_string = GetCallArg(argv, 0); - JSHandle limit = GetCallArg(argv, 1); + JSHandle input_string = builtins_common::GetCallArg(argv, 0); + JSHandle limit = builtins_common::GetCallArg(argv, 1); JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); // 4. ReturnIfAbrupt(string). @@ -1332,9 +1357,8 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) } // NOLINTNEXTLINE(readability-non-const-parameter) -RegExpExecutor::MatchResult BuiltinsRegExp::Matcher(JSThread *thread, const JSHandle ®exp, - const uint8_t *buffer, size_t length, int32_t last_index, - bool is_utf16) +RegExpExecutor::MatchResult Matcher(JSThread *thread, const JSHandle ®exp, const uint8_t *buffer, + size_t length, int32_t last_index, bool is_utf16) { // get bytecode JSTaggedValue buffer_data = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); @@ -1350,7 +1374,7 @@ RegExpExecutor::MatchResult BuiltinsRegExp::Matcher(JSThread *thread, const JSHa return result; } -uint32_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode) +uint32_t reg_exp::AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode) { // 1. Assert: Type(S) is String. ASSERT(input_str->IsString()); @@ -1383,7 +1407,7 @@ uint32_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &input return index + 2; } -bool BuiltinsRegExp::GetFlagsInternal(JSThread *thread, const JSHandle &obj, const uint8_t mask) +bool GetFlagsInternal(JSThread *thread, const JSHandle &obj, const uint8_t mask) { // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. @@ -1406,8 +1430,8 @@ bool BuiltinsRegExp::GetFlagsInternal(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_str, bool use_cache) +JSTaggedValue RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, + const JSHandle &input_str, bool use_cache) { ASSERT(JSObject::IsRegExp(thread, regexp)); ASSERT(input_str->IsString()); @@ -1536,8 +1560,8 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle } // 21.2.5.2.1 -JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_string, bool use_cache) +JSTaggedValue reg_exp::RegExpExec(JSThread *thread, const JSHandle ®exp, + const JSHandle &input_string, bool use_cache) { // 1. Assert: Type(R) is Object. ASSERT(regexp->IsECMAObject()); @@ -1575,7 +1599,7 @@ JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandle &new_target) +JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &new_target) { /** * 1. Let obj be OrdinaryCreateFromConstructor(new_target, "%RegExpPrototype%", @@ -1591,7 +1615,7 @@ JSTaggedValue BuiltinsRegExp::RegExpAlloc(JSThread *thread, const JSHandle(0xC0)) == 0); // 0xC0: first 2 bits of flags must be 0 @@ -1671,9 +1695,8 @@ JSTaggedValue BuiltinsRegExp::FlagsBitsToString(JSThread *thread, uint8_t flags) } // 21.2.3.2.2 -JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle &obj, - const JSHandle &pattern, - const JSHandle &flags) +JSTaggedValue RegExpInitialize(JSThread *thread, const JSHandle &obj, + const JSHandle &pattern, const JSHandle &flags) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle pattern_str_handle; @@ -1757,8 +1780,8 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< return obj.GetTaggedValue(); } -JSTaggedValue BuiltinsRegExp::RegExpCreate(JSThread *thread, const JSHandle &pattern, - const JSHandle &flags) +JSTaggedValue reg_exp::RegExpCreate(JSThread *thread, const JSHandle &pattern, + const JSHandle &flags) { BUILTINS_API_TRACE(thread, RegExp, Create); auto ecma_vm = thread->GetEcmaVM(); @@ -1773,8 +1796,8 @@ JSTaggedValue BuiltinsRegExp::RegExpCreate(JSThread *thread, const JSHandle &src, - const JSHandle &flags) +EcmaString *EscapeRegExpPattern(JSThread *thread, const JSHandle &src, + const JSHandle &flags) { // String -> PandaString JSHandle src_str(thread, static_cast(src->GetTaggedObject())); diff --git a/runtime/builtins/builtins_regexp.h b/runtime/builtins/builtins_regexp.h index 64f043a02f5b4354d8b86d5fb81db0ff3bcc0990..1db068d027dba0611539da86c88d69fbd12acfa1 100644 --- a/runtime/builtins/builtins_regexp.h +++ b/runtime/builtins/builtins_regexp.h @@ -17,88 +17,12 @@ #define ECMASCRIPT_BUILTINS_BUILTINS_REGEXP_H #include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_string.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/js_tagged_value.h" #include "plugins/ecmascript/runtime/regexp/regexp_executor.h" #include "plugins/ecmascript/runtime/regexp/regexp_parser.h" namespace panda::ecmascript::builtins { -class BuiltinsRegExp : public ecmascript::base::BuiltinsBase { -public: - // 21.2.3.1 RegExp ( pattern, flags ) - static JSTaggedValue RegExpConstructor(EcmaRuntimeCallInfo *argv); - - // prototype - // 21.2.5.2 RegExp.prototype.exec ( string ) - static JSTaggedValue Exec(EcmaRuntimeCallInfo *argv); - // 21.2.5.13 RegExp.prototype.test( S ) - static JSTaggedValue Test(EcmaRuntimeCallInfo *argv); - // 21.2.5.14 RegExp.prototype.toString ( ) - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 21.2.5.3 get RegExp.prototype.flags - static JSTaggedValue GetFlags(EcmaRuntimeCallInfo *argv); - // 21.2.5.4 get RegExp.prototype.global - static JSTaggedValue GetGlobal(EcmaRuntimeCallInfo *argv); - // 21.2.5.5 get RegExp.prototype.ignoreCase - static JSTaggedValue GetIgnoreCase(EcmaRuntimeCallInfo *argv); - // 21.2.5.7 get RegExp.prototype.multiline - static JSTaggedValue GetMultiline(EcmaRuntimeCallInfo *argv); - static JSTaggedValue GetDotAll(EcmaRuntimeCallInfo *argv); - // 21.2.5.10 get RegExp.prototype.source - static JSTaggedValue GetSource(EcmaRuntimeCallInfo *argv); - // 21.2.5.12 get RegExp.prototype.sticky - static JSTaggedValue GetSticky(EcmaRuntimeCallInfo *argv); - // 21.2.5.15 get RegExp.prototype.unicode - static JSTaggedValue GetUnicode(EcmaRuntimeCallInfo *argv); - // 21.2.4.2 get RegExp [ @@species ] - static JSTaggedValue GetSpecies(EcmaRuntimeCallInfo *argv); - // 21.2.5.6 RegExp.prototype [ @@match ] ( string ) - static JSTaggedValue Match(EcmaRuntimeCallInfo *argv); - // 22.2.5.8 RegExp.prototype [ @@matchAll ] ( string ) - static JSTaggedValue MatchAll(EcmaRuntimeCallInfo *argv); - // 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) - static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv); - // 21.2.5.9 RegExp.prototype [ @@search ] ( string ) - static JSTaggedValue Search(EcmaRuntimeCallInfo *argv); - // 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit ) - static JSTaggedValue Split(EcmaRuntimeCallInfo *argv); - // 21.2.3.2.3 Runtime Semantics: RegExpCreate ( P, F ) - static JSTaggedValue RegExpCreate(JSThread *thread, const JSHandle &pattern, - const JSHandle &flags); - static JSTaggedValue FlagsBitsToString(JSThread *thread, uint8_t flags); - // 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) - static JSTaggedValue RegExpExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_string, bool use_cache); - // 21.2.5.2.3 AdvanceStringIndex ( S, index, unicode ) - static uint32_t AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode); - -private: - static constexpr uint32_t MIN_REPLACE_STRING_LENGTH = 1000; - static constexpr uint32_t MAX_SPLIT_LIMIT = 0xFFFFFFFFU; - - static RegExpExecutor::MatchResult Matcher(JSThread *thread, const JSHandle ®exp, - const uint8_t *buffer, size_t length, int32_t last_index, bool is_utf16); - - static bool GetFlagsInternal(JSThread *thread, const JSHandle &obj, uint8_t mask); - // 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) - static JSTaggedValue RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &input_str, bool use_cache); - - // 21.2.3.2.1 Runtime Semantics: RegExpAlloc ( new_target ) - static JSTaggedValue RegExpAlloc(JSThread *thread, const JSHandle &new_target); - - static uint32_t UpdateExpressionFlags(JSThread *thread, const PandaString &check_str); - - // 21.2.3.2.2 Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) - static JSTaggedValue RegExpInitialize(JSThread *thread, const JSHandle &obj, - const JSHandle &pattern, const JSHandle &flags); - // 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern ( P, F ) - static EcmaString *EscapeRegExpPattern(JSThread *thread, const JSHandle &src, - const JSHandle &flags); - static JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, - JSHandle input_string, uint32_t input_length); -}; class RegExpExecResultCache : public TaggedArray { public: diff --git a/runtime/builtins/builtins_relative_time_format.cpp b/runtime/builtins/builtins_relative_time_format.cpp index ee8e8cefa57fb7d9e41c819db85f238b398bebb4..4ac23a2294c277fa844e0ce0317194a0c9ceb4df 100644 --- a/runtime/builtins/builtins_relative_time_format.cpp +++ b/runtime/builtins/builtins_relative_time_format.cpp @@ -13,10 +13,12 @@ * limitations under the License. */ -#include "builtins_relative_time_format.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" +#include "plugins/ecmascript/runtime/js_relative_time_format.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRuntimeCallInfo *argv) +// 14.2.1 Intl.RelativeTimeFormat ([ locales [ , options ]]) +JSTaggedValue relative_time_format::RelativeTimeFormatConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -25,7 +27,7 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new_target is undefined", JSTaggedValue::Exception()); } @@ -33,20 +35,20 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt // 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor // (NewTarget, "%RelativeTimeFormatPrototype%", « [[InitializedRelativeTimeFormat]], // [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle relative_time_format = JSHandle::Cast( factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options). - JSHandle locales = GetCallArg(argv, 0); - JSHandle options = GetCallArg(argv, 1); + JSHandle locales = builtins_common::GetCallArg(argv, 0); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relative_time_format, 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 this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); bool is_instance_of = JSObject::InstanceOf(thread, this_value, env->GetRelativeTimeFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { @@ -60,7 +62,8 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt return relative_time_format.GetTaggedValue(); } -JSTaggedValue BuiltinsRelativeTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) +// 14.3.1 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] ) +JSTaggedValue relative_time_format::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); @@ -69,24 +72,25 @@ JSTaggedValue BuiltinsRelativeTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo JSHandle available_locales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options). - JSHandle options = GetCallArg(argv, 1); + JSHandle options = builtins_common::GetCallArg(argv, 1); JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } -JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv) +// 14.4.3 Intl.RelativeTimeFormat.prototype.format( value, unit ) +JSTaggedValue relative_time_format::proto::Format(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). if (!this_value->IsJSRelativeTimeFormat()) { @@ -95,13 +99,13 @@ JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv) // 3. Let value be ? ToNumber(value). double x = 0.0; - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::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 unit_value = GetCallArg(argv, 1); + JSHandle unit_value = builtins_common::GetCallArg(argv, 1); JSHandle unit = JSTaggedValue::ToString(thread, unit_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -112,13 +116,14 @@ JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } -JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) +// 14.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit ) +JSTaggedValue relative_time_format::proto::FormatToParts(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). if (!this_value->IsJSRelativeTimeFormat()) { @@ -127,13 +132,13 @@ JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *arg // 3. Let value be ? ToNumber(value). double x = 0.0; - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::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 unit_value = GetCallArg(argv, 1); + JSHandle unit_value = builtins_common::GetCallArg(argv, 1); JSHandle unit = JSTaggedValue::ToString(thread, unit_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -144,13 +149,14 @@ JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *arg return result.GetTaggedValue(); } -JSTaggedValue BuiltinsRelativeTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) +// 14.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions () +JSTaggedValue relative_time_format::proto::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). if (!this_value->IsJSRelativeTimeFormat()) { diff --git a/runtime/builtins/builtins_relative_time_format.h b/runtime/builtins/builtins_relative_time_format.h deleted file mode 100644 index da57c03a2b7abf7dfbef5230acffd8b3e54655a0..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_relative_time_format.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_RELATIVE_TIME_FORMAT_H -#define ECMASCRIPT_BUILTINS_BUILTINS_RELATIVE_TIME_FORMAT_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/ecma_vm.h" -#include "plugins/ecmascript/runtime/global_env.h" -#include "plugins/ecmascript/runtime/js_array.h" -#include "plugins/ecmascript/runtime/js_date.h" -#include "plugins/ecmascript/runtime/js_hclass.h" -#include "plugins/ecmascript/runtime/js_intl.h" -#include "plugins/ecmascript/runtime/js_locale.h" -#include "plugins/ecmascript/runtime/js_object.h" -#include "plugins/ecmascript/runtime/js_relative_time_format.h" -#include "plugins/ecmascript/runtime/object_factory.h" - -namespace panda::ecmascript::builtins { -class BuiltinsRelativeTimeFormat : public ecmascript::base::BuiltinsBase { -public: - // 14.2.1 Intl.RelativeTimeFormat ([ locales [ , options ]]) - static JSTaggedValue RelativeTimeFormatConstructor(EcmaRuntimeCallInfo *argv); - - // 14.3.1 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] ) - static JSTaggedValue SupportedLocalesOf(EcmaRuntimeCallInfo *argv); - - // 14.4.3 Intl.RelativeTimeFormat.prototype.format( value, unit ) - static JSTaggedValue Format(EcmaRuntimeCallInfo *argv); - - // 14.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit ) - static JSTaggedValue FormatToParts(EcmaRuntimeCallInfo *argv); - - // 14.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions () - static JSTaggedValue ResolvedOptions(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_RELATIVE_TIME_FORMAT_H diff --git a/runtime/builtins/builtins_runtime_testing.cpp b/runtime/builtins/builtins_runtime_testing.cpp index 0d10a6f08a37f104931aa368b11b0cf97141dd30..98e7c4bc780a51e87e5f640086ba462971e4857d 100644 --- a/runtime/builtins/builtins_runtime_testing.cpp +++ b/runtime/builtins/builtins_runtime_testing.cpp @@ -15,16 +15,36 @@ #ifndef PANDA_PRODUCT_BUILD -#include "builtins_runtime_testing.h" - +#include "plugins/ecmascript/runtime/base/builtins_base.h" namespace panda::ecmascript::builtins { - -JSTaggedValue BuiltinsRuntimeTesting::GetOptimizationStatus(EcmaRuntimeCallInfo *argv) +// A set of bits returned by GetOptimizationStatus. +enum class OptimizationStatus { + IS_FUNCTION = 1U << 0U, // NOLINT(readability-magic-numbers) + NEVER_OPTIMIZE = 1U << 1U, // NOLINT(readability-magic-numbers) + ALWAYS_OPTIMIZE = 1U << 2U, // NOLINT(readability-magic-numbers) + MAYBE_DEOPTED = 1U << 3U, // NOLINT(readability-magic-numbers) + OPTIMIZED = 1U << 4U, // NOLINT(readability-magic-numbers) + + INTERPRETED = 1U << 7U, // NOLINT(readability-magic-numbers) + MARKED_FOR_OPTIMIZATION = 1U << 8U, // NOLINT(readability-magic-numbers) + MARKED_FOR_CONCURRENT_OPTIMIZATION = 1U << 9U, // NOLINT(readability-magic-numbers) + OPTIMIZING_CONCURRENTLY = 1U << 10U, // NOLINT(readability-magic-numbers) + IS_EXECUTING = 1U << 11U, // NOLINT(readability-magic-numbers) + TOPMOST_FRAME_IS_COMPILED = 1U << 12U, // NOLINT(readability-magic-numbers) + LITE_MODE = 1U << 13U, // NOLINT(readability-magic-numbers) + MARKED_FOR_DEOPTIMIZATION = 1U << 14U, // NOLINT(readability-magic-numbers) + + TOPMOST_FRAME_IS_INTERPRETED = 1U << 16U, // NOLINT(readability-magic-numbers) + + IS_LAZY = 1U << 18U, // NOLINT(readability-magic-numbers) +}; + +JSTaggedValue runtime_testing::GetOptimizationStatus(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, GetOptimizationStatus); - JSHandle arg_tagged = GetCallArg(argv, 0); + JSHandle arg_tagged = builtins_common::GetCallArg(argv, 0); uint32_t status = 0; @@ -92,12 +112,12 @@ JSTaggedValue BuiltinsRuntimeTesting::GetOptimizationStatus(EcmaRuntimeCallInfo return JSTaggedValue(status); } -JSTaggedValue BuiltinsRuntimeTesting::PrepareFunctionForOptimization(EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::PrepareFunctionForOptimization(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, PrepareFunctionForOptimization); - JSHandle arg_tagged = GetCallArg(argv, 0); + JSHandle arg_tagged = builtins_common::GetCallArg(argv, 0); ASSERT(arg_tagged->IsCallable()); auto *js_method = JSHandle::Cast(arg_tagged)->GetCallTarget(); @@ -109,13 +129,13 @@ JSTaggedValue BuiltinsRuntimeTesting::PrepareFunctionForOptimization(EcmaRuntime return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsRuntimeTesting::OptimizeFunctionOnNextCall(EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::OptimizeFunctionOnNextCall(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, OptimizeFunctionOnNextCall); - JSHandle arg_tagged_0 = GetCallArg(argv, 0); - JSHandle arg_tagged_1 = GetCallArg(argv, 1); + JSHandle arg_tagged_0 = builtins_common::GetCallArg(argv, 0); + JSHandle arg_tagged_1 = builtins_common::GetCallArg(argv, 1); ASSERT(arg_tagged_0->IsCallable()); auto *js_method = JSHandle::Cast(arg_tagged_0)->GetCallTarget(); @@ -146,12 +166,12 @@ JSTaggedValue BuiltinsRuntimeTesting::OptimizeFunctionOnNextCall(EcmaRuntimeCall return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsRuntimeTesting::Exit(EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::Exit(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, Exit); - JSHandle arg_tagged = GetCallArg(argv, 0); + JSHandle arg_tagged = builtins_common::GetCallArg(argv, 0); ASSERT(arg_tagged->IsInt()); Runtime::Halt(arg_tagged->GetInt()); @@ -159,7 +179,7 @@ JSTaggedValue BuiltinsRuntimeTesting::Exit(EcmaRuntimeCallInfo *argv) } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::IsBeingInterpreted([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::IsBeingInterpreted([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, IsBeingInterpreted); @@ -167,7 +187,7 @@ JSTaggedValue BuiltinsRuntimeTesting::IsBeingInterpreted([[maybe_unused]] EcmaRu } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::DeoptimizeFunction([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::DeoptimizeFunction([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, DeoptimizeFunction); @@ -175,7 +195,7 @@ JSTaggedValue BuiltinsRuntimeTesting::DeoptimizeFunction([[maybe_unused]] EcmaRu } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::NeverOptimizeFunction([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::NeverOptimizeFunction([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, NeverOptimizeFunction); @@ -183,7 +203,7 @@ JSTaggedValue BuiltinsRuntimeTesting::NeverOptimizeFunction([[maybe_unused]] Ecm } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::DeoptimizeNow([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::DeoptimizeNow([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, DeoptimizeNow); @@ -191,7 +211,7 @@ JSTaggedValue BuiltinsRuntimeTesting::DeoptimizeNow([[maybe_unused]] EcmaRuntime } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::_DeoptimizeNow([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::_DeoptimizeNow([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, _DeoptimizeNow); @@ -199,7 +219,7 @@ JSTaggedValue BuiltinsRuntimeTesting::_DeoptimizeNow([[maybe_unused]] EcmaRuntim } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::ClearFunctionFeedback([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::ClearFunctionFeedback([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, ClearFunctionFeedback); @@ -207,7 +227,7 @@ JSTaggedValue BuiltinsRuntimeTesting::ClearFunctionFeedback([[maybe_unused]] Ecm } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::OptimizeOsr([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::OptimizeOsr([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, OptimizeOsr); @@ -215,7 +235,7 @@ JSTaggedValue BuiltinsRuntimeTesting::OptimizeOsr([[maybe_unused]] EcmaRuntimeCa } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::CompleteInobjectSlackTracking([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::CompleteInobjectSlackTracking([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, CompleteInobjectSlackTracking); @@ -223,7 +243,7 @@ JSTaggedValue BuiltinsRuntimeTesting::CompleteInobjectSlackTracking([[maybe_unus } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::IsDictPropertyConstTrackingEnbled([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::IsDictPropertyConstTrackingEnbled([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, IsDictPropertyConstTrackingEnbled); @@ -231,7 +251,7 @@ JSTaggedValue BuiltinsRuntimeTesting::IsDictPropertyConstTrackingEnbled([[maybe_ } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::StringMaxLength([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::StringMaxLength([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, StringMaxLength); @@ -239,7 +259,7 @@ JSTaggedValue BuiltinsRuntimeTesting::StringMaxLength([[maybe_unused]] EcmaRunti } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::TypedArrayMaxLength([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::TypedArrayMaxLength([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, TypedArrayMaxLength); @@ -247,7 +267,7 @@ JSTaggedValue BuiltinsRuntimeTesting::TypedArrayMaxLength([[maybe_unused]] EcmaR } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::DisableOptimizationFinalization([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::DisableOptimizationFinalization([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, DisableOptimizationFinalization); @@ -255,7 +275,7 @@ JSTaggedValue BuiltinsRuntimeTesting::DisableOptimizationFinalization([[maybe_un } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::WaitForBackgroundOptimization([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::WaitForBackgroundOptimization([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, WaitForBackgroundOptimization); @@ -263,7 +283,7 @@ JSTaggedValue BuiltinsRuntimeTesting::WaitForBackgroundOptimization([[maybe_unus } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::FinalizeOptimization([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::FinalizeOptimization([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, FinalizeOptimization); @@ -271,7 +291,7 @@ JSTaggedValue BuiltinsRuntimeTesting::FinalizeOptimization([[maybe_unused]] Ecma } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::ArrayBufferDetach([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::ArrayBufferDetach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, ArrayBufferDetach); @@ -279,7 +299,7 @@ JSTaggedValue BuiltinsRuntimeTesting::ArrayBufferDetach([[maybe_unused]] EcmaRun } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::EnsureFeedbackVectorForFunction([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::EnsureFeedbackVectorForFunction([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, EnsureFeedbackVectorForFunction); @@ -287,7 +307,7 @@ JSTaggedValue BuiltinsRuntimeTesting::EnsureFeedbackVectorForFunction([[maybe_un } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::SimulateNewspaceFull([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::SimulateNewspaceFull([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, SimulateNewspaceFull); @@ -295,7 +315,7 @@ JSTaggedValue BuiltinsRuntimeTesting::SimulateNewspaceFull([[maybe_unused]] Ecma } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::VerifyType([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::VerifyType([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, VerifyType); @@ -303,7 +323,7 @@ JSTaggedValue BuiltinsRuntimeTesting::VerifyType([[maybe_unused]] EcmaRuntimeCal } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::ToFastProperties([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::ToFastProperties([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, ToFastProperties); @@ -311,7 +331,7 @@ JSTaggedValue BuiltinsRuntimeTesting::ToFastProperties([[maybe_unused]] EcmaRunt } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::IsConcurrentRecompilationSupported([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::IsConcurrentRecompilationSupported([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, IsConcurrentRecompilationSupported); @@ -319,7 +339,7 @@ JSTaggedValue BuiltinsRuntimeTesting::IsConcurrentRecompilationSupported([[maybe } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::GetUndetectable([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::GetUndetectable([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, GetUndetectable); @@ -327,7 +347,7 @@ JSTaggedValue BuiltinsRuntimeTesting::GetUndetectable([[maybe_unused]] EcmaRunti } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::ToLength([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::ToLength([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, ToLength); @@ -335,7 +355,7 @@ JSTaggedValue BuiltinsRuntimeTesting::ToLength([[maybe_unused]] EcmaRuntimeCallI } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::RunningInSimulator([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::RunningInSimulator([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, RunningInSimulator); @@ -343,7 +363,7 @@ JSTaggedValue BuiltinsRuntimeTesting::RunningInSimulator([[maybe_unused]] EcmaRu } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::AllocateHeapNumber([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::AllocateHeapNumber([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, AllocateHeapNumber); @@ -351,7 +371,7 @@ JSTaggedValue BuiltinsRuntimeTesting::AllocateHeapNumber([[maybe_unused]] EcmaRu } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::PretenureAllocationSite([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::PretenureAllocationSite([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, PretenureAllocationSite); @@ -359,7 +379,7 @@ JSTaggedValue BuiltinsRuntimeTesting::PretenureAllocationSite([[maybe_unused]] E } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::MaxSmi([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::MaxSmi([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, MaxSmi); @@ -367,7 +387,7 @@ JSTaggedValue BuiltinsRuntimeTesting::MaxSmi([[maybe_unused]] EcmaRuntimeCallInf } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::CreatePrivateSymbol([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::CreatePrivateSymbol([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, CreatePrivateSymbol); @@ -375,7 +395,7 @@ JSTaggedValue BuiltinsRuntimeTesting::CreatePrivateSymbol([[maybe_unused]] EcmaR } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::CreatePrivateNameSymbol([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::CreatePrivateNameSymbol([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, CreatePrivateNameSymbol); @@ -383,7 +403,7 @@ JSTaggedValue BuiltinsRuntimeTesting::CreatePrivateNameSymbol([[maybe_unused]] E } // Not implemented -JSTaggedValue BuiltinsRuntimeTesting::Is64Bit([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue runtime_testing::Is64Bit([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RuntimeTesting, Is64Bit); diff --git a/runtime/builtins/builtins_runtime_testing.h b/runtime/builtins/builtins_runtime_testing.h deleted file mode 100644 index 74ce39c0b5ce05d4ce88dc526a4eda7aefe17670..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_runtime_testing.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_RUNTIME_TESTING_H -#define ECMASCRIPT_BUILTINS_BUILTINS_RUNTIME_TESTING_H -#ifndef PANDA_PRODUCT_BUILD - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { - -class BuiltinsRuntimeTesting : public base::BuiltinsBase { -public: - // A set of bits returned by GetOptimizationStatus. - enum class OptimizationStatus { - IS_FUNCTION = 1U << 0U, // NOLINT(readability-magic-numbers) - NEVER_OPTIMIZE = 1U << 1U, // NOLINT(readability-magic-numbers) - ALWAYS_OPTIMIZE = 1U << 2U, // NOLINT(readability-magic-numbers) - MAYBE_DEOPTED = 1U << 3U, // NOLINT(readability-magic-numbers) - OPTIMIZED = 1U << 4U, // NOLINT(readability-magic-numbers) - - INTERPRETED = 1U << 7U, // NOLINT(readability-magic-numbers) - MARKED_FOR_OPTIMIZATION = 1U << 8U, // NOLINT(readability-magic-numbers) - MARKED_FOR_CONCURRENT_OPTIMIZATION = 1U << 9U, // NOLINT(readability-magic-numbers) - OPTIMIZING_CONCURRENTLY = 1U << 10U, // NOLINT(readability-magic-numbers) - IS_EXECUTING = 1U << 11U, // NOLINT(readability-magic-numbers) - TOPMOST_FRAME_IS_COMPILED = 1U << 12U, // NOLINT(readability-magic-numbers) - LITE_MODE = 1U << 13U, // NOLINT(readability-magic-numbers) - MARKED_FOR_DEOPTIMIZATION = 1U << 14U, // NOLINT(readability-magic-numbers) - - TOPMOST_FRAME_IS_INTERPRETED = 1U << 16U, // NOLINT(readability-magic-numbers) - - IS_LAZY = 1U << 18U, // NOLINT(readability-magic-numbers) - }; - - static JSTaggedValue GetOptimizationStatus(EcmaRuntimeCallInfo *argv); - static JSTaggedValue PrepareFunctionForOptimization(EcmaRuntimeCallInfo *argv); - static JSTaggedValue OptimizeFunctionOnNextCall(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Exit(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue IsBeingInterpreted(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue DeoptimizeFunction(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue NeverOptimizeFunction(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue DeoptimizeNow(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue _DeoptimizeNow(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue ClearFunctionFeedback(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue OptimizeOsr(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue CompleteInobjectSlackTracking(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue IsDictPropertyConstTrackingEnbled(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue StringMaxLength(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue TypedArrayMaxLength(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue DisableOptimizationFinalization(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue WaitForBackgroundOptimization(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue FinalizeOptimization(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue ArrayBufferDetach(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue EnsureFeedbackVectorForFunction(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue SimulateNewspaceFull(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue VerifyType(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue ToFastProperties(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue IsConcurrentRecompilationSupported(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue GetUndetectable(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue ToLength(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue RunningInSimulator(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue AllocateHeapNumber(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue PretenureAllocationSite(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue MaxSmi(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue CreatePrivateSymbol(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue CreatePrivateNameSymbol(EcmaRuntimeCallInfo *argv); - - // Not implemented - static JSTaggedValue Is64Bit(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // PANDA_PRODUCT_BUILD -#endif // ECMASCRIPT_BUILTINS_BUILTINS_RUNTIME_TESTING_H \ No newline at end of file diff --git a/runtime/builtins/builtins_set.cpp b/runtime/builtins/builtins_set.cpp index ea8cc8255e3e92c4f3a835dcb65c45d88bb5f577..abe2d158f3cc7b3318bd9383490b885643e27fb7 100644 --- a/runtime/builtins/builtins_set.cpp +++ b/runtime/builtins/builtins_set.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_set.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -25,7 +25,7 @@ #include "plugins/ecmascript/runtime/tagged_array-inl.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::SetConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Constructor); @@ -33,13 +33,13 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let set be OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", «‍[[SetData]]» ). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -52,7 +52,7 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) // add data into set from iterable // 5.If iterable is not present, let iterable be undefined. // 6.If iterable is either undefined or null, let iter be undefined. - JSHandle iterable(GetCallArg(argv, 0)); + JSHandle iterable(builtins_common::GetCallArg(argv, 0)); // 8.If iter is undefined, return set if (iterable->IsUndefined() || iterable->IsNull()) { return set.GetTaggedValue(); @@ -103,13 +103,13 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) return set.GetTaggedValue(); } -JSTaggedValue BuiltinsSet::Add(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::Add(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Add); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. @@ -117,20 +117,20 @@ JSTaggedValue BuiltinsSet::Add(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception()); } - JSHandle value(GetCallArg(argv, 0)); + JSHandle value(builtins_common::GetCallArg(argv, 0)); JSHandle set(JSTaggedValue::ToObject(thread, self)); JSSet::Add(thread, set, value); return set.GetTaggedValue(); } -JSTaggedValue BuiltinsSet::Clear(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::Clear(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Clear); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. @@ -142,13 +142,13 @@ JSTaggedValue BuiltinsSet::Clear(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsSet::Delete(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::Delete(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Delete); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSSet()) { @@ -156,39 +156,39 @@ JSTaggedValue BuiltinsSet::Delete(EcmaRuntimeCallInfo *argv) } JSHandle set(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); bool flag = JSSet::Delete(thread, set, value); - return GetTaggedBoolean(flag); + return builtins_common::GetTaggedBoolean(flag); } -JSTaggedValue BuiltinsSet::Has(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::Has(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Has); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSSet()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception()); } JSHandle js_set(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); bool flag = false; if (JSSet::IsKey(value.GetTaggedValue())) { int hash = LinkedHash::Hash(value.GetTaggedValue()); flag = js_set->Has(value.GetTaggedValue(), hash); } - return GetTaggedBoolean(flag); + return builtins_common::GetTaggedBoolean(flag); } -JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSSet()) { @@ -197,13 +197,13 @@ JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSHandle set(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); // 4.If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle func(GetCallArg(argv, 0)); + JSHandle func(builtins_common::GetCallArg(argv, 0)); if (!func->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "callbackfn is not callable", JSTaggedValue::Exception()); } // 5.If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg = GetCallArg(argv, 1); + JSHandle this_arg = builtins_common::GetCallArg(argv, 1); // composed arguments JSHandle iter(factory->NewJSSetIterator(set, IterationKind::KEY)); @@ -223,18 +223,18 @@ JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsSet::Species([[maybe_unused]] EcmaRuntimeCallInfo *argv) +JSTaggedValue set::GetSpecies([[maybe_unused]] EcmaRuntimeCallInfo *argv) { - return GetThis(argv).GetTaggedValue(); + return builtins_common::GetThis(argv).GetTaggedValue(); } -JSTaggedValue BuiltinsSet::GetSize(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::GetSize(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, GetSize); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSSet()) { @@ -245,24 +245,24 @@ JSTaggedValue BuiltinsSet::GetSize(EcmaRuntimeCallInfo *argv) return JSTaggedValue(count); } -JSTaggedValue BuiltinsSet::Entries(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::Entries(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Entries); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::KEY_AND_VALUE); return iter.GetTaggedValue(); } -JSTaggedValue BuiltinsSet::Values(EcmaRuntimeCallInfo *argv) +JSTaggedValue set::proto::Values(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Values); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); JSHandle iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::VALUE); return iter.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_set.h b/runtime/builtins/builtins_set.h deleted file mode 100644 index 51d893c77d60520b0f4fc2aca533727f378f3e28..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_set.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_SET_H -#define ECMASCRIPT_BUILTINS_BUILTINS_SET_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsSet : public ecmascript::base::BuiltinsBase { -public: - // 23.2.1.1 - static JSTaggedValue SetConstructor(EcmaRuntimeCallInfo *argv); - // 23.2.2.2 - static JSTaggedValue Species(EcmaRuntimeCallInfo *argv); - // 23.2.3.1 - static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); - // 23.2.3.2 - static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); - // 23.2.3.4 - static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv); - // 23.2.3.5 - static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); - // 23.2.3.6 - static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); - // 23.2.3.7 - static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); - // 23.2.3.9 - static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv); - // 23.2.3.10 - static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_SET_H diff --git a/runtime/builtins/builtins_string.cpp b/runtime/builtins/builtins_string.cpp index e4ad3ff5730032c922b1b56864db854cfef42dab..a6b955a5155d73b0bed309d82663fca51b57aef7 100644 --- a/runtime/builtins/builtins_string.cpp +++ b/runtime/builtins/builtins_string.cpp @@ -13,15 +13,12 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_string.h" - #include +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/number_helper.h" #include "plugins/ecmascript/runtime/base/string_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_json.h" #include "plugins/ecmascript/runtime/builtins/builtins_regexp.h" -#include "plugins/ecmascript/runtime/builtins/builtins_symbol.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string-inl.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -48,19 +45,29 @@ namespace panda::ecmascript::builtins { using ObjectFactory = ecmascript::ObjectFactory; using JSArray = ecmascript::JSArray; +constexpr int32_t ENCODE_MAX_UTF16 = 0X10FFFF; +constexpr uint16_t ENCODE_LEAD_LOW = 0xD800; +constexpr uint16_t ENCODE_TRAIL_LOW = 0xDC00; +constexpr uint32_t ENCODE_FIRST_FACTOR = 0x400; +constexpr uint32_t ENCODE_SECOND_FACTOR = 0x10000; + +static int32_t ConvertDoubleToInt(double d); +// 21.1.3 +static JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value); + // 21.1.1.1 String(value) -JSTaggedValue BuiltinsString::StringConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::StringConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (argv->GetArgsNumber() > 0) { - JSHandle val_tag_new = GetCallArg(argv, 0); + JSHandle val_tag_new = builtins_common::GetCallArg(argv, 0); if (new_target->IsUndefined() && val_tag_new->IsSymbol()) { - return BuiltinsSymbol::SymbolDescriptiveString(thread, val_tag_new.GetTaggedValue()); + return symbol::SymbolDescriptiveString(thread, val_tag_new.GetTaggedValue()); } JSHandle str = JSTaggedValue::ToString(thread, val_tag_new); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -79,7 +86,7 @@ JSTaggedValue BuiltinsString::StringConstructor(EcmaRuntimeCallInfo *argv) } // 21.1.2.1 -JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::FromCharCode(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, FromCharCode); @@ -90,7 +97,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) if (arg_length == 0) { return factory->GetEmptyString().GetTaggedValue(); } - JSHandle code_point_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle code_point_tag = builtins_common::GetCallArg(argv, 0); uint16_t code_point_value = JSTaggedValue::ToUint16(thread, code_point_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle str_handle = factory->NewFromUtf16Literal(&code_point_value, 1); @@ -101,7 +108,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) PandaVector value_table; value_table.reserve(arg_length - 1); for (int32_t i = 1; i < arg_length; i++) { - JSHandle next_cp = BuiltinsString::GetCallArg(argv, i); + JSHandle next_cp = builtins_common::GetCallArg(argv, i); uint16_t next_cv = JSTaggedValue::ToUint16(thread, next_cp); value_table.emplace_back(next_cv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -116,7 +123,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) } // 21.1.2.2 -JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::FromCodePoint(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, FromCodePoint); @@ -130,7 +137,7 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) std::u16string u16str; int32_t u16str_size = arg_length; for (int i = 0; i < arg_length; i++) { - JSHandle next_cp_tag = BuiltinsString::GetCallArg(argv, i); + JSHandle next_cp_tag = builtins_common::GetCallArg(argv, i); JSTaggedNumber next_cp_val = JSTaggedValue::ToNumber(thread, next_cp_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!next_cp_val.IsInteger()) { @@ -165,7 +172,7 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) } // 21.1.2.4 -JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::Raw(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Raw); @@ -173,7 +180,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Let cooked be ToObject(template). - JSHandle cooked = JSTaggedValue::ToObject(thread, BuiltinsString::GetCallArg(argv, 0)); + JSHandle cooked = JSTaggedValue::ToObject(thread, builtins_common::GetCallArg(argv, 0)); // ReturnIfAbrupt(cooked). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let raw be ToObject(Get(cooked, "raw")). @@ -215,7 +222,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) break; } if (args_i <= argc) { - EcmaString *next_sub = *JSTaggedValue::ToString(thread, GetCallArg(argv, args_i)); + EcmaString *next_sub = *JSTaggedValue::ToString(thread, builtins_common::GetCallArg(argv, args_i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (next_sub->IsUtf16()) { u16str += @@ -233,18 +240,18 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) } // 21.1.3.1 -JSTaggedValue BuiltinsString::CharAt(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::CharAt(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, CharAt); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 0); int32_t pos; if (pos_tag->IsUndefined()) { pos = 0; @@ -261,17 +268,17 @@ JSTaggedValue BuiltinsString::CharAt(EcmaRuntimeCallInfo *argv) } // 21.1.3.2 -JSTaggedValue BuiltinsString::CharCodeAt(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::CharCodeAt(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, CharCodeAt); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 0); int32_t pos; if (pos_tag->IsUndefined()) { pos = 0; @@ -281,23 +288,23 @@ JSTaggedValue BuiltinsString::CharCodeAt(EcmaRuntimeCallInfo *argv) pos = pos_val.ToInt32(); } if (pos < 0 || pos >= this_len) { - return GetTaggedDouble(ecmascript::base::NAN_VALUE); + return builtins_common::GetTaggedDouble(ecmascript::base::NAN_VALUE); } uint16_t ret = this_handle->At(pos); - return GetTaggedInt(ret); + return builtins_common::GetTaggedInt(ret); } // 21.1.3.3 -JSTaggedValue BuiltinsString::CodePointAt(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::CodePointAt(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, CodePointAt); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 0); JSTaggedNumber pos_val = JSTaggedValue::ToNumber(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -308,25 +315,25 @@ JSTaggedValue BuiltinsString::CodePointAt(EcmaRuntimeCallInfo *argv) } uint16_t first = this_handle->At(pos); if (first < utf::DECODE_LEAD_LOW || first > utf::DECODE_LEAD_HIGH || pos + 1 == this_len) { - return GetTaggedInt(first); + return builtins_common::GetTaggedInt(first); } uint16_t second = this_handle->At(pos + 1); if (second < utf::DECODE_TRAIL_LOW || second > utf::DECODE_TRAIL_HIGH) { - return GetTaggedInt(first); + return builtins_common::GetTaggedInt(first); } uint32_t res = utf::UTF16Decode(first, second); - return GetTaggedInt(res); + return builtins_common::GetTaggedInt(res); } // 21.1.3.4 -JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Concat(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Concat); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); @@ -344,7 +351,7 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(this_handle->GetDataUtf8(), this_len); } for (int i = 0; i < arg_length; i++) { - JSHandle next_tag = BuiltinsString::GetCallArg(argv, i); + JSHandle next_tag = builtins_common::GetCallArg(argv, i); JSHandle next_handle = JSTaggedValue::ToString(thread, next_tag); int32_t next_len = next_handle->GetLength(); if (next_handle->IsUtf16()) { @@ -364,14 +371,14 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) // 21.1.3.5 String.prototype.constructor // 21.1.3.6 -JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::EndsWith(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, EndsWith); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool is_regexp = JSObject::IsRegExp(thread, search_tag); @@ -383,7 +390,7 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) int32_t this_len = this_handle->GetLength(); int32_t search_len = search_handle->GetLength(); int32_t pos; - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); if (pos_tag->IsUndefined()) { pos = this_len; } else { @@ -394,7 +401,7 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) int32_t end = std::min(std::max(pos, 0), this_len); int32_t start = end - search_len; if (start < 0) { - return BuiltinsString::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } std::u16string u16str_this; std::u16string u16str_search; @@ -412,20 +419,20 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) } int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, start); if (idx == start) { - return BuiltinsString::GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } - return BuiltinsString::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 21.1.3.7 -JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Includes(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Includes); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool is_regexp = JSObject::IsRegExp(thread, search_tag); @@ -437,7 +444,7 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) int32_t this_len = this_handle->GetLength(); int32_t search_len = search_handle->GetLength(); int32_t pos = 0; - JSHandle pos_tag = BuiltinsBase::GetCallArg(argv, 1); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); if (argv->GetArgsNumber() == 1) { pos = 0; } else { @@ -462,26 +469,26 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) } int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, start); if (idx < 0 || idx > this_len) { - return BuiltinsString::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } - return BuiltinsString::GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // 21.1.3.8 -JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::IndexOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, IndexOf); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t this_len = this_handle->GetLength(); JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); int32_t pos; if (pos_tag->IsInt()) { pos = pos_tag->GetInt(); @@ -495,20 +502,20 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv) pos = std::min(std::max(pos, 0), static_cast(this_len)); int32_t res = this_handle->IndexOf(*search_handle, pos); if (res >= 0 && res < static_cast(this_len)) { - return GetTaggedInt(res); + return builtins_common::GetTaggedInt(res); } - return GetTaggedInt(-1); + return builtins_common::GetTaggedInt(-1); } // 21.1.3.9 -JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, LastIndexOf); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); @@ -519,7 +526,7 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) if (argv->GetArgsNumber() == 1) { pos = this_len; } else { - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (std::isnan(JSTaggedValue::ToNumber(thread, pos_tag).GetNumber())) { @@ -545,39 +552,39 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) } int32_t res = ecmascript::base::StringHelper::RFind(u16str_this, u16str_search, pos); if (res >= 0 && res < this_len) { - return GetTaggedInt(res); + return builtins_common::GetTaggedInt(res); } res = -1; - return GetTaggedInt(res); + return builtins_common::GetTaggedInt(res); } // 21.1.3.10 -JSTaggedValue BuiltinsString::LocaleCompare(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::LocaleCompare(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, LocaleCompare); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle that_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle that_tag = builtins_common::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle that_handle = JSTaggedValue::ToString(thread, that_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t res = this_handle->Compare(*that_handle); - return GetTaggedInt(res); + return builtins_common::GetTaggedInt(res); } // 21.1.3.11 -JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Match(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Match); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle regexp = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle regexp = builtins_common::GetCallArg(argv, 0); JSHandle match_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); if (regexp->IsJSRegExp()) { JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); @@ -606,7 +613,7 @@ JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv) JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle undifined_handle = global_const->GetHandledUndefined(); - JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifined_handle)); + JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, undifined_handle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); @@ -614,7 +621,7 @@ JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv) return JSFunction::Invoke(info.Get(), match_tag); } -JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::MatchAll(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, MatchAll); @@ -622,8 +629,8 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. Let O be ? RequireObjectCoercible(this value). - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle regexp = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle regexp = builtins_common::GetCallArg(argv, 0); JSHandle match_all_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchAllSymbol(); JSHandle gvalue(global_const->GetHandledGString()); @@ -670,7 +677,7 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let rx be ? RegExpCreate(regexp, "g"). - JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, gvalue)); + JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, gvalue)); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); info->SetCallArgs(this_val.GetTaggedValue()); @@ -678,21 +685,21 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) } // 21.1.3.12 -JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Normalize(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Normalize); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); JSHandle form_value; if (argv->GetArgsNumber() == 0) { form_value = factory->NewFromString("NFC"); } else { - JSHandle form_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle form_tag = builtins_common::GetCallArg(argv, 0); if (form_tag->IsUndefined()) { form_value = factory->NewFromString("NFC"); } else { @@ -740,43 +747,43 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv) } // ES2021 22.1.3.14 -JSTaggedValue BuiltinsString::PadEnd(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::PadEnd(EcmaRuntimeCallInfo *argv) { // 1. Let O be ? RequireObjectCoercible(this value). JSThread *thread = argv->GetThread(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return ? StringPad(O, maxLength, fillString, start). - return base::StringHelper::StringPad(thread, this_tag, BuiltinsString::GetCallArg(argv, 0), - BuiltinsString::GetCallArg(argv, 1), base::PadPlacement::END); + return base::StringHelper::StringPad(thread, this_tag, builtins_common::GetCallArg(argv, 0), + builtins_common::GetCallArg(argv, 1), base::PadPlacement::END); } // ES2021 22.1.3.15 -JSTaggedValue BuiltinsString::PadStart(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::PadStart(EcmaRuntimeCallInfo *argv) { // 1. Let O be ? RequireObjectCoercible(this value). JSThread *thread = argv->GetThread(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return ? StringPad(O, maxLength, fillString, start). - return base::StringHelper::StringPad(thread, this_tag, BuiltinsString::GetCallArg(argv, 0), - BuiltinsString::GetCallArg(argv, 1), base::PadPlacement::START); + return base::StringHelper::StringPad(thread, this_tag, builtins_common::GetCallArg(argv, 0), + builtins_common::GetCallArg(argv, 1), base::PadPlacement::START); } // 21.1.3.13 -JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Repeat(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Repeat); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); - JSHandle count_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle count_tag = builtins_common::GetCallArg(argv, 0); JSTaggedNumber num = JSTaggedValue::ToInteger(thread, count_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double d = num.GetNumber(); @@ -805,20 +812,20 @@ JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv) } // 21.1.3.14 -JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Replace(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Replace); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); + JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto ecma_vm = thread->GetEcmaVM(); JSHandle env = ecma_vm->GetGlobalEnv(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle replace_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); + JSHandle replace_tag = builtins_common::GetCallArg(argv, 1); ObjectFactory *factory = ecma_vm->GetFactory(); @@ -892,7 +899,7 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) JSHandle replacement(thread, replace_tag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) repl_handle.Update( - GetSubstitution(thread, search_string, this_string, pos, captures_list, undefined, replacement)); + string::GetSubstitution(thread, search_string, this_string, pos, captures_list, undefined, replacement)); } JSHandle real_replace_str = JSTaggedValue::ToString(thread, repl_handle); // Let tailPos be pos + the number of code units in matched. @@ -910,20 +917,20 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) // ES2021 22.1.3.18 // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ReplaceAll(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, String, ReplaceAll); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); + JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto ecma_vm = thread->GetEcmaVM(); JSHandle env = ecma_vm->GetGlobalEnv(); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle replace_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); + JSHandle replace_tag = builtins_common::GetCallArg(argv, 1); ObjectFactory *factory = ecma_vm->GetFactory(); @@ -1009,8 +1016,8 @@ JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) ASSERT_PRINT(replace_tag->IsString(), "replace must be string"); JSHandle replacement(thread, replace_tag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) - repl_handle.Update( - GetSubstitution(thread, search_string, this_string, pos, captures_list, undefined, replacement)); + repl_handle.Update(string::GetSubstitution(thread, search_string, this_string, pos, captures_list, + undefined, replacement)); } JSHandle real_replace_str = JSTaggedValue::ToString(thread, repl_handle); // Let tailPos be pos + the number of code units in matched. @@ -1063,12 +1070,13 @@ JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) return factory->NewFromUtf16LiteralUnCheck(uint16t_data, string_builder.length(), can_be_compress).GetTaggedValue(); } +// 21.1.3.14.1 Runtime Semantics: GetSubstitution() // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle &matched, - const JSHandle &src_string, int position, - const JSHandle &capture_list, - const JSHandle &named_captures, - const JSHandle &replacement) +JSTaggedValue string::GetSubstitution(JSThread *thread, const JSHandle &matched, + const JSHandle &src_string, int position, + const JSHandle &capture_list, + const JSHandle &named_captures, + const JSHandle &replacement) { BUILTINS_API_TRACE(thread, String, GetSubstitution); auto ecma_vm = thread->GetEcmaVM(); @@ -1279,15 +1287,15 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleGetThread(), String, Search); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); const GlobalEnvConstants *global_const = thread->GlobalConstants(); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle regexp = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); + JSHandle regexp = builtins_common::GetCallArg(argv, 0); JSHandle search_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetSearchSymbol(); if (!regexp->IsUndefined() && !regexp->IsNull()) { if (regexp->IsECMAObject()) { @@ -1305,7 +1313,7 @@ JSTaggedValue BuiltinsString::Search(EcmaRuntimeCallInfo *argv) JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle undifined_handle = global_const->GetHandledUndefined(); - JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifined_handle)); + JSHandle rx(thread, reg_exp::RegExpCreate(thread, regexp, undifined_handle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); @@ -1314,23 +1322,23 @@ JSTaggedValue BuiltinsString::Search(EcmaRuntimeCallInfo *argv) } // 21.1.3.16 -JSTaggedValue BuiltinsString::Slice(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Slice(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Slice); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); - JSHandle start_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle start_tag = builtins_common::GetCallArg(argv, 0); JSTaggedNumber start_val = JSTaggedValue::ToInteger(thread, start_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t start = ConvertDoubleToInt(start_val.GetNumber()); int32_t end; - JSHandle end_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle end_tag = builtins_common::GetCallArg(argv, 1); if (end_tag->IsUndefined()) { end = this_len; } else { @@ -1355,7 +1363,7 @@ JSTaggedValue BuiltinsString::Slice(EcmaRuntimeCallInfo *argv) } // 21.1.3.17 -JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Split(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Split); @@ -1365,11 +1373,11 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) JSHandle env = ecma_vm->GetGlobalEnv(); // Let O be RequireObjectCoercible(this value). - JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)); + JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv)); JSHandle this_obj(this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle seperator_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle limit_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle seperator_tag = builtins_common::GetCallArg(argv, 0); + JSHandle limit_tag = builtins_common::GetCallArg(argv, 1); // If separator is neither undefined nor null, then if (seperator_tag->IsECMAObject()) { JSHandle split_key = env->GetSplitSymbol(); @@ -1460,32 +1468,16 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) return result_array.GetTaggedValue(); } -int32_t BuiltinsString::SplitMatch(const JSHandle &str, int32_t q, const JSHandle ®) -{ - int32_t s = str->GetLength(); - int32_t r = reg->GetLength(); - if (q + r > s) { - return -1; - } - int32_t i = 0; - for (i = 0; i < r; i++) { - if (str->At(q + i) != reg->At(i)) { - return -1; - } - } - return q + r; -} - // 21.1.3.18 -JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::StartsWith(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, StartsWith); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle search_tag = builtins_common::GetCallArg(argv, 0); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool is_regexp = JSObject::IsRegExp(thread, search_tag); @@ -1498,7 +1490,7 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) int32_t this_len = this_handle->GetLength(); int32_t search_len = search_handle->GetLength(); int32_t pos; - JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle pos_tag = builtins_common::GetCallArg(argv, 1); if (pos_tag->IsUndefined()) { pos = 0; } else { @@ -1508,7 +1500,7 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) } pos = std::min(std::max(pos, 0), this_len); if (pos + search_len > this_len) { - return BuiltinsString::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } std::u16string u16str_this; std::u16string u16str_search; @@ -1526,29 +1518,29 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) } int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, pos); if (idx == pos) { - return BuiltinsString::GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } - return BuiltinsString::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 21.1.3.19 -JSTaggedValue BuiltinsString::Substring(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Substring(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Substring); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t this_len = this_handle->GetLength(); - JSHandle start_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle start_tag = builtins_common::GetCallArg(argv, 0); JSTaggedNumber start_val = JSTaggedValue::ToInteger(thread, start_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t start = ConvertDoubleToInt(start_val.GetNumber()); int32_t end; - JSHandle end_tag = BuiltinsString::GetCallArg(argv, 1); + JSHandle end_tag = builtins_common::GetCallArg(argv, 1); if (end_tag->IsUndefined()) { end = this_len; } else { @@ -1565,7 +1557,7 @@ JSTaggedValue BuiltinsString::Substring(EcmaRuntimeCallInfo *argv) } // 21.1.3.20 -JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToLocaleLowerCase); @@ -1575,14 +1567,14 @@ JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let O be RequireObjectCoercible(this value). - JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); // Let S be ? ToString(O). JSHandle string = JSTaggedValue::ToString(thread, obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1634,7 +1626,7 @@ JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) } // 21.1.3.21 -JSTaggedValue BuiltinsString::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToLocaleLowerCase); @@ -1644,14 +1636,14 @@ JSTaggedValue BuiltinsString::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let O be RequireObjectCoercible(this value). - JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); // Let S be ? ToString(O). JSHandle string = JSTaggedValue::ToString(thread, obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let requestedLocales be ? CanonicalizeLocaleList(locales). - JSHandle locales = GetCallArg(argv, 0); + JSHandle locales = builtins_common::GetCallArg(argv, 0); JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1707,7 +1699,7 @@ static std::u16string ToU16String(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle this_tag( - JSTaggedValue::RequireObjectCoercible(thread, ecmascript::base::BuiltinsBase::GetThis(argv))); + JSTaggedValue::RequireObjectCoercible(thread, ecmascript::builtins_common::GetThis(argv))); JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); if (UNLIKELY(thread->HasPendingException())) { return std::u16string(); @@ -1723,7 +1715,7 @@ static std::u16string ToU16String(EcmaRuntimeCallInfo *argv) } // 21.1.3.22 -JSTaggedValue BuiltinsString::ToLowerCase(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ToLowerCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToLowerCase); @@ -1735,14 +1727,14 @@ JSTaggedValue BuiltinsString::ToLowerCase(EcmaRuntimeCallInfo *argv) } // 21.1.3.23 -JSTaggedValue BuiltinsString::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - return ThisStringValue(argv->GetThread(), GetThis(argv).GetTaggedValue()); + return ThisStringValue(argv->GetThread(), builtins_common::GetThis(argv).GetTaggedValue()); } // 21.1.3.24 -JSTaggedValue BuiltinsString::ToUpperCase(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ToUpperCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToUpperCase); @@ -1754,7 +1746,7 @@ JSTaggedValue BuiltinsString::ToUpperCase(EcmaRuntimeCallInfo *argv) } // 21.1.3.25 -JSTaggedValue BuiltinsString::Trim(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Trim(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Trim); @@ -1766,7 +1758,7 @@ JSTaggedValue BuiltinsString::Trim(EcmaRuntimeCallInfo *argv) } // ES2021 22.1.3.30 -JSTaggedValue BuiltinsString::TrimEnd(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::TrimEnd(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Trim); @@ -1778,7 +1770,7 @@ JSTaggedValue BuiltinsString::TrimEnd(EcmaRuntimeCallInfo *argv) } // ES2021 22.1.3.31 -JSTaggedValue BuiltinsString::TrimStart(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::TrimStart(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Trim); @@ -1790,21 +1782,21 @@ JSTaggedValue BuiltinsString::TrimStart(EcmaRuntimeCallInfo *argv) } // 21.1.3.26 -JSTaggedValue BuiltinsString::ValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - return ThisStringValue(argv->GetThread(), GetThis(argv).GetTaggedValue()); + return ThisStringValue(argv->GetThread(), builtins_common::GetThis(argv).GetTaggedValue()); } // 21.1.3.27 -JSTaggedValue BuiltinsString::GetStringIterator(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Iterator(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, GetStringIterator); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(this value). - JSHandle current(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle current(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); // Let S be ToString(O). JSHandle string = JSTaggedValue::ToString(thread, current); @@ -1814,7 +1806,7 @@ JSTaggedValue BuiltinsString::GetStringIterator(EcmaRuntimeCallInfo *argv) } // B.2.3.1 -JSTaggedValue BuiltinsString::SubStr(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::Substr(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, SubStr); @@ -1825,18 +1817,18 @@ JSTaggedValue BuiltinsString::SubStr(EcmaRuntimeCallInfo *argv) // 1. Let O be RequireObjectCoercible(this value). // 2. Let S be ToString(O). - JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, builtins_common::GetThis(argv))); JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); // 3. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle int_start = GetCallArg(argv, 0); + JSHandle int_start = builtins_common::GetCallArg(argv, 0); // 4. Let intStart be ToInteger(start). JSTaggedNumber num_start = JSTaggedValue::ToInteger(thread, int_start); // 5. ReturnIfAbrupt(intStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); int32_t start = num_start.ToInt32(); - JSHandle length_tag = GetCallArg(argv, 1); + JSHandle length_tag = builtins_common::GetCallArg(argv, 1); // 6. If length is undefined, let end be +; otherwise let end be ToInteger(length). int32_t end; if (length_tag->IsUndefined()) { @@ -1863,19 +1855,19 @@ JSTaggedValue BuiltinsString::SubStr(EcmaRuntimeCallInfo *argv) return JSTaggedValue(EcmaString::FastSubString(this_string, start, result_length, thread->GetEcmaVM())); } -JSTaggedValue BuiltinsString::GetLength(EcmaRuntimeCallInfo *argv) +JSTaggedValue string::proto::GetLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); JSHandle this_string = JSTaggedValue::ToString(thread, this_handle); - return GetTaggedInt(this_string->GetLength()); + return builtins_common::GetTaggedInt(this_string->GetLength()); } // 21.1.3 -JSTaggedValue BuiltinsString::ThisStringValue(JSThread *thread, JSTaggedValue value) +JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value) { if (value.IsString()) { return value; @@ -1892,7 +1884,7 @@ JSTaggedValue BuiltinsString::ThisStringValue(JSThread *thread, JSTaggedValue va THROW_TYPE_ERROR_AND_RETURN(thread, "can not convert to String", JSTaggedValue::Exception()); } -int32_t BuiltinsString::ConvertDoubleToInt(double d) +int32_t ConvertDoubleToInt(double d) { if (std::isnan(d) || d == -ecmascript::base::POSITIVE_INFINITY) { return 0; diff --git a/runtime/builtins/builtins_string.h b/runtime/builtins/builtins_string.h deleted file mode 100644 index 88eb2f99f7b21e7a762104fc278193c69f97d4eb..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_string.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_STRING_H -#define ECMASCRIPT_BUILTINS_BUILTINS_STRING_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/js_tagged_value.h" - -namespace panda::ecmascript::builtins { -constexpr int32_t ENCODE_MAX_UTF16 = 0X10FFFF; -constexpr uint16_t ENCODE_LEAD_LOW = 0xD800; -constexpr uint16_t ENCODE_TRAIL_LOW = 0xDC00; -constexpr uint32_t ENCODE_FIRST_FACTOR = 0x400; -constexpr uint32_t ENCODE_SECOND_FACTOR = 0x10000; -constexpr double DOUBLE_INT_MAX = static_cast(INT_MAX); -constexpr double DOUBLE_INT_MIN = static_cast(INT_MIN); - -class BuiltinsString : public ecmascript::base::BuiltinsBase { -public: - // 21.1.1.1 - static JSTaggedValue StringConstructor(EcmaRuntimeCallInfo *argv); - // 21.1.2.1 - static JSTaggedValue FromCharCode(EcmaRuntimeCallInfo *argv); - // 21.1.2.2 - static JSTaggedValue FromCodePoint(EcmaRuntimeCallInfo *argv); - // 21.1.2.4 - static JSTaggedValue Raw(EcmaRuntimeCallInfo *argv); - // 21.1.3.14.1 Runtime Semantics: GetSubstitution() - static JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle &matched, - const JSHandle &src_string, int position, - const JSHandle &capture_list, - const JSHandle &named_captures, - const JSHandle &replacement); - // 21.1.3.1 - static JSTaggedValue CharAt(EcmaRuntimeCallInfo *argv); - // 21.1.3.2 - static JSTaggedValue CharCodeAt(EcmaRuntimeCallInfo *argv); - // 21.1.3.3 - static JSTaggedValue CodePointAt(EcmaRuntimeCallInfo *argv); - // 21.1.3.4 - static JSTaggedValue Concat(EcmaRuntimeCallInfo *argv); - // 21.1.3.5 String.prototype.constructor - // 21.1.3.6 - static JSTaggedValue EndsWith(EcmaRuntimeCallInfo *argv); - // 21.1.3.7 - static JSTaggedValue Includes(EcmaRuntimeCallInfo *argv); - // 21.1.3.8 - static JSTaggedValue IndexOf(EcmaRuntimeCallInfo *argv); - // 21.1.3.9 - static JSTaggedValue LastIndexOf(EcmaRuntimeCallInfo *argv); - // 21.1.3.10 - static JSTaggedValue LocaleCompare(EcmaRuntimeCallInfo *argv); - // 21.1.3.11 - static JSTaggedValue Match(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue MatchAll(EcmaRuntimeCallInfo *argv); - // 21.1.3.12 - static JSTaggedValue Normalize(EcmaRuntimeCallInfo *argv); - // ES2021 22.1.3.14 - static JSTaggedValue PadEnd(EcmaRuntimeCallInfo *argv); - // ES2021 22.1.3.15 - static JSTaggedValue PadStart(EcmaRuntimeCallInfo *argv); - // 21.1.3.13 - static JSTaggedValue Repeat(EcmaRuntimeCallInfo *argv); - // 21.1.3.14 - static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv); - // ES2021 22.1.3.18 - static JSTaggedValue ReplaceAll(EcmaRuntimeCallInfo *argv); - // 21.1.3.15 - static JSTaggedValue Search(EcmaRuntimeCallInfo *argv); - // 21.1.3.16 - static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); - // 21.1.3.17 - static JSTaggedValue Split(EcmaRuntimeCallInfo *argv); - // 21.1.3.17.1 Runtime Semantics: SplitMatch - // 21.1.3.18 - static JSTaggedValue StartsWith(EcmaRuntimeCallInfo *argv); - // 21.1.3.19 - static JSTaggedValue Substring(EcmaRuntimeCallInfo *argv); - // 21.1.3.20 - static JSTaggedValue ToLocaleLowerCase(EcmaRuntimeCallInfo *argv); - // 21.1.3.21 - static JSTaggedValue ToLocaleUpperCase(EcmaRuntimeCallInfo *argv); - // 21.1.3.22 - static JSTaggedValue ToLowerCase(EcmaRuntimeCallInfo *argv); - // 21.1.3.23 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 21.1.3.24 - static JSTaggedValue ToUpperCase(EcmaRuntimeCallInfo *argv); - // 21.1.3.25 - static JSTaggedValue Trim(EcmaRuntimeCallInfo *argv); - // ES2021 22.1.3.30 - static JSTaggedValue TrimEnd(EcmaRuntimeCallInfo *argv); - // ES2021 22.1.3.31 - static JSTaggedValue TrimStart(EcmaRuntimeCallInfo *argv); - // 21.1.3.26 - static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); - // 21.1.3.27 - static JSTaggedValue GetStringIterator(EcmaRuntimeCallInfo *argv); - // 21.1.3 - static JSTaggedValue ThisStringValue(JSThread *thread, JSTaggedValue value); - // 21.1.2.27 - static JSTaggedValue CreateIterator(EcmaRuntimeCallInfo *argv); - // 10.1.2 - static uint16_t UTF16Decode(uint16_t lead, uint16_t trail); - // annexB B.2.3.1 - static JSTaggedValue SubStr(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv); - -private: - static int32_t ConvertDoubleToInt(double d); - // 21.1.3.17.1 - static int32_t SplitMatch(const JSHandle &str, int32_t q, const JSHandle ®); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_STRING_H diff --git a/runtime/builtins/builtins_string_iterator.cpp b/runtime/builtins/builtins_string_iterator.cpp index 2adc17e154cbc676585ec7c047a860cc56939f36..839d5cc07f075ddd4e87da2162e697dda6b75a0e 100644 --- a/runtime/builtins/builtins_string_iterator.cpp +++ b/runtime/builtins/builtins_string_iterator.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_string_iterator.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/string_helper.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/js_iterator.h" @@ -23,14 +23,15 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) +// 21.1.5.2.1 +JSTaggedValue string_iterator::proto::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringIterator, Next); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_value = GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. // 3. If O does not have all of the internal slots of an String Iterator Instance (21.1.5.3), // throw a TypeError exception. diff --git a/runtime/builtins/builtins_string_iterator.h b/runtime/builtins/builtins_string_iterator.h deleted file mode 100644 index 815313e225c08160723b84d3aa9b88f29316f88b..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_string_iterator.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_STRING_ITERATOR_H -#define ECMASCRIPT_BUILTINS_BUILTINS_STRING_ITERATOR_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsStringIterator : public ecmascript::base::BuiltinsBase { -public: - // 21.1.5.2.1 - static JSTaggedValue Next(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_STRING_ITERATOR_H diff --git a/runtime/builtins/builtins_symbol.cpp b/runtime/builtins/builtins_symbol.cpp index 8fb82483938fb325d0f7cd7bfca4214251aee44a..14b62ef188993fd481dd10ac8deb9d806dc64312 100644 --- a/runtime/builtins/builtins_symbol.cpp +++ b/runtime/builtins/builtins_symbol.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_symbol.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -25,18 +25,21 @@ #include "utils/bit_utils.h" namespace panda::ecmascript::builtins { + +static JSTaggedValue ThisSymbolValue(JSThread *thread, const JSHandle &value); + // prototype // 19.4.3.1 // constructor -JSTaggedValue BuiltinsSymbol::SymbolConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue symbol::SymbolConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, Constructor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If NewTarget is not undefined, throw a TypeError exception. - JSHandle key = GetCallArg(argv, 0); - JSHandle new_target = GetNewTarget(argv); + JSHandle key = builtins_common::GetCallArg(argv, 0); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (!new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "SymbolConstructor: NewTarget is not undefined", JSTaggedValue::Exception()); @@ -57,14 +60,14 @@ JSTaggedValue BuiltinsSymbol::SymbolConstructor(EcmaRuntimeCallInfo *argv) } // 19.4.3.2 Symbol.prototype.toString() -JSTaggedValue BuiltinsSymbol::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue symbol::proto::ToString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, ToString); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let s be the this value. - JSHandle value_handle = GetThis(argv); + JSHandle value_handle = builtins_common::GetThis(argv); // 2.If Type(s) is Symbol, let sym be s. JSTaggedValue sym = value_handle.GetTaggedValue(); // 3.Else @@ -84,10 +87,10 @@ JSTaggedValue BuiltinsSymbol::ToString(EcmaRuntimeCallInfo *argv) } } // Return SymbolDescriptiveString(sym). - return SymbolDescriptiveString(thread, sym); + return symbol::SymbolDescriptiveString(thread, sym); } -JSTaggedValue BuiltinsSymbol::SymbolDescriptiveString(JSThread *thread, JSTaggedValue sym) +JSTaggedValue symbol::SymbolDescriptiveString(JSThread *thread, JSTaggedValue sym) { BUILTINS_API_TRACE(thread, Symbol, SymbolDescriptiveString); // Assert: Type(sym) is Symbol. @@ -118,14 +121,14 @@ JSTaggedValue BuiltinsSymbol::SymbolDescriptiveString(JSThread *thread, JSTagged } // 19.4.3.3 -JSTaggedValue BuiltinsSymbol::ValueOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue symbol::proto::ValueOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, ValueOf); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let s be the this value. - JSHandle value_handle = GetThis(argv); + JSHandle value_handle = builtins_common::GetThis(argv); // If Type(s) is Symbol, return s. if (value_handle->IsSymbol()) { return value_handle.GetTaggedValue(); @@ -147,14 +150,14 @@ JSTaggedValue BuiltinsSymbol::ValueOf(EcmaRuntimeCallInfo *argv) } // 19.4.2.1 Symbol.for (key) -JSTaggedValue BuiltinsSymbol::For(EcmaRuntimeCallInfo *argv) +JSTaggedValue symbol::For(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, For); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let stringKey be ToString(key). - JSHandle key = BuiltinsSymbol::GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); JSHandle string_handle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); // 2.ReturnIfAbrupt RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -171,14 +174,14 @@ JSTaggedValue BuiltinsSymbol::For(EcmaRuntimeCallInfo *argv) } // 19.4.2.5 Symbol.keyFor (sym) -JSTaggedValue BuiltinsSymbol::KeyFor(EcmaRuntimeCallInfo *argv) +JSTaggedValue symbol::KeyFor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, KeyFor); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(sym) is not Symbol, throw a TypeError exception. - JSHandle sym = BuiltinsSymbol::GetCallArg(argv, 0); + JSHandle sym = builtins_common::GetCallArg(argv, 0); if (!sym->IsSymbol()) { // return typeError THROW_TYPE_ERROR_AND_RETURN(thread, "KeyFor: sym is not Symbol", JSTaggedValue::Exception()); @@ -197,7 +200,7 @@ JSTaggedValue BuiltinsSymbol::KeyFor(EcmaRuntimeCallInfo *argv) } // 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint ) -JSTaggedValue BuiltinsSymbol::ToPrimitive(EcmaRuntimeCallInfo *argv) +JSTaggedValue symbol::proto::ToPrimitive(EcmaRuntimeCallInfo *argv) { // The allowed values for hint are "default", "number", and "string". ASSERT(argv); @@ -205,7 +208,7 @@ JSTaggedValue BuiltinsSymbol::ToPrimitive(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let s be the this value. - JSHandle sym = GetThis(argv); + JSHandle sym = builtins_common::GetThis(argv); // 2.If Type(s) is Symbol, return s. if (sym->IsSymbol()) { return sym.GetTaggedValue(); @@ -228,20 +231,21 @@ JSTaggedValue BuiltinsSymbol::ToPrimitive(EcmaRuntimeCallInfo *argv) return primitive; } -JSTaggedValue BuiltinsSymbol::DescriptionGetter(EcmaRuntimeCallInfo *argv) +// 19.4.3.2 get Symbol.prototype.description +JSTaggedValue symbol::proto::GetDescription(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, DescriptionGetter); // 1.Let s be the this value. JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle s = GetThis(argv); + JSHandle s = builtins_common::GetThis(argv); // 2.Let sym be ? thisSymbolValue(s). // 3.Return sym.[[Description]]. return ThisSymbolValue(thread, s); } -JSTaggedValue BuiltinsSymbol::ThisSymbolValue(JSThread *thread, const JSHandle &value) +JSTaggedValue ThisSymbolValue(JSThread *thread, const JSHandle &value) { BUILTINS_API_TRACE(thread, Symbol, ThisSymbolValue); if (value->IsSymbol()) { diff --git a/runtime/builtins/builtins_symbol.h b/runtime/builtins/builtins_symbol.h deleted file mode 100644 index 9cf538c12bb9c3393808115ce748fce81092edd5..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_symbol.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_SYMBOL_H -#define ECMASCRIPT_BUILTINS_BUILTINS_SYMBOL_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" -#include "plugins/ecmascript/runtime/js_tagged_value.h" - -namespace panda::ecmascript::builtins { -class BuiltinsSymbol : public ecmascript::base::BuiltinsBase { -public: - // 19.4.1 - static JSTaggedValue SymbolConstructor(EcmaRuntimeCallInfo *argv); - - // prototype - // 19.4.3.2 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 19.4.3.3 - static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv); - // 19.4.2.1 Symbol.for (key) - static JSTaggedValue For(EcmaRuntimeCallInfo *argv); - // 19.4.2.5 Symbol.keyFor (sym) - static JSTaggedValue KeyFor(EcmaRuntimeCallInfo *argv); - - // 19.4.3.2 get Symbol.prototype.description - static JSTaggedValue DescriptionGetter(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue ThisSymbolValue(JSThread *thread, const JSHandle &value); - - // 19.4.3.4 - static JSTaggedValue ToPrimitive(EcmaRuntimeCallInfo *argv); - - static JSTaggedValue SymbolDescriptiveString(JSThread *thread, JSTaggedValue sym); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_SYMBOL_H diff --git a/runtime/builtins/builtins_typedarray.cpp b/runtime/builtins/builtins_typedarray.cpp index 39208833a6d9a02402d5b85d92eda02c3f46fc29..b2df033b3664cad70b4a4c080eac5af70a762738 100644 --- a/runtime/builtins/builtins_typedarray.cpp +++ b/runtime/builtins/builtins_typedarray.cpp @@ -13,12 +13,10 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_typedarray.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" #include "plugins/ecmascript/runtime/base/typed_array_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_array.h" -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -35,11 +33,9 @@ namespace panda::ecmascript::builtins { using TypedArrayHelper = ecmascript::base::TypedArrayHelper; -using BuiltinsArray = builtins::BuiltinsArray; -using BuiltinsArrayBuffer = builtins::BuiltinsArrayBuffer; // 22.2.1 -JSTaggedValue BuiltinsTypedArray::TypedArrayBaseConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::TypedArrayBaseConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, BaseConstructor); @@ -47,21 +43,21 @@ JSTaggedValue BuiltinsTypedArray::TypedArrayBaseConstructor(EcmaRuntimeCallInfo JSTaggedValue::Exception()); } -JSTaggedValue BuiltinsTypedArray::Int8ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue int8_array::Int8ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledInt8ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Uint8ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue uint8_array::Uint8ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledUint8ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Uint8ClampedArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue uint8_clamped_array::Uint8ClampedArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -69,56 +65,56 @@ JSTaggedValue BuiltinsTypedArray::Uint8ClampedArrayConstructor(EcmaRuntimeCallIn thread->GlobalConstants()->GetHandledUint8ClampedArrayString()); } -JSTaggedValue BuiltinsTypedArray::Int16ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue int16_array::Int16ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledInt16ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Uint16ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue uint16_array::Uint16ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledUint16ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Int32ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue int32_array::Int32ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledInt32ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Uint32ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue uint32_array::Uint32ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledUint32ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Float32ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue float32_array::Float32ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledFloat32ArrayString()); } -JSTaggedValue BuiltinsTypedArray::Float64ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue float64_array::Float64ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledFloat64ArrayString()); } -JSTaggedValue BuiltinsTypedArray::BigInt64ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_int64_array::BigInt64ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); return TypedArrayHelper::TypedArrayConstructor(argv, thread->GlobalConstants()->GetHandledBigInt64ArrayString()); } -JSTaggedValue BuiltinsTypedArray::BigUint64ArrayConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue big_uint64_array::BigUint64ArrayConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); @@ -126,7 +122,7 @@ JSTaggedValue BuiltinsTypedArray::BigUint64ArrayConstructor(EcmaRuntimeCallInfo } // 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) -JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::From(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, From); @@ -135,18 +131,18 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 1. Let C be the this value. // 2. If IsConstructor(C) is false, throw a TypeError exception. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (!this_handle->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the this value is not a Constructor.", JSTaggedValue::Exception()); } - JSHandle this_arg_handle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, builtins_common::ArgsPosition::THIRD); // 3. If mapfn is undefined, let mapping be false. // 4. Else, // a. If IsCallable(mapfn) is false, throw a TypeError exception. // b. Let mapping be true. bool mapping = false; - JSHandle mapfn = GetCallArg(argv, 1); + JSHandle mapfn = builtins_common::GetCallArg(argv, 1); if (!mapfn->IsUndefined()) { if (!mapfn->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the mapfn is not callable.", JSTaggedValue::Exception()); @@ -154,7 +150,7 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) mapping = true; } // 5. Let usingIterator be ? GetMethod(source, @@iterator). - JSHandle source = GetCallArg(argv, 0); + JSHandle source = builtins_common::GetCallArg(argv, 0); if (!source->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the source is not an object.", JSTaggedValue::Exception()); } @@ -275,7 +271,7 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) } // 22.2.2.2 %TypedArray%.of ( ...items ) -JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::Of(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Of); @@ -285,7 +281,7 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) uint32_t len = argv->GetArgsNumber(); // 2. Let items be the List of arguments passed to this function. // 3. Let C be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 4. If IsConstructor(C) is false, throw a TypeError exception. if (!this_handle->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the this value is not a Constructor.", JSTaggedValue::Exception()); @@ -308,7 +304,7 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) while (k < len) { t_key.Update(JSTaggedValue(k)); JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); - JSHandle k_value = GetCallArg(argv, k); + JSHandle k_value = builtins_common::GetCallArg(argv, k); JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_obj), k_key, k_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; @@ -318,23 +314,23 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) } // 22.2.2.4 -JSTaggedValue BuiltinsTypedArray::Species(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::GetSpecies(EcmaRuntimeCallInfo *argv) { ASSERT(argv); // 1. Return the this value. - return GetThis(argv).GetTaggedValue(); + return builtins_common::GetThis(argv).GetTaggedValue(); } // prototype // 22.2.3.1 get %TypedArray%.prototype.buffer -JSTaggedValue BuiltinsTypedArray::GetBuffer(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::GetBuffer(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetBuffer); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); @@ -351,14 +347,14 @@ JSTaggedValue BuiltinsTypedArray::GetBuffer(EcmaRuntimeCallInfo *argv) } // 22.2.3.2 -JSTaggedValue BuiltinsTypedArray::GetByteLength(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::GetByteLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetByteLength); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); @@ -371,7 +367,7 @@ JSTaggedValue BuiltinsTypedArray::GetByteLength(EcmaRuntimeCallInfo *argv) // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. @@ -380,14 +376,14 @@ JSTaggedValue BuiltinsTypedArray::GetByteLength(EcmaRuntimeCallInfo *argv) } // 22.2.3.3 -JSTaggedValue BuiltinsTypedArray::GetByteOffset(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::GetByteOffset(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetByteOffset); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); @@ -400,7 +396,7 @@ JSTaggedValue BuiltinsTypedArray::GetByteOffset(EcmaRuntimeCallInfo *argv) // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. @@ -410,25 +406,25 @@ JSTaggedValue BuiltinsTypedArray::GetByteOffset(EcmaRuntimeCallInfo *argv) } // 22.2.3.5 -JSTaggedValue BuiltinsTypedArray::CopyWithin(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::CopyWithin(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, CopyWithin); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::CopyWithin(argv); + return builtins::array::proto::CopyWithin(argv); } // 22.2.3.6 -JSTaggedValue BuiltinsTypedArray::Entries(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Entries(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Entries); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). @@ -441,7 +437,7 @@ JSTaggedValue BuiltinsTypedArray::Entries(EcmaRuntimeCallInfo *argv) } // 22.2.3.7 -JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Every(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Every); @@ -449,7 +445,7 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } @@ -464,13 +460,13 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -498,27 +494,27 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool bool_result = call_result.ToBoolean(); if (!bool_result) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } k++; } // 9. Return true. - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // 22.2.3.8 -JSTaggedValue BuiltinsTypedArray::Fill(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Fill(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::Fill(argv); + return builtins::array::proto::Fill(argv); } // 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) -JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Filter(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Filter); @@ -526,7 +522,7 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). @@ -536,12 +532,12 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) // 4. Let len be the value of O’s [[ArrayLength]] internal slot. int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 10. Let kept be a new empty List. JSHandle kept(factory->NewTaggedArray(len)); @@ -601,27 +597,27 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) } // 22.2.3.10 -JSTaggedValue BuiltinsTypedArray::Find(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Find(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::Find(argv); + return builtins::array::proto::Find(argv); } // 22.2.3.11 -JSTaggedValue BuiltinsTypedArray::FindIndex(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::FindIndex(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::FindIndex(argv); + return builtins::array::proto::FindIndex(argv); } // 22.2.3.12 -JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, ForEach); @@ -629,7 +625,7 @@ JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } @@ -644,13 +640,13 @@ JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -682,7 +678,7 @@ JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) } // ES2021 23.2.3.13 -JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Includes(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Includes); @@ -690,7 +686,7 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Perform ? ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); @@ -703,7 +699,7 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) // 3. If len is 0, return false. if (len == 0) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } ArraySizeT argc = argv->GetArgsNumber(); @@ -711,7 +707,7 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) if (argc > 1) { // 4-5. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. - JSHandle msg1 = GetCallArg(argv, 1); + JSHandle msg1 = builtins_common::GetCallArg(argv, 1); JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -720,7 +716,7 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) // 6. If n is positiveInfinity, return false. if (JSTaggedValue::Equal(thread, msg1, JSHandle(thread, JSTaggedValue(base::POSITIVE_INFINITY)))) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 7. Else if n is negativeInfinity, set n to 0. @@ -738,7 +734,7 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); // 10. - const JSHandle search_element = GetCallArg(argv, 0); + const JSHandle search_element = builtins_common::GetCallArg(argv, 0); while (from < len) { // a) JSHandle index_handle(thread, JSTaggedValue(from)); @@ -748,44 +744,44 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) // b) if (JSTaggedValue::SameValueZero(search_element.GetTaggedValue(), element.GetTaggedValue())) { - return GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } // c) from++; } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // 22.2.3.13 -JSTaggedValue BuiltinsTypedArray::IndexOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::IndexOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::IndexOf(argv); + return builtins::array::proto::IndexOf(argv); } // 22.2.3.14 -JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Join(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::Join(argv); + return builtins::array::proto::Join(argv); } // 22.2.3.15 -JSTaggedValue BuiltinsTypedArray::Keys(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Keys(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Keys); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). @@ -798,24 +794,24 @@ JSTaggedValue BuiltinsTypedArray::Keys(EcmaRuntimeCallInfo *argv) } // 22.2.3.16 -JSTaggedValue BuiltinsTypedArray::LastIndexOf(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::LastIndexOf(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::LastIndexOf(argv); + return builtins::array::proto::LastIndexOf(argv); } // 22.2.3.17 -JSTaggedValue BuiltinsTypedArray::GetLength(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::GetLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetLength); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); @@ -829,7 +825,7 @@ JSTaggedValue BuiltinsTypedArray::GetLength(EcmaRuntimeCallInfo *argv) // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 6. If IsDetachedBuffer(buffer) is true, return 0. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 7. Let length be the value of O’s [[ArrayLength]] internal slot. @@ -839,14 +835,14 @@ JSTaggedValue BuiltinsTypedArray::GetLength(EcmaRuntimeCallInfo *argv) } // 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) -JSTaggedValue BuiltinsTypedArray::Map(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Map(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Map); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). @@ -856,12 +852,12 @@ JSTaggedValue BuiltinsTypedArray::Map(EcmaRuntimeCallInfo *argv) // 4. Let len be the value of O’s [[ArrayLength]] internal slot. int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackfn_handle = GetCallArg(argv, 0); + JSHandle callbackfn_handle = builtins_common::GetCallArg(argv, 0); if (!callbackfn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } // 6. If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle this_arg_handle = GetCallArg(argv, 1); + JSHandle this_arg_handle = builtins_common::GetCallArg(argv, 1); // es11 5. Let A be ? TypedArraySpeciesCreate(O, « len »). std::array args = {JSTaggedValue(len).GetRawData()}; @@ -900,38 +896,38 @@ JSTaggedValue BuiltinsTypedArray::Map(EcmaRuntimeCallInfo *argv) } // 22.2.3.19 -JSTaggedValue BuiltinsTypedArray::Reduce(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Reduce(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::Reduce(argv); + return builtins::array::proto::Reduce(argv); } // 22.2.3.20 -JSTaggedValue BuiltinsTypedArray::ReduceRight(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::ReduceRight(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::ReduceRight(argv); + return builtins::array::proto::ReduceRight(argv); } // 22.2.3.21 -JSTaggedValue BuiltinsTypedArray::Reverse(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Reverse(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::Reverse(argv); + return builtins::array::proto::Reverse(argv); } // 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ]) // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Set(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Set); @@ -941,7 +937,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 1. Assert: array is any ECMAScript language value other than an Object with a [[TypedArrayName]] internal slot. // If it is such an Object, the definition in 22.2.3.22.2 applies. // 2. Let target be the this value. - JSHandle target = GetThis(argv); + JSHandle target = builtins_common::GetThis(argv); // 3. If Type(target) is not Object, throw a TypeError exception. if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); @@ -955,7 +951,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 5. Assert: target has a [[ViewedArrayBuffer]] internal slot. // 6. Let targetOffset be ToInteger (offset). - JSTaggedNumber t_target_offset = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 1)); + JSTaggedNumber t_target_offset = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 1)); // 7. ReturnIfAbrupt(targetOffset). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double target_offset = t_target_offset.GetNumber(); @@ -967,7 +963,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 9. Let targetBuffer be the value of target’s [[ViewedArrayBuffer]] internal slot. JSHandle target_buffer(thread, JSTypedArray::Cast(*target_obj)->GetViewedArrayBuffer()); // 10. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -982,7 +978,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) DataViewType target_type = TypedArrayHelper::GetTypeFromName(thread, target_name); int32_t target_byte_offset = TypedArrayHelper::GetByteOffset(thread, target_obj); - JSHandle arg_array = GetCallArg(argv, 0); + JSHandle arg_array = builtins_common::GetCallArg(argv, 0); // 22.2.3.22.1 %TypedArray%.prototype.set (array [ , offset ] ) if (!arg_array->IsTypedArray()) { @@ -1026,7 +1022,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) JSHandle k_value = JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), k_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (BuiltinsArrayBuffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -1038,8 +1034,8 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) k_number_handle.Update(JSTaggedValue::ToNumber(thread, k_value)); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - BuiltinsArrayBuffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, - k_number_handle, true); + builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, + k_number_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; target_byte_index = target_byte_index + target_element_size; @@ -1053,7 +1049,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 12. Let srcBuffer be the value of typedArray’s [[ViewedArrayBuffer]] internal slot. // 13. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. JSMutableHandle src_buffer(thread, JSTypedArray::Cast(*typed_array)->GetViewedArrayBuffer()); - if (BuiltinsArrayBuffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of typedArray is detached buffer.", JSTaggedValue::Exception()); } @@ -1081,8 +1077,8 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 25. Else, let srcByteIndex be srcByteOffset. int32_t src_byte_index; if (JSTaggedValue::SameValue(src_buffer.GetTaggedValue(), target_buffer.GetTaggedValue())) { - src_buffer.Update(BuiltinsArrayBuffer::CloneArrayBuffer(thread, target_buffer, src_byte_offset, - env->GetArrayBufferFunction())); + src_buffer.Update(builtins::array_buffer::CloneArrayBuffer(thread, target_buffer, src_byte_offset, + env->GetArrayBufferFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); src_byte_index = 0; } else { @@ -1102,9 +1098,10 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) if (src_type != target_type) { while (target_byte_index < limit) { JSTaggedValue tagged_data = - BuiltinsArrayBuffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, src_type, true); + builtins::array_buffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, src_type, true); value.Update(tagged_data); - BuiltinsArrayBuffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, value, true); + builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, value, + true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); src_byte_index = src_byte_index + src_element_size; target_byte_index = target_byte_index + target_element_size; @@ -1123,10 +1120,11 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // TODO(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue // (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - BuiltinsArrayBuffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, DataViewType::UINT8, true); + builtins::array_buffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, DataViewType::UINT8, + true); value.Update(tagged_data); - BuiltinsArrayBuffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, value, - true); + builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, + value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); src_byte_index = src_byte_index + 1; target_byte_index = target_byte_index + 1; @@ -1137,14 +1135,14 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) } // 22.2.3.23 %TypedArray%.prototype.slice ( start, end ) -JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Slice(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Slice); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). @@ -1156,7 +1154,7 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) double k; // 5. Let relativeStart be ToInteger(start). - JSTaggedNumber t_relative_start = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); + JSTaggedNumber t_relative_start = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double relative_start = t_relative_start.GetNumber(); @@ -1168,7 +1166,7 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) } // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). double relative_end = len; - JSHandle end = GetCallArg(argv, 1); + JSHandle end = builtins_common::GetCallArg(argv, 1); if (!end->IsUndefined()) { JSTaggedNumber t_relative_end = JSTaggedValue::ToInteger(thread, end); // 9. ReturnIfAbrupt(relativeEnd). @@ -1231,7 +1229,7 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) // a. Let srcBuffer be the value of O’s [[ViewedArrayBuffer]] internal slot. // b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. JSHandle src_buffer(thread, JSTypedArray::Cast(*this_obj)->GetViewedArrayBuffer()); - if (BuiltinsArrayBuffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of this value is detached buffer.", JSTaggedValue::Exception()); } @@ -1255,11 +1253,11 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (int32_t target_byte_index = 0; target_byte_index < count * element_size; src_byte_index++, target_byte_index++) { - JSTaggedValue tagged_data = - BuiltinsArrayBuffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, DataViewType::UINT8, true); + JSTaggedValue tagged_data = builtins::array_buffer::GetValueFromBuffer(thread, src_buffer, src_byte_index, + DataViewType::UINT8, true); value.Update(tagged_data); - BuiltinsArrayBuffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, value, - true); + builtins::array_buffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, + value, true); } } // 23. Return A. @@ -1267,17 +1265,17 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) } // 22.2.3.24 -JSTaggedValue BuiltinsTypedArray::Some(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Some(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::Some(argv); + return builtins::array::proto::Some(argv); } // 22.2.3.25 -JSTaggedValue BuiltinsTypedArray::Sort(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Sort(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Sort); @@ -1285,7 +1283,7 @@ JSTaggedValue BuiltinsTypedArray::Sort(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ToObject(this value). - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } @@ -1299,7 +1297,7 @@ JSTaggedValue BuiltinsTypedArray::Sort(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); - JSHandle callback_fn_handle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = builtins_common::GetCallArg(argv, 0); uint32_t i = 0; while (i < len - 1) { @@ -1326,14 +1324,14 @@ JSTaggedValue BuiltinsTypedArray::Sort(EcmaRuntimeCallInfo *argv) } // 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) -JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Subarray(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Subarray); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); @@ -1348,7 +1346,7 @@ JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) // 6. Let srcLength be the value of O’s [[ArrayLength]] internal slot. int32_t src_length = TypedArrayHelper::GetArrayLength(thread, this_obj); // 7. Let relativeBegin be ToInteger(begin). - JSTaggedNumber t_relative_begin = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); + JSTaggedNumber t_relative_begin = JSTaggedValue::ToInteger(thread, builtins_common::GetCallArg(argv, 0)); // 8. ReturnIfAbrupt(relativeBegin). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double relative_begin = t_relative_begin.GetNumber(); @@ -1364,7 +1362,7 @@ JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) // 10. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be ToInteger(end). double relative_end = src_length; - JSHandle end = GetCallArg(argv, 1); + JSHandle end = builtins_common::GetCallArg(argv, 1); if (!end->IsUndefined()) { JSTaggedNumber t_relative_end = JSTaggedValue::ToInteger(thread, end); // 11. ReturnIfAbrupt(relativeEnd). @@ -1403,34 +1401,24 @@ JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) } // 22.2.3.27 -JSTaggedValue BuiltinsTypedArray::ToLocaleString(EcmaRuntimeCallInfo *argv) -{ - ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { - THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); - } - return BuiltinsArray::ToLocaleString(argv); -} - -// 22.2.3.28 -JSTaggedValue BuiltinsTypedArray::ToString(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - if (!GetThis(argv)->IsTypedArray()) { + if (!builtins_common::GetThis(argv)->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - return BuiltinsArray::ToString(argv); + return builtins::array::proto::ToLocaleString(argv); } // 22.2.3.29 -JSTaggedValue BuiltinsTypedArray::Values(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::Values(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Values); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. Let valid be ValidateTypedArray(O). TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). @@ -1443,14 +1431,14 @@ JSTaggedValue BuiltinsTypedArray::Values(EcmaRuntimeCallInfo *argv) } // 22.2.3.31 -JSTaggedValue BuiltinsTypedArray::ToStringTag(EcmaRuntimeCallInfo *argv) +JSTaggedValue typed_array::proto::GetToStringTag(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, ToStringTag); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle this_handle = GetThis(argv); + JSHandle this_handle = builtins_common::GetThis(argv); // 2. If Type(O) is not Object, return undefined. if (!this_handle->IsECMAObject()) { return JSTaggedValue::Undefined(); diff --git a/runtime/builtins/builtins_typedarray.h b/runtime/builtins/builtins_typedarray.h deleted file mode 100644 index 8fb2ced64c167130341a8df21f203246b9b1d51b..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_typedarray.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_TYPEDARRAY_H -#define ECMASCRIPT_BUILTINS_BUILTINS_TYPEDARRAY_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" - -namespace panda::ecmascript::builtins { -class BuiltinsTypedArray : public ecmascript::base::BuiltinsBase { -public: - // 22.2.1 - static JSTaggedValue TypedArrayBaseConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Int8ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Uint8ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Uint8ClampedArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Int16ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Uint16ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Int32ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Uint32ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Float32ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue Float64ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue BigInt64ArrayConstructor(EcmaRuntimeCallInfo *argv); - static JSTaggedValue BigUint64ArrayConstructor(EcmaRuntimeCallInfo *argv); - - // 22.2.1.2.1 - static JSTaggedValue AllocateTypedArray(EcmaRuntimeCallInfo *argv); - - // 22.2.2.1 - static JSTaggedValue From(EcmaRuntimeCallInfo *argv); - // 22.2.2.2 - static JSTaggedValue Of(EcmaRuntimeCallInfo *argv); - // 22.2.2.4 - static JSTaggedValue Species(EcmaRuntimeCallInfo *argv); - - // prototype - // 22.2.3.1 - static JSTaggedValue GetBuffer(EcmaRuntimeCallInfo *argv); - // 22.2.3.2 - static JSTaggedValue GetByteLength(EcmaRuntimeCallInfo *argv); - // 22.2.3.3 - static JSTaggedValue GetByteOffset(EcmaRuntimeCallInfo *argv); - // 22.2.3.5 - static JSTaggedValue CopyWithin(EcmaRuntimeCallInfo *argv); - // 22.2.3.6 - static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); - // 22.2.3.7 - static JSTaggedValue Every(EcmaRuntimeCallInfo *argv); - // 22.2.3.8 - static JSTaggedValue Fill(EcmaRuntimeCallInfo *argv); - // 22.2.3.9 - static JSTaggedValue Filter(EcmaRuntimeCallInfo *argv); - // 22.2.3.10 - static JSTaggedValue Find(EcmaRuntimeCallInfo *argv); - // 22.2.3.11 - static JSTaggedValue FindIndex(EcmaRuntimeCallInfo *argv); - // 22.2.3.12 - static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); - // ES2021 23.2.3.13 - static JSTaggedValue Includes(EcmaRuntimeCallInfo *argv); - // 22.2.3.13 - static JSTaggedValue IndexOf(EcmaRuntimeCallInfo *argv); - // 22.2.3.14 - static JSTaggedValue Join(EcmaRuntimeCallInfo *argv); - // 22.2.3.15 - static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); - // 22.2.3.16 - static JSTaggedValue LastIndexOf(EcmaRuntimeCallInfo *argv); - // 22.2.3.17 - static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv); - // 22.2.3.18 - static JSTaggedValue Map(EcmaRuntimeCallInfo *argv); - // 22.2.3.19 - static JSTaggedValue Reduce(EcmaRuntimeCallInfo *argv); - // 22.2.3.20 - static JSTaggedValue ReduceRight(EcmaRuntimeCallInfo *argv); - // 22.2.3.21 - static JSTaggedValue Reverse(EcmaRuntimeCallInfo *argv); - // 22.2.3.22 - static JSTaggedValue Set(EcmaRuntimeCallInfo *argv); - // 22.2.3.23 - static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); - // 22.2.3.24 - static JSTaggedValue Some(EcmaRuntimeCallInfo *argv); - // 22.2.3.25 - static JSTaggedValue Sort(EcmaRuntimeCallInfo *argv); - // 22.2.3.26 - static JSTaggedValue Subarray(EcmaRuntimeCallInfo *argv); - // 22.2.3.27 - static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv); - // 22.2.3.28 - static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); - // 22.2.3.29 - static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); - // 22.2.3.31 - static JSTaggedValue ToStringTag(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_TYPEDARRAY_H diff --git a/runtime/builtins/builtins_weak_map.cpp b/runtime/builtins/builtins_weak_map.cpp index 9aad53c94bf7f9f4f34d22aa04015519de6756e6..1a8bdd844edd4feb99fe84800e20dbe6bcd72365 100644 --- a/runtime/builtins/builtins_weak_map.cpp +++ b/runtime/builtins/builtins_weak_map.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_weak_map.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -24,7 +24,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_map::WeakMapConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Constructor); @@ -32,13 +32,13 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let WeakMap be OrdinaryCreateFromConstructor(NewTarget, "%WeakMapPrototype%", «‍[[WeakMapData]]» ). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -50,7 +50,7 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // add data into set from iterable // 5.If iterable is not present, let iterable be undefined. // 6.If iterable is either undefined or null, let iter be undefined. - JSHandle iterable = GetCallArg(argv, 0); + JSHandle iterable = builtins_common::GetCallArg(argv, 0); // 8.If iter is undefined, return set if (iterable->IsUndefined() || iterable->IsNull()) { return weak_map.GetTaggedValue(); @@ -126,13 +126,13 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) return weak_map.GetTaggedValue(); } -JSTaggedValue BuiltinsWeakMap::Delete(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_map::proto::Delete(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Delete); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakMap()) { @@ -140,50 +140,50 @@ JSTaggedValue BuiltinsWeakMap::Delete(EcmaRuntimeCallInfo *argv) } JSHandle weak_map(self); - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); // 5.if Type(key) is not Object, return false. if (!key->IsHeapObject()) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } - return GetTaggedBoolean(JSWeakMap::Delete(thread, weak_map, key)); + return builtins_common::GetTaggedBoolean(JSWeakMap::Delete(thread, weak_map, key)); } -JSTaggedValue BuiltinsWeakMap::Has(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_map::proto::Has(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Has); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } JSHandle js_weak_map(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); // 5.if Type(key) is not Object, return false. if (!key->IsHeapObject()) { - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } int hash = LinkedHash::Hash(key.GetTaggedValue()); - return GetTaggedBoolean(js_weak_map->Has(key.GetTaggedValue(), hash)); + return builtins_common::GetTaggedBoolean(js_weak_map->Has(key.GetTaggedValue(), hash)); } -JSTaggedValue BuiltinsWeakMap::Get(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_map::proto::Get(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Get); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self(GetThis(argv)); + JSHandle self(builtins_common::GetThis(argv)); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakMap()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } JSHandle js_weak_map(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); if (!key->IsHeapObject()) { return JSTaggedValue::Undefined(); } @@ -191,13 +191,13 @@ JSTaggedValue BuiltinsWeakMap::Get(EcmaRuntimeCallInfo *argv) return js_weak_map->Get(key.GetTaggedValue(), hash); } -JSTaggedValue BuiltinsWeakMap::Set(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_map::proto::Set(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Set); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakMapData]] internal slot, throw a TypeError exception. @@ -205,7 +205,7 @@ JSTaggedValue BuiltinsWeakMap::Set(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); if (!key->IsHeapObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not an object.", JSTaggedValue::Exception()); } @@ -213,7 +213,7 @@ JSTaggedValue BuiltinsWeakMap::Set(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "key is Symblol or String", JSTaggedValue::Exception()); } - JSHandle value = GetCallArg(argv, 1); + JSHandle value = builtins_common::GetCallArg(argv, 1); JSHandle map(self); JSWeakMap::Set(thread, map, key, value); diff --git a/runtime/builtins/builtins_weak_map.h b/runtime/builtins/builtins_weak_map.h deleted file mode 100644 index 0a71ffc8b353860e6463d529399c337721cd3172..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_weak_map.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_WEAK_MAP_H -#define ECMASCRIPT_BUILTINS_BUILTINS_WEAK_MAP_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsWeakMap : public ecmascript::base::BuiltinsBase { -public: - // 23.3.3.1 - static JSTaggedValue WeakMapConstructor(EcmaRuntimeCallInfo *argv); - // 23.3.3.2 - static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv); - // 23.3.3.3 - static JSTaggedValue Get(EcmaRuntimeCallInfo *argv); - // 23.3.3.4 - static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); - // 23.1.3.5 - static JSTaggedValue Set(EcmaRuntimeCallInfo *argv); - // 23.1.3.6 @@toStringTag -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_MAP_H diff --git a/runtime/builtins/builtins_weak_ref.cpp b/runtime/builtins/builtins_weak_ref.cpp index 14d4dfd1595084753d6802d1b30bab748d734984..5e1ca14ca09154ebf7e6ebf7f5cb925f8d4690b4 100644 --- a/runtime/builtins/builtins_weak_ref.cpp +++ b/runtime/builtins/builtins_weak_ref.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_weak_ref.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -21,7 +21,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsWeakRef::Constructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_ref::Constructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakRef, Constructor); @@ -29,17 +29,17 @@ JSTaggedValue BuiltinsWeakRef::Constructor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new target must not be undefined", JSTaggedValue::Exception()); } // 2. If Type(target) is not Object, throw a TypeError exception. - JSHandle target = GetCallArg(argv, 0); + JSHandle target = builtins_common::GetCallArg(argv, 0); if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "target must not be undefined", JSTaggedValue::Exception()); } // 3. Let WeakRef be OrdinaryCreateFromConstructor(NewTarget, "%WeakRefPrototype%", «[[WeakRefTarget]]» ). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle weak_ref = JSHandle::Cast(obj); @@ -51,13 +51,13 @@ JSTaggedValue BuiltinsWeakRef::Constructor(EcmaRuntimeCallInfo *argv) return weak_ref.GetTaggedValue(); } -JSTaggedValue BuiltinsWeakRef::Deref(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_ref::proto::Deref(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakRef, Deref); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 1. Let weakRef be the this value. // 2. Perform ? RequireInternalSlot(weakRef, [[WeakRefTarget]]). if (!self->IsJSWeakRef()) { diff --git a/runtime/builtins/builtins_weak_ref.h b/runtime/builtins/builtins_weak_ref.h deleted file mode 100644 index d60e94700c51c85e13545d0a3e111d142df329ac..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_weak_ref.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_WEAK_REF_H -#define ECMASCRIPT_BUILTINS_BUILTINS_WEAK_REF_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsWeakRef : public ecmascript::base::BuiltinsBase { -public: - // 26.1.1.1 - static JSTaggedValue Constructor(EcmaRuntimeCallInfo *argv); - // 26.1.3.2 - static JSTaggedValue Deref(EcmaRuntimeCallInfo *argv); - // 26.1.3.3 @@toStringTag -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_REF_H diff --git a/runtime/builtins/builtins_weak_set.cpp b/runtime/builtins/builtins_weak_set.cpp index 625bf451989284b9987b80e7032adf33dbca98f0..84c446a3bcc377cfb35db386a3c0bbc892b39c4b 100644 --- a/runtime/builtins/builtins_weak_set.cpp +++ b/runtime/builtins/builtins_weak_set.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "builtins_weak_set.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -24,7 +24,7 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript::builtins { -JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_set::WeakSetConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Constructor); @@ -32,13 +32,13 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1.If NewTarget is undefined, throw a TypeError exception - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { // throw type error THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } // 2.Let weakset be OrdinaryCreateFromConstructor(NewTarget, "%WeakSetPrototype%", «‍[[WeakSetData]]» ). - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -51,7 +51,7 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) // add data into weakset from iterable // 5.If iterable is not present, let iterable be undefined. // 6.If iterable is either undefined or null, let iter be undefined. - JSHandle iterable(GetCallArg(argv, 0)); + JSHandle iterable(builtins_common::GetCallArg(argv, 0)); // 8.If iter is undefined, return weakset if (iterable->IsUndefined() || iterable->IsNull()) { return weak_set.GetTaggedValue(); @@ -105,13 +105,13 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) return weak_set.GetTaggedValue(); } -JSTaggedValue BuiltinsWeakSet::Add(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_set::proto::Add(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Add); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakSetData]] internal slot, throw a TypeError exception. @@ -119,7 +119,7 @@ JSTaggedValue BuiltinsWeakSet::Add(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakSet", JSTaggedValue::Exception()); } - JSHandle value(GetCallArg(argv, 0)); + JSHandle value(builtins_common::GetCallArg(argv, 0)); if (!value->IsHeapObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "value is not an object", JSTaggedValue::Exception()); } @@ -133,13 +133,13 @@ JSTaggedValue BuiltinsWeakSet::Add(EcmaRuntimeCallInfo *argv) return weak_set.GetTaggedValue(); } -JSTaggedValue BuiltinsWeakSet::Delete(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_set::proto::Delete(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Delete); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[WeakSetData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakSet()) { @@ -147,31 +147,31 @@ JSTaggedValue BuiltinsWeakSet::Delete(EcmaRuntimeCallInfo *argv) } JSHandle weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); if (!value->IsHeapObject()) { - GetTaggedBoolean(false); + builtins_common::GetTaggedBoolean(false); } - return GetTaggedBoolean(JSWeakSet::Delete(thread, weak_set, value)); + return builtins_common::GetTaggedBoolean(JSWeakSet::Delete(thread, weak_set, value)); } -JSTaggedValue BuiltinsWeakSet::Has(EcmaRuntimeCallInfo *argv) +JSTaggedValue weak_set::proto::Has(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Has); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception. if (!self->IsJSWeakSet()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakSet", JSTaggedValue::Exception()); } JSHandle js_weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); - JSHandle value = GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); if (!value->IsHeapObject()) { - GetTaggedBoolean(false); + builtins_common::GetTaggedBoolean(false); } int hash = LinkedHash::Hash(value.GetTaggedValue()); - return GetTaggedBoolean(js_weak_set->Has(value.GetTaggedValue(), hash)); + return builtins_common::GetTaggedBoolean(js_weak_set->Has(value.GetTaggedValue(), hash)); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_weak_set.h b/runtime/builtins/builtins_weak_set.h deleted file mode 100644 index 5d5349ab39167fd4f059fd589ec9a472029566cd..0000000000000000000000000000000000000000 --- a/runtime/builtins/builtins_weak_set.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ - -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_WEAK_SET_H -#define ECMASCRIPT_BUILTINS_BUILTINS_WEAK_SET_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" - -namespace panda::ecmascript::builtins { -class BuiltinsWeakSet : public ecmascript::base::BuiltinsBase { -public: - // 23.4.1.1 - static JSTaggedValue WeakSetConstructor(EcmaRuntimeCallInfo *argv); - // 23.4.3.1 - static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); - // 23.4.3.3 - static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv); - // 23.4.3.4 - static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_SET_H diff --git a/runtime/builtins/templates/builtins.rb b/runtime/builtins/templates/builtins.rb new file mode 100644 index 0000000000000000000000000000000000000000..d12c71bf2930763d07ac45f279c94391a1c6906c --- /dev/null +++ b/runtime/builtins/templates/builtins.rb @@ -0,0 +1,530 @@ +# 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. + +require 'yaml' +require 'ostruct' +require 'set' +require 'delegate' + +class JSString + def initialize(str) + raise if !str.kind_of?(String) + @str = str + end + + def to_cpp_literal() + return "\"#{@str}\"" + end + + def to_cpp_value() + if is_global_constant? + return "thread_->GlobalConstants()->GetHandled#{@str[0].upcase + @str[1..-1]}String()" + else + return "JSHandle(factory_->NewFromCanBeCompressString(\"#{@str}\"))" + end + end + + def is_global_constant? + case @str + when "toLocaleString", + "toString", + "valueOf", + "set", + "get", + "baseName", + "calendar", + "caseFirst", + "collation", + "hourCycle", + "numberingSystem", + "numeric", + "language", + "script", + "region", + "format" + return true + else + return false + end + end + + def ==(other) + other.kind_of?(JSString) && other.raw == @str + end + + def raw() @str end +end + +class JSSymbol + def initialize(str) + raise if !str.kind_of?(String) + @str = str + end + + def to_cpp_literal(try_resolve_global_const = false) + return "\"[Symbol.#{@str}]\"" + end + + def to_cpp_value() + return "env->Get#{@str[0].upcase + @str[1..-1]}Symbol()" + end + + def raw() @str end +end + +class CPPImpl + def initialize(str) + if str.kind_of?(Numeric) + str = String(str) + end + @str = str + raise if !@str.kind_of?(String) + end + + def raw() @str end +end + +class Alias + def initialize(str) + @obj = nil + @is_proto = nil + @key = nil + #TODO: parse properly + chain = str.split(".") + @key = JSString.new(chain[-1]) + case chain.size + when 2 + @obj = chain[0] + @is_proto = false + when 3 + @obj = chain[0] + @is_proto = true + end + end + + def gen_cpp_obj_getter + res = "" + if @obj == nil + res += "env->GetJSGlobalObject()" + else + res += "env->Get#{@obj[0].upcase + @obj[1..-1]}" + if @is_proto + res += "Prototype()" + else + res += "Function()" + end + end + res + end + + def gen_cpp_prop_getter + res = "JSObject::GetProperty(thread_, " + res += gen_cpp_obj_getter + ", " + res += @key.to_cpp_value + ").GetValue()" + res + end +end + +class CtorDescr + def initialize(ostr, is_function_ctor = false) + raise "Not OpenStruct" if !ostr.kind_of?(OpenStruct) + @is_function_ctor = is_function_ctor + ostr.each_pair do |key, value| + case key.to_s + when "impl" + @impl = CPPImpl.new value + when "argc" + @argc = value + else + raise "Unknown field: " + key.to_s + end + end + # check created struct: + raise "Invalid `impl` type" if !@impl.kind_of?(CPPImpl) # cpp-impl + raise "Invalid `argc` type" if !@argc.kind_of?(Numeric) + end + + def gen_cpp_id + @impl.raw + end + + def impl() @impl end + def argc() @argc end +end + +class MethodDescr + def initialize(ostr) + raise "Not OpenStruct" if !ostr.kind_of?(OpenStruct) + ostr.each_pair do |key, value| + case key.to_s + when "name" + raise "`name` and `symb` shouldn't be used together" if @id != nil + @id = JSString.new value + when "symb" + raise "`name` and `symb` shouldn't be used together" if @id != nil + @id = JSSymbol.new value + when "argc" + @argc = value + when "impl" + raise "`impl` and `alias` shouldn't be used together" if @impl != nil + @impl = CPPImpl.new value + when "alias" + raise "`impl` and `alias` shouldn't be used together" if @impl != nil + @impl = Alias.new value + when "ifdef" + raise if !value.kind_of?(String) + @ifdef_flag = value + else + raise "Unknown field: " + key.to_s + end + end + # check created struct: + raise "Missing `name` or `symb` fields" if @id == nil + raise "Missing `argc` field" if (@argc == nil) && (@impl == nil) + raise "`argc` should be of `Numeric`" if (@impl.kind_of?(CPPImpl) || @impl == nil) && !@argc.kind_of?(Numeric) + end + + def gen_cpp_id + raise "`impl` is redefined" if @impl != nil + id.raw[0].upcase + id.raw[1..-1] + end + + def gen_setfunction(namespace_name, obj_var_name) + res = "" + res += "#ifdef #{@ifdef_flag}\n" if @ifdef_flag + if @id.kind_of?(JSString) + res += " SetFunction(" + res += "env, " if !@impl.kind_of?(Alias) + res += "#{obj_var_name}, #{@id.to_cpp_value}, " + elsif @id.kind_of?(JSSymbol) + res += " SetFunctionAtSymbol(" + res += "env, " if !@impl.kind_of?(Alias) + res += "#{obj_var_name}, #{@id.to_cpp_value}, " + res += "#{@id.to_cpp_literal}, " if !@impl.kind_of?(Alias) + end + if !@impl + res += "#{namespace_name}::#{gen_cpp_id}, #{@argc});" + elsif @impl.kind_of?(CPPImpl) + res += "#{@impl.raw}, #{@argc});" + elsif @impl.kind_of?(Alias) + res += "#{@impl.gen_cpp_prop_getter});" + else + raise "Invalid `@impl` field in MethodDescr" + end + res += "\n#endif // #{@ifdef_flag}" if @ifdef_flag + res + end + + def id() @id end + def argc() @argc end + def impl() @impl end +end + +class GetDescr + def initialize(ostr) + raise "Not OpenStruct" if !ostr.kind_of?(OpenStruct) + ostr.each_pair do |key, value| + case key.to_s + when "name" + raise "`name` and `symb` shouldn't be used together" if @id != nil + @id = JSString.new value + when "symb" + raise "`name` and `symb` shouldn't be used together" if @id != nil + @id = JSSymbol.new value + else + raise "Unknown field: " + key.to_s + end + end + # check created struct: + raise "Missing `name` or `symb` fields" if @id == nil + end + + def set_setter(setter) + raise if @setter + @setter = setter + end + + def gen_creategetter(namespace_name, obj_var_name) + res = " JSHandle #{gen_cpp_id.snakecase} = CreateGetter(env, " + if @impl + res += "#{@impl.raw}, " + else + res += "#{namespace_name}::#{gen_cpp_id}, " + end + res += "#{@id.to_cpp_literal}, FunctionLength::ZERO);\n" + res + end + + def gen_setfunction(namespace_name, obj_var_name) + res = "" + res += "#ifdef #{@ifdef_flag}\n" if @ifdef_flag + res += gen_creategetter(namespace_name, obj_var_name) + res += @setter.gen_createsetter(namespace_name, obj_var_name) if @setter + + if @setter + res += " SetAccessor(#{obj_var_name}, #{@id.to_cpp_value}, #{gen_cpp_id.snakecase}, #{@setter.gen_cpp_id.snakecase});" + else + res += " SetGetter(#{obj_var_name}, #{@id.to_cpp_value}, #{gen_cpp_id.snakecase});" + end + + res += "\n#endif // #{@ifdef_flag}" if @ifdef_flag + res + end + + def gen_cpp_id + "Get" + id.raw[0].upcase + id.raw[1..-1] + end + + def setter() @setter end + def id() @id end +end + +class SetDescr + def initialize(ostr) + raise "Not OpenStruct" if !ostr.kind_of?(OpenStruct) + ostr.each_pair do |key, value| + case key.to_s + when "name" + raise "`name` and `symb` shouldn't be used together" if @id != nil + @id = JSString.new value + when "symb" + raise "`name` and `symb` shouldn't be used together" if @id != nil + @id = JSSymbol.new value + else + raise "Unknown field: " + key.to_s + end + end + # check created struct: + raise "Missing `name` or `symb` fields" if @id == nil + end + + def id() @id end + def gen_cpp_id + "Set" + id.raw[0].upcase + id.raw[1..-1] + end + + def gen_createsetter(namespace_name, obj_var_name) + res = " JSHandle #{gen_cpp_id.snakecase} = CreateSetter(env, " + if @impl + res += "#{@impl.raw}, " + else + res += "#{namespace_name}::#{gen_cpp_id}, " + end + res += "#{@id.to_cpp_literal}, FunctionLength::ONE);\n" + res + end + + def ==(other) + if other.kind_of?(GetDescr) + other.id == @id + else + false + end + end +end + +class PropertyDescr + class AccessorDescr + def initialize(ostr = nil) + raise "Not OpenStruct" if ostr && !ostr.kind_of?(OpenStruct) + @configurable = false + @enumerable = false + @writable = false + if ostr + ostr.each_pair do |key, value| + raise "Accessor descriptors expected to be `true`/`false`" if !value.kind_of?(TrueClass) && !value.kind_of?(FalseClass) + case key.to_s + when "configurable" + @configurable = value + when "enumerable" + @enumerable = value + when "writable" + @writable = value + else + raise "Unknown field: " + key.to_s + end + end + end + end + + def is_default? + !@configurable && !@enumerable && !@writable + end + end + + def initialize(ostr) + @accessor_descriptors = AccessorDescr.new + raise "Not OpenStruct" if !ostr.kind_of?(OpenStruct) + ostr.each_pair do |key, value| + case key.to_s + when "name" + @id = JSString.new value + when "impl" + raise "`impl` and `str` shouldn't be used together" if @value != nil + @value = CPPImpl.new value + when "str" + raise "`impl` and `str` shouldn't be used together" if @value != nil + @value = JSString.new value + when "accessor_descriptors" + @accessor_descriptors = AccessorDescr.new value + else + raise "Unknown field: " + key.to_s + end + end + + def gen_propertydef + res = "" + if @value.kind_of?(CPPImpl) + res += "inline auto GetProp#{@id.raw}()\n {\n return JSTaggedValue(#{@value.raw}); // NOLINT(readability-magic-numbers)\n }" + raise if !@accessor_descriptors.is_default? + end + res + end + + # check created struct: + raise "Missing `impl` or `str` fields" if @value == nil + raise "Missing `name` field" if @id == nil + end + + def id() @id end + def value() @value end + def accessor_descriptors() @accessor_descriptors end +end + +class AbstractOpDescr + def initialize(abstract_op_decl) + raise "Expected string" if !abstract_op_decl.kind_of? String + @raw = abstract_op_decl + end + + def decl + @raw + ';' + end +end + + +class Builtin + def initialize(ostr, is_proto = false) + @properties = [] + @getters = [] + @setters = [] + @methods = [] + @abstract_ops = [] + + ostr.each_pair do |key, value| + begin + case key.to_s + when "name" + @name = value + when "ctor" + if ostr.name.to_s == "Function" + @ctor = CtorDescr.new value, true + else + @ctor = CtorDescr.new value + end + when "properties" + @properties = convert_to_array_of_descr(PropertyDescr, value) + when "getters" + @getters = convert_to_array_of_descr(GetDescr, value) + when "setters" + @setters = convert_to_array_of_descr(SetDescr, value) + when "methods" + @methods = convert_to_array_of_descr(MethodDescr, value) + when "abstract_ops" + @abstract_ops = convert_to_array_of_descr(AbstractOpDescr, value) + when "prototype" + @prototype = Builtin.new(value, true) + else + raise "Unknown field: " + key.to_s + end + rescue RuntimeError => e + if is_proto + raise "`#{key.to_s}`\n" + e.to_s + else + raise "Error in intiialization of\n`#{@name}`\n`#{key.to_s}`\n#{e.to_s}" + end + end + end + + # Merge setters into getters; currently, every `setter` should have a corresponding `getter` + getters.each do |getter| + getter.set_setter(setters.delete(getter)) + end + raise "Builtin space should have `name` field" if !@name && !is_proto + raise "Prototype should not have `name` field" if @name && is_proto + raise "Prototype should not have `prototype` field" if @prototype && is_proto + end + + def convert_to_array_of_descr(descr_class, array) + raise if !array.kind_of?(Array) + res = [] + array.each do |elem| + res.append(descr_class.new(elem)) + end + res + end + + def gen_cpp_decl(cpp_id) + "JSTaggedValue #{cpp_id}(EcmaRuntimeCallInfo *argv);" + end + + def cpp_functions_decls + decls = [] + if @ctor + decls.append(gen_cpp_decl(@ctor.gen_cpp_id)) + end + @methods.each do |method| + decls.append(gen_cpp_decl(method.gen_cpp_id)) if !method.impl + end + @getters.each do |getter| + decls.append(gen_cpp_decl(getter.gen_cpp_id)) + decls.append(gen_cpp_decl(getter.setter.gen_cpp_id)) if getter.setter + + end + @setters.each do |setter| + decls.append(gen_cpp_decl(setter.gen_cpp_id)) + end + @abstract_ops.each do |abstract_op| + decls.append(abstract_op.decl) + end + decls + end + + def name() @name end + def ctor() @ctor end + def getters() @getters end + def setters() @setters end + def methods() @methods end + def properties() @properties end + def prototype() @prototype end +end + +class Builtins < SimpleDelegator + def self.wrap_data(data) + @builtins = [] + data.builtins.each do |space| + @builtins.append Builtin.new space + end + @builtins_internal = [] + data.builtins_internal.each do |name| + @builtins_internal.append Builtin.new name + end + end + def self.spaces() @builtins end + def self.internal_spaces() @builtins_internal end +end + +def Gen.on_require(data) + Builtins.wrap_data(data) +end + \ No newline at end of file diff --git a/runtime/builtins/templates/builtins.yaml b/runtime/builtins/templates/builtins.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f93215fde9a3a7adc22e75ca70557ff218a8d52 --- /dev/null +++ b/runtime/builtins/templates/builtins.yaml @@ -0,0 +1,1635 @@ +# 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. + +builtins: + - name: ArkTools + methods: + - name: print + argc: 0 + + - name: Array + ctor: + impl: ArrayConstructor + argc: 1 + methods: + - name: from + argc: 1 + - name: isArray + argc: 1 + - name: of + argc: 0 + getters: + - symb: species + prototype: + methods: + - name: concat + argc: 1 + - name: copyWithin + argc: 2 + - name: entries + argc: 0 + - name: every + argc: 1 + - name: flat + argc: 0 + - name: flatMap + argc: 1 + - name: fill + argc: 1 + - name: filter + argc: 1 + - name: find + argc: 1 + - name: findIndex + argc: 1 + - name: forEach + argc: 1 + - name: includes + argc: 1 + - name: indexOf + argc: 1 + - name: join + argc: 1 + - name: keys + argc: 0 + - name: lastIndexOf + argc: 1 + - name: map + argc: 1 + - name: pop + argc: 0 + - name: push + argc: 1 + - name: reduce + argc: 1 + - name: reduceRight + argc: 1 + - name: reverse + argc: 0 + - name: shift + argc: 0 + - name: slice + argc: 2 + - name: some + argc: 1 + - name: sort + argc: 1 + - name: splice + argc: 2 + - name: toLocaleString + argc: 0 + - name: toString + argc: 0 + - name: unshift + argc: 1 + - name: values + argc: 0 + - symb: iterator + alias: Array.prototype.values + getters: + - symb: unscopables + + - name: ArrayBuffer + ctor: + impl: ArrayBufferConstructor + argc: 1 + methods: + - name: isView + argc: 1 + getters: + - symb: species + prototype: + getters: + - name: byteLength + methods: + - name: slice + argc: 2 + abstract_ops: + - bool IsDetachedBuffer(JSTaggedValue array_buffer) + - JSTaggedValue GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, int32_t byte_index, DataViewType type, bool little_endian) + - JSTaggedValue SetValueInBuffer(JSThread *thread, JSHandle arr_buf, int32_t byte_index, DataViewType type, const JSHandle &value, bool little_endian) + - JSTaggedValue CloneArrayBuffer(JSThread *thread, const JSHandle &src_buffer, int32_t src_byte_offset, JSHandle constructor) + - JSTaggedValue AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, double byte_length) + + - name: AsyncFromSyncIterator + prototype: + methods: + - name: next + argc: 1 + - name: return + argc: 1 + - name: throw + argc: 1 + + - name: AsyncFunction + ctor: + impl: AsyncFunctionConstructor + argc: 1 + + - name: AsyncGeneratorFunction + ctor: + impl: AsyncGeneratorFunctionConstructor + argc: 1 + + - name: AsyncGenerator + prototype: + methods: + - name: next + argc: 1 + - name: return + argc: 1 + - name: throw + argc: 1 + + - name: AsyncIterator + prototype: + methods: + - symb: asyncIterator + argc: 0 + + - name: BigInt + ctor: + impl: BigIntConstructor + argc: 1 + methods: + - name: asUintN + argc: 2 + - name: asIntN + argc: 2 + prototype: + methods: + - name: toLocaleString + argc: 0 + - name: toString + argc: 0 + - name: valueOf + argc: 0 + + - name: Boolean + ctor: + impl: BooleanConstructor + argc: 1 + prototype: + methods: + - name: toString + argc: 0 + - name: valueOf + argc: 0 + + - name: Collator + ctor: + impl: CollatorConstructor + argc: 0 + methods: + - name: supportedLocalesOf + argc: 1 + prototype: + getters: + - name: compare + methods: + - name: resolvedOptions + argc: 0 + + - name: DataView + ctor: + impl: DataViewConstructor + argc: 1 + prototype: + getters: + - name: buffer + - name: byteLength + - name: byteOffset + methods: + - name: getFloat32 + argc: 1 + - name: getFloat64 + argc: 1 + - name: getInt8 + argc: 1 + - name: getInt16 + argc: 1 + - name: getInt32 + argc: 1 + - name: getUint8 + argc: 1 + - name: getUint16 + argc: 1 + - name: getUint32 + argc: 1 + - name: getBigInt64 + argc: 1 + - name: getBigUint64 + argc: 1 + - name: setFloat32 + argc: 2 + - name: setFloat64 + argc: 2 + - name: setInt8 + argc: 2 + - name: setInt16 + argc: 2 + - name: setInt32 + argc: 2 + - name: setUint8 + argc: 2 + - name: setUint16 + argc: 2 + - name: setUint32 + argc: 2 + - name: setBigInt64 + argc: 2 + - name: setBigUint64 + argc: 2 + + - name: DateTimeFormat + ctor: + impl: DateTimeFormatConstructor + argc: 1 + methods: + - name: supportedLocalesOf + argc: 1 + prototype: + getters: + - name: format + methods: + - name: formatToParts + argc: 1 + - name: resolvedOptions + argc: 0 + - name: formatRange + argc: 2 + - name: formatRangeToParts + argc: 2 + + - name: Date + properties: + - name: length + impl: 7 + ctor: + impl: DateConstructor + argc: 1 + methods: + - name: now + argc: 0 + - name: UTC + argc: 7 + - name: parse + argc: 1 + prototype: + methods: + - name: getDate + argc: 0 + - name: getDay + argc: 0 + - name: getFullYear + argc: 0 + - name: getYear + argc: 0 + - name: getHours + argc: 0 + - name: getMilliseconds + argc: 0 + - name: getMinutes + argc: 0 + - name: getMonth + argc: 0 + - name: getSeconds + argc: 0 + - name: getTime + argc: 0 + - name: getTimezoneOffset + argc: 0 + - name: getUTCDate + argc: 0 + - name: getUTCDay + argc: 0 + - name: getUTCFullYear + argc: 0 + - name: getUTCHours + argc: 0 + - name: getUTCMilliseconds + argc: 0 + - name: getUTCMinutes + argc: 0 + - name: getUTCMonth + argc: 0 + - name: getUTCSeconds + argc: 0 + - name: setDate + argc: 1 + - name: setFullYear + argc: 3 + - name: setHours + argc: 4 + - name: setMilliseconds + argc: 1 + - name: setMinutes + argc: 3 + - name: setMonth + argc: 2 + - name: setSeconds + argc: 2 + - name: setTime + argc: 1 + - name: setUTCDate + argc: 1 + - name: setUTCFullYear + argc: 3 + - name: setUTCHours + argc: 4 + - name: setUTCMilliseconds + argc: 1 + - name: setUTCMinutes + argc: 3 + - name: setUTCMonth + argc: 2 + - name: setUTCSeconds + argc: 2 + - name: toDateString + argc: 0 + - name: toISOString + argc: 0 + - name: toJSON + argc: 1 + - name: toLocaleDateString + argc: 0 + - name: toLocaleString + argc: 0 + - name: toLocaleTimeString + argc: 0 + - name: toString + argc: 0 + - name: toTimeString + argc: 0 + - name: toUTCString + argc: 0 + - name: valueOf + argc: 0 + - symb: toPrimitive + argc: 1 + + - name: Error + ctor: + impl: ErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + enumerable: false + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: Error + accessor_descriptors: + writable: true + enumerable: false + configurable: true + + - name: RangeError + ctor: + impl: RangeErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: RangeError + accessor_descriptors: + writable: true + configurable: true + + - name: ReferenceError + ctor: + impl: ReferenceErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: ReferenceError + accessor_descriptors: + writable: true + configurable: true + + - name: TypeError + ctor: + impl: TypeErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: TypeError + accessor_descriptors: + writable: true + configurable: true + + - name: URIError + ctor: + impl: URIErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: URIError + accessor_descriptors: + writable: true + configurable: true + + - name: SyntaxError + ctor: + impl: SyntaxErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: SyntaxError + accessor_descriptors: + writable: true + configurable: true + + - name: EvalError + ctor: + impl: EvalErrorConstructor + argc: 1 + properties: + - name: message + str: "" + accessor_descriptors: + writable: true + configurable: true + prototype: + methods: + - name: toString + argc: 0 + properties: + - name: name + str: EvalError + accessor_descriptors: + writable: true + configurable: true + + - name: FinalizationRegistry + ctor: + impl: Constructor + argc: 1 + prototype: + methods: + - name: register + argc: 2 + - name: unregister + argc: 1 + + - name: Function + ctor: + impl: FunctionConstructor + argc: 1 + prototype: + methods: + - name: apply + argc: 2 + - name: bind + argc: 1 + - name: call + argc: 1 + - name: toString + argc: 0 + # `Function` is initialized before `Symbol`, so `@@hasInstance` is declared via `internal_builtins` + # and initialized manually. + # - symb: hasInstance + # argc: 1 + + - name: GeneratorFunction + ctor: + impl: GeneratorFunctionConstructor + argc: 1 + + - name: Generator + prototype: + methods: + - name: next + argc: 1 + - name: return + argc: 1 + - name: throw + argc: 1 + + - name: Global + properties: + - name: Infinity + impl: JSTaggedValue(base::POSITIVE_INFINITY) + - name: NaN + impl: JSTaggedValue(base::NAN_VALUE) + - name: undefined + impl: JSTaggedValue::Undefined() + methods: + - name: eval + argc: 1 + - name: isFinite + argc: 1 + - name: isNaN + argc: 1 + - name: escape + argc: 1 + - name: unescape + argc: 1 + - name: decodeURI + argc: 1 + - name: encodeURI + argc: 1 + - name: decodeURIComponent + argc: 1 + - name: encodeURIComponent + argc: 1 + - name: parseFloat + alias: Number.parseFloat + - name: parseInt + alias: Number.parseInt + # Global object test + - name: print + argc: 1 + - name: gc + argc: 1 + # Intrusive GC testing framework + - name: startGC + argc: 2 + - name: waitForFinishGC + argc: 1 + - name: scheduleGcAfterNthAlloc + argc: 2 + - name: isScheduledGcTriggered + argc: 0 + - name: allocateArrayObject + argc: 1 + - name: markObject + argc: 1 + - name: getMarkQueue + argc: 0 + - name: clearMarkQueue + argc: 0 + - name: getObjectSpaceType + argc: 1 + - name: pinObject + argc: 1 + - name: unpinObject + argc: 1 + - name: getObjectAddress + argc: 1 + # runtime stat + - name: startRuntimeStat + argc: 0 + ifdef: ECMASCRIPT_ENABLE_RUNTIME_STAT + - name: stopRuntimeStat + argc: 0 + ifdef: ECMASCRIPT_ENABLE_RUNTIME_STAT + + - name: GCMarker + methods: + - name: markObjectRecursively + argc: 1 + + - name: Intl + methods: + - name: getCanonicalLocales + argc: 1 + + - name: Iterator + prototype: + methods: + - name: next + argc: 1 + - name: throw + argc: 1 + - name: return + argc: 1 + - symb: iterator + argc: 0 + + - name: StringIterator + prototype: + methods: + - name: next + argc: 0 + + - name: ForInIterator + prototype: + methods: + - name: next + impl: JSForInIterator::Next + argc: 0 + + - name: MapIterator + prototype: + methods: + - name: next + impl: JSMapIterator::Next + argc: 0 + + - name: SetIterator + prototype: + methods: + - name: next + impl: JSSetIterator::Next + argc: 0 + + - name: ArrayIterator + prototype: + methods: + - name: next + impl: JSArrayIterator::Next + argc: 0 + + - name: RegExpIterator + prototype: + methods: + - name: next + impl: JSRegExpIterator::Next + argc: 0 + + - name: Json + methods: + - name: parse + argc: 2 + - name: stringify + argc: 3 + + - name: Locale + ctor: + impl: LocaleConstructor + argc: 1 + prototype: + methods: + - name: maximize + argc: 0 + - name: minimize + argc: 0 + - name: toString + argc: 0 + getters: + - name: baseName + - name: calendar + - name: caseFirst + - name: collation + - name: hourCycle + - name: numeric + - name: numberingSystem + - name: language + - name: script + - name: region + + - name: Map + ctor: + impl: MapConstructor + argc: 0 + getters: + - symb: species + prototype: + getters: + - name: size + methods: + - name: clear + argc: 0 + - name: delete + argc: 1 + - name: entries + argc: 0 + - name: forEach + argc: 1 + - name: get + argc: 1 + - name: has + argc: 1 + - name: keys + argc: 0 + - name: set + argc: 2 + - name: values + argc: 0 + - symb: iterator + alias: Map.prototype.entries + + - name: Math + properties: + - name: E + impl: 2.718281828459045 + - name: LN10 + impl: 2.302585092994046 + - name: LN2 + impl: 0.6931471805599453 + - name: LOG10E + impl: 0.4342944819032518 + - name: LOG2E + impl: 1.4426950408889634 + - name: PI + impl: 3.141592653589793 + - name: SQRT1_2 + impl: 0.7071067811865476 + - name: SQRT2 + impl: 1.4142135623730951 + methods: + - name: abs + argc: 1 + - name: acos + argc: 1 + - name: acosh + argc: 1 + - name: asin + argc: 1 + - name: asinh + argc: 1 + - name: atan + argc: 1 + - name: atanh + argc: 1 + - name: atan2 + argc: 2 + - name: cbrt + argc: 1 + - name: ceil + argc: 1 + - name: clz32 + argc: 1 + - name: cos + argc: 1 + - name: cosh + argc: 1 + - name: exp + argc: 1 + - name: expm1 + argc: 1 + - name: floor + argc: 1 + - name: fround + argc: 1 + - name: hypot + argc: 2 + - name: imul + argc: 2 + - name: log + argc: 1 + - name: log1p + argc: 1 + - name: log10 + argc: 1 + - name: log2 + argc: 1 + - name: max + argc: 2 + - name: min + argc: 2 + - name: pow + argc: 2 + - name: random + argc: 0 + - name: round + argc: 1 + - name: sign + argc: 1 + - name: sin + argc: 1 + - name: sinh + argc: 1 + - name: sqrt + argc: 1 + - name: tan + argc: 1 + - name: tanh + argc: 1 + - name: trunc + argc: 1 + + - name: NumberFormat + ctor: + impl: NumberFormatConstructor + argc: 0 + methods: + - name: supportedLocalesOf + argc: 1 + prototype: + getters: + - name: format + methods: + - name: formatToParts + argc: 1 + - name: resolvedOptions + argc: 0 + + - name: Number + ctor: + impl: NumberConstructor + argc: 1 + properties: + - name: MAX_VALUE + impl: 1.7976931348623157e+308 + - name: MIN_VALUE + impl: 5e-324 + - name: NaN + impl: NAN + - name: POSITIVE_INFINITY + impl: std::numeric_limits::infinity() + - name: NEGATIVE_INFINITY + impl: -std::numeric_limits::infinity() + - name: MAX_SAFE_INTEGER + impl: 9007199254740991 + - name: MIN_SAFE_INTEGER + impl: -9007199254740991 + - name: EPSILON + impl: 2.220446049250313e-16 + methods: + - name: isFinite + argc: 1 + - name: isInteger + argc: 1 + - name: isNaN + argc: 1 + - name: isSafeInteger + argc: 1 + - name: parseFloat + argc: 1 + - name: parseInt + argc: 2 + prototype: + methods: + - name: toExponential + argc: 1 + - name: toFixed + argc: 1 + - name: toLocaleString + argc: 0 + - name: toPrecision + argc: 1 + - name: toString + argc: 1 + - name: valueOf + argc: 0 + + - name: Object + ctor: + impl: ObjectConstructor + argc: 1 + methods: + - name: assign + argc: 2 + - name: create + argc: 2 + - name: defineProperties + argc: 2 + - name: defineProperty + argc: 3 + - name: freeze + argc: 1 + - name: fromEntries + argc: 1 + - name: getOwnPropertyDescriptor + argc: 2 + - name: getOwnPropertyDescriptors + argc: 1 + - name: getOwnPropertyNames + argc: 1 + - name: getOwnPropertySymbols + argc: 1 + - name: getPrototypeOf + argc: 1 + - name: is + argc: 2 + - name: isExtensible + argc: 1 + - name: isFrozen + argc: 1 + - name: isSealed + argc: 1 + - name: keys + argc: 1 + - name: preventExtensions + argc: 1 + - name: seal + argc: 1 + - name: setPrototypeOf + argc: 2 + - name: entries + argc: 1 + - name: values + argc: 1 + prototype: + methods: + - name: hasOwnProperty + argc: 1 + - name: isPrototypeOf + argc: 1 + - name: propertyIsEnumerable + argc: 1 + - name: toLocaleString + argc: 0 + - name: toString + argc: 0 + - name: valueOf + argc: 0 + - name: createRealm + argc: 0 + - name: __defineGetter__ + argc: 2 + - name: __defineSetter__ + argc: 2 + - name: __lookupGetter__ + argc: 1 + - name: __lookupSetter__ + argc: 1 + getters: + - name: __proto__ + setters: + - name: __proto__ + + - name: PluralRules + ctor: + impl: PluralRulesConstructor + argc: 0 + methods: + - name: supportedLocalesOf + argc: 1 + prototype: + methods: + - name: select + argc: 1 + - name: resolvedOptions + argc: 0 + + - name: Promise + ctor: + impl: PromiseConstructor + argc: 1 + getters: + - symb: species + methods: + - name: all + argc: 1 + - name: race + argc: 1 + - name: reject + argc: 1 + - name: resolve + argc: 1 + prototype: + methods: + - name: catch + argc: 1 + - name: then + argc: 2 + abstract_ops: + - >- + JSTaggedValue PerformPromiseThen(JSThread *thread, const JSHandle &promise, + const JSHandle &on_fulfilled, + const JSHandle &on_rejected, + const JSHandle &capability) + + - name: Proxy + ctor: + impl: ProxyConstructor + argc: 2 + methods: + - name: revocable + argc: 2 + + - name: Reflect + methods: + - name: apply + argc: 3 + - name: construct + argc: 2 + - name: defineProperty + argc: 3 + - name: deleteProperty + argc: 2 + - name: get + argc: 2 + - name: getOwnPropertyDescriptor + argc: 2 + - name: getPrototypeOf + argc: 1 + - name: has + argc: 2 + - name: isExtensible + argc: 1 + - name: ownKeys + argc: 1 + - name: preventExtensions + argc: 1 + - name: set + argc: 3 + - name: setPrototypeOf + argc: 2 + + - name: RegExp + ctor: + impl: RegExpConstructor + argc: 2 + getters: + - symb: species + prototype: + methods: + - name: exec + argc: 1 + - name: test + argc: 1 + - name: toString + argc: 0 + - symb: match + argc: 1 + - symb: matchAll + argc: 1 + - symb: replace + argc: 2 + - symb: search + argc: 1 + - symb: split + argc: 2 + getters: + - name: flags + - name: global + - name: ignoreCase + - name: multiline + - name: dotAll + - name: source + - name: sticky + - name: unicode + abstract_ops: + - JSTaggedValue RegExpCreate(JSThread *thread, const JSHandle &pattern, const JSHandle &flags) + - JSTaggedValue FlagsBitsToString(JSThread *thread, uint8_t flags) + - JSTaggedValue RegExpExec(JSThread *thread, const JSHandle ®exp, const JSHandle &input_string, bool use_cache) + - uint32_t AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode) + + - name: RelativeTimeFormat + ctor: + impl: RelativeTimeFormatConstructor + argc: 0 + methods: + - name: supportedLocalesOf + argc: 1 + prototype: + methods: + - name: format + argc: 2 + - name: formatToParts + argc: 2 + - name: resolvedOptions + argc: 0 + + - name: RuntimeTesting + methods: + - name: GetOptimizationStatus + argc: 1 + - name: PrepareFunctionForOptimization + argc: 1 + - name: OptimizeFunctionOnNextCall + argc: 2 + - name: Exit + argc: 1 + - name: IsBeingInterpreted + argc: 1 + - name: DeoptimizeFunction + argc: 1 + - name: NeverOptimizeFunction + argc: 1 + - name: DeoptimizeNow + argc: 1 + - name: _DeoptimizeNow + argc: 1 + - name: ClearFunctionFeedback + argc: 1 + - name: OptimizeOsr + argc: 1 + - name: CompleteInobjectSlackTracking + argc: 1 + - name: IsDictPropertyConstTrackingEnbled + argc: 1 + - name: StringMaxLength + argc: 1 + - name: TypedArrayMaxLength + argc: 1 + - name: DisableOptimizationFinalization + argc: 1 + - name: WaitForBackgroundOptimization + argc: 1 + - name: FinalizeOptimization + argc: 1 + - name: ArrayBufferDetach + argc: 1 + - name: EnsureFeedbackVectorForFunction + argc: 1 + - name: SimulateNewspaceFull + argc: 1 + - name: VerifyType + argc: 1 + - name: ToFastProperties + argc: 1 + - name: IsConcurrentRecompilationSupported + argc: 1 + - name: GetUndetectable + argc: 1 + - name: ToLength + argc: 1 + - name: RunningInSimulator + argc: 1 + - name: AllocateHeapNumber + argc: 1 + - name: PretenureAllocationSite + argc: 1 + - name: MaxSmi + argc: 1 + - name: CreatePrivateSymbol + argc: 1 + - name: CreatePrivateNameSymbol + argc: 1 + - name: Is64Bit + argc: 1 + + - name: Set + ctor: + impl: SetConstructor + argc: 0 + getters: + - symb: species + prototype: + getters: + - name: size + methods: + - name: add + argc: 1 + - name: clear + argc: 0 + - name: delete + argc: 1 + - name: entries + argc: 0 + - name: forEach + argc: 1 + - name: has + argc: 1 + - name: values + argc: 0 + - name: keys + alias: Set.prototype.values + - symb: iterator + alias: Set.prototype.values + + - name: String + ctor: + impl: StringConstructor + argc: 1 + methods: + - name: fromCharCode + argc: 1 + - name: fromCodePoint + argc: 1 + - name: raw + argc: 1 + prototype: + methods: + - name: charAt + argc: 1 + - name: charCodeAt + argc: 1 + - name: codePointAt + argc: 1 + - name: concat + argc: 1 + - name: endsWith + argc: 1 + - name: includes + argc: 1 + - name: indexOf + argc: 1 + - name: lastIndexOf + argc: 1 + - name: localeCompare + argc: 1 + - name: match + argc: 1 + - name: matchAll + argc: 1 + - name: normalize + argc: 0 + - name: padEnd + argc: 1 + - name: padStart + argc: 1 + - name: repeat + argc: 1 + - name: replace + argc: 2 + - name: replaceAll + argc: 2 + - name: search + argc: 1 + - name: slice + argc: 2 + - name: split + argc: 2 + - name: startsWith + argc: 1 + - name: substring + argc: 2 + - name: substr + argc: 2 + - name: toLocaleLowerCase + argc: 0 + - name: toLocaleUpperCase + argc: 0 + - name: toLowerCase + argc: 0 + - name: toString + argc: 0 + - name: toUpperCase + argc: 0 + - name: trim + argc: 0 + - name: trimEnd + argc: 0 + - name: trimStart + argc: 0 + - name: trimRight + alias: String.prototype.trimEnd + - name: trimLeft + alias: String.prototype.trimStart + - name: valueOf + argc: 0 + - symb: iterator + argc: 0 + getters: + - name: length + abstract_ops: + - >- + JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle &matched, + const JSHandle &src_string, int position, + const JSHandle &capture_list, + const JSHandle &named_captures, + const JSHandle &replacement) + + - name: Symbol + ctor: + impl: SymbolConstructor + argc: 0 + methods: + - name: for + argc: 1 + - name: keyFor + argc: 1 + prototype: + methods: + - name: toString + argc: 0 + - name: valueOf + argc: 0 + - symb: toPrimitive + argc: 1 + getters: + - name: description + abstract_ops: + - JSTaggedValue SymbolDescriptiveString(JSThread *thread, JSTaggedValue sym) + + - name: TypedArray + ctor: + impl: TypedArrayBaseConstructor + argc: 0 + methods: + - name: from + argc: 1 + - name: of + argc: 0 + getters: + - symb: species + prototype: + getters: + - name: buffer + - name: byteLength + - name: byteOffset + - name: length + - symb: toStringTag + methods: + - name: copyWithin + argc: 2 + - name: entries + argc: 0 + - name: every + argc: 1 + - name: fill + argc: 1 + - name: filter + argc: 1 + - name: find + argc: 1 + - name: findIndex + argc: 1 + - name: forEach + argc: 1 + - name: includes + argc: 1 + - name: indexOf + argc: 1 + - name: join + argc: 1 + - name: keys + argc: 0 + - name: lastIndexOf + argc: 1 + - name: map + argc: 1 + - name: reduce + argc: 1 + - name: reduceRight + argc: 1 + - name: reverse + argc: 0 + - name: set + argc: 1 + - name: slice + argc: 2 + - name: some + argc: 1 + - name: sort + argc: 1 + - name: subarray + argc: 2 + - name: toLocaleString + argc: 0 + - name: toString + alias: Array.prototype.toString + - name: values + argc: 0 + - symb: iterator + alias: TypedArray.prototype.values + + - name: Int8Array + ctor: + impl: Int8ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 1 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 1 + + - name: Uint8Array + ctor: + impl: Uint8ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 1 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 1 + + - name: Uint8ClampedArray + ctor: + impl: Uint8ClampedArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 1 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 1 + + - name: Int16Array + ctor: + impl: Int16ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 2 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 2 + + - name: Uint16Array + ctor: + impl: Uint16ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 2 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 2 + + - name: Int32Array + ctor: + impl: Int32ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 4 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 4 + + - name: Uint32Array + ctor: + impl: Uint32ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 4 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 4 + + - name: Float32Array + ctor: + impl: Float32ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 4 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 4 + + - name: Float64Array + ctor: + impl: Float64ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 8 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 8 + + - name: BigInt64Array + ctor: + impl: BigInt64ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 8 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 8 + + - name: BigUint64Array + ctor: + impl: BigUint64ArrayConstructor + argc: 3 + properties: + - name: BYTES_PER_ELEMENT + impl: 8 + prototype: + properties: + - name: BYTES_PER_ELEMENT + impl: 8 + + - name: WeakMap + ctor: + impl: WeakMapConstructor + argc: 0 + prototype: + methods: + - name: delete + argc: 1 + - name: get + argc: 1 + - name: has + argc: 1 + - name: set + argc: 2 + + - name: WeakRef + ctor: + impl: Constructor + argc: 1 + prototype: + methods: + - name: deref + argc: 0 + + - name: WeakSet + ctor: + impl: WeakSetConstructor + argc: 0 + prototype: + methods: + - name: add + argc: 1 + - name: delete + argc: 1 + - name: has + argc: 1 + + +# This space is similiar to the `builtins` with the difference that no +# property initialization is generated from it; only declaration is generated. +# It is intended for such cases as `Function.prototype[@@hasInstance]`, when +# `Symbol` is not initialized yet, but `[Symbol.hasInstance]` is needed. +builtins_internal: +- name: PromiseHandler + methods: + - name: Resolve + argc: 1 + - name: Reject + argc: 1 + - name: Executor + argc: 2 + - name: ResolveElementFunction + argc: 1 + - name: AsyncAwaitFulfilled + argc: 1 + - name: AsyncAwaitRejected + argc: 1 + +- name: PromiseJob + methods: + - name: PromiseReactionJob + argc: 2 + - name: PromiseResolveThenableJob + argc: 3 + +- name: Function + methods: + - name: FunctionPrototypeInvokeSelf + argc: 0 + prototype: + methods: + - symb: hasInstance + argc: 1 + +- name: Global + methods: + - name: CallJsBoundFunction + argc: 0 + - name: CallJsProxy + argc: 0 + +- name: TypeError + methods: + - name: ThrowTypeError + argc: 1 diff --git a/runtime/builtins/builtins_generator.h b/runtime/builtins/templates/builtins_declaration_gen.h.erb similarity index 37% rename from runtime/builtins/builtins_generator.h rename to runtime/builtins/templates/builtins_declaration_gen.h.erb index ddb9ad44a350dc18e8d3605316c8202aecb3eaff..767bd8b51891064ed2f1e3b7f194a44a318979f5 100644 --- a/runtime/builtins/builtins_generator.h +++ b/runtime/builtins/templates/builtins_declaration_gen.h.erb @@ -13,29 +13,40 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_GENERATOR_H -#define ECMASCRIPT_BUILTINS_BUILTINS_GENERATOR_H - -#include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/js_tagged_value-inl.h" - -namespace panda::ecmascript::builtins { -class BuiltinsGenerator : public ecmascript::base::BuiltinsBase { -public: - // 26.2.1.1 GeneratorFunction(p1, p2, … , pn, body) - static JSTaggedValue GeneratorFunctionConstructor(EcmaRuntimeCallInfo *argv); - - // 26.4.1.2 Generator.prototype.next(value) - static JSTaggedValue GeneratorPrototypeNext(EcmaRuntimeCallInfo *argv); - - // 26.4.1.3 Generator.prototype.return(value) - static JSTaggedValue GeneratorPrototypeReturn(EcmaRuntimeCallInfo *argv); - - // 26.4.1.4 Generator.prototype.throw(exception) - static JSTaggedValue GeneratorPrototypeThrow(EcmaRuntimeCallInfo *argv); - - // 26.4.1.5 Generator.prototype[@@toStringTag] -}; -} // namespace panda::ecmascript::builtins - -#endif // ECMASCRIPT_BUILTINS_BUILTINS_GENERATOR_H +% Builtins.spaces.each do |space| +namespace <%= space.name.snakecase %> { // <%= space.name %> NOLINT(modernize-concat-nested-namespaces) +% space.properties.each do |property| + <%= property.gen_propertydef %> +% end +% space.cpp_functions_decls.each do |cpp_decl| + <%= cpp_decl %> +% end +% if space.prototype + namespace proto { +% space.prototype.properties.each do |property| + <%= property.gen_propertydef %> +% end +% space.prototype.cpp_functions_decls.each do |cpp_decl| + <%= cpp_decl %> +% end + } // namespace proto +% end +} // namespace <%= space.name.snakecase %> + +% end + +% Builtins.internal_spaces.each do |ispace| +namespace <%= ispace.name.snakecase %> { // <%= ispace.name %> +% ispace.cpp_functions_decls.each do |cpp_decl| + <%= cpp_decl %> +% end +% if ispace.prototype + namespace proto { +% ispace.prototype.cpp_functions_decls.each do |cpp_decl| + <%= cpp_decl %> +% end + } // namespace proto +% end +} // namespace <%= ispace.name.snakecase %> + +% end diff --git a/runtime/builtins/builtins_boolean.h b/runtime/builtins/templates/builtins_initializers_gen.h.erb similarity index 31% rename from runtime/builtins/builtins_boolean.h rename to runtime/builtins/templates/builtins_initializers_gen.h.erb index 118afed95ecf2fad77140df653d01398b2bc61c0..5730919a2764aa039d83cb2cc2ec986f5f75a6cd 100644 --- a/runtime/builtins/builtins_boolean.h +++ b/runtime/builtins/templates/builtins_initializers_gen.h.erb @@ -13,26 +13,35 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_BUILTINS_BUILTINS_BOOLEAN_H -#define ECMASCRIPT_BUILTINS_BUILTINS_BOOLEAN_H +% Builtins.spaces.each do |space| +% if (space.methods.length + space.setters.length + space.getters.length) > 0 +void SetFunctionsGen<%= space.name %>(const JSHandle &env, const JSHandle &<%= space.name.snakecase %>_func) const +{ +% space.methods.each do |method| +<%= method.gen_setfunction(space.name.snakecase, space.name.snakecase + "_func") %> +% end -#include "plugins/ecmascript/runtime/js_tagged_value-inl.h" -#include "plugins/ecmascript/runtime/base/builtins_base.h" +% space.getters.each do |getter| +<%= getter.gen_setfunction(space.name.snakecase, space.name.snakecase + "_func") %> +% end +} -namespace panda::ecmascript::builtins { -class BuiltinsBoolean : public ecmascript::base::BuiltinsBase { -public: - // ecma 19.3.1 - static JSTaggedValue BooleanConstructor(EcmaRuntimeCallInfo *argv); +% end +% if space.prototype && (space.prototype.methods.length + space.prototype.setters.length + space.prototype.getters.length) > 0 +void SetFunctionsGen<%= space.name %>Proto(const JSHandle &env, const JSHandle &<%= space.name.snakecase %>_proto) const +{ +% space.prototype.methods.each do |method| +<%= method.gen_setfunction(space.name.snakecase + "::proto", space.name.snakecase + "_proto") %> +% end +% space.prototype.getters.each do |getter| +<%= getter.gen_setfunction(space.name.snakecase + "::proto", space.name.snakecase + "_proto") %> +% end +% space.prototype.setters.each do |setter| +% raise "Setters without corresponding getters are not implemented" if !space.prototype.getters.find do |i| +% i.id == setter.id +% end +% end +} - // ecma 19.3.3 abstract operation thisBooleanValue(value) - static JSTaggedValue ThisBooleanValue(JSThread *thread, JSTaggedValue value); - - // ecma 19.3.3.2 - static JSTaggedValue BooleanPrototypeToString(EcmaRuntimeCallInfo *argv); - - // ecma 19.3.3.3 - static JSTaggedValue BooleanPrototypeValueOf(EcmaRuntimeCallInfo *argv); -}; -} // namespace panda::ecmascript::builtins -#endif // ECMASCRIPT_BUILTINS_BUILTINS_BOOLEAN_H +% end +% end diff --git a/runtime/compiler/ecmascript_runtime_interface.h b/runtime/compiler/ecmascript_runtime_interface.h index 00ee1f086603b9aaa7c65cbe5a6deb3253e6f854..6bb1266c5192b01af65bfdacd11e8c99f521d2c9 100644 --- a/runtime/compiler/ecmascript_runtime_interface.h +++ b/runtime/compiler/ecmascript_runtime_interface.h @@ -37,7 +37,7 @@ public: NO_COPY_SEMANTIC(EcmaRuntimeInterface); NO_MOVE_SEMANTIC(EcmaRuntimeInterface); - ecmascript::JSMethod *JsMethodCast(RuntimeInterface::MethodPtr method) const + static ecmascript::JSMethod *JsMethodCast(RuntimeInterface::MethodPtr method) { return static_cast(method); } diff --git a/runtime/containers/containers_arraylist.cpp b/runtime/containers/containers_arraylist.cpp index 41e1366945697bdd05edfd8750a727713e8256cc..77a242f55e36fa02397b839bdca360c8d3fd8606 100644 --- a/runtime/containers/containers_arraylist.cpp +++ b/runtime/containers/containers_arraylist.cpp @@ -27,11 +27,11 @@ JSTaggedValue ContainersArrayList::ArrayListConstructor(EcmaRuntimeCallInfo *arg JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle new_target = GetNewTarget(argv); + JSHandle new_target = builtins_common::GetNewTarget(argv); if (new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); } - JSHandle constructor = GetConstructor(argv); + JSHandle constructor = builtins_common::GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -45,13 +45,13 @@ JSTaggedValue ContainersArrayList::Add(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), ArrayList, Add); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle self = GetThis(argv); + JSHandle self = builtins_common::GetThis(argv); if (!self->IsJSArrayList()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSArrayList", JSTaggedValue::Exception()); } - JSHandle value(GetCallArg(argv, 0)); + JSHandle value(builtins_common::GetCallArg(argv, 0)); JSArrayList::Add(thread, JSHandle::Cast(self), value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::False()); diff --git a/runtime/containers/containers_arraylist.h b/runtime/containers/containers_arraylist.h index acf34ab734e4b2a15ac9b3c2e88e58ba9b758bda..e478635bdfbea94c27dee89b723252a1385d2219 100644 --- a/runtime/containers/containers_arraylist.h +++ b/runtime/containers/containers_arraylist.h @@ -20,7 +20,7 @@ #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" namespace panda::ecmascript::containers { -class ContainersArrayList : public base::BuiltinsBase { +class ContainersArrayList { public: static JSTaggedValue ArrayListConstructor(EcmaRuntimeCallInfo *argv); diff --git a/runtime/containers/containers_private.cpp b/runtime/containers/containers_private.cpp index 1f4850f80d78ff1121d3b9948daf4deeb3ed967e..f17c403889aeba3cb41ab859afbb09c8083ecb3d 100644 --- a/runtime/containers/containers_private.cpp +++ b/runtime/containers/containers_private.cpp @@ -27,8 +27,8 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle argv = GetCallArg(msg, 0); - JSHandle this_value(GetThis(msg)); + JSHandle argv = builtins_common::GetCallArg(msg, 0); + JSHandle this_value(builtins_common::GetThis(msg)); uint32_t tag = 0; if (!JSTaggedValue::ToElementIndex(argv.GetTaggedValue(), &tag) || tag >= ContainerTag::END) { diff --git a/runtime/containers/containers_private.h b/runtime/containers/containers_private.h index 83a7a686338891dc987d4f03966a17e2ff94edcd..18d4a1f349adac4f24f79eb8de5b3c9619cd9de2 100644 --- a/runtime/containers/containers_private.h +++ b/runtime/containers/containers_private.h @@ -40,7 +40,7 @@ enum ContainerTag : uint8_t { // Using Lazy-loading container, including ArrayList, Queue, Stack, Vector, List, LinkedList, Deque, // TreeMap, TreeSet, HashMap, HashSet, LightWightMap, LightWightSet, PlainArray. // Use through ArkPrivate.Load([ContainerTag]) in js, ContainTag was declaerd in ArkPrivate like ArkPrivate::ArrayList. -class ContainersPrivate : public base::BuiltinsBase { +class ContainersPrivate { public: static JSTaggedValue Load(EcmaRuntimeCallInfo *msg); diff --git a/runtime/dump.cpp b/runtime/dump.cpp index 2a807e9e26bad75e92cf9ee2e7effb93da022c1d..2d3c566891de014a8ce35e67d26c427ec4b08e5d 100644 --- a/runtime/dump.cpp +++ b/runtime/dump.cpp @@ -1298,14 +1298,14 @@ void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const GetEvalErrorFunction().GetTaggedValue().Dump(thread, os); os << " - RegExpFunction: "; GetRegExpFunction().GetTaggedValue().Dump(thread, os); - os << " - BuiltinsSetFunction: "; - GetBuiltinsSetFunction().GetTaggedValue().Dump(thread, os); - os << " - BuiltinsMapFunction: "; - GetBuiltinsMapFunction().GetTaggedValue().Dump(thread, os); - os << " - BuiltinsWeakSetFunction: "; - GetBuiltinsWeakSetFunction().GetTaggedValue().Dump(thread, os); - os << " - BuiltinsWeakMapFunction: "; - GetBuiltinsWeakMapFunction().GetTaggedValue().Dump(thread, os); + os << " - SetFunction: "; + GetSetFunction().GetTaggedValue().Dump(thread, os); + os << " - MapFunction: "; + GetMapFunction().GetTaggedValue().Dump(thread, os); + os << " - WeakSetFunction: "; + GetWeakSetFunction().GetTaggedValue().Dump(thread, os); + os << " - WeakMapFunction: "; + GetWeakMapFunction().GetTaggedValue().Dump(thread, os); os << " - MathFunction: "; GetMathFunction().GetTaggedValue().Dump(thread, os); os << " - JsonFunction: "; @@ -1361,7 +1361,7 @@ void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const os << " - ForinIteratorPrototype: "; GetForinIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - StringIterator: "; - GetStringIterator().GetTaggedValue().Dump(thread, os); + GetStringIteratorFunction().GetTaggedValue().Dump(thread, os); os << " - MapIteratorPrototype: "; GetMapIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - SetIteratorPrototype: "; @@ -2731,12 +2731,10 @@ void GlobalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, vec.emplace_back(std::make_pair(PandaString("SyntaxErrorFunction"), GetSyntaxErrorFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("EvalErrorFunction"), GetEvalErrorFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("RegExpFunction"), GetRegExpFunction().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("BuiltinsSetFunction"), GetBuiltinsSetFunction().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("BuiltinsMapFunction"), GetBuiltinsMapFunction().GetTaggedValue())); - vec.emplace_back( - std::make_pair(PandaString("BuiltinsWeakSetFunction"), GetBuiltinsWeakSetFunction().GetTaggedValue())); - vec.emplace_back( - std::make_pair(PandaString("BuiltinsWeakMapFunction"), GetBuiltinsWeakMapFunction().GetTaggedValue())); + vec.emplace_back(std::make_pair(PandaString("SetFunction"), GetSetFunction().GetTaggedValue())); + vec.emplace_back(std::make_pair(PandaString("MapFunction"), GetMapFunction().GetTaggedValue())); + vec.emplace_back(std::make_pair(PandaString("BuiltinsWeakSetFunction"), GetWeakSetFunction().GetTaggedValue())); + vec.emplace_back(std::make_pair(PandaString("BuiltinsWeakMapFunction"), GetWeakMapFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("MathFunction"), GetMathFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("JsonFunction"), GetJsonFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("StringFunction"), GetStringFunction().GetTaggedValue())); @@ -2767,7 +2765,7 @@ void GlobalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, vec.emplace_back(std::make_pair(PandaString("IteratorPrototype"), GetIteratorPrototype().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("ForinIteratorPrototype"), GetForinIteratorPrototype().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("StringIterator"), GetStringIterator().GetTaggedValue())); + vec.emplace_back(std::make_pair(PandaString("StringIterator"), GetStringIteratorFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("MapIteratorPrototype"), GetMapIteratorPrototype().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("SetIteratorPrototype"), GetSetIteratorPrototype().GetTaggedValue())); vec.emplace_back( diff --git a/runtime/ecma_macros.h b/runtime/ecma_macros.h index b6b8e29ece456856a59b51af0a1598fce7e6e221..29efff7048b7089f6b1c7720c2ada83ced94771d 100644 --- a/runtime/ecma_macros.h +++ b/runtime/ecma_macros.h @@ -135,72 +135,6 @@ static inline void UnalignedStore(T *p, T v) #define THROW_NEW_ERROR_AND_RETURN_EXCEPTION(thread, error) \ THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception()); -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define SET_DATE_VALUE(name, code, isLocal) \ - static JSTaggedValue name(EcmaRuntimeCallInfo *argv) \ - { \ - ASSERT(argv); \ - JSThread *thread = argv->GetThread(); \ - JSHandle msg = GetThis(argv); \ - if (!msg->IsDate()) { \ - THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ - } \ - JSHandle jsDate = JSHandle(msg); \ - JSTaggedValue result = jsDate->SetDateValue(argv, code, isLocal); \ - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); \ - jsDate->SetTimeValue(thread, result); \ - return result; \ - } - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DATE_TO_STRING(name) \ - static JSTaggedValue name(EcmaRuntimeCallInfo *argv) \ - { \ - ASSERT(argv); \ - JSThread *thread = argv->GetThread(); \ - [[maybe_unused]] EcmaHandleScope handle_scope(thread); \ - JSHandle msg = GetThis(argv); \ - if (!msg->IsDate()) { \ - THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ - } \ - if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ - THROW_RANGE_ERROR_AND_RETURN(thread, "range error", JSTaggedValue::Exception()); \ - } \ - return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ - } - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DATE_STRING(name) \ - static JSTaggedValue name(EcmaRuntimeCallInfo *argv) \ - { \ - ASSERT(argv); \ - JSThread *thread = argv->GetThread(); \ - [[maybe_unused]] EcmaHandleScope handle_scope(thread); \ - JSHandle msg = GetThis(argv); \ - if (!msg->IsDate()) { \ - THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ - } \ - if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ - return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Invalid Date").GetTaggedValue(); \ - } \ - return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ - } - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define GET_DATE_VALUE(name, code, isLocal) \ - static JSTaggedValue name(EcmaRuntimeCallInfo *argv) \ - { \ - ASSERT(argv); \ - JSThread *thread = argv->GetThread(); \ - JSHandle msg = GetThis(argv); \ - if (!msg->IsDate()) { \ - THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ - } \ - JSHandle jsDate = JSHandle(msg); \ - double result = jsDate->GetDateValue(jsDate->GetTimeValue().GetDouble(), code, isLocal); \ - return GetTaggedDouble(result); \ - } - // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define THROW_NEW_ERROR_AND_RETURN(thread, error) \ do { \ diff --git a/runtime/ecma_vm.cpp b/runtime/ecma_vm.cpp index 90ff219a2ee26f32d45d041c97d879f3fd08514e..03dfdf359b05c1ced19838c012b4e3a44c270968 100644 --- a/runtime/ecma_vm.cpp +++ b/runtime/ecma_vm.cpp @@ -274,7 +274,7 @@ bool EcmaVM::Initialize() micro_job_queue_ = factory_->NewMicroJobQueue().GetTaggedValue(); { - Builtins builtins; + builtins::Builtins builtins; builtins.Initialize(global_env_handle, thread_); } diff --git a/runtime/ecma_vm.h b/runtime/ecma_vm.h index a08f908cd7d5b99a0851bb93d982fe8e9b4053fe..42b97378d4aec3255373dccc8a82b58e320234e4 100644 --- a/runtime/ecma_vm.h +++ b/runtime/ecma_vm.h @@ -22,6 +22,7 @@ #include "include/mem/panda_containers.h" #include "include/mem/panda_string.h" #include "plugins/ecmascript/runtime/base/config.h" +//#include "plugins/ecmascript/runtime/builtins.h" #include "plugins/ecmascript/runtime/ecma_call_profiling_table.h" #include "plugins/ecmascript/runtime/ecma_string_table.h" #include "plugins/ecmascript/runtime/global_handle_collection.h" @@ -63,6 +64,10 @@ namespace job { class MicroJobQueue; } // namespace job +#ifndef INL_BUILTS +#define INL_BUILTS +enum class BuiltinId : uint16_t { NONE, MATH_SIN }; +#endif namespace builtins { class RegExpExecResultCache; } // namespace builtins diff --git a/runtime/global_env.cpp b/runtime/global_env.cpp index bdcf86379c7afa47a5e8c2ac3fadd95f4c88c177..282997298bebf0f64c8526217e49ea97e037f0d7 100644 --- a/runtime/global_env.cpp +++ b/runtime/global_env.cpp @@ -15,7 +15,7 @@ #include "plugins/ecmascript/runtime/global_env.h" #include "ecma_module.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_handler.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/class_linker/program_object-inl.h" #include "plugins/ecmascript/runtime/ic/ic_handler.h" #include "plugins/ecmascript/runtime/ic/proto_change_details.h" diff --git a/runtime/global_env.h b/runtime/global_env.h index dcaa2356511136a4d1f7bbe5c2849dd5a98022b2..a80e1b76c02d30cd15a5ff7afb120ac21dbf70c4 100644 --- a/runtime/global_env.h +++ b/runtime/global_env.h @@ -71,15 +71,16 @@ class JSThread; V(JSTaggedValue, CollatorFunction, COLLATOR_FUNCTION_INDEX) \ V(JSTaggedValue, PluralRulesFunction, PLURAL_RULES_FUNCTION_INDEX) \ V(JSTaggedValue, RegExpFunction, REGEXP_FUNCTION_INDEX) \ - V(JSTaggedValue, BuiltinsSetFunction, BUILTINS_SET_FUNCTION_INDEX) \ + V(JSTaggedValue, SetFunction, BUILTINS_SET_FUNCTION_INDEX) \ V(JSTaggedValue, SetPrototype, SET_PROTOTYPE_INDEX) \ - V(JSTaggedValue, BuiltinsMapFunction, BUILTINS_MAP_FUNCTION_INDEX) \ - V(JSTaggedValue, BuiltinsWeakMapFunction, BUILTINS_WEAK_MAP_FUNCTION_INDEX) \ - V(JSTaggedValue, BuiltinsWeakSetFunction, BUILTINS_WEAK_SET_FUNCTION_INDEX) \ + V(JSTaggedValue, MapFunction, MAP_FUNCTION_INDEX) \ + V(JSTaggedValue, WeakMapFunction, WEAK_MAP_FUNCTION_INDEX) \ + V(JSTaggedValue, WeakSetFunction, WEAK_SET_FUNCTION_INDEX) \ V(JSTaggedValue, MapPrototype, MAP_PROTOTYPE_INDEX) \ V(JSTaggedValue, MathFunction, MATH_FUNCTION_INDEX) \ V(JSTaggedValue, JsonFunction, JSON_FUNCTION_INDEX) \ V(JSTaggedValue, StringFunction, STRING_FUNCTION_INDEX) \ + V(JSTaggedValue, StringPrototype, STRING_PROTOTYPE_INDEX) \ V(JSTaggedValue, ProxyFunction, PROXY_FUNCTION_INDEX) \ V(JSTaggedValue, GeneratorFunctionFunction, GENERATOR_FUNCTION_OFFSET) \ V(JSTaggedValue, GeneratorFunctionPrototype, GENERATOR_FUNCTION_PROTOTYPE_OFFSET) \ @@ -117,7 +118,7 @@ class JSThread; V(JSTaggedValue, AsyncIteratorPrototype, ASYNC_ITERATOR_PROTOTYPE_INDEX) \ V(JSTaggedValue, ForinIteratorPrototype, FORIN_ITERATOR_PROTOTYPE_INDEX) \ V(JSTaggedValue, ForinIteratorClass, FOR_IN_ITERATOR_CLASS_INDEX) \ - V(JSTaggedValue, StringIterator, STRING_ITERATOR_INDEX) \ + V(JSTaggedValue, StringIteratorFunction, STRING_ITERATOR_INDEX) \ V(JSTaggedValue, MapIteratorPrototype, MAP_ITERATOR_PROTOTYPE_INDEX) \ V(JSTaggedValue, SetIteratorPrototype, SET_ITERATOR_PROTOTYPE_INDEX) \ V(JSTaggedValue, RegExpIteratorPrototype, REGEXP_ITERATOR_PROTOTYPE_INDEX) \ diff --git a/runtime/global_env_constants.cpp b/runtime/global_env_constants.cpp index 2c2101c8684e143ce250cf0f5a13e31166394f56..aa2d9f96e3b2a14c98b1b1522f43b975f83992e6 100644 --- a/runtime/global_env_constants.cpp +++ b/runtime/global_env_constants.cpp @@ -17,7 +17,6 @@ #include "plugins/ecmascript/runtime/accessor_data.h" #include "plugins/ecmascript/runtime/builtins.h" -#include "plugins/ecmascript/runtime/builtins/builtins_global.h" #include "plugins/ecmascript/runtime/class_info_extractor.h" #include "plugins/ecmascript/runtime/class_linker/program_object.h" #include "plugins/ecmascript/runtime/ecma_module.h" diff --git a/runtime/interpreter/slow_runtime_stub.cpp b/runtime/interpreter/slow_runtime_stub.cpp index a8713b8327c9da8e8c234d24cd1bd635491900cc..21f4b880dbbaeae1a1e40bd48f2753b6f12bb3e8 100644 --- a/runtime/interpreter/slow_runtime_stub.cpp +++ b/runtime/interpreter/slow_runtime_stub.cpp @@ -1509,7 +1509,7 @@ JSTaggedValue SlowRuntimeStub::CreateRegExpWithLiteral(JSThread *thread, JSTagge JSHandle pattern_handle(thread, pattern); JSHandle flags_handle(thread, JSTaggedValue(flags)); - return builtins::BuiltinsRegExp::RegExpCreate(thread, pattern_handle, flags_handle); + return builtins::reg_exp::RegExpCreate(thread, pattern_handle, flags_handle); } JSTaggedValue SlowRuntimeStub::CreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, JSArray *literal) diff --git a/runtime/js_array_iterator.cpp b/runtime/js_array_iterator.cpp index 62cf36f947ad1c4c55b869bfea0476f04e67d572..f258f4132d4a73b809ce1dbc349898bbd42cd493 100644 --- a/runtime/js_array_iterator.cpp +++ b/runtime/js_array_iterator.cpp @@ -14,7 +14,6 @@ */ #include "js_array_iterator.h" -#include "builtins/builtins_errors.h" #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" #include "plugins/ecmascript/runtime/base/typed_array_helper.h" #include "global_env.h" @@ -22,7 +21,6 @@ #include "object_factory.h" namespace panda::ecmascript { -using BuiltinsBase = base::BuiltinsBase; // 22.1.5.2.1 %ArrayIteratorPrototype%.next ( ) JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) { @@ -30,7 +28,7 @@ JSTaggedValue JSArrayIterator::Next(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let O be the this value. - JSHandle input(BuiltinsBase::GetThis(argv)); + JSHandle input(builtins_common::GetThis(argv)); // 2.If Type(O) is not Object, throw a TypeError exception. // 3.If O does not have all of the internal slots of an TaggedArray Iterator Instance (22.1.5.3), throw a TypeError diff --git a/runtime/js_async_from_sync_iterator_object.cpp b/runtime/js_async_from_sync_iterator_object.cpp index ec807b10cc84f1249ffe0d49ff0cba014ab2deb8..f1e990b11ee297f7c181b6f03eeea78642f13d09 100644 --- a/runtime/js_async_from_sync_iterator_object.cpp +++ b/runtime/js_async_from_sync_iterator_object.cpp @@ -2,7 +2,6 @@ * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. * Description: */ -#include "plugins/ecmascript/runtime/builtins/builtins_promise.h" #include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/internal_call_params.h" #include "plugins/ecmascript/runtime/js_async_from_sync_iterator_object.h" @@ -12,7 +11,6 @@ #include "plugins/ecmascript/runtime/generator_helper.h" namespace panda::ecmascript { -using BuiltinsPromise = builtins::BuiltinsPromise; JSTaggedValue JSAsyncFromSyncIteratorValueUnwrapFunction::AsyncFromSyncIteratorValueUnwrapFunction( EcmaRuntimeCallInfo *argv) @@ -21,10 +19,10 @@ JSTaggedValue JSAsyncFromSyncIteratorValueUnwrapFunction::AsyncFromSyncIteratorV [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let F be the active function object. - JSHandle func(base::BuiltinsBase::GetConstructor(argv)); + JSHandle func(builtins_common::GetConstructor(argv)); // 2. Return ! CreateIterResultObject(value, F.[[Done]]). - JSHandle value = base::BuiltinsBase::GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); return JSIterator::CreateIterResultObject(thread, value, func->GetDone().IsTrue()).GetTaggedValue(); } @@ -88,7 +86,7 @@ JSTaggedValue JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation( on_fulfilled->SetDone(thread, done.GetTaggedValue()); // 11. Perform ! PerformPromiseThen(valueWrapper, onFulfilled, undefined, promiseCapability). - [[maybe_unused]] JSTaggedValue then_result = BuiltinsPromise::PerformPromiseThen( + [[maybe_unused]] JSTaggedValue then_result = builtins::promise::PerformPromiseThen( thread, JSHandle::Cast(value_wrapper), JSHandle::Cast(on_fulfilled), thread->GlobalConstants()->GetHandledUndefined(), JSHandle::Cast(promise_capability)); diff --git a/runtime/js_async_function.cpp b/runtime/js_async_function.cpp index 6b064eee67908c9e1669c594558cbf57fa314e08..ef93c5318fa3e6c3289e03bafd3b9abe52f26500 100644 --- a/runtime/js_async_function.cpp +++ b/runtime/js_async_function.cpp @@ -15,8 +15,7 @@ #include "plugins/ecmascript/runtime/js_async_function.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_handler.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/generator_helper.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -26,8 +25,6 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript { -using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler; -using BuiltinsPromise = builtins::BuiltinsPromise; JSTaggedValue JSAsyncFuncObject::AsyncFunctionAwait(JSThread *thread, const JSHandle &async_func_obj, const JSHandle &value) @@ -45,12 +42,12 @@ JSTaggedValue JSAsyncFuncObject::AsyncFunctionAwait(JSThread *thread, const JSHa JSHandle promise(thread, JSPromise::Cast(promise_val.GetHeapObject())); // 4.Let onFulfilled be a new built-in function object as defined in AsyncFunction Awaited Fulfilled. - JSHandle ful_func = - factory->NewJSAsyncAwaitStatusFunction(reinterpret_cast(BuiltinsPromiseHandler::AsyncAwaitFulfilled)); + JSHandle ful_func = factory->NewJSAsyncAwaitStatusFunction( + reinterpret_cast(builtins::promise_handler::AsyncAwaitFulfilled)); // 5.Let onRejected be a new built-in function object as defined in AsyncFunction Awaited Rejected. JSHandle rej_func = - factory->NewJSAsyncAwaitStatusFunction(reinterpret_cast(BuiltinsPromiseHandler::AsyncAwaitRejected)); + factory->NewJSAsyncAwaitStatusFunction(reinterpret_cast(builtins::promise_handler::AsyncAwaitRejected)); // 6.Set onFulfilled.[[AsyncContext]] to asyncContext. // 7.Set onRejected.[[AsyncContext]] to asyncContext. @@ -64,7 +61,7 @@ JSTaggedValue JSAsyncFuncObject::AsyncFunctionAwait(JSThread *thread, const JSHa JSHandle(thread, tcap->GetPromise())->SetPromiseIsHandled(thread, JSTaggedValue::Undefined()); // 10.Perform ! PerformPromiseThen(promiseCapability.[[Promise]], onFulfilled, onRejected, throwawayCapability). - [[maybe_unused]] JSTaggedValue pres = BuiltinsPromise::PerformPromiseThen( + [[maybe_unused]] JSTaggedValue pres = builtins::promise::PerformPromiseThen( thread, promise, JSHandle::Cast(ful_func), JSHandle::Cast(rej_func), JSHandle::Cast(tcap)); diff --git a/runtime/js_async_generator_object.cpp b/runtime/js_async_generator_object.cpp index 2bf3b07d7392208c2bb32078ad9f24abfabd7149..4b6ffbca94529e0d073e0524c4df62117cf86b5a 100644 --- a/runtime/js_async_generator_object.cpp +++ b/runtime/js_async_generator_object.cpp @@ -3,7 +3,6 @@ * Description: */ #include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise.h" #include "plugins/ecmascript/runtime/internal_call_params.h" #include "plugins/ecmascript/runtime/js_async_generator_object.h" #include "plugins/ecmascript/runtime/js_promise.h" @@ -13,7 +12,6 @@ namespace panda::ecmascript { enum class AsyncGeneratorRequest : panda::ArraySizeT { COMPLETION, PROMISE_CAPABILITY }; -using BuiltinsPromise = builtins::BuiltinsPromise; JSTaggedValue JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextFulfilled(EcmaRuntimeCallInfo *argv) { @@ -21,14 +19,14 @@ JSTaggedValue JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextFulf [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let F be the active function object. - JSHandle this_func(base::BuiltinsBase::GetConstructor(argv)); + JSHandle this_func(builtins_common::GetConstructor(argv)); JSHandle async_gen_object(thread, this_func->GetAsyncGenerator()); // 2. Set F.[[Generator]].[[AsyncGeneratorState]] to completed. async_gen_object->SetState(thread, JSGeneratorState::COMPLETED); // 3. Return ! AsyncGeneratorResolve(F.[[Generator]], value, true). - JSHandle value = base::BuiltinsBase::GetCallArg(argv, 0); + JSHandle value = builtins_common::GetCallArg(argv, 0); return JSAsyncGeneratorObject::AsyncGeneratorResolve(thread, JSHandle::Cast(async_gen_object), value, true) .GetTaggedValue(); @@ -40,14 +38,14 @@ JSTaggedValue JSAsyncGeneratorResolveNextFunction::AsyncGeneratorResolveNextReje [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let F be the active function object. - JSHandle this_func(base::BuiltinsBase::GetConstructor(argv)); + JSHandle this_func(builtins_common::GetConstructor(argv)); JSHandle async_gen_object(thread, this_func->GetAsyncGenerator()); // 2. Set F.[[Generator]].[[AsyncGeneratorState]] to completed. async_gen_object->SetState(thread, JSGeneratorState::COMPLETED); // 3. Return ! AsyncGeneratorReject(F.[[Generator]], reason). - JSHandle reason = base::BuiltinsBase::GetCallArg(argv, 0); + JSHandle reason = builtins_common::GetCallArg(argv, 0); return JSAsyncGeneratorObject::AsyncGeneratorReject(thread, JSHandle::Cast(async_gen_object), reason) .GetTaggedValue(); } @@ -246,7 +244,7 @@ JSHandle JSAsyncGeneratorObject::AsyncGeneratorResumeNext(JSThrea on_rejected->SetAsyncGenerator(thread, async_gen_object.GetTaggedValue()); // 11. Perform ! PerformPromiseThen(promise, onFulfilled, onRejected). - [[maybe_unused]] JSTaggedValue then_result = BuiltinsPromise::PerformPromiseThen( + [[maybe_unused]] JSTaggedValue then_result = builtins::promise::PerformPromiseThen( thread, promise, JSHandle::Cast(on_fulfilled), JSHandle::Cast(on_rejected), global_const->GetHandledUndefined()); diff --git a/runtime/js_date.cpp b/runtime/js_date.cpp index d03fa07d28df058cdc8795e5aedabf926c08b1af..ffb49cc0e62ebe03ddeccb7d32ad916be5dbcbc6 100644 --- a/runtime/js_date.cpp +++ b/runtime/js_date.cpp @@ -471,7 +471,7 @@ JSTaggedValue JSDate::Parse(EcmaRuntimeCallInfo *argv) std::regex iso_reg(iso_reg_str); std::regex utc_reg(utc_reg_str); std::regex local_reg(local_reg_str); - JSHandle msg = base::BuiltinsBase::GetCallArg(argv, 0); + JSHandle msg = builtins_common::GetCallArg(argv, 0); JSHandle str = JSHandle::Cast(JSTaggedValue::ToString(thread, msg)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); PandaString date = ConvertToPandaString(EcmaString::Cast(str->GetTaggedObject())); @@ -509,7 +509,7 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) double seconds = 0; double ms = 0; JSThread *thread = argv->GetThread(); - JSHandle year_arg = base::BuiltinsBase::GetCallArg(argv, 0); + JSHandle year_arg = builtins_common::GetCallArg(argv, 0); JSTaggedNumber year_value = JSTaggedValue::ToNumber(thread, year_arg); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); if (year_value.IsNumber()) { @@ -527,42 +527,42 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) uint32_t num_args = argv->GetArgsNumber(); JSTaggedValue res; if (num_args > index) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); + JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); month = res.GetNumber(); index++; } if (num_args > index) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); + JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); date = res.GetNumber(); index++; } if (num_args > index) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); + JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); hours = res.GetNumber(); index++; } if (num_args > index) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); + JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); minutes = res.GetNumber(); index++; } if (num_args > index) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); + JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); seconds = res.GetNumber(); index++; } if (num_args > index) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); + JSHandle value = builtins_common::GetCallArg(argv, index); res = JSTaggedValue::ToNumber(thread, value); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); ms = res.GetNumber(); @@ -948,7 +948,7 @@ JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, boo [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); for (uint32_t i = 0; i < count; i++) { - JSHandle value = base::BuiltinsBase::GetCallArg(argv, i); + JSHandle value = builtins_common::GetCallArg(argv, i); JSThread *thread = argv->GetThread(); JSTaggedNumber res = JSTaggedValue::ToNumber(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/runtime/js_eval.cpp b/runtime/js_eval.cpp index 6876e9a8f2bb97713460b4f7bf1de03a24e4d7e3..9d767206164ac34545cdc7e89f94f216556a5697 100644 --- a/runtime/js_eval.cpp +++ b/runtime/js_eval.cpp @@ -16,7 +16,7 @@ #include "js_eval.h" #include "ecma_string.h" #include "include/mem/panda_string.h" -#include "plugins/ecmascript/runtime/builtins/builtins_function.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/internal_call_params.h" #include "plugins/ecmascript/runtime/interpreter/interpreter-inl.h" #include "plugins/ecmascript/es2panda/es2panda.h" @@ -119,7 +119,6 @@ JSTaggedValue EvalUtils::Eval(JSThread *thread, const JSHandle &a JSTaggedValue EvalUtils::CreateDynamicFunction(EcmaRuntimeCallInfo *argv, DynamicFunctionKind kind) { - using BuiltinsFunction = builtins::BuiltinsFunction; JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); @@ -129,9 +128,9 @@ JSTaggedValue EvalUtils::CreateDynamicFunction(EcmaRuntimeCallInfo *argv, Dynami uint32_t nargs = argv->GetArgsNumber(); if (nargs == 1) { - function_body = BuiltinsFunction::GetCallArg(argv, 0); + function_body = builtins_common::GetCallArg(argv, 0); } else if (nargs > 1) { - JSHandle first_param_handle = builtins::BuiltinsFunction::GetCallArg(argv, 0); + JSHandle first_param_handle = builtins_common::GetCallArg(argv, 0); function_param_str = JSTaggedValue::ToString(thread, first_param_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -140,14 +139,14 @@ JSTaggedValue EvalUtils::CreateDynamicFunction(EcmaRuntimeCallInfo *argv, Dynami while (iter < nargs - 1) { JSHandle comma_str = factory->NewFromCanBeCompressString(","); function_param_str = factory->ConcatFromString(function_param_str, comma_str); - JSHandle param_handle = BuiltinsFunction::GetCallArg(argv, iter); + JSHandle param_handle = builtins_common::GetCallArg(argv, iter); JSHandle param_string = JSTaggedValue::ToString(thread, param_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); function_param_str = factory->ConcatFromString(function_param_str, param_string); iter++; } - function_body = BuiltinsFunction::GetCallArg(argv, iter); + function_body = builtins_common::GetCallArg(argv, iter); } JSHandle result_str = factory->NewFromCanBeCompressString("("); diff --git a/runtime/js_for_in_iterator.cpp b/runtime/js_for_in_iterator.cpp index 033aed4438e32a01ef06d2dc74410baa164664c7..da08720fd3d625a8605b4f7575e1e312bef99ca9 100644 --- a/runtime/js_for_in_iterator.cpp +++ b/runtime/js_for_in_iterator.cpp @@ -27,7 +27,6 @@ #include "plugins/ecmascript/runtime/tagged_queue.h" namespace panda::ecmascript { -using BuiltinsBase = base::BuiltinsBase; bool JSForInIterator::CheckObjProto(const JSThread *thread, const JSHandle &it) { @@ -305,7 +304,7 @@ JSTaggedValue JSForInIterator::Next(EcmaRuntimeCallInfo *msg) JSThread *thread = msg->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle it(BuiltinsBase::GetThis(msg)); + JSHandle it(builtins_common::GetThis(msg)); ASSERT(it->IsForinIterator()); std::pair res = NextInternal(thread, it); return res.first; diff --git a/runtime/js_map_iterator.cpp b/runtime/js_map_iterator.cpp index 6989adb5ad39b5cc0a412226dd12227db5492fff..6c14ec69b16452ef992f39b9f934954919b48a18 100644 --- a/runtime/js_map_iterator.cpp +++ b/runtime/js_map_iterator.cpp @@ -14,21 +14,20 @@ */ #include "js_map_iterator.h" -#include "builtins/builtins_errors.h" #include "js_array.h" #include "js_map.h" #include "linked_hash_table-inl.h" #include "object_factory.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" namespace panda::ecmascript { -using BuiltinsBase = base::BuiltinsBase; JSTaggedValue JSMapIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let O be the this value - JSHandle input(BuiltinsBase::GetThis(argv)); + JSHandle input(builtins_common::GetThis(argv)); // 3.If O does not have all of the internal slots of a Map Iterator Instance (23.1.5.3), throw a TypeError // exception. diff --git a/runtime/js_promise.cpp b/runtime/js_promise.cpp index f536fba49d50b60e3defdefeb8f0a1e8fa8a3ce1..92ed1e2134a16c7003f27e9b65d308f14b0a6c2f 100644 --- a/runtime/js_promise.cpp +++ b/runtime/js_promise.cpp @@ -15,7 +15,7 @@ #include "plugins/ecmascript/runtime/js_promise.h" #include "plugins/ecmascript/runtime/base/error_type.h" -#include "plugins/ecmascript/runtime/builtins/builtins_promise_handler.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/internal_call_params.h" @@ -27,7 +27,6 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript { -using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler; JSHandle JSPromise::CreateResolvingFunctions(JSThread *thread, const JSHandle &promise) @@ -39,14 +38,14 @@ JSHandle JSPromise::CreateResolvingFunctions(JSThread // 2. Let resolve be a new built-in function object as defined in Promise Resolve Functions (25.4.1.3.2). JSHandle resolve = - factory->CreateJSPromiseReactionsFunction(reinterpret_cast(BuiltinsPromiseHandler::Resolve)); + factory->CreateJSPromiseReactionsFunction(reinterpret_cast(builtins::promise_handler::Resolve)); // 3. Set the [[Promise]] internal slot of resolve to promise. resolve->SetPromise(thread, promise); // 4. Set the [[AlreadyResolved]] internal slot of resolve to alreadyResolved. resolve->SetAlreadyResolved(thread, record); // 5. Let reject be a new built-in function object as defined in Promise Reject Functions (25.4.1.3.1). JSHandle reject = - factory->CreateJSPromiseReactionsFunction(reinterpret_cast(BuiltinsPromiseHandler::Reject)); + factory->CreateJSPromiseReactionsFunction(reinterpret_cast(builtins::promise_handler::Reject)); // 6. Set the [[Promise]] internal slot of reject to promise. reject->SetPromise(thread, promise); // 7. Set the [[AlreadyResolved]] internal slot of reject to alreadyResolved. @@ -97,7 +96,7 @@ JSHandle JSPromise::NewPromiseCapability(JSThread *thread, co // 4. Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions // (25.4.1.5.1). JSHandle executor = - factory->CreateJSPromiseExecutorFunction(reinterpret_cast(BuiltinsPromiseHandler::Executor)); + factory->CreateJSPromiseExecutorFunction(reinterpret_cast(builtins::promise_handler::Executor)); // 5. Set the [[Capability]] internal slot of executor to promiseCapability. executor->SetCapability(thread, promise_capability.GetTaggedValue()); // 6. Let promise be Construct(C, «executor»). diff --git a/runtime/js_regexp_iterator.cpp b/runtime/js_regexp_iterator.cpp index 9810fb06b6ba782f5526fc25472d3f927fa304e3..61eb893be1e0d19bc4f2d0cb2abdbac7db1865f7 100644 --- a/runtime/js_regexp_iterator.cpp +++ b/runtime/js_regexp_iterator.cpp @@ -15,15 +15,13 @@ #include "plugins/ecmascript/runtime/js_regexp_iterator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/builtins/builtins_regexp.h" #include "plugins/ecmascript/runtime/interpreter/fast_runtime_stub-inl.h" #include "plugins/ecmascript/runtime/js_tagged_value.h" #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript { -using BuiltinsBase = base::BuiltinsBase; -using BuiltinsRegExp = builtins::BuiltinsRegExp; JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); @@ -31,7 +29,7 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle input(BuiltinsBase::GetThis(argv)); + JSHandle input(builtins_common::GetThis(argv)); // 2. If Type(O) is not Object, throw a TypeError exception. // 3. If O does not have all of the internal slots of a RegExp String Iterator Object Instance // (see 21.2.7.2), throw a TypeError exception. @@ -57,7 +55,7 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) bool full_unicode = js_iterator->GetUnicode(); // 9. Let match be ? RegExpExec(R, S). - JSTaggedValue match = BuiltinsRegExp::RegExpExec(thread, regex_handle, input_str, false); + JSTaggedValue match = builtins::reg_exp::RegExpExec(thread, regex_handle, input_str, false); JSHandle match_handle(thread, match); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -88,7 +86,7 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) JSTaggedNumber this_index = JSTaggedValue::ToLength(thread, get_last_index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue next_index( - BuiltinsRegExp::AdvanceStringIndex(input_str, this_index.ToUint32(), full_unicode)); + builtins::reg_exp::AdvanceStringIndex(input_str, this_index.ToUint32(), full_unicode)); FastRuntimeStub::FastSetPropertyByValue(thread, regex_handle, last_index_string, HandleFromLocal(&next_index)); } diff --git a/runtime/js_serializer.cpp b/runtime/js_serializer.cpp index b0306e8897eda262f1ba731df430195b36be558e..418e79f59084bbe57da9af1b911467532fbadda1 100644 --- a/runtime/js_serializer.cpp +++ b/runtime/js_serializer.cpp @@ -1024,7 +1024,7 @@ JSHandle JSDeserializer::ReadJSMap() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle map_function = env->GetBuiltinsMapFunction(); + JSHandle map_function = env->GetMapFunction(); JSHandle js_map = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(map_function), map_function)); JSHandle map_tag = JSHandle::Cast(js_map); @@ -1056,7 +1056,7 @@ JSHandle JSDeserializer::ReadJSSet() { ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle set_function = env->GetBuiltinsSetFunction(); + JSHandle set_function = env->GetSetFunction(); JSHandle js_set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(set_function), set_function)); JSHandle set_tag = JSHandle::Cast(js_set); diff --git a/runtime/js_set_iterator.cpp b/runtime/js_set_iterator.cpp index 7f5d130a8eb68a613a13c05be8085c0e2316e1cd..3bc404db45e0dc4c8dfaf21744d2897c34538cdc 100644 --- a/runtime/js_set_iterator.cpp +++ b/runtime/js_set_iterator.cpp @@ -14,7 +14,7 @@ */ #include "plugins/ecmascript/runtime/js_set_iterator.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_macros.h" #include "plugins/ecmascript/runtime/js_array.h" #include "plugins/ecmascript/runtime/js_set.h" @@ -22,14 +22,13 @@ #include "plugins/ecmascript/runtime/object_factory.h" namespace panda::ecmascript { -using BuiltinsBase = base::BuiltinsBase; JSTaggedValue JSSetIterator::Next(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(O) is not Object, throw a TypeError exception. - JSHandle input(BuiltinsBase::GetThis(argv)); + JSHandle input(builtins_common::GetThis(argv)); // 3.If O does not have all of the internal slots of a Set Iterator Instance (23.2.5.3), throw a TypeError // exception. diff --git a/runtime/js_stable_array.cpp b/runtime/js_stable_array.cpp index e62c41494f568d48687827cde2e525abe97a8569..ff9f1ec85577a9e8a1c089c58ffaf29e94efe1fd 100644 --- a/runtime/js_stable_array.cpp +++ b/runtime/js_stable_array.cpp @@ -191,7 +191,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInf { JSThread *thread = argv->GetThread(); uint32_t length = receiver->GetArrayLength(); - JSHandle sep_handle = base::BuiltinsBase::GetCallArg(argv, 0); + JSHandle sep_handle = builtins_common::GetCallArg(argv, 0); int sep = ','; uint32_t sep_length = 1; JSHandle sep_string_handle; diff --git a/runtime/js_string_iterator.cpp b/runtime/js_string_iterator.cpp index 02d72730efc79ffec15352c777de72702807cb0d..ef044cdbb587d6f2b910fb8b6e0fbd77ccd04444 100644 --- a/runtime/js_string_iterator.cpp +++ b/runtime/js_string_iterator.cpp @@ -28,7 +28,7 @@ JSHandle JSStringIterator::CreateStringIterator(const JSThread // 1. Assert: Type(string) is String. // 2. Let iterator be ObjectCreate(%StringIteratorPrototype%, [[IteratedString]], [[StringIteratorNextIndex]] ?.) JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle str_iter_ctor = env->GetStringIterator(); + JSHandle str_iter_ctor = env->GetStringIteratorFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle iterator = JSHandle::Cast( factory->NewJSObjectByConstructor(JSHandle(str_iter_ctor), str_iter_ctor)); diff --git a/runtime/js_symbol.h b/runtime/js_symbol.h index 3ba598b874053dc2120117e1243fed3dd595179b..407b9001546d61b2f3e17d795a62b00a5309481c 100644 --- a/runtime/js_symbol.h +++ b/runtime/js_symbol.h @@ -29,9 +29,18 @@ public: static constexpr uint64_t IS_PRIVATE_NAME = 1U << 4U; static constexpr uint64_t IS_PRIVATE_BRAND = 1U << 5U; - static constexpr int SYMBOL_HAS_INSTANCE_TYPE = 0; - static constexpr int SYMBOL_TO_PRIMITIVE_TYPE = 1; - static constexpr int SYMBOL_DEFAULT_TYPE = 2; + enum class SymbolType { + HAS_INSTANCE, + TO_PRIMITIVE, + ASYNC_ITERATOR, + ITERATOR, + MATCH, + MATCH_ALL, + REPLACE, + SEARCH, + SPLIT, + DEFAULT + }; static constexpr const uint32_t LINEAR_X = 1103515245U; static constexpr const uint32_t LINEAR_Y = 12345U; diff --git a/runtime/js_typed_array.cpp b/runtime/js_typed_array.cpp index e73364f2856bc2b6853f522503be23b6d8dd6723..39d26a9f45af6d603f921b71cd29944c7ae7fc5f 100644 --- a/runtime/js_typed_array.cpp +++ b/runtime/js_typed_array.cpp @@ -13,14 +13,13 @@ * limitations under the License. */ +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/js_typed_array.h" #include "plugins/ecmascript/runtime/accessor_data.h" #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" namespace panda::ecmascript { using TypedArrayHelper = base::TypedArrayHelper; -using BuiltinsArrayBuffer = builtins::BuiltinsArrayBuffer; JSHandle JSTypedArray::ToPropKey(JSThread *thread, const JSHandle &key) { @@ -90,7 +89,7 @@ bool JSTypedArray::HasProperty(JSThread *thread, const JSHandle & RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); if (!numeric_index.IsUndefined()) { JSTaggedValue buffer = JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer(); - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); } if (!numeric_index.IsInteger()) { @@ -316,7 +315,7 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J // To make developer get buffer each time use scope and don't populate buffer into function's scope. JSTaggedValue buffer = JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer(); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } @@ -359,7 +358,7 @@ OperationResult JSTypedArray::IntegerIndexedElementGet(JSThread *thread, const J // We use buffer without handle and GC can move it. So we have to get buffer each time. // To make developer get buffer each time use scope and don't populate buffer into function's scope. JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); - result = BuiltinsArrayBuffer::GetValueFromBuffer(thread, buffer, byte_index, element_type, true); + result = builtins::array_buffer::GetValueFromBuffer(thread, buffer, byte_index, element_type, true); } return OperationResult(thread, result, PropertyMetaData(true)); } @@ -376,7 +375,7 @@ bool JSTypedArray::FastCopyElementToArray(JSThread *thread, const JSHandle typedarray_obj(typed_array); JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { + if (builtins::array_buffer::IsDetachedBuffer(buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); } @@ -397,7 +396,8 @@ bool JSTypedArray::FastCopyElementToArray(JSThread *thread, const JSHandleSet(thread, index, result); } return true; @@ -417,7 +417,7 @@ OperationResult JSTypedArray::FastElementGet(JSThread *thread, const JSHandleGetViewedArrayBuffer(); // 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } @@ -442,7 +442,8 @@ OperationResult JSTypedArray::FastElementGet(JSThread *thread, const JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); - JSTaggedValue result = BuiltinsArrayBuffer::GetValueFromBuffer(thread, buffer, byte_index, element_type, true); + JSTaggedValue result = + builtins::array_buffer::GetValueFromBuffer(thread, buffer, byte_index, element_type, true); return OperationResult(thread, result, PropertyMetaData(true)); } } @@ -475,7 +476,7 @@ bool JSTypedArray::IntegerIndexedElementSet(JSThread *thread, const JSHandleGetViewedArrayBuffer(); // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { + if (builtins::array_buffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", false); } } @@ -516,7 +517,7 @@ bool JSTypedArray::IntegerIndexedElementSet(JSThread *thread, const JSHandle buffer(thread, JSTypedArray::Cast(*typedarray_obj)->GetViewedArrayBuffer()); - BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, byte_index, element_type, num_value_handle, true); + builtins::array_buffer::SetValueInBuffer(thread, buffer, byte_index, element_type, num_value_handle, true); } // 17. Return true. return true; diff --git a/runtime/napi/jsnapi.cpp b/runtime/napi/jsnapi.cpp index b5612c644dbe4341625ebf7bc402395e3a4a7d2b..38948b67b267dc8b7fb1b58ed831d8955500a434 100644 --- a/runtime/napi/jsnapi.cpp +++ b/runtime/napi/jsnapi.cpp @@ -91,7 +91,6 @@ using ecmascript::OperationResult; using ecmascript::PromiseCapability; using ecmascript::PropertyDescriptor; using ecmascript::TaggedArray; -using ecmascript::base::BuiltinsBase; using ecmascript::base::JsonParser; using ecmascript::base::JsonStringifier; using ecmascript::base::StringHelper; @@ -1447,7 +1446,7 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) // Constructor JSThread *thread = info->GetThread(); [[maybe_unused]] panda::ecmascript::EcmaHandleScope handle_scope(thread); - JSHandle constructor = BuiltinsBase::GetConstructor(info); + JSHandle constructor = ecmascript::builtins_common::GetConstructor(info); if (!constructor->IsJSFunction()) { return JSTaggedValue::False(); } @@ -1480,13 +1479,13 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) FunctionCallback native_func = (reinterpret_cast(call_back_obj->GetExternalPointer())); // this - JSHandle this_value(BuiltinsBase::GetThis(info)); + JSHandle this_value(ecmascript::builtins_common::GetThis(info)); // arguments std::vector> arguments; uint32_t length = info->GetArgsNumber(); for (uint32_t i = 0; i < length; ++i) { - arguments.emplace_back(JSNApiHelper::ToLocal(BuiltinsBase::GetCallArg(info, i))); + arguments.emplace_back(JSNApiHelper::ToLocal(ecmascript::builtins_common::GetCallArg(info, i))); } ScopedNativeCodeThread s(thread); @@ -1499,7 +1498,7 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall { // Constructor JSThread *thread = info->GetThread(); - JSHandle constructor = BuiltinsBase::GetConstructor(info); + JSHandle constructor = ecmascript::builtins_common::GetConstructor(info); if (!constructor->IsJSFunction()) { return JSTaggedValue::False(); } @@ -1525,13 +1524,13 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall FunctionCallback native_func = (reinterpret_cast(call_back_obj->GetExternalPointer())); // constructor - JSHandle this_value(BuiltinsBase::GetConstructor(info)); + JSHandle this_value(ecmascript::builtins_common::GetConstructor(info)); // arguments std::vector> arguments; uint32_t length = info->GetArgsNumber(); for (uint32_t i = 0; i < length; ++i) { - arguments.emplace_back(JSNApiHelper::ToLocal(BuiltinsBase::GetCallArg(info, i))); + arguments.emplace_back(JSNApiHelper::ToLocal(ecmascript::builtins_common::GetCallArg(info, i))); } ScopedNativeCodeThread s(thread); @@ -1544,7 +1543,7 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal { // Constructor JSThread *thread = info->GetThread(); - JSHandle constructor = BuiltinsBase::GetConstructor(info); + JSHandle constructor = ecmascript::builtins_common::GetConstructor(info); if (!constructor->IsJSFunction()) { return JSTaggedValue::False(); } @@ -1571,16 +1570,16 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal (reinterpret_cast(call_back_obj->GetExternalPointer())); // new_target - JSHandle new_target(BuiltinsBase::GetNewTarget(info)); + JSHandle new_target(ecmascript::builtins_common::GetNewTarget(info)); // this - JSHandle this_value(BuiltinsBase::GetThis(info)); + JSHandle this_value(ecmascript::builtins_common::GetThis(info)); // arguments std::vector> arguments; uint32_t length = info->GetArgsNumber(); for (uint32_t i = 0; i < length; ++i) { - arguments.emplace_back(JSNApiHelper::ToLocal(BuiltinsBase::GetCallArg(info, i))); + arguments.emplace_back(JSNApiHelper::ToLocal(ecmascript::builtins_common::GetCallArg(info, i))); } ScopedNativeCodeThread s(thread); diff --git a/runtime/object_factory.cpp b/runtime/object_factory.cpp index 8565a3820d60e7db2b772dce03c58a08b7e15f14..f69a6eede2421353cc1572e03de4594aae9834f7 100644 --- a/runtime/object_factory.cpp +++ b/runtime/object_factory.cpp @@ -20,8 +20,6 @@ #include "plugins/ecmascript/runtime/accessor_data.h" #include "plugins/ecmascript/runtime/base/error_helper.h" #include "plugins/ecmascript/runtime/builtins.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" -#include "plugins/ecmascript/runtime/builtins/builtins_global.h" #include "plugins/ecmascript/runtime/class_info_extractor.h" #include "plugins/ecmascript/runtime/class_linker/program_object.h" #include "plugins/ecmascript/runtime/ecma_macros.h" @@ -79,13 +77,7 @@ #include "plugins/ecmascript/runtime/interpreter/slow_runtime_stub.h" namespace panda::ecmascript { -using Error = builtins::BuiltinsError; -using RangeError = builtins::BuiltinsRangeError; -using ReferenceError = builtins::BuiltinsReferenceError; -using TypeError = builtins::BuiltinsTypeError; -using URIError = builtins::BuiltinsURIError; -using SyntaxError = builtins::BuiltinsSyntaxError; -using EvalError = builtins::BuiltinsEvalError; + using ErrorType = base::ErrorType; using ErrorHelper = base::ErrorHelper; @@ -902,8 +894,8 @@ JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandleSetCollator(thread_, JSTaggedValue::Undefined()); break; case JSType::JS_BOUND_FUNCTION: { - JSMethod *method = vm_->GetMethodForNativeFunction( - reinterpret_cast(builtins::BuiltinsGlobal::CallJsBoundFunction)); + JSMethod *method = + vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::global::CallJsBoundFunction)); JSBoundFunction::Cast(*obj)->SetMethod(method); JSBoundFunction::Cast(*obj)->SetBoundTarget(thread_, JSTaggedValue::Undefined()); JSBoundFunction::Cast(*obj)->SetBoundThis(thread_, JSTaggedValue::Undefined()); @@ -1120,8 +1112,7 @@ JSHandle ObjectFactory::NewJSBoundFunction(const JSHandleSetConstructor(true); } - JSMethod *method = - vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::BuiltinsGlobal::CallJsBoundFunction)); + JSMethod *method = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::global::CallJsBoundFunction)); bundle_function->SetCallTarget(thread_, method); return bundle_function; } @@ -1612,7 +1603,7 @@ JSHandle ObjectFactory::NewJSProxy(const JSHandle &targe JSHandle proxy(thread_, header); JSMethod *method = nullptr; if (target->IsCallable()) { - method = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::BuiltinsGlobal::CallJsProxy)); + method = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::global::CallJsProxy)); proxy->SetCallTarget(thread_, method); } proxy->SetMethod(method); @@ -1635,7 +1626,7 @@ JSHandle ObjectFactory::NewJSRealm() auto result = TemplateMap::Create(thread_); realm_env_handle->SetTemplateMap(thread_, result); - Builtins builtins; + builtins::Builtins builtins; builtins.Initialize(realm_env_handle, thread_); JSHandle proto_value = thread_->GlobalConstants()->GetHandledJSRealmClass(); JSHandle dyn_handle = CreateDynClass(JSType::JS_REALM, proto_value); @@ -2124,7 +2115,7 @@ JSHandle ObjectFactory::CreateJSPromiseExecutorFuncti executor_function->SetCapability(thread_, JSTaggedValue::Undefined()); JSHandle function = JSHandle::Cast(executor_function); JSFunction::InitializeJSFunction(thread_, function, FunctionKind::NORMAL_FUNCTION); - JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(FunctionLength::TWO)); + JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(builtins::FunctionLength::TWO)); return executor_function; } diff --git a/runtime/object_factory.h b/runtime/object_factory.h index f5aadb9257a6ad4733ed9d3ad0ef6291f387f9f0..e4a1f6103c8f946264c931e9830c47b83fd00e63 100644 --- a/runtime/object_factory.h +++ b/runtime/object_factory.h @@ -103,6 +103,10 @@ class ProtoChangeDetails; class ProfileTypeInfo; class ClassInfoExtractor; +namespace builtins { +class Builtins; +} // namespace builtins + enum class PrimitiveType : uint8_t; enum class IterationKind; @@ -546,10 +550,10 @@ private: JSHandle CreateJSArrayInstanceClass(JSHandle proto); JSHandle CreateJSRegExpInstanceClass(JSHandle proto); - friend class Builtins; // create builtins object need dynclass - friend class JSFunction; // create prototype_or_dynclass need dynclass - friend class JSHClass; // HC transition need dynclass - friend class EcmaVM; // hold the factory instance + friend class builtins::Builtins; // create builtins object need dynclass + friend class JSFunction; // create prototype_or_dynclass need dynclass + friend class JSHClass; // HC transition need dynclass + friend class EcmaVM; // hold the factory instance friend class JsVerificationTest; friend class PandaFileTranslator; friend class LiteralDataExtractor; diff --git a/runtime/runtime_call_id.h b/runtime/runtime_call_id.h index 0906412a1f216ed6aad3f1f1de384fedf118c75c..1a7a9a0dfae2bd786a05ac9162048074fb25eaf0 100644 --- a/runtime/runtime_call_id.h +++ b/runtime/runtime_call_id.h @@ -427,8 +427,8 @@ namespace panda::ecmascript { V(Object, DefineProperty) \ V(Object, Freeze) \ V(Object, FromEntries) \ - V(Object, GetOwnPropertyDesciptor) \ - V(Object, GetOwnPropertyDesciptors) \ + V(Object, GetOwnPropertyDescriptor) \ + V(Object, GetOwnPropertyDescriptors) \ V(Object, GetOwnPropertyKeys) \ V(Object, GetOwnPropertyNames) \ V(Object, GetOwnPropertySymbols) \ diff --git a/subproject_sources.gn b/subproject_sources.gn index 28616162e568b30f646a8e0ea37ba2dac71ff9d3..1c75a77bcece720d7708ab3161234fc5053c3514 100644 --- a/subproject_sources.gn +++ b/subproject_sources.gn @@ -42,6 +42,8 @@ irtoc_plugins = [ arkruntime_header_sub_deps = [ "$_plugin_dir:ecma_intrinsics_gen_arkruntime", + "$_plugin_dir:ecma_builtins_gen_builtins_declaration_gen_h", + "$_plugin_dir:ecma_builtins_gen_builtins_initializers_gen_h", ] arkruntime_stdlib_sub_deps = [ "$_plugin_dir:ecmastdlib_inline_h", diff --git a/tests/runtime/builtins/builtins_array_test.cpp b/tests/runtime/builtins/builtins_array_test.cpp index f8cb53c8912e9395cf3507c55f6435c8aead4e85..7ba67a3868609521d4774d2b7761e909f693e91d 100644 --- a/tests/runtime/builtins/builtins_array_test.cpp +++ b/tests/runtime/builtins/builtins_array_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_array.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -38,7 +38,6 @@ using namespace panda::ecmascript::builtins; using namespace panda::ecmascript::base; namespace panda::test { -using Array = ecmascript::builtins::BuiltinsArray; class BuiltinsArrayTest : public testing::Test { public: static void SetUpTestCase() @@ -65,15 +64,15 @@ public: EcmaHandleScope *scope {nullptr}; JSThread *thread {nullptr}; - class TestClass : public base::BuiltinsBase { + class TestClass { public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); if (key->IsUndefined()) { return JSTaggedValue::Undefined(); } - JSArray *js_array = JSArray::Cast(GetThis(argv)->GetTaggedObject()); + JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); int length = js_array->GetArrayLength() + 1; js_array->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); @@ -83,18 +82,18 @@ public: { uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { - if (GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestMapFunc(EcmaRuntimeCallInfo *argv) { - int accumulator = GetCallArg(argv, 0)->GetInt(); + int accumulator = builtins_common::GetCallArg(argv, 0)->GetInt(); accumulator = accumulator * 2; // 2 : mapped to 2 times the original value - return BuiltinsBase::GetTaggedInt(accumulator); + return builtins_common::GetTaggedInt(accumulator); } static JSTaggedValue TestFindFunc(EcmaRuntimeCallInfo *argv) @@ -102,11 +101,11 @@ public: uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestFindIndexFunc(EcmaRuntimeCallInfo *argv) @@ -114,36 +113,36 @@ public: uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestReduceFunc(EcmaRuntimeCallInfo *argv) { - int accumulator = GetCallArg(argv, 0)->GetInt(); - accumulator = accumulator + GetCallArg(argv, 1)->GetInt(); - return BuiltinsBase::GetTaggedInt(accumulator); + int accumulator = builtins_common::GetCallArg(argv, 0)->GetInt(); + accumulator = accumulator + builtins_common::GetCallArg(argv, 1)->GetInt(); + return builtins_common::GetTaggedInt(accumulator); } static JSTaggedValue TestReduceRightFunc(EcmaRuntimeCallInfo *argv) { - int accumulator = GetCallArg(argv, 0)->GetInt(); - accumulator = accumulator + GetCallArg(argv, 1)->GetInt(); - return BuiltinsBase::GetTaggedInt(accumulator); + int accumulator = builtins_common::GetCallArg(argv, 0)->GetInt(); + accumulator = accumulator + builtins_common::GetCallArg(argv, 1)->GetInt(); + return builtins_common::GetTaggedInt(accumulator); } static JSTaggedValue TestSomeFunc(EcmaRuntimeCallInfo *argv) { uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { - if (GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } // x => [x*2] @@ -152,7 +151,7 @@ public: auto thread = argv->GetThread(); // element = [x] - JSTaggedValue element = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue element = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle key0(thread, JSTaggedValue(0)); @@ -163,7 +162,7 @@ public: int accumulator = val.GetNumber(); accumulator *= 2; - return BuiltinsBase::GetTaggedInt(accumulator); + return builtins_common::GetTaggedInt(accumulator); } }; }; @@ -198,7 +197,7 @@ TEST_F(BuiltinsArrayTest, ArrayConstructor) ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::ArrayConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::ArrayConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -246,7 +245,7 @@ TEST_F(BuiltinsArrayTest, From) ecma_runtime_call_info1->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::From(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::From(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -279,7 +278,7 @@ TEST_F(BuiltinsArrayTest, IsArray) ecma_runtime_call_info1->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::IsArray(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::IsArray(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -289,7 +288,7 @@ TEST_F(BuiltinsArrayTest, IsArray) ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue(static_cast(1))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result = Array::IsArray(ecma_runtime_call_info2.get()); + result = array::IsArray(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -309,7 +308,7 @@ TEST_F(BuiltinsArrayTest, Of) ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Of(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::Of(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -339,7 +338,7 @@ TEST_F(BuiltinsArrayTest, Species) ecma_runtime_call_info1->SetThis(global_object.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Species(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::GetSpecies(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); } @@ -379,7 +378,7 @@ TEST_F(BuiltinsArrayTest, Concat) ecma_runtime_call_info1->SetCallArg(0, obj1.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Concat(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Concat(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -426,7 +425,7 @@ TEST_F(BuiltinsArrayTest, CopyWithin) ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::CopyWithin(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::CopyWithin(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -477,7 +476,7 @@ TEST_F(BuiltinsArrayTest, Every) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = Array::Every(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = array::proto::Every(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -513,7 +512,7 @@ TEST_F(BuiltinsArrayTest, Map) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Map(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Map(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -553,7 +552,7 @@ TEST_F(BuiltinsArrayTest, Reverse) ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Reverse(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Reverse(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -607,7 +606,7 @@ TEST_F(BuiltinsArrayTest, Slice) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(4))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Slice(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Slice(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -655,7 +654,7 @@ TEST_F(BuiltinsArrayTest, Splice) ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(100))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Splice(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Splice(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -724,7 +723,7 @@ TEST_F(BuiltinsArrayTest, Flat) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Flat(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Flat(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); PropertyDescriptor desc_res(thread); @@ -758,7 +757,7 @@ TEST_F(BuiltinsArrayTest, Flat) ecma_runtime_call_info2->SetThis(obj1.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result = Array::Flat(ecma_runtime_call_info2.get()); + result = array::proto::Flat(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value2(static_cast(result.GetRawData())); @@ -854,7 +853,7 @@ TEST_F(BuiltinsArrayTest, FlatMap) ecma_runtime_call_info1->SetCallArg(0, cb.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::FlatMap(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::FlatMap(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); PropertyDescriptor res_desc(thread); @@ -906,7 +905,7 @@ TEST_F(BuiltinsArrayTest, Fill) ecma_runtime_call_info1->SetCallArg(2, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Fill(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Fill(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -954,7 +953,7 @@ TEST_F(BuiltinsArrayTest, Find) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = Array::Find(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = array::proto::Find(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue(102).GetRawData()); @@ -993,7 +992,7 @@ TEST_F(BuiltinsArrayTest, FindIndex) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = Array::FindIndex(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = array::proto::FindIndex(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -1031,7 +1030,7 @@ TEST_F(BuiltinsArrayTest, ForEach) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = Array::ForEach(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = array::proto::ForEach(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(js_array->GetArrayLength(), 3); @@ -1072,7 +1071,7 @@ TEST_F(BuiltinsArrayTest, Includes1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Array::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -1112,7 +1111,7 @@ TEST_F(BuiltinsArrayTest, Includes2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Array::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -1152,7 +1151,7 @@ TEST_F(BuiltinsArrayTest, Includes3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Array::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -1191,7 +1190,7 @@ TEST_F(BuiltinsArrayTest, Includes4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Array::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -1230,7 +1229,7 @@ TEST_F(BuiltinsArrayTest, Includes5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Array::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -1267,7 +1266,7 @@ TEST_F(BuiltinsArrayTest, IndexOf) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::IndexOf(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::IndexOf(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -1278,7 +1277,7 @@ TEST_F(BuiltinsArrayTest, IndexOf) ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue(static_cast(3))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result = Array::IndexOf(ecma_runtime_call_info2.get()); + result = array::proto::IndexOf(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); @@ -1289,7 +1288,7 @@ TEST_F(BuiltinsArrayTest, IndexOf) ecma_runtime_call_info3->SetCallArg(1, JSTaggedValue(static_cast(0))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - result = Array::IndexOf(ecma_runtime_call_info3.get()); + result = array::proto::IndexOf(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); @@ -1299,7 +1298,7 @@ TEST_F(BuiltinsArrayTest, IndexOf) ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(static_cast(3))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - result = Array::IndexOf(ecma_runtime_call_info4.get()); + result = array::proto::IndexOf(ecma_runtime_call_info4.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -1337,7 +1336,7 @@ TEST_F(BuiltinsArrayTest, LastIndexOf) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(4))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::LastIndexOf(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::LastIndexOf(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); @@ -1349,7 +1348,7 @@ TEST_F(BuiltinsArrayTest, LastIndexOf) ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue(static_cast(3))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result = Array::LastIndexOf(ecma_runtime_call_info2.get()); + result = array::proto::LastIndexOf(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -1361,7 +1360,7 @@ TEST_F(BuiltinsArrayTest, LastIndexOf) ecma_runtime_call_info3->SetCallArg(1, JSTaggedValue(static_cast(4))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - result = Array::LastIndexOf(ecma_runtime_call_info3.get()); + result = array::proto::LastIndexOf(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); @@ -1372,7 +1371,7 @@ TEST_F(BuiltinsArrayTest, LastIndexOf) ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(static_cast(3))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - result = Array::LastIndexOf(ecma_runtime_call_info4.get()); + result = array::proto::LastIndexOf(ecma_runtime_call_info4.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); } @@ -1391,7 +1390,7 @@ TEST_F(BuiltinsArrayTest, Pop) ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Pop(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Pop(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -1411,7 +1410,7 @@ TEST_F(BuiltinsArrayTest, Pop) ecma_runtime_call_info2->SetThis(obj.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result = Array::Pop(ecma_runtime_call_info2.get()); + result = array::proto::Pop(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); } @@ -1442,7 +1441,7 @@ TEST_F(BuiltinsArrayTest, Push) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Push(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Push(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetNumber(), 5); @@ -1483,7 +1482,7 @@ TEST_F(BuiltinsArrayTest, Reduce) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Reduce(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Reduce(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(16).GetRawData()); } @@ -1518,7 +1517,7 @@ TEST_F(BuiltinsArrayTest, ReduceRight) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::ReduceRight(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::ReduceRight(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(16).GetRawData()); } @@ -1546,7 +1545,7 @@ TEST_F(BuiltinsArrayTest, Shift) ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Shift(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Shift(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -1583,7 +1582,7 @@ TEST_F(BuiltinsArrayTest, Some) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = Array::Some(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = array::proto::Some(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -1611,7 +1610,7 @@ TEST_F(BuiltinsArrayTest, Sort) ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = Array::Sort(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = array::proto::Sort(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsECMAObject()); @@ -1647,7 +1646,7 @@ TEST_F(BuiltinsArrayTest, Unshift) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Unshift(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Unshift(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); @@ -1683,7 +1682,7 @@ TEST_F(BuiltinsArrayTest, Join) ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Join(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Join(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); [[maybe_unused]] auto *res = EcmaString::Cast(result_handle.GetTaggedValue().GetTaggedObject()); @@ -1715,7 +1714,7 @@ TEST_F(BuiltinsArrayTest, ToString) ecma_runtime_call_info1->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = Array::Join(ecma_runtime_call_info1.get()); + JSTaggedValue result = array::proto::Join(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); [[maybe_unused]] auto *res = EcmaString::Cast(result_handle.GetTaggedValue().GetTaggedObject()); diff --git a/tests/runtime/builtins/builtins_arraybuffer_test.cpp b/tests/runtime/builtins/builtins_arraybuffer_test.cpp index d6ccd3d9caaafbf0b225645ae9d8ce369bbb75cb..ed11e264182cb354c466e28a9b328d5eaf03591d 100644 --- a/tests/runtime/builtins/builtins_arraybuffer_test.cpp +++ b/tests/runtime/builtins/builtins_arraybuffer_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -66,7 +66,7 @@ JSTaggedValue CreateBuiltinsArrayBuffer(JSThread *thread, int32_t length) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(length)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); return result; } @@ -82,7 +82,7 @@ TEST_F(BuiltinsArrayBufferTest, Constructor1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(8))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -96,7 +96,7 @@ TEST_F(BuiltinsArrayBufferTest, byteLength1) ecma_runtime_call_info->SetThis(arr_buf.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsArrayBuffer::GetByteLength(ecma_runtime_call_info.get()); + JSTaggedValue result = builtins::array_buffer::proto::GetByteLength(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(5).GetRawData()); } @@ -112,7 +112,7 @@ TEST_F(BuiltinsArrayBufferTest, slice1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsArrayBuffer::Slice(ecma_runtime_call_info.get()); + JSTaggedValue result1 = builtins::array_buffer::proto::Slice(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); JSHandle arr_buf1(thread, JSArrayBuffer::Cast(reinterpret_cast(result1.GetRawData()))); @@ -120,7 +120,7 @@ TEST_F(BuiltinsArrayBufferTest, slice1) ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); ecma_runtime_call_info1->SetThis(arr_buf1.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsArrayBuffer::GetByteLength(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = builtins::array_buffer::proto::GetByteLength(ecma_runtime_call_info1.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(4).GetRawData()); } diff --git a/tests/runtime/builtins/builtins_bigint_test.cpp b/tests/runtime/builtins/builtins_bigint_test.cpp index cf053f0809ff0e83f3a2a3c54423da8c08a5374a..53d45231eceb205b91c0f56b080f94ff61e8834f 100644 --- a/tests/runtime/builtins/builtins_bigint_test.cpp +++ b/tests/runtime/builtins/builtins_bigint_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_bigint.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/js_bigint.h" #include "plugins/ecmascript/runtime/js_primitive_ref.h" @@ -21,7 +21,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; -using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; namespace panda::test { using BigInt = ecmascript::BigInt; @@ -65,7 +64,7 @@ TEST_F(BuiltinsBigIntTest, BigIntConstructor1) ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = big_int::BigIntConstructor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -83,7 +82,7 @@ TEST_F(BuiltinsBigIntTest, BigIntConstructor2) ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = big_int::BigIntConstructor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -103,7 +102,7 @@ TEST_F(BuiltinsBigIntTest, AsIntN1) ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBigInt::AsIntN(ecma_runtime_call_info.get()); + JSTaggedValue result = big_int::AsIntN(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -127,7 +126,7 @@ TEST_F(BuiltinsBigIntTest, AsIntN2) ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBigInt::AsIntN(ecma_runtime_call_info.get()); + JSTaggedValue result = big_int::AsIntN(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -151,7 +150,7 @@ TEST_F(BuiltinsBigIntTest, AsUintN1) ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBigInt::AsUintN(ecma_runtime_call_info.get()); + JSTaggedValue result = big_int::AsUintN(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -175,7 +174,7 @@ TEST_F(BuiltinsBigIntTest, AsUintN2) ecma_runtime_call_info->SetCallArg(1, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBigInt::AsUintN(ecma_runtime_call_info.get()); + JSTaggedValue result = big_int::AsUintN(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -197,7 +196,7 @@ TEST_F(BuiltinsBigIntTest, ToLocaleString1) ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -210,7 +209,7 @@ TEST_F(BuiltinsBigIntTest, ToLocaleString1) ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue::Undefined()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToLocaleString(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ToLocaleString(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -237,7 +236,7 @@ TEST_F(BuiltinsBigIntTest, ToLocaleString2) ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -252,7 +251,7 @@ TEST_F(BuiltinsBigIntTest, ToLocaleString2) ecma_runtime_call_info2->SetCallArg(1, options_obj.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToLocaleString(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ToLocaleString(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -272,7 +271,7 @@ TEST_F(BuiltinsBigIntTest, ToString1) ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -282,7 +281,7 @@ TEST_F(BuiltinsBigIntTest, ToString1) ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue::Undefined()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -302,7 +301,7 @@ TEST_F(BuiltinsBigIntTest, ToString2) ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -312,7 +311,7 @@ TEST_F(BuiltinsBigIntTest, ToString2) ecma_runtime_call_info2->SetCallArg(0, JSTaggedValue::Undefined()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -332,7 +331,7 @@ TEST_F(BuiltinsBigIntTest, ToString3) ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -343,7 +342,7 @@ TEST_F(BuiltinsBigIntTest, ToString3) ecma_runtime_call_info2->SetCallArg(0, radix.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -363,7 +362,7 @@ TEST_F(BuiltinsBigIntTest, ToString4) ecma_runtime_call_info1->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -374,7 +373,7 @@ TEST_F(BuiltinsBigIntTest, ToString4) ecma_runtime_call_info2->SetCallArg(0, radix.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ToString(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -394,7 +393,7 @@ TEST_F(BuiltinsBigIntTest, ValueOf1) ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -403,7 +402,7 @@ TEST_F(BuiltinsBigIntTest, ValueOf1) ecma_runtime_call_info2->SetThis(big_int_handle.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ValueOf(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ValueOf(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(BigInt::SameValue(thread, result1, result2), true); @@ -421,7 +420,7 @@ TEST_F(BuiltinsBigIntTest, ValueOf2) ecma_runtime_call_info->SetCallArg(0, numeric_value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result1 = big_int::BigIntConstructor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); JSHandle big_int_handle(thread, result1); @@ -434,7 +433,7 @@ TEST_F(BuiltinsBigIntTest, ValueOf2) ecma_runtime_call_info2->SetThis(js_primitive_ref.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ValueOf(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = big_int::proto::ValueOf(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(BigInt::SameValue(thread, big_int_handle.GetTaggedValue(), result2), true); diff --git a/tests/runtime/builtins/builtins_boolean_test.cpp b/tests/runtime/builtins/builtins_boolean_test.cpp index 5f088dc65d60949474085ebccc3d962899743e69..2a0cd4067125b540987b56693a0ad5b33d02e030 100644 --- a/tests/runtime/builtins/builtins_boolean_test.cpp +++ b/tests/runtime/builtins/builtins_boolean_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_boolean.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -26,7 +26,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; -using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; namespace panda::test { class BuiltinsBooleanTest : public testing::Test { @@ -70,7 +69,7 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(123))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsTrue(), 1); @@ -90,7 +89,7 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsFalse(), 1); @@ -111,9 +110,9 @@ TEST_F(BuiltinsBooleanTest, BooleanConstructor2) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info.get()); - JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(true); + JSTaggedValue ruler = builtins_common::GetTaggedBoolean(true); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); } @@ -125,7 +124,7 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeToString) ecma_runtime_call_info->SetThis(JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeToString(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::proto::ToString(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); auto ruler = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("false"); @@ -147,7 +146,7 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeToString1) ecma_runtime_call_info->SetThis(boolean.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeToString(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::proto::ToString(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); auto ruler = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("true"); @@ -162,9 +161,9 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeValueOf) ecma_runtime_call_info->SetThis(JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::proto::ValueOf(ecma_runtime_call_info.get()); - JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(true); + JSTaggedValue ruler = builtins_common::GetTaggedBoolean(true); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); } @@ -183,9 +182,9 @@ TEST_F(BuiltinsBooleanTest, BooleanPrototypeValueOf1) ecma_runtime_call_info->SetThis(boolean.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result = boolean::proto::ValueOf(ecma_runtime_call_info.get()); - JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(false); + JSTaggedValue ruler = builtins_common::GetTaggedBoolean(false); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_dataview_test.cpp b/tests/runtime/builtins/builtins_dataview_test.cpp index 89be40416d4da67b8a673b9d727f1bb746ddf6f8..ff610b0696261b187855c418421f52c8e1c1c2b1 100644 --- a/tests/runtime/builtins/builtins_dataview_test.cpp +++ b/tests/runtime/builtins/builtins_dataview_test.cpp @@ -13,8 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_dataview.h" -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -68,7 +67,7 @@ JSTaggedValue CreateBuiltinsArrayBuffer(JSThread *thread, int32_t length) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(length)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = builtins::array_buffer::ArrayBufferConstructor(ecma_runtime_call_info.get()); return result; } @@ -87,7 +86,7 @@ JSTaggedValue CreateBuiltinsDataView(JSThread *thread, int32_t length, int32_t b ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(byte_offset)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::DataViewConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::DataViewConstructor(ecma_runtime_call_info.get()); return result; } @@ -100,7 +99,7 @@ void SetUint8(JSThread *thread, const JSHandle &view, int32_t offset ecma_runtime_call_info->SetCallArg(1, value); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDataView::SetUint8(ecma_runtime_call_info.get()); + data_view::proto::SetUint8(ecma_runtime_call_info.get()); } // new DataView(new ArrayBuffer(10), 1) @@ -118,7 +117,7 @@ TEST_F(BuiltinsDataViewTest, Constructor) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(1)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::DataViewConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::DataViewConstructor(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -132,7 +131,7 @@ TEST_F(BuiltinsDataViewTest, byteOffset) ecma_runtime_call_info->SetThis(view.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetOffset(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetByteOffset(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -146,7 +145,7 @@ TEST_F(BuiltinsDataViewTest, byteLength) ecma_runtime_call_info->SetThis(view.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetByteLength(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetByteLength(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(8).GetRawData()); } @@ -160,7 +159,7 @@ TEST_F(BuiltinsDataViewTest, buffer) ecma_runtime_call_info->SetThis(view.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetBuffer(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetBuffer(ecma_runtime_call_info.get()); ASSERT_EQ(result.IsArrayBuffer(), true); } @@ -177,7 +176,7 @@ TEST_F(BuiltinsDataViewTest, getUint16) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetUint16(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetUint16(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -186,7 +185,7 @@ TEST_F(BuiltinsDataViewTest, getUint16) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::True()); - JSTaggedValue result1 = BuiltinsDataView::GetUint16(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetUint16(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(63488).GetRawData()); } @@ -203,7 +202,7 @@ TEST_F(BuiltinsDataViewTest, getInt16) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetInt16(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetInt16(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -212,7 +211,7 @@ TEST_F(BuiltinsDataViewTest, getInt16) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::True()); - JSTaggedValue result1 = BuiltinsDataView::GetInt16(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetInt16(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(-2048).GetRawData()); } @@ -233,7 +232,7 @@ TEST_F(BuiltinsDataViewTest, GetUint32) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetUint32(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetUint32(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(2147483647).GetRawData()); } @@ -254,7 +253,7 @@ TEST_F(BuiltinsDataViewTest, GetInt32) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetInt32(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetInt32(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(2147483647).GetRawData()); } @@ -271,7 +270,7 @@ TEST_F(BuiltinsDataViewTest, GetInt8) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetInt8(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetInt8(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -288,7 +287,7 @@ TEST_F(BuiltinsDataViewTest, GetUint8) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetUint8(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetUint8(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(127).GetRawData()); } @@ -309,7 +308,7 @@ TEST_F(BuiltinsDataViewTest, GetFloat32) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetFloat32(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetFloat32(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(13323083)).GetRawData()); } @@ -334,7 +333,7 @@ TEST_F(BuiltinsDataViewTest, GetFloat64) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::GetFloat64(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::GetFloat64(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(10846169068898440)).GetRawData()); } @@ -351,7 +350,7 @@ TEST_F(BuiltinsDataViewTest, SetUint32) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetUint32(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetUint32(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -360,7 +359,7 @@ TEST_F(BuiltinsDataViewTest, SetUint32) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetUint32(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetUint32(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(0xf8007f90)).GetRawData()); } @@ -377,7 +376,7 @@ TEST_F(BuiltinsDataViewTest, SetInt32) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetInt32(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetInt32(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -386,7 +385,7 @@ TEST_F(BuiltinsDataViewTest, SetInt32) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetInt32(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetInt32(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(-134185072).GetRawData()); } @@ -401,14 +400,14 @@ TEST_F(BuiltinsDataViewTest, SetInt8) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetInt8(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetInt8(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecma_runtime_call_info1->SetFunction(JSTaggedValue::Undefined()); ecma_runtime_call_info1->SetThis(view.GetTaggedValue()); ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); - JSTaggedValue result1 = BuiltinsDataView::GetUint8(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetUint8(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(255).GetRawData()); } @@ -425,7 +424,7 @@ TEST_F(BuiltinsDataViewTest, SetFloat32) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetFloat32(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetFloat32(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -434,7 +433,7 @@ TEST_F(BuiltinsDataViewTest, SetFloat32) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetFloat32(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetFloat32(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1.4441781973331565e-41)).GetRawData()); } @@ -451,7 +450,7 @@ TEST_F(BuiltinsDataViewTest, SetFloat64) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDataView::SetFloat64(ecma_runtime_call_info.get()); + JSTaggedValue result = data_view::proto::SetFloat64(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); auto ecma_runtime_call_info1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); @@ -460,7 +459,7 @@ TEST_F(BuiltinsDataViewTest, SetFloat64) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(0)); ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetFloat64(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = data_view::proto::GetFloat64(ecma_runtime_call_info1.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(8.759e-320)).GetRawData()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_date_test.cpp b/tests/runtime/builtins/builtins_date_test.cpp index 36642888286949f8cc1765ee2a46af2c4726915c..b0b9e0313f85831061ed9ebcd7408a8d115df1a6 100644 --- a/tests/runtime/builtins/builtins_date_test.cpp +++ b/tests/runtime/builtins/builtins_date_test.cpp @@ -14,9 +14,10 @@ */ #include "plugins/ecmascript/runtime/base/string_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_date.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" +#include "plugins/ecmascript/runtime/js_date.h" #include "plugins/ecmascript/runtime/js_function.h" #include "plugins/ecmascript/runtime/js_thread.h" #include "plugins/ecmascript/tests/runtime/common/test_helper.h" @@ -88,8 +89,8 @@ TEST_F(BuiltinsDateTest, SetGetDate) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - [[maybe_unused]] JSTaggedValue result1 = BuiltinsDate::SetDate(ecma_runtime_call_info.get()); - JSTaggedValue result2 = BuiltinsDate::GetDate(ecma_runtime_call_info.get()); + [[maybe_unused]] JSTaggedValue result1 = date::proto::SetDate(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetDate(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -101,8 +102,8 @@ TEST_F(BuiltinsDateTest, SetGetUTCDate) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - [[maybe_unused]] JSTaggedValue result3 = BuiltinsDate::SetUTCDate(ecma_runtime_call_info.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecma_runtime_call_info.get()); + [[maybe_unused]] JSTaggedValue result3 = date::proto::SetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -114,8 +115,8 @@ TEST_F(BuiltinsDateTest, SetGetMinusUTCDate) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - [[maybe_unused]] JSTaggedValue result3 = BuiltinsDate::SetUTCDate(ecma_runtime_call_info.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecma_runtime_call_info.get()); + [[maybe_unused]] JSTaggedValue result3 = date::proto::SetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(29)).GetRawData()); } @@ -132,16 +133,16 @@ TEST_F(BuiltinsDateTest, SetGetFullYear) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetFullYear(ecma_runtime_call_info.get()); + date::proto::SetFullYear(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetFullYear(ecma_runtime_call_info.get()); // 2018 : test case ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMonth(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMonth(ecma_runtime_call_info.get()); // 10 : test case ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetDate(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetDate(ecma_runtime_call_info.get()); // 6 : test case ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); } @@ -159,16 +160,16 @@ TEST_F(BuiltinsDateTest, SetGetUTCFullYear) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCFullYear(ecma_runtime_call_info.get()); + date::proto::SetUTCFullYear(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCFullYear(ecma_runtime_call_info.get()); // 2018 : test case ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result5 = BuiltinsDate::GetUTCMonth(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCMonth(ecma_runtime_call_info.get()); // 10 : test case ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); // 6 : test case ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); } @@ -182,14 +183,14 @@ TEST_F(BuiltinsDateTest, SetGetMinusFullYear) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(-6))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetFullYear(ecma_runtime_call_info.get()); + date::proto::SetFullYear(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetFullYear(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-2019)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMonth(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMonth(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(1)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetDate(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetDate(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(22)).GetRawData()); } @@ -203,14 +204,14 @@ TEST_F(BuiltinsDateTest, SetGetMinusUTCFullYear) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(-6))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCFullYear(ecma_runtime_call_info.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCFullYear(ecma_runtime_call_info.get()); + date::proto::SetUTCFullYear(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCFullYear(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(-2019)).GetRawData()); - JSTaggedValue result5 = BuiltinsDate::GetUTCMonth(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCMonth(ecma_runtime_call_info.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(1)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(22)).GetRawData()); } @@ -225,17 +226,17 @@ TEST_F(BuiltinsDateTest, SetGetHours) ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(111))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetHours(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetHours(ecma_runtime_call_info.get()); + date::proto::SetHours(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetHours(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(18)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMinutes(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -250,17 +251,17 @@ TEST_F(BuiltinsDateTest, SetGetUTCHours) ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(111))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCHours(ecma_runtime_call_info.get()); - JSTaggedValue result5 = BuiltinsDate::GetUTCHours(ecma_runtime_call_info.get()); + date::proto::SetUTCHours(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCHours(ecma_runtime_call_info.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(18)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCMinutes(ecma_runtime_call_info.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result7 = BuiltinsDate::GetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result7 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result8 = BuiltinsDate::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result8 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result8.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -275,17 +276,17 @@ TEST_F(BuiltinsDateTest, SetGetMinusHours) ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(-111))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetHours(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetHours(ecma_runtime_call_info.get()); + date::proto::SetHours(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetHours(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMinutes(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(49)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(53)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(889)).GetRawData()); } @@ -300,17 +301,17 @@ TEST_F(BuiltinsDateTest, SetGetMinusUTCHours) ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(-111))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCHours(ecma_runtime_call_info.get()); - JSTaggedValue result5 = BuiltinsDate::GetUTCHours(ecma_runtime_call_info.get()); + date::proto::SetUTCHours(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCHours(ecma_runtime_call_info.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCMinutes(ecma_runtime_call_info.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(49)).GetRawData()); - JSTaggedValue result7 = BuiltinsDate::GetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result7 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(53)).GetRawData()); - JSTaggedValue result8 = BuiltinsDate::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result8 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result8.GetRawData(), JSTaggedValue(static_cast(889)).GetRawData()); } @@ -322,10 +323,10 @@ TEST_F(BuiltinsDateTest, SetGetMilliseconds) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(100))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::SetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::SetMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); } @@ -337,10 +338,10 @@ TEST_F(BuiltinsDateTest, SetGetUTCMilliseconds) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(100))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result3 = BuiltinsDate::SetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::SetUTCMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); } @@ -354,14 +355,14 @@ TEST_F(BuiltinsDateTest, SetGetMinutes) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(111))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetMinutes(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetMinutes(ecma_runtime_call_info.get()); + date::proto::SetMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetMinutes(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -375,14 +376,14 @@ TEST_F(BuiltinsDateTest, SetGetUTCMinutes) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(111))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCMinutes(ecma_runtime_call_info.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCMinutes(ecma_runtime_call_info.get()); + date::proto::SetUTCMinutes(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCMinutes(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result5 = BuiltinsDate::GetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result5 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result6 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -395,11 +396,11 @@ TEST_F(BuiltinsDateTest, SetGetMonth) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetMonth(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetMonth(ecma_runtime_call_info.get()); + date::proto::SetMonth(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetMonth(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(8)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetDate(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetDate(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(3)).GetRawData()); } @@ -412,11 +413,11 @@ TEST_F(BuiltinsDateTest, SetGetUTCMonth) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCMonth(ecma_runtime_call_info.get()); - JSTaggedValue result3 = BuiltinsDate::GetUTCMonth(ecma_runtime_call_info.get()); + date::proto::SetUTCMonth(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetUTCMonth(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(8)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCDate(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(3)).GetRawData()); } @@ -429,11 +430,11 @@ TEST_F(BuiltinsDateTest, SetGetSeconds) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetSeconds(ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::GetSeconds(ecma_runtime_call_info.get()); + date::proto::SetSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::GetSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(59)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(123)).GetRawData()); } @@ -446,11 +447,11 @@ TEST_F(BuiltinsDateTest, SetGetUTCSeconds) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(123))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetUTCSeconds(ecma_runtime_call_info.get()); - JSTaggedValue result3 = BuiltinsDate::GetUTCSeconds(ecma_runtime_call_info.get()); + date::proto::SetUTCSeconds(ecma_runtime_call_info.get()); + JSTaggedValue result3 = date::proto::GetUTCSeconds(ecma_runtime_call_info.get()); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(59)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetUTCMilliseconds(ecma_runtime_call_info.get()); + JSTaggedValue result4 = date::proto::GetUTCMilliseconds(ecma_runtime_call_info.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(123)).GetRawData()); } @@ -462,10 +463,10 @@ TEST_F(BuiltinsDateTest, SetGetTime) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::SetTime(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::SetTime(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetTime(ecma_runtime_call_info.get()); + JSTaggedValue result2 = date::proto::GetTime(ecma_runtime_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -478,7 +479,7 @@ TEST_F(BuiltinsDateTest, UTC) ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(11.32)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::UTC(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::UTC(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604487600000)).GetRawData()); @@ -492,7 +493,7 @@ TEST_F(BuiltinsDateTest, UTC) ecma_runtime_call_info1->SetCallArg(6, JSTaggedValue(static_cast(231))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - result1 = BuiltinsDate::UTC(ecma_runtime_call_info1.get()); + result1 = date::UTC(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604490334231)).GetRawData()); @@ -502,7 +503,7 @@ TEST_F(BuiltinsDateTest, UTC) ecma_runtime_call_info2->SetCallArg(2, JSTaggedValue(11.32)); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result1 = BuiltinsDate::UTC(ecma_runtime_call_info2.get()); + result1 = date::UTC(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-1882224000000)).GetRawData()); @@ -510,7 +511,7 @@ TEST_F(BuiltinsDateTest, UTC) ecma_runtime_call_info3->SetCallArg(0, JSTaggedValue(1994.982)); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - result1 = BuiltinsDate::UTC(ecma_runtime_call_info3.get()); + result1 = date::UTC(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(757382400000)).GetRawData()); @@ -518,7 +519,7 @@ TEST_F(BuiltinsDateTest, UTC) ecma_runtime_call_info4->SetCallArg(0, JSTaggedValue(19999944.982)); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - result1 = BuiltinsDate::UTC(ecma_runtime_call_info4.get()); + result1 = date::UTC(ecma_runtime_call_info4.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(base::NAN_VALUE)).GetRawData()); } @@ -534,7 +535,7 @@ void SetAllYearAndHours(JSThread *thread, const JSHandle &js_date) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(6))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetFullYear(ecma_runtime_call_info.get()); + date::proto::SetFullYear(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread, 12, js_date.GetTaggedValue()); @@ -548,7 +549,7 @@ void SetAllYearAndHours(JSThread *thread, const JSHandle &js_date) ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(static_cast(111))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - BuiltinsDate::SetHours(ecma_runtime_call_info1.get()); + date::proto::SetHours(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); } @@ -563,7 +564,7 @@ void SetAll1(JSThread *thread, const JSHandle &js_date) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(31))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetFullYear(ecma_runtime_call_info.get()); + date::proto::SetFullYear(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread, 12, js_date.GetTaggedValue()); @@ -577,7 +578,7 @@ void SetAll1(JSThread *thread, const JSHandle &js_date) ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(static_cast(888))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - BuiltinsDate::SetHours(ecma_runtime_call_info1.get()); + date::proto::SetHours(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); } @@ -589,7 +590,7 @@ void SetAll2(JSThread *thread, const JSHandle &js_date) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(1))); // 2 : test case [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - BuiltinsDate::SetFullYear(ecma_runtime_call_info.get()); + date::proto::SetFullYear(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); // 12 : test case @@ -600,7 +601,7 @@ void SetAll2(JSThread *thread, const JSHandle &js_date) ecma_runtime_call_info1->SetCallArg(3, JSTaggedValue(static_cast(129))); // 3, 129 : test case prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - BuiltinsDate::SetHours(ecma_runtime_call_info1.get()); + date::proto::SetHours(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); } @@ -612,7 +613,7 @@ TEST_F(BuiltinsDateTest, parse) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::Parse(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::Parse(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298132)).GetRawData()); JSHandle str1 = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("2020-11-19Z"); @@ -620,7 +621,7 @@ TEST_F(BuiltinsDateTest, parse) ecma_runtime_call_info1->SetCallArg(0, str1.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - result1 = BuiltinsDate::Parse(ecma_runtime_call_info1.get()); + result1 = date::Parse(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605744000000)).GetRawData()); @@ -630,7 +631,7 @@ TEST_F(BuiltinsDateTest, parse) ecma_runtime_call_info2->SetCallArg(0, str2.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - result1 = BuiltinsDate::Parse(ecma_runtime_call_info2.get()); + result1 = date::Parse(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604204297231)).GetRawData()); @@ -640,7 +641,7 @@ TEST_F(BuiltinsDateTest, parse) ecma_runtime_call_info3->SetCallArg(0, str3.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - result1 = BuiltinsDate::Parse(ecma_runtime_call_info3.get()); + result1 = date::Parse(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298000)).GetRawData()); @@ -650,7 +651,7 @@ TEST_F(BuiltinsDateTest, parse) ecma_runtime_call_info4->SetCallArg(0, str4.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - result1 = BuiltinsDate::Parse(ecma_runtime_call_info4.get()); + result1 = date::Parse(ecma_runtime_call_info4.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(3894841080000)).GetRawData()); @@ -658,7 +659,7 @@ TEST_F(BuiltinsDateTest, parse) ecma_runtime_call_info5->SetCallArg(0, JSTaggedValue::Null()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info5.get()); - result1 = BuiltinsDate::Parse(ecma_runtime_call_info5.get()); + result1 = date::Parse(ecma_runtime_call_info5.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(base::NAN_VALUE)).GetRawData()); } @@ -673,7 +674,7 @@ TEST_F(BuiltinsDateTest, ToDateString) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsDate::ToDateString(ecma_runtime_call_info.get()); + JSTaggedValue result = date::proto::ToDateString(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -689,7 +690,7 @@ TEST_F(BuiltinsDateTest, ToISOString) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ToISOString(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToISOString(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); @@ -705,7 +706,7 @@ TEST_F(BuiltinsDateTest, ToISOStringMinus) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ToISOString(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToISOString(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); @@ -721,7 +722,7 @@ TEST_F(BuiltinsDateTest, ToJSON) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ToJSON(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToJSON(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); @@ -736,7 +737,7 @@ TEST_F(BuiltinsDateTest, ToJSONMinus) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ToJSON(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToJSON(ecma_runtime_call_info.get()); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -772,7 +773,7 @@ TEST_F(BuiltinsDateTest, ToString) SetAllYearAndHours(thread, js_date); local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result1 = BuiltinsDate::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToString(ecma_runtime_call_info.get()); ASSERT_TRUE(result1.IsString()); TestHelper::TearDownFrame(thread, prev); JSHandle result1_val(thread, reinterpret_cast(result1.GetRawData())); @@ -786,7 +787,7 @@ TEST_F(BuiltinsDateTest, ToString) SetAll1(thread, js_date1); local_time = GetLocalTime(js_date1, local_min); - JSTaggedValue result2 = BuiltinsDate::ToString(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = date::proto::ToString(ecma_runtime_call_info1.get()); ASSERT_TRUE(result2.IsString()); TestHelper::TearDownFrame(thread, prev); JSHandle result2_val(thread, reinterpret_cast(result2.GetRawData())); @@ -800,7 +801,7 @@ TEST_F(BuiltinsDateTest, ToString) SetAll2(thread, js_date2); local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result3 = BuiltinsDate::ToString(ecma_runtime_call_info2.get()); + JSTaggedValue result3 = date::proto::ToString(ecma_runtime_call_info2.get()); ASSERT_TRUE(result3.IsString()); TestHelper::TearDownFrame(thread, prev); JSHandle result3_val(thread, reinterpret_cast(result3.GetRawData())); @@ -821,7 +822,7 @@ TEST_F(BuiltinsDateTest, ToTimeString) SetAllYearAndHours(thread, js_date); local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result1 = BuiltinsDate::ToTimeString(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToTimeString(ecma_runtime_call_info.get()); ASSERT_TRUE(result1.IsString()); JSHandle result1_val(thread, reinterpret_cast(result1.GetRawData())); PandaString str = "18:10:06 GMT" + local_time; @@ -833,7 +834,7 @@ TEST_F(BuiltinsDateTest, ToTimeString) prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); SetAll1(thread, js_date1); local_time = GetLocalTime(js_date1, local_min); - JSTaggedValue result2 = BuiltinsDate::ToTimeString(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = date::proto::ToTimeString(ecma_runtime_call_info1.get()); ASSERT_TRUE(result2.IsString()); JSHandle result2_val(thread, reinterpret_cast(result2.GetRawData())); str = "23:54:16 GMT" + local_time; @@ -844,7 +845,7 @@ TEST_F(BuiltinsDateTest, ToTimeString) prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); SetAll2(thread, js_date2); local_time = GetLocalTime(js_date, local_min); - JSTaggedValue result3 = BuiltinsDate::ToTimeString(ecma_runtime_call_info2.get()); + JSTaggedValue result3 = date::proto::ToTimeString(ecma_runtime_call_info2.get()); ASSERT_TRUE(result3.IsString()); JSHandle result3_val(thread, reinterpret_cast(result3.GetRawData())); str = "00:03:21 GMT" + local_time; @@ -861,7 +862,7 @@ TEST_F(BuiltinsDateTest, ToUTCString) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToUTCString(ecma_runtime_call_info.get()); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -875,7 +876,7 @@ TEST_F(BuiltinsDateTest, ToUTCStringMinus) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ToUTCString(ecma_runtime_call_info.get()); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -887,7 +888,7 @@ TEST_F(BuiltinsDateTest, ValueOf) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ValueOf(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298132)).GetRawData()); } @@ -898,7 +899,7 @@ TEST_F(BuiltinsDateTest, ValueOfMinus) auto ecma_runtime_call_info = CreateAndSetRuntimeCallInfo(thread, 4, js_date.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsDate::ValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result1 = date::proto::ValueOf(ecma_runtime_call_info.get()); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-4357419161618)).GetRawData()); } @@ -911,7 +912,7 @@ TEST_F(BuiltinsDateTest, DateConstructor) auto ecma_runtime_call_info1 = CreateAndSetRuntimeCallInfo(thread, 4, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsDate::DateConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = date::DateConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); @@ -921,7 +922,7 @@ TEST_F(BuiltinsDateTest, DateConstructor) ecma_runtime_call_info2->SetThis(js_date.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsDate::DateConstructor(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = date::DateConstructor(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result2.IsObject()); @@ -932,12 +933,12 @@ TEST_F(BuiltinsDateTest, DateConstructor) ecma_runtime_call_info3->SetCallArg(0, JSTaggedValue(static_cast(2018))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - JSTaggedValue result3 = BuiltinsDate::DateConstructor(ecma_runtime_call_info3.get()); + JSTaggedValue result3 = date::DateConstructor(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result3.IsObject()); - BuiltinsDate::SetFullYear(ecma_runtime_call_info3.get()); - JSTaggedValue result4 = BuiltinsDate::GetFullYear(ecma_runtime_call_info3.get()); + date::proto::SetFullYear(ecma_runtime_call_info3.get()); + JSTaggedValue result4 = date::proto::GetFullYear(ecma_runtime_call_info3.get()); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); // case3: length > 1 @@ -948,14 +949,14 @@ TEST_F(BuiltinsDateTest, DateConstructor) ecma_runtime_call_info4->SetCallArg(1, JSTaggedValue(static_cast(10))); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - JSTaggedValue result5 = BuiltinsDate::DateConstructor(ecma_runtime_call_info4.get()); + JSTaggedValue result5 = date::DateConstructor(ecma_runtime_call_info4.get()); ASSERT_TRUE(result5.IsObject()); SetAllYearAndHours(thread, js_date); - BuiltinsDate::SetFullYear(ecma_runtime_call_info4.get()); - JSTaggedValue result6 = BuiltinsDate::GetFullYear(ecma_runtime_call_info4.get()); + date::proto::SetFullYear(ecma_runtime_call_info4.get()); + JSTaggedValue result6 = date::proto::GetFullYear(ecma_runtime_call_info4.get()); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result7 = BuiltinsDate::GetMonth(ecma_runtime_call_info4.get()); + JSTaggedValue result7 = date::proto::GetMonth(ecma_runtime_call_info4.get()); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_errors_test.cpp b/tests/runtime/builtins/builtins_errors_test.cpp index 088a95749f54ce36206d9002f1dabe8c398df874..4a7ec1aa8e9b77f7692b336ec5c5ed91d1344db3 100644 --- a/tests/runtime/builtins/builtins_errors_test.cpp +++ b/tests/runtime/builtins/builtins_errors_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/base/error_helper.h" #include "plugins/ecmascript/runtime/ecma_string.h" @@ -34,13 +34,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using Error = ecmascript::builtins::BuiltinsError; -using RangeError = builtins::BuiltinsRangeError; -using ReferenceError = builtins::BuiltinsReferenceError; -using TypeError = builtins::BuiltinsTypeError; -using URIError = builtins::BuiltinsURIError; -using EvalError = builtins::BuiltinsEvalError; -using SyntaxError = builtins::BuiltinsSyntaxError; using JSType = ecmascript::JSType; class BuiltinsErrorsTest : public testing::Test { @@ -146,7 +139,7 @@ TEST_F(BuiltinsErrorsTest, ErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Error::ErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = error::ErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); @@ -186,7 +179,7 @@ TEST_F(BuiltinsErrorsTest, ErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Error::ErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = error::ErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); @@ -225,7 +218,7 @@ TEST_F(BuiltinsErrorsTest, ErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Error::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -258,7 +251,7 @@ TEST_F(BuiltinsErrorsTest, ErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Error::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -285,7 +278,7 @@ TEST_F(BuiltinsErrorsTest, RangeErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = RangeError::RangeErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = range_error::RangeErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); @@ -324,7 +317,7 @@ TEST_F(BuiltinsErrorsTest, RangeErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = RangeError::RangeErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = range_error::RangeErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); @@ -363,7 +356,7 @@ TEST_F(BuiltinsErrorsTest, RangeErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = RangeError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = range_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, result); EXPECT_TRUE(result.IsString()); @@ -396,7 +389,7 @@ TEST_F(BuiltinsErrorsTest, RangeErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = RangeError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = range_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -421,7 +414,7 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = reference_error::ReferenceErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -460,7 +453,7 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = reference_error::ReferenceErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -497,7 +490,7 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = ReferenceError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = reference_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( @@ -528,7 +521,7 @@ TEST_F(BuiltinsErrorsTest, ReferenceErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = ReferenceError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = reference_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(factory->NewFromCanBeCompressString("ReferenceError: This is ReferenceError!")->Compare(*result_handle), @@ -552,7 +545,7 @@ TEST_F(BuiltinsErrorsTest, TypeErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = TypeError::TypeErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = type_error::TypeErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -590,7 +583,7 @@ TEST_F(BuiltinsErrorsTest, TypeErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = TypeError::TypeErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = type_error::TypeErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -628,7 +621,7 @@ TEST_F(BuiltinsErrorsTest, TypeErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = TypeError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = type_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( @@ -659,7 +652,7 @@ TEST_F(BuiltinsErrorsTest, TypeErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = TypeError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = type_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(factory->NewFromCanBeCompressString("TypeError: This is TypeError!")->Compare(*result_handle), 0); @@ -682,7 +675,7 @@ TEST_F(BuiltinsErrorsTest, URIErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = URIError::URIErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = uri_error::URIErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -721,7 +714,7 @@ TEST_F(BuiltinsErrorsTest, URIErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = URIError::URIErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = uri_error::URIErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -759,7 +752,7 @@ TEST_F(BuiltinsErrorsTest, URIErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = URIError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = uri_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -792,7 +785,7 @@ TEST_F(BuiltinsErrorsTest, URIErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = URIError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = uri_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -820,7 +813,7 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = syntax_error::SyntaxErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -859,7 +852,7 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = syntax_error::SyntaxErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -897,7 +890,7 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = SyntaxError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = syntax_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -929,7 +922,7 @@ TEST_F(BuiltinsErrorsTest, SyntaxErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = SyntaxError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = syntax_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -953,7 +946,7 @@ TEST_F(BuiltinsErrorsTest, EvalErrorNoParameterConstructor) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = EvalError::EvalErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = eval_error::EvalErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -992,7 +985,7 @@ TEST_F(BuiltinsErrorsTest, EvalErrorParameterConstructor) ecma_runtime_call_info->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = EvalError::EvalErrorConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = eval_error::EvalErrorConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSHandle error_object(thread, reinterpret_cast(result.GetRawData())); @@ -1029,7 +1022,7 @@ TEST_F(BuiltinsErrorsTest, EvalErrorNoParameterToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = EvalError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = eval_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( @@ -1061,7 +1054,7 @@ TEST_F(BuiltinsErrorsTest, EvalErrorToString) ecma_runtime_call_info->SetThis(JSTaggedValue(*error)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = EvalError::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = eval_error::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(factory->NewFromCanBeCompressString("EvalError: This is EvalError!")->Compare(*result_handle), 0); diff --git a/tests/runtime/builtins/builtins_function_test.cpp b/tests/runtime/builtins/builtins_function_test.cpp index 7dc4d1d38d6582c0e5aed3ea720ee9b9018b02c7..e3083888bf66777b6ae84ec9c548b8be9f39f77f 100644 --- a/tests/runtime/builtins/builtins_function_test.cpp +++ b/tests/runtime/builtins/builtins_function_test.cpp @@ -13,8 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_function.h" -#include "plugins/ecmascript/runtime/builtins/builtins_boolean.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" @@ -30,7 +29,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; -using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; using JSArray = panda::ecmascript::JSArray; namespace panda::test { @@ -70,9 +68,9 @@ JSTaggedValue TestFunctionApplyAndCall(EcmaRuntimeCallInfo *argv) int result = 0; for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { - result += BuiltinsBase::GetCallArg(argv, index)->GetInt(); + result += builtins_common::GetCallArg(argv, index)->GetInt(); } - JSHandle this_value(BuiltinsBase::GetThis(argv)); + JSHandle this_value(builtins_common::GetThis(argv)); JSTaggedValue test_a = JSObject::GetProperty(thread, this_value, @@ -86,7 +84,7 @@ JSTaggedValue TestFunctionApplyAndCall(EcmaRuntimeCallInfo *argv) .GetTaggedValue(); result = result + test_a.GetInt() + test_b.GetInt(); - return BuiltinsBase::GetTaggedInt(result); + return builtins_common::GetTaggedInt(result); } // func.apply(thisArg) @@ -113,7 +111,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeApply) ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeApply(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Apply(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); @@ -157,7 +155,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeApply1) ecma_runtime_call_info->SetCallArg(1, array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeApply(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Apply(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(100).GetRawData()); @@ -188,7 +186,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind) ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Bind(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); @@ -237,7 +235,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind1) ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Bind(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); @@ -293,7 +291,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeBind2) ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Bind(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); @@ -350,7 +348,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeCall) ecma_runtime_call_info->SetCallArg(0, (this_arg.GetTaggedValue())); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeCall(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Call(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); @@ -389,7 +387,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeCall1) ecma_runtime_call_info->SetCallArg(3, JSTaggedValue(static_cast(789))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeCall(ecma_runtime_call_info.get()); + JSTaggedValue result = function::proto::Call(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1371).GetRawData()); @@ -411,7 +409,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeHasInstance) ecma_runtime_call_info1->SetCallArg(0, JSTaggedValue(static_cast(123))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result = boolean::BooleanConstructor(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle boolean_instance(thread, result); @@ -422,7 +420,7 @@ TEST_F(BuiltinsFunctionTest, FunctionPrototypeHasInstance) ecma_runtime_call_info2->SetCallArg(0, boolean_instance.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - EXPECT_TRUE(BuiltinsFunction::FunctionPrototypeHasInstance(ecma_runtime_call_info2.get()).GetRawData()); + EXPECT_TRUE(function::proto::HasInstance(ecma_runtime_call_info2.get()).GetRawData()); TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_global_test.cpp b/tests/runtime/builtins/builtins_global_test.cpp index b9cd9aa6da9765e081b30d26255a633006aa217d..95e1824f409abb5c7023e1bcea52ffaeb5665627 100644 --- a/tests/runtime/builtins/builtins_global_test.cpp +++ b/tests/runtime/builtins/builtins_global_test.cpp @@ -14,7 +14,6 @@ */ #include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_global.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -56,7 +55,7 @@ public: ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsGlobal::Escape(ecma_runtime_call_info.get()); + JSTaggedValue result = global::Escape(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_EQ(expected->Compare(reinterpret_cast(result.GetRawData())), 0); @@ -75,7 +74,7 @@ public: ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsGlobal::Unescape(ecma_runtime_call_info.get()); + JSTaggedValue result = global::Unescape(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_EQ(expected->Compare(reinterpret_cast(result.GetRawData())), 0); @@ -144,7 +143,7 @@ TEST_F(BuiltinsGlobalTest, Escape1000) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsGlobal::Escape(ecma_runtime_call_info.get()); + JSTaggedValue result = global::Escape(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); bool is_equal = (str->Compare(reinterpret_cast(result.GetRawData())) == 0); @@ -182,7 +181,7 @@ TEST_F(BuiltinsGlobalTest, Unescape1000) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result_escape = BuiltinsGlobal::Escape(ecma_runtime_call_info.get()); + JSTaggedValue result_escape = global::Escape(ecma_runtime_call_info.get()); auto ecma_runtime_call_info2 = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); ecma_runtime_call_info2->SetFunction(JSTaggedValue::Undefined()); @@ -190,7 +189,7 @@ TEST_F(BuiltinsGlobalTest, Unescape1000) ecma_runtime_call_info2->SetCallArg(0, result_escape); [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread_, ecma_runtime_call_info2.get()); - JSTaggedValue result = BuiltinsGlobal::Unescape(ecma_runtime_call_info2.get()); + JSTaggedValue result = global::Unescape(ecma_runtime_call_info2.get()); ASSERT_TRUE(result.IsString()); ASSERT_EQ(str->Compare(reinterpret_cast(result.GetRawData())), 0); diff --git a/tests/runtime/builtins/builtins_iterator_test.cpp b/tests/runtime/builtins/builtins_iterator_test.cpp index 3c9340be1d08736e7157c873887430a8adac8fd6..09e9a7ac1538221baa714ae9a20e110e2b4b3bb0 100644 --- a/tests/runtime/builtins/builtins_iterator_test.cpp +++ b/tests/runtime/builtins/builtins_iterator_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_iterator.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/global_env.h" diff --git a/tests/runtime/builtins/builtins_json_test.cpp b/tests/runtime/builtins/builtins_json_test.cpp index 0b8524b6b2b3872df430331ed98013f5cb788e28..1f90f7ea2cb8bc08bd8981da2c79338e215d4555 100644 --- a/tests/runtime/builtins/builtins_json_test.cpp +++ b/tests/runtime/builtins/builtins_json_test.cpp @@ -18,8 +18,6 @@ #include "algorithm" #include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_errors.h" -#include "plugins/ecmascript/runtime/builtins/builtins_json.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string-inl.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -66,18 +64,18 @@ public: EcmaHandleScope *scope {nullptr}; JSThread *thread {nullptr}; - class TestClass : public base::BuiltinsBase { + class TestClass { public: static JSTaggedValue TestForParse(EcmaRuntimeCallInfo *argv) { uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { } - JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue key = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); if (key.IsUndefined()) { return JSTaggedValue::Undefined(); } - JSTaggedValue value = GetCallArg(argv, 1).GetTaggedValue(); + JSTaggedValue value = builtins_common::GetCallArg(argv, 1).GetTaggedValue(); if (value.IsUndefined()) { return JSTaggedValue::Undefined(); } @@ -97,11 +95,11 @@ public: { uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { - JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue key = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); if (key.IsUndefined()) { return JSTaggedValue::Undefined(); } - JSTaggedValue value = GetCallArg(argv, 1).GetTaggedValue(); + JSTaggedValue value = builtins_common::GetCallArg(argv, 1).GetTaggedValue(); if (value.IsUndefined()) { return JSTaggedValue::Undefined(); } @@ -156,7 +154,7 @@ TEST_F(BuiltinsJsonTest, Parse10) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -177,7 +175,7 @@ TEST_F(BuiltinsJsonTest, Parse21) ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -195,7 +193,7 @@ TEST_F(BuiltinsJsonTest, Parse) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle value_handle(thread, value); @@ -217,7 +215,7 @@ TEST_F(BuiltinsJsonTest, Parse2) ecma_runtime_call_info->SetCallArg(0, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Parse(ecma_runtime_call_info.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle value_handle(thread, value); @@ -247,7 +245,7 @@ TEST_F(BuiltinsJsonTest, Stringify11) ecma_runtime_call_info->SetCallArg(1, handle_func.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } @@ -267,7 +265,7 @@ TEST_F(BuiltinsJsonTest, Stringify12) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } @@ -289,7 +287,7 @@ TEST_F(BuiltinsJsonTest, Stringify13) ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } @@ -318,7 +316,7 @@ TEST_F(BuiltinsJsonTest, Stringify14) ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } @@ -331,7 +329,7 @@ TEST_F(BuiltinsJsonTest, Stringify) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } @@ -371,7 +369,7 @@ TEST_F(BuiltinsJsonTest, Stringify1) ecma_runtime_call_info->SetCallArg(2, str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } @@ -402,7 +400,7 @@ TEST_F(BuiltinsJsonTest, Stringify2) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecma_runtime_call_info.get()); + JSTaggedValue result = json::Stringify(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_map_test.cpp b/tests/runtime/builtins/builtins_map_test.cpp index ba4dd15ff34ba76b9f429432fb38f9bead17020c..1cbd1235859c292c5605ebfa6f7e6088224c784a 100644 --- a/tests/runtime/builtins/builtins_map_test.cpp +++ b/tests/runtime/builtins/builtins_map_test.cpp @@ -14,7 +14,6 @@ */ #include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_map.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -36,7 +35,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using BuiltinsMap = ecmascript::builtins::BuiltinsMap; using JSMap = ecmascript::JSMap; class BuiltinsMapTest : public testing::Test { @@ -65,12 +63,12 @@ public: EcmaHandleScope *scope {nullptr}; JSThread *thread {nullptr}; - class TestClass : public base::BuiltinsBase { + class TestClass { public: static JSTaggedValue TestFunc(EcmaRuntimeCallInfo *argv) { - int num = GetCallArg(argv, 0)->GetInt(); - JSArray *js_array = JSArray::Cast(GetThis(argv)->GetTaggedObject()); + int num = builtins_common::GetCallArg(argv, 0)->GetInt(); + JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); int length = js_array->GetArrayLength() + num; js_array->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); @@ -81,14 +79,14 @@ public: JSMap *CreateBuiltinsMap(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsMapFunction()); + JSHandle new_target(env->GetMapFunction()); // 4 : test case auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*new_target), 4); ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMap::MapConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = map::MapConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSMap *js_map = JSMap::Cast(reinterpret_cast(result.GetRawData())); @@ -99,7 +97,7 @@ TEST_F(BuiltinsMapTest, CreateAndGetSize) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsMapFunction()); + JSHandle new_target(env->GetMapFunction()); JSHandle map(thread, CreateBuiltinsMap(thread)); auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -109,7 +107,7 @@ TEST_F(BuiltinsMapTest, CreateAndGetSize) { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMap::GetSize(ecma_runtime_call_info.get()); + JSTaggedValue result = map::proto::GetSize(ecma_runtime_call_info.get()); EXPECT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -129,7 +127,7 @@ TEST_F(BuiltinsMapTest, CreateAndGetSize) ecma_runtime_call_info1->SetNewTarget(new_target.GetTaggedValue()); { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsMap::MapConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = map::MapConstructor(ecma_runtime_call_info1.get()); EXPECT_EQ(JSMap::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); } @@ -151,12 +149,12 @@ TEST_F(BuiltinsMapTest, SetAndHas) JSMap *js_map; { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsMap::Has(ecma_runtime_call_info.get()); + JSTaggedValue result1 = map::proto::Has(ecma_runtime_call_info.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Set() - JSTaggedValue result2 = BuiltinsMap::Set(ecma_runtime_call_info.get()); + JSTaggedValue result2 = map::proto::Set(ecma_runtime_call_info.get()); EXPECT_TRUE(result2.IsECMAObject()); js_map = JSMap::Cast(reinterpret_cast(result2.GetRawData())); @@ -171,7 +169,7 @@ TEST_F(BuiltinsMapTest, SetAndHas) ecma_runtime_call_info1->SetCallArg(1, JSTaggedValue(static_cast(1))); { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = BuiltinsMap::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = map::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -194,7 +192,7 @@ TEST_F(BuiltinsMapTest, ForEach) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(i))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsMap::Set(ecma_runtime_call_info.get()); + JSTaggedValue result1 = map::proto::Set(ecma_runtime_call_info.get()); EXPECT_TRUE(result1.IsECMAObject()); JSMap *js_map = JSMap::Cast(reinterpret_cast(result1.GetRawData())); EXPECT_EQ(js_map->GetSize(), i + 1); @@ -210,7 +208,7 @@ TEST_F(BuiltinsMapTest, ForEach) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsMap::ForEach(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = map::proto::ForEach(ecma_runtime_call_info1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(js_array->GetArrayLength(), 10); @@ -234,7 +232,7 @@ TEST_F(BuiltinsMapTest, DeleteAndRemove) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(i))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsMap::Set(ecma_runtime_call_info.get()); + JSTaggedValue result1 = map::proto::Set(ecma_runtime_call_info.get()); EXPECT_TRUE(result1.IsECMAObject()); JSMap *js_map = JSMap::Cast(reinterpret_cast(result1.GetRawData())); @@ -250,25 +248,25 @@ TEST_F(BuiltinsMapTest, DeleteAndRemove) ecma_runtime_call_info1->SetCallArg(0, delete_key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsMap::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = map::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsMap::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = map::proto::Delete(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsMap::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = map::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); - JSTaggedValue result5 = BuiltinsMap::GetSize(ecma_runtime_call_info1.get()); + JSTaggedValue result5 = map::proto::GetSize(ecma_runtime_call_info1.get()); EXPECT_EQ(result5.GetRawData(), JSTaggedValue(39).GetRawData()); // clear - JSTaggedValue result6 = BuiltinsMap::Clear(ecma_runtime_call_info1.get()); + JSTaggedValue result6 = map::proto::Clear(ecma_runtime_call_info1.get()); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(map->GetSize(), 0); } @@ -283,7 +281,7 @@ TEST_F(BuiltinsMapTest, Species) JSHandle species_symbol = env->GetSpeciesSymbol(); EXPECT_TRUE(!species_symbol.GetTaggedValue().IsUndefined()); - JSHandle new_target(env->GetBuiltinsMapFunction()); + JSHandle new_target(env->GetMapFunction()); JSTaggedValue value = JSObject::GetProperty(thread, JSHandle(new_target), species_symbol).GetValue().GetTaggedValue(); @@ -338,20 +336,20 @@ TEST_F(BuiltinsMapTest, GetIterator) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // test Values() - JSTaggedValue result = BuiltinsMap::Values(ecma_runtime_call_info.get()); + JSTaggedValue result = map::proto::Values(ecma_runtime_call_info.get()); JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSMapIterator()); EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind().GetInt())); EXPECT_EQ(JSMap::Cast(map.GetTaggedValue().GetTaggedObject())->GetLinkedMap(), iter->GetIteratedMap()); // test Keys() - JSTaggedValue result1 = BuiltinsMap::Keys(ecma_runtime_call_info.get()); + JSTaggedValue result1 = map::proto::Keys(ecma_runtime_call_info.get()); JSHandle iter1(thread, result1); EXPECT_TRUE(iter1->IsJSMapIterator()); EXPECT_EQ(IterationKind::KEY, IterationKind(iter1->GetIterationKind().GetInt())); // test entries() - JSTaggedValue result2 = BuiltinsMap::Entries(ecma_runtime_call_info.get()); + JSTaggedValue result2 = map::proto::Entries(ecma_runtime_call_info.get()); JSHandle iter2(thread, result2); EXPECT_TRUE(iter2->IsJSMapIterator()); EXPECT_EQ(IterationKind::KEY_AND_VALUE, IterationKind(iter2->GetIterationKind().GetInt())); diff --git a/tests/runtime/builtins/builtins_math_test.cpp b/tests/runtime/builtins/builtins_math_test.cpp index e3374974c8af850d169ae11833d54034d4c935f9..570e30f86ccf8552602e8e26745e5d0d696ae4fe 100644 --- a/tests/runtime/builtins/builtins_math_test.cpp +++ b/tests/runtime/builtins/builtins_math_test.cpp @@ -14,7 +14,7 @@ */ #include "plugins/ecmascript/runtime/base/number_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_math.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/js_tagged_value-inl.h" @@ -58,9 +58,9 @@ TEST_F(BuiltinsMathTest, Abs) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(10); + JSTaggedValue expect = builtins_common::GetTaggedInt(10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -73,9 +73,9 @@ TEST_F(BuiltinsMathTest, Abs_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(10); + JSTaggedValue expect = builtins_common::GetTaggedInt(10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -88,9 +88,9 @@ TEST_F(BuiltinsMathTest, Abs_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); + JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -103,9 +103,9 @@ TEST_F(BuiltinsMathTest, Abs_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); + JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -120,9 +120,9 @@ TEST_F(BuiltinsMathTest, Abs_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -136,9 +136,9 @@ TEST_F(BuiltinsMathTest, Abs_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::MAX_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::MAX_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -152,9 +152,9 @@ TEST_F(BuiltinsMathTest, Abs_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -168,9 +168,9 @@ TEST_F(BuiltinsMathTest, Abs_7) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -184,9 +184,9 @@ TEST_F(BuiltinsMathTest, Abs_8) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -200,9 +200,9 @@ TEST_F(BuiltinsMathTest, Abs_9) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(test_value)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -215,9 +215,9 @@ TEST_F(BuiltinsMathTest, Abs_10) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -230,9 +230,9 @@ TEST_F(BuiltinsMathTest, Abs_11) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(1); + JSTaggedValue expect = builtins_common::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -245,9 +245,9 @@ TEST_F(BuiltinsMathTest, Abs_12) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); + JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -260,9 +260,9 @@ TEST_F(BuiltinsMathTest, Abs_13) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Hole()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -276,9 +276,9 @@ TEST_F(BuiltinsMathTest, Abs_14) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Abs(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(100.12); + JSTaggedValue expect = builtins_common::GetTaggedDouble(100.12); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -291,9 +291,9 @@ TEST_F(BuiltinsMathTest, Acos) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI); + JSTaggedValue expect = math::GetPropPI(); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -306,9 +306,9 @@ TEST_F(BuiltinsMathTest, Acos_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -321,9 +321,9 @@ TEST_F(BuiltinsMathTest, Acos_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -336,9 +336,9 @@ TEST_F(BuiltinsMathTest, Acos_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -351,9 +351,9 @@ TEST_F(BuiltinsMathTest, Acos_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -366,9 +366,9 @@ TEST_F(BuiltinsMathTest, Acos_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -381,9 +381,9 @@ TEST_F(BuiltinsMathTest, Acos_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -397,9 +397,9 @@ TEST_F(BuiltinsMathTest, Acos_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.4706289056333368); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.4706289056333368); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -413,9 +413,9 @@ TEST_F(BuiltinsMathTest, Acos_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -428,9 +428,9 @@ TEST_F(BuiltinsMathTest, Acos_9) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -443,9 +443,9 @@ TEST_F(BuiltinsMathTest, Acosh) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.1)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.4435682543851154); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.4435682543851154); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -458,9 +458,9 @@ TEST_F(BuiltinsMathTest, Acosh_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -473,9 +473,9 @@ TEST_F(BuiltinsMathTest, Acosh_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -488,9 +488,9 @@ TEST_F(BuiltinsMathTest, Acosh_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -503,9 +503,9 @@ TEST_F(BuiltinsMathTest, Acosh_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -518,9 +518,9 @@ TEST_F(BuiltinsMathTest, Acosh_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -533,9 +533,9 @@ TEST_F(BuiltinsMathTest, Acosh_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -548,9 +548,9 @@ TEST_F(BuiltinsMathTest, Acosh_7) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Hole()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -564,9 +564,9 @@ TEST_F(BuiltinsMathTest, Acosh_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -580,9 +580,9 @@ TEST_F(BuiltinsMathTest, Acosh_9) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -595,9 +595,9 @@ TEST_F(BuiltinsMathTest, Acosh_10) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Acosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -610,9 +610,9 @@ TEST_F(BuiltinsMathTest, Asin) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -625,9 +625,9 @@ TEST_F(BuiltinsMathTest, Asin_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -640,9 +640,9 @@ TEST_F(BuiltinsMathTest, Asin_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -655,9 +655,9 @@ TEST_F(BuiltinsMathTest, Asin_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -670,9 +670,9 @@ TEST_F(BuiltinsMathTest, Asin_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -685,9 +685,9 @@ TEST_F(BuiltinsMathTest, Asin_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -700,9 +700,9 @@ TEST_F(BuiltinsMathTest, Asin_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -716,9 +716,9 @@ TEST_F(BuiltinsMathTest, Asin_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -732,9 +732,9 @@ TEST_F(BuiltinsMathTest, Asin_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -747,9 +747,9 @@ TEST_F(BuiltinsMathTest, Asinh) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.881373587019543); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -762,10 +762,10 @@ TEST_F(BuiltinsMathTest, Asinh_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.881373587019543); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -778,10 +778,10 @@ TEST_F(BuiltinsMathTest, Asinh_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -794,9 +794,9 @@ TEST_F(BuiltinsMathTest, Asinh_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -809,9 +809,9 @@ TEST_F(BuiltinsMathTest, Asinh_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -824,9 +824,9 @@ TEST_F(BuiltinsMathTest, Asinh_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.881373587019543); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -839,9 +839,9 @@ TEST_F(BuiltinsMathTest, Asinh_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -855,9 +855,9 @@ TEST_F(BuiltinsMathTest, Asinh_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -871,9 +871,9 @@ TEST_F(BuiltinsMathTest, Asinh_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Asinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-2.44122070725561); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-2.44122070725561); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -886,9 +886,9 @@ TEST_F(BuiltinsMathTest, Atan) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.7853981633974483); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -901,9 +901,9 @@ TEST_F(BuiltinsMathTest, Atan_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.7853981633974483); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -916,9 +916,9 @@ TEST_F(BuiltinsMathTest, Atan_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -931,9 +931,9 @@ TEST_F(BuiltinsMathTest, Atan_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -946,9 +946,9 @@ TEST_F(BuiltinsMathTest, Atan_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI / 2); + JSTaggedValue expect = builtins_common::GetTaggedDouble(math::GetPropPI().GetDouble() / 2); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -961,9 +961,9 @@ TEST_F(BuiltinsMathTest, Atan_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.7853981633974483); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -976,9 +976,9 @@ TEST_F(BuiltinsMathTest, Atan_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -992,9 +992,9 @@ TEST_F(BuiltinsMathTest, Atan_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1008,9 +1008,9 @@ TEST_F(BuiltinsMathTest, Atan_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.7853981633974483); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1023,9 +1023,9 @@ TEST_F(BuiltinsMathTest, Atanh) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1038,9 +1038,9 @@ TEST_F(BuiltinsMathTest, Atanh_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1053,9 +1053,9 @@ TEST_F(BuiltinsMathTest, Atanh_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1068,9 +1068,9 @@ TEST_F(BuiltinsMathTest, Atanh_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1083,9 +1083,9 @@ TEST_F(BuiltinsMathTest, Atanh_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1098,9 +1098,9 @@ TEST_F(BuiltinsMathTest, Atanh_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1113,9 +1113,9 @@ TEST_F(BuiltinsMathTest, Atanh_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1129,9 +1129,9 @@ TEST_F(BuiltinsMathTest, Atanh_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1145,9 +1145,9 @@ TEST_F(BuiltinsMathTest, Atanh_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1161,9 +1161,9 @@ TEST_F(BuiltinsMathTest, Atan2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1177,9 +1177,9 @@ TEST_F(BuiltinsMathTest, Atan2_1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.5880026035475675); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.5880026035475675); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1193,9 +1193,9 @@ TEST_F(BuiltinsMathTest, Atan2_2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI / 2); + JSTaggedValue expect = builtins_common::GetTaggedDouble(math::GetPropPI().GetDouble() / 2); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1209,9 +1209,9 @@ TEST_F(BuiltinsMathTest, Atan2_3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1225,9 +1225,9 @@ TEST_F(BuiltinsMathTest, Atan2_4) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI); + JSTaggedValue expect = math::GetPropPI(); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1241,9 +1241,9 @@ TEST_F(BuiltinsMathTest, Atan2_5) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1257,9 +1257,9 @@ TEST_F(BuiltinsMathTest, Atan2_6) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-BuiltinsMath::PI); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-math::GetPropPI().GetDouble()); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1273,9 +1273,9 @@ TEST_F(BuiltinsMathTest, Atan2_7) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1289,9 +1289,9 @@ TEST_F(BuiltinsMathTest, Atan2_8) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1307,9 +1307,9 @@ TEST_F(BuiltinsMathTest, Atan2_9) ecma_runtime_call_info->SetCallArg(1, test_2.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.5707963267948966); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1325,9 +1325,9 @@ TEST_F(BuiltinsMathTest, Atan2_10) ecma_runtime_call_info->SetCallArg(1, test_2.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.3091989123270746); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.3091989123270746); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1341,9 +1341,9 @@ TEST_F(BuiltinsMathTest, Atan2_11) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(-1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Atan2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1356,9 +1356,9 @@ TEST_F(BuiltinsMathTest, Cbrt) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1371,9 +1371,9 @@ TEST_F(BuiltinsMathTest, Cbrt_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1386,9 +1386,9 @@ TEST_F(BuiltinsMathTest, Cbrt_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1401,9 +1401,9 @@ TEST_F(BuiltinsMathTest, Cbrt_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1416,9 +1416,9 @@ TEST_F(BuiltinsMathTest, Cbrt_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1431,9 +1431,9 @@ TEST_F(BuiltinsMathTest, Cbrt_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1446,9 +1446,9 @@ TEST_F(BuiltinsMathTest, Cbrt_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1462,9 +1462,9 @@ TEST_F(BuiltinsMathTest, Cbrt_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1478,9 +1478,9 @@ TEST_F(BuiltinsMathTest, Cbrt_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0714412696907731); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0714412696907731); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1493,9 +1493,9 @@ TEST_F(BuiltinsMathTest, Cbrt_9) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cbrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1508,9 +1508,9 @@ TEST_F(BuiltinsMathTest, Ceil) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(3.25)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(4.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1523,9 +1523,9 @@ TEST_F(BuiltinsMathTest, Ceil_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1538,9 +1538,9 @@ TEST_F(BuiltinsMathTest, Ceil_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1553,9 +1553,9 @@ TEST_F(BuiltinsMathTest, Ceil_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1568,9 +1568,9 @@ TEST_F(BuiltinsMathTest, Ceil_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1583,9 +1583,9 @@ TEST_F(BuiltinsMathTest, Ceil_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1598,9 +1598,9 @@ TEST_F(BuiltinsMathTest, Ceil_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1614,9 +1614,9 @@ TEST_F(BuiltinsMathTest, Ceil_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1630,9 +1630,9 @@ TEST_F(BuiltinsMathTest, Ceil_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(4.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1645,9 +1645,9 @@ TEST_F(BuiltinsMathTest, Ceil_9) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Ceil(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1660,9 +1660,9 @@ TEST_F(BuiltinsMathTest, Cos) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1675,9 +1675,9 @@ TEST_F(BuiltinsMathTest, Cos_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1690,9 +1690,9 @@ TEST_F(BuiltinsMathTest, Cos_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1705,9 +1705,9 @@ TEST_F(BuiltinsMathTest, Cos_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1720,9 +1720,9 @@ TEST_F(BuiltinsMathTest, Cos_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.5403023058681398); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.5403023058681398); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1735,9 +1735,9 @@ TEST_F(BuiltinsMathTest, Cos_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1751,9 +1751,9 @@ TEST_F(BuiltinsMathTest, Cos_6) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1767,9 +1767,9 @@ TEST_F(BuiltinsMathTest, Cos_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cos(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9960946152060809); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9960946152060809); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1782,9 +1782,9 @@ TEST_F(BuiltinsMathTest, Cosh) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1797,9 +1797,9 @@ TEST_F(BuiltinsMathTest, Cosh_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1812,9 +1812,9 @@ TEST_F(BuiltinsMathTest, Cosh_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1827,9 +1827,9 @@ TEST_F(BuiltinsMathTest, Cosh_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1842,9 +1842,9 @@ TEST_F(BuiltinsMathTest, Cosh_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5430806348152437); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5430806348152437); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1857,9 +1857,9 @@ TEST_F(BuiltinsMathTest, Cosh_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1873,9 +1873,9 @@ TEST_F(BuiltinsMathTest, Cosh_6) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1889,9 +1889,9 @@ TEST_F(BuiltinsMathTest, Cosh_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Cosh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(12.659607234875645); + JSTaggedValue expect = builtins_common::GetTaggedDouble(12.659607234875645); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1904,9 +1904,9 @@ TEST_F(BuiltinsMathTest, Exp) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1919,9 +1919,9 @@ TEST_F(BuiltinsMathTest, Exp_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1934,9 +1934,9 @@ TEST_F(BuiltinsMathTest, Exp_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1949,9 +1949,9 @@ TEST_F(BuiltinsMathTest, Exp_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1964,9 +1964,9 @@ TEST_F(BuiltinsMathTest, Exp_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(2.718281828459045); + JSTaggedValue expect = builtins_common::GetTaggedDouble(2.718281828459045); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1979,9 +1979,9 @@ TEST_F(BuiltinsMathTest, Exp_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -1995,9 +1995,9 @@ TEST_F(BuiltinsMathTest, Exp_6) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2011,9 +2011,9 @@ TEST_F(BuiltinsMathTest, Exp_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Exp(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.039557498788398725); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.039557498788398725); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2026,9 +2026,9 @@ TEST_F(BuiltinsMathTest, Expm1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2041,9 +2041,9 @@ TEST_F(BuiltinsMathTest, Expm1_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2056,9 +2056,9 @@ TEST_F(BuiltinsMathTest, Expm1_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2071,9 +2071,9 @@ TEST_F(BuiltinsMathTest, Expm1_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2086,9 +2086,9 @@ TEST_F(BuiltinsMathTest, Expm1_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2101,7 +2101,7 @@ TEST_F(BuiltinsMathTest, Expm1_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); double expect = 1.718281828459045; ASSERT_TRUE(result.IsDouble()); @@ -2117,9 +2117,9 @@ TEST_F(BuiltinsMathTest, Expm1_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2133,9 +2133,9 @@ TEST_F(BuiltinsMathTest, Expm1_7) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2149,9 +2149,9 @@ TEST_F(BuiltinsMathTest, Expm1_8) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9604425012116012); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9604425012116012); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2165,9 +2165,9 @@ TEST_F(BuiltinsMathTest, Expm1_9) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Expm1(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(65659968.13733051); + JSTaggedValue expect = builtins_common::GetTaggedDouble(65659968.13733051); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2180,9 +2180,9 @@ TEST_F(BuiltinsMathTest, Floor) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2195,9 +2195,9 @@ TEST_F(BuiltinsMathTest, Floor_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2210,9 +2210,9 @@ TEST_F(BuiltinsMathTest, Floor_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2225,9 +2225,9 @@ TEST_F(BuiltinsMathTest, Floor_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2241,9 +2241,9 @@ TEST_F(BuiltinsMathTest, Floor_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Floor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-4.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2256,9 +2256,9 @@ TEST_F(BuiltinsMathTest, Log) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2271,9 +2271,9 @@ TEST_F(BuiltinsMathTest, Log_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2286,9 +2286,9 @@ TEST_F(BuiltinsMathTest, Log_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2301,9 +2301,9 @@ TEST_F(BuiltinsMathTest, Log_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2317,9 +2317,9 @@ TEST_F(BuiltinsMathTest, Log_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2332,9 +2332,9 @@ TEST_F(BuiltinsMathTest, Log_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.12)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-2.120263536200091); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-2.120263536200091); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2347,9 +2347,9 @@ TEST_F(BuiltinsMathTest, Log1p) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2362,9 +2362,9 @@ TEST_F(BuiltinsMathTest, Log1p_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2377,9 +2377,9 @@ TEST_F(BuiltinsMathTest, Log1p_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2392,9 +2392,9 @@ TEST_F(BuiltinsMathTest, Log1p_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.6931471805599453); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.6931471805599453); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2408,9 +2408,9 @@ TEST_F(BuiltinsMathTest, Log1p_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2423,9 +2423,9 @@ TEST_F(BuiltinsMathTest, Log1p_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.12)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log1p(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.11332868530700317); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.11332868530700317); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2438,9 +2438,9 @@ TEST_F(BuiltinsMathTest, Log10) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2453,9 +2453,9 @@ TEST_F(BuiltinsMathTest, Log10_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2468,9 +2468,9 @@ TEST_F(BuiltinsMathTest, Log10_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2483,9 +2483,9 @@ TEST_F(BuiltinsMathTest, Log10_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2499,9 +2499,9 @@ TEST_F(BuiltinsMathTest, Log10_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.3010299956639812); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.3010299956639812); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2514,9 +2514,9 @@ TEST_F(BuiltinsMathTest, Log10_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.12)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log10(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9208187539523752); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9208187539523752); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2529,9 +2529,9 @@ TEST_F(BuiltinsMathTest, Log2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2544,9 +2544,9 @@ TEST_F(BuiltinsMathTest, Log2_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2559,9 +2559,9 @@ TEST_F(BuiltinsMathTest, Log2_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2574,9 +2574,9 @@ TEST_F(BuiltinsMathTest, Log2_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2590,9 +2590,9 @@ TEST_F(BuiltinsMathTest, Log2_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2605,9 +2605,9 @@ TEST_F(BuiltinsMathTest, Log2_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Log2(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2622,9 +2622,9 @@ TEST_F(BuiltinsMathTest, Max) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Max(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2636,9 +2636,9 @@ TEST_F(BuiltinsMathTest, Max_1) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Max(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2654,9 +2654,9 @@ TEST_F(BuiltinsMathTest, Max_2) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(2.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Max(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(100); + JSTaggedValue expect = builtins_common::GetTaggedInt(100); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2672,9 +2672,9 @@ TEST_F(BuiltinsMathTest, Max_3) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(-101.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Max(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(100.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(100.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2690,9 +2690,9 @@ TEST_F(BuiltinsMathTest, Max_4) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Max(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Max(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(1); + JSTaggedValue expect = builtins_common::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2707,9 +2707,9 @@ TEST_F(BuiltinsMathTest, Min) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Min(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2721,9 +2721,9 @@ TEST_F(BuiltinsMathTest, Min_1) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Min(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2739,9 +2739,9 @@ TEST_F(BuiltinsMathTest, Min_2) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(2.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Min(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(2.5); + JSTaggedValue expect = builtins_common::GetTaggedDouble(2.5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2757,9 +2757,9 @@ TEST_F(BuiltinsMathTest, Min_3) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(-101.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Min(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-101.5); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-101.5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2774,9 +2774,9 @@ TEST_F(BuiltinsMathTest, Min_4) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue::False()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Min(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Min(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); + JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2791,9 +2791,9 @@ TEST_F(BuiltinsMathTest, Pow) ecma_runtime_call_info->SetCallArg(1, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.25); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.25); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2807,7 +2807,7 @@ TEST_F(BuiltinsMathTest, Pow_1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); ASSERT_TRUE(std::isnan(result.GetDouble())); } @@ -2819,9 +2819,9 @@ TEST_F(BuiltinsMathTest, Pow_2) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2835,9 +2835,9 @@ TEST_F(BuiltinsMathTest, Pow_3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Pow(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2849,9 +2849,9 @@ TEST_F(BuiltinsMathTest, Random) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsMath::Random(ecma_runtime_call_info.get()); + JSTaggedValue result1 = math::Random(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue result2 = BuiltinsMath::Random(ecma_runtime_call_info.get()); + JSTaggedValue result2 = math::Random(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_NE(result1.GetRawData(), result2.GetRawData()); } @@ -2864,9 +2864,9 @@ TEST_F(BuiltinsMathTest, Random_1) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsMath::Random(ecma_runtime_call_info.get()); + JSTaggedValue result1 = math::Random(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue result2 = BuiltinsMath::Random(ecma_runtime_call_info.get()); + JSTaggedValue result2 = math::Random(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); double value1 = JSTaggedValue(static_cast(result1.GetRawData())).GetDouble(); double value2 = JSTaggedValue(static_cast(result2.GetRawData())).GetDouble(); @@ -2885,9 +2885,9 @@ TEST_F(BuiltinsMathTest, Round) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Round(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2900,9 +2900,9 @@ TEST_F(BuiltinsMathTest, Round_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.25)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Round(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2915,9 +2915,9 @@ TEST_F(BuiltinsMathTest, Round_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.14)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Round(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2930,9 +2930,9 @@ TEST_F(BuiltinsMathTest, Round_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.7)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Round(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2945,9 +2945,9 @@ TEST_F(BuiltinsMathTest, Round_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Round(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Round(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2960,9 +2960,9 @@ TEST_F(BuiltinsMathTest, Fround) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2975,9 +2975,9 @@ TEST_F(BuiltinsMathTest, Fround_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -2990,9 +2990,9 @@ TEST_F(BuiltinsMathTest, Fround_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3005,9 +3005,9 @@ TEST_F(BuiltinsMathTest, Fround_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(1.337)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.3370000123977661); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.3370000123977661); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3020,9 +3020,9 @@ TEST_F(BuiltinsMathTest, Fround_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-668523145.253485)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Fround(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-668523136.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-668523136.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3035,9 +3035,9 @@ TEST_F(BuiltinsMathTest, Clz32) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(32); + JSTaggedValue expect = builtins_common::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3050,9 +3050,9 @@ TEST_F(BuiltinsMathTest, Clz32_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(32); + JSTaggedValue expect = builtins_common::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3065,9 +3065,9 @@ TEST_F(BuiltinsMathTest, Clz32_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(31); + JSTaggedValue expect = builtins_common::GetTaggedInt(31); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3080,9 +3080,9 @@ TEST_F(BuiltinsMathTest, Clz32_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(568243))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(12); + JSTaggedValue expect = builtins_common::GetTaggedInt(12); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3095,9 +3095,9 @@ TEST_F(BuiltinsMathTest, Clz32_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(4294967295))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); + JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3110,9 +3110,9 @@ TEST_F(BuiltinsMathTest, Clz32_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(10000000000.123)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(1); + JSTaggedValue expect = builtins_common::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3124,9 +3124,9 @@ TEST_F(BuiltinsMathTest, Clz32_6) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Clz32(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(32); + JSTaggedValue expect = builtins_common::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3138,9 +3138,9 @@ TEST_F(BuiltinsMathTest, Hypot) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3153,9 +3153,9 @@ TEST_F(BuiltinsMathTest, Hypot_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-2.1)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(2.1); + JSTaggedValue expect = builtins_common::GetTaggedDouble(2.1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3168,7 +3168,7 @@ TEST_F(BuiltinsMathTest, Hypot_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsDouble()); ASSERT_TRUE(std::isnan(result.GetDouble())); @@ -3187,9 +3187,9 @@ TEST_F(BuiltinsMathTest, Hypot_3) ecma_runtime_call_info->SetCallArg(4, JSTaggedValue(static_cast(90000))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Hypot(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(90000.00050022222); + JSTaggedValue expect = builtins_common::GetTaggedDouble(90000.00050022222); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3201,9 +3201,9 @@ TEST_F(BuiltinsMathTest, Imul) ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); + JSTaggedValue expect = builtins_common::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3218,9 +3218,9 @@ TEST_F(BuiltinsMathTest, Imul_1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(9.256)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(-18); + JSTaggedValue expect = builtins_common::GetTaggedInt(-18); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3234,9 +3234,9 @@ TEST_F(BuiltinsMathTest, Imul_2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0xffffffff))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(-5); + JSTaggedValue expect = builtins_common::GetTaggedInt(-5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3250,9 +3250,9 @@ TEST_F(BuiltinsMathTest, Imul_3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0xfffffffe))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Imul(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedInt(-10); + JSTaggedValue expect = builtins_common::GetTaggedInt(-10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3265,9 +3265,9 @@ TEST_F(BuiltinsMathTest, Sin) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.8414709848078965); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.8414709848078965); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3280,9 +3280,9 @@ TEST_F(BuiltinsMathTest, Sin_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9974949866040544); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.9974949866040544); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3295,9 +3295,9 @@ TEST_F(BuiltinsMathTest, Sin_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3310,9 +3310,9 @@ TEST_F(BuiltinsMathTest, Sin_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3325,9 +3325,9 @@ TEST_F(BuiltinsMathTest, Sin_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.8414709848078965); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.8414709848078965); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3341,9 +3341,9 @@ TEST_F(BuiltinsMathTest, Sin_6) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.09983341664682815); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.09983341664682815); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3356,9 +3356,9 @@ TEST_F(BuiltinsMathTest, Sin_7) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3371,9 +3371,9 @@ TEST_F(BuiltinsMathTest, Sin_8) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sin(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3386,9 +3386,9 @@ TEST_F(BuiltinsMathTest, Sinh) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.1752011936438014); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.1752011936438014); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3401,9 +3401,9 @@ TEST_F(BuiltinsMathTest, Sinh_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-1.5)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-2.1292794550948173); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-2.1292794550948173); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3416,9 +3416,9 @@ TEST_F(BuiltinsMathTest, Sinh_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3431,9 +3431,9 @@ TEST_F(BuiltinsMathTest, Sinh_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3446,9 +3446,9 @@ TEST_F(BuiltinsMathTest, Sinh_4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.1752011936438014); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.1752011936438014); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3462,9 +3462,9 @@ TEST_F(BuiltinsMathTest, Sinh_5) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.10016675001984403); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.10016675001984403); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3477,9 +3477,9 @@ TEST_F(BuiltinsMathTest, Sinh_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3492,9 +3492,9 @@ TEST_F(BuiltinsMathTest, Sinh_7) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sinh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3507,9 +3507,9 @@ TEST_F(BuiltinsMathTest, Sqrt) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3522,9 +3522,9 @@ TEST_F(BuiltinsMathTest, Sqrt_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3537,9 +3537,9 @@ TEST_F(BuiltinsMathTest, Sqrt_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3552,9 +3552,9 @@ TEST_F(BuiltinsMathTest, Sqrt_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3568,9 +3568,9 @@ TEST_F(BuiltinsMathTest, Sqrt_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.31622776601683794); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.31622776601683794); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3583,9 +3583,9 @@ TEST_F(BuiltinsMathTest, Sqrt_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3598,9 +3598,9 @@ TEST_F(BuiltinsMathTest, Sqrt_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Sqrt(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3613,9 +3613,9 @@ TEST_F(BuiltinsMathTest, Tan) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.5574077246549023); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.5574077246549023); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3628,9 +3628,9 @@ TEST_F(BuiltinsMathTest, Tan_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3643,9 +3643,9 @@ TEST_F(BuiltinsMathTest, Tan_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3658,9 +3658,9 @@ TEST_F(BuiltinsMathTest, Tan_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5574077246549023); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.5574077246549023); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3674,9 +3674,9 @@ TEST_F(BuiltinsMathTest, Tan_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.10033467208545055); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.10033467208545055); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3689,9 +3689,9 @@ TEST_F(BuiltinsMathTest, Tan_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3704,9 +3704,9 @@ TEST_F(BuiltinsMathTest, Tan_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tan(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3719,9 +3719,9 @@ TEST_F(BuiltinsMathTest, Tanh) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.7615941559557649); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.7615941559557649); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3734,9 +3734,9 @@ TEST_F(BuiltinsMathTest, Tanh_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3749,9 +3749,9 @@ TEST_F(BuiltinsMathTest, Tanh_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3764,9 +3764,9 @@ TEST_F(BuiltinsMathTest, Tanh_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.7615941559557649); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.7615941559557649); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3780,9 +3780,9 @@ TEST_F(BuiltinsMathTest, Tanh_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.09966799462495582); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0.09966799462495582); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3795,9 +3795,9 @@ TEST_F(BuiltinsMathTest, Tanh_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3810,9 +3810,9 @@ TEST_F(BuiltinsMathTest, Tanh_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Tanh(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3825,9 +3825,9 @@ TEST_F(BuiltinsMathTest, Trunc) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3840,9 +3840,9 @@ TEST_F(BuiltinsMathTest, Trunc_1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-0.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3855,9 +3855,9 @@ TEST_F(BuiltinsMathTest, Trunc_2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3870,9 +3870,9 @@ TEST_F(BuiltinsMathTest, Trunc_3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::True()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3886,9 +3886,9 @@ TEST_F(BuiltinsMathTest, Trunc_4) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); + JSTaggedValue expect = builtins_common::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3901,9 +3901,9 @@ TEST_F(BuiltinsMathTest, Trunc_5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } @@ -3916,9 +3916,9 @@ TEST_F(BuiltinsMathTest, Trunc_6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecma_runtime_call_info.get()); + JSTaggedValue result = math::Trunc(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue expect = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); } } // namespace panda::test diff --git a/tests/runtime/builtins/builtins_number_test.cpp b/tests/runtime/builtins/builtins_number_test.cpp index c1ddaf1d6f3dfb64a50196c70db94e5be54e4a08..35f1a223c3da2b98e3b1a4846afbd9d9eca5619c 100644 --- a/tests/runtime/builtins/builtins_number_test.cpp +++ b/tests/runtime/builtins/builtins_number_test.cpp @@ -18,7 +18,7 @@ #include #include "plugins/ecmascript/runtime/base/number_helper.h" #include "plugins/ecmascript/runtime/base/string_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_number.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -77,7 +77,7 @@ TEST_F(BuiltinsNumberTest, NumberConstructor) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::NumberConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = number::NumberConstructor(ecma_runtime_call_info.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSPrimitiveRef *ref = JSPrimitiveRef::Cast(value.GetTaggedObject()); @@ -94,7 +94,7 @@ TEST_F(BuiltinsNumberTest, IsFinite) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(value))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -107,7 +107,7 @@ TEST_F(BuiltinsNumberTest, IsFinite1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::MAX_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -121,7 +121,7 @@ TEST_F(BuiltinsNumberTest, IsFinite2) ecma_runtime_call_info->SetCallArg(0, test.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -134,7 +134,7 @@ TEST_F(BuiltinsNumberTest, IsFinite3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -147,7 +147,7 @@ TEST_F(BuiltinsNumberTest, IsFinite4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -160,7 +160,7 @@ TEST_F(BuiltinsNumberTest, IsFinite5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -173,7 +173,7 @@ TEST_F(BuiltinsNumberTest, IsFinite6) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Null()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsFinite(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -186,7 +186,7 @@ TEST_F(BuiltinsNumberTest, IsInteger) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.1)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsInteger(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsInteger(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -199,7 +199,7 @@ TEST_F(BuiltinsNumberTest, IsNaN) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(0.1)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::IsNaN(ecma_runtime_call_info.get()); + JSTaggedValue result = number::IsNaN(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -220,7 +220,7 @@ TEST_F(BuiltinsNumberTest, ToString) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(7.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = number::proto::ToString(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correct_result = factory->NewFromCanBeCompressString("234.312256641535441"); @@ -246,7 +246,7 @@ TEST_F(BuiltinsNumberTest, IsExponential) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(5.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ToExponential(ecma_runtime_call_info.get()); + JSTaggedValue result = number::proto::ToExponential(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correct_result = factory->NewFromCanBeCompressString("1.23456e+2"); @@ -272,7 +272,7 @@ TEST_F(BuiltinsNumberTest, ToFixed) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(10.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ToFixed(ecma_runtime_call_info.get()); + JSTaggedValue result = number::proto::ToFixed(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correct_result = factory->NewFromCanBeCompressString("123.4560000000"); @@ -296,7 +296,7 @@ TEST_F(BuiltinsNumberTest, ToFixed1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(30.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ToFixed(ecma_runtime_call_info.get()); + JSTaggedValue result = number::proto::ToFixed(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correct_result = factory->NewFromCanBeCompressString("123.456000000000003069544618483633"); @@ -320,7 +320,7 @@ TEST_F(BuiltinsNumberTest, ToFixed2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(20.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ToFixed(ecma_runtime_call_info.get()); + JSTaggedValue result = number::proto::ToFixed(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correct_result = factory->NewFromCanBeCompressString("1e+21"); @@ -347,7 +347,7 @@ TEST_F(BuiltinsNumberTest, ToPrecision) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(8.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ToPrecision(ecma_runtime_call_info.get()); + JSTaggedValue result = number::proto::ToPrecision(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correct_result = factory->NewFromCanBeCompressString("123.45600"); @@ -364,7 +364,7 @@ TEST_F(BuiltinsNumberTest, parseFloat) ecma_runtime_call_info->SetCallArg(0, param.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ParseFloat(ecma_runtime_call_info.get()); + JSTaggedValue result = number::ParseFloat(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(0)).GetRawData()); } @@ -378,7 +378,7 @@ TEST_F(BuiltinsNumberTest, parseFloat1) ecma_runtime_call_info->SetCallArg(0, param.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ParseFloat(ecma_runtime_call_info.get()); + JSTaggedValue result = number::ParseFloat(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(0)).GetRawData()); } @@ -395,7 +395,7 @@ TEST_F(BuiltinsNumberTest, parseInt) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(16.0)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsNumber::ParseInt(ecma_runtime_call_info.get()); + JSTaggedValue result = number::ParseInt(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(291)).GetRawData()); } diff --git a/tests/runtime/builtins/builtins_object_test.cpp b/tests/runtime/builtins/builtins_object_test.cpp index efae2fa0f1bf045384abf9770fc3af52ee1ca107..78612747a1b8b361b4fbdf7a3a2fa2bc8f1f9df8 100644 --- a/tests/runtime/builtins/builtins_object_test.cpp +++ b/tests/runtime/builtins/builtins_object_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_object.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -103,7 +103,7 @@ TEST_F(BuiltinsObjectTest, ObjectConstructor) obj_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::ObjectConstructor(obj_call_info.get()); + JSTaggedValue result = object::ObjectConstructor(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -122,7 +122,7 @@ TEST_F(BuiltinsObjectTest, ObjectConstructor) tg_obj_call_info->SetNewTarget(JSTaggedValue(*obj_fun)); prev = TestHelper::SetupFrame(thread, tg_obj_call_info.get()); - JSTaggedValue result_tg = BuiltinsObject::ObjectConstructor(tg_obj_call_info.get()); + JSTaggedValue result_tg = object::ObjectConstructor(tg_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_tg.IsObject()); JSHandle jt_handle_tg(thread, JSTaggedValue(reinterpret_cast(result_tg.GetRawData()))); @@ -141,7 +141,7 @@ TEST_F(BuiltinsObjectTest, ObjectConstructor) vn_obj_call_info->SetNewTarget(JSTaggedValue(*obj_fun)); prev = TestHelper::SetupFrame(thread, vn_obj_call_info.get()); - JSTaggedValue result_vn = BuiltinsObject::ObjectConstructor(vn_obj_call_info.get()); + JSTaggedValue result_vn = object::ObjectConstructor(vn_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_vn.IsObject()); @@ -178,7 +178,7 @@ TEST_F(BuiltinsObjectTest, Assign) assign_obj_call_info->SetCallArg(1, obj_handle2.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, assign_obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::Assign(assign_obj_call_info.get()); + JSTaggedValue result = object::Assign(assign_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -201,7 +201,7 @@ TEST_F(BuiltinsObjectTest, Create) obj_call_info->SetCallArg(0, func_proto.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::Create(obj_call_info.get()); + JSTaggedValue result = object::Create(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -229,7 +229,7 @@ TEST_F(BuiltinsObjectTest, Create) hp_obj_call_info->SetCallArg(1, obj_handle.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, hp_obj_call_info.get()); - JSTaggedValue result_hp = BuiltinsObject::Create(hp_obj_call_info.get()); + JSTaggedValue result_hp = object::Create(hp_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_hp.IsObject()); @@ -245,7 +245,7 @@ TEST_F(BuiltinsObjectTest, Create) un_call_info->SetCallArg(0, JSTaggedValue::Undefined()); prev = TestHelper::SetupFrame(thread, un_call_info.get()); - JSTaggedValue result_un = BuiltinsObject::Create(un_call_info.get()); + JSTaggedValue result_un = object::Create(un_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result_un.GetRawData(), JSTaggedValue::VALUE_EXCEPTION); } @@ -276,7 +276,7 @@ TEST_F(BuiltinsObjectTest, DefineProperties) obj_call_info->SetCallArg(1, jsobj_handle.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::DefineProperties(obj_call_info.get()); + JSTaggedValue result = object::DefineProperties(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -318,7 +318,7 @@ TEST_F(BuiltinsObjectTest, DefineProperty) obj_call_info->SetCallArg(2, att_handle.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::DefineProperty(obj_call_info.get()); + JSTaggedValue result = object::DefineProperty(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -344,7 +344,7 @@ TEST_F(BuiltinsObjectTest, DefineGetter) ecma_runtime_call_info->SetCallArg(1, getter.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::DefineSetter(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::__defineGetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -366,7 +366,7 @@ TEST_F(BuiltinsObjectTest, DefineSetter) ecma_runtime_call_info->SetCallArg(1, setter.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::DefineGetter(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::__defineSetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -388,7 +388,7 @@ TEST_F(BuiltinsObjectTest, LookupGetter) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::LookupGetter(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::__lookupGetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -401,7 +401,7 @@ TEST_F(BuiltinsObjectTest, LookupGetter) ecma_runtime_call_info->SetCallArg(1, getter.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - result = BuiltinsObject::DefineGetter(ecma_runtime_call_info.get()); + result = object::proto::__defineGetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -413,7 +413,7 @@ TEST_F(BuiltinsObjectTest, LookupGetter) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - result = BuiltinsObject::LookupGetter(ecma_runtime_call_info.get()); + result = object::proto::__lookupGetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result, getter.GetTaggedValue()); @@ -435,7 +435,7 @@ TEST_F(BuiltinsObjectTest, LookupSetter) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::LookupSetter(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::__lookupSetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -448,7 +448,7 @@ TEST_F(BuiltinsObjectTest, LookupSetter) ecma_runtime_call_info->SetCallArg(1, setter.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - result = BuiltinsObject::DefineSetter(ecma_runtime_call_info.get()); + result = object::proto::__defineSetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -460,7 +460,7 @@ TEST_F(BuiltinsObjectTest, LookupSetter) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - result = BuiltinsObject::LookupSetter(ecma_runtime_call_info.get()); + result = object::proto::__lookupSetter__(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result, setter.GetTaggedValue()); @@ -480,12 +480,12 @@ TEST_F(BuiltinsObjectTest, Freeze) nofreeze_obj_call_info->SetCallArg(0, empty_obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, nofreeze_obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::IsFrozen(nofreeze_obj_call_info.get()); + JSTaggedValue result = object::IsFrozen(nofreeze_obj_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); - BuiltinsObject::Freeze(nofreeze_obj_call_info.get()); - JSTaggedValue result_is = BuiltinsObject::IsFrozen(nofreeze_obj_call_info.get()); + object::Freeze(nofreeze_obj_call_info.get()); + JSTaggedValue result_is = object::IsFrozen(nofreeze_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result_is.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -525,7 +525,7 @@ TEST_F(BuiltinsObjectTest, FromEntries) obj_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::FromEntries(obj_call_info.get()); + JSTaggedValue result = object::FromEntries(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -537,7 +537,7 @@ TEST_F(BuiltinsObjectTest, FromEntries) } // 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) -TEST_F(BuiltinsObjectTest, GetOwnPropertyDesciptor) +TEST_F(BuiltinsObjectTest, GetOwnPropertyDescriptor) { JSHandle function(thread, BuiltinsObjectTestCreate(thread)); JSHandle obj_handle = @@ -556,7 +556,7 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertyDesciptor) obj_call_info->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertyDesciptor(obj_call_info.get()); + JSTaggedValue result = object::GetOwnPropertyDescriptor(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -569,7 +569,7 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertyDesciptor) } // ES2021 20.1.2.9 Object.getOwnPropertyDescriptors ( O ) -TEST_F(BuiltinsObjectTest, GetOwnPropertyDesciptors) +TEST_F(BuiltinsObjectTest, GetOwnPropertyDescriptors) { JSHandle function(thread, BuiltinsObjectTestCreate(thread)); JSHandle obj_handle = @@ -586,7 +586,7 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertyDesciptors) obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertyDesciptors(obj_call_info.get()); + JSTaggedValue result = object::GetOwnPropertyDescriptors(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -625,7 +625,7 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertyNames) obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertyNames(obj_call_info.get()); + JSTaggedValue result = object::GetOwnPropertyNames(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -649,7 +649,7 @@ TEST_F(BuiltinsObjectTest, GetOwnPropertySymbols) obj_call_info->SetCallArg(0, obj_handle.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertySymbols(obj_call_info.get()); + JSTaggedValue result = object::GetOwnPropertySymbols(obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -673,13 +673,13 @@ TEST_F(BuiltinsObjectTest, Is) obj_call_info1->SetCallArg(1, obj2.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, obj_call_info1.get()); - JSTaggedValue obj_result1 = BuiltinsObject::Is(obj_call_info1.get()); + JSTaggedValue obj_result1 = object::Is(obj_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(obj_result1.GetRawData(), JSTaggedValue::False().GetRawData()); obj_call_info1->SetCallArg(1, obj1.GetTaggedValue()); - JSTaggedValue obj_result2 = BuiltinsObject::Is(obj_call_info1.get()); + JSTaggedValue obj_result2 = object::Is(obj_call_info1.get()); ASSERT_EQ(obj_result2.GetRawData(), JSTaggedValue::True().GetRawData()); // string compare @@ -693,7 +693,7 @@ TEST_F(BuiltinsObjectTest, Is) str_call_info->SetCallArg(1, test_str_value2.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, str_call_info.get()); - JSTaggedValue str_result = BuiltinsObject::Is(str_call_info.get()); + JSTaggedValue str_result = object::Is(str_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(str_result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -706,7 +706,7 @@ TEST_F(BuiltinsObjectTest, Is) bool_call_info->SetCallArg(1, JSTaggedValue::False()); prev = TestHelper::SetupFrame(thread, bool_call_info.get()); - JSTaggedValue bool_result = BuiltinsObject::Is(bool_call_info.get()); + JSTaggedValue bool_result = object::Is(bool_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(bool_result.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -719,7 +719,7 @@ TEST_F(BuiltinsObjectTest, Is) num_call_info->SetCallArg(1, JSTaggedValue(-0.0)); prev = TestHelper::SetupFrame(thread, num_call_info.get()); - JSTaggedValue num_result = BuiltinsObject::Is(num_call_info.get()); + JSTaggedValue num_result = object::Is(num_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(num_result.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -732,7 +732,7 @@ TEST_F(BuiltinsObjectTest, Is) null_call_info->SetCallArg(1, JSTaggedValue::Null()); prev = TestHelper::SetupFrame(thread, null_call_info.get()); - JSTaggedValue null_result = BuiltinsObject::Is(null_call_info.get()); + JSTaggedValue null_result = object::Is(null_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(null_result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -744,7 +744,7 @@ TEST_F(BuiltinsObjectTest, Is) undefine_call_info->SetCallArg(1, JSTaggedValue::Undefined()); prev = TestHelper::SetupFrame(thread, undefine_call_info.get()); - JSTaggedValue undefine_result = BuiltinsObject::Is(undefine_call_info.get()); + JSTaggedValue undefine_result = object::Is(undefine_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(undefine_result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -765,13 +765,13 @@ TEST_F(BuiltinsObjectTest, IsExtensible) empty_obj_call_info->SetCallArg(0, empty_obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, empty_obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::IsExtensible(empty_obj_call_info.get()); + JSTaggedValue result = object::IsExtensible(empty_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); empty_obj->GetJSHClass()->SetExtensible(false); - JSTaggedValue result2 = BuiltinsObject::IsExtensible(empty_obj_call_info.get()); + JSTaggedValue result2 = object::IsExtensible(empty_obj_call_info.get()); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -793,10 +793,10 @@ TEST_F(BuiltinsObjectTest, IsFrozen) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, empty_obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::IsFrozen(empty_obj_call_info.get()); + JSTaggedValue result = object::IsFrozen(empty_obj_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); obj->GetJSHClass()->SetExtensible(false); - JSTaggedValue result_nex = BuiltinsObject::IsFrozen(empty_obj_call_info.get()); + JSTaggedValue result_nex = object::IsFrozen(empty_obj_call_info.get()); ASSERT_EQ(result_nex.GetRawData(), JSTaggedValue::True().GetRawData()); TestHelper::TearDownFrame(thread, prev); @@ -813,7 +813,7 @@ TEST_F(BuiltinsObjectTest, IsFrozen) empty_obj_call_info2->SetCallArg(0, obj.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, empty_obj_call_info2.get()); - JSTaggedValue result_nw = BuiltinsObject::IsFrozen(empty_obj_call_info2.get()); + JSTaggedValue result_nw = object::IsFrozen(empty_obj_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result_nw.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -828,7 +828,7 @@ TEST_F(BuiltinsObjectTest, IsFrozen) empty_obj_call_info3->SetCallArg(0, obj.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, empty_obj_call_info3.get()); - JSTaggedValue result_nc = BuiltinsObject::IsFrozen(empty_obj_call_info3.get()); + JSTaggedValue result_nc = object::IsFrozen(empty_obj_call_info3.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result_nc.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -849,7 +849,7 @@ TEST_F(BuiltinsObjectTest, IsSealed) empty_obj_call_info->SetCallArg(0, empty_obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, empty_obj_call_info.get()); - JSTaggedValue result = BuiltinsObject::IsSealed(empty_obj_call_info.get()); + JSTaggedValue result = object::IsSealed(empty_obj_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -865,7 +865,7 @@ TEST_F(BuiltinsObjectTest, Keys) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::Keys(ecma_runtime_call_info.get()); + JSTaggedValue result = object::Keys(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -882,7 +882,7 @@ TEST_F(BuiltinsObjectTest, PreventExtensions) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::PreventExtensions(ecma_runtime_call_info.get()); + JSTaggedValue result = object::PreventExtensions(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -901,13 +901,13 @@ TEST_F(BuiltinsObjectTest, Seal) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::Seal(ecma_runtime_call_info.get()); + JSTaggedValue result = object::Seal(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(result.GetRawData(), obj->GetRawData()); // test isSealed(). - JSTaggedValue res = BuiltinsObject::IsSealed(ecma_runtime_call_info.get()); + JSTaggedValue res = object::IsSealed(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(res.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -925,7 +925,7 @@ TEST_F(BuiltinsObjectTest, SetPrototypeOf) ecma_runtime_call_info->SetCallArg(1, obj_father.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::SetPrototypeOf(ecma_runtime_call_info.get()); + JSTaggedValue result = object::SetPrototypeOf(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -951,7 +951,7 @@ TEST_F(BuiltinsObjectTest, Values) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::Values(ecma_runtime_call_info.get()); + JSTaggedValue result = object::Values(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); @@ -977,7 +977,7 @@ TEST_F(BuiltinsObjectTest, HasOwnProperty) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::HasOwnProperty(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::HasOwnProperty(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -995,7 +995,7 @@ TEST_F(BuiltinsObjectTest, IsPrototypeOfFalse) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsObject::IsPrototypeOf(ecma_runtime_call_info.get()); + JSTaggedValue result1 = object::proto::IsPrototypeOf(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -1013,7 +1013,7 @@ TEST_F(BuiltinsObjectTest, IsPrototypeOfTrue) ecma_runtime_call_info1->SetCallArg(1, obj_father.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsObject::SetPrototypeOf(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = object::SetPrototypeOf(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsObject()); @@ -1025,7 +1025,7 @@ TEST_F(BuiltinsObjectTest, IsPrototypeOfTrue) ecma_runtime_call_info2->SetCallArg(0, obj.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsObject::IsPrototypeOf(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = object::proto::IsPrototypeOf(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -1043,7 +1043,7 @@ TEST_F(BuiltinsObjectTest, PropertyIsEnumerable) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::PropertyIsEnumerable(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::PropertyIsEnumerable(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -1054,7 +1054,7 @@ TEST_F(BuiltinsObjectTest, ToLocaleString) { JSHandle obj(thread, CreateBuiltinJSObject(thread, "x")); JSHandle callee_func = thread->GetEcmaVM()->GetFactory()->NewJSFunction( - thread->GetEcmaVM()->GetGlobalEnv(), reinterpret_cast(BuiltinsObject::ToString)); + thread->GetEcmaVM()->GetGlobalEnv(), reinterpret_cast(object::proto::ToString)); JSHandle callee_value(callee_func); JSHandle callee_key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("toString")); JSObject::SetProperty(thread, obj, callee_key, callee_value); @@ -1068,7 +1068,7 @@ TEST_F(BuiltinsObjectTest, ToLocaleString) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::ToLocaleString(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::ToLocaleString(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -1088,7 +1088,7 @@ TEST_F(BuiltinsObjectTest, ToString) ecma_runtime_call_info->SetThis(obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::ToString(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -1103,7 +1103,7 @@ TEST_F(BuiltinsObjectTest, ToString) arr_ecma_runtime_call_info->SetThis(arr.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, arr_ecma_runtime_call_info.get()); - JSTaggedValue result_arr = BuiltinsObject::ToString(arr_ecma_runtime_call_info.get()); + JSTaggedValue result_arr = object::proto::ToString(arr_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_arr.IsString()); @@ -1118,7 +1118,7 @@ TEST_F(BuiltinsObjectTest, ToString) str_ecma_runtime_call_info->SetThis(str.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, str_ecma_runtime_call_info.get()); - JSTaggedValue result_str = BuiltinsObject::ToString(str_ecma_runtime_call_info.get()); + JSTaggedValue result_str = object::proto::ToString(str_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_str.IsString()); @@ -1133,7 +1133,7 @@ TEST_F(BuiltinsObjectTest, ToString) func_ecma_runtime_call_info->SetThis(func.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, func_ecma_runtime_call_info.get()); - JSTaggedValue result_func = BuiltinsObject::ToString(func_ecma_runtime_call_info.get()); + JSTaggedValue result_func = object::proto::ToString(func_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_func.IsString()); @@ -1151,7 +1151,7 @@ TEST_F(BuiltinsObjectTest, ToString) error_ecma_runtime_call_info->SetThis(error.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, error_ecma_runtime_call_info.get()); - JSTaggedValue result_error = BuiltinsObject::ToString(error_ecma_runtime_call_info.get()); + JSTaggedValue result_error = object::proto::ToString(error_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_error.IsString()); @@ -1168,7 +1168,7 @@ TEST_F(BuiltinsObjectTest, ToString) bool_ecma_runtime_call_info->SetThis(boolean.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, bool_ecma_runtime_call_info.get()); - JSTaggedValue result_bool = BuiltinsObject::ToString(bool_ecma_runtime_call_info.get()); + JSTaggedValue result_bool = object::proto::ToString(bool_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_bool.IsString()); @@ -1182,7 +1182,7 @@ TEST_F(BuiltinsObjectTest, ToString) num_ecma_runtime_call_info->SetThis(JSTaggedValue(static_cast(0))); prev = TestHelper::SetupFrame(thread, num_ecma_runtime_call_info.get()); - JSTaggedValue result_num = BuiltinsObject::ToString(num_ecma_runtime_call_info.get()); + JSTaggedValue result_num = object::proto::ToString(num_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result_num.IsString()); @@ -1199,7 +1199,7 @@ TEST_F(BuiltinsObjectTest, ValueOf) ecma_runtime_call_info->SetCallArg(0, obj.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsObject::ValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result = object::proto::ValueOf(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); diff --git a/tests/runtime/builtins/builtins_promise_test.cpp b/tests/runtime/builtins/builtins_promise_test.cpp index ee273882cafa99588e9a2e1d557ff0fc10232080..63c5dcd907060ddfa62479d158b3e92129731586 100644 --- a/tests/runtime/builtins/builtins_promise_test.cpp +++ b/tests/runtime/builtins/builtins_promise_test.cpp @@ -13,8 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_promise.h" -#include "plugins/ecmascript/runtime/builtins/builtins_array.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -32,7 +31,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; using JSArray = panda::ecmascript::JSArray; class BuiltinsPromiseTest : public testing::Test { @@ -65,7 +63,7 @@ public: // native function for race2 then_on_rejected() JSTaggedValue TestPromiseRaceThenOnRejectd(EcmaRuntimeCallInfo *argv) { - JSHandle result = BuiltinsBase::GetCallArg(argv, 0); + JSHandle result = builtins_common::GetCallArg(argv, 0); // 12345 : test case EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), JSTaggedValue(12345)), true); return JSTaggedValue::Undefined(); @@ -75,7 +73,7 @@ JSTaggedValue TestPromiseRaceThenOnRejectd(EcmaRuntimeCallInfo *argv) JSTaggedValue TestPromiseAllThenOnResolved(EcmaRuntimeCallInfo *argv) { [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); - JSHandle array = BuiltinsBase::GetCallArg(argv, 0); + JSHandle array = builtins_common::GetCallArg(argv, 0); JSHandle object_array = JSHandle::Cast(array); [[maybe_unused]] PropertyDescriptor desc(argv->GetThread()); [[maybe_unused]] bool result1 = JSObject::GetOwnProperty( @@ -96,7 +94,7 @@ JSTaggedValue TestPromiseAllThenOnResolved(EcmaRuntimeCallInfo *argv) // native function for catch catch_on_rejected() JSTaggedValue TestPromiseCatch(EcmaRuntimeCallInfo *argv) { - JSHandle result = BuiltinsBase::GetCallArg(argv, 0); + JSHandle result = builtins_common::GetCallArg(argv, 0); // 3 : test case EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), JSTaggedValue(3)), true); return JSTaggedValue::Undefined(); @@ -107,7 +105,7 @@ JSTaggedValue TestPromiseThenOnResolved(EcmaRuntimeCallInfo *argv) { [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); - JSHandle result = BuiltinsBase::GetCallArg(argv, 0); + JSHandle result = builtins_common::GetCallArg(argv, 0); auto expect = factory->NewFromCanBeCompressString("resolve"); EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), expect.GetTaggedValue()), true); return JSTaggedValue::Undefined(); @@ -118,7 +116,7 @@ JSTaggedValue TestPromiseThenOnRejected(EcmaRuntimeCallInfo *argv) { [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); auto factory = argv->GetThread()->GetEcmaVM()->GetFactory(); - JSHandle result = BuiltinsBase::GetCallArg(argv, 0); + JSHandle result = builtins_common::GetCallArg(argv, 0); auto expect = factory->NewFromCanBeCompressString("reject"); EXPECT_EQ(JSTaggedValue::SameValue(result.GetTaggedValue(), expect.GetTaggedValue()), true); return JSTaggedValue::Undefined(); @@ -145,7 +143,7 @@ TEST_F(BuiltinsPromiseTest, Reject1) * @tc.steps: var p1 = Promise.reject(3). */ [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result = promise::Reject(ecma_runtime_call_info1.get()); JSHandle reject_promise(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -177,7 +175,7 @@ TEST_F(BuiltinsPromiseTest, Reject2) ecma_runtime_call_info->SetCallArg(0, param_msg1.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecma_runtime_call_info.get()); + JSTaggedValue result = promise::Reject(ecma_runtime_call_info.get()); JSHandle promise1(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -193,7 +191,7 @@ TEST_F(BuiltinsPromiseTest, Reject2) ecma_runtime_call_info1->SetCallArg(0, promise1.GetTaggedValue()); [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsPromise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Reject(ecma_runtime_call_info1.get()); JSHandle promise2(thread, result1); EXPECT_NE(*promise1, *promise2); EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseState(), @@ -225,7 +223,7 @@ TEST_F(BuiltinsPromiseTest, Resolve1) ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = BuiltinsPromise::Resolve(ecma_runtime_call_info1.get()); + JSTaggedValue result = promise::Resolve(ecma_runtime_call_info1.get()); JSHandle reject_promise(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), @@ -257,7 +255,7 @@ TEST_F(BuiltinsPromiseTest, Resolve2) ecma_runtime_call_info->SetCallArg(0, param_msg1.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecma_runtime_call_info.get()); + JSTaggedValue result = promise::Reject(ecma_runtime_call_info.get()); JSHandle promise1(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -274,7 +272,7 @@ TEST_F(BuiltinsPromiseTest, Resolve2) ecma_runtime_call_info1->SetCallArg(0, promise1.GetTaggedValue()); [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsPromise::Resolve(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Resolve(ecma_runtime_call_info1.get()); JSHandle promise2(thread, result1); EXPECT_EQ(*promise1, *promise2); EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseState(), @@ -305,7 +303,7 @@ TEST_F(BuiltinsPromiseTest, Race1) ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsPromise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Reject(ecma_runtime_call_info1.get()); JSHandle reject_promise(thread, result1); EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -321,7 +319,7 @@ TEST_F(BuiltinsPromiseTest, Race1) ecma_runtime_call_info2->SetCallArg(0, param_msg2.GetTaggedValue()); [[maybe_unused]] auto prev_resolve = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsPromise::Resolve(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = promise::Resolve(ecma_runtime_call_info2.get()); JSHandle resolve_promise(thread, result2); EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), @@ -347,7 +345,7 @@ TEST_F(BuiltinsPromiseTest, Race1) ecma_runtime_call_info4->SetCallArg(0, array.GetTaggedValue()); [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = BuiltinsPromise::Race(ecma_runtime_call_info4.get()); + JSTaggedValue result4 = promise::Race(ecma_runtime_call_info4.get()); JSHandle race_promise(thread, result4); EXPECT_EQ(JSTaggedValue::SameValue(race_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), @@ -379,7 +377,7 @@ TEST_F(BuiltinsPromiseTest, Race2) ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsPromise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Reject(ecma_runtime_call_info1.get()); JSHandle reject_promise(thread, result1); EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -395,7 +393,7 @@ TEST_F(BuiltinsPromiseTest, Race2) ecma_runtime_call_info2->SetCallArg(0, param_msg2.GetTaggedValue()); [[maybe_unused]] auto prev_resolve = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsPromise::Resolve(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = promise::Resolve(ecma_runtime_call_info2.get()); JSHandle resolve_promise(thread, result2); EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), @@ -421,7 +419,7 @@ TEST_F(BuiltinsPromiseTest, Race2) ecma_runtime_call_info4->SetCallArg(0, array.GetTaggedValue()); [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = BuiltinsPromise::Race(ecma_runtime_call_info4.get()); + JSTaggedValue result4 = promise::Race(ecma_runtime_call_info4.get()); JSHandle race_promise(thread, result4); EXPECT_EQ(JSTaggedValue::SameValue(race_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), @@ -440,7 +438,7 @@ TEST_F(BuiltinsPromiseTest, Race2) ecma_runtime_call_info5->SetCallArg(1, native_func_race_then_onrejected.GetTaggedValue()); [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread, ecma_runtime_call_info5.get()); - JSTaggedValue then_result = BuiltinsPromise::Then(ecma_runtime_call_info5.get()); + JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info5.get()); JSHandle then_promise(thread, then_result); EXPECT_TRUE(JSTaggedValue::SameValue(then_promise->GetPromiseState(), @@ -480,7 +478,7 @@ TEST_F(BuiltinsPromiseTest, All) ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsPromise::Resolve(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = promise::Resolve(ecma_runtime_call_info1.get()); JSHandle resolve_promise1(thread, result1); EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise1->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), @@ -496,7 +494,7 @@ TEST_F(BuiltinsPromiseTest, All) ecma_runtime_call_info2->SetCallArg(0, param_msg2.GetTaggedValue()); [[maybe_unused]] auto prev_resolve = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsPromise::Resolve(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = promise::Resolve(ecma_runtime_call_info2.get()); JSHandle resolve_promise2(thread, result2); EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise2->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), @@ -522,7 +520,7 @@ TEST_F(BuiltinsPromiseTest, All) ecma_runtime_call_info4->SetCallArg(0, array.GetTaggedValue()); [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = BuiltinsPromise::All(ecma_runtime_call_info4.get()); + JSTaggedValue result4 = promise::All(ecma_runtime_call_info4.get()); JSHandle all_promise(thread, result4); EXPECT_EQ(JSTaggedValue::SameValue(all_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING))), @@ -541,7 +539,7 @@ TEST_F(BuiltinsPromiseTest, All) ecma_runtime_call_info5->SetCallArg(1, native_func_race_then_on_resolved.GetTaggedValue()); [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread, ecma_runtime_call_info5.get()); - JSTaggedValue then_result = BuiltinsPromise::Then(ecma_runtime_call_info5.get()); + JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info5.get()); JSHandle then_promise(thread, then_result); EXPECT_TRUE(JSTaggedValue::SameValue(then_promise->GetPromiseState(), @@ -579,7 +577,7 @@ TEST_F(BuiltinsPromiseTest, Catch) ecma_runtime_call_info1->SetCallArg(0, param_msg1.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result = promise::Reject(ecma_runtime_call_info1.get()); JSHandle reject_promise(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -596,7 +594,7 @@ TEST_F(BuiltinsPromiseTest, Catch) ecma_runtime_call_info2->SetCallArg(0, test_promise_catch.GetTaggedValue()); [[maybe_unused]] auto prev_catch = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue catch_result = BuiltinsPromise::Catch(ecma_runtime_call_info2.get()); + JSTaggedValue catch_result = promise::proto::Catch(ecma_runtime_call_info2.get()); JSHandle catch_promise(thread, catch_result); EXPECT_EQ(JSTaggedValue::SameValue(catch_promise->GetPromiseState(), @@ -635,7 +633,7 @@ TEST_F(BuiltinsPromiseTest, ThenResolve) ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = BuiltinsPromise::Resolve(ecma_runtime_call_info1.get()); + JSTaggedValue result = promise::Resolve(ecma_runtime_call_info1.get()); JSHandle resolve_promise(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(resolve_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED))), @@ -654,7 +652,7 @@ TEST_F(BuiltinsPromiseTest, ThenResolve) ecma_runtime_call_info2->SetCallArg(1, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev_then = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue then_result = BuiltinsPromise::Then(ecma_runtime_call_info2.get()); + JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info2.get()); JSHandle then_promise(thread, then_result); EXPECT_EQ(JSTaggedValue::SameValue(then_promise->GetPromiseState(), @@ -693,7 +691,7 @@ TEST_F(BuiltinsPromiseTest, ThenReject) ecma_runtime_call_info1->SetCallArg(0, param_msg.GetTaggedValue()); [[maybe_unused]] auto prev_reject = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecma_runtime_call_info1.get()); + JSTaggedValue result = promise::Reject(ecma_runtime_call_info1.get()); JSHandle reject_promise(thread, result); EXPECT_EQ(JSTaggedValue::SameValue(reject_promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED))), @@ -712,7 +710,7 @@ TEST_F(BuiltinsPromiseTest, ThenReject) ecma_runtime_call_info2->SetCallArg(1, test_promise_then_on_rejected.GetTaggedValue()); [[maybe_unused]] auto prev_then = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue then_result = BuiltinsPromise::Then(ecma_runtime_call_info2.get()); + JSTaggedValue then_result = promise::proto::Then(ecma_runtime_call_info2.get()); JSHandle then_promise(thread, then_result); EXPECT_EQ(JSTaggedValue::SameValue(then_promise->GetPromiseState(), diff --git a/tests/runtime/builtins/builtins_proxy_test.cpp b/tests/runtime/builtins/builtins_proxy_test.cpp index 21ec23aae5753a7ac1341a887c95b486e9eb1428..ce112cc162f00ee0e2b40e2ae5005cc585ecf56c 100644 --- a/tests/runtime/builtins/builtins_proxy_test.cpp +++ b/tests/runtime/builtins/builtins_proxy_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_proxy.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -82,7 +82,7 @@ TEST_F(BuiltinsProxyTest, ProxyConstructor) ecma_runtime_call_info->SetCallArg(1, handler.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsProxy::ProxyConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = proxy::ProxyConstructor(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle result_handle(thread, result); EXPECT_TRUE(result_handle->IsJSProxy()); @@ -109,7 +109,7 @@ TEST_F(BuiltinsProxyTest, Revocable) ecma_runtime_call_info->SetNewTarget(JSTaggedValue(*proxy_fun)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsProxy::Revocable(ecma_runtime_call_info.get()); + JSTaggedValue result = proxy::Revocable(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle result_handle(thread, result); diff --git a/tests/runtime/builtins/builtins_reflect_test.cpp b/tests/runtime/builtins/builtins_reflect_test.cpp index 0da059ef04e9ba941b9720e4ad537a1830e57db9..0a0c80e7c4ad8d2975aa1a793f9402c72173b129 100644 --- a/tests/runtime/builtins/builtins_reflect_test.cpp +++ b/tests/runtime/builtins/builtins_reflect_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_reflect.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -29,7 +29,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; -using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; using JSArray = panda::ecmascript::JSArray; namespace panda::test { @@ -76,9 +75,9 @@ JSTaggedValue TestReflectApply(EcmaRuntimeCallInfo *argv) int result = 0; for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { - result += BuiltinsBase::GetCallArg(argv, index).GetTaggedValue().GetInt(); + result += builtins_common::GetCallArg(argv, index).GetTaggedValue().GetInt(); } - JSHandle this_value = BuiltinsBase::GetThis(argv); + JSHandle this_value = builtins_common::GetThis(argv); JSTaggedValue test_a = JSObject::GetProperty(thread, this_value, @@ -92,7 +91,7 @@ JSTaggedValue TestReflectApply(EcmaRuntimeCallInfo *argv) .GetTaggedValue(); result = result + test_a.GetInt() + test_b.GetInt(); - return BuiltinsBase::GetTaggedInt(result); + return builtins_common::GetTaggedInt(result); } // Reflect.apply (target, thisArgument, argumentsList) @@ -129,7 +128,7 @@ TEST_F(BuiltinsReflectTest, ReflectApply) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(*arguments_list)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectApply(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::Apply(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(110).GetRawData()); JSObject::DeleteProperty(thread, (this_argument), @@ -160,7 +159,7 @@ TEST_F(BuiltinsReflectTest, ReflectConstruct) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(*arguments_list)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectConstruct(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::Construct(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle tagged_result(thread, result); @@ -208,7 +207,7 @@ TEST_F(BuiltinsReflectTest, ReflectDefineProperty) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(*attributes)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectDefineProperty(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::DefineProperty(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); PropertyDescriptor desc_ruler(thread); @@ -242,7 +241,7 @@ TEST_F(BuiltinsReflectTest, ReflectDeleteProperty) ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectDeleteProperty(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::DeleteProperty(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(JSObject::GetOwnProperty(thread, target, key, desc), false); } @@ -268,7 +267,7 @@ TEST_F(BuiltinsReflectTest, ReflectGet) ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectGet(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::Get(ecma_runtime_call_info.get()); JSHandle result_value(thread, result); ASSERT_EQ(result_value->GetDouble(), 101.5); @@ -294,7 +293,7 @@ TEST_F(BuiltinsReflectTest, ReflectGetOwnPropertyDescriptor) ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectGetOwnPropertyDescriptor(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::GetOwnPropertyDescriptor(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); @@ -337,7 +336,7 @@ TEST_F(BuiltinsReflectTest, ReflectGetPrototypeOf) ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectGetPrototypeOf(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::GetPrototypeOf(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle result_obj(thread, JSTaggedValue(reinterpret_cast(result.GetRawData()))); ASSERT_EQ(JSTaggedValue::SameValue(result_obj.GetTaggedValue(), proto.GetTaggedValue()), true); @@ -363,7 +362,7 @@ TEST_F(BuiltinsReflectTest, ReflectHas) ecma_runtime_call_info->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectHas(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::Has(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -384,7 +383,7 @@ TEST_F(BuiltinsReflectTest, ReflectIsExtensible) ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectIsExtensible(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::IsExtensible(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -410,7 +409,7 @@ TEST_F(BuiltinsReflectTest, ReflectOwnKeys) ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectOwnKeys(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::OwnKeys(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle result_tagged_value(thread, reinterpret_cast(result.GetRawData())); @@ -452,7 +451,7 @@ TEST_F(BuiltinsReflectTest, ReflectPreventExtensions) ecma_runtime_call_info->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectPreventExtensions(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::PreventExtensions(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(target->IsExtensible(), false); @@ -479,7 +478,7 @@ TEST_F(BuiltinsReflectTest, ReflectSet) ecma_runtime_call_info->SetCallArg(2, value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectSet(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::Set(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -504,7 +503,7 @@ TEST_F(BuiltinsReflectTest, ReflectSetPrototypeOf) ecma_runtime_call_info->SetCallArg(1, proto.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsReflect::ReflectSetPrototypeOf(ecma_runtime_call_info.get()); + JSTaggedValue result = reflect::SetPrototypeOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle result_obj(thread, target->GetJSHClass()->GetPrototype()); diff --git a/tests/runtime/builtins/builtins_regexp_test.cpp b/tests/runtime/builtins/builtins_regexp_test.cpp index b70cd9ee2a0009b4b1c866299000a3fa86d9ffb4..8558f56aec7e8056d116f4062ee0f2e4f9db5593 100644 --- a/tests/runtime/builtins/builtins_regexp_test.cpp +++ b/tests/runtime/builtins/builtins_regexp_test.cpp @@ -78,7 +78,7 @@ JSTaggedValue CreateBuiltinsRegExpObjByPatternAndFlags(JSThread *thread, const J [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke RegExpConstructor method - JSTaggedValue result = BuiltinsRegExp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); return result; } @@ -96,7 +96,7 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor1) JSHandle js_regexp(thread, JSRegExp::Cast(regexp_object->GetTaggedObject())); JSHandle original_source(thread, js_regexp->GetOriginalSource()); uint8_t flags_bits = static_cast(js_regexp->GetOriginalFlags().GetInt()); - JSHandle original_flags(thread, BuiltinsRegExp::FlagsBitsToString(thread, flags_bits)); + JSHandle original_flags(thread, reg_exp::FlagsBitsToString(thread, flags_bits)); ASSERT_EQ(static_cast(original_source->GetTaggedObject())->Compare(*pattern), 0); ASSERT_EQ(static_cast(original_flags->GetTaggedObject())->Compare(*flags), 0); } @@ -121,7 +121,7 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor2) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke RegExpConstructor method - JSTaggedValue result2 = BuiltinsRegExp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result2 = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); // ASSERT IsRegExp() @@ -131,7 +131,7 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor2) JSHandle js_regexp(thread, JSRegExp::Cast(regexp_object->GetTaggedObject())); JSHandle original_source(thread, js_regexp->GetOriginalSource()); uint8_t flags_bits = static_cast(js_regexp->GetOriginalFlags().GetInt()); - JSHandle original_flags(thread, BuiltinsRegExp::FlagsBitsToString(thread, flags_bits)); + JSHandle original_flags(thread, reg_exp::FlagsBitsToString(thread, flags_bits)); ASSERT_EQ(static_cast(original_source->GetTaggedObject())->Compare(*pattern), 0); ASSERT_EQ(static_cast(original_flags->GetTaggedObject())->Compare(*flags), 0); } @@ -157,7 +157,7 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor3) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke RegExpConstructor method - JSTaggedValue result2 = BuiltinsRegExp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result2 = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); // ASSERT IsRegExp() JSHandle regexp_object(thread, result2); @@ -166,7 +166,7 @@ TEST_F(BuiltinsRegExpTest, RegExpConstructor3) JSHandle js_regexp(thread, JSRegExp::Cast(regexp_object->GetTaggedObject())); JSHandle original_source(thread, js_regexp->GetOriginalSource()); uint8_t flags_bits = static_cast(js_regexp->GetOriginalFlags().GetInt()); - JSHandle original_flags(thread, BuiltinsRegExp::FlagsBitsToString(thread, flags_bits)); + JSHandle original_flags(thread, reg_exp::FlagsBitsToString(thread, flags_bits)); ASSERT_EQ(static_cast(original_source->GetTaggedObject())->Compare(*pattern1), 0); ASSERT_EQ(static_cast(original_flags->GetTaggedObject())->Compare(*flags2), 0); } @@ -268,7 +268,7 @@ TEST_F(BuiltinsRegExpTest, toString) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke ToString method - JSTaggedValue to_string_result = BuiltinsRegExp::ToString(ecma_runtime_call_info.get()); + JSTaggedValue to_string_result = reg_exp::proto::ToString(ecma_runtime_call_info.get()); ASSERT_TRUE(to_string_result.IsString()); JSHandle to_string_result_handle(thread, to_string_result); JSHandle expect_result = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("/\\w+/gimuy"); @@ -293,7 +293,7 @@ TEST_F(BuiltinsRegExpTest, Exec1) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Exec method - JSTaggedValue results = BuiltinsRegExp::Exec(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Exec(ecma_runtime_call_info.get()); JSHandle exec_result(thread, results); JSHandle result_zero = @@ -352,7 +352,7 @@ TEST_F(BuiltinsRegExpTest, Exec2) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Exec method - JSTaggedValue results = BuiltinsRegExp::Exec(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Exec(ecma_runtime_call_info.get()); JSHandle exec_result(thread, results); JSHandle result_zero = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("123"); @@ -430,7 +430,7 @@ TEST_F(BuiltinsRegExpTest, Match1) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Match method - JSTaggedValue match_results = BuiltinsRegExp::Match(ecma_runtime_call_info.get()); + JSTaggedValue match_results = reg_exp::proto::Match(ecma_runtime_call_info.get()); JSHandle match_result(thread, match_results); JSHandle zero(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); @@ -459,7 +459,7 @@ TEST_F(BuiltinsRegExpTest, Test1) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Test method - JSTaggedValue test_result = BuiltinsRegExp::Test(ecma_runtime_call_info.get()); + JSTaggedValue test_result = reg_exp::proto::Test(ecma_runtime_call_info.get()); ASSERT_EQ(test_result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -481,7 +481,7 @@ TEST_F(BuiltinsRegExpTest, Search1) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Search method - JSTaggedValue search_result = BuiltinsRegExp::Search(ecma_runtime_call_info.get()); + JSTaggedValue search_result = reg_exp::proto::Search(ecma_runtime_call_info.get()); ASSERT_EQ(search_result.GetRawData(), JSTaggedValue(4).GetRawData()); } @@ -503,7 +503,7 @@ TEST_F(BuiltinsRegExpTest, Split1) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Split method - JSTaggedValue split_results = BuiltinsRegExp::Split(ecma_runtime_call_info.get()); + JSTaggedValue split_results = reg_exp::proto::Split(ecma_runtime_call_info.get()); JSHandle split_result(thread, split_results); JSHandle zero(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("0")); @@ -531,7 +531,7 @@ TEST_F(BuiltinsRegExpTest, Split2) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke Split method - JSTaggedValue split_results = BuiltinsRegExp::Split(ecma_runtime_call_info.get()); + JSTaggedValue split_results = reg_exp::proto::Split(ecma_runtime_call_info.get()); JSHandle split_result(thread, split_results); JSHandle result_zero = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("a"); JSHandle result_one = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("b"); @@ -588,7 +588,7 @@ TEST_F(BuiltinsRegExpTest, Replace1) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke replace method - JSTaggedValue results = BuiltinsRegExp::Replace(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Replace(ecma_runtime_call_info.get()); JSHandle replace_result(thread, results); JSHandle result_zero = thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString( "The Quick Brown Fox Jumpsa The Over The Lazy Dog Jumps Brown $1 Jumps1 $32 a Over The Lazy Dog"); @@ -614,7 +614,7 @@ TEST_F(BuiltinsRegExpTest, Replace2) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke replace method - JSTaggedValue results = BuiltinsRegExp::Replace(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Replace(ecma_runtime_call_info.get()); JSHandle replace_result(thread, results); JSHandle result_zero = factory->NewFromCanBeCompressString("a[cd$04$00]e"); ASSERT_EQ(static_cast(replace_result->GetTaggedObject())->Compare(*result_zero), 0); @@ -639,7 +639,7 @@ TEST_F(BuiltinsRegExpTest, Replace3) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // invoke replace method - JSTaggedValue results = BuiltinsRegExp::Replace(ecma_runtime_call_info.get()); + JSTaggedValue results = reg_exp::proto::Replace(ecma_runtime_call_info.get()); JSHandle replace_result(thread, results); JSHandle result_zero = factory->NewFromCanBeCompressString("de"); ASSERT_EQ(static_cast(replace_result->GetTaggedObject())->Compare(*result_zero), 0); diff --git a/tests/runtime/builtins/builtins_set_test.cpp b/tests/runtime/builtins/builtins_set_test.cpp index 72a2dda2c7bc152116aca249c7d1c3e9ace4e2f7..843b9b17b8655f0f75296d31f37211b30a938a31 100644 --- a/tests/runtime/builtins/builtins_set_test.cpp +++ b/tests/runtime/builtins/builtins_set_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_set.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -34,7 +34,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using BuiltinsSet = ecmascript::builtins::BuiltinsSet; using JSSet = ecmascript::JSSet; class BuiltinsSetTest : public testing::Test { @@ -63,15 +62,15 @@ public: EcmaHandleScope *scope {nullptr}; JSThread *thread {nullptr}; - class TestClass : public base::BuiltinsBase { + class TestClass { public: static JSTaggedValue TestFunc(EcmaRuntimeCallInfo *argv) { - JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); + JSTaggedValue key = builtins_common::GetCallArg(argv, 0).GetTaggedValue(); if (key.IsUndefined()) { return JSTaggedValue::Undefined(); } - JSArray *js_array = JSArray::Cast(GetThis(argv)->GetTaggedObject()); + JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); int length = js_array->GetArrayLength() + 1; js_array->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); @@ -82,14 +81,14 @@ public: JSSet *CreateBuiltinsSet(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsSetFunction()); + JSHandle new_target(env->GetSetFunction()); // 4 : test case auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*new_target), 4); ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSet::SetConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = set::SetConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); return JSSet::Cast(reinterpret_cast(result.GetRawData())); @@ -99,7 +98,7 @@ TEST_F(BuiltinsSetTest, CreateAndGetSize) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsSetFunction()); + JSHandle new_target(env->GetSetFunction()); JSHandle set(thread, CreateBuiltinsSet(thread)); auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -108,7 +107,7 @@ TEST_F(BuiltinsSetTest, CreateAndGetSize) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSet::GetSize(ecma_runtime_call_info.get()); + JSTaggedValue result = set::proto::GetSize(ecma_runtime_call_info.get()); EXPECT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -126,7 +125,7 @@ TEST_F(BuiltinsSetTest, CreateAndGetSize) ecma_runtime_call_info1->SetNewTarget(new_target.GetTaggedValue()); { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsSet::SetConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = set::SetConstructor(ecma_runtime_call_info1.get()); EXPECT_EQ(JSSet::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); } @@ -145,12 +144,12 @@ TEST_F(BuiltinsSetTest, AddAndHas) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsSet::Has(ecma_runtime_call_info.get()); + JSTaggedValue result1 = set::proto::Has(ecma_runtime_call_info.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Add() - JSTaggedValue result2 = BuiltinsSet::Add(ecma_runtime_call_info.get()); + JSTaggedValue result2 = set::proto::Add(ecma_runtime_call_info.get()); EXPECT_TRUE(result2.IsECMAObject()); JSSet *js_set = JSSet::Cast(reinterpret_cast(result2.GetRawData())); EXPECT_EQ(js_set->GetSize(), 1); @@ -162,7 +161,7 @@ TEST_F(BuiltinsSetTest, AddAndHas) ecma_runtime_call_info1->SetCallArg(0, key.GetTaggedValue()); { [[maybe_unused]] auto prev_local = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = BuiltinsSet::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = set::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -176,7 +175,7 @@ TEST_F(BuiltinsSetTest, AddAndHas) ecma_runtime_call_info2->SetCallArg(0, negative_zero.GetTaggedValue()); { [[maybe_unused]] auto prev_local = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - BuiltinsSet::Add(ecma_runtime_call_info.get()); + set::proto::Add(ecma_runtime_call_info.get()); } auto ecma_runtime_call_info3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -185,7 +184,7 @@ TEST_F(BuiltinsSetTest, AddAndHas) ecma_runtime_call_info3->SetCallArg(0, positive_zero.GetTaggedValue()); { [[maybe_unused]] auto prev_local = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - JSTaggedValue result4 = BuiltinsSet::Has(ecma_runtime_call_info3.get()); + JSTaggedValue result4 = set::proto::Has(ecma_runtime_call_info3.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -206,7 +205,7 @@ TEST_F(BuiltinsSetTest, ForEach) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsSet::Add(ecma_runtime_call_info.get()); + JSTaggedValue result1 = set::proto::Add(ecma_runtime_call_info.get()); EXPECT_TRUE(result1.IsECMAObject()); JSSet *js_set = JSSet::Cast(reinterpret_cast(result1.GetRawData())); @@ -224,7 +223,7 @@ TEST_F(BuiltinsSetTest, ForEach) ecma_runtime_call_info1->SetCallArg(1, js_array.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsSet::ForEach(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = set::proto::ForEach(ecma_runtime_call_info1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(js_array->GetArrayLength(), 5); @@ -248,7 +247,7 @@ TEST_F(BuiltinsSetTest, DeleteAndRemove) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsSet::Add(ecma_runtime_call_info.get()); + JSTaggedValue result1 = set::proto::Add(ecma_runtime_call_info.get()); EXPECT_TRUE(result1.IsECMAObject()); JSSet *js_set = JSSet::Cast(reinterpret_cast(result1.GetRawData())); @@ -264,26 +263,26 @@ TEST_F(BuiltinsSetTest, DeleteAndRemove) ecma_runtime_call_info1->SetCallArg(0, delete_key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsSet::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = set::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsSet::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = set::proto::Delete(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsSet::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = set::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); - JSTaggedValue result5 = BuiltinsSet::GetSize(ecma_runtime_call_info1.get()); + JSTaggedValue result5 = set::proto::GetSize(ecma_runtime_call_info1.get()); EXPECT_EQ(result5.GetRawData(), JSTaggedValue(39).GetRawData()); // clear - JSTaggedValue result6 = BuiltinsSet::Clear(ecma_runtime_call_info1.get()); + JSTaggedValue result6 = set::proto::Clear(ecma_runtime_call_info1.get()); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(set->GetSize(), 0); } @@ -296,7 +295,7 @@ TEST_F(BuiltinsSetTest, Species) JSHandle species_symbol = env->GetSpeciesSymbol(); EXPECT_TRUE(!species_symbol->IsUndefined()); - JSHandle new_target(env->GetBuiltinsSetFunction()); + JSHandle new_target(env->GetSetFunction()); JSTaggedValue value = JSObject::GetProperty(thread, JSHandle(new_target), species_symbol).GetValue().GetTaggedValue(); @@ -348,14 +347,14 @@ TEST_F(BuiltinsSetTest, GetIterator) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); // test Values() - JSTaggedValue result = BuiltinsSet::Values(ecma_runtime_call_info.get()); + JSTaggedValue result = set::proto::Values(ecma_runtime_call_info.get()); JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSSetIterator()); EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind().GetInt())); EXPECT_EQ(JSSet::Cast(set.GetTaggedValue().GetTaggedObject())->GetLinkedSet(), iter->GetIteratedSet()); // test entrys() - JSTaggedValue result2 = BuiltinsSet::Entries(ecma_runtime_call_info.get()); + JSTaggedValue result2 = set::proto::Entries(ecma_runtime_call_info.get()); JSHandle iter2(thread, result2); EXPECT_TRUE(iter2->IsJSSetIterator()); EXPECT_EQ(IterationKind::KEY_AND_VALUE, IterationKind(iter2->GetIterationKind().GetInt())); diff --git a/tests/runtime/builtins/builtins_string_test.cpp b/tests/runtime/builtins/builtins_string_test.cpp index 618d7b527f742287a4616fcb1d04f4b6319d09d1..3492a62b4e0d6b4f1cbf428159a82cb62ee39372 100644 --- a/tests/runtime/builtins/builtins_string_test.cpp +++ b/tests/runtime/builtins/builtins_string_test.cpp @@ -15,7 +15,6 @@ #include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/builtins/builtins_regexp.h" -#include "plugins/ecmascript/runtime/builtins/builtins_string.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -74,7 +73,7 @@ JSTaggedValue CreateRegExpObjByPatternAndFlags(JSThread *thread, const JSHandle< ecma_runtime_call_info->SetCallArg(1, flags.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsRegExp::RegExpConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = reg_exp::RegExpConstructor(ecma_runtime_call_info.get()); return result; } @@ -93,7 +92,7 @@ TEST_F(BuiltinsStringTest, StringConstructor1) ecma_runtime_call_info->SetCallArg(0, string2.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::StringConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = string::StringConstructor(ecma_runtime_call_info.get()); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle ref(thread, JSPrimitiveRef::Cast(value.GetTaggedObject())); @@ -119,7 +118,7 @@ TEST_F(BuiltinsStringTest, fromCharCode1) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(arg3)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::FromCharCode(ecma_runtime_call_info.get()); + JSTaggedValue result = string::FromCharCode(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSTaggedValue value(static_cast(result.GetRawData())); JSHandle value_handle(thread, JSTaggedValue(value.GetTaggedObject())); @@ -145,7 +144,7 @@ TEST_F(BuiltinsStringTest, fromCodePoint1) ecma_runtime_call_info->SetCallArg(2, JSTaggedValue(arg3)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::FromCodePoint(ecma_runtime_call_info.get()); + JSTaggedValue result = string::FromCodePoint(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("ABC").GetTaggedValue(); @@ -164,7 +163,7 @@ TEST_F(BuiltinsStringTest, charAt1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::CharAt(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::CharAt(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("c").GetTaggedValue(); @@ -183,7 +182,7 @@ TEST_F(BuiltinsStringTest, charAt2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::CharAt(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::CharAt(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("三").GetTaggedValue(); @@ -202,7 +201,7 @@ TEST_F(BuiltinsStringTest, charAt3) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::CharAt(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::CharAt(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->GetEmptyString().GetTaggedValue(); @@ -221,7 +220,7 @@ TEST_F(BuiltinsStringTest, charCodeAt1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::CharCodeAt(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::CharCodeAt(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(65).GetRawData()); } @@ -238,9 +237,9 @@ TEST_F(BuiltinsStringTest, charCodeAt2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(-1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::CharCodeAt(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::CharCodeAt(ecma_runtime_call_info.get()); - JSTaggedValue test = BuiltinsString::GetTaggedDouble(base::NAN_VALUE); + JSTaggedValue test = builtins_common::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), test.GetRawData()); } @@ -256,7 +255,7 @@ TEST_F(BuiltinsStringTest, codePointAt1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::CodePointAt(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::CodePointAt(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(66).GetRawData()); } @@ -278,7 +277,7 @@ TEST_F(BuiltinsStringTest, concat1) ecma_runtime_call_info->SetCallArg(2, val3.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Concat(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Concat(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("abcd").GetTaggedValue(); @@ -298,7 +297,7 @@ TEST_F(BuiltinsStringTest, indexof1) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::IndexOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::IndexOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -317,7 +316,7 @@ TEST_F(BuiltinsStringTest, indexof2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::IndexOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::IndexOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(4).GetRawData()); } @@ -335,7 +334,7 @@ TEST_F(BuiltinsStringTest, indexof3) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::IndexOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::IndexOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -353,7 +352,7 @@ TEST_F(BuiltinsStringTest, lastIndexOf1) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::LastIndexOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::LastIndexOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(7).GetRawData()); } @@ -371,7 +370,7 @@ TEST_F(BuiltinsStringTest, lastIndexOf2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::LastIndexOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::LastIndexOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -389,7 +388,7 @@ TEST_F(BuiltinsStringTest, lastIndexOf3) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::LastIndexOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::LastIndexOf(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -407,7 +406,7 @@ TEST_F(BuiltinsStringTest, Includes2) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Includes(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -426,7 +425,7 @@ TEST_F(BuiltinsStringTest, Includes3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Includes(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -444,7 +443,7 @@ TEST_F(BuiltinsStringTest, Includes4) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Includes(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -462,7 +461,7 @@ TEST_F(BuiltinsStringTest, startsWith1) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::StartsWith(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::StartsWith(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -480,7 +479,7 @@ TEST_F(BuiltinsStringTest, startsWith2) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::StartsWith(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::StartsWith(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -499,7 +498,7 @@ TEST_F(BuiltinsStringTest, startsWith3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::StartsWith(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::StartsWith(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -517,7 +516,7 @@ TEST_F(BuiltinsStringTest, endsWith1) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::EndsWith(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::EndsWith(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -535,7 +534,7 @@ TEST_F(BuiltinsStringTest, endsWith2) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::EndsWith(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::EndsWith(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -554,7 +553,7 @@ TEST_F(BuiltinsStringTest, endsWith3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(19))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::EndsWith(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::EndsWith(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -571,7 +570,7 @@ TEST_F(BuiltinsStringTest, toLocaleLowerCase2) ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ToLocaleLowerCase(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ToLocaleLowerCase(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("有abc").GetTaggedValue(); @@ -589,7 +588,7 @@ TEST_F(BuiltinsStringTest, toLowerCase1) ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ToLowerCase(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ToLowerCase(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSHandle test = factory->NewFromCanBeCompressString("abc"); @@ -607,7 +606,7 @@ TEST_F(BuiltinsStringTest, toUpperCase1) ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ToUpperCase(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ToUpperCase(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("ABC").GetTaggedValue(); @@ -627,7 +626,7 @@ TEST_F(BuiltinsStringTest, localecompare1) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::LocaleCompare(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::LocaleCompare(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -645,7 +644,7 @@ TEST_F(BuiltinsStringTest, localecompare2) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::LocaleCompare(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::LocaleCompare(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -663,7 +662,7 @@ TEST_F(BuiltinsStringTest, localecompare3) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::LocaleCompare(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::LocaleCompare(ecma_runtime_call_info.get()); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -682,7 +681,7 @@ TEST_F(BuiltinsStringTest, normalize1) ecma_runtime_call_info->SetCallArg(0, val.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Normalize(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Normalize(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("abc").GetTaggedValue(); @@ -703,7 +702,7 @@ TEST_F(BuiltinsStringTest, padEnd1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::PadEnd(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::PadEnd(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("hello ").GetTaggedValue(); @@ -726,7 +725,7 @@ TEST_F(BuiltinsStringTest, padEnd2) ecma_runtime_call_info->SetCallArg(1, fill_string.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::PadEnd(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::PadEnd(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("helloworldw").GetTaggedValue(); @@ -747,7 +746,7 @@ TEST_F(BuiltinsStringTest, padStart1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(10))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::PadStart(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::PadStart(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString(" world").GetTaggedValue(); @@ -770,7 +769,7 @@ TEST_F(BuiltinsStringTest, padStart2) ecma_runtime_call_info->SetCallArg(1, fill_string.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::PadStart(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::PadStart(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("hellohworld").GetTaggedValue(); @@ -789,7 +788,7 @@ TEST_F(BuiltinsStringTest, repeat1) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Repeat(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Repeat(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("abcabcabcabcabc").GetTaggedValue(); @@ -809,7 +808,7 @@ TEST_F(BuiltinsStringTest, slice1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-2))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Slice(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Slice(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("morning is upon u").GetTaggedValue(); @@ -828,7 +827,7 @@ TEST_F(BuiltinsStringTest, slice2) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(12))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Slice(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Slice(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("is upon us.").GetTaggedValue(); @@ -848,7 +847,7 @@ TEST_F(BuiltinsStringTest, substring1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(-3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Substring(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Substring(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("Moz").GetTaggedValue(); @@ -868,7 +867,7 @@ TEST_F(BuiltinsStringTest, substring2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(4))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Substring(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Substring(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("lla").GetTaggedValue(); @@ -886,7 +885,7 @@ TEST_F(BuiltinsStringTest, trim1) ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Trim(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Trim(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("Hello world!").GetTaggedValue(); @@ -909,7 +908,7 @@ TEST_F(BuiltinsStringTest, trim2) ecma_runtime_call_info->SetThis(str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Trim(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Trim(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromCanBeCompressString("Hello world!").GetTaggedValue(); @@ -929,7 +928,7 @@ TEST_F(BuiltinsStringTest, trimEnd1) ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::TrimEnd(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::TrimEnd(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString(" Hello world!").GetTaggedValue(); @@ -954,7 +953,7 @@ TEST_F(BuiltinsStringTest, trimEnd2) ecma_runtime_call_info->SetThis(str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::TrimEnd(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::TrimEnd(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString(" Hello world!").GetTaggedValue(); @@ -974,7 +973,7 @@ TEST_F(BuiltinsStringTest, trimStart1) ecma_runtime_call_info->SetThis(this_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::TrimStart(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::TrimStart(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("Hello world! ").GetTaggedValue(); @@ -999,7 +998,7 @@ TEST_F(BuiltinsStringTest, trimStart2) ecma_runtime_call_info->SetThis(str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::TrimStart(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::TrimStart(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromString("Hello world! ").GetTaggedValue(); @@ -1023,7 +1022,7 @@ TEST_F(BuiltinsStringTest, ToString) ecma_runtime_call_info->SetThis(str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ToString(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = JSTaggedValue(*this_str); @@ -1046,7 +1045,7 @@ TEST_F(BuiltinsStringTest, ValueOf) ecma_runtime_call_info->SetThis(str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ValueOf(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = JSTaggedValue(*this_str); @@ -1095,7 +1094,7 @@ TEST_F(BuiltinsStringTest, Raw) ecma_runtime_call_info->SetCallArg(2, javascript.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Raw(ecma_runtime_call_info.get()); + JSTaggedValue result = string::Raw(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *test)); } @@ -1115,7 +1114,7 @@ TEST_F(BuiltinsStringTest, Replace) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Replace(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -1131,7 +1130,7 @@ TEST_F(BuiltinsStringTest, Replace) ecma_runtime_call_info1->SetCallArg(1, replace_str1.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result1 = BuiltinsString::Replace(ecma_runtime_call_info1.get()); + JSTaggedValue result1 = string::proto::Replace(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string1(thread, result1); @@ -1148,7 +1147,7 @@ TEST_F(BuiltinsStringTest, Replace) ecma_runtime_call_info2->SetCallArg(1, replace_str2.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsString::Replace(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = string::proto::Replace(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string2(thread, result2); @@ -1165,7 +1164,7 @@ TEST_F(BuiltinsStringTest, Replace) ecma_runtime_call_info3->SetCallArg(1, replace_str3.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - JSTaggedValue result3 = BuiltinsString::Replace(ecma_runtime_call_info3.get()); + JSTaggedValue result3 = string::proto::Replace(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string3(thread, result3); @@ -1183,7 +1182,7 @@ TEST_F(BuiltinsStringTest, Replace) ecma_runtime_call_info4->SetCallArg(1, replace_str4.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = BuiltinsString::Replace(ecma_runtime_call_info4.get()); + JSTaggedValue result4 = string::proto::Replace(ecma_runtime_call_info4.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string4(thread, result4); @@ -1206,7 +1205,7 @@ TEST_F(BuiltinsStringTest, Replace2) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Replace(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -1223,7 +1222,7 @@ TEST_F(BuiltinsStringTest, Replace2) ecma_runtime_call_info2->SetCallArg(1, replace_str2.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue result2 = BuiltinsString::Replace(ecma_runtime_call_info2.get()); + JSTaggedValue result2 = string::proto::Replace(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string2(thread, result2); @@ -1241,7 +1240,7 @@ TEST_F(BuiltinsStringTest, Replace2) ecma_runtime_call_info3->SetCallArg(1, replace_str3.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info3.get()); - JSTaggedValue result3 = BuiltinsString::Replace(ecma_runtime_call_info3.get()); + JSTaggedValue result3 = string::proto::Replace(ecma_runtime_call_info3.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string3(thread, result3); @@ -1259,7 +1258,7 @@ TEST_F(BuiltinsStringTest, Replace2) ecma_runtime_call_info4->SetCallArg(1, replace_str4.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info4.get()); - JSTaggedValue result4 = BuiltinsString::Replace(ecma_runtime_call_info4.get()); + JSTaggedValue result4 = string::proto::Replace(ecma_runtime_call_info4.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result4.IsString()); @@ -1283,7 +1282,7 @@ TEST_F(BuiltinsStringTest, Replace3) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Replace(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1313,7 +1312,7 @@ TEST_F(BuiltinsStringTest, Replace4) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Replace(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Replace(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1335,7 +1334,7 @@ TEST_F(BuiltinsStringTest, ReplaceAll1) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ReplaceAll(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ReplaceAll(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1357,7 +1356,7 @@ TEST_F(BuiltinsStringTest, ReplaceAll2) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ReplaceAll(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ReplaceAll(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1379,7 +1378,7 @@ TEST_F(BuiltinsStringTest, ReplaceAll3) ecma_runtime_call_info->SetCallArg(1, replace_str.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::ReplaceAll(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::ReplaceAll(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1403,7 +1402,7 @@ TEST_F(BuiltinsStringTest, Split) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Split(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Split(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle result_array(thread, reinterpret_cast(result.GetRawData())); @@ -1442,7 +1441,7 @@ TEST_F(BuiltinsStringTest, Split2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsString::Split(ecma_runtime_call_info.get()); + JSTaggedValue result = string::proto::Split(ecma_runtime_call_info.get()); ASSERT_TRUE(result.IsECMAObject()); JSHandle result_array(thread, result); diff --git a/tests/runtime/builtins/builtins_symbol_test.cpp b/tests/runtime/builtins/builtins_symbol_test.cpp index 5b27c020ddb7807cb7d77fef5b00d90771798c5b..18b2c128dcc128c40fd315ca27642f14b081bf1d 100644 --- a/tests/runtime/builtins/builtins_symbol_test.cpp +++ b/tests/runtime/builtins/builtins_symbol_test.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_symbol.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -34,8 +34,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using Symbol = ecmascript::builtins::BuiltinsSymbol; -using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; class BuiltinsSymbolTest : public testing::Test { public: @@ -76,11 +74,11 @@ TEST_F(BuiltinsSymbolTest, SymbolNoParameterToString) ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Symbol::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); ASSERT_TRUE(result.IsString()); - auto symbol_value = ecmascript::base::BuiltinsBase::GetTaggedString(thread, "Symbol()"); + auto symbol_value = ecmascript::builtins_common::GetTaggedString(thread, "Symbol()"); ASSERT_EQ(reinterpret_cast(symbol_value.GetRawData())->Compare(*result_handle), 0); } @@ -96,11 +94,11 @@ TEST_F(BuiltinsSymbolTest, SymbolWithParameterToString) ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = Symbol::ToString(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::proto::ToString(ecma_runtime_call_info.get()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); ASSERT_TRUE(result.IsString()); - auto symbol_value = ecmascript::base::BuiltinsBase::GetTaggedString(thread, "Symbol(aaa)"); + auto symbol_value = ecmascript::builtins_common::GetTaggedString(thread, "Symbol(aaa)"); ASSERT_EQ(reinterpret_cast(symbol_value.GetRawData())->Compare(*result_handle), 0); } @@ -117,7 +115,7 @@ TEST_F(BuiltinsSymbolTest, SymbolNoParameterValueOf) ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::ValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::proto::ValueOf(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -131,7 +129,7 @@ TEST_F(BuiltinsSymbolTest, SymbolNoParameterValueOf) other_ecma_runtime_call_info->SetThis(symbol_ref.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, other_ecma_runtime_call_info.get()); - JSTaggedValue other_result = BuiltinsSymbol::ValueOf(other_ecma_runtime_call_info.get()); + JSTaggedValue other_result = symbol::proto::ValueOf(other_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(other_result.IsSymbol()); ASSERT_EQ(other_result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -150,7 +148,7 @@ TEST_F(BuiltinsSymbolTest, SymbolWithParameterValueOf) ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::ValueOf(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::proto::ValueOf(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -164,7 +162,7 @@ TEST_F(BuiltinsSymbolTest, SymbolWithParameterValueOf) other_ecma_runtime_call_info->SetThis(symbol_ref.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, other_ecma_runtime_call_info.get()); - JSTaggedValue other_result = BuiltinsSymbol::ValueOf(other_ecma_runtime_call_info.get()); + JSTaggedValue other_result = symbol::proto::ValueOf(other_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(other_result.IsSymbol()); ASSERT_EQ(other_result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -191,7 +189,7 @@ TEST_F(BuiltinsSymbolTest, SymbolWithParameterFor) ecma_runtime_call_info->SetCallArg(0, string.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::For(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::For(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(table_handle->ContainsKey(thread, string_handle.GetTaggedValue()), true); @@ -213,7 +211,7 @@ TEST_F(BuiltinsSymbolTest, SymbolKeyFor) ecma_runtime_call_info->SetCallArg(0, symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::KeyFor(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::KeyFor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -226,7 +224,7 @@ TEST_F(BuiltinsSymbolTest, SymbolKeyFor) ecma_runtime_call_info1->SetCallArg(0, string.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - BuiltinsSymbol::For(ecma_runtime_call_info1.get()); + symbol::For(ecma_runtime_call_info1.get()); TestHelper::TearDownFrame(thread, prev); JSHandle other_symbol = ecma_vm->GetFactory()->NewPublicSymbolWithChar("ccc"); @@ -236,7 +234,7 @@ TEST_F(BuiltinsSymbolTest, SymbolKeyFor) ecma_runtime_call_info2->SetCallArg(0, other_symbol.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info2.get()); - JSTaggedValue other_result = BuiltinsSymbol::KeyFor(ecma_runtime_call_info2.get()); + JSTaggedValue other_result = symbol::KeyFor(ecma_runtime_call_info2.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(other_result.IsString()); JSHandle table_handle(env->GetRegisterSymbols()); @@ -257,7 +255,7 @@ TEST_F(BuiltinsSymbolTest, SymbolToPrimitive) ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::ToPrimitive(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::proto::ToPrimitive(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -271,7 +269,7 @@ TEST_F(BuiltinsSymbolTest, SymbolToPrimitive) other_ecma_runtime_call_info->SetThis(symbol_ref.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, other_ecma_runtime_call_info.get()); - JSTaggedValue other_result = BuiltinsSymbol::ToPrimitive(other_ecma_runtime_call_info.get()); + JSTaggedValue other_result = symbol::proto::ToPrimitive(other_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(other_result.IsSymbol()); ASSERT_EQ(other_result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -288,7 +286,7 @@ TEST_F(BuiltinsSymbolTest, SymbolConstructor) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::SymbolConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::SymbolConstructor(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); JSSymbol *sym = reinterpret_cast(result.GetRawData()); @@ -302,7 +300,7 @@ TEST_F(BuiltinsSymbolTest, SymbolConstructor) other_ecma_runtime_call_info->SetCallArg(0, string.GetTaggedValue()); prev = TestHelper::SetupFrame(thread, other_ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsSymbol::SymbolConstructor(other_ecma_runtime_call_info.get()); + JSTaggedValue result1 = symbol::SymbolConstructor(other_ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); JSHandle result_string = JSTaggedValue::ToString( thread, JSHandle(thread, reinterpret_cast(result1.GetRawData())->GetDescription())); @@ -321,7 +319,7 @@ TEST_F(BuiltinsSymbolTest, SymbolGetter) ecma_runtime_call_info->SetThis(symbol.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsSymbol::DescriptionGetter(ecma_runtime_call_info.get()); + JSTaggedValue result = symbol::proto::GetDescription(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); EcmaString *res_string = reinterpret_cast(result.GetRawData()); diff --git a/tests/runtime/builtins/builtins_typedarray_test.cpp b/tests/runtime/builtins/builtins_typedarray_test.cpp index 4a52819415f533d46243b1ab84c30f8d54da6798..1df3b91c1883ddd57f4814a7caf0995c2a6c5ebb 100644 --- a/tests/runtime/builtins/builtins_typedarray_test.cpp +++ b/tests/runtime/builtins/builtins_typedarray_test.cpp @@ -16,9 +16,7 @@ #include "plugins/ecmascript/runtime/base/typed_array_helper-inl.h" #include "plugins/ecmascript/runtime/base/typed_array_helper.h" -#include "plugins/ecmascript/runtime/builtins/builtins_array.h" -#include "plugins/ecmascript/runtime/builtins/builtins_object.h" -#include "plugins/ecmascript/runtime/builtins/builtins_typedarray.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -43,9 +41,6 @@ using namespace panda::ecmascript::builtins; using namespace panda::ecmascript::base; namespace panda::test { -using Array = ecmascript::builtins::BuiltinsArray; -using TypedArray = ecmascript::builtins::BuiltinsTypedArray; -using TypedArrayHelper = ecmascript::base::TypedArrayHelper; class BuiltinsTypedArrayTest : public testing::Test { public: @@ -74,15 +69,15 @@ protected: EcmaHandleScope *scope_ {nullptr}; JSThread *thread_ {nullptr}; - class TestClass : public base::BuiltinsBase { + class TestClass { public: static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) { - JSHandle key = GetCallArg(argv, 0); + JSHandle key = builtins_common::GetCallArg(argv, 0); if (key->IsUndefined()) { return JSTaggedValue::Undefined(); } - JSArray *js_array = JSArray::Cast(GetThis(argv)->GetTaggedObject()); + JSArray *js_array = JSArray::Cast(builtins_common::GetThis(argv)->GetTaggedObject()); int length = js_array->GetArrayLength() + 1; js_array->SetArrayLength(argv->GetThread(), length); return JSTaggedValue::Undefined(); @@ -92,13 +87,13 @@ protected: { uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { - [[maybe_unused]] int aaa = GetCallArg(argv, 0)->GetInt(); + [[maybe_unused]] int aaa = builtins_common::GetCallArg(argv, 0)->GetInt(); // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestFilterFunc(EcmaRuntimeCallInfo *argv) @@ -107,18 +102,18 @@ protected: uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestMapFunc(EcmaRuntimeCallInfo *argv) { - int accumulator = GetCallArg(argv, 0)->GetInt(); + int accumulator = builtins_common::GetCallArg(argv, 0)->GetInt(); accumulator = accumulator * 2; // 2 : mapped to 2 times the original value - return BuiltinsBase::GetTaggedInt(accumulator); + return builtins_common::GetTaggedInt(accumulator); } static JSTaggedValue TestFindFunc(EcmaRuntimeCallInfo *argv) @@ -126,11 +121,11 @@ protected: uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestFindIndexFunc(EcmaRuntimeCallInfo *argv) @@ -138,25 +133,25 @@ protected: uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } static JSTaggedValue TestReduceFunc(EcmaRuntimeCallInfo *argv) { - int accumulator = GetCallArg(argv, 0)->GetInt(); - accumulator = accumulator + GetCallArg(argv, 1)->GetInt(); - return BuiltinsBase::GetTaggedInt(accumulator); + int accumulator = builtins_common::GetCallArg(argv, 0)->GetInt(); + accumulator = accumulator + builtins_common::GetCallArg(argv, 1)->GetInt(); + return builtins_common::GetTaggedInt(accumulator); } static JSTaggedValue TestReduceRightFunc(EcmaRuntimeCallInfo *argv) { - int accumulator = GetCallArg(argv, 0)->GetInt(); - accumulator = accumulator + GetCallArg(argv, 1)->GetInt(); - return BuiltinsBase::GetTaggedInt(accumulator); + int accumulator = builtins_common::GetCallArg(argv, 0)->GetInt(); + accumulator = accumulator + builtins_common::GetCallArg(argv, 1)->GetInt(); + return builtins_common::GetTaggedInt(accumulator); } static JSTaggedValue TestSomeFunc(EcmaRuntimeCallInfo *argv) @@ -164,11 +159,11 @@ protected: uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case - if (GetCallArg(argv, 0)->GetInt() > 10) { - return GetTaggedBoolean(true); + if (builtins_common::GetCallArg(argv, 0)->GetInt() > 10) { + return builtins_common::GetTaggedBoolean(true); } } - return GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } }; }; @@ -202,7 +197,7 @@ JSTypedArray *CreateTypedArrayFromList(JSThread *thread, const JSHandleSetCallArg(0, jsarray.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result = TypedArray::Int8ArrayConstructor(ecma_runtime_call_info1.get()); + JSTaggedValue result = int8_array::Int8ArrayConstructor(ecma_runtime_call_info1.get()); EXPECT_TRUE(result.IsECMAObject()); JSTypedArray *int8arr = JSTypedArray::Cast(reinterpret_cast(result.GetRawData())); @@ -221,7 +216,7 @@ TEST_F(BuiltinsTypedArrayTest, Species) ecma_runtime_call_info1->SetThis(global_object.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info1.get()); - JSTaggedValue result = TypedArray::Species(ecma_runtime_call_info1.get()); + JSTaggedValue result = typed_array::GetSpecies(ecma_runtime_call_info1.get()); ASSERT_TRUE(result.IsECMAObject()); } @@ -248,7 +243,7 @@ TEST_F(BuiltinsTypedArrayTest, Includes1) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = TypedArray::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -276,7 +271,7 @@ TEST_F(BuiltinsTypedArrayTest, Includes2) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(3))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = TypedArray::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -304,7 +299,7 @@ TEST_F(BuiltinsTypedArrayTest, Includes3) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(0))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = TypedArray::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } @@ -331,7 +326,7 @@ TEST_F(BuiltinsTypedArrayTest, Includes4) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(1))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = TypedArray::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(true).GetRawData()); } @@ -358,7 +353,7 @@ TEST_F(BuiltinsTypedArrayTest, Includes5) ecma_runtime_call_info->SetCallArg(0, JSTaggedValue(static_cast(5))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecma_runtime_call_info.get()); - JSTaggedValue result = TypedArray::Includes(ecma_runtime_call_info.get()); + JSTaggedValue result = typed_array::proto::Includes(ecma_runtime_call_info.get()); TestHelper::TearDownFrame(thread_, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(false).GetRawData()); } diff --git a/tests/runtime/builtins/builtins_weak_map_test.cpp b/tests/runtime/builtins/builtins_weak_map_test.cpp index 96c63484d74ed9a33187e47bebb3f4ea059c7e7b..203f1078f397f793173ffec8fcd33352edf91fc5 100644 --- a/tests/runtime/builtins/builtins_weak_map_test.cpp +++ b/tests/runtime/builtins/builtins_weak_map_test.cpp @@ -14,7 +14,6 @@ */ #include "plugins/ecmascript/runtime/base/builtins_base.h" -#include "plugins/ecmascript/runtime/builtins/builtins_weak_map.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -36,7 +35,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using BuiltinsWeakMap = ecmascript::builtins::BuiltinsWeakMap; using JSWeakMap = ecmascript::JSWeakMap; class BuiltinsWeakMapTest : public testing::Test { @@ -79,14 +77,14 @@ static JSObject *JSObjectTestCreate(JSThread *thread) JSWeakMap *CreateBuiltinsWeakMap(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsWeakMapFunction()); + JSHandle new_target(env->GetWeakMapFunction()); // 4 : test case auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, new_target.GetTaggedValue(), 4); ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsWeakMap::WeakMapConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = weak_map::WeakMapConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); return JSWeakMap::Cast(reinterpret_cast(result.GetRawData())); @@ -97,7 +95,7 @@ TEST_F(BuiltinsWeakMapTest, CreateAndGetSize) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsWeakMapFunction()); + JSHandle new_target(env->GetWeakMapFunction()); JSHandle map(thread, CreateBuiltinsWeakMap(thread)); JSHandle array(factory->NewTaggedArray(1)); @@ -118,7 +116,7 @@ TEST_F(BuiltinsWeakMapTest, CreateAndGetSize) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsWeakMap::WeakMapConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result1 = weak_map::WeakMapConstructor(ecma_runtime_call_info.get()); JSHandle weak_map(thread, JSWeakMap::Cast(reinterpret_cast(result1.GetRawData()))); EXPECT_EQ(weak_map->GetSize(), 1); } @@ -137,13 +135,13 @@ TEST_F(BuiltinsWeakMapTest, SetAndHas) { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsWeakMap::Has(ecma_runtime_call_info.get()); + JSTaggedValue result1 = weak_map::proto::Has(ecma_runtime_call_info.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); } // test Set() - JSTaggedValue result2 = BuiltinsWeakMap::Set(ecma_runtime_call_info.get()); + JSTaggedValue result2 = weak_map::proto::Set(ecma_runtime_call_info.get()); EXPECT_TRUE(result2.IsECMAObject()); JSWeakMap *js_weak_map = JSWeakMap::Cast(reinterpret_cast(result2.GetRawData())); EXPECT_EQ(js_weak_map->GetSize(), 1); @@ -156,7 +154,7 @@ TEST_F(BuiltinsWeakMapTest, SetAndHas) ecma_runtime_call_info1->SetThis(JSTaggedValue(js_weak_map)); { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = BuiltinsWeakMap::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = weak_map::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -178,7 +176,7 @@ TEST_F(BuiltinsWeakMapTest, DeleteAndRemove) ecma_runtime_call_info->SetCallArg(1, JSTaggedValue(static_cast(i))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsWeakMap::Set(ecma_runtime_call_info.get()); + JSTaggedValue result1 = weak_map::proto::Set(ecma_runtime_call_info.get()); EXPECT_TRUE(result1.IsECMAObject()); JSWeakMap *js_weak_map = JSWeakMap::Cast(reinterpret_cast(result1.GetRawData())); @@ -194,17 +192,17 @@ TEST_F(BuiltinsWeakMapTest, DeleteAndRemove) ecma_runtime_call_info1->SetCallArg(0, last_key); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsWeakMap::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = weak_map::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsWeakMap::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = weak_map::proto::Delete(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsWeakMap::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = weak_map::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } diff --git a/tests/runtime/builtins/builtins_weak_set_test.cpp b/tests/runtime/builtins/builtins_weak_set_test.cpp index 3d99d788346b5089debbdaeb4a8201d7b6fbff97..0f4d50e2a34602c73c3f570272c29298ec42a297 100644 --- a/tests/runtime/builtins/builtins_weak_set_test.cpp +++ b/tests/runtime/builtins/builtins_weak_set_test.cpp @@ -13,7 +13,8 @@ * limitations under the License. */ -#include "plugins/ecmascript/runtime/builtins/builtins_weak_set.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" + #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -34,7 +35,6 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; namespace panda::test { -using BuiltinsWeakSet = ecmascript::builtins::BuiltinsWeakSet; using JSWeakSet = ecmascript::JSWeakSet; class BuiltinsWeakSetTest : public testing::Test { @@ -78,14 +78,14 @@ static JSObject *JSObjectTestCreate(JSThread *thread) JSWeakSet *CreateBuiltinsWeakSet(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsWeakSetFunction()); + JSHandle new_target(env->GetWeakSetFunction()); // 4 : test case auto ecma_runtime_call_info = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*new_target), 4); ecma_runtime_call_info->SetFunction(new_target.GetTaggedValue()); ecma_runtime_call_info->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result = BuiltinsWeakSet::WeakSetConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result = weak_set::WeakSetConstructor(ecma_runtime_call_info.get()); EXPECT_TRUE(result.IsECMAObject()); JSWeakSet *js_weak_set = JSWeakSet::Cast(reinterpret_cast(result.GetRawData())); @@ -96,7 +96,7 @@ TEST_F(BuiltinsWeakSetTest, CreateAndGetSize) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle new_target(env->GetBuiltinsWeakSetFunction()); + JSHandle new_target(env->GetWeakSetFunction()); JSHandle weak_set(thread, CreateBuiltinsWeakSet(thread)); JSHandle array(factory->NewTaggedArray(5)); @@ -114,7 +114,7 @@ TEST_F(BuiltinsWeakSetTest, CreateAndGetSize) [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsWeakSet::WeakSetConstructor(ecma_runtime_call_info.get()); + JSTaggedValue result1 = weak_set::WeakSetConstructor(ecma_runtime_call_info.get()); JSHandle weak_set_result(thread, JSWeakSet::Cast(reinterpret_cast(result1.GetRawData()))); EXPECT_EQ(weak_set_result->GetSize(), 5); @@ -133,12 +133,12 @@ TEST_F(BuiltinsWeakSetTest, AddAndHas) JSWeakSet *js_weak_set; { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsWeakSet::Has(ecma_runtime_call_info.get()); + JSTaggedValue result1 = weak_set::proto::Has(ecma_runtime_call_info.get()); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Add() - JSTaggedValue result2 = BuiltinsWeakSet::Add(ecma_runtime_call_info.get()); + JSTaggedValue result2 = weak_set::proto::Add(ecma_runtime_call_info.get()); EXPECT_TRUE(result2.IsECMAObject()); js_weak_set = JSWeakSet::Cast(reinterpret_cast(result2.GetRawData())); EXPECT_EQ(js_weak_set->GetSize(), 1); @@ -151,7 +151,7 @@ TEST_F(BuiltinsWeakSetTest, AddAndHas) ecma_runtime_call_info1->SetCallArg(0, key.GetTaggedValue()); { [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result3 = BuiltinsWeakSet::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = weak_set::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -173,7 +173,7 @@ TEST_F(BuiltinsWeakSetTest, DeleteAndRemove) ecma_runtime_call_info->SetCallArg(0, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info.get()); - JSTaggedValue result1 = BuiltinsWeakSet::Add(ecma_runtime_call_info.get()); + JSTaggedValue result1 = weak_set::proto::Add(ecma_runtime_call_info.get()); EXPECT_TRUE(result1.IsECMAObject()); JSWeakSet *js_weak_set = JSWeakSet::Cast(reinterpret_cast(result1.GetRawData())); @@ -188,17 +188,17 @@ TEST_F(BuiltinsWeakSetTest, DeleteAndRemove) ecma_runtime_call_info1->SetCallArg(0, last_key); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecma_runtime_call_info1.get()); - JSTaggedValue result2 = BuiltinsWeakSet::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result2 = weak_set::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsWeakSet::Delete(ecma_runtime_call_info1.get()); + JSTaggedValue result3 = weak_set::proto::Delete(ecma_runtime_call_info1.get()); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsWeakSet::Has(ecma_runtime_call_info1.get()); + JSTaggedValue result4 = weak_set::proto::Has(ecma_runtime_call_info1.get()); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } diff --git a/tests/runtime/common/builtins_test.cpp b/tests/runtime/common/builtins_test.cpp index e4710324b1604880e032bdb9496912aa164c5634..7aff9ce462c55efb7dc743105f79f1e98a9ee7c6 100644 --- a/tests/runtime/common/builtins_test.cpp +++ b/tests/runtime/common/builtins_test.cpp @@ -83,7 +83,7 @@ TEST_F(BuiltinsTest, SetInit) auto ecma_vm = thread->GetEcmaVM(); JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle set_function(env->GetBuiltinsSetFunction()); + JSHandle set_function(env->GetSetFunction()); ASSERT_NE(*set_function, nullptr); } @@ -93,7 +93,7 @@ TEST_F(BuiltinsTest, MapInit) auto ecma_vm = thread->GetEcmaVM(); JSHandle env = ecma_vm->GetGlobalEnv(); - JSHandle map_function(env->GetBuiltinsMapFunction()); + JSHandle map_function(env->GetMapFunction()); ASSERT_NE(*map_function, nullptr); } diff --git a/tests/runtime/common/js_function_test.cpp b/tests/runtime/common/js_function_test.cpp index 92c681cd8f96b2616b1ce77040c9fa61945aaffc..a4cffa27bdc8775e0ff3829b575ec3008542277c 100644 --- a/tests/runtime/common/js_function_test.cpp +++ b/tests/runtime/common/js_function_test.cpp @@ -116,9 +116,9 @@ TEST_F(JSFunctionTest, OrdinaryHasInstance) JSTaggedValue TestInvokeInternal(EcmaRuntimeCallInfo *argv) { if (argv->GetArgsNumber() == 1 && argv->GetCallArg(0).GetTaggedValue() == JSTaggedValue(1)) { - return BuiltinsBase::GetTaggedBoolean(true); + return builtins_common::GetTaggedBoolean(true); } - return BuiltinsBase::GetTaggedBoolean(false); + return builtins_common::GetTaggedBoolean(false); } TEST_F(JSFunctionTest, Invoke) @@ -141,7 +141,7 @@ TEST_F(JSFunctionTest, Invoke) info->SetCallArgs(JSTaggedValue(1)); JSTaggedValue res = JSFunction::Invoke(info.Get(), callee_key); - JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(true); + JSTaggedValue ruler = builtins_common::GetTaggedBoolean(true); EXPECT_EQ(res.GetRawData(), ruler.GetRawData()); } diff --git a/tests/runtime/common/js_map_test.cpp b/tests/runtime/common/js_map_test.cpp index 6f8eeb4584a6f21ad37d6bcf21b57a0b71a967ba..ca69adf4ff32153e4c583d42e794fdac0c92e40e 100644 --- a/tests/runtime/common/js_map_test.cpp +++ b/tests/runtime/common/js_map_test.cpp @@ -59,7 +59,7 @@ protected: { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle constructor = env->GetBuiltinsMapFunction(); + JSHandle constructor = env->GetMapFunction(); JSHandle map = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle hash_map = LinkedHashMap::Create(thread); diff --git a/tests/runtime/common/js_object_test.cpp b/tests/runtime/common/js_object_test.cpp index af9a8624e06570e632e0d798c28c50a24ef0063b..3d9e511d45db1a0652f10f12cf55b51e09c6786c 100644 --- a/tests/runtime/common/js_object_test.cpp +++ b/tests/runtime/common/js_object_test.cpp @@ -608,7 +608,7 @@ JSTaggedValue TestGetter(EcmaRuntimeCallInfo *argv) auto thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle obj(BuiltinsBase::GetThis(argv)); + JSHandle obj(builtins_common::GetThis(argv)); JSHandle key(factory->NewFromString("y")); JSTaggedValue value = JSObject::GetProperty(thread, JSHandle(obj), key).GetValue().GetTaggedValue(); @@ -645,7 +645,7 @@ JSTaggedValue TestSetter(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle obj(BuiltinsBase::GetThis(argv)); + JSHandle obj(builtins_common::GetThis(argv)); JSHandle key(factory->NewFromString("y")); JSTaggedValue value(JSObject::GetProperty(thread, JSHandle(obj), key).GetValue().GetTaggedValue()); JSHandle value_handle(thread, JSTaggedValue(value.GetInt() + 1)); diff --git a/tests/runtime/common/js_serializer_test.cpp b/tests/runtime/common/js_serializer_test.cpp index 960613dd6cedd17d892280cf84c43477861a223a..2f9f90f5b1209e8e1ffd61e0ab6a72894a65b3ca 100644 --- a/tests/runtime/common/js_serializer_test.cpp +++ b/tests/runtime/common/js_serializer_test.cpp @@ -15,7 +15,7 @@ #include -#include "plugins/ecmascript/runtime/builtins/builtins_arraybuffer.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_language_context.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/global_env.h" @@ -580,7 +580,7 @@ TEST_F(JSSerializerTest, TestSerializeJSSet) ObjectFactory *factory = ecmaVm->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle constructor = env->GetBuiltinsSetFunction(); + JSHandle constructor = env->GetSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle linkedSet = LinkedHashSet::Create(thread); @@ -773,7 +773,7 @@ JSMap *CreateMap(JSThread *thread) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle constructor = env->GetBuiltinsMapFunction(); + JSHandle constructor = env->GetMapFunction(); JSHandle map = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle linkedMap = LinkedHashMap::Create(thread); @@ -820,9 +820,9 @@ TEST_F(JSSerializerTest, SerializeJSArrayBuffer) jsArrayBuffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byteLength))); JSHandle obj = JSHandle(jsArrayBuffer); JSHandle number(thread, JSTaggedValue(7)); - BuiltinsArrayBuffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 1, DataViewType::UINT8, number, true); + builtins::array_buffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 1, DataViewType::UINT8, number, true); number = JSHandle(thread, JSTaggedValue(17)); - BuiltinsArrayBuffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 3, DataViewType::UINT8, number, true); + builtins::array_buffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 3, DataViewType::UINT8, number, true); JSSerializer *serializer = new JSSerializer(thread); bool success = serializer->SerializeJSTaggedValue(JSHandle::Cast(jsArrayBuffer)); @@ -917,10 +917,10 @@ JSArrayBuffer *CreateTestJSArrayBuffer(JSThread *thread) JSHandle obj = JSHandle(jsArrayBuffer); // 7 : test case JSHandle number(thread, JSTaggedValue(7)); - BuiltinsArrayBuffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 1, DataViewType::UINT8, number, true); + builtins::array_buffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 1, DataViewType::UINT8, number, true); // 3, 17 : test case number = JSHandle(thread, JSTaggedValue(17)); - BuiltinsArrayBuffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 3, DataViewType::UINT8, number, true); + builtins::array_buffer::SetValueInBuffer(thread, obj.GetTaggedValue(), 3, DataViewType::UINT8, number, true); return *jsArrayBuffer; } diff --git a/tests/runtime/common/js_set_iterator_test.cpp b/tests/runtime/common/js_set_iterator_test.cpp index 94cf7b6cbd8e03845efce84c16fe0b77f1b013c2..d74f0294a186646874e463e8fae3b6c9135b4158 100644 --- a/tests/runtime/common/js_set_iterator_test.cpp +++ b/tests/runtime/common/js_set_iterator_test.cpp @@ -54,7 +54,7 @@ JSSet *CreateSet(JSThread *thread) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle constructor = env->GetBuiltinsSetFunction(); + JSHandle constructor = env->GetSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle hash_set = LinkedHashSet::Create(thread); diff --git a/tests/runtime/common/js_set_test.cpp b/tests/runtime/common/js_set_test.cpp index af3f1c5aa8bfb433e2ef4820901aea7c21423800..e778d66febceecaeb75daffc6fba8797d0ce2c67 100644 --- a/tests/runtime/common/js_set_test.cpp +++ b/tests/runtime/common/js_set_test.cpp @@ -60,7 +60,7 @@ protected: ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle constructor = env->GetBuiltinsSetFunction(); + JSHandle constructor = env->GetSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle hash_set = LinkedHashSet::Create(thread); diff --git a/tests/runtime/ic/ic_compareop_test.cpp b/tests/runtime/ic/ic_compareop_test.cpp index 31be6295b6f8be4bf1d3b2391b3d0fc072016341..0e25c9cf920bba23943b1c8ad4dab11edd24d78b 100644 --- a/tests/runtime/ic/ic_compareop_test.cpp +++ b/tests/runtime/ic/ic_compareop_test.cpp @@ -14,7 +14,7 @@ */ #include -#include "plugins/ecmascript/runtime/builtins/builtins_boolean.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/ecma_runtime_call_info.h" #include "plugins/ecmascript/runtime/ecma_string.h" #include "plugins/ecmascript/runtime/ecma_vm.h" @@ -83,7 +83,7 @@ TEST_F(IcCompareOPTest, EqualWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = @@ -143,7 +143,7 @@ TEST_F(IcCompareOPTest, NotEqualWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::NotEqDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); @@ -206,7 +206,7 @@ TEST_F(IcCompareOPTest, LessDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = @@ -265,7 +265,7 @@ TEST_F(IcCompareOPTest, LessEqDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::LessEqDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); @@ -327,7 +327,7 @@ TEST_F(IcCompareOPTest, GreaterDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::GreaterDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); @@ -391,7 +391,7 @@ TEST_F(IcCompareOPTest, GreaterEqDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::boolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::GreaterEqDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); diff --git a/tests/runtime/napi/jsnapi_tests.cpp b/tests/runtime/napi/jsnapi_tests.cpp index 59e3e0aa986ffcdb5a099f125b817456bfdd6016..1859433232e964dab821f57a46150a1000934e66 100644 --- a/tests/runtime/napi/jsnapi_tests.cpp +++ b/tests/runtime/napi/jsnapi_tests.cpp @@ -17,7 +17,7 @@ #include -#include "plugins/ecmascript/runtime/builtins/builtins_function.h" +#include "plugins/ecmascript/runtime/base/builtins_base.h" #include "plugins/ecmascript/runtime/global_env.h" #include "plugins/ecmascript/runtime/ecma_vm.h" #include "plugins/ecmascript/runtime/js_thread.h" @@ -663,10 +663,10 @@ TEST_F(JSNApiTests, InheritPrototype_001) LocalScope scope(vm_); JSHandle env = vm_->GetGlobalEnv(); // new with Builtins::Set Prototype - JSHandle set = env->GetBuiltinsSetFunction(); + JSHandle set = env->GetSetFunction(); Local set_local = JSNApiHelper::ToLocal(set); // new with Builtins::Map Prototype - JSHandle map = env->GetBuiltinsMapFunction(); + JSHandle map = env->GetMapFunction(); Local map_local = JSNApiHelper::ToLocal(map); JSHandle set_prototype(thread_, JSHandle::Cast(set)->GetFunctionPrototype()); JSHandle map_prototype(thread_, JSHandle::Cast(map)->GetFunctionPrototype()); @@ -728,10 +728,10 @@ TEST_F(JSNApiTests, InheritPrototype_002) LocalScope scope(vm_); JSHandle env = vm_->GetGlobalEnv(); // new with Builtins::weakSet Prototype - JSHandle weak_set = env->GetBuiltinsWeakSetFunction(); + JSHandle weak_set = env->GetWeakSetFunction(); Local weak_set_local = JSNApiHelper::ToLocal(weak_set); // new with Builtins::weakMap Prototype - JSHandle weak_map = env->GetBuiltinsWeakMapFunction(); + JSHandle weak_map = env->GetWeakMapFunction(); Local weak_map_local = JSNApiHelper::ToLocal(weak_map); weak_map_local->Inherit(vm_, weak_set_local); @@ -757,8 +757,8 @@ TEST_F(JSNApiTests, InheritPrototype_003) LocalScope scope(vm_); JSHandle env = vm_->GetGlobalEnv(); - JSMethod *invoke_self = vm_->GetMethodForNativeFunction( - reinterpret_cast(builtins::BuiltinsFunction::FunctionPrototypeInvokeSelf)); + JSMethod *invoke_self = + vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionPrototypeInvokeSelf)); // father type Local proto_local = NewFunctionByHClass(JSHandle::Cast(env->GetFunctionClassWithProto()), invoke_self); @@ -799,17 +799,16 @@ TEST_F(JSNApiTests, DISABLED_InheritPrototype_004) // TODO(vpukhov) JSHandle env = vm_->GetGlobalEnv(); auto factory = vm_->GetFactory(); - JSHandle weak_set = env->GetBuiltinsWeakSetFunction(); + JSHandle weak_set = env->GetWeakSetFunction(); JSHandle delete_string(factory->NewFromCanBeCompressString("delete")); JSHandle add_string(factory->NewFromCanBeCompressString("add")); JSHandle default_string = thread_->GlobalConstants()->GetHandledDefaultString(); JSHandle delete_method = JSObject::GetMethod(thread_, weak_set, delete_string); JSHandle add_method = JSObject::GetMethod(thread_, weak_set, add_string); - JSMethod *invoke_self = vm_->GetMethodForNativeFunction( - reinterpret_cast(builtins::BuiltinsFunction::FunctionPrototypeInvokeSelf)); - JSMethod *ctor = - vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::BuiltinsFunction::FunctionConstructor)); + JSMethod *invoke_self = + vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionPrototypeInvokeSelf)); + JSMethod *ctor = vm_->GetMethodForNativeFunction(reinterpret_cast(builtins::function::FunctionConstructor)); JSHandle proto_dynclass = JSHandle::Cast(env->GetFunctionClassWithProto()); JSHandle func_func_prototype = factory->NewJSFunctionByDynClass(invoke_self, proto_dynclass);