diff --git a/compiler/ecmascript_call_params.h b/compiler/ecmascript_call_params.h index 73f7dfb5ea112d43b54b2935dd61263159d73123..75b68afbecf03feecb6a75c74b6f168a20af8ec9 100644 --- a/compiler/ecmascript_call_params.h +++ b/compiler/ecmascript_call_params.h @@ -22,15 +22,15 @@ // NOLINTNEXTLINE(modernize-concat-nested-namespaces) namespace panda::compiler { -namespace EcmascriptCallParams { +namespace ecmascript_call_params { enum : uint8_t { SLOT_FUNCTION = CallConvDynInfo::SLOT_CALLEE, SLOT_NEWTARGET = ::panda::ecmascript::js_method_args::NEW_TARGET_IDX, SLOT_THIS = ::panda::ecmascript::js_method_args::THIS_IDX, SLOT_FIRST_ARG = ::panda::ecmascript::js_method_args::FIRST_ARG_IDX, }; -} // namespace EcmascriptCallParams -static_assert(static_cast(EcmascriptCallParams::SLOT_FUNCTION) == +} // namespace ecmascript_call_params +static_assert(static_cast(ecmascript_call_params::SLOT_FUNCTION) == static_cast(::panda::ecmascript::js_method_args::FUNC_IDX)); } // namespace panda::compiler diff --git a/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp b/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp index c7bcbd3805a46371056fac6579c2656a9437198f..3fa409ee9321aaccc9f112c14b444cb364a228e2 100644 --- a/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp +++ b/compiler/ecmascript_extensions/ecmascript_codegen_extensions.cpp @@ -35,7 +35,8 @@ void Codegen::GenerateEcmascriptEnvInPrologue(Reg jsfunc_reg, uint32_t depth) if (!jsfunc_reg.IsValid()) { ASSERT(depth == 0); jsfunc_reg_tmp.Acquire(); - auto args_jsfunc_offset = GetStackOffset(Location::MakeStackParameter(EcmascriptCallParams::SLOT_FUNCTION)); + auto args_jsfunc_offset = + GetStackOffset(Location::MakeStackParameter(ecmascript_call_params::SLOT_FUNCTION)); enc->EncodeLdr(jsfunc_reg_tmp, false, MemRef(SpReg(), args_jsfunc_offset)); jsfunc_reg = jsfunc_reg_tmp.GetReg(); } diff --git a/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp b/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp index 94505581da4ce48ecb17bb434d7f296aea598a62..4d84a656d096fbe346df9748254f211cab3e1a26 100644 --- a/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp +++ b/compiler/optimizer/ir_builder/ecmascript_inst_builder.cpp @@ -160,7 +160,7 @@ void InstBuilder::BuildEcmaNewobjdynrange(const BytecodeInstruction *bc_inst) namespace panda::compiler { -template +template void InstBuilder::BuildStGlobalVar(const BytecodeInstruction *bc_inst, size_t type_id) { auto pc = GetPc(bc_inst->GetAddress()); @@ -179,7 +179,7 @@ void InstBuilder::BuildStGlobalVar(const BytecodeInstruction *bc_inst, size_t ty store_object->SetObjectType(ObjectType::MEM_GLOBAL); store_object->SetInput(0, get_address); Inst *store_val = nullptr; - if constexpr (is_acc_read) { + if constexpr (IS_ACC_READ) { store_val = GetDefinitionAcc(); } else { store_val = GetDefinition(bc_inst->GetVReg(0)); @@ -191,7 +191,7 @@ void InstBuilder::BuildStGlobalVar(const BytecodeInstruction *bc_inst, size_t ty AddInstruction(store_object); } -template +template void InstBuilder::BuildLdGlobalVar(const BytecodeInstruction *bc_inst, size_t type_id) { auto pc = GetPc(bc_inst->GetAddress()); @@ -212,7 +212,7 @@ void InstBuilder::BuildLdGlobalVar(const BytecodeInstruction *bc_inst, size_t ty AddInstruction(get_address); AddInstruction(load_object); - if constexpr (is_acc_write) { + if constexpr (IS_ACC_WRITE) { UpdateDefinitionAcc(load_object); } else { UpdateDefinition(bc_inst->GetVReg(0), load_object); diff --git a/runtime/base/array_helper.cpp b/runtime/base/array_helper.cpp index f771344d9e6e7b4d2b38c1da5de4aa9e47a53011..c8555ed678cdb2f5c0824a55d95b7be3293fa064 100644 --- a/runtime/base/array_helper.cpp +++ b/runtime/base/array_helper.cpp @@ -34,10 +34,10 @@ bool ArrayHelper::IsConcatSpreadable(JSThread *thread, const JSHandleGetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle isConcatsprKey = env->GetIsConcatSpreadableSymbol(); - JSHandle spreadable = JSTaggedValue::GetProperty(thread, obj, isConcatsprKey).GetValue(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + JSHandle is_concatspr_key = env->GetIsConcatSpreadableSymbol(); + JSHandle spreadable = JSTaggedValue::GetProperty(thread, obj, is_concatspr_key).GetValue(); // 3. ReturnIfAbrupt(spreadable). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -50,28 +50,28 @@ bool ArrayHelper::IsConcatSpreadable(JSThread *thread, const JSHandleIsArray(thread); } -int32_t ArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, - const JSHandle &valueX, const JSHandle &valueY) +int32_t ArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfn_handle, + const JSHandle &value_x, const JSHandle &value_y) { // 1. If x and y are both undefined, return +0. - if (valueX->IsHole()) { - if (valueY->IsHole()) { + if (value_x->IsHole()) { + if (value_y->IsHole()) { return 0; } return 1; } - if (valueY->IsHole()) { + if (value_y->IsHole()) { return -1; } - if (valueX->IsUndefined()) { - if (valueY->IsUndefined()) { + if (value_x->IsUndefined()) { + if (value_y->IsUndefined()) { return 0; } // 2. If x is undefined, return 1. return 1; } // 3. If y is undefined, return -1. - if (valueY->IsUndefined()) { + if (value_y->IsUndefined()) { return -1; } // 4. If the argument comparefn is not undefined, then @@ -79,18 +79,18 @@ int32_t ArrayHelper::SortCompare(JSThread *thread, const JSHandle // b. ReturnIfAbrupt(v). // c. If v is NaN, return +0. // d. Return v. - if (!callbackfnHandle->IsUndefined()) { - JSHandle thisArgHandle(thread, JSTaggedValue::Undefined()); + if (!callbackfn_handle->IsUndefined()) { + JSHandle this_arg_handle(thread, JSTaggedValue::Undefined()); - auto info = NewRuntimeCallInfo(thread, callbackfnHandle, thisArgHandle, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(valueX, valueY); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 2: two args - if (callResult.IsInt()) { - return callResult.GetInt(); + auto info = NewRuntimeCallInfo(thread, callbackfn_handle, this_arg_handle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(value_x, value_y); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 2: two args + if (call_result.IsInt()) { + return call_result.GetInt(); } RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSHandle testResult(thread, callResult); - JSTaggedNumber v = JSTaggedValue::ToNumber(thread, testResult); + JSHandle test_result(thread, call_result); + JSTaggedNumber v = JSTaggedValue::ToNumber(thread, test_result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); double value = v.GetNumber(); if (std::isnan(value)) { @@ -105,39 +105,39 @@ int32_t ArrayHelper::SortCompare(JSThread *thread, const JSHandle // 9. If xString < yString, return -1. // 10. If xString > yString, return 1. // 11. Return +0. - JSHandle xValueHandle(JSTaggedValue::ToString(thread, valueX)); + JSHandle x_value_handle(JSTaggedValue::ToString(thread, value_x)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSHandle yValueHandle(JSTaggedValue::ToString(thread, valueY)); + JSHandle y_value_handle(JSTaggedValue::ToString(thread, value_y)); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - ComparisonResult compareResult = JSTaggedValue::Compare(thread, xValueHandle, yValueHandle); - return compareResult == ComparisonResult::GREAT ? 1 : 0; + ComparisonResult compare_result = JSTaggedValue::Compare(thread, x_value_handle, y_value_handle); + return compare_result == ComparisonResult::GREAT ? 1 : 0; } -double ArrayHelper::GetLength(JSThread *thread, const JSHandle &thisHandle) +double ArrayHelper::GetLength(JSThread *thread, const JSHandle &this_handle) { - if (thisHandle->IsJSArray()) { - return JSArray::Cast(thisHandle->GetTaggedObject())->GetArrayLength(); + if (this_handle->IsJSArray()) { + return JSArray::Cast(this_handle->GetTaggedObject())->GetArrayLength(); } - if (thisHandle->IsTypedArray()) { - return TypedArrayHelper::GetArrayLength(thread, JSHandle::Cast(thisHandle)); + if (this_handle->IsTypedArray()) { + return TypedArrayHelper::GetArrayLength(thread, JSHandle::Cast(this_handle)); } - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle lenResult = JSTaggedValue::GetProperty(thread, thisHandle, lengthKey).GetValue(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle len_result = JSTaggedValue::GetProperty(thread, this_handle, length_key).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSTaggedNumber len = JSTaggedValue::ToLength(thread, lenResult); + JSTaggedNumber len = JSTaggedValue::ToLength(thread, len_result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); return len.GetNumber(); } -double ArrayHelper::GetArrayLength(JSThread *thread, const JSHandle &thisHandle) +double ArrayHelper::GetArrayLength(JSThread *thread, const JSHandle &this_handle) { - if (thisHandle->IsJSArray()) { - return JSArray::Cast(thisHandle->GetTaggedObject())->GetArrayLength(); + if (this_handle->IsJSArray()) { + return JSArray::Cast(this_handle->GetTaggedObject())->GetArrayLength(); } - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle lenResult = JSTaggedValue::GetProperty(thread, thisHandle, lengthKey).GetValue(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle len_result = JSTaggedValue::GetProperty(thread, this_handle, length_key).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); - JSTaggedNumber len = JSTaggedValue::ToLength(thread, lenResult); + JSTaggedNumber len = JSTaggedValue::ToLength(thread, len_result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); return len.GetNumber(); } diff --git a/runtime/base/array_helper.h b/runtime/base/array_helper.h index f6e79090966a9f5837c5af814c8a172e18f89ce9..0a9ac84099cf2a588caf30d857e9bad7a4ce5df8 100644 --- a/runtime/base/array_helper.h +++ b/runtime/base/array_helper.h @@ -25,10 +25,10 @@ namespace panda::ecmascript::base { class ArrayHelper { public: static bool IsConcatSpreadable(JSThread *thread, const JSHandle &obj); - static int32_t SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, - const JSHandle &valueX, const JSHandle &valueY); - static double GetLength(JSThread *thread, const JSHandle &thisHandle); - static double GetArrayLength(JSThread *thread, const JSHandle &thisHandle); + static int32_t SortCompare(JSThread *thread, const JSHandle &callbackfn_handle, + const JSHandle &value_x, const JSHandle &value_y); + static double GetLength(JSThread *thread, const JSHandle &this_handle); + static double GetArrayLength(JSThread *thread, const JSHandle &this_handle); }; } // namespace panda::ecmascript::base diff --git a/runtime/base/error_helper.cpp b/runtime/base/error_helper.cpp index a6821c5b15ae41bf9c770e70ffd3ef76ee30472c..dda5c028aa555dc3706a1d6dcfd3ea20d0aa1e8a 100644 --- a/runtime/base/error_helper.cpp +++ b/runtime/base/error_helper.cpp @@ -33,19 +33,19 @@ JSTaggedValue ErrorHelper::ErrorCommonToString(EcmaRuntimeCallInfo *argv, const { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. // 2. If Type(O) is not Object, throw a TypeError exception - JSHandle thisValue = BuiltinsBase::GetThis(argv); - if (!thisValue->IsECMAObject()) { + JSHandle this_value = BuiltinsBase::GetThis(argv); + if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "ErrorToString:not an object", JSTaggedValue::Exception()); } // 3. Let name be Get(O, "name"). // 4. ReturnIfAbrupt(name). - auto globalConst = thread->GlobalConstants(); - JSHandle handleName = globalConst->GetHandledNameString(); - JSHandle name = JSObject::GetProperty(thread, thisValue, handleName).GetValue(); + auto global_const = thread->GlobalConstants(); + JSHandle handle_name = global_const->GetHandledNameString(); + JSHandle name = JSObject::GetProperty(thread, this_value, handle_name).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If name is undefined, let name be "Error"; otherwise let name be ToString(name). @@ -55,8 +55,8 @@ JSTaggedValue ErrorHelper::ErrorCommonToString(EcmaRuntimeCallInfo *argv, const // 7. Let msg be Get(O, "message"). // 8. ReturnIfAbrupt(msg). - JSHandle handleMsg = globalConst->GetHandledMessageString(); - JSHandle msg = JSObject::GetProperty(thread, thisValue, handleMsg).GetValue(); + JSHandle handle_msg = global_const->GetHandledMessageString(); + JSHandle msg = JSObject::GetProperty(thread, this_value, handle_msg).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If msg is undefined, let msg be the empty String; otherwise let msg be ToString(msg). @@ -81,33 +81,33 @@ JSTaggedValue ErrorHelper::ErrorCommonToString(EcmaRuntimeCallInfo *argv, const // 13. Return the result of concatenating name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and msg. JSHandle space = factory->NewFromCanBeCompressString(": "); - JSHandle jsHandleName = JSHandle::Cast(name); - JSHandle jsHandleMsg = JSHandle::Cast(msg); - JSHandle handleNameSpace = factory->ConcatFromString(jsHandleName, space); - JSHandle result = factory->ConcatFromString(handleNameSpace, jsHandleMsg); + JSHandle js_handle_name = JSHandle::Cast(name); + JSHandle js_handle_msg = JSHandle::Cast(msg); + JSHandle handle_name_space = factory->ConcatFromString(js_handle_name, space); + JSHandle result = factory->ConcatFromString(handle_name_space, js_handle_msg); return result.GetTaggedValue(); } JSHandle ErrorHelper::GetErrorName(JSThread *thread, const JSHandle &name, const ErrorType &error_type) { - auto globalConst = thread->GlobalConstants(); + auto global_const = thread->GlobalConstants(); if (name->IsUndefined()) { switch (error_type) { case ErrorType::RANGE_ERROR: - return globalConst->GetHandledRangeErrorString(); + return global_const->GetHandledRangeErrorString(); case ErrorType::EVAL_ERROR: - return globalConst->GetHandledEvalErrorString(); + return global_const->GetHandledEvalErrorString(); case ErrorType::REFERENCE_ERROR: - return globalConst->GetHandledReferenceErrorString(); + return global_const->GetHandledReferenceErrorString(); case ErrorType::TYPE_ERROR: - return globalConst->GetHandledTypeErrorString(); + return global_const->GetHandledTypeErrorString(); case ErrorType::URI_ERROR: - return globalConst->GetHandledURIErrorString(); + return global_const->GetHandledURIErrorString(); case ErrorType::SYNTAX_ERROR: - return globalConst->GetHandledSyntaxErrorString(); + return global_const->GetHandledSyntaxErrorString(); default: - return globalConst->GetHandledErrorString(); + return global_const->GetHandledErrorString(); } } return JSHandle::Cast(JSTaggedValue::ToString(thread, name)); @@ -117,11 +117,11 @@ JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, [[maybe_unused]] const ErrorType &error_type) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If NewTarget is undefined, let new_target be the active function object, else let new_target be NewTarget. - auto ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = BuiltinsBase::GetConstructor(argv); JSMutableHandle new_target(BuiltinsBase::GetNewTarget(argv)); if (new_target->IsUndefined()) { @@ -130,7 +130,7 @@ JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, JSHandle message = BuiltinsBase::GetCallArg(argv, 0); // 2. Let O be OrdinaryCreateFromConstructor(new_target, "%ErrorPrototype%", «[[ErrorData]]»). - JSHandle nativeInstanceObj = factory->NewJSObjectByConstructor(JSHandle(ctor), new_target); + JSHandle native_instance_obj = factory->NewJSObjectByConstructor(JSHandle(ctor), new_target); // 3. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -142,25 +142,25 @@ JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, // [[Configurable]]: true}. // d. Let status be DefinePropertyOrThrow(O, "message", msgDesc). // e. Assert: status is not an abrupt completion - auto globalConst = thread->GlobalConstants(); + auto global_const = thread->GlobalConstants(); if (!message->IsUndefined()) { - JSHandle handleStr = JSTaggedValue::ToString(thread, message); - LOG(DEBUG, ECMASCRIPT) << "Ark throw error: " << utf::Mutf8AsCString(handleStr->GetDataUtf8()); + JSHandle handle_str = JSTaggedValue::ToString(thread, message); + LOG(DEBUG, ECMASCRIPT) << "Ark throw error: " << utf::Mutf8AsCString(handle_str->GetDataUtf8()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle msgKey = globalConst->GetHandledMessageString(); - PropertyDescriptor msgDesc(thread, JSHandle::Cast(handleStr), true, false, true); - [[maybe_unused]] bool status = JSObject::DefineOwnProperty(thread, nativeInstanceObj, msgKey, msgDesc); + JSHandle msg_key = global_const->GetHandledMessageString(); + PropertyDescriptor msg_desc(thread, JSHandle::Cast(handle_str), true, false, true); + [[maybe_unused]] bool status = JSObject::DefineOwnProperty(thread, native_instance_obj, msg_key, msg_desc); ASSERT_PRINT(status, "return result exception!"); } - JSHandle handleStack = BuildEcmaStackTrace(thread); - JSHandle stackkey = globalConst->GetHandledStackString(); - PropertyDescriptor stackDesc(thread, JSHandle::Cast(handleStack), true, false, true); - [[maybe_unused]] bool status = JSObject::DefineOwnProperty(thread, nativeInstanceObj, stackkey, stackDesc); + JSHandle handle_stack = BuildEcmaStackTrace(thread); + JSHandle stackkey = global_const->GetHandledStackString(); + PropertyDescriptor stack_desc(thread, JSHandle::Cast(handle_stack), true, false, true); + [[maybe_unused]] bool status = JSObject::DefineOwnProperty(thread, native_instance_obj, stackkey, stack_desc); ASSERT_PRINT(status, "return result exception!"); // 5. Return O. - return nativeInstanceObj.GetTaggedValue(); + return native_instance_obj.GetTaggedValue(); } PandaString ErrorHelper::DecodeFunctionName(const PandaString &name) @@ -181,7 +181,7 @@ JSHandle ErrorHelper::BuildEcmaStackTrace(JSThread *thread) PandaString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread) { - auto ecmaVm = thread->GetEcmaVM(); + auto ecma_vm = thread->GetEcmaVM(); PandaString data; for (auto stack = StackWalker::Create(thread); stack.HasFrame(); stack.NextFrame()) { @@ -193,22 +193,22 @@ PandaString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread) data += DecodeFunctionName(JSMethod::Cast(method)->ParseFunctionName()); data.append(" ("); // source file - PtJSExtractor *debugExtractor = ecmaVm->GetDebugInfoExtractor(method->GetPandaFile()); - const PandaString &sourceFile = debugExtractor->GetSourceFile(method->GetFileId()); - if (sourceFile.empty()) { + PtJSExtractor *debug_extractor = ecma_vm->GetDebugInfoExtractor(method->GetPandaFile()); + const PandaString &source_file = debug_extractor->GetSourceFile(method->GetFileId()); + if (source_file.empty()) { data.push_back('?'); } else { - data += sourceFile; + data += source_file; } data.push_back(':'); // line number and column number - auto callbackFunc = [&data](size_t line, size_t column) -> bool { + auto callback_func = [&data](size_t line, size_t column) -> bool { data += ToPandaString(line + 1); data.push_back(':'); data += ToPandaString(column + 1); return true; }; - if (!debugExtractor->MatchWithOffset(callbackFunc, method->GetFileId(), stack.GetBytecodePc())) { + if (!debug_extractor->MatchWithOffset(callback_func, method->GetFileId(), stack.GetBytecodePc())) { data.push_back('?'); } data.push_back(')'); diff --git a/runtime/base/json_parser.cpp b/runtime/base/json_parser.cpp index 9cb10f43de045f17d5da9721202d86eca8a67f49..ff01897f13b472ba4e3b429ddd49a3d795eaec98 100644 --- a/runtime/base/json_parser.cpp +++ b/runtime/base/json_parser.cpp @@ -20,46 +20,46 @@ JSHandle Internalize::InternalizeJsonProperty(JSThread *thread, c const JSHandle &name, const JSHandle &receiver) { - JSHandle objHandle(holder); - JSHandle val = JSTaggedValue::GetProperty(thread, objHandle, name).GetValue(); - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle obj_handle(holder); + JSHandle val = JSTaggedValue::GetProperty(thread, obj_handle, name).GetValue(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); if (val->IsECMAObject()) { JSHandle obj = JSTaggedValue::ToObject(thread, val); - bool isArray = val->IsArray(thread); - if (isArray) { - JSHandle lenResult = JSTaggedValue::GetProperty(thread, val, lengthKey).GetValue(); + bool is_array = val->IsArray(thread); + if (is_array) { + JSHandle len_result = JSTaggedValue::GetProperty(thread, val, length_key).GetValue(); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread, lenResult); + JSTaggedNumber len_number = JSTaggedValue::ToLength(thread, len_result); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - uint32_t length = lenNumber.ToUint32(); - JSMutableHandle keyUnknow(thread, JSTaggedValue::Undefined()); - JSMutableHandle keyName(thread, JSTaggedValue::Undefined()); + uint32_t length = len_number.ToUint32(); + JSMutableHandle key_unknow(thread, JSTaggedValue::Undefined()); + JSMutableHandle key_name(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i++) { // Let prop be ! ToString((I)). - keyUnknow.Update(JSTaggedValue(i)); - keyName.Update(JSTaggedValue::ToString(thread, keyUnknow).GetTaggedValue()); - RecurseAndApply(thread, obj, keyName, receiver); + key_unknow.Update(JSTaggedValue(i)); + key_name.Update(JSTaggedValue::ToString(thread, key_unknow).GetTaggedValue()); + RecurseAndApply(thread, obj, key_name, receiver); } } else { // Let keys be ? EnumerableOwnPropertyNames(val, key). - JSHandle ownerNames(JSObject::EnumerableOwnNames(thread, obj)); + JSHandle owner_names(JSObject::EnumerableOwnNames(thread, obj)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - uint32_t namesLength = ownerNames->GetLength(); - JSMutableHandle keyName(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 0; i < namesLength; i++) { - keyName.Update(JSTaggedValue::GetProperty(thread, JSHandle(ownerNames), i) - .GetValue() - .GetTaggedValue()); - RecurseAndApply(thread, obj, keyName, receiver); + uint32_t names_length = owner_names->GetLength(); + JSMutableHandle key_name(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < names_length; i++) { + key_name.Update(JSTaggedValue::GetProperty(thread, JSHandle(owner_names), i) + .GetValue() + .GetTaggedValue()); + RecurseAndApply(thread, obj, key_name, receiver); } } } // Return ? Call(receiver, holder, « name, val »). - auto info = NewRuntimeCallInfo(thread, receiver, objHandle, JSTaggedValue::Undefined(), 2); + auto info = NewRuntimeCallInfo(thread, receiver, obj_handle, JSTaggedValue::Undefined(), 2); info->SetCallArgs(name, val); - JSTaggedValue result = JSFunction::Call(info.get()); // 2: two args + JSTaggedValue result = JSFunction::Call(info.Get()); // 2: two args return JSHandle(thread, result); } @@ -67,15 +67,15 @@ bool Internalize::RecurseAndApply(JSThread *thread, const JSHandle &ho const JSHandle &name, const JSHandle &receiver) { JSHandle value = InternalizeJsonProperty(thread, holder, name, receiver); - bool changeResult = false; + bool change_result = false; // If newElement is undefined, then Perform ? val.[[Delete]](P). if (value->IsUndefined()) { - changeResult = JSObject::DeleteProperty(thread, holder, name); + change_result = JSObject::DeleteProperty(thread, holder, name); } else { // Perform ? CreateDataProperty(val, P, newElement) - changeResult = JSObject::CreateDataProperty(thread, holder, name, value); + change_result = JSObject::CreateDataProperty(thread, holder, name, value); } - return changeResult; + return change_result; } } // namespace panda::ecmascript::base diff --git a/runtime/base/json_parser.h b/runtime/base/json_parser.h index 99b6854700e29ce61b8d507f703ed57b136fba34..dedf9468f76a3d8f8febea75346793c60675e43e 100644 --- a/runtime/base/json_parser.h +++ b/runtime/base/json_parser.h @@ -78,7 +78,7 @@ public: JSHandle ParseUtf8(EcmaString *str) { ASSERT(str != nullptr); - isAsciiString_ = true; + is_ascii_string_ = true; uint32_t len = str->GetUtf8Length(); PandaVector buf(len); str->CopyDataUtf8(buf.data(), len); @@ -97,16 +97,16 @@ public: } private: - template + template JSTaggedValue ParseJSONText() { SkipStartWhiteSpace(); Tokens token = ParseToken(); switch (token) { case Tokens::OBJECT: - return ParseObject(); + return ParseObject(); case Tokens::ARRAY: - return ParseArray(); + return ParseArray(); case Tokens::LITERAL_TRUE: return ParseLiteral("true", Tokens::LITERAL_TRUE); case Tokens::LITERAL_FALSE: @@ -114,27 +114,27 @@ private: case Tokens::LITERAL_NULL: return ParseLiteral("null", Tokens::LITERAL_NULL); case Tokens::NUMBER: - return ParseNumber(); + return ParseNumber(); case Tokens::STRING: - return ParseString(); + return ParseString(); default: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Text in JSON", JSTaggedValue::Exception()); } } - template + template JSTaggedValue ParseNumber() { - if (inObjOrArr) { - bool isFast = true; - bool isNumber = ReadNumberRange(isFast); - if (!isNumber) { + if (IN_OBJ_OR_ARR) { + bool is_fast = true; + bool is_number = ReadNumberRange(is_fast); + if (!is_number) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } - if (isFast) { - std::string strNum(current_, end_ + 1); + if (is_fast) { + std::string str_num(current_, end_ + 1); current_ = end_; - auto d = std::stod(strNum); + auto d = std::stod(str_num); if (es2panda::util::Helpers::IsInteger(d)) { return JSTaggedValue(static_cast(d)); } @@ -143,45 +143,45 @@ private: } Text current = current_; - bool hasExponent = false; + bool has_exponent = false; if (*current_ == '-') { if (UNLIKELY(current_++ == end_)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } } if (*current_ == '0') { - if (!CheckZeroBeginNumber(hasExponent)) { + if (!CheckZeroBeginNumber(has_exponent)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } } else if (*current_ >= '1' && *current_ <= '9') { - if (!CheckNonZeroBeginNumber(hasExponent)) { + if (!CheckNonZeroBeginNumber(has_exponent)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } } else { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Number in JSON", JSTaggedValue::Exception()); } - std::string strNum(current, end_ + 1); + std::string str_num(current, end_ + 1); current_ = end_; - return JSTaggedValue(std::stod(strNum)); + return JSTaggedValue(std::stod(str_num)); } - bool ReadJsonStringRange(bool &isFastString, bool &isAscii) + bool ReadJsonStringRange(bool &is_fast_string, bool &is_ascii) { current_++; - if (isAsciiString_) { - return ReadAsciiStringRange(isFastString); + if (is_ascii_string_) { + return ReadAsciiStringRange(is_fast_string); } - return ReadStringRange(isFastString, isAscii); + return ReadStringRange(is_fast_string, is_ascii); } - bool IsFastParseJsonString(bool &isFastString, bool &isAscii) + bool IsFastParseJsonString(bool &is_fast_string, bool &is_ascii) { current_++; - if (isAsciiString_) { - return IsFastParseString(isFastString, isAscii); + if (is_ascii_string_) { + return IsFastParseString(is_fast_string, is_ascii); } - return IsFastParseAsciiString(isFastString); + return IsFastParseAsciiString(is_fast_string); } bool ParseBackslash(PandaString &res) @@ -220,9 +220,9 @@ private: if (UNLIKELY(!ConvertStringUnicode(vec))) { return false; } - std::u16string u16Str; - u16Str.assign(vec.begin(), vec.end()); - res += base::StringHelper::U16stringToString(u16Str); + std::u16string u16_str; + u16_str.assign(vec.begin(), vec.end()); + res += base::StringHelper::U16stringToString(u16_str); break; } default: @@ -237,8 +237,8 @@ private: PandaString res; while (current_ <= end_) { if (*current_ == '\\') { - bool isLegalChar = ParseBackslash(res); - if (!isLegalChar) { + bool is_legal_char = ParseBackslash(res); + if (!is_legal_char) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected string in JSON", JSTaggedValue::Exception()); } } else { @@ -250,19 +250,19 @@ private: .GetTaggedValue(); } - template + template JSTaggedValue ParseString() { - bool isFastString = true; - bool isAscii = true; - bool isLegal = true; - if (inObjorArr) { - isLegal = ReadJsonStringRange(isFastString, isAscii); - if (!isLegal) { + bool is_fast_string = true; + bool is_ascii = true; + bool is_legal = true; + if (IN_OBJOR_ARR) { + is_legal = ReadJsonStringRange(is_fast_string, is_ascii); + if (!is_legal) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end Text in JSON", JSTaggedValue::Exception()); } - if (isFastString) { - if (isAscii) { + if (is_fast_string) { + if (is_ascii) { PandaString value(current_, end_); current_ = end_; return factory_ @@ -281,12 +281,12 @@ private: if (*end_ != '"' || current_ == end_) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end Text in JSON", JSTaggedValue::Exception()); } - isLegal = IsFastParseJsonString(isFastString, isAscii); - if (!isLegal) { + is_legal = IsFastParseJsonString(is_fast_string, is_ascii); + if (!is_legal) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected end Text in JSON", JSTaggedValue::Exception()); } - if (LIKELY(isFastString)) { - if (isAscii) { + if (LIKELY(is_fast_string)) { + if (is_ascii) { PandaString value(current_, end_); return factory_ ->NewFromUtf8LiteralUnCheck(reinterpret_cast(value.c_str()), value.length(), @@ -303,10 +303,10 @@ private: return SlowParseString(); } - template + template JSTaggedValue ParseArray() { - if (UNLIKELY(*range_ != ']' && !inObjorArr)) { + if (UNLIKELY(*range_ != ']' && !IN_OBJOR_ARR)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Array in JSON", JSTaggedValue::Exception()); } @@ -327,7 +327,7 @@ private: if (*current_ == ',') { current_++; } else if (*current_ == ']') { - if (inObjorArr || current_ == range_) { + if (IN_OBJOR_ARR || current_ == range_) { return arr.GetTaggedValue(); } THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Array in JSON", JSTaggedValue::Exception()); @@ -336,10 +336,10 @@ private: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Array in JSON", JSTaggedValue::Exception()); } - template + template JSTaggedValue ParseObject() { - if (UNLIKELY(*range_ != '}' && !inObjorArr)) { + if (UNLIKELY(*range_ != '}' && !IN_OBJOR_ARR)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); } @@ -351,14 +351,14 @@ private: return result.GetTaggedValue(); } - JSMutableHandle keyHandle(thread_, JSTaggedValue::Undefined()); + JSMutableHandle key_handle(thread_, JSTaggedValue::Undefined()); JSMutableHandle value(thread_, JSTaggedValue::Undefined()); while (current_ <= range_) { SkipStartWhiteSpace(); if (*current_ == '"') { - keyHandle.Update(ParseString()); + key_handle.Update(ParseString()); } else { - if (*current_ == '}' && (inObjorArr || current_ == range_)) { + if (*current_ == '}' && (IN_OBJOR_ARR || current_ == range_)) { return result.GetTaggedValue(); } THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); @@ -370,12 +370,12 @@ private: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); } value.Update(ParseJSONText()); - FastRuntimeStub::SetPropertyByValue(thread_, JSHandle(result), keyHandle, value); + FastRuntimeStub::SetPropertyByValue(thread_, JSHandle(result), key_handle, value); GetNextNonSpaceChar(); if (*current_ == ',') { current_++; } else if (*current_ == '}') { - if (inObjorArr || current_ == range_) { + if (IN_OBJOR_ARR || current_ == range_) { return result.GetTaggedValue(); } THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Object in JSON", JSTaggedValue::Exception()); @@ -444,17 +444,17 @@ private: } } - JSTaggedValue ParseLiteral(const PandaString &str, Tokens literalToken) + JSTaggedValue ParseLiteral(const PandaString &str, Tokens literal_token) { - uint32_t strLen = str.size() - 1; - uint32_t remainingLength = range_ - current_; - if (UNLIKELY(remainingLength < strLen)) { + uint32_t str_len = str.size() - 1; + uint32_t remaining_length = range_ - current_; + if (UNLIKELY(remaining_length < str_len)) { THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Text in JSON", JSTaggedValue::Exception()); } - bool isMatch = MatchText(str, strLen); - if (LIKELY(isMatch)) { - switch (literalToken) { + bool is_match = MatchText(str, str_len); + if (LIKELY(is_match)) { + switch (literal_token) { case Tokens::LITERAL_TRUE: return JSTaggedValue::True(); case Tokens::LITERAL_FALSE: @@ -468,31 +468,31 @@ private: THROW_SYNTAX_ERROR_AND_RETURN(thread_, "Unexpected Text in JSON", JSTaggedValue::Exception()); } - bool MatchText(const PandaString &str, uint32_t matchLen) + bool MatchText(const PandaString &str, uint32_t match_len) { const char *text = str.c_str(); uint32_t pos = 1; - while (pos <= matchLen) { + while (pos <= match_len) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (current_[pos] != text[pos]) { return false; } pos++; } - current_ += matchLen; + current_ += match_len; return true; } - bool ReadNumberRange(bool &isFast) + bool ReadNumberRange(bool &is_fast) { Text current = current_; if (*current == '0') { - isFast = false; + is_fast = false; current++; } else if (*current == '-') { current++; if (*current == '0') { - isFast = false; + is_fast = false; current++; } } @@ -503,7 +503,7 @@ private: continue; } if (IsNumberSignalCharacter(*current)) { - isFast = false; + is_fast = false; current++; continue; } @@ -551,7 +551,7 @@ private: return false; } - bool IsDecimalsLegal(bool &hasExponent) + bool IsDecimalsLegal(bool &has_exponent) { if (current_ == end_ && !IsNumberCharacter(*++current_)) { return false; @@ -563,14 +563,14 @@ private: continue; } if (*current_ == 'e' || *current_ == 'E') { - if (hasExponent || current_ == end_) { + if (has_exponent || current_ == end_) { return false; } current_++; if (!IsExponentNumber()) { return false; } - hasExponent = true; + has_exponent = true; } else { return false; } @@ -578,9 +578,9 @@ private: return true; } - bool IsExponentLegal(bool &hasExponent) + bool IsExponentLegal(bool &has_exponent) { - if (hasExponent || current_ == end_) { + if (has_exponent || current_ == end_) { return false; } current_++; @@ -596,7 +596,7 @@ private: return true; } - bool ReadStringRange(bool &isFast, bool &isAscii) + bool ReadStringRange(bool &is_fast, bool &is_ascii) { T c = 0; Text current = current_; @@ -611,9 +611,9 @@ private: if (*(current + 1) == '"') { current++; } - isFast = false; + is_fast = false; } - if (!IsLegalAsciiCharacter(c, isAscii)) { + if (!IsLegalAsciiCharacter(c, is_ascii)) { return false; } current++; @@ -621,7 +621,7 @@ private: return false; } - bool ReadAsciiStringRange(bool &isFast) + bool ReadAsciiStringRange(bool &is_fast) { T c = 0; Text current = current_; @@ -636,7 +636,7 @@ private: if (*(current + 1) == '"') { current++; } - isFast = false; + is_fast = false; } else if (UNLIKELY(c < CODE_SPACE)) { return false; } @@ -645,22 +645,22 @@ private: return false; } - bool IsFastParseString(bool &isFast, bool &isAscii) + bool IsFastParseString(bool &is_fast, bool &is_ascii) { Text current = current_; while (current != end_) { - if (!IsLegalAsciiCharacter(*current, isAscii)) { + if (!IsLegalAsciiCharacter(*current, is_ascii)) { return false; } if (*current == '\\') { - isFast = false; + is_fast = false; } current++; } return true; } - bool IsFastParseAsciiString(bool &isFast) + bool IsFastParseAsciiString(bool &is_fast) { Text current = current_; while (current != end_) { @@ -668,7 +668,7 @@ private: return false; } if (*current == '\\') { - isFast = false; + is_fast = false; } current++; } @@ -677,8 +677,8 @@ private: bool ConvertStringUnicode(PandaVector &vec) { - uint32_t remainingLength = end_ - current_; - if (remainingLength < UNICODE_DIGIT_LENGTH) { + uint32_t remaining_length = end_ - current_; + if (remaining_length < UNICODE_DIGIT_LENGTH) { return false; } uint16_t res = 0; @@ -709,15 +709,15 @@ private: return true; } - bool CheckZeroBeginNumber(bool &hasExponent) + bool CheckZeroBeginNumber(bool &has_exponent) { if (current_++ != end_) { if (*current_ == '.') { - if (!IsDecimalsLegal(hasExponent)) { + if (!IsDecimalsLegal(has_exponent)) { return false; } } else if (*current_ == 'e' || *current_ == 'E') { - if (!IsExponentLegal(hasExponent)) { + if (!IsExponentLegal(has_exponent)) { return false; } } else { @@ -727,7 +727,7 @@ private: return true; } - bool CheckNonZeroBeginNumber(bool &hasExponent) + bool CheckNonZeroBeginNumber(bool &has_exponent) { while (current_ != end_) { current_++; @@ -735,11 +735,11 @@ private: continue; } if (*current_ == '.') { - if (!IsDecimalsLegal(hasExponent)) { + if (!IsDecimalsLegal(has_exponent)) { return false; } } else if (*current_ == 'e' || *current_ == 'E') { - if (!IsExponentLegal(hasExponent)) { + if (!IsExponentLegal(has_exponent)) { return false; } } else { @@ -749,16 +749,16 @@ private: return true; } - bool IsLegalAsciiCharacter(T c, bool &isAscii) + bool IsLegalAsciiCharacter(T c, bool &is_ascii) { if (c <= ASCII_END) { return c >= CODE_SPACE; } - isAscii = false; + is_ascii = false; return true; } - bool isAsciiString_ {false}; + bool is_ascii_string_ {false}; Text end_ {nullptr}; Text current_ {nullptr}; Text range_ {nullptr}; diff --git a/runtime/base/json_stringifier.cpp b/runtime/base/json_stringifier.cpp index 088142db4290fbb7c1f908eef7ac1dfbc00a9598..dbfcdad99f021977d7c71a1e9b6567c88562587c 100644 --- a/runtime/base/json_stringifier.cpp +++ b/runtime/base/json_stringifier.cpp @@ -59,8 +59,8 @@ PandaString JsonStringifier::ValueToQuotedString(const PandaString &str) PandaString product; const char *value = str.c_str(); // fast mode - bool isFast = IsFastValueToQuotedString(value); - if (isFast) { + bool is_fast = IsFastValueToQuotedString(value); + if (is_fast) { product += "\""; product += str; product += "\""; @@ -141,14 +141,14 @@ JSHandle JsonStringifier::Stringify(const JSHandle const JSHandle &gap) { factory_ = thread_->GetEcmaVM()->GetFactory(); - handleValue_.Update(JSTaggedValue::Undefined()); - handleKey_.Update(JSTaggedValue::Undefined()); + handle_value_.Update(JSTaggedValue::Undefined()); + handle_key_.Update(JSTaggedValue::Undefined()); // Let isArray be IsArray(replacer). - bool isArray = replacer->IsArray(thread_); + bool is_array = replacer->IsArray(thread_); // ReturnIfAbrupt(isArray). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); // If isArray is true, then - if (isArray) { + if (is_array) { uint32_t len; if (replacer->IsJSArray()) { // FastPath @@ -156,16 +156,16 @@ JSHandle JsonStringifier::Stringify(const JSHandle len = arr->GetArrayLength(); } else { // Let len be ToLength(Get(replacer, "length")). - JSHandle lengthKey = thread_->GlobalConstants()->GetHandledLengthString(); - JSHandle lenResult = JSTaggedValue::GetProperty(thread_, replacer, lengthKey).GetValue(); + JSHandle length_key = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle len_result = JSTaggedValue::GetProperty(thread_, replacer, length_key).GetValue(); // ReturnIfAbrupt(len). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); - JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread_, lenResult); + JSTaggedNumber len_number = JSTaggedValue::ToLength(thread_, len_result); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); - len = lenNumber.ToUint32(); + len = len_number.ToUint32(); } if (len > 0) { - JSMutableHandle propHandle(thread_, JSTaggedValue::Undefined()); + JSMutableHandle prop_handle(thread_, JSTaggedValue::Undefined()); // Repeat while k JsonStringifier::Stringify(const JSHandle * i. Append item to the end of PropertyList. * h. Let k be k+1. */ - propHandle.Update(prop); + prop_handle.Update(prop); if (prop.IsNumber() || prop.IsString()) { - AddDeduplicateProp(propHandle); + AddDeduplicateProp(prop_handle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); } else if (prop.IsJSPrimitiveRef()) { JSTaggedValue primitive = JSPrimitiveRef::Cast(prop.GetTaggedObject())->GetValue(); if (primitive.IsNumber() || primitive.IsString()) { - AddDeduplicateProp(propHandle); + AddDeduplicateProp(prop_handle); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); } } @@ -234,10 +234,10 @@ JSHandle JsonStringifier::Stringify(const JSHandle return JSHandle(thread_, JSTaggedValue::Exception()); } - JSTaggedValue serializeValue = GetSerializeValue(JSHandle::Cast(wrapper), key, value, replacer); + JSTaggedValue serialize_value = GetSerializeValue(JSHandle::Cast(wrapper), key, value, replacer); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); - handleValue_.Update(serializeValue); - JSTaggedValue result = SerializeJSONProperty(handleValue_, replacer); + handle_value_.Update(serialize_value); + JSTaggedValue result = SerializeJSONProperty(handle_value_, replacer); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread_); if (!result.IsUndefined()) { return JSHandle( @@ -248,25 +248,25 @@ JSHandle JsonStringifier::Stringify(const JSHandle void JsonStringifier::AddDeduplicateProp(const JSHandle &property) { - uint32_t propLen = propList_.size(); - for (uint32_t i = 0; i < propLen; i++) { - if (JSTaggedValue::SameValue(propList_[i], property)) { + uint32_t prop_len = prop_list_.size(); + for (uint32_t i = 0; i < prop_len; i++) { + if (JSTaggedValue::SameValue(prop_list_[i], property)) { return; } } - JSHandle primString = JSTaggedValue::ToString(thread_, property); + JSHandle prim_string = JSTaggedValue::ToString(thread_, property); RETURN_IF_ABRUPT_COMPLETION(thread_); - JSHandle addVal(thread_, *primString); - propList_.emplace_back(addVal); + JSHandle add_val(thread_, *prim_string); + prop_list_.emplace_back(add_val); } bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) { - double numValue = gap.GetNumber(); - int num = static_cast(numValue); + double num_value = gap.GetNumber(); + int num = static_cast(num_value); if (num > 0) { - int gapLength = std::min(num, GAP_MAX_LEN); - for (int i = 0; i < gapLength; i++) { + int gap_length = std::min(num, GAP_MAX_LEN); + for (int i = 0; i < gap_length; i++) { gap_ += " "; } gap_.append("\0"); @@ -274,13 +274,13 @@ bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap) return true; } -bool JsonStringifier::CalculateStringGap(const JSHandle &primString) +bool JsonStringifier::CalculateStringGap(const JSHandle &prim_string) { - PandaString gapString = ConvertToPandaString(*primString); - int gapLen = gapString.length(); - if (gapLen > 0) { - int gapLength = std::min(gapLen, GAP_MAX_LEN); - PandaString str = gapString.substr(0, gapLength); + PandaString gap_string = ConvertToPandaString(*prim_string); + int gap_len = gap_string.length(); + if (gap_len > 0) { + int gap_length = std::min(gap_len, GAP_MAX_LEN); + PandaString str = gap_string.substr(0, gap_length); gap_ += str; gap_.append("\0"); } @@ -292,65 +292,65 @@ JSTaggedValue JsonStringifier::GetSerializeValue(const JSHandle & const JSHandle &value, const JSHandle &replacer) { - JSTaggedValue tagValue = value.GetTaggedValue(); + JSTaggedValue tag_value = value.GetTaggedValue(); // If Type(value) is Object, then if (value->IsECMAObject()) { // a. Let toJSON be Get(value, "toJSON"). - JSHandle toJson = thread_->GlobalConstants()->GetHandledToJsonString(); - JSHandle toJsonFun(thread_, FastRuntimeStub::FastGetPropertyByValue(thread_, value, toJson)); + JSHandle to_json = thread_->GlobalConstants()->GetHandledToJsonString(); + JSHandle to_json_fun(thread_, FastRuntimeStub::FastGetPropertyByValue(thread_, value, to_json)); // b. ReturnIfAbrupt(toJSON). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); // Reread tagValue because GC may move it in FastRuntimeStub::FastGetPropertyByValue - tagValue = value.GetTaggedValue(); + tag_value = value.GetTaggedValue(); // c. If IsCallable(toJSON) is true - if (UNLIKELY(toJsonFun->IsCallable())) { + if (UNLIKELY(to_json_fun->IsCallable())) { // Let value be Call(toJSON, value, «key»). - auto info = NewRuntimeCallInfo(thread_, toJsonFun, value, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread_, to_json_fun, value, JSTaggedValue::Undefined(), 1); info->SetCallArgs(key); - tagValue = JSFunction::Call(info.get()); + tag_value = JSFunction::Call(info.Get()); // ii. ReturnIfAbrupt(value). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } } if (UNLIKELY(replacer->IsCallable())) { - handleValue_.Update(tagValue); + handle_value_.Update(tag_value); // a. Let value be Call(ReplacerFunction, holder, «key, value»). auto info = NewRuntimeCallInfo(thread_, replacer, object, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(key, handleValue_); - tagValue = JSFunction::Call(info.get()); // 2: two args + info->SetCallArgs(key, handle_value_); + tag_value = JSFunction::Call(info.Get()); // 2: two args // b. ReturnIfAbrupt(value). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } - return tagValue; + return tag_value; } JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle &value, const JSHandle &replacer) { - JSTaggedValue tagValue = value.GetTaggedValue(); - if (!tagValue.IsHeapObject()) { - TaggedType type = tagValue.GetRawData(); + JSTaggedValue tag_value = value.GetTaggedValue(); + if (!tag_value.IsHeapObject()) { + TaggedType type = tag_value.GetRawData(); switch (type) { // If value is false, return "false". case JSTaggedValue::VALUE_FALSE: result_ += "false"; - return tagValue; + return tag_value; // If value is true, return "true". case JSTaggedValue::VALUE_TRUE: result_ += "true"; - return tagValue; + return tag_value; // If value is null, return "null". case JSTaggedValue::VALUE_NULL: result_ += "null"; - return tagValue; + return tag_value; default: // If Type(value) is Number, then - if (tagValue.IsNumber()) { + if (tag_value.IsNumber()) { // a. If value is finite, return ToString(value). - if (std::isfinite(tagValue.GetNumber())) { - result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, tagValue)); + if (std::isfinite(tag_value.GetNumber())) { + result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, tag_value)); } else { // b. Else, return "null". result_ += "null"; @@ -358,41 +358,41 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandleGetClass()->GetObjectType(); - JSHandle valHandle(thread_, tagValue); - switch (jsType) { + JSType js_type = tag_value.GetTaggedObject()->GetClass()->GetObjectType(); + JSHandle val_handle(thread_, tag_value); + switch (js_type) { case JSType::JS_ARRAY: { - SerializeJSArray(valHandle, replacer); + SerializeJSArray(val_handle, replacer); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); - return valHandle.GetTaggedValue(); + return val_handle.GetTaggedValue(); } // If Type(value) is String, return QuoteJSONString(value). case JSType::STRING: { - PandaString str = ConvertToPandaString(*JSHandle(valHandle)); + PandaString str = ConvertToPandaString(*JSHandle(val_handle)); str = ValueToQuotedString(str); result_ += str; - return valHandle.GetTaggedValue(); + return val_handle.GetTaggedValue(); } case JSType::JS_PRIMITIVE_REF: { - SerilaizePrimitiveRef(valHandle); - return valHandle.GetTaggedValue(); + SerilaizePrimitiveRef(val_handle); + return val_handle.GetTaggedValue(); } case JSType::SYMBOL: return JSTaggedValue::Undefined(); default: { - if (!valHandle->IsCallable()) { - if (UNLIKELY(valHandle->IsJSProxy())) { - SerializeJSProxy(valHandle, replacer); + if (!val_handle->IsCallable()) { + if (UNLIKELY(val_handle->IsJSProxy())) { + SerializeJSProxy(val_handle, replacer); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } else { - SerializeJSONObject(valHandle, replacer); + SerializeJSONObject(val_handle, replacer); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } - return valHandle.GetTaggedValue(); + return val_handle.GetTaggedValue(); } } } @@ -400,17 +400,17 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle &key, bool hasContent) +void JsonStringifier::SerializeObjectKey(const JSHandle &key, bool has_content) { - PandaString stepBegin; - PandaString stepEnd; - if (hasContent) { + PandaString step_begin; + PandaString step_end; + if (has_content) { result_ += ","; } if (!gap_.empty()) { - stepBegin += "\n"; - stepBegin += indent_; - stepEnd += " "; + step_begin += "\n"; + step_begin += indent_; + step_end += " "; } PandaString str; if (key->IsString()) { @@ -420,18 +420,18 @@ void JsonStringifier::SerializeObjectKey(const JSHandle &key, boo } else { str = ConvertToPandaString(*JSTaggedValue::ToString(thread_, key)); } - result_ += stepBegin; + result_ += step_begin; str = ValueToQuotedString(str); result_ += str; result_ += ":"; - result_ += stepEnd; + result_ += step_end; } bool JsonStringifier::PushValue(const JSHandle &value) { - uint32_t thisLen = stack_.size(); + uint32_t this_len = stack_.size(); - for (uint32_t i = 0; i < thisLen; i++) { + for (uint32_t i = 0; i < this_len; i++) { bool equal = JSTaggedValue::SameValue(stack_[i].GetTaggedValue(), value.GetTaggedValue()); if (equal) { return true; @@ -449,8 +449,8 @@ void JsonStringifier::PopValue() bool JsonStringifier::SerializeJSONObject(const JSHandle &value, const JSHandle &replacer) { - bool isContain = PushValue(value); - if (isContain) { + bool is_contain = PushValue(value); + if (is_contain) { THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value", true); } @@ -458,42 +458,42 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, indent_ += gap_; result_ += "{"; - bool hasContent = false; + bool has_content = false; JSHandle obj(value); if (!replacer->IsArray(thread_)) { - uint32_t numOfKeys = obj->GetNumberOfKeys(); - uint32_t numOfElements = obj->GetNumberOfElements(); - if (numOfElements > 0) { - hasContent = JsonStringifier::SerializeElements(obj, replacer, hasContent); + uint32_t num_of_keys = obj->GetNumberOfKeys(); + uint32_t num_of_elements = obj->GetNumberOfElements(); + if (num_of_elements > 0) { + has_content = JsonStringifier::SerializeElements(obj, replacer, has_content); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } - if (numOfKeys > 0) { - hasContent = JsonStringifier::SerializeKeys(obj, replacer, hasContent); + if (num_of_keys > 0) { + has_content = JsonStringifier::SerializeKeys(obj, replacer, has_content); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } else { - uint32_t propLen = propList_.size(); - for (uint32_t i = 0; i < propLen; i++) { - JSTaggedValue tagVal = - FastRuntimeStub::FastGetPropertyByValue(thread_, JSHandle(obj), propList_[i]); - handleValue_.Update(tagVal); - JSTaggedValue serializeValue = GetSerializeValue(value, propList_[i], handleValue_, replacer); + uint32_t prop_len = prop_list_.size(); + for (uint32_t i = 0; i < prop_len; i++) { + JSTaggedValue tag_val = + FastRuntimeStub::FastGetPropertyByValue(thread_, JSHandle(obj), prop_list_[i]); + handle_value_.Update(tag_val); + JSTaggedValue serialize_value = GetSerializeValue(value, prop_list_[i], handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - if (UNLIKELY(serializeValue.IsUndefined() || serializeValue.IsSymbol() || - (serializeValue.IsECMAObject() && serializeValue.IsCallable()))) { + if (UNLIKELY(serialize_value.IsUndefined() || serialize_value.IsSymbol() || + (serialize_value.IsECMAObject() && serialize_value.IsCallable()))) { continue; } - handleValue_.Update(serializeValue); - SerializeObjectKey(propList_[i], hasContent); - JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); + handle_value_.Update(serialize_value); + SerializeObjectKey(prop_list_[i], has_content); + JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (!res.IsUndefined()) { - hasContent = true; + has_content = true; } } } - if (hasContent && gap_.length() != 0) { + if (has_content && gap_.length() != 0) { result_ += "\n"; result_ += stepback; } @@ -505,39 +505,39 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, bool JsonStringifier::SerializeJSProxy(const JSHandle &object, const JSHandle &replacer) { - bool isContain = PushValue(object); - if (isContain) { + bool is_contain = PushValue(object); + if (is_contain) { THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value", true); } PandaString stepback = indent_; - PandaString stepBegin; + PandaString step_begin; indent_ += gap_; if (!gap_.empty()) { - stepBegin += "\n"; - stepBegin += indent_; + step_begin += "\n"; + step_begin += indent_; } result_ += "["; JSHandle proxy(object); - JSHandle lengthKey = thread_->GlobalConstants()->GetHandledLengthString(); - JSHandle lenghHandle = JSProxy::GetProperty(thread_, proxy, lengthKey).GetValue(); + JSHandle length_key = thread_->GlobalConstants()->GetHandledLengthString(); + JSHandle lengh_handle = JSProxy::GetProperty(thread_, proxy, length_key).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread_, lenghHandle); + JSTaggedNumber len_number = JSTaggedValue::ToLength(thread_, lengh_handle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - uint32_t length = lenNumber.ToUint32(); + uint32_t length = len_number.ToUint32(); for (uint32_t i = 0; i < length; i++) { - handleKey_.Update(JSTaggedValue(i)); - JSHandle valHandle = JSProxy::GetProperty(thread_, proxy, handleKey_).GetValue(); + handle_key_.Update(JSTaggedValue(i)); + JSHandle val_handle = JSProxy::GetProperty(thread_, proxy, handle_key_).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (i > 0) { result_ += ","; } - result_ += stepBegin; - JSTaggedValue serializeValue = GetSerializeValue(object, handleKey_, valHandle, replacer); + result_ += step_begin; + JSTaggedValue serialize_value = GetSerializeValue(object, handle_key_, val_handle, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - handleValue_.Update(serializeValue); - JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); + handle_value_.Update(serialize_value); + JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (res.IsUndefined()) { result_ += "null"; @@ -557,39 +557,39 @@ bool JsonStringifier::SerializeJSProxy(const JSHandle &object, co bool JsonStringifier::SerializeJSArray(const JSHandle &value, const JSHandle &replacer) { // If state.[[Stack]] contains value, throw a TypeError exception because the structure is cyclical. - bool isContain = PushValue(value); - if (isContain) { + bool is_contain = PushValue(value); + if (is_contain) { THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value", true); } PandaString stepback = indent_; - PandaString stepBegin; + PandaString step_begin; indent_ += gap_; if (!gap_.empty()) { - stepBegin += "\n"; - stepBegin += indent_; + step_begin += "\n"; + step_begin += indent_; } result_ += "["; - JSHandle jsArr(value); - uint32_t len = jsArr->GetArrayLength(); + JSHandle js_arr(value); + uint32_t len = js_arr->GetArrayLength(); if (len > 0) { for (uint32_t i = 0; i < len; i++) { - JSTaggedValue tagVal = FastRuntimeStub::FastGetPropertyByIndex(thread_, value.GetTaggedValue(), i); - if (UNLIKELY(tagVal.IsAccessor())) { - tagVal = JSObject::CallGetter(thread_, AccessorData::Cast(tagVal.GetTaggedObject()), value); + JSTaggedValue tag_val = FastRuntimeStub::FastGetPropertyByIndex(thread_, value.GetTaggedValue(), i); + if (UNLIKELY(tag_val.IsAccessor())) { + tag_val = JSObject::CallGetter(thread_, AccessorData::Cast(tag_val.GetTaggedObject()), value); } - handleValue_.Update(tagVal); - handleKey_.Update(JSTaggedNumber(i).ToString(thread_).GetTaggedValue()); + handle_value_.Update(tag_val); + handle_key_.Update(JSTaggedNumber(i).ToString(thread_).GetTaggedValue()); if (i > 0) { result_ += ","; } - result_ += stepBegin; - JSTaggedValue serializeValue = GetSerializeValue(value, handleKey_, handleValue_, replacer); + result_ += step_begin; + JSTaggedValue serialize_value = GetSerializeValue(value, handle_key_, handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - handleValue_.Update(serializeValue); - JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); + handle_value_.Update(serialize_value); + JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (res.IsUndefined()) { result_ += "null"; @@ -608,20 +608,20 @@ bool JsonStringifier::SerializeJSArray(const JSHandle &value, con return true; } -void JsonStringifier::SerilaizePrimitiveRef(const JSHandle &primitiveRef) +void JsonStringifier::SerilaizePrimitiveRef(const JSHandle &primitive_ref) { - JSTaggedValue primitive = JSPrimitiveRef::Cast(primitiveRef.GetTaggedValue().GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(primitive_ref.GetTaggedValue().GetTaggedObject())->GetValue(); if (primitive.IsString()) { - auto priStr = JSTaggedValue::ToString(thread_, primitiveRef); + auto pri_str = JSTaggedValue::ToString(thread_, primitive_ref); RETURN_IF_ABRUPT_COMPLETION(thread_); - PandaString str = ConvertToPandaString(*priStr); + PandaString str = ConvertToPandaString(*pri_str); str = ValueToQuotedString(str); result_ += str; } else if (primitive.IsNumber()) { - auto priNum = JSTaggedValue::ToNumber(thread_, primitiveRef); + auto pri_num = JSTaggedValue::ToNumber(thread_, primitive_ref); RETURN_IF_ABRUPT_COMPLETION(thread_); - if (std::isfinite(priNum.GetNumber())) { - result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, priNum)); + if (std::isfinite(pri_num.GetNumber())) { + result_ += ConvertToPandaString(*base::NumberHelper::NumberToString(thread_, pri_num)); } else { result_ += "null"; } @@ -631,63 +631,63 @@ void JsonStringifier::SerilaizePrimitiveRef(const JSHandle &primi } bool JsonStringifier::SerializeElements(const JSHandle &obj, const JSHandle &replacer, - bool hasContent) + bool has_content) { - JSHandle elementsArr(thread_, obj->GetElements()); - if (!elementsArr->IsDictionaryMode()) { - uint32_t elementsLen = elementsArr->GetLength(); - for (uint32_t i = 0; i < elementsLen; ++i) { - if (!elementsArr->Get(i).IsHole()) { - handleKey_.Update(JSTaggedValue(i)); - handleValue_.Update(elementsArr->Get(i)); - hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); + JSHandle elements_arr(thread_, obj->GetElements()); + if (!elements_arr->IsDictionaryMode()) { + uint32_t elements_len = elements_arr->GetLength(); + for (uint32_t i = 0; i < elements_len; ++i) { + if (!elements_arr->Get(i).IsHole()) { + handle_key_.Update(JSTaggedValue(i)); + handle_value_.Update(elements_arr->Get(i)); + has_content = JsonStringifier::AppendJsonString(obj, replacer, has_content); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } } else { - JSHandle numberDic(elementsArr); - PandaVector> sortArr; - int size = numberDic->Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key = numberDic->GetKey(hashIndex); + JSHandle number_dic(elements_arr); + PandaVector> sort_arr; + int size = number_dic->Size(); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key = number_dic->GetKey(hash_index); if (!key.IsUndefined() && !key.IsHole()) { - PropertyAttributes attr = numberDic->GetAttributes(hashIndex); + PropertyAttributes attr = number_dic->GetAttributes(hash_index); if (attr.IsEnumerable()) { - auto numberKey = JSTaggedValue(static_cast(key.GetInt())); - sortArr.emplace_back(JSHandle(thread_, numberKey)); + auto number_key = JSTaggedValue(static_cast(key.GetInt())); + sort_arr.emplace_back(JSHandle(thread_, number_key)); } } } - std::sort(sortArr.begin(), sortArr.end(), CompareNumber); - for (const auto &entry : sortArr) { - JSTaggedValue entryKey = entry.GetTaggedValue(); - handleKey_.Update(entryKey); - int index = numberDic->FindEntry(entryKey); - JSTaggedValue value = numberDic->GetValue(index); - handleValue_.Update(value); - hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); + std::sort(sort_arr.begin(), sort_arr.end(), CompareNumber); + for (const auto &entry : sort_arr) { + JSTaggedValue entry_key = entry.GetTaggedValue(); + handle_key_.Update(entry_key); + int index = number_dic->FindEntry(entry_key); + JSTaggedValue value = number_dic->GetValue(index); + handle_value_.Update(value); + has_content = JsonStringifier::AppendJsonString(obj, replacer, has_content); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } - return hasContent; + return has_content; } bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandle &replacer, - bool hasContent) + bool has_content) { - JSHandle ownKeys = JSTaggedValue::GetOwnPropertyKeys(thread_, JSHandle(obj)); + JSHandle own_keys = JSTaggedValue::GetOwnPropertyKeys(thread_, JSHandle(obj)); - uint32_t length = ownKeys->GetLength(); + uint32_t length = own_keys->GetLength(); for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = ownKeys->Get(thread_, i); + JSTaggedValue key = own_keys->Get(thread_, i); if (!key.IsString()) { continue; } - handleKey_.Update(key); + handle_key_.Update(key); TaggedArray *properties = TaggedArray::Cast(obj->GetProperties().GetHeapObject()); PropertyAttributes attr; - uint32_t indexOrEntry = 0; - JSTaggedValue value = FastRuntimeStub::FindOwnProperty(thread_, *obj, properties, key, &attr, &indexOrEntry); + uint32_t index_or_entry = 0; + JSTaggedValue value = FastRuntimeStub::FindOwnProperty(thread_, *obj, properties, key, &attr, &index_or_entry); if (!value.IsHole()) { if (!attr.IsEnumerable()) { continue; @@ -700,29 +700,30 @@ bool JsonStringifier::SerializeKeys(const JSHandle &obj, const JSHandl } else { value = JSTaggedValue::Undefined(); } - handleValue_.Update(value); - hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent); + handle_value_.Update(value); + has_content = JsonStringifier::AppendJsonString(obj, replacer, has_content); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } - return hasContent; + return has_content; } bool JsonStringifier::AppendJsonString(const JSHandle &obj, const JSHandle &replacer, - bool hasContent) + bool has_content) { - JSTaggedValue serializeValue = GetSerializeValue(JSHandle(obj), handleKey_, handleValue_, replacer); + JSTaggedValue serialize_value = + GetSerializeValue(JSHandle(obj), handle_key_, handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); - if (UNLIKELY(serializeValue.IsUndefined() || serializeValue.IsSymbol() || - (serializeValue.IsECMAObject() && serializeValue.IsCallable()))) { - return hasContent; + if (UNLIKELY(serialize_value.IsUndefined() || serialize_value.IsSymbol() || + (serialize_value.IsECMAObject() && serialize_value.IsCallable()))) { + return has_content; } - handleValue_.Update(serializeValue); - SerializeObjectKey(handleKey_, hasContent); - JSTaggedValue res = SerializeJSONProperty(handleValue_, replacer); + handle_value_.Update(serialize_value); + SerializeObjectKey(handle_key_, has_content); + JSTaggedValue res = SerializeJSONProperty(handle_value_, replacer); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); if (!res.IsUndefined()) { return true; } - return hasContent; + return has_content; } } // namespace panda::ecmascript::base diff --git a/runtime/base/json_stringifier.h b/runtime/base/json_stringifier.h index fed09e9102f56ef92a9937f74c87d177e0d92036..99a98608ab0d03d04a4d10b750252996cb5a9dd0 100644 --- a/runtime/base/json_stringifier.h +++ b/runtime/base/json_stringifier.h @@ -26,8 +26,8 @@ class JsonStringifier { public: explicit JsonStringifier(JSThread *thread) : thread_(thread), - handleKey_(thread, JSTaggedValue::Undefined()), - handleValue_(thread, JSTaggedValue::Undefined()) + handle_key_(thread, JSTaggedValue::Undefined()), + handle_value_(thread, JSTaggedValue::Undefined()) { } @@ -48,14 +48,14 @@ private: JSTaggedValue SerializeJSONProperty(const JSHandle &value, const JSHandle &replacer); JSTaggedValue GetSerializeValue(const JSHandle &object, const JSHandle &key, const JSHandle &value, const JSHandle &replacer); - void SerializeObjectKey(const JSHandle &key, bool hasContent); + void SerializeObjectKey(const JSHandle &key, bool has_content); bool SerializeJSONObject(const JSHandle &value, const JSHandle &replacer); bool SerializeJSArray(const JSHandle &value, const JSHandle &replacer); bool SerializeJSProxy(const JSHandle &object, const JSHandle &replacer); - void SerilaizePrimitiveRef(const JSHandle &primitiveRef); + void SerilaizePrimitiveRef(const JSHandle &primitive_ref); bool PushValue(const JSHandle &value); @@ -63,10 +63,10 @@ private: bool CalculateNumberGap(JSTaggedValue gap); - bool CalculateStringGap(const JSHandle &primString); - bool AppendJsonString(const JSHandle &obj, const JSHandle &replacer, bool hasContent); - bool SerializeElements(const JSHandle &obj, const JSHandle &replacer, bool hasContent); - bool SerializeKeys(const JSHandle &obj, const JSHandle &replacer, bool hasContent); + bool CalculateStringGap(const JSHandle &prim_string); + bool AppendJsonString(const JSHandle &obj, const JSHandle &replacer, bool has_content); + bool SerializeElements(const JSHandle &obj, const JSHandle &replacer, bool has_content); + bool SerializeKeys(const JSHandle &obj, const JSHandle &replacer, bool has_content); static inline bool CompareKey(const std::pair, PropertyAttributes> &a, const std::pair, PropertyAttributes> &b) @@ -85,9 +85,9 @@ private: JSThread *thread_ {nullptr}; ObjectFactory *factory_ {nullptr}; PandaVector> stack_; - PandaVector> propList_; - JSMutableHandle handleKey_; - JSMutableHandle handleValue_; + PandaVector> prop_list_; + JSMutableHandle handle_key_; + JSMutableHandle handle_value_; }; } // namespace panda::ecmascript::base #endif // ECMASCRIPT_BASE_JSON_STRINGIFY_INL_H diff --git a/runtime/base/number_helper.cpp b/runtime/base/number_helper.cpp index c5a9423392efeb670b7713836d71ca491ab77116..cf38bc14d6394b47a44b6ce845b795c228c4b97a 100644 --- a/runtime/base/number_helper.cpp +++ b/runtime/base/number_helper.cpp @@ -173,11 +173,11 @@ JSTaggedValue NumberHelper::DoubleToPrecision(JSThread *thread, double number, i return DoubleToFixed(thread, number, digit - 1); } PandaStringStream ss; - double positiveNumber = number > 0 ? number : -number; - int log_digit = std::floor(log10(positiveNumber)); + double positive_number = number > 0 ? number : -number; + int log_digit = std::floor(log10(positive_number)); int radix_digit = digit - log_digit - 1; - const int MAX_EXPONENT_DIGIT = 6; - if ((log_digit >= 0 && radix_digit >= 0) || (log_digit < 0 && radix_digit <= MAX_EXPONENT_DIGIT)) { + const int max_exponent_digit = 6; + if ((log_digit >= 0 && radix_digit >= 0) || (log_digit < 0 && radix_digit <= max_exponent_digit)) { return DoubleToFixed(thread, number, std::abs(radix_digit)); } return DoubleToExponential(thread, number, digit - 1); @@ -186,19 +186,19 @@ 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 nanResult = BuiltinsBase::GetTaggedDouble(NAN_VALUE); + JSTaggedValue nan_result = BuiltinsBase::GetTaggedDouble(NAN_VALUE); // 1. skip space and line terminal if (!NumberHelper::GotoNonspace(&p, end)) { - return nanResult; + return nan_result; } // 2. sign bit bool negative = false; if (*p == '-') { negative = true; - RETURN_IF_CONVERSION_END(++p, end, nanResult); + RETURN_IF_CONVERSION_END(++p, end, nan_result); } else if (*p == '+') { - RETURN_IF_CONVERSION_END(++p, end, nanResult); + RETURN_IF_CONVERSION_END(++p, end, nan_result); } // 3. 0x or 0X bool strip_prefix = true; @@ -207,7 +207,7 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const // b. If R  16, let strip_prefix be false. if (radix != 0) { if (radix < MIN_RADIX || radix > MAX_RADIX) { - return nanResult; + return nan_result; } if (radix != HEXADECIMAL) { strip_prefix = false; @@ -220,28 +220,28 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const if (*p == '0') { size++; if (++p != end && (*p == 'x' || *p == 'X')) { - RETURN_IF_CONVERSION_END(++p, end, nanResult); + RETURN_IF_CONVERSION_END(++p, end, nan_result); radix = HEXADECIMAL; } } } double result = 0; - bool isDone = false; + bool is_done = false; do { double part = 0; uint32_t multiplier = 1; for (; p != end; ++p) { // The maximum value to ensure that uint32_t will not overflow - const uint32_t MAX_MULTIPER = 0xffffffffU / 36; + const uint32_t max_multiper = 0xffffffffU / 36; uint32_t m = multiplier * radix; - if (m > MAX_MULTIPER) { + if (m > max_multiper) { break; } int current_bit = ToDigit(*p); if (current_bit >= radix) { - isDone = true; + is_done = true; break; } size++; @@ -249,13 +249,13 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const multiplier = m; } result = result * multiplier + part; - if (isDone) { + if (is_done) { break; } } while (p != end); if (size == 0) { - return nanResult; + return nan_result; } if (negative) { @@ -326,22 +326,22 @@ PandaString NumberHelper::IntToString(int number) return ToPandaString(number); } -JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle strVal) +JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle str_val) { Span str; - auto strObj = static_cast(strVal->GetTaggedObject()); - size_t strLen = strObj->GetLength(); - if (strLen == 0) { + auto str_obj = static_cast(str_val->GetTaggedObject()); + size_t str_len = str_obj->GetLength(); + if (str_len == 0) { return BigInt::Int32ToBigInt(thread, 0).GetTaggedValue(); } - if (UNLIKELY(strObj->IsUtf16())) { + if (UNLIKELY(str_obj->IsUtf16())) { PandaVector buf; - size_t len = utf::Utf16ToUtf8Size(strObj->GetDataUtf16(), strLen) - 1; + size_t len = utf::Utf16ToUtf8Size(str_obj->GetDataUtf16(), str_len) - 1; buf.reserve(len); - len = utf::ConvertRegionUtf16ToUtf8(strObj->GetDataUtf16(), buf.data(), strLen, len, 0); + len = utf::ConvertRegionUtf16ToUtf8(str_obj->GetDataUtf16(), buf.data(), str_len, len, 0); str = Span(buf.data(), len); } else { - str = Span(strObj->GetDataUtf8(), strLen); + str = Span(str_obj->GetDataUtf8(), str_len); } auto p = const_cast(str.begin()); auto end = str.end(); @@ -389,7 +389,7 @@ JSTaggedValue NumberHelper::StringToBigInt(JSThread *thread, JSHandle= radix) { - if (pStart != p && !NumberHelper::GotoNonspace(&p, end)) { + if (p_start != p && !NumberHelper::GotoNonspace(&p, end)) { break; } return JSTaggedValue(NAN_VALUE); @@ -428,48 +428,48 @@ JSTaggedValue NumberHelper::Pow(double base, double exponent) // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic) static inline void GetBase(double d, uint8_t digits, int &decpt, std::array &buf, - std::array &bufTmp, int size) + std::array &buf_tmp, int size) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - [[maybe_unused]] int result1 = snprintf_s(bufTmp.data(), size, size - 1, "%+.*e", digits - 1, d); + [[maybe_unused]] int result1 = snprintf_s(buf_tmp.data(), size, size - 1, "%+.*e", digits - 1, d); ASSERT(result1 != -1); // mantissa - buf[0] = bufTmp[1]; + buf[0] = buf_tmp[1]; if (digits > 1) { [[maybe_unused]] int result2 = - memcpy_s(buf.data() + 1, digits, bufTmp.data() + 2, digits); // 2 means add the point char to buf + memcpy_s(buf.data() + 1, digits, buf_tmp.data() + 2, digits); // 2 means add the point char to buf ASSERT(result2 == EOK); } buf[digits + 1] = '\0'; // exponent - constexpr uint8_t base = 10; - decpt = strtol(bufTmp.data() + digits + 2 + static_cast(digits > 1), nullptr, base) + + constexpr uint8_t BASE = 10; + decpt = strtol(buf_tmp.data() + digits + 2 + static_cast(digits > 1), nullptr, BASE) + 1; // 2 means ignore the integer and point } static inline int GetMinmumDigits(double d, int &decpt, std::array &buf) { uint8_t digits = 0; - std::array bufTmp = {0}; + std::array buf_tmp = {0}; // find the minimum amount of digits - uint8_t MinDigits = 1; - uint8_t MaxDigits = DOUBLE_MAX_PRECISION; - while (MinDigits < MaxDigits) { - digits = (MinDigits + MaxDigits) / 2; - GetBase(d, digits, decpt, buf, bufTmp, bufTmp.size()); - if (std::strtod(bufTmp.data(), nullptr) == d) { + uint8_t min_digits = 1; + uint8_t max_digits = DOUBLE_MAX_PRECISION; + while (min_digits < max_digits) { + digits = (min_digits + max_digits) / 2; + GetBase(d, digits, decpt, buf, buf_tmp, buf_tmp.size()); + if (std::strtod(buf_tmp.data(), nullptr) == d) { // no need to keep the trailing zeros while (digits >= 2 && buf[digits] == '0') { // 2 means ignore the integer and point digits--; } - MaxDigits = digits; + max_digits = digits; } else { - MinDigits = digits + 1; + min_digits = digits + 1; } } - digits = MaxDigits; - GetBase(d, digits, decpt, buf, bufTmp, bufTmp.size()); + digits = max_digits; + GetBase(d, digits, decpt, buf, buf_tmp, buf_tmp.size()); return digits; } @@ -582,7 +582,7 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); sign = Sign::NEG; } - bool ignoreTrailing = (flags & IGNORE_TRAILING) != 0; + bool ignore_trailing = (flags & IGNORE_TRAILING) != 0; // 3. judge Infinity static const char INF[] = "Infinity"; // NOLINT(modernize-avoid-c-arrays) @@ -594,84 +594,84 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui } } ++p; - if (!ignoreTrailing && NumberHelper::GotoNonspace(&p, end)) { + if (!ignore_trailing && NumberHelper::GotoNonspace(&p, end)) { return NAN_VALUE; } return sign == Sign::NEG ? -POSITIVE_INFINITY : POSITIVE_INFINITY; } // 4. get number radix - bool leadingZero = false; - bool prefixRadix = false; + bool leading_zero = false; + bool prefix_radix = false; if (*p == '0' && radix == 0) { RETURN_IF_CONVERSION_END(++p, end, SignedZero(sign)); if (*p == 'x' || *p == 'X') { if ((flags & ALLOW_HEX) == 0) { - return ignoreTrailing ? SignedZero(sign) : NAN_VALUE; + return ignore_trailing ? SignedZero(sign) : NAN_VALUE; } RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); if (sign != Sign::NONE) { return NAN_VALUE; } - prefixRadix = true; + prefix_radix = true; radix = HEXADECIMAL; } else if (*p == 'o' || *p == 'O') { if ((flags & ALLOW_OCTAL) == 0) { - return ignoreTrailing ? SignedZero(sign) : NAN_VALUE; + return ignore_trailing ? SignedZero(sign) : NAN_VALUE; } RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); if (sign != Sign::NONE) { return NAN_VALUE; } - prefixRadix = true; + prefix_radix = true; radix = OCTAL; } else if (*p == 'b' || *p == 'B') { if ((flags & ALLOW_BINARY) == 0) { - return ignoreTrailing ? SignedZero(sign) : NAN_VALUE; + return ignore_trailing ? SignedZero(sign) : NAN_VALUE; } RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); if (sign != Sign::NONE) { return NAN_VALUE; } - prefixRadix = true; + prefix_radix = true; radix = BINARY; } else { - leadingZero = true; + leading_zero = true; } } if (radix == 0) { radix = DECIMAL; } - auto pStart = p; + auto p_start = p; // 5. skip leading '0' while (*p == '0') { RETURN_IF_CONVERSION_END(++p, end, SignedZero(sign)); - leadingZero = true; + leading_zero = true; } // 6. parse to number - uint64_t intNumber = 0; - uint64_t numberMax = (UINT64_MAX - (radix - 1)) / radix; + uint64_t int_number = 0; + uint64_t number_max = (UINT64_MAX - (radix - 1)) / radix; int digits = 0; int exponent = 0; do { uint8_t c = ToDigit(*p); if (c >= radix) { - if (!prefixRadix || ignoreTrailing || (pStart != p && !NumberHelper::GotoNonspace(&p, end))) { + if (!prefix_radix || ignore_trailing || (p_start != p && !NumberHelper::GotoNonspace(&p, end))) { break; } // "0b" "0x1.2" "0b1e2" ... return NAN_VALUE; } ++digits; - if (intNumber < numberMax) { - intNumber = intNumber * radix + c; + if (int_number < number_max) { + int_number = int_number * radix + c; } else { ++exponent; } } while (++p != end); - auto number = static_cast(intNumber); + auto number = static_cast(int_number); if (sign == Sign::NEG) { if (number == 0) { number = -0.0; @@ -682,7 +682,7 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui // 7. deal with other radix except DECIMAL if (p == end || radix != DECIMAL) { - if ((digits == 0 && !leadingZero) || (p != end && !ignoreTrailing && NumberHelper::GotoNonspace(&p, end))) { + if ((digits == 0 && !leading_zero) || (p != end && !ignore_trailing && NumberHelper::GotoNonspace(&p, end))) { // no digits there, like "0x", "0xh", or error trailing of "0x3q" return NAN_VALUE; } @@ -700,38 +700,38 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui } } } - if (digits == 0 && !leadingZero) { + if (digits == 0 && !leading_zero) { // no digits there, like ".", "sss", or ".e1" return NAN_VALUE; } - auto pEnd = p; + auto p_end = p; // 9. parse 'e/E' with '+/-' - char exponentSign = '+'; - int additionalExponent = 0; + char exponent_sign = '+'; + int additional_exponent = 0; constexpr int MAX_EXPONENT = INT32_MAX / 2; if (radix == DECIMAL && (p != end && (*p == 'e' || *p == 'E'))) { RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); // 10. parse exponent number if (*p == '+' || *p == '-') { - exponentSign = static_cast(*p); + exponent_sign = static_cast(*p); RETURN_IF_CONVERSION_END(++p, end, NAN_VALUE); } uint8_t digit; while ((digit = ToDigit(*p)) < radix) { - if (additionalExponent > MAX_EXPONENT / radix) { - additionalExponent = MAX_EXPONENT; + if (additional_exponent > MAX_EXPONENT / radix) { + additional_exponent = MAX_EXPONENT; } else { - additionalExponent = additionalExponent * radix + digit; + additional_exponent = additional_exponent * radix + digit; } if (++p == end) { break; } } } - exponent += (exponentSign == '-' ? -additionalExponent : additionalExponent); - if (!ignoreTrailing && NumberHelper::GotoNonspace(&p, end)) { + exponent += (exponent_sign == '-' ? -additional_exponent : additional_exponent); + if (!ignore_trailing && NumberHelper::GotoNonspace(&p, end)) { return NAN_VALUE; } @@ -740,7 +740,7 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui if (sign == Sign::NEG) { buffer += "-"; } - for (uint8_t *i = pStart; i < pEnd; ++i) { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + for (uint8_t *i = p_start; i < p_end; ++i) { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (*i != static_cast('.')) { buffer += *i; } @@ -786,7 +786,7 @@ double NumberHelper::Strtod(const char *str, int exponent, uint8_t radix) auto p = const_cast(str); Sign sign = Sign::NONE; uint64_t number = 0; - uint64_t numberMax = (UINT64_MAX - (radix - 1)) / radix; + uint64_t number_max = (UINT64_MAX - (radix - 1)) / radix; double result = 0.0; if (*p == '-') { sign = Sign::NEG; @@ -800,7 +800,7 @@ double NumberHelper::Strtod(const char *str, int exponent, uint8_t radix) if (digit >= radix) { break; } - if (number < numberMax) { + if (number < number_max) { number = number * radix + digit; } else { ++exponent; diff --git a/runtime/base/number_helper.h b/runtime/base/number_helper.h index 0e27fdd9c83da3ab4c47a38bbb1384fa5ce0322b..b4ab600b1b78e18327c35da3a8f85433c1f54d84 100644 --- a/runtime/base/number_helper.h +++ b/runtime/base/number_helper.h @@ -93,7 +93,7 @@ public: static JSTaggedValue DoubleToPrecision(JSThread *thread, double number, int digit); static JSTaggedValue StringToDoubleWithRadix(const uint8_t *start, const uint8_t *end, int radix); static PandaString IntToString(int number); - static JSTaggedValue StringToBigInt(JSThread *thread, JSHandle strVal); + static JSTaggedValue StringToBigInt(JSThread *thread, JSHandle str_val); private: static char Carry(char current, int radix); @@ -108,41 +108,41 @@ class JSDoubleOperator { public: explicit JSDoubleOperator(double val) // NOLINT(cppcoreguidelines-pro-type-member-init) { - u.fval = val; // NOLINT(cppcoreguidelines-pro-type-union-access) + u_.fval = val; // NOLINT(cppcoreguidelines-pro-type-union-access) } JSDoubleOperator() // NOLINT(cppcoreguidelines-pro-type-member-init) { - u.uval = 0; // NOLINT(cppcoreguidelines-pro-type-union-access) + u_.uval = 0; // NOLINT(cppcoreguidelines-pro-type-union-access) } int16_t GetExponent() const { - return u.bits.exponent; // NOLINT(cppcoreguidelines-pro-type-union-access) + return u_.bits.exponent; // NOLINT(cppcoreguidelines-pro-type-union-access) } uint64_t GetSignificand() const { - return u.bits.significand; // NOLINT(cppcoreguidelines-pro-type-union-access) + return u_.bits.significand; // NOLINT(cppcoreguidelines-pro-type-union-access) } void SetExponent(int16_t val) { - u.bits.exponent = val; // NOLINT(cppcoreguidelines-pro-type-union-access) + u_.bits.exponent = val; // NOLINT(cppcoreguidelines-pro-type-union-access) } void SetSignificand(uint64_t val) { - u.bits.significand = val; // NOLINT(cppcoreguidelines-pro-type-union-access) + u_.bits.significand = val; // NOLINT(cppcoreguidelines-pro-type-union-access) } void SetDouble(double val) { - u.fval = val; // NOLINT(cppcoreguidelines-pro-type-union-access) + u_.fval = val; // NOLINT(cppcoreguidelines-pro-type-union-access) } double GetDouble() const { - return u.fval; // NOLINT(cppcoreguidelines-pro-type-union-access) + return u_.fval; // NOLINT(cppcoreguidelines-pro-type-union-access) } private: @@ -154,7 +154,7 @@ private: } bits __attribute__((packed)); uint64_t uval; double fval; - } __attribute__((may_alias, packed)) u; + } __attribute__((may_alias, packed)) u_; }; } // namespace panda::ecmascript::base diff --git a/runtime/base/object_helper.cpp b/runtime/base/object_helper.cpp index 0814273f7e1de4858480758c9f1f1f12afb3b61f..5e2c346cc78e01fb6a3cf774809351ef75cdfd26 100644 --- a/runtime/base/object_helper.cpp +++ b/runtime/base/object_helper.cpp @@ -27,12 +27,12 @@ JSTaggedValue ObjectHelper::CreateDataPropertyOnObject(EcmaRuntimeCallInfo *argv // 4. Let propertyKey be ? ToPropertyKey(key). JSHandle key = BuiltinsBase::GetCallArg(argv, 0); - JSHandle propertyKey = JSTaggedValue::ToPropertyKey(thread, key); + 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); - JSObject::CreateDataPropertyOrThrow(thread, JSTaggedValue::ToObject(thread, object), propertyKey, value); + JSObject::CreateDataPropertyOrThrow(thread, JSTaggedValue::ToObject(thread, object), property_key, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Return undefined. @@ -51,8 +51,8 @@ JSTaggedValue ObjectHelper::AddEntriesFromIterable(JSThread *thread, const JSHan JSHandle iter(JSIterator::GetIterator(thread, iterable)); // ReturnIfAbrupt(iter). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter.GetTaggedValue()); - JSHandle keyIndex(thread, JSTaggedValue(0)); - JSHandle valueIndex(thread, JSTaggedValue(1)); + JSHandle key_index(thread, JSTaggedValue(0)); + JSHandle value_index(thread, JSTaggedValue(1)); JSHandle next = JSIterator::IteratorStep(thread, iter); JSMutableHandle status(thread, JSTaggedValue::Undefined()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); @@ -61,29 +61,29 @@ JSTaggedValue ObjectHelper::AddEntriesFromIterable(JSThread *thread, const JSHan // ReturnIfAbrupt(next). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // Let nextValue be IteratorValue(next). - JSHandle nextValue(JSIterator::IteratorValue(thread, next)); + JSHandle next_value(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // If Type(nextItem) is not Object - if (!nextValue->IsECMAObject()) { - JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); + if (!next_value->IsECMAObject()) { + JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); JSHandle record( - factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(typeError))); + factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(type_error))); JSTaggedValue ret = JSIterator::IteratorClose(thread, iter, record).GetTaggedValue(); if (LIKELY(!thread->HasPendingException())) { - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, typeError.GetTaggedValue(), ret); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, type_error.GetTaggedValue(), ret); }; return ret; } // Let k be Get(nextItem, "0"). - JSHandle key = JSObject::GetProperty(thread, nextValue, keyIndex).GetValue(); + JSHandle key = JSObject::GetProperty(thread, next_value, key_index).GetValue(); // If k is an abrupt completion, return IteratorClose(iter, k). if (UNLIKELY(thread->HasPendingException())) { return JSIterator::IteratorCloseAndReturn(thread, iter, key); } // Let v be Get(nextItem, "1"). - JSHandle value = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); + JSHandle value = JSObject::GetProperty(thread, next_value, value_index).GetValue(); // If v is an abrupt completion, return IteratorClose(iter, v). if (UNLIKELY(thread->HasPendingException())) { return JSIterator::IteratorCloseAndReturn(thread, iter, value); @@ -91,7 +91,7 @@ JSTaggedValue ObjectHelper::AddEntriesFromIterable(JSThread *thread, const JSHan // Let status be Call(adder, target, «nextValue.[[value]]»). auto info = NewRuntimeCallInfo(thread, adder, target, JSTaggedValue::Undefined(), 2U); info->SetCallArgs(key, value); // 2: key and value pair - JSTaggedValue ret = JSFunction::Call(info.get()); + JSTaggedValue ret = JSFunction::Call(info.Get()); status.Update(ret); // If status is an abrupt completion, return IteratorClose(iter, status). diff --git a/runtime/base/string_helper.cpp b/runtime/base/string_helper.cpp index c06d622667f215eb91e15c35b091aae5787fcc95..d0230bf01caab7c476941b6853aef3b24d5d1abb 100644 --- a/runtime/base/string_helper.cpp +++ b/runtime/base/string_helper.cpp @@ -27,13 +27,13 @@ bool StringHelper::CheckDuplicate(EcmaString *string) if (string->IsUtf8()) { const uint8_t *array = string->GetDataUtf8(); size_t length = string->GetUtf8Length() - 1; - std::bitset bitSet; + std::bitset bit_set; for (size_t i = 0; i < length; ++i) { char idx = *array; - if (bitSet.test(idx)) { + if (bit_set.test(idx)) { return true; } - bitSet.set(idx); + bit_set.set(idx); array++; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } } else { @@ -135,8 +135,8 @@ panda::ecmascript::JSTaggedValue StringHelper::StringPad(JSThread *thread, JSHan } // 8. If filler is the empty String, return S. - size_t fillerLength = filler->GetLength(); - if (fillerLength == 0) { + size_t filler_length = filler->GetLength(); + if (filler_length == 0) { return string.GetTaggedValue(); } @@ -148,7 +148,7 @@ panda::ecmascript::JSTaggedValue StringHelper::StringPad(JSThread *thread, JSHan std::string truncated_string; std::string filler_string = ToStdString(filler.GetObject()); for (size_t i = 0; i < fill_len; i++) { - truncated_string += filler_string[i % fillerLength]; + truncated_string += filler_string[i % filler_length]; } JSHandle truncated_string_filler = factory->NewFromStdString(truncated_string); diff --git a/runtime/base/typed_array_helper-inl.h b/runtime/base/typed_array_helper-inl.h index b74e7f9a7162ab338f144494a14af93b39345d80..695f02f46e55f693dd82841a0f856a0896319357 100644 --- a/runtime/base/typed_array_helper-inl.h +++ b/runtime/base/typed_array_helper-inl.h @@ -83,37 +83,37 @@ int32_t TypedArrayHelper::GetElementSize(const JSHandle &obj) } } -DataViewType TypedArrayHelper::GetTypeFromName(JSThread *thread, const JSHandle &typeName) +DataViewType TypedArrayHelper::GetTypeFromName(JSThread *thread, const JSHandle &type_name) { - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString())) { + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt8ArrayString())) { return DataViewType::INT8; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ArrayString())) { return DataViewType::UINT8; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ClampedArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ClampedArrayString())) { return DataViewType::UINT8_CLAMPED; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt16ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt16ArrayString())) { return DataViewType::INT16; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint16ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint16ArrayString())) { return DataViewType::UINT16; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt32ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt32ArrayString())) { return DataViewType::INT32; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint32ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint32ArrayString())) { return DataViewType::UINT32; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat32ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat32ArrayString())) { return DataViewType::FLOAT32; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat64ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat64ArrayString())) { return DataViewType::FLOAT64; } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledBigInt64ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledBigInt64ArrayString())) { return DataViewType::BIGINT64; } return DataViewType::BIGUINT64; @@ -149,62 +149,63 @@ JSHandle TypedArrayHelper::GetConstructor(JSThread *thread, const } } -JSHandle TypedArrayHelper::GetConstructorFromName(JSThread *thread, const JSHandle &typeName) +JSHandle TypedArrayHelper::GetConstructorFromName(JSThread *thread, + const JSHandle &type_name) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - auto globalConst = thread->GlobalConstants(); - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString())) { + auto global_const = thread->GlobalConstants(); + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt8ArrayString())) { return JSHandle(env->GetInt8ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ArrayString())) { return JSHandle(env->GetUint8ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ClampedArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ClampedArrayString())) { return JSHandle(env->GetUint8ClampedArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt16ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt16ArrayString())) { return JSHandle(env->GetInt16ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint16ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint16ArrayString())) { return JSHandle(env->GetUint16ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt32ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt32ArrayString())) { return JSHandle(env->GetInt32ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint32ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledUint32ArrayString())) { return JSHandle(env->GetUint32ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat32ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat32ArrayString())) { return JSHandle(env->GetFloat32ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat64ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat64ArrayString())) { return JSHandle(env->GetFloat64ArrayFunction()); } - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledBigInt64ArrayString())) { + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledBigInt64ArrayString())) { return JSHandle(env->GetBigInt64ArrayFunction()); } return JSHandle(env->GetBigUint64ArrayFunction()); } -int32_t TypedArrayHelper::GetSizeFromName(JSThread *thread, const JSHandle &typeName) +int32_t TypedArrayHelper::GetSizeFromName(JSThread *thread, const JSHandle &type_name) { - int32_t elementSize; - auto globalConst = thread->GlobalConstants(); - if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt8ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint8ClampedArrayString())) { - elementSize = ElementSize::ONE; - } else if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt16ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint16ArrayString())) { - elementSize = ElementSize::TWO; - } else if (JSTaggedValue::SameValue(typeName, globalConst->GetHandledInt32ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledUint32ArrayString()) || - JSTaggedValue::SameValue(typeName, globalConst->GetHandledFloat32ArrayString())) { - elementSize = ElementSize::FOUR; + int32_t element_size; + auto global_const = thread->GlobalConstants(); + if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt8ArrayString()) || + JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ArrayString()) || + JSTaggedValue::SameValue(type_name, global_const->GetHandledUint8ClampedArrayString())) { + element_size = ElementSize::ONE; + } else if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt16ArrayString()) || + JSTaggedValue::SameValue(type_name, global_const->GetHandledUint16ArrayString())) { + element_size = ElementSize::TWO; + } else if (JSTaggedValue::SameValue(type_name, global_const->GetHandledInt32ArrayString()) || + JSTaggedValue::SameValue(type_name, global_const->GetHandledUint32ArrayString()) || + JSTaggedValue::SameValue(type_name, global_const->GetHandledFloat32ArrayString())) { + element_size = ElementSize::FOUR; } else { - elementSize = ElementSize::EIGHT; + element_size = ElementSize::EIGHT; } - return elementSize; + return element_size; } int32_t TypedArrayHelper::GetByteOffset(JSThread *thread, const JSHandle &obj) diff --git a/runtime/base/typed_array_helper.cpp b/runtime/base/typed_array_helper.cpp index 458188ae85bfe12439b6237fb07036e974029f3b..91e234922ca86cfd0e51c09a0dadbae2c13ba29a 100644 --- a/runtime/base/typed_array_helper.cpp +++ b/runtime/base/typed_array_helper.cpp @@ -37,12 +37,12 @@ using BuiltinsArrayBuffer = builtins::BuiltinsArrayBuffer; // es11 22.2.4 The TypedArray Constructors JSTaggedValue TypedArrayHelper::TypedArrayConstructor(EcmaRuntimeCallInfo *argv, - const JSHandle &constructorName) + const JSHandle &constructor_name) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); JSHandle new_target = BuiltinsBase::GetNewTarget(argv); // 2. If NewTarget is undefined, throw a TypeError exception. if (new_target->IsUndefined()) { @@ -52,28 +52,28 @@ JSTaggedValue TypedArrayHelper::TypedArrayConstructor(EcmaRuntimeCallInfo *argv, // TypedArray constructor. // 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, "%TypedArray.prototype%"). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle firstArg = BuiltinsBase::GetCallArg(argv, 0); - if (!firstArg->IsECMAObject()) { + JSHandle first_arg = BuiltinsBase::GetCallArg(argv, 0); + if (!first_arg->IsECMAObject()) { // es11 22.2.4.1 TypedArray ( ) - double elementLength = 0; + double element_length = 0; // es11 22.2.4.2 TypedArray ( length ) - if (!firstArg->IsUndefined()) { - JSTaggedNumber index = JSTaggedValue::ToIndex(thread, firstArg); + if (!first_arg->IsUndefined()) { + JSTaggedNumber index = JSTaggedValue::ToIndex(thread, first_arg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - elementLength = index.GetNumber(); + element_length = index.GetNumber(); } JSHandle obj = - TypedArrayHelper::AllocateTypedArray(factory, ecmaVm, constructorName, new_target, elementLength); + TypedArrayHelper::AllocateTypedArray(factory, ecma_vm, constructor_name, new_target, element_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return obj.GetTaggedValue(); } - JSHandle obj = TypedArrayHelper::AllocateTypedArray(factory, ecmaVm, constructorName, new_target); + JSHandle obj = TypedArrayHelper::AllocateTypedArray(factory, ecma_vm, constructor_name, new_target); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (firstArg->IsTypedArray()) { - return TypedArrayHelper::CreateFromTypedArray(argv, obj, constructorName); + if (first_arg->IsTypedArray()) { + return TypedArrayHelper::CreateFromTypedArray(argv, obj, constructor_name); } - if (firstArg->IsArrayBuffer()) { - return TypedArrayHelper::CreateFromArrayBuffer(argv, obj, constructorName); + if (first_arg->IsArrayBuffer()) { + return TypedArrayHelper::CreateFromArrayBuffer(argv, obj, constructor_name); } return TypedArrayHelper::CreateFromOrdinaryObject(argv, obj); } @@ -83,36 +83,36 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle objectArg = BuiltinsBase::GetCallArg(argv, 0); - JSHandle object(objectArg); + [[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(object_arg); // 5. Let usingIterator be ? GetMethod(object, @@iterator). - JSHandle iteratorSymbol = env->GetIteratorSymbol(); - JSHandle usingIterator = - JSObject::GetMethod(thread, JSHandle::Cast(object), iteratorSymbol); + JSHandle iterator_symbol = env->GetIteratorSymbol(); + JSHandle using_iterator = + JSObject::GetMethod(thread, JSHandle::Cast(object), iterator_symbol); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If usingIterator is not undefined, then - if (!usingIterator->IsUndefined()) { + if (!using_iterator->IsUndefined()) { PandaVector> vec; // a. Let values be ? IterableToList(object, usingIterator). // b. Let len be the number of elements in values. // c. Perform ? AllocateTypedArrayBuffer(O, len). - JSHandle iterator = JSIterator::GetIterator(thread, objectArg, usingIterator); + JSHandle iterator = JSIterator::GetIterator(thread, object_arg, using_iterator); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle next(thread, JSTaggedValue::True()); while (!next->IsFalse()) { next = JSIterator::IteratorStep(thread, iterator); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!next->IsFalse()) { - JSHandle nextValue = JSIterator::IteratorValue(thread, next); - vec.push_back(nextValue); + JSHandle next_value = JSIterator::IteratorValue(thread, next); + vec.push_back(next_value); } } int32_t len = vec.size(); - TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, len); + TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecma_vm, obj, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. Let k be 0. // e. Repeat, while k < len @@ -120,13 +120,13 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar // ii. Let kValue be the first element of values and remove that element from values. // iii. Perform ? Set(O, Pk, kValue, true). // iv. Set k to k + 1. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSHandle kValue = vec[k]; - JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), kKey, kValue, true); + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSHandle k_value = vec[k]; + JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), k_key, k_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } @@ -138,13 +138,13 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar // 7. NOTE: object is not an Iterable so assume it is already an array-like object. // 8. Let arrayLike be object. // 9. Let len be ? LengthOfArrayLike(arrayLike). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSTaggedNumber lenTemp = - JSTaggedValue::ToLength(thread, JSObject::GetProperty(thread, objectArg, lengthKey).GetValue()); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSTaggedNumber len_temp = + JSTaggedValue::ToLength(thread, JSObject::GetProperty(thread, object_arg, length_key).GetValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double len = lenTemp.GetNumber(); + double len = len_temp.GetNumber(); // 10. Perform ? AllocateTypedArrayBuffer(O, len). - TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, len); + TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecma_vm, obj, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Let k be 0. // 12. Repeat, while k < len @@ -152,14 +152,14 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar // b. Let kValue be ? Get(arrayLike, Pk). // c. Perform ? Set(O, Pk, kValue, true). // d. Set k to k + 1. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSHandle kValue = JSObject::GetProperty(thread, objectArg, kKey).GetValue(); + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSHandle k_value = JSObject::GetProperty(thread, object_arg, k_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), kKey, kValue, true); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(obj), k_key, k_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } @@ -169,79 +169,79 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar // es11 22.2.4.3 TypedArray ( typedArray ) JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructorName) + const JSHandle &constructor_name) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 5. Let srcArray be typedArray. - JSHandle srcArray = BuiltinsBase::GetCallArg(argv, 0); - JSHandle srcObj(srcArray); + JSHandle src_array = BuiltinsBase::GetCallArg(argv, 0); + JSHandle src_obj(src_array); // 6. Let srcData be srcArray.[[ViewedArrayBuffer]]. - JSHandle srcData(thread, JSTypedArray::Cast(*srcObj)->GetViewedArrayBuffer()); + JSHandle src_data(thread, JSTypedArray::Cast(*src_obj)->GetViewedArrayBuffer()); // 7. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcData.GetTaggedValue())) { + if (BuiltinsArrayBuffer::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. - DataViewType elementType = TypedArrayHelper::GetTypeFromName(thread, constructorName); + DataViewType element_type = TypedArrayHelper::GetTypeFromName(thread, constructor_name); // 9. Let elementLength be srcArray.[[ArrayLength]]. // 10. Let srcName be the String value of srcArray.[[TypedArrayName]]. // 11. Let srcType be the Element Type value in Table 61 for srcName. // 12. Let srcElementSize be the Element Size value specified in Table 61 for srcName. - int32_t elementLength = TypedArrayHelper::GetArrayLength(thread, srcObj); - JSHandle srcName(thread, JSTypedArray::Cast(*srcObj)->GetTypedArrayName()); - DataViewType srcType = TypedArrayHelper::GetTypeFromName(thread, srcName); - int32_t srcElementSize = TypedArrayHelper::GetSizeFromName(thread, srcName); + int32_t element_length = TypedArrayHelper::GetArrayLength(thread, src_obj); + JSHandle src_name(thread, JSTypedArray::Cast(*src_obj)->GetTypedArrayName()); + DataViewType src_type = TypedArrayHelper::GetTypeFromName(thread, src_name); + int32_t src_element_size = TypedArrayHelper::GetSizeFromName(thread, src_name); // 13. Let srcByteOffset be srcArray.[[ByteOffset]]. // 14. Let elementSize be the Element Size value specified in Table 61 for constructorName. // 15. Let byteLength be elementSize × elementLength. - double srcByteOffset = TypedArrayHelper::GetByteOffset(thread, srcObj); - double elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); - double byteLength = elementSize * elementLength; + double src_byte_offset = TypedArrayHelper::GetByteOffset(thread, src_obj); + double element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); + double byte_length = element_size * element_length; // 16. If IsSharedArrayBuffer(srcData) is false, then // a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). JSMutableHandle data(thread, JSTaggedValue::Undefined()); // 18. If elementType is the same as srcType, then // a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor). - if (elementType == srcType) { - data.Update( - BuiltinsArrayBuffer::CloneArrayBuffer(thread, srcData, srcByteOffset, globalConst->GetHandledUndefined())); + if (element_type == src_type) { + data.Update(BuiltinsArrayBuffer::CloneArrayBuffer(thread, src_data, src_byte_offset, + global_const->GetHandledUndefined())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { // 19. Else, // a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). - JSHandle bufferConstructor = - JSObject::SpeciesConstructor(thread, JSHandle(srcData), env->GetArrayBufferFunction()); + JSHandle buffer_constructor = + JSObject::SpeciesConstructor(thread, JSHandle(src_data), env->GetArrayBufferFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - data.Update(BuiltinsArrayBuffer::AllocateArrayBuffer(thread, bufferConstructor, byteLength)); + data.Update(BuiltinsArrayBuffer::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(srcData.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(src_data.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // d. Let srcByteIndex be srcByteOffset. // e. Let targetByteIndex be 0. - int32_t srcByteIndex = srcByteOffset; - int32_t targetByteIndex = 0; + int32_t src_byte_index = src_byte_offset; + int32_t target_byte_index = 0; // f. Let count be elementLength. // g. Repeat, while count > 0 JSMutableHandle value(thread, JSTaggedValue::Undefined()); - for (int32_t count = elementLength; count > 0; count--) { + for (int32_t count = element_length; count > 0; count--) { // i. Let value be GetValueFromBuffer(srcData, srcByteIndex, srcType, true, Unordered). - JSTaggedValue taggedData = - BuiltinsArrayBuffer::GetValueFromBuffer(thread, srcData, srcByteIndex, srcType, true); - value.Update(taggedData); + JSTaggedValue tagged_data = + BuiltinsArrayBuffer::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, targetByteIndex, elementType, value, true); + BuiltinsArrayBuffer::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. - srcByteIndex = srcByteIndex + srcElementSize; - targetByteIndex = targetByteIndex + elementSize; + src_byte_index = src_byte_index + src_element_size; + target_byte_index = target_byte_index + element_size; } } // 19. Set O’s [[ViewedArrayBuffer]] internal slot to data. @@ -249,29 +249,29 @@ JSTaggedValue TypedArrayHelper::CreateFromTypedArray(EcmaRuntimeCallInfo *argv, // 21. Set O’s [[ByteOffset]] internal slot to 0. // 22. Set O’s [[ArrayLength]] internal slot to elementLength. JSTypedArray::Cast(*obj)->SetViewedArrayBuffer(thread, data.GetTaggedValue()); - JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(byteLength)); + JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(byte_length)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(0)); - JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(elementLength)); + JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(element_length)); // 23. Return O. return obj.GetTaggedValue(); } // es11 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructorName) + const JSHandle &constructor_name) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 5. Let elementSize be the Element Size value specified in Table 61 for constructorName. // 6. Let offset be ? ToIndex(byteOffset). - int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); - JSHandle byteOffset = BuiltinsBase::GetCallArg(argv, 1); - JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byteOffset); + int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); + JSHandle byte_offset = BuiltinsBase::GetCallArg(argv, 1); + JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byte_offset); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto offset = static_cast(index.GetNumber()); // 7. If offset modulo elementSize ≠ 0, throw a RangeError exception. - if (offset % elementSize != 0) { + if (offset % element_size != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The offset cannot be an integral multiple of elementSize.", JSTaggedValue::Exception()); } @@ -290,29 +290,29 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, THROW_TYPE_ERROR_AND_RETURN(thread, "The srcData is detached buffer.", JSTaggedValue::Exception()); } // 10. Let bufferByteLength be buffer.[[ArrayBufferByteLength]]. - JSTaggedNumber newLengthNum = + JSTaggedNumber new_length_num = JSTaggedNumber::FromIntOrDouble(thread, JSHandle(buffer)->GetArrayBufferByteLength()); - int32_t bufferByteLength = newLengthNum.ToInt32(); + int32_t buffer_byte_length = new_length_num.ToInt32(); // 11. If length is undefined, then // a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. // b. Let newByteLength be bufferByteLength - offset. // c. If newByteLength < 0, throw a RangeError exception. - int32_t newByteLength; + int32_t new_byte_length; if (length->IsUndefined()) { - if (bufferByteLength % elementSize != 0) { + if (buffer_byte_length % element_size != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The bufferByteLength cannot be an integral multiple of elementSize.", JSTaggedValue::Exception()); } - newByteLength = bufferByteLength - offset; - if (newByteLength < 0) { + new_byte_length = buffer_byte_length - offset; + if (new_byte_length < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The newByteLength is less than 0.", JSTaggedValue::Exception()); } } else { // 12. Else, // a. Let newByteLength be new_length × elementSize. // b. If offset + newByteLength > bufferByteLength, throw a RangeError exception. - newByteLength = new_length * elementSize; - if (offset + newByteLength > bufferByteLength) { + new_byte_length = new_length * element_size; + if (offset + new_byte_length > buffer_byte_length) { THROW_RANGE_ERROR_AND_RETURN(thread, "The newByteLength is out of range.", JSTaggedValue::Exception()); } } @@ -321,43 +321,43 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, // 15. Set O.[[ByteOffset]] to offset. // 16. Set O.[[ArrayLength]] to newByteLength / elementSize. JSTypedArray::Cast(*obj)->SetViewedArrayBuffer(thread, buffer); - JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(newByteLength)); + JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(new_byte_length)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(offset)); - JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(newByteLength / elementSize)); + JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(new_byte_length / element_size)); // 17. Return O. return obj.GetTaggedValue(); } // es11 22.2.4.2.1 Runtime Semantics: AllocateTypedArray ( constructorName, new_target, defaultProto ) -JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, - const JSHandle &constructorName, +JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecma_vm, + const JSHandle &constructor_name, const JSHandle &new_target) { - JSThread *thread = ecmaVm->GetJSThread(); + JSThread *thread = ecma_vm->GetJSThread(); // 1. Let proto be ? GetPrototypeFromConstructor(new_target, defaultProto). // 2. Let obj be ! IntegerIndexedObjectCreate(proto). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); - JSHandle typedArrayFunc = TypedArrayHelper::GetConstructorFromName(thread, constructorName); - JSHandle obj = factory->NewJSObjectByConstructor(typedArrayFunc, new_target); + JSHandle typed_array_func = TypedArrayHelper::GetConstructorFromName(thread, constructor_name); + JSHandle obj = factory->NewJSObjectByConstructor(typed_array_func, new_target); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); // 3. Assert: obj.[[ViewedArrayBuffer]] is undefined. // 4. Set obj.[[TypedArrayName]] to constructorName. // 5. If constructorName is "BigInt64Array" or "BigUint64Array", set obj.[[ContentType]] to BigInt. // 6. Otherwise, set obj.[[ContentType]] to Number. - JSTypedArray *jsTypedArray = JSTypedArray::Cast(*obj); - if (JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || - JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigUint64ArrayString())) { - jsTypedArray->SetContentType(ContentType::BigInt); + JSTypedArray *js_typed_array = JSTypedArray::Cast(*obj); + if (JSTaggedValue::SameValue(constructor_name, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || + JSTaggedValue::SameValue(constructor_name, thread->GlobalConstants()->GetHandledBigUint64ArrayString())) { + js_typed_array->SetContentType(ContentType::BIG_INT); } else { - jsTypedArray->SetContentType(ContentType::Number); + js_typed_array->SetContentType(ContentType::NUMBER); } // 7. If length is not present, then // a. Set obj.[[ByteLength]] to 0. // b. Set obj.[[ByteOffset]] to 0. // c. Set obj.[[ArrayLength]] to 0. - JSTypedArray::Cast(*obj)->SetTypedArrayName(thread, constructorName); + JSTypedArray::Cast(*obj)->SetTypedArrayName(thread, constructor_name); JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(0)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(0)); JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(0)); @@ -366,34 +366,34 @@ JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, } // namespace panda::ecmascript::base // es11 22.2.4.2.1 Runtime Semantics: AllocateTypedArray ( constructorName, new_target, defaultProto, length ) -JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, - const JSHandle &constructorName, +JSHandle TypedArrayHelper::AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecma_vm, + const JSHandle &constructor_name, const JSHandle &new_target, double length) { - JSThread *thread = ecmaVm->GetJSThread(); + JSThread *thread = ecma_vm->GetJSThread(); // 1. Let proto be ? GetPrototypeFromConstructor(new_target, defaultProto). // 2. Let obj be ! IntegerIndexedObjectCreate(proto). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); - JSHandle typedArrayFunc = TypedArrayHelper::GetConstructorFromName(thread, constructorName); - JSHandle obj = factory->NewJSObjectByConstructor(typedArrayFunc, new_target); + JSHandle typed_array_func = TypedArrayHelper::GetConstructorFromName(thread, constructor_name); + JSHandle obj = factory->NewJSObjectByConstructor(typed_array_func, new_target); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); // 3. Assert: obj.[[ViewedArrayBuffer]] is undefined. // 4. Set obj.[[TypedArrayName]] to constructorName. - JSTypedArray::Cast(*obj)->SetTypedArrayName(thread, constructorName); + JSTypedArray::Cast(*obj)->SetTypedArrayName(thread, constructor_name); // 7. If length is not present, then // 8. Else, // a. Perform ? AllocateTypedArrayBuffer(obj, length). - TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, length); + TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecma_vm, obj, length); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); // 9. Return obj. return obj; } // es11 22.2.4.2.2 Runtime Semantics: AllocateTypedArrayBuffer ( O, length ) -JSHandle TypedArrayHelper::AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecmaVm, +JSHandle TypedArrayHelper::AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecma_vm, const JSHandle &obj, double length) { - JSHandle env = ecmaVm->GetGlobalEnv(); + JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. // 2. Assert: O.[[ViewedArrayBuffer]] is undefined. // 3. Assert: ! IsNonNegativeInteger(length) is true. @@ -404,28 +404,28 @@ JSHandle TypedArrayHelper::AllocateTypedArrayBuffer(JSThread *thread, THROW_RANGE_ERROR_AND_RETURN(thread, "array length must less than 2^32 - 1", exception); } // 4. Let constructorName be the String value of O.[[TypedArrayName]]. - JSHandle constructorName(thread, JSTypedArray::Cast(*obj)->GetTypedArrayName()); + JSHandle constructor_name(thread, JSTypedArray::Cast(*obj)->GetTypedArrayName()); // 5. Let elementSize be the Element Size value specified in Table 61 for constructorName. - int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); + int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); // 6. Let byteLength be elementSize × length. - double byteLength = elementSize * length; + double byte_length = element_size * length; // 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). JSHandle constructor = env->GetArrayBufferFunction(); - JSTaggedValue data = BuiltinsArrayBuffer::AllocateArrayBuffer(thread, constructor, byteLength); + JSTaggedValue data = BuiltinsArrayBuffer::AllocateArrayBuffer(thread, constructor, byte_length); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, exception); - JSTypedArray *jsTypedArray = JSTypedArray::Cast(*obj); - if (JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || - JSTaggedValue::SameValue(constructorName, thread->GlobalConstants()->GetHandledBigUint64ArrayString())) { - jsTypedArray->SetContentType(ContentType::BigInt); + JSTypedArray *js_typed_array = JSTypedArray::Cast(*obj); + if (JSTaggedValue::SameValue(constructor_name, thread->GlobalConstants()->GetHandledBigInt64ArrayString()) || + JSTaggedValue::SameValue(constructor_name, thread->GlobalConstants()->GetHandledBigUint64ArrayString())) { + js_typed_array->SetContentType(ContentType::BIG_INT); } else { - jsTypedArray->SetContentType(ContentType::Number); + js_typed_array->SetContentType(ContentType::NUMBER); } // 8. Set O.[[ViewedArrayBuffer]] to data. // 9. Set O.[[ByteLength]] to byteLength. // 10. Set O.[[ByteOffset]] to 0. // 11. Set O.[[ArrayLength]] to length. JSTypedArray::Cast(*obj)->SetViewedArrayBuffer(thread, data); - JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(byteLength)); + JSTypedArray::Cast(*obj)->SetByteLength(thread, JSTaggedValue(byte_length)); JSTypedArray::Cast(*obj)->SetByteOffset(thread, JSTaggedValue(0)); JSTypedArray::Cast(*obj)->SetArrayLength(thread, JSTaggedValue(length)); // 12. Return O. @@ -441,12 +441,13 @@ JSHandle TypedArrayHelper::TypedArraySpeciesCreate( // 1. Assert: exemplar is an Object that has [[TypedArrayName]] and [[ContentType]] internal slots. // 2. Let defaultConstructor be the intrinsic object listed in column one of Table 61 for // exemplar.[[TypedArrayName]]. - JSHandle defaultConstructor = TypedArrayHelper::GetConstructor(thread, JSHandle(obj)); + JSHandle default_constructor = + TypedArrayHelper::GetConstructor(thread, JSHandle(obj)); // 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). - JSHandle thisConstructor = JSObject::SpeciesConstructor(thread, obj, defaultConstructor); + JSHandle this_constructor = JSObject::SpeciesConstructor(thread, obj, default_constructor); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); // 4. Let result be ? TypedArrayCreate(constructor, argumentList). - return TypedArrayHelper::TypedArrayCreate(thread, thisConstructor, argc, argv); + return TypedArrayHelper::TypedArrayCreate(thread, this_constructor, argc, argv); } // es11 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) @@ -459,21 +460,21 @@ JSHandle TypedArrayHelper::TypedArrayCreate(JSThread *thread, const JS auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), argc); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); info->SetCallArg(argc, argv); - JSTaggedValue taggedArray = JSFunction::Construct(info.get()); + JSTaggedValue tagged_array = JSFunction::Construct(info.Get()); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); - if (!taggedArray.IsECMAObject()) { + if (!tagged_array.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the Typedarray.", JSHandle(thread, JSTaggedValue::Exception())); } - JSHandle taggedArrayHandle(thread, taggedArray); + JSHandle tagged_array_handle(thread, tagged_array); // 2. Perform ? ValidateTypedArray(newTypedArray). - TypedArrayHelper::ValidateTypedArray(thread, taggedArrayHandle); + TypedArrayHelper::ValidateTypedArray(thread, tagged_array_handle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); - JSHandle newTypedArray(taggedArrayHandle); + JSHandle new_typed_array(tagged_array_handle); // 3. If argumentList is a List of a single Number, then // a. If newTypedArray.[[ArrayLength]] < argumentList[0], throw a TypeError exception. if (argc == 1) { - if (TypedArrayHelper::GetArrayLength(thread, newTypedArray) < + if (TypedArrayHelper::GetArrayLength(thread, new_typed_array) < // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedValue::ToInt32(thread, JSHandle(thread, JSTaggedValue(argv[0])))) { THROW_TYPE_ERROR_AND_RETURN(thread, "the length of newTypedArray is not a correct value.", @@ -481,7 +482,7 @@ JSHandle TypedArrayHelper::TypedArrayCreate(JSThread *thread, const JS } } // 4. Return newTypedArray. - return newTypedArray; + return new_typed_array; } // es11 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) @@ -503,31 +504,32 @@ JSTaggedValue TypedArrayHelper::ValidateTypedArray(JSThread *thread, const JSHan return buffer; } -int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, - const JSHandle &buffer, const JSHandle &firstValue, - const JSHandle &secondValue) +int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandle &callbackfn_handle, + const JSHandle &buffer, const JSHandle &first_value, + const JSHandle &second_value) { - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. Assert: Both Type(x) and Type(y) is Number. - ASSERT((firstValue->IsNumber() && secondValue->IsNumber()) || (firstValue->IsBigInt() && secondValue->IsBigInt())); + ASSERT((first_value->IsNumber() && second_value->IsNumber()) || + (first_value->IsBigInt() && second_value->IsBigInt())); // 2. If the argument comparefn is not undefined, then // a. Let v be Call(comparefn, undefined, «x, y»). // b. ReturnIfAbrupt(v). // c. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // d. If v is NaN, return +0. // e. Return v. - if (!callbackfnHandle->IsUndefined()) { - JSHandle thisArgHandle = globalConst->GetHandledUndefined(); + if (!callbackfn_handle->IsUndefined()) { + JSHandle this_arg_handle = global_const->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, callbackfnHandle, thisArgHandle, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(firstValue, secondValue); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, callbackfn_handle, this_arg_handle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(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())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The buffer is detached buffer.", 0); } - JSHandle testResult(thread, callResult); - JSTaggedNumber v = JSTaggedValue::ToNumber(thread, testResult); + JSHandle test_result(thread, call_result); + JSTaggedNumber v = JSTaggedValue::ToNumber(thread, test_result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); double value = v.GetNumber(); if (std::isnan(value)) { @@ -536,39 +538,39 @@ int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandle y, return 1. // 8. If x is -0 and y is +0, return -1. // 9. If x is +0 and y is -0, return 1. // 10. Return +0. - if (compareResult == ComparisonResult::LESS) { + if (compare_result == ComparisonResult::LESS) { return -1; } - if (compareResult == ComparisonResult::GREAT) { + if (compare_result == ComparisonResult::GREAT) { return 1; } - JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, firstValue); - JSTaggedNumber yNumber = JSTaggedValue::ToNumber(thread, secondValue); - double eZeroTemp = -0.0; - auto eZero = JSTaggedNumber(eZeroTemp); - double pZeroTemp = +0.0; - auto pZero = JSTaggedNumber(pZeroTemp); - if (JSTaggedNumber::SameValue(xNumber, eZero) && JSTaggedNumber::SameValue(yNumber, pZero)) { + JSTaggedNumber x_number = JSTaggedValue::ToNumber(thread, first_value); + JSTaggedNumber y_number = JSTaggedValue::ToNumber(thread, second_value); + double e_zero_temp = -0.0; + auto e_zero = JSTaggedNumber(e_zero_temp); + double p_zero_temp = +0.0; + auto p_zero = JSTaggedNumber(p_zero_temp); + if (JSTaggedNumber::SameValue(x_number, e_zero) && JSTaggedNumber::SameValue(y_number, p_zero)) { return -1; } - if (JSTaggedNumber::SameValue(xNumber, pZero) && JSTaggedNumber::SameValue(yNumber, eZero)) { + if (JSTaggedNumber::SameValue(x_number, p_zero) && JSTaggedNumber::SameValue(y_number, e_zero)) { return 1; } return +0; diff --git a/runtime/base/typed_array_helper.h b/runtime/base/typed_array_helper.h index 5cfb1b0721531a3c55c12af24041018cac1574dd..30975c06a4db27b3347d6e3fc1690b4e203e3a00 100644 --- a/runtime/base/typed_array_helper.h +++ b/runtime/base/typed_array_helper.h @@ -27,12 +27,12 @@ enum ElementSize : uint8_t { ONE = 1, TWO = 2, FOUR = 4, EIGHT = 8 }; class TypedArrayHelper { public: static JSTaggedValue TypedArrayConstructor(EcmaRuntimeCallInfo *argv, - const JSHandle &constructorName); - static JSHandle AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, - const JSHandle &constructorName, + const JSHandle &constructor_name); + static JSHandle AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecma_vm, + const JSHandle &constructor_name, const JSHandle &new_target); - static JSHandle AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecmaVm, - const JSHandle &constructorName, + static JSHandle AllocateTypedArray(ObjectFactory *factory, EcmaVM *ecma_vm, + const JSHandle &constructor_name, const JSHandle &new_target, double length); static JSHandle TypedArraySpeciesCreate(JSThread *thread, const JSHandle &obj, uint32_t argc, const JSTaggedType argv[] // NOLINT(modernize-avoid-c-arrays) @@ -44,24 +44,24 @@ public: static JSTaggedValue ValidateTypedArray(JSThread *thread, const JSHandle &value); inline static DataViewType GetType(const JSHandle &obj); inline static int32_t GetElementSize(const JSHandle &obj); - inline static DataViewType GetTypeFromName(JSThread *thread, const JSHandle &typeName); + inline static DataViewType GetTypeFromName(JSThread *thread, const JSHandle &type_name); inline static JSHandle GetConstructor(JSThread *thread, const JSHandle &obj); inline static JSHandle GetConstructorFromName(JSThread *thread, - const JSHandle &typeName); - inline static int32_t GetSizeFromName(JSThread *thread, const JSHandle &typeName); + const JSHandle &type_name); + inline static int32_t GetSizeFromName(JSThread *thread, const JSHandle &type_name); inline static int32_t GetByteOffset(JSThread *thread, const JSHandle &obj); inline static int32_t GetArrayLength(JSThread *thread, const JSHandle &obj); - static int32_t SortCompare(JSThread *thread, const JSHandle &callbackfnHandle, - const JSHandle &buffer, const JSHandle &firstValue, - const JSHandle &secondValue); + static int32_t SortCompare(JSThread *thread, const JSHandle &callbackfn_handle, + const JSHandle &buffer, const JSHandle &first_value, + const JSHandle &second_value); private: static JSTaggedValue CreateFromOrdinaryObject(EcmaRuntimeCallInfo *argv, const JSHandle &obj); static JSTaggedValue CreateFromTypedArray(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructorName); + const JSHandle &constructor_name); static JSTaggedValue CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv, const JSHandle &obj, - const JSHandle &constructorName); - static JSHandle AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecmaVm, const JSHandle &obj, + const JSHandle &constructor_name); + static JSHandle AllocateTypedArrayBuffer(JSThread *thread, EcmaVM *ecma_vm, const JSHandle &obj, double length); }; } // namespace panda::ecmascript::base diff --git a/runtime/builtins.cpp b/runtime/builtins.cpp index 44b59a7d2d9522de6e4ca78530fd7c3dc8db6f8f..38b53b174ff8842c769165810f52462825dce45a 100644 --- a/runtime/builtins.cpp +++ b/runtime/builtins.cpp @@ -159,159 +159,160 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) vm_ = thread->GetEcmaVM(); factory_ = vm_->GetFactory(); [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle nullHandle(thread, JSTaggedValue::Null()); + JSHandle null_handle(thread, JSTaggedValue::Null()); // Object.prototype[dynclass] - JSHandle objPrototypeDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, nullHandle); + JSHandle obj_prototype_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, null_handle); // Object.prototype - JSHandle objFuncPrototype = factory_->NewJSObject(objPrototypeDynclass); - JSHandle objFuncPrototypeVal(objFuncPrototype); + JSHandle obj_func_prototype = factory_->NewJSObject(obj_prototype_dynclass); + JSHandle obj_func_prototype_val(obj_func_prototype); // Object.prototype_or_dynclass - JSHandle objFuncDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); + JSHandle obj_func_dynclass = + factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); // GLobalObject.prototype_or_dynclass - JSHandle globalObjFuncDynclass = factory_->CreateDynClass(JSType::JS_GLOBAL_OBJECT, 0); - globalObjFuncDynclass->SetPrototype(thread_, objFuncPrototypeVal.GetTaggedValue()); - globalObjFuncDynclass->SetIsDictionaryMode(true); + JSHandle global_obj_func_dynclass = factory_->CreateDynClass(JSType::JS_GLOBAL_OBJECT, 0); + global_obj_func_dynclass->SetPrototype(thread_, obj_func_prototype_val.GetTaggedValue()); + global_obj_func_dynclass->SetIsDictionaryMode(true); // Function.prototype_or_dynclass - JSHandle emptyFuncDynclass( - factory_->CreateDynClass(JSType::JS_FUNCTION, objFuncPrototypeVal, HClass::IS_CALLABLE)); - emptyFuncDynclass->SetExtensible(true); + JSHandle empty_func_dynclass( + factory_->CreateDynClass(JSType::JS_FUNCTION, obj_func_prototype_val, HClass::IS_CALLABLE)); + empty_func_dynclass->SetExtensible(true); // PrimitiveRef.prototype_or_dynclass - JSHandle primRefObjDynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, objFuncPrototypeVal); + JSHandle prim_ref_obj_dynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, obj_func_prototype_val); // init global object - JSHandle globalObject = factory_->NewNonMovableJSObject(globalObjFuncDynclass); - JSHandle newGlobalDynclass = JSHClass::Clone(thread_, globalObjFuncDynclass); - globalObject->SetClass(newGlobalDynclass); - env->SetJSGlobalObject(thread_, globalObject); + JSHandle global_object = factory_->NewNonMovableJSObject(global_obj_func_dynclass); + JSHandle new_global_dynclass = JSHClass::Clone(thread_, global_obj_func_dynclass); + global_object->SetClass(new_global_dynclass); + env->SetJSGlobalObject(thread_, global_object); // initialize Function, forbidden change order - InitializeFunction(env, emptyFuncDynclass); + InitializeFunction(env, empty_func_dynclass); - JSHandle objFuncInstancePrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle objFuncInstancePrototypeValue(objFuncInstancePrototype); - JSHandle asyncFuncClass = factory_->CreateFunctionClass( - FunctionKind::ASYNC_FUNCTION, JSType::JS_ASYNC_FUNCTION, objFuncInstancePrototypeValue); - asyncFuncClass->SetExtensible(true); - env->SetAsyncFunctionClass(thread_, asyncFuncClass); + JSHandle obj_func_instance_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle obj_func_instance_prototype_value(obj_func_instance_prototype); + JSHandle async_func_class = factory_->CreateFunctionClass( + FunctionKind::ASYNC_FUNCTION, JSType::JS_ASYNC_FUNCTION, obj_func_instance_prototype_value); + async_func_class->SetExtensible(true); + env->SetAsyncFunctionClass(thread_, async_func_class); - JSHandle asyncAwaitStatusFuncClass = factory_->CreateFunctionClass( + JSHandle async_await_status_func_class = factory_->CreateFunctionClass( FunctionKind::NORMAL_FUNCTION, JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION, env->GetFunctionPrototype()); - env->SetAsyncAwaitStatusFunctionClass(thread_, asyncAwaitStatusFuncClass); + env->SetAsyncAwaitStatusFunctionClass(thread_, async_await_status_func_class); - JSHandle asyncGeneratorResolveNextFuncClass = + JSHandle async_generator_resolve_next_func_class = factory_->CreateDynClass(JSType::JS_ASYNC_GENERATOR_RESOLVE_NEXT_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - asyncGeneratorResolveNextFuncClass->SetExtensible(true); - env->SetAsyncGeneratorResolveNextFunctionClass(thread_, asyncGeneratorResolveNextFuncClass); + async_generator_resolve_next_func_class->SetExtensible(true); + env->SetAsyncGeneratorResolveNextFunctionClass(thread_, async_generator_resolve_next_func_class); - JSHandle asyncFromSyncIteratorValueUnwrapFuncClass = + JSHandle async_from_sync_iterator_value_unwrap_func_class = factory_->CreateDynClass( JSType::JS_ASYNC_FROM_SYNC_ITERATOR_VALUE_UNWRAP_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - asyncFromSyncIteratorValueUnwrapFuncClass->SetExtensible(true); - env->SetAsyncFromSyncIteratorValueUnwrapFunctionClass(thread_, asyncFromSyncIteratorValueUnwrapFuncClass); + async_from_sync_iterator_value_unwrap_func_class->SetExtensible(true); + env->SetAsyncFromSyncIteratorValueUnwrapFunctionClass(thread_, async_from_sync_iterator_value_unwrap_func_class); - JSHandle promiseReactionFuncClass = factory_->CreateDynClass( + JSHandle promise_reaction_func_class = factory_->CreateDynClass( JSType::JS_PROMISE_REACTIONS_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - promiseReactionFuncClass->SetExtensible(true); - env->SetPromiseReactionFunctionClass(thread_, promiseReactionFuncClass); + promise_reaction_func_class->SetExtensible(true); + env->SetPromiseReactionFunctionClass(thread_, promise_reaction_func_class); - JSHandle promiseExecutorFuncClass = factory_->CreateDynClass( + JSHandle promise_executor_func_class = factory_->CreateDynClass( JSType::JS_PROMISE_EXECUTOR_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - promiseExecutorFuncClass->SetExtensible(true); - env->SetPromiseExecutorFunctionClass(thread_, promiseExecutorFuncClass); + promise_executor_func_class->SetExtensible(true); + env->SetPromiseExecutorFunctionClass(thread_, promise_executor_func_class); - JSHandle promiseAllResolveElementFunctionClass = + JSHandle promise_all_resolve_element_function_class = factory_->CreateDynClass(JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - promiseAllResolveElementFunctionClass->SetExtensible(true); - env->SetPromiseAllResolveElementFunctionClass(thread_, promiseAllResolveElementFunctionClass); + promise_all_resolve_element_function_class->SetExtensible(true); + env->SetPromiseAllResolveElementFunctionClass(thread_, promise_all_resolve_element_function_class); - JSHandle proxyRevocFuncClass = factory_->CreateDynClass( + JSHandle proxy_revoc_func_class = factory_->CreateDynClass( JSType::JS_PROXY_REVOC_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - proxyRevocFuncClass->SetExtensible(true); - env->SetProxyRevocFunctionClass(thread_, proxyRevocFuncClass); + proxy_revoc_func_class->SetExtensible(true); + env->SetProxyRevocFunctionClass(thread_, proxy_revoc_func_class); // Object = new Function() - JSHandle objectFunction( - NewBuiltinConstructor(env, objFuncPrototype, Object::ObjectConstructor, "Object", FunctionLength::ONE)); - objectFunction.GetObject()->SetFunctionPrototype(thread_, objFuncDynclass.GetTaggedValue()); + JSHandle object_function( + 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_, objectFunction); - env->SetObjectFunctionPrototype(thread_, objFuncPrototype); + env->SetObjectFunction(thread_, object_function); + env->SetObjectFunctionPrototype(thread_, obj_func_prototype); - JSHandle functionClass = factory_->CreateFunctionClass( + JSHandle function_class = factory_->CreateFunctionClass( FunctionKind::BASE_CONSTRUCTOR, JSType::JS_FUNCTION, env->GetFunctionPrototype()); - env->SetFunctionClassWithProto(thread_, functionClass); - functionClass = factory_->CreateFunctionClass(FunctionKind::NORMAL_FUNCTION, JSType::JS_FUNCTION, - env->GetFunctionPrototype()); - env->SetFunctionClassWithoutProto(thread_, functionClass); - functionClass = factory_->CreateFunctionClass(FunctionKind::CLASS_CONSTRUCTOR, JSType::JS_FUNCTION, - env->GetFunctionPrototype()); - env->SetFunctionClassWithoutName(thread_, functionClass); + env->SetFunctionClassWithProto(thread_, function_class); + function_class = factory_->CreateFunctionClass(FunctionKind::NORMAL_FUNCTION, JSType::JS_FUNCTION, + env->GetFunctionPrototype()); + env->SetFunctionClassWithoutProto(thread_, function_class); + function_class = factory_->CreateFunctionClass(FunctionKind::CLASS_CONSTRUCTOR, JSType::JS_FUNCTION, + env->GetFunctionPrototype()); + env->SetFunctionClassWithoutName(thread_, function_class); if (env == vm_->GetGlobalEnv()) { - InitializeAllTypeError(env, objFuncDynclass); - InitializeSymbol(env, primRefObjDynclass); + InitializeAllTypeError(env, obj_func_dynclass); + InitializeSymbol(env, prim_ref_obj_dynclass); } else { // error and symbol need to be shared when initialize realm InitializeAllTypeErrorWithRealm(env); - InitializeSymbolWithRealm(env, primRefObjDynclass); + InitializeSymbolWithRealm(env, prim_ref_obj_dynclass); } - InitializeNumber(env, globalObject, primRefObjDynclass); - InitializeBigInt(env, objFuncDynclass); - InitializeDate(env, objFuncDynclass); - InitializeObject(env, objFuncPrototype, objectFunction); - InitializeBoolean(env, primRefObjDynclass); + InitializeNumber(env, global_object, prim_ref_obj_dynclass); + InitializeBigInt(env, obj_func_dynclass); + InitializeDate(env, obj_func_dynclass); + InitializeObject(env, obj_func_prototype, object_function); + InitializeBoolean(env, prim_ref_obj_dynclass); InitializeRegExp(env); - InitializeSet(env, objFuncDynclass); - InitializeMap(env, objFuncDynclass); - InitializeWeakRef(env, objFuncDynclass); - InitializeWeakMap(env, objFuncDynclass); - InitializeWeakSet(env, objFuncDynclass); - InitializeArray(env, objFuncPrototypeVal); - InitializeTypedArray(env, objFuncDynclass); - InitializeString(env, primRefObjDynclass); - InitializeArrayBuffer(env, objFuncDynclass); - InitializeDataView(env, objFuncDynclass); - - JSHandle argumentsDynclass = factory_->CreateJSArguments(); - env->SetArgumentsClass(thread_, argumentsDynclass); + InitializeSet(env, obj_func_dynclass); + InitializeMap(env, obj_func_dynclass); + InitializeWeakRef(env, obj_func_dynclass); + InitializeWeakMap(env, obj_func_dynclass); + InitializeWeakSet(env, obj_func_dynclass); + InitializeArray(env, obj_func_prototype_val); + InitializeTypedArray(env, obj_func_dynclass); + InitializeString(env, prim_ref_obj_dynclass); + InitializeArrayBuffer(env, obj_func_dynclass); + InitializeDataView(env, obj_func_dynclass); + + JSHandle arguments_dynclass = factory_->CreateJSArguments(); + env->SetArgumentsClass(thread_, arguments_dynclass); SetArgumentsSharedAccessor(env); - InitializeGlobalObject(env, globalObject); - InitializeMath(env, objFuncPrototypeVal); - InitializeJson(env, objFuncPrototypeVal); - InitializeIterator(env, objFuncDynclass); - InitializeAsyncIterator(env, objFuncDynclass); + InitializeGlobalObject(env, global_object); + InitializeMath(env, obj_func_prototype_val); + InitializeJson(env, obj_func_prototype_val); + InitializeIterator(env, obj_func_dynclass); + InitializeAsyncIterator(env, obj_func_dynclass); InitializeProxy(env); - InitializeReflect(env, objFuncPrototypeVal); - InitializeAsyncFunction(env, objFuncDynclass); - InitializeGenerator(env, objFuncDynclass); - InitializeGeneratorFunction(env, objFuncDynclass); - InitializeAsyncGenerator(env, objFuncDynclass); - InitializeAsyncGeneratorFunction(env, objFuncDynclass); - InitializeAsyncFromSyncIteratorPrototypeObject(env, objFuncDynclass); - InitializePromise(env, objFuncDynclass); + InitializeReflect(env, obj_func_prototype_val); + InitializeAsyncFunction(env, obj_func_dynclass); + InitializeGenerator(env, obj_func_dynclass); + InitializeGeneratorFunction(env, obj_func_dynclass); + InitializeAsyncGenerator(env, obj_func_dynclass); + InitializeAsyncGeneratorFunction(env, obj_func_dynclass); + InitializeAsyncFromSyncIteratorPrototypeObject(env, obj_func_dynclass); + InitializePromise(env, obj_func_dynclass); InitializePromiseJob(env); - InitializeFinalizationRegistry(env, objFuncDynclass); + InitializeFinalizationRegistry(env, obj_func_dynclass); JSRuntimeOptions options = JSRuntimeOptions::Cast(vm_->GetOptions()); - std::string icuPath = options.GetIcuDataPath(); - if (icuPath == "default") { + std::string icu_path = options.GetIcuDataPath(); + if (icu_path == "default") { SetIcuDirectory(); } else { - u_setDataDirectory(icuPath.c_str()); + u_setDataDirectory(icu_path.c_str()); } - InitializeIntl(env, objFuncPrototypeVal); + InitializeIntl(env, obj_func_prototype_val); InitializeLocale(env); InitializeDateTimeFormat(env); InitializeNumberFormat(env); @@ -319,16 +320,16 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) InitializeCollator(env); InitializePluralRules(env); - JSHandle generatorFuncClass = factory_->CreateFunctionClass( + JSHandle generator_func_class = factory_->CreateFunctionClass( FunctionKind::GENERATOR_FUNCTION, JSType::JS_GENERATOR_FUNCTION, env->GetGeneratorFunctionPrototype()); - env->SetGeneratorFunctionClass(thread_, generatorFuncClass); + env->SetGeneratorFunctionClass(thread_, generator_func_class); - JSHandle asyncGeneratorFuncClass = factory_->CreateFunctionClass( + JSHandle async_generator_func_class = factory_->CreateFunctionClass( FunctionKind::ASYNC_GENERATOR_FUNCTION, JSType::JS_ASYNC_GENERATOR_FUNCTION, env->GetAsyncGeneratorFunctionPrototype()); - env->SetAsyncGeneratorFunctionClass(thread_, asyncGeneratorFuncClass); + env->SetAsyncGeneratorFunctionClass(thread_, async_generator_func_class); - env->SetObjectFunctionPrototypeClass(thread_, JSTaggedValue(objFuncPrototype->GetClass())); + env->SetObjectFunctionPrototypeClass(thread_, JSTaggedValue(obj_func_prototype->GetClass())); thread_->ResetGuardians(); #ifdef FUZZING_FUZZILLI_BUILTIN @@ -336,38 +337,38 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) #endif } -void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHandle &globalObject) +void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHandle &global_object) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Global object test - SetFunction(env, globalObject, "print", Global::PrintEntrypoint, 0); - SetFunction(env, globalObject, "gc", Global::GCEntrypoint, 0); + SetFunction(env, global_object, "print", Global::PrintEntrypoint, 0); + SetFunction(env, global_object, "gc", Global::GCEntrypoint, 0); // Intrusice GC testing framework - SetFunction(env, globalObject, "startGC", Global::SpecifiedGCEntrypoint, 2); - SetFunction(env, globalObject, "waitForFinishGC", Global::WaitForFinishGC, 1); - SetFunction(env, globalObject, "scheduleGcAfterNthAlloc", Global::ScheduleGCAfterNthAlloc, 2); - SetFunction(env, globalObject, "isScheduledGcTriggered", Global::IsScheduledGCTriggered, 0); - SetFunction(env, globalObject, "allocateArrayObject", Global::AllocateArrayObject, 1); - SetFunction(env, globalObject, "markObject", Global::MarkObject, 1); - SetFunction(env, globalObject, "getMarkQueue", Global::GetMarkQueue, 0); - SetFunction(env, globalObject, "clearMarkQueue", Global::ClearMarkQueue, 0); - SetFunction(env, globalObject, "getObjectSpaceType", Global::GCObjectSpaceType, 1); - SetFunction(env, globalObject, "pinObject", Global::PinObject, 1); - SetFunction(env, globalObject, "unpinObject", Global::UnpinObject, 1); - SetFunction(env, globalObject, "getObjectAddress", Global::GetObjectAddress, 1); + 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, globalObject, "startRuntimeStat", Global::StartRuntimeStat, 0); - SetFunction(env, globalObject, "stopRuntimeStat", Global::StopRuntimeStat, 0); + SetFunction(env, global_object, "startRuntimeStat", Global::StartRuntimeStat, 0); + SetFunction(env, global_object, "stopRuntimeStat", Global::StopRuntimeStat, 0); #endif JSRuntimeOptions options = JSRuntimeOptions::Cast(vm_->GetOptions()); if (options.IsEnableArkTools()) { - JSHandle arkTools(InitializeArkTools(env)); - SetConstantObject(globalObject, "ArkTools", arkTools); + JSHandle ark_tools(InitializeArkTools(env)); + SetConstantObject(global_object, "ArkTools", ark_tools); } #if ECMASCRIPT_ENABLE_ARK_CONTAINER @@ -377,319 +378,323 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa #endif // Global object function - SetFunction(env, globalObject, "eval", Global::Eval, FunctionLength::ONE); - SetFunction(env, globalObject, "isFinite", Global::IsFinite, FunctionLength::ONE); - SetFunction(env, globalObject, "isNaN", Global::IsNaN, FunctionLength::ONE); - SetFunction(env, globalObject, "unescape", Global::Unescape, FunctionLength::ONE); - SetFunction(env, globalObject, "escape", Global::Escape, FunctionLength::ONE); - SetFunction(env, globalObject, "decodeURI", Global::DecodeURI, FunctionLength::ONE); - SetFunction(env, globalObject, "encodeURI", Global::EncodeURI, FunctionLength::ONE); - SetFunction(env, globalObject, "decodeURIComponent", Global::DecodeURIComponent, FunctionLength::ONE); - SetFunction(env, globalObject, "encodeURIComponent", Global::EncodeURIComponent, FunctionLength::ONE); + 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(globalObject, "globalThis", JSHandle::Cast(globalObject)); - SetConstant(globalObject, "Infinity", JSTaggedValue(base::POSITIVE_INFINITY)); - SetConstant(globalObject, "NaN", JSTaggedValue(base::NAN_VALUE)); - SetConstant(globalObject, "undefined", JSTaggedValue::Undefined()); + 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()); } -void Builtins::InitializeFunction(const JSHandle &env, const JSHandle &emptyFuncDynclass) const +void Builtins::InitializeFunction(const JSHandle &env, const JSHandle &empty_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Initialize Function.prototype - JSMethod *invokeSelf = + JSMethod *invoke_self = vm_->GetMethodForNativeFunction(reinterpret_cast(Function::FunctionPrototypeInvokeSelf)); - JSHandle funcFuncPrototype = factory_->NewJSFunctionByDynClass(invokeSelf, emptyFuncDynclass); + 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 emptyString(thread_->GlobalConstants()->GetHandledEmptyString()); - JSHandle undefinedString(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, JSHandle(funcFuncPrototype), emptyString, undefinedString); + JSHandle empty_string(thread_->GlobalConstants()->GetHandledEmptyString()); + JSHandle undefined_string(thread_, JSTaggedValue::Undefined()); + JSFunction::SetFunctionName(thread_, JSHandle(func_func_prototype), empty_string, undefined_string); // ecma 19.2.3 The value of the length property of the Function prototype object is 0. - JSFunction::SetFunctionLength(thread_, funcFuncPrototype, JSTaggedValue(FunctionLength::ZERO)); + JSFunction::SetFunctionLength(thread_, func_func_prototype, JSTaggedValue(FunctionLength::ZERO)); - JSHandle funcFuncPrototypeValue(funcFuncPrototype); + JSHandle func_func_prototype_value(func_func_prototype); // Function.prototype_or_dynclass - JSHandle funcFuncIntanceDynclass = factory_->CreateDynClass( - JSType::JS_FUNCTION, funcFuncPrototypeValue, HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - funcFuncIntanceDynclass->SetConstructor(true); + JSHandle func_func_intance_dynclass = factory_->CreateDynClass( + JSType::JS_FUNCTION, func_func_prototype_value, HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); + func_func_intance_dynclass->SetConstructor(true); // Function = new Function() (forbidden use NewBuiltinConstructor) JSMethod *ctor = vm_->GetMethodForNativeFunction(reinterpret_cast(Function::FunctionConstructor)); - JSHandle funcFunc = - factory_->NewJSFunctionByDynClass(ctor, funcFuncIntanceDynclass, FunctionKind::BUILTIN_CONSTRUCTOR); + JSHandle func_func = + factory_->NewJSFunctionByDynClass(ctor, func_func_intance_dynclass, FunctionKind::BUILTIN_CONSTRUCTOR); - auto funcFuncPrototypeObj = JSHandle(funcFuncPrototype); - InitializeCtor(env, funcFuncPrototypeObj, funcFunc, "Function", FunctionLength::ONE); + auto func_func_prototype_obj = JSHandle(func_func_prototype); + InitializeCtor(env, func_func_prototype_obj, func_func, "Function", FunctionLength::ONE); - funcFunc->SetFunctionPrototype(thread_, funcFuncIntanceDynclass.GetTaggedValue()); - env->SetFunctionFunction(thread_, funcFunc); - env->SetFunctionPrototype(thread_, funcFuncPrototype); + func_func->SetFunctionPrototype(thread_, func_func_intance_dynclass.GetTaggedValue()); + env->SetFunctionFunction(thread_, func_func); + env->SetFunctionPrototype(thread_, func_func_prototype); - JSHandle normalFuncClass = + JSHandle normal_func_class = factory_->CreateDynClass(JSType::JS_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE); - env->SetNormalFunctionClass(thread_, normalFuncClass); + env->SetNormalFunctionClass(thread_, normal_func_class); - JSHandle jSIntlBoundFunctionClass = factory_->CreateFunctionClass( + JSHandle j_s_intl_bound_function_class = factory_->CreateFunctionClass( FunctionKind::NORMAL_FUNCTION, JSType::JS_INTL_BOUND_FUNCTION, env->GetFunctionPrototype()); - env->SetJSIntlBoundFunctionClass(thread_, jSIntlBoundFunctionClass); + env->SetJSIntlBoundFunctionClass(thread_, j_s_intl_bound_function_class); - JSHandle constructorFunctionClass = factory_->CreateDynClass( + JSHandle constructor_function_class = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetFunctionPrototype(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - constructorFunctionClass->SetConstructor(true); - env->SetConstructorFunctionClass(thread_, constructorFunctionClass); + constructor_function_class->SetConstructor(true); + env->SetConstructorFunctionClass(thread_, constructor_function_class); - StrictModeForbiddenAccessCallerArguments(env, funcFuncPrototypeObj); + StrictModeForbiddenAccessCallerArguments(env, func_func_prototype_obj); // Function.prototype method // 19.2.3.1 Function.prototype.apply ( thisArg, argArray ) - SetFunction(env, funcFuncPrototypeObj, "apply", Function::FunctionPrototypeApply, FunctionLength::TWO); + SetFunction(env, func_func_prototype_obj, "apply", Function::FunctionPrototypeApply, FunctionLength::TWO); // 19.2.3.2 Function.prototype.bind ( thisArg , ...args) - SetFunction(env, funcFuncPrototypeObj, "bind", Function::FunctionPrototypeBind, FunctionLength::ONE); + SetFunction(env, func_func_prototype_obj, "bind", Function::FunctionPrototypeBind, FunctionLength::ONE); // 19.2.3.3 Function.prototype.call (thisArg , ...args) - SetFunction(env, funcFuncPrototypeObj, "call", Function::FunctionPrototypeCall, FunctionLength::ONE); + SetFunction(env, func_func_prototype_obj, "call", Function::FunctionPrototypeCall, FunctionLength::ONE); // 19.2.3.5 Function.prototype.toString ( ) - SetFunction(env, funcFuncPrototypeObj, thread_->GlobalConstants()->GetHandledToStringString(), + SetFunction(env, func_func_prototype_obj, thread_->GlobalConstants()->GetHandledToStringString(), Function::FunctionPrototypeToString, FunctionLength::ZERO); } -void Builtins::InitializeObject(const JSHandle &env, const JSHandle &objFuncPrototype, - const JSHandle &objFunc) +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, objFunc, "assign", Object::Assign, FunctionLength::TWO); + SetFunction(env, obj_func, "assign", Object::Assign, FunctionLength::TWO); // 19.1.2.2Object.create ( O [ , Properties ] ) - SetFunction(env, objFunc, "create", Object::Create, FunctionLength::TWO); + SetFunction(env, obj_func, "create", Object::Create, FunctionLength::TWO); // 19.1.2.3Object.defineProperties ( O, Properties ) - SetFunction(env, objFunc, "defineProperties", Object::DefineProperties, FunctionLength::TWO); + SetFunction(env, obj_func, "defineProperties", Object::DefineProperties, FunctionLength::TWO); // 19.1.2.4Object.defineProperty ( O, P, Attributes ) - SetFunction(env, objFunc, "defineProperty", Object::DefineProperty, FunctionLength::THREE); + SetFunction(env, obj_func, "defineProperty", Object::DefineProperty, FunctionLength::THREE); // 19.1.2.5Object.freeze ( O ) - SetFunction(env, objFunc, "freeze", Object::Freeze, FunctionLength::ONE); + SetFunction(env, obj_func, "freeze", Object::Freeze, FunctionLength::ONE); // ES2021 20.1.2.7Object.fromEntries ( iterable ) - SetFunction(env, objFunc, "fromEntries", Object::FromEntries, FunctionLength::ONE); + SetFunction(env, obj_func, "fromEntries", Object::FromEntries, FunctionLength::ONE); // 19.1.2.6Object.getOwnPropertyDescriptor ( O, P ) - SetFunction(env, objFunc, "getOwnPropertyDescriptor", Object::GetOwnPropertyDesciptor, FunctionLength::TWO); + SetFunction(env, obj_func, "getOwnPropertyDescriptor", Object::GetOwnPropertyDesciptor, FunctionLength::TWO); // ES2021 20.1.2.9 Object.getOwnPropertyDescriptors ( O ) - SetFunction(env, objFunc, "getOwnPropertyDescriptors", Object::GetOwnPropertyDesciptors, FunctionLength::ONE); + SetFunction(env, obj_func, "getOwnPropertyDescriptors", Object::GetOwnPropertyDesciptors, FunctionLength::ONE); // 19.1.2.7Object.getOwnPropertyNames ( O ) - SetFunction(env, objFunc, "getOwnPropertyNames", Object::GetOwnPropertyNames, FunctionLength::ONE); + SetFunction(env, obj_func, "getOwnPropertyNames", Object::GetOwnPropertyNames, FunctionLength::ONE); // 19.1.2.8Object.getOwnPropertySymbols ( O ) - SetFunction(env, objFunc, "getOwnPropertySymbols", Object::GetOwnPropertySymbols, FunctionLength::ONE); + SetFunction(env, obj_func, "getOwnPropertySymbols", Object::GetOwnPropertySymbols, FunctionLength::ONE); // 19.1.2.9Object.getPrototypeOf ( O ) - SetFunction(env, objFunc, "getPrototypeOf", Object::GetPrototypeOf, FunctionLength::ONE); + SetFunction(env, obj_func, "getPrototypeOf", Object::GetPrototypeOf, FunctionLength::ONE); // 19.1.2.10Object.is ( value1, value2 ) - SetFunction(env, objFunc, "is", Object::Is, 2); + SetFunction(env, obj_func, "is", Object::Is, 2); // 19.1.2.11Object.isExtensible ( O ) - SetFunction(env, objFunc, "isExtensible", Object::IsExtensible, FunctionLength::ONE); + SetFunction(env, obj_func, "isExtensible", Object::IsExtensible, FunctionLength::ONE); // 19.1.2.12Object.isFrozen ( O ) - SetFunction(env, objFunc, "isFrozen", Object::IsFrozen, FunctionLength::ONE); + SetFunction(env, obj_func, "isFrozen", Object::IsFrozen, FunctionLength::ONE); // 19.1.2.13Object.isSealed ( O ) - SetFunction(env, objFunc, "isSealed", Object::IsSealed, FunctionLength::ONE); + SetFunction(env, obj_func, "isSealed", Object::IsSealed, FunctionLength::ONE); // 19.1.2.14 Object.keys(O) - SetFunction(env, objFunc, "keys", Object::Keys, FunctionLength::ONE); + SetFunction(env, obj_func, "keys", Object::Keys, FunctionLength::ONE); // 19.1.2.15 Object.preventExtensions(O) - SetFunction(env, objFunc, "preventExtensions", Object::PreventExtensions, FunctionLength::ONE); + SetFunction(env, obj_func, "preventExtensions", Object::PreventExtensions, FunctionLength::ONE); // 19.1.2.17 Object.seal(O) - SetFunction(env, objFunc, "seal", Object::Seal, FunctionLength::ONE); + SetFunction(env, obj_func, "seal", Object::Seal, FunctionLength::ONE); // 19.1.2.18 Object.setPrototypeOf(O, proto) - SetFunction(env, objFunc, "setPrototypeOf", Object::SetPrototypeOf, FunctionLength::TWO); + SetFunction(env, obj_func, "setPrototypeOf", Object::SetPrototypeOf, FunctionLength::TWO); // 20.1.2.5 Object.entries ( O ) - SetFunction(env, objFunc, "entries", Object::Entries, FunctionLength::ONE); + SetFunction(env, obj_func, "entries", Object::Entries, FunctionLength::ONE); // ES2021 20.1.2.22 Object.values ( O ) - SetFunction(env, objFunc, "values", Object::Values, FunctionLength::ONE); + SetFunction(env, obj_func, "values", Object::Values, FunctionLength::ONE); // Object.property method // 19.1.3.2 Object.prototype.hasOwnProperty(V) - SetFunction(env, objFuncPrototype, "hasOwnProperty", Object::HasOwnProperty, FunctionLength::ONE); + SetFunction(env, obj_func_prototype, "hasOwnProperty", Object::HasOwnProperty, FunctionLength::ONE); // 19.1.3.3 Object.prototype.isPrototypeOf(V) - SetFunction(env, objFuncPrototype, "isPrototypeOf", Object::IsPrototypeOf, FunctionLength::ONE); + SetFunction(env, obj_func_prototype, "isPrototypeOf", Object::IsPrototypeOf, FunctionLength::ONE); // 19.1.3.4 Object.prototype.propertyIsEnumerable(V) - SetFunction(env, objFuncPrototype, "propertyIsEnumerable", Object::PropertyIsEnumerable, FunctionLength::ONE); + SetFunction(env, obj_func_prototype, "propertyIsEnumerable", Object::PropertyIsEnumerable, FunctionLength::ONE); // 19.1.3.5 Object.prototype.toLocaleString([reserved1[, reserved2]]) - SetFunction(env, objFuncPrototype, "toLocaleString", Object::ToLocaleString, FunctionLength::ZERO); + SetFunction(env, obj_func_prototype, "toLocaleString", Object::ToLocaleString, FunctionLength::ZERO); // 19.1.3.6 Object.prototype.toString() - SetFunction(env, objFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Object::ToString, + SetFunction(env, obj_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Object::ToString, FunctionLength::ZERO); // 19.1.3.7 Object.prototype.valueOf() - SetFunction(env, objFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), Object::ValueOf, + SetFunction(env, obj_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Object::ValueOf, FunctionLength::ZERO); - SetFunction(env, objFuncPrototype, "createRealm", Object::CreateRealm, FunctionLength::ZERO); + SetFunction(env, obj_func_prototype, "createRealm", Object::CreateRealm, FunctionLength::ZERO); // B.2.2.1 Object.prototype.__proto__ - JSHandle protoKey(factory_->NewFromCanBeCompressString("__proto__")); - JSHandle protoGetter = CreateGetter(env, Object::ProtoGetter, "__proto__", FunctionLength::ZERO); - JSHandle protoSetter = CreateSetter(env, Object::ProtoSetter, "__proto__", FunctionLength::ONE); - SetAccessor(objFuncPrototype, protoKey, protoGetter, protoSetter); + 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, objFuncPrototype, "__defineGetter__", Object::DefineGetter, FunctionLength::TWO); + SetFunction(env, obj_func_prototype, "__defineGetter__", Object::DefineGetter, FunctionLength::TWO); // B.2.2.3 Object.prototype.__defineSetter__ ( P, setter ) - SetFunction(env, objFuncPrototype, "__defineSetter__", Object::DefineSetter, FunctionLength::TWO); + SetFunction(env, obj_func_prototype, "__defineSetter__", Object::DefineSetter, FunctionLength::TWO); // B.2.2.4 Object.prototype.__lookupGetter__ ( P ) - SetFunction(env, objFuncPrototype, "__lookupGetter__", Object::LookupGetter, FunctionLength::ONE); + SetFunction(env, obj_func_prototype, "__lookupGetter__", Object::LookupGetter, FunctionLength::ONE); // B.2.2.5 Object.prototype.__lookupSetter__ ( P ) - SetFunction(env, objFuncPrototype, "__lookupSetter__", Object::LookupSetter, FunctionLength::ONE); + SetFunction(env, obj_func_prototype, "__lookupSetter__", Object::LookupSetter, FunctionLength::ONE); } -void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeSymbol(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // Symbol.prototype - JSHandle symbolFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle symbolFuncPrototypeValue(symbolFuncPrototype); + JSHandle symbol_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle symbol_func_prototype_value(symbol_func_prototype); // Symbol.prototype_or_dynclass - JSHandle symbolFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbolFuncPrototypeValue); + JSHandle symbol_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbol_func_prototype_value); // Symbol = new Function() - JSHandle symbolFunction( - NewBuiltinConstructor(env, symbolFuncPrototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); - JSHandle(symbolFunction)->SetFunctionPrototype(thread_, symbolFuncInstanceDynclass.GetTaggedValue()); + JSHandle symbol_function( + NewBuiltinConstructor(env, symbol_func_prototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); + JSHandle(symbol_function) + ->SetFunctionPrototype(thread_, symbol_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbolFunction), true, false, true); - JSObject::DefineOwnProperty(thread_, symbolFuncPrototype, constructorKey, descriptor); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbol_function), true, false, true); + JSObject::DefineOwnProperty(thread_, symbol_func_prototype, constructor_key, descriptor); - SetFunction(env, symbolFunction, "for", Symbol::For, FunctionLength::ONE); - SetFunction(env, symbolFunction, "keyFor", Symbol::KeyFor, FunctionLength::ONE); + SetFunction(env, symbol_function, "for", Symbol::For, FunctionLength::ONE); + SetFunction(env, symbol_function, "keyFor", Symbol::KeyFor, FunctionLength::ONE); // Symbol attribute - JSHandle hasInstanceSymbol(factory_->NewWellKnownSymbolWithChar("Symbol.hasInstance")); - SetNoneAttributeProperty(symbolFunction, "hasInstance", hasInstanceSymbol); - JSHandle isConcatSpreadableSymbol(factory_->NewWellKnownSymbolWithChar("Symbol.isConcatSpreadable")); - SetNoneAttributeProperty(symbolFunction, "isConcatSpreadable", isConcatSpreadableSymbol); - JSHandle toStringTagSymbol(factory_->NewWellKnownSymbolWithChar("Symbol.toStringTag")); - SetNoneAttributeProperty(symbolFunction, "toStringTag", toStringTagSymbol); - JSHandle iteratorSymbol(factory_->NewPublicSymbolWithChar("Symbol.iterator")); - SetNoneAttributeProperty(symbolFunction, "iterator", iteratorSymbol); - JSHandle asyncIteratorSymbol(factory_->NewPublicSymbolWithChar("Symbol.asyncIterator")); - SetNoneAttributeProperty(symbolFunction, "asyncIterator", asyncIteratorSymbol); - JSHandle matchSymbol(factory_->NewPublicSymbolWithChar("Symbol.match")); - SetNoneAttributeProperty(symbolFunction, "match", matchSymbol); - JSHandle matchAllSymbol(factory_->NewPublicSymbolWithChar("Symbol.matchAll")); - SetNoneAttributeProperty(symbolFunction, "matchAll", matchAllSymbol); - JSHandle replaceSymbol(factory_->NewPublicSymbolWithChar("Symbol.replace")); - SetNoneAttributeProperty(symbolFunction, "replace", replaceSymbol); - JSHandle searchSymbol(factory_->NewPublicSymbolWithChar("Symbol.search")); - SetNoneAttributeProperty(symbolFunction, "search", searchSymbol); - JSHandle speciesSymbol(factory_->NewPublicSymbolWithChar("Symbol.species")); - SetNoneAttributeProperty(symbolFunction, "species", speciesSymbol); - JSHandle splitSymbol(factory_->NewPublicSymbolWithChar("Symbol.split")); - SetNoneAttributeProperty(symbolFunction, "split", splitSymbol); - JSHandle toPrimitiveSymbol(factory_->NewPublicSymbolWithChar("Symbol.toPrimitive")); - SetNoneAttributeProperty(symbolFunction, "toPrimitive", toPrimitiveSymbol); - JSHandle unscopablesSymbol(factory_->NewPublicSymbolWithChar("Symbol.unscopables")); - SetNoneAttributeProperty(symbolFunction, "unscopables", unscopablesSymbol); + JSHandle has_instance_symbol(factory_->NewWellKnownSymbolWithChar("Symbol.hasInstance")); + SetNoneAttributeProperty(symbol_function, "hasInstance", has_instance_symbol); + JSHandle is_concat_spreadable_symbol( + factory_->NewWellKnownSymbolWithChar("Symbol.isConcatSpreadable")); + SetNoneAttributeProperty(symbol_function, "isConcatSpreadable", is_concat_spreadable_symbol); + JSHandle to_string_tag_symbol(factory_->NewWellKnownSymbolWithChar("Symbol.toStringTag")); + SetNoneAttributeProperty(symbol_function, "toStringTag", to_string_tag_symbol); + JSHandle iterator_symbol(factory_->NewPublicSymbolWithChar("Symbol.iterator")); + SetNoneAttributeProperty(symbol_function, "iterator", iterator_symbol); + JSHandle async_iterator_symbol(factory_->NewPublicSymbolWithChar("Symbol.asyncIterator")); + SetNoneAttributeProperty(symbol_function, "asyncIterator", async_iterator_symbol); + JSHandle match_symbol(factory_->NewPublicSymbolWithChar("Symbol.match")); + SetNoneAttributeProperty(symbol_function, "match", match_symbol); + JSHandle match_all_symbol(factory_->NewPublicSymbolWithChar("Symbol.matchAll")); + SetNoneAttributeProperty(symbol_function, "matchAll", match_all_symbol); + JSHandle replace_symbol(factory_->NewPublicSymbolWithChar("Symbol.replace")); + SetNoneAttributeProperty(symbol_function, "replace", replace_symbol); + JSHandle search_symbol(factory_->NewPublicSymbolWithChar("Symbol.search")); + SetNoneAttributeProperty(symbol_function, "search", search_symbol); + JSHandle species_symbol(factory_->NewPublicSymbolWithChar("Symbol.species")); + SetNoneAttributeProperty(symbol_function, "species", species_symbol); + JSHandle split_symbol(factory_->NewPublicSymbolWithChar("Symbol.split")); + SetNoneAttributeProperty(symbol_function, "split", split_symbol); + JSHandle to_primitive_symbol(factory_->NewPublicSymbolWithChar("Symbol.toPrimitive")); + SetNoneAttributeProperty(symbol_function, "toPrimitive", to_primitive_symbol); + JSHandle unscopables_symbol(factory_->NewPublicSymbolWithChar("Symbol.unscopables")); + SetNoneAttributeProperty(symbol_function, "unscopables", unscopables_symbol); // symbol.prototype.description - PropertyDescriptor descriptionDesc(thread_); - JSHandle getterKey(factory_->NewFromCanBeCompressString("description")); + PropertyDescriptor description_desc(thread_); + JSHandle getter_key(factory_->NewFromCanBeCompressString("description")); JSHandle getter(factory_->NewJSFunction(env, reinterpret_cast(Symbol::DescriptionGetter))); - SetGetter(symbolFuncPrototype, getterKey, getter); + SetGetter(symbol_func_prototype, getter_key, getter); // Setup symbol.prototype[@@toPrimitive] - SetFunctionAtSymbol( - env, symbolFuncPrototype, toPrimitiveSymbol, "[Symbol.toPrimitive]", Symbol::ToPrimitive, FunctionLength::ONE); + SetFunctionAtSymbol(env, symbol_func_prototype, to_primitive_symbol, + "[Symbol.toPrimitive]", Symbol::ToPrimitive, + FunctionLength::ONE); // install the Symbol.prototype methods - SetFunction(env, symbolFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Symbol::ToString, + SetFunction(env, symbol_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Symbol::ToString, FunctionLength::ZERO); - SetFunction(env, symbolFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), Symbol::ValueOf, + SetFunction(env, symbol_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Symbol::ValueOf, FunctionLength::ZERO); - env->SetSymbolFunction(thread_, symbolFunction); - env->SetHasInstanceSymbol(thread_, hasInstanceSymbol); - env->SetIsConcatSpreadableSymbol(thread_, isConcatSpreadableSymbol); - env->SetToStringTagSymbol(thread_, toStringTagSymbol); - env->SetIteratorSymbol(thread_, iteratorSymbol); - env->SetAsyncIteratorSymbol(thread_, asyncIteratorSymbol); - env->SetMatchSymbol(thread_, matchSymbol); - env->SetMatchAllSymbol(thread_, matchAllSymbol); - env->SetReplaceSymbol(thread_, replaceSymbol); - env->SetSearchSymbol(thread_, searchSymbol); - env->SetSpeciesSymbol(thread_, speciesSymbol); - env->SetSplitSymbol(thread_, splitSymbol); - env->SetToPrimitiveSymbol(thread_, toPrimitiveSymbol); - env->SetUnscopablesSymbol(thread_, unscopablesSymbol); + env->SetSymbolFunction(thread_, symbol_function); + env->SetHasInstanceSymbol(thread_, has_instance_symbol); + env->SetIsConcatSpreadableSymbol(thread_, is_concat_spreadable_symbol); + env->SetToStringTagSymbol(thread_, to_string_tag_symbol); + env->SetIteratorSymbol(thread_, iterator_symbol); + env->SetAsyncIteratorSymbol(thread_, async_iterator_symbol); + env->SetMatchSymbol(thread_, match_symbol); + env->SetMatchAllSymbol(thread_, match_all_symbol); + env->SetReplaceSymbol(thread_, replace_symbol); + env->SetSearchSymbol(thread_, search_symbol); + env->SetSpeciesSymbol(thread_, species_symbol); + env->SetSplitSymbol(thread_, split_symbol); + env->SetToPrimitiveSymbol(thread_, to_primitive_symbol); + env->SetUnscopablesSymbol(thread_, unscopables_symbol); // Setup %SymbolPrototype% - SetStringTagSymbol(env, symbolFuncPrototype, "Symbol"); + SetStringTagSymbol(env, symbol_func_prototype, "Symbol"); - JSHandle holeySymbol(factory_->NewPrivateNameSymbolWithChar("holey")); - env->SetHoleySymbol(thread_, holeySymbol.GetTaggedValue()); - JSHandle elementIcSymbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); - env->SetElementICSymbol(thread_, elementIcSymbol.GetTaggedValue()); + JSHandle holey_symbol(factory_->NewPrivateNameSymbolWithChar("holey")); + env->SetHoleySymbol(thread_, holey_symbol.GetTaggedValue()); + JSHandle element_ic_symbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); + env->SetElementICSymbol(thread_, element_ic_symbol.GetTaggedValue()); // ecma 19.2.3.6 Function.prototype[@@hasInstance] ( V ) - JSHandle funcFuncPrototypeObj = JSHandle(env->GetFunctionPrototype()); + JSHandle func_func_prototype_obj = JSHandle(env->GetFunctionPrototype()); SetFunctionAtSymbol( - env, funcFuncPrototypeObj, env->GetHasInstanceSymbol(), "[Symbol.hasInstance]", + env, func_func_prototype_obj, env->GetHasInstanceSymbol(), "[Symbol.hasInstance]", Function::FunctionPrototypeHasInstance, FunctionLength::ONE); } void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, - const JSHandle &objFuncInstanceDynclass) + const JSHandle &obj_func_instance_dynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); JSHandle env = vm_->GetGlobalEnv(); // Symbol.prototype - JSHandle symbolFuncPrototype = factory_->NewJSObject(objFuncInstanceDynclass); - JSHandle symbolFuncPrototypeValue(symbolFuncPrototype); + JSHandle symbol_func_prototype = factory_->NewJSObject(obj_func_instance_dynclass); + JSHandle symbol_func_prototype_value(symbol_func_prototype); // Symbol.prototype_or_dynclass - JSHandle symbolFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbolFuncPrototypeValue); + JSHandle symbol_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, symbol_func_prototype_value); // Symbol = new Function() - JSHandle symbolFunction( - NewBuiltinConstructor(realm, symbolFuncPrototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); - JSHandle(symbolFunction)->SetFunctionPrototype(thread_, symbolFuncInstanceDynclass.GetTaggedValue()); + JSHandle symbol_function( + NewBuiltinConstructor(realm, symbol_func_prototype, Symbol::SymbolConstructor, "Symbol", FunctionLength::ZERO)); + JSHandle(symbol_function) + ->SetFunctionPrototype(thread_, symbol_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = thread_->GlobalConstants()->GetHandledConstructorString(); - PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbolFunction), true, false, true); - JSObject::DefineOwnProperty(thread_, symbolFuncPrototype, constructorKey, descriptor); + JSHandle constructor_key = thread_->GlobalConstants()->GetHandledConstructorString(); + PropertyDescriptor descriptor(thread_, JSHandle::Cast(symbol_function), true, false, true); + JSObject::DefineOwnProperty(thread_, symbol_func_prototype, constructor_key, descriptor); - SetFunction(realm, symbolFunction, "for", Symbol::For, FunctionLength::ONE); - SetFunction(realm, symbolFunction, "keyFor", Symbol::KeyFor, FunctionLength::ONE); + SetFunction(realm, symbol_function, "for", Symbol::For, FunctionLength::ONE); + SetFunction(realm, symbol_function, "keyFor", Symbol::KeyFor, FunctionLength::ONE); // Symbol attribute - SetNoneAttributeProperty(symbolFunction, "hasInstance", env->GetHasInstanceSymbol()); - SetNoneAttributeProperty(symbolFunction, "isConcatSpreadable", env->GetIsConcatSpreadableSymbol()); - SetNoneAttributeProperty(symbolFunction, "toStringTag", env->GetToStringTagSymbol()); - SetNoneAttributeProperty(symbolFunction, "iterator", env->GetIteratorSymbol()); - SetNoneAttributeProperty(symbolFunction, "asyncIterator", env->GetAsyncIteratorSymbol()); - SetNoneAttributeProperty(symbolFunction, "match", env->GetMatchSymbol()); - SetNoneAttributeProperty(symbolFunction, "matchAll", env->GetMatchAllSymbol()); - SetNoneAttributeProperty(symbolFunction, "replace", env->GetReplaceSymbol()); - SetNoneAttributeProperty(symbolFunction, "search", env->GetSearchSymbol()); - SetNoneAttributeProperty(symbolFunction, "species", env->GetSpeciesSymbol()); - SetNoneAttributeProperty(symbolFunction, "split", env->GetSplitSymbol()); - SetNoneAttributeProperty(symbolFunction, "toPrimitive", env->GetToPrimitiveSymbol()); - SetNoneAttributeProperty(symbolFunction, "unscopables", env->GetUnscopablesSymbol()); + SetNoneAttributeProperty(symbol_function, "hasInstance", env->GetHasInstanceSymbol()); + SetNoneAttributeProperty(symbol_function, "isConcatSpreadable", env->GetIsConcatSpreadableSymbol()); + SetNoneAttributeProperty(symbol_function, "toStringTag", env->GetToStringTagSymbol()); + SetNoneAttributeProperty(symbol_function, "iterator", env->GetIteratorSymbol()); + SetNoneAttributeProperty(symbol_function, "asyncIterator", env->GetAsyncIteratorSymbol()); + SetNoneAttributeProperty(symbol_function, "match", env->GetMatchSymbol()); + SetNoneAttributeProperty(symbol_function, "matchAll", env->GetMatchAllSymbol()); + SetNoneAttributeProperty(symbol_function, "replace", env->GetReplaceSymbol()); + SetNoneAttributeProperty(symbol_function, "search", env->GetSearchSymbol()); + SetNoneAttributeProperty(symbol_function, "species", env->GetSpeciesSymbol()); + SetNoneAttributeProperty(symbol_function, "split", env->GetSplitSymbol()); + SetNoneAttributeProperty(symbol_function, "toPrimitive", env->GetToPrimitiveSymbol()); + SetNoneAttributeProperty(symbol_function, "unscopables", env->GetUnscopablesSymbol()); // symbol.prototype.description - PropertyDescriptor descriptionDesc(thread_); - JSHandle getterKey(factory_->NewFromCanBeCompressString("description")); + PropertyDescriptor description_desc(thread_); + JSHandle getter_key(factory_->NewFromCanBeCompressString("description")); JSHandle getter(factory_->NewJSFunction(realm, reinterpret_cast(Symbol::DescriptionGetter))); - SetGetter(symbolFuncPrototype, getterKey, getter); + SetGetter(symbol_func_prototype, getter_key, getter); // Setup symbol.prototype[@@toPrimitive] - SetFunctionAtSymbol(realm, symbolFuncPrototype, env->GetToPrimitiveSymbol(), + SetFunctionAtSymbol(realm, symbol_func_prototype, env->GetToPrimitiveSymbol(), "[Symbol.toPrimitive]", Symbol::ToPrimitive, FunctionLength::ONE); // install the Symbol.prototype methods - SetFunction(realm, symbolFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Symbol::ToString, + SetFunction(realm, symbol_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Symbol::ToString, FunctionLength::ZERO); - SetFunction(realm, symbolFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), Symbol::ValueOf, + SetFunction(realm, symbol_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Symbol::ValueOf, FunctionLength::ZERO); - realm->SetSymbolFunction(thread_, symbolFunction); + realm->SetSymbolFunction(thread_, symbol_function); realm->SetHasInstanceSymbol(thread_, env->GetHasInstanceSymbol()); realm->SetIsConcatSpreadableSymbol(thread_, env->GetIsConcatSpreadableSymbol()); realm->SetToStringTagSymbol(thread_, env->GetToStringTagSymbol()); @@ -705,301 +710,303 @@ void Builtins::InitializeSymbolWithRealm(const JSHandle &realm, realm->SetUnscopablesSymbol(thread_, env->GetUnscopablesSymbol()); // Setup %SymbolPrototype% - SetStringTagSymbol(realm, symbolFuncPrototype, "Symbol"); + SetStringTagSymbol(realm, symbol_func_prototype, "Symbol"); - JSHandle holeySymbol(factory_->NewPrivateNameSymbolWithChar("holey")); - realm->SetHoleySymbol(thread_, holeySymbol.GetTaggedValue()); - JSHandle elementIcSymbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); - realm->SetElementICSymbol(thread_, elementIcSymbol.GetTaggedValue()); + JSHandle holey_symbol(factory_->NewPrivateNameSymbolWithChar("holey")); + realm->SetHoleySymbol(thread_, holey_symbol.GetTaggedValue()); + JSHandle element_ic_symbol(factory_->NewPrivateNameSymbolWithChar("element-ic")); + realm->SetElementICSymbol(thread_, element_ic_symbol.GetTaggedValue()); // ecma 19.2.3.6 Function.prototype[@@hasInstance] ( V ) - JSHandle funcFuncPrototypeObj = JSHandle(realm->GetFunctionPrototype()); + JSHandle func_func_prototype_obj = JSHandle(realm->GetFunctionPrototype()); SetFunctionAtSymbol( - realm, funcFuncPrototypeObj, realm->GetHasInstanceSymbol(), "[Symbol.hasInstance]", + realm, func_func_prototype_obj, realm->GetHasInstanceSymbol(), "[Symbol.hasInstance]", Function::FunctionPrototypeHasInstance, FunctionLength::ONE); } -void Builtins::InitializeNumber(const JSHandle &env, const JSHandle &globalObject, - const JSHandle &primRefObjDynclass) +void Builtins::InitializeNumber(const JSHandle &env, const JSHandle &global_object, + const JSHandle &prim_ref_obj_dynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Number.prototype - JSHandle toObject(thread_, JSTaggedValue(FunctionLength::ZERO)); - JSHandle numFuncPrototype = - JSHandle::Cast(factory_->NewJSPrimitiveRef(primRefObjDynclass, toObject)); - JSHandle numFuncPrototypeValue(numFuncPrototype); + JSHandle to_object(thread_, JSTaggedValue(FunctionLength::ZERO)); + JSHandle num_func_prototype = + JSHandle::Cast(factory_->NewJSPrimitiveRef(prim_ref_obj_dynclass, to_object)); + JSHandle num_func_prototype_value(num_func_prototype); // Number.prototype_or_dynclass - JSHandle numFuncInstanceClass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, numFuncPrototypeValue); + JSHandle num_func_instance_class = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, num_func_prototype_value); // Number = new Function() - JSHandle numFunction( - NewBuiltinConstructor(env, numFuncPrototype, Number::NumberConstructor, "Number", FunctionLength::ONE)); - numFunction.GetObject()->SetFunctionPrototype(thread_, numFuncInstanceClass.GetTaggedValue()); + JSHandle num_function( + NewBuiltinConstructor(env, num_func_prototype, Number::NumberConstructor, "Number", FunctionLength::ONE)); + num_function.GetObject()->SetFunctionPrototype(thread_, num_func_instance_class.GetTaggedValue()); // Number.prototype method - SetFunction(env, numFuncPrototype, "toExponential", Number::ToExponential, FunctionLength::ONE); - SetFunction(env, numFuncPrototype, "toFixed", Number::ToFixed, FunctionLength::ONE); - SetFunction(env, numFuncPrototype, "toLocaleString", Number::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, numFuncPrototype, "toPrecision", Number::ToPrecision, FunctionLength::ONE); - SetFunction(env, numFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Number::ToString, + 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, numFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), Number::ValueOf, + SetFunction(env, num_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Number::ValueOf, FunctionLength::ZERO); // Number method - SetFunction(env, numFunction, "isFinite", Number::IsFinite, FunctionLength::ONE); - SetFunction(env, numFunction, "isInteger", Number::IsInteger, FunctionLength::ONE); - SetFunction(env, numFunction, "isNaN", Number::IsNaN, FunctionLength::ONE); - SetFunction(env, numFunction, "isSafeInteger", Number::IsSafeInteger, FunctionLength::ONE); - SetFuncToObjAndGlobal(env, globalObject, numFunction, "parseFloat", Number::ParseFloat, FunctionLength::ONE); - SetFuncToObjAndGlobal(env, globalObject, numFunction, "parseInt", Number::ParseInt, FunctionLength::TWO); + 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; - const double maxSafeInteger = 9007199254740991; - const double maxValue = 1.7976931348623157e+308; - const double minValue = 5e-324; - const double positiveInfinity = std::numeric_limits::infinity(); - SetConstant(numFunction, "MAX_VALUE", JSTaggedValue(maxValue)); - SetConstant(numFunction, "MIN_VALUE", JSTaggedValue(minValue)); - SetConstant(numFunction, "NaN", JSTaggedValue(NAN)); - SetConstant(numFunction, "NEGATIVE_INFINITY", JSTaggedValue(-positiveInfinity)); - SetConstant(numFunction, "POSITIVE_INFINITY", JSTaggedValue(positiveInfinity)); - SetConstant(numFunction, "MAX_SAFE_INTEGER", JSTaggedValue(maxSafeInteger)); - SetConstant(numFunction, "MIN_SAFE_INTEGER", JSTaggedValue(-maxSafeInteger)); - SetConstant(numFunction, "EPSILON", JSTaggedValue(epsilon)); + const double max_safe_integer = 9007199254740991; + const double max_value = 1.7976931348623157e+308; + const double min_value = 5e-324; + const double positive_infinity = std::numeric_limits::infinity(); + SetConstant(num_function, "MAX_VALUE", JSTaggedValue(max_value)); + SetConstant(num_function, "MIN_VALUE", JSTaggedValue(min_value)); + SetConstant(num_function, "NaN", JSTaggedValue(NAN)); + SetConstant(num_function, "NEGATIVE_INFINITY", JSTaggedValue(-positive_infinity)); + SetConstant(num_function, "POSITIVE_INFINITY", JSTaggedValue(positive_infinity)); + SetConstant(num_function, "MAX_SAFE_INTEGER", JSTaggedValue(max_safe_integer)); + SetConstant(num_function, "MIN_SAFE_INTEGER", JSTaggedValue(-max_safe_integer)); + SetConstant(num_function, "EPSILON", JSTaggedValue(epsilon)); - env->SetNumberFunction(thread_, numFunction); + env->SetNumberFunction(thread_, num_function); } -void Builtins::InitializeBigInt(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeBigInt(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigInt.prototype - JSHandle bigIntFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle bigIntFuncPrototypeValue(bigIntFuncPrototype); + JSHandle big_int_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle big_int_func_prototype_value(big_int_func_prototype); // BigInt.prototype_or_dynclass - JSHandle bigIntFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, bigIntFuncPrototypeValue); + JSHandle big_int_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, big_int_func_prototype_value); // BigInt = new Function() - JSHandle bigIntFunction(NewBuiltinConstructor(env, bigIntFuncPrototype, BuiltinsBigInt::BigIntConstructor, - "BigInt", FunctionLength::ONE)); - JSHandle(bigIntFunction)->SetFunctionPrototype(thread_, bigIntFuncInstanceDynclass.GetTaggedValue()); + JSHandle big_int_function(NewBuiltinConstructor( + env, big_int_func_prototype, BuiltinsBigInt::BigIntConstructor, "BigInt", FunctionLength::ONE)); + JSHandle(big_int_function) + ->SetFunctionPrototype(thread_, big_int_func_instance_dynclass.GetTaggedValue()); // BigInt.prototype method - SetFunction(env, bigIntFuncPrototype, "toLocaleString", BuiltinsBigInt::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, bigIntFuncPrototype, "toString", BuiltinsBigInt::ToString, FunctionLength::ZERO); - SetFunction(env, bigIntFuncPrototype, "valueOf", BuiltinsBigInt::ValueOf, FunctionLength::ZERO); + 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, bigIntFunction, "asUintN", BuiltinsBigInt::AsUintN, FunctionLength::TWO); - SetFunction(env, bigIntFunction, "asIntN", BuiltinsBigInt::AsIntN, FunctionLength::TWO); + SetFunction(env, big_int_function, "asUintN", BuiltinsBigInt::AsUintN, FunctionLength::TWO); + SetFunction(env, big_int_function, "asIntN", BuiltinsBigInt::AsIntN, FunctionLength::TWO); // @@ToStringTag - SetStringTagSymbol(env, bigIntFuncPrototype, "BigInt"); - env->SetBigIntFunction(thread_, bigIntFunction); + SetStringTagSymbol(env, big_int_func_prototype, "BigInt"); + env->SetBigIntFunction(thread_, big_int_function); } -void Builtins::InitializeDate(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeDate(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const int utcLength = 7; + const int utc_length = 7; // Date.prototype - JSHandle dateFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle dateFuncPrototypeValue(dateFuncPrototype); + JSHandle date_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle date_func_prototype_value(date_func_prototype); // Date.prototype_or_dynclass - JSHandle dateFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_DATE, dateFuncPrototypeValue); + JSHandle date_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_DATE, date_func_prototype_value); // Date = new Function() - JSHandle dateFunction( - NewBuiltinConstructor(env, dateFuncPrototype, Date::DateConstructor, "Date", FunctionLength::ONE)); - JSHandle(dateFunction)->SetFunctionPrototype(thread_, dateFuncInstanceDynclass.GetTaggedValue()); + JSHandle date_function( + NewBuiltinConstructor(env, date_func_prototype, Date::DateConstructor, "Date", FunctionLength::ONE)); + JSHandle(date_function)->SetFunctionPrototype(thread_, date_func_instance_dynclass.GetTaggedValue()); // Date.prototype method - SetFunction(env, dateFuncPrototype, "getDate", Date::GetDate, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getDay", Date::GetDay, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getFullYear", Date::GetFullYear, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getYear", Date::GetYear, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getHours", Date::GetHours, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getMilliseconds", Date::GetMilliseconds, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getMinutes", Date::GetMinutes, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getMonth", Date::GetMonth, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getSeconds", Date::GetSeconds, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getTime", Date::GetTime, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getTimezoneOffset", Date::GetTimezoneOffset, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCDate", Date::GetUTCDate, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCDay", Date::GetUTCDay, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCFullYear", Date::GetUTCFullYear, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCHours", Date::GetUTCHours, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCMilliseconds", Date::GetUTCMilliseconds, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCMinutes", Date::GetUTCMinutes, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCMonth", Date::GetUTCMonth, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "getUTCSeconds", Date::GetUTCSeconds, FunctionLength::ZERO); - - SetFunction(env, dateFuncPrototype, "setDate", Date::SetDate, FunctionLength::ONE); - SetFunction(env, dateFuncPrototype, "setFullYear", Date::SetFullYear, FunctionLength::THREE); - SetFunction(env, dateFuncPrototype, "setHours", Date::SetHours, FunctionLength::FOUR); - SetFunction(env, dateFuncPrototype, "setMilliseconds", Date::SetMilliseconds, FunctionLength::ONE); - SetFunction(env, dateFuncPrototype, "setMinutes", Date::SetMinutes, FunctionLength::THREE); - SetFunction(env, dateFuncPrototype, "setMonth", Date::SetMonth, FunctionLength::TWO); - SetFunction(env, dateFuncPrototype, "setSeconds", Date::SetSeconds, FunctionLength::TWO); - SetFunction(env, dateFuncPrototype, "setTime", Date::SetTime, FunctionLength::ONE); - SetFunction(env, dateFuncPrototype, "setUTCDate", Date::SetUTCDate, FunctionLength::ONE); - SetFunction(env, dateFuncPrototype, "setUTCFullYear", Date::SetUTCFullYear, FunctionLength::THREE); - SetFunction(env, dateFuncPrototype, "setUTCHours", Date::SetUTCHours, FunctionLength::FOUR); - SetFunction(env, dateFuncPrototype, "setUTCMilliseconds", Date::SetUTCMilliseconds, FunctionLength::ONE); - SetFunction(env, dateFuncPrototype, "setUTCMinutes", Date::SetUTCMinutes, FunctionLength::THREE); - SetFunction(env, dateFuncPrototype, "setUTCMonth", Date::SetUTCMonth, FunctionLength::TWO); - SetFunction(env, dateFuncPrototype, "setUTCSeconds", Date::SetUTCSeconds, FunctionLength::TWO); - - SetFunction(env, dateFuncPrototype, "toDateString", Date::ToDateString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "toISOString", Date::ToISOString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "toJSON", Date::ToJSON, FunctionLength::ONE); - SetFunction(env, dateFuncPrototype, "toLocaleDateString", Date::ToLocaleDateString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "toLocaleString", Date::ToLocaleString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "toLocaleTimeString", Date::ToLocaleTimeString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Date::ToString, + 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, dateFuncPrototype, "toTimeString", Date::ToTimeString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, "toUTCString", Date::ToUTCString, FunctionLength::ZERO); - SetFunction(env, dateFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), Date::ValueOf, + 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, dateFuncPrototype, env->GetToPrimitiveSymbol(), "[Symbol.toPrimitive]", Date::ToPrimitive, - FunctionLength::ONE); + SetFunctionAtSymbol(env, date_func_prototype, env->GetToPrimitiveSymbol(), "[Symbol.toPrimitive]", + Date::ToPrimitive, FunctionLength::ONE); // Date method - SetFunction(env, dateFunction, "now", Date::Now, FunctionLength::ZERO); - SetFunction(env, dateFunction, "parse", Date::Parse, FunctionLength::ONE); - SetFunction(env, dateFunction, "UTC", Date::UTC, utcLength); + 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); // Date.length - SetConstant(dateFunction, "length", JSTaggedValue(utcLength)); + SetConstant(date_function, "length", JSTaggedValue(utc_length)); - env->SetDateFunction(thread_, dateFunction); + env->SetDateFunction(thread_, date_function); } -void Builtins::InitializeBoolean(const JSHandle &env, const JSHandle &primRefObjDynclass) const +void Builtins::InitializeBoolean(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Boolean.prototype - JSHandle toObject(thread_, JSTaggedValue::False()); - JSHandle booleanFuncPrototype = - JSHandle::Cast(factory_->NewJSPrimitiveRef(primRefObjDynclass, toObject)); - JSHandle booleanFuncPrototypeValue(booleanFuncPrototype); + JSHandle to_object(thread_, JSTaggedValue::False()); + JSHandle boolean_func_prototype = + JSHandle::Cast(factory_->NewJSPrimitiveRef(prim_ref_obj_dynclass, to_object)); + JSHandle boolean_func_prototype_value(boolean_func_prototype); // Boolean.prototype_or_dynclass - JSHandle booleanFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, booleanFuncPrototypeValue); + JSHandle boolean_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, boolean_func_prototype_value); // new Boolean Function() - JSHandle booleanFunction( - NewBuiltinConstructor(env, booleanFuncPrototype, Boolean::BooleanConstructor, "Boolean", FunctionLength::ONE)); - booleanFunction->SetFunctionPrototype(thread_, booleanFuncInstanceDynclass.GetTaggedValue()); + JSHandle boolean_function(NewBuiltinConstructor( + env, boolean_func_prototype, Boolean::BooleanConstructor, "Boolean", FunctionLength::ONE)); + boolean_function->SetFunctionPrototype(thread_, boolean_func_instance_dynclass.GetTaggedValue()); // Boolean.prototype method - SetFunction(env, booleanFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), + SetFunction(env, boolean_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Boolean::BooleanPrototypeToString, FunctionLength::ZERO); - SetFunction(env, booleanFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), + SetFunction(env, boolean_func_prototype, thread_->GlobalConstants()->GetHandledValueOfString(), Boolean::BooleanPrototypeValueOf, FunctionLength::ZERO); - env->SetBooleanFunction(thread_, booleanFunction); + env->SetBooleanFunction(thread_, boolean_function); } void Builtins::InitializeProxy(const JSHandle &env) { - JSHandle proxyFunction(InitializeExoticConstructor(env, Proxy::ProxyConstructor, "Proxy", 2)); + JSHandle proxy_function(InitializeExoticConstructor(env, Proxy::ProxyConstructor, "Proxy", 2)); // Proxy method - SetFunction(env, proxyFunction, "revocable", Proxy::Revocable, FunctionLength::TWO); - env->SetProxyFunction(thread_, proxyFunction); + SetFunction(env, proxy_function, "revocable", Proxy::Revocable, FunctionLength::TWO); + env->SetProxyFunction(thread_, proxy_function); } -JSHandle Builtins::InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctorFunc, +JSHandle Builtins::InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctor_func, const char *name, int length) { JSHandle ctor = - factory_->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_PROXY_CONSTRUCTOR); + factory_->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_PROXY_CONSTRUCTOR); JSFunction::SetFunctionLength(thread_, ctor, JSTaggedValue(length)); - JSHandle nameString(factory_->NewFromString(name)); - JSFunction::SetFunctionName(thread_, JSHandle(ctor), nameString, + JSHandle name_string(factory_->NewFromString(name)); + JSFunction::SetFunctionName(thread_, JSHandle(ctor), name_string, JSHandle(thread_, JSTaggedValue::Undefined())); - JSHandle globalObject(thread_, env->GetGlobalObject()); + JSHandle global_object(thread_, env->GetGlobalObject()); PropertyDescriptor descriptor(thread_, JSHandle(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor); + JSObject::DefineOwnProperty(thread_, global_object, name_string, descriptor); return ctor; } -void Builtins::InitializeAsyncFunction(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeAsyncFunction(const JSHandle &env, + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // AsyncFunction.prototype - JSHandle asyncFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSObject::SetPrototype(thread_, asyncFuncPrototype, env->GetFunctionPrototype()); - JSHandle async_func_prototype_value(asyncFuncPrototype); + JSHandle async_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSObject::SetPrototype(thread_, async_func_prototype, env->GetFunctionPrototype()); + JSHandle async_func_prototype_value(async_func_prototype); // AsyncFunction.prototype_or_dynclass - JSHandle asyncFuncInstanceDynclass = + JSHandle async_func_instance_dynclass = factory_->CreateDynClass(JSType::JS_ASYNC_FUNCTION, async_func_prototype_value); // AsyncFunction = new Function() - JSHandle asyncFunction = NewBuiltinConstructor( - env, asyncFuncPrototype, AsyncFunction::AsyncFunctionConstructor, "AsyncFunction", FunctionLength::ONE); - JSObject::SetPrototype(thread_, JSHandle::Cast(asyncFunction), env->GetFunctionFunction()); - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - PropertyDescriptor asyncDesc(thread_, JSHandle::Cast(asyncFunction), false, false, true); - JSObject::DefineOwnProperty(thread_, asyncFuncPrototype, constructorKey, asyncDesc); - asyncFunction->SetProtoOrDynClass(thread_, asyncFuncInstanceDynclass.GetTaggedValue()); + JSHandle async_function = NewBuiltinConstructor( + env, async_func_prototype, AsyncFunction::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); + JSObject::DefineOwnProperty(thread_, async_func_prototype, constructor_key, async_desc); + async_function->SetProtoOrDynClass(thread_, async_func_instance_dynclass.GetTaggedValue()); // AsyncFunction.prototype property - SetStringTagSymbol(env, asyncFuncPrototype, "AsyncFunction"); - env->SetAsyncFunction(thread_, asyncFunction); - env->SetAsyncFunctionPrototype(thread_, asyncFuncPrototype); + SetStringTagSymbol(env, async_func_prototype, "AsyncFunction"); + env->SetAsyncFunction(thread_, async_function); + env->SetAsyncFunctionPrototype(thread_, async_func_prototype); } -void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHandle &obj_func_dynclass) const { // Error.prototype - JSHandle errorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle errorFuncPrototypeValue(errorFuncPrototype); + JSHandle error_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle error_func_prototype_value(error_func_prototype); // Error.prototype_or_dynclass - JSHandle errorFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_ERROR, errorFuncPrototypeValue); + JSHandle error_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_ERROR, error_func_prototype_value); // Error() = new Function() - JSHandle errorFunction( - NewBuiltinConstructor(env, errorFuncPrototype, Error::ErrorConstructor, "Error", FunctionLength::ONE)); - errorFunction->SetFunctionPrototype(thread_, errorFuncInstanceDynclass.GetTaggedValue()); + JSHandle error_function( + NewBuiltinConstructor(env, error_func_prototype, Error::ErrorConstructor, "Error", FunctionLength::ONE)); + error_function->SetFunctionPrototype(thread_, error_func_instance_dynclass.GetTaggedValue()); // Error.prototype method - SetFunction(env, errorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), Error::ToString, + SetFunction(env, error_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), Error::ToString, FunctionLength::ZERO); // Error.prototype Attribute - SetAttribute(errorFuncPrototype, "name", "Error"); - SetAttribute(errorFuncPrototype, "message", ""); - env->SetErrorFunction(thread_, errorFunction); + SetAttribute(error_func_prototype, "name", "Error"); + SetAttribute(error_func_prototype, "message", ""); + env->SetErrorFunction(thread_, error_function); - JSHandle nativeErrorFuncClass = factory_->CreateDynClass( + JSHandle native_error_func_class = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetErrorFunction(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - nativeErrorFuncClass->SetConstructor(true); - env->SetNativeErrorFunctionClass(thread_, nativeErrorFuncClass); + native_error_func_class->SetConstructor(true); + env->SetNativeErrorFunctionClass(thread_, native_error_func_class); - JSHandle errorNativeFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_OBJECT, errorFuncPrototypeValue); - InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_RANGE_ERROR); - InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_REFERENCE_ERROR); - InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_TYPE_ERROR); - InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_URI_ERROR); - InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_SYNTAX_ERROR); - InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_EVAL_ERROR); + JSHandle error_native_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_OBJECT, error_func_prototype_value); + InitializeError(env, error_native_func_instance_dynclass, JSType::JS_RANGE_ERROR); + InitializeError(env, error_native_func_instance_dynclass, JSType::JS_REFERENCE_ERROR); + InitializeError(env, error_native_func_instance_dynclass, JSType::JS_TYPE_ERROR); + InitializeError(env, error_native_func_instance_dynclass, JSType::JS_URI_ERROR); + InitializeError(env, error_native_func_instance_dynclass, JSType::JS_SYNTAX_ERROR); + InitializeError(env, error_native_func_instance_dynclass, JSType::JS_EVAL_ERROR); } void Builtins::InitializeAllTypeErrorWithRealm(const JSHandle &realm) const @@ -1017,92 +1024,92 @@ void Builtins::InitializeAllTypeErrorWithRealm(const JSHandle &realm) SetErrorWithRealm(realm, JSType::JS_EVAL_ERROR); } -void Builtins::SetErrorWithRealm(const JSHandle &realm, const JSType &errorTag) const +void Builtins::SetErrorWithRealm(const JSHandle &realm, const JSType &error_tag) const { JSHandle env = vm_->GetGlobalEnv(); - JSHandle globalObject(thread_, realm->GetGlobalObject()); - JSHandle nameString; - JSHandle nativeErrorFunction; - switch (errorTag) { + JSHandle global_object(thread_, realm->GetGlobalObject()); + JSHandle name_string; + JSHandle native_error_function; + switch (error_tag) { case JSType::JS_RANGE_ERROR: - nativeErrorFunction = env->GetRangeErrorFunction(); - nameString = JSHandle(thread_->GlobalConstants()->GetHandledRangeErrorString()); - realm->SetRangeErrorFunction(thread_, nativeErrorFunction); + native_error_function = env->GetRangeErrorFunction(); + name_string = JSHandle(thread_->GlobalConstants()->GetHandledRangeErrorString()); + realm->SetRangeErrorFunction(thread_, native_error_function); break; case JSType::JS_EVAL_ERROR: - nativeErrorFunction = env->GetEvalErrorFunction(); - nameString = JSHandle(thread_->GlobalConstants()->GetHandledEvalErrorString()); - realm->SetEvalErrorFunction(thread_, nativeErrorFunction); + native_error_function = env->GetEvalErrorFunction(); + name_string = JSHandle(thread_->GlobalConstants()->GetHandledEvalErrorString()); + realm->SetEvalErrorFunction(thread_, native_error_function); break; case JSType::JS_REFERENCE_ERROR: - nativeErrorFunction = env->GetReferenceErrorFunction(); - nameString = JSHandle(thread_->GlobalConstants()->GetHandledReferenceErrorString()); - realm->SetReferenceErrorFunction(thread_, nativeErrorFunction); + native_error_function = env->GetReferenceErrorFunction(); + name_string = JSHandle(thread_->GlobalConstants()->GetHandledReferenceErrorString()); + realm->SetReferenceErrorFunction(thread_, native_error_function); break; case JSType::JS_TYPE_ERROR: - nativeErrorFunction = env->GetTypeErrorFunction(); - nameString = JSHandle(thread_->GlobalConstants()->GetHandledTypeErrorString()); - realm->SetTypeErrorFunction(thread_, nativeErrorFunction); + native_error_function = env->GetTypeErrorFunction(); + name_string = JSHandle(thread_->GlobalConstants()->GetHandledTypeErrorString()); + realm->SetTypeErrorFunction(thread_, native_error_function); realm->SetThrowTypeError(thread_, env->GetThrowTypeError()); break; case JSType::JS_URI_ERROR: - nativeErrorFunction = env->GetURIErrorFunction(); - nameString = JSHandle(thread_->GlobalConstants()->GetHandledURIErrorString()); - realm->SetURIErrorFunction(thread_, nativeErrorFunction); + native_error_function = env->GetURIErrorFunction(); + name_string = JSHandle(thread_->GlobalConstants()->GetHandledURIErrorString()); + realm->SetURIErrorFunction(thread_, native_error_function); break; case JSType::JS_SYNTAX_ERROR: - nativeErrorFunction = env->GetSyntaxErrorFunction(); - nameString = JSHandle(thread_->GlobalConstants()->GetHandledSyntaxErrorString()); - realm->SetSyntaxErrorFunction(thread_, nativeErrorFunction); + native_error_function = env->GetSyntaxErrorFunction(); + name_string = JSHandle(thread_->GlobalConstants()->GetHandledSyntaxErrorString()); + realm->SetSyntaxErrorFunction(thread_, native_error_function); break; default: break; } - PropertyDescriptor descriptor(thread_, nativeErrorFunction, true, false, true); - JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor); + PropertyDescriptor descriptor(thread_, native_error_function, true, false, true); + JSObject::DefineOwnProperty(thread_, global_object, name_string, descriptor); } void Builtins::GeneralUpdateError(ErrorParameter *error, EcmaEntrypoint constructor, EcmaEntrypoint method, const char *name, JSType type) const { - error->nativeConstructor = constructor; - error->nativeMethod = method; - error->nativePropertyName = name; - error->nativeJstype = type; + error->native_constructor = constructor; + error->native_method = method; + error->native_property_name = name; + error->native_jstype = type; } -void Builtins::InitializeError(const JSHandle &env, const JSHandle &objFuncDynclass, - const JSType &errorTag) const +void Builtins::InitializeError(const JSHandle &env, const JSHandle &obj_func_dynclass, + const JSType &error_tag) const { // NativeError.prototype - JSHandle nativeErrorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle nativeErrorFuncPrototypeValue(nativeErrorFuncPrototype); + JSHandle native_error_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle native_error_func_prototype_value(native_error_func_prototype); - ErrorParameter errorParameter {RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", - JSType::JS_RANGE_ERROR}; - switch (errorTag) { + ErrorParameter error_parameter {RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", + JSType::JS_RANGE_ERROR}; + switch (error_tag) { case JSType::JS_RANGE_ERROR: - GeneralUpdateError(&errorParameter, RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", + GeneralUpdateError(&error_parameter, RangeError::RangeErrorConstructor, RangeError::ToString, "RangeError", JSType::JS_RANGE_ERROR); break; case JSType::JS_EVAL_ERROR: - GeneralUpdateError(&errorParameter, EvalError::EvalErrorConstructor, EvalError::ToString, "EvalError", + GeneralUpdateError(&error_parameter, EvalError::EvalErrorConstructor, EvalError::ToString, "EvalError", JSType::JS_EVAL_ERROR); break; case JSType::JS_REFERENCE_ERROR: - GeneralUpdateError(&errorParameter, ReferenceError::ReferenceErrorConstructor, ReferenceError::ToString, + GeneralUpdateError(&error_parameter, ReferenceError::ReferenceErrorConstructor, ReferenceError::ToString, "ReferenceError", JSType::JS_REFERENCE_ERROR); break; case JSType::JS_TYPE_ERROR: - GeneralUpdateError(&errorParameter, TypeError::TypeErrorConstructor, TypeError::ToString, "TypeError", + GeneralUpdateError(&error_parameter, TypeError::TypeErrorConstructor, TypeError::ToString, "TypeError", JSType::JS_TYPE_ERROR); break; case JSType::JS_URI_ERROR: - GeneralUpdateError(&errorParameter, URIError::URIErrorConstructor, URIError::ToString, "URIError", + GeneralUpdateError(&error_parameter, URIError::URIErrorConstructor, URIError::ToString, "URIError", JSType::JS_URI_ERROR); break; case JSType::JS_SYNTAX_ERROR: - GeneralUpdateError(&errorParameter, SyntaxError::SyntaxErrorConstructor, SyntaxError::ToString, + GeneralUpdateError(&error_parameter, SyntaxError::SyntaxErrorConstructor, SyntaxError::ToString, "SyntaxError", JSType::JS_SYNTAX_ERROR); break; default: @@ -1110,1352 +1117,1380 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandle nativeErrorFuncInstanceDynclass = - factory_->CreateDynClass(errorParameter.nativeJstype, nativeErrorFuncPrototypeValue); + JSHandle native_error_func_instance_dynclass = + factory_->CreateDynClass(error_parameter.native_jstype, native_error_func_prototype_value); // NativeError() = new Error() - JSHandle nativeErrorFunction = - factory_->NewJSNativeErrorFunction(env, reinterpret_cast(errorParameter.nativeConstructor)); - InitializeCtor(env, nativeErrorFuncPrototype, nativeErrorFunction, errorParameter.nativePropertyName, + JSHandle native_error_function = + factory_->NewJSNativeErrorFunction(env, reinterpret_cast(error_parameter.native_constructor)); + InitializeCtor(env, native_error_func_prototype, native_error_function, error_parameter.native_property_name, FunctionLength::ONE); - nativeErrorFunction->SetFunctionPrototype(thread_, nativeErrorFuncInstanceDynclass.GetTaggedValue()); + native_error_function->SetFunctionPrototype(thread_, native_error_func_instance_dynclass.GetTaggedValue()); // NativeError.prototype method - SetFunction(env, nativeErrorFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), - errorParameter.nativeMethod, FunctionLength::ZERO); + SetFunction(env, native_error_func_prototype, thread_->GlobalConstants()->GetHandledToStringString(), + error_parameter.native_method, FunctionLength::ZERO); // Error.prototype Attribute - SetAttribute(nativeErrorFuncPrototype, "name", errorParameter.nativePropertyName); - SetAttribute(nativeErrorFuncPrototype, "message", ""); - - if (errorTag == JSType::JS_RANGE_ERROR) { - env->SetRangeErrorFunction(thread_, nativeErrorFunction); - } else if (errorTag == JSType::JS_REFERENCE_ERROR) { - env->SetReferenceErrorFunction(thread_, nativeErrorFunction); - } else if (errorTag == JSType::JS_TYPE_ERROR) { - env->SetTypeErrorFunction(thread_, nativeErrorFunction); - JSHandle throwTypeErrorFunction = + SetAttribute(native_error_func_prototype, "name", error_parameter.native_property_name); + SetAttribute(native_error_func_prototype, "message", ""); + + if (error_tag == JSType::JS_RANGE_ERROR) { + env->SetRangeErrorFunction(thread_, native_error_function); + } else if (error_tag == JSType::JS_REFERENCE_ERROR) { + env->SetReferenceErrorFunction(thread_, native_error_function); + } else if (error_tag == JSType::JS_TYPE_ERROR) { + env->SetTypeErrorFunction(thread_, native_error_function); + JSHandle throw_type_error_function = factory_->NewJSFunction(env, reinterpret_cast(TypeError::ThrowTypeError)); - JSFunction::SetFunctionLength(thread_, throwTypeErrorFunction, JSTaggedValue(1), false); - JSObject::PreventExtensions(thread_, JSHandle::Cast(throwTypeErrorFunction)); - env->SetThrowTypeError(thread_, throwTypeErrorFunction); - } else if (errorTag == JSType::JS_URI_ERROR) { - env->SetURIErrorFunction(thread_, nativeErrorFunction); - } else if (errorTag == JSType::JS_SYNTAX_ERROR) { - env->SetSyntaxErrorFunction(thread_, nativeErrorFunction); + 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); + } else if (error_tag == JSType::JS_URI_ERROR) { + env->SetURIErrorFunction(thread_, native_error_function); + } else if (error_tag == JSType::JS_SYNTAX_ERROR) { + env->SetSyntaxErrorFunction(thread_, native_error_function); } else { - env->SetEvalErrorFunction(thread_, nativeErrorFunction); + env->SetEvalErrorFunction(thread_, native_error_function); } } // namespace panda::ecmascript void Builtins::InitializeCtor(const JSHandle &env, const JSHandle &prototype, const JSHandle &ctor, const char *name, int length) const { - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); JSFunction::SetFunctionLength(thread_, ctor, JSTaggedValue(length)); - JSHandle nameString(factory_->NewFromString(name)); - JSFunction::SetFunctionName(thread_, JSHandle(ctor), nameString, + JSHandle name_string(factory_->NewFromString(name)); + JSFunction::SetFunctionName(thread_, JSHandle(ctor), name_string, JSHandle(thread_, JSTaggedValue::Undefined())); - JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSHandle constructor_key = global_const->GetHandledConstructorString(); PropertyDescriptor descriptor1(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1); + JSObject::DefineOwnProperty(thread_, prototype, constructor_key, descriptor1); /* set "prototype" in constructor */ ctor->SetFunctionPrototype(thread_, prototype.GetTaggedValue()); - if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { - JSHandle globalObject(thread_, env->GetGlobalObject()); + if (!JSTaggedValue::SameValue(name_string, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { + JSHandle global_object(thread_, env->GetGlobalObject()); PropertyDescriptor descriptor2(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, globalObject, nameString, descriptor2); + JSObject::DefineOwnProperty(thread_, global_object, name_string, descriptor2); } } -void Builtins::InitializeSet(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // Set.prototype - JSHandle setFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle setFuncPrototypeValue(setFuncPrototype); + JSHandle set_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle set_func_prototype_value(set_func_prototype); // Set.prototype_or_dynclass - JSHandle setFuncInstanceDynclass = factory_->CreateDynClass(JSType::JS_SET, setFuncPrototypeValue); + JSHandle set_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_SET, set_func_prototype_value); // Set() = new Function() - JSHandle setFunction( - NewBuiltinConstructor(env, setFuncPrototype, BuiltinsSet::SetConstructor, "Set", FunctionLength::ZERO)); - JSHandle(setFunction)->SetFunctionPrototype(thread_, setFuncInstanceDynclass.GetTaggedValue()); + JSHandle set_function( + NewBuiltinConstructor(env, set_func_prototype, BuiltinsSet::SetConstructor, "Set", FunctionLength::ZERO)); + JSHandle(set_function)->SetFunctionPrototype(thread_, set_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(setFuncPrototype), constructorKey, setFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(set_func_prototype), constructor_key, set_function); // set.prototype.add() - SetFunction(env, setFuncPrototype, "add", BuiltinsSet::Add, FunctionLength::ONE); + SetFunction(env, set_func_prototype, "add", BuiltinsSet::Add, FunctionLength::ONE); // set.prototype.clear() - SetFunction(env, setFuncPrototype, "clear", BuiltinsSet::Clear, FunctionLength::ZERO); + SetFunction(env, set_func_prototype, "clear", BuiltinsSet::Clear, FunctionLength::ZERO); // set.prototype.delete() - SetFunction(env, setFuncPrototype, "delete", BuiltinsSet::Delete, FunctionLength::ONE); + SetFunction(env, set_func_prototype, "delete", BuiltinsSet::Delete, FunctionLength::ONE); // set.prototype.has() - SetFunction(env, setFuncPrototype, "has", BuiltinsSet::Has, FunctionLength::ONE); + SetFunction(env, set_func_prototype, "has", BuiltinsSet::Has, FunctionLength::ONE); // set.prototype.forEach() - SetFunction(env, setFuncPrototype, "forEach", BuiltinsSet::ForEach, FunctionLength::ONE); + SetFunction(env, set_func_prototype, "forEach", BuiltinsSet::ForEach, FunctionLength::ONE); // set.prototype.entries() - SetFunction(env, setFuncPrototype, "entries", BuiltinsSet::Entries, FunctionLength::ZERO); + SetFunction(env, set_func_prototype, "entries", BuiltinsSet::Entries, FunctionLength::ZERO); // set.prototype.keys() - SetFunction(env, setFuncPrototype, "values", BuiltinsSet::Values, FunctionLength::ZERO); + SetFunction(env, set_func_prototype, "values", BuiltinsSet::Values, FunctionLength::ZERO); // set.prototype.values() JSHandle keys(factory_->NewFromCanBeCompressString("keys")); JSHandle values(factory_->NewFromCanBeCompressString("values")); - JSHandle valuesFunc = - JSObject::GetMethod(thread_, JSHandle::Cast(setFuncPrototype), values); - PropertyDescriptor descriptor(thread_, valuesFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, setFuncPrototype, keys, descriptor); + 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); // @@ToStringTag - SetStringTagSymbol(env, setFuncPrototype, "Set"); + SetStringTagSymbol(env, set_func_prototype, "Set"); // 23.1.3.10get Set.prototype.size - JSHandle sizeGetter = CreateGetter(env, BuiltinsSet::GetSize, "size", FunctionLength::ZERO); - JSHandle sizeKey(factory_->NewFromCanBeCompressString("size")); - SetGetter(setFuncPrototype, sizeKey, sizeGetter); + 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 speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesGetter = + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_getter = CreateGetter(env, BuiltinsSet::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(setFunction), speciesSymbol, speciesGetter); + SetGetter(JSHandle(set_function), species_symbol, species_getter); // %SetPrototype% [ @@iterator ] - JSHandle iteratorSymbol = env->GetIteratorSymbol(); - JSObject::DefineOwnProperty(thread_, setFuncPrototype, iteratorSymbol, descriptor); + JSHandle iterator_symbol = env->GetIteratorSymbol(); + JSObject::DefineOwnProperty(thread_, set_func_prototype, iterator_symbol, descriptor); - env->SetBuiltinsSetFunction(thread_, setFunction); + env->SetBuiltinsSetFunction(thread_, set_function); } -void Builtins::InitializeMap(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // Map.prototype - JSHandle mapFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle mapFuncPrototypeValue(mapFuncPrototype); + JSHandle map_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle map_func_prototype_value(map_func_prototype); // Map.prototype_or_dynclass - JSHandle mapFuncInstanceDynclass = factory_->CreateDynClass(JSType::JS_MAP, mapFuncPrototypeValue); + JSHandle map_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_MAP, map_func_prototype_value); // Map() = new Function() - JSHandle mapFunction( - NewBuiltinConstructor(env, mapFuncPrototype, BuiltinsMap::MapConstructor, "Map", FunctionLength::ZERO)); + JSHandle map_function( + NewBuiltinConstructor(env, map_func_prototype, BuiltinsMap::MapConstructor, "Map", FunctionLength::ZERO)); // Map().prototype = Map.Prototype & Map.prototype.constructor = Map() - JSFunction::Cast(mapFunction->GetTaggedObject()) - ->SetFunctionPrototype(thread_, mapFuncInstanceDynclass.GetTaggedValue()); + JSFunction::Cast(map_function->GetTaggedObject()) + ->SetFunctionPrototype(thread_, map_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(mapFuncPrototype), constructorKey, mapFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(map_func_prototype), constructor_key, map_function); // map.prototype.set() - SetFunction(env, mapFuncPrototype, globalConst->GetHandledSetString(), BuiltinsMap::Set, FunctionLength::TWO); + SetFunction(env, map_func_prototype, global_const->GetHandledSetString(), BuiltinsMap::Set, FunctionLength::TWO); // map.prototype.clear() - SetFunction(env, mapFuncPrototype, "clear", BuiltinsMap::Clear, FunctionLength::ZERO); + SetFunction(env, map_func_prototype, "clear", BuiltinsMap::Clear, FunctionLength::ZERO); // map.prototype.delete() - SetFunction(env, mapFuncPrototype, "delete", BuiltinsMap::Delete, FunctionLength::ONE); + SetFunction(env, map_func_prototype, "delete", BuiltinsMap::Delete, FunctionLength::ONE); // map.prototype.has() - SetFunction(env, mapFuncPrototype, "has", BuiltinsMap::Has, FunctionLength::ONE); + SetFunction(env, map_func_prototype, "has", BuiltinsMap::Has, FunctionLength::ONE); // map.prototype.get() - SetFunction(env, mapFuncPrototype, thread_->GlobalConstants()->GetHandledGetString(), BuiltinsMap::Get, + SetFunction(env, map_func_prototype, thread_->GlobalConstants()->GetHandledGetString(), BuiltinsMap::Get, FunctionLength::ONE); // map.prototype.forEach() - SetFunction(env, mapFuncPrototype, "forEach", BuiltinsMap::ForEach, FunctionLength::ONE); + SetFunction(env, map_func_prototype, "forEach", BuiltinsMap::ForEach, FunctionLength::ONE); // map.prototype.keys() - SetFunction(env, mapFuncPrototype, "keys", BuiltinsMap::Keys, FunctionLength::ZERO); + SetFunction(env, map_func_prototype, "keys", BuiltinsMap::Keys, FunctionLength::ZERO); // map.prototype.values() - SetFunction(env, mapFuncPrototype, "values", BuiltinsMap::Values, FunctionLength::ZERO); + SetFunction(env, map_func_prototype, "values", BuiltinsMap::Values, FunctionLength::ZERO); // map.prototype.entries() - SetFunction(env, mapFuncPrototype, "entries", BuiltinsMap::Entries, FunctionLength::ZERO); + SetFunction(env, map_func_prototype, "entries", BuiltinsMap::Entries, FunctionLength::ZERO); // @@ToStringTag - SetStringTagSymbol(env, mapFuncPrototype, "Map"); + SetStringTagSymbol(env, map_func_prototype, "Map"); // 23.1.3.10get Map.prototype.size - JSHandle sizeGetter = CreateGetter(env, BuiltinsMap::GetSize, "size", FunctionLength::ZERO); - JSHandle sizeKey(factory_->NewFromCanBeCompressString("size")); - SetGetter(mapFuncPrototype, sizeKey, sizeGetter); + 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 speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesGetter = + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_getter = CreateGetter(env, BuiltinsMap::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(mapFunction), speciesSymbol, speciesGetter); + SetGetter(JSHandle(map_function), species_symbol, species_getter); // %MapPrototype% [ @@iterator ] - JSHandle iteratorSymbol = env->GetIteratorSymbol(); + JSHandle iterator_symbol = env->GetIteratorSymbol(); JSHandle entries(factory_->NewFromCanBeCompressString("entries")); - JSHandle entriesFunc = - JSObject::GetMethod(thread_, JSHandle::Cast(mapFuncPrototype), entries); - PropertyDescriptor descriptor(thread_, entriesFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, mapFuncPrototype, iteratorSymbol, descriptor); + 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_, mapFunction); - env->SetMapPrototype(thread_, mapFuncPrototype); + env->SetBuiltinsMapFunction(thread_, map_function); + env->SetMapPrototype(thread_, map_func_prototype); } -void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeWeakRef(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // WeakRef.prototype - JSHandle weakRefFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle weakRefFuncPrototypeValue(weakRefFuncPrototype); + JSHandle weak_ref_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle weak_ref_func_prototype_value(weak_ref_func_prototype); // WeakRef.prototype_or_dynclass - JSHandle weakRefFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_WEAK_REF, weakRefFuncPrototypeValue); - weakRefFuncInstanceDynclass->SetWeakContainer(true); + JSHandle weak_ref_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_WEAK_REF, weak_ref_func_prototype_value); + weak_ref_func_instance_dynclass->SetWeakContainer(true); // WeakRef() = new Function() - JSHandle weakRefFunction( - NewBuiltinConstructor(env, weakRefFuncPrototype, BuiltinsWeakRef::Constructor, "WeakRef", FunctionLength::ONE)); + JSHandle weak_ref_function(NewBuiltinConstructor( + env, weak_ref_func_prototype, BuiltinsWeakRef::Constructor, "WeakRef", FunctionLength::ONE)); // WeakRef().prototype = WeakRef.Prototype & WeakRef.prototype.constructor = WeakRef() - JSFunction::Cast(weakRefFunction->GetTaggedObject()) - ->SetProtoOrDynClass(thread_, weakRefFuncInstanceDynclass.GetTaggedValue()); + JSFunction::Cast(weak_ref_function->GetTaggedObject()) + ->SetProtoOrDynClass(thread_, weak_ref_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(weakRefFuncPrototype), constructorKey, weakRefFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(weak_ref_func_prototype), constructor_key, + weak_ref_function); // weakref.prototype.deref() - SetFunction(env, weakRefFuncPrototype, "deref", BuiltinsWeakRef::Deref, FunctionLength::ZERO); + SetFunction(env, weak_ref_func_prototype, "deref", BuiltinsWeakRef::Deref, FunctionLength::ZERO); // @@ToStringTag - SetStringTagSymbol(env, weakRefFuncPrototype, "WeakRef"); + SetStringTagSymbol(env, weak_ref_func_prototype, "WeakRef"); } -void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeWeakMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // WeakMap.prototype - JSHandle weakMapFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle weakMapFuncPrototypeValue(weakMapFuncPrototype); + JSHandle weak_map_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle weak_map_func_prototype_value(weak_map_func_prototype); // WeakMap.prototype_or_dynclass - JSHandle weakMapFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_WEAK_MAP, weakMapFuncPrototypeValue); + JSHandle weak_map_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_WEAK_MAP, weak_map_func_prototype_value); // WeakMap() = new Function() - JSHandle weakMapFunction(NewBuiltinConstructor( - env, weakMapFuncPrototype, BuiltinsWeakMap::WeakMapConstructor, "WeakMap", FunctionLength::ZERO)); + JSHandle weak_map_function(NewBuiltinConstructor( + env, weak_map_func_prototype, BuiltinsWeakMap::WeakMapConstructor, "WeakMap", FunctionLength::ZERO)); // WeakMap().prototype = WeakMap.Prototype & WeakMap.prototype.constructor = WeakMap() - JSFunction::Cast(weakMapFunction->GetTaggedObject()) - ->SetProtoOrDynClass(thread_, weakMapFuncInstanceDynclass.GetTaggedValue()); + JSFunction::Cast(weak_map_function->GetTaggedObject()) + ->SetProtoOrDynClass(thread_, weak_map_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(weakMapFuncPrototype), constructorKey, weakMapFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(weak_map_func_prototype), constructor_key, + weak_map_function); // weakmap.prototype.set() - SetFunction(env, weakMapFuncPrototype, globalConst->GetHandledSetString(), BuiltinsWeakMap::Set, + SetFunction(env, weak_map_func_prototype, global_const->GetHandledSetString(), BuiltinsWeakMap::Set, FunctionLength::TWO); // weakmap.prototype.delete() - SetFunction(env, weakMapFuncPrototype, "delete", BuiltinsWeakMap::Delete, FunctionLength::ONE); + SetFunction(env, weak_map_func_prototype, "delete", BuiltinsWeakMap::Delete, FunctionLength::ONE); // weakmap.prototype.has() - SetFunction(env, weakMapFuncPrototype, "has", BuiltinsWeakMap::Has, FunctionLength::ONE); + SetFunction(env, weak_map_func_prototype, "has", BuiltinsWeakMap::Has, FunctionLength::ONE); // weakmap.prototype.get() - SetFunction(env, weakMapFuncPrototype, thread_->GlobalConstants()->GetHandledGetString(), BuiltinsWeakMap::Get, + SetFunction(env, weak_map_func_prototype, thread_->GlobalConstants()->GetHandledGetString(), BuiltinsWeakMap::Get, FunctionLength::ONE); // @@ToStringTag - SetStringTagSymbol(env, weakMapFuncPrototype, "WeakMap"); + SetStringTagSymbol(env, weak_map_func_prototype, "WeakMap"); - env->SetBuiltinsWeakMapFunction(thread_, weakMapFunction); + env->SetBuiltinsWeakMapFunction(thread_, weak_map_function); } -void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeWeakSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // Set.prototype - JSHandle weakSetFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle weakSetFuncPrototypeValue(weakSetFuncPrototype); + JSHandle weak_set_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle weak_set_func_prototype_value(weak_set_func_prototype); // Set.prototype_or_dynclass - JSHandle weakSetFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_WEAK_SET, weakSetFuncPrototypeValue); + JSHandle weak_set_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_WEAK_SET, weak_set_func_prototype_value); // Set() = new Function() - JSHandle weakSetFunction(NewBuiltinConstructor( - env, weakSetFuncPrototype, BuiltinsWeakSet::WeakSetConstructor, "WeakSet", FunctionLength::ZERO)); - JSHandle(weakSetFunction)->SetProtoOrDynClass(thread_, weakSetFuncInstanceDynclass.GetTaggedValue()); + JSHandle weak_set_function(NewBuiltinConstructor( + env, weak_set_func_prototype, BuiltinsWeakSet::WeakSetConstructor, "WeakSet", FunctionLength::ZERO)); + JSHandle(weak_set_function) + ->SetProtoOrDynClass(thread_, weak_set_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(weakSetFuncPrototype), constructorKey, weakSetFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(weak_set_func_prototype), constructor_key, + weak_set_function); // set.prototype.add() - SetFunction(env, weakSetFuncPrototype, "add", BuiltinsWeakSet::Add, FunctionLength::ONE); + SetFunction(env, weak_set_func_prototype, "add", BuiltinsWeakSet::Add, FunctionLength::ONE); // set.prototype.delete() - SetFunction(env, weakSetFuncPrototype, "delete", BuiltinsWeakSet::Delete, FunctionLength::ONE); + SetFunction(env, weak_set_func_prototype, "delete", BuiltinsWeakSet::Delete, FunctionLength::ONE); // set.prototype.has() - SetFunction(env, weakSetFuncPrototype, "has", BuiltinsWeakSet::Has, FunctionLength::ONE); + SetFunction(env, weak_set_func_prototype, "has", BuiltinsWeakSet::Has, FunctionLength::ONE); // @@ToStringTag - SetStringTagSymbol(env, weakSetFuncPrototype, "WeakSet"); + SetStringTagSymbol(env, weak_set_func_prototype, "WeakSet"); - env->SetBuiltinsWeakSetFunction(thread_, weakSetFunction); + env->SetBuiltinsWeakSetFunction(thread_, weak_set_function); } -void Builtins::InitializeMath(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const +void Builtins::InitializeMath(const JSHandle &env, + const JSHandle &obj_func_prototype_val) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle mathDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); - JSHandle mathObject = factory_->NewJSObject(mathDynclass); - SetFunction(env, mathObject, "abs", Math::Abs, FunctionLength::ONE); - SetFunction(env, mathObject, "acos", Math::Acos, FunctionLength::ONE); - SetFunction(env, mathObject, "acosh", Math::Acosh, FunctionLength::ONE); - SetFunction(env, mathObject, "asin", Math::Asin, FunctionLength::ONE); - SetFunction(env, mathObject, "asinh", Math::Asinh, FunctionLength::ONE); - SetFunction(env, mathObject, "atan", Math::Atan, FunctionLength::ONE); - SetFunction(env, mathObject, "atanh", Math::Atanh, FunctionLength::ONE); - SetFunction(env, mathObject, "atan2", Math::Atan2, FunctionLength::TWO); - SetFunction(env, mathObject, "cbrt", Math::Cbrt, FunctionLength::ONE); - SetFunction(env, mathObject, "ceil", Math::Ceil, FunctionLength::ONE); - SetFunction(env, mathObject, "clz32", Math::Clz32, FunctionLength::ONE); - SetFunction(env, mathObject, "cos", Math::Cos, FunctionLength::ONE); - SetFunction(env, mathObject, "cosh", Math::Cosh, FunctionLength::ONE); - SetFunction(env, mathObject, "exp", Math::Exp, FunctionLength::ONE); - SetFunction(env, mathObject, "expm1", Math::Expm1, FunctionLength::ONE); - SetFunction(env, mathObject, "floor", Math::Floor, FunctionLength::ONE); - SetFunction(env, mathObject, "fround", Math::Fround, FunctionLength::ONE); - SetFunction(env, mathObject, "hypot", Math::Hypot, FunctionLength::TWO); - SetFunction(env, mathObject, "imul", Math::Imul, FunctionLength::TWO); - SetFunction(env, mathObject, "log", Math::Log, FunctionLength::ONE); - SetFunction(env, mathObject, "log1p", Math::Log1p, FunctionLength::ONE); - SetFunction(env, mathObject, "log10", Math::Log10, FunctionLength::ONE); - SetFunction(env, mathObject, "log2", Math::Log2, FunctionLength::ONE); - SetFunction(env, mathObject, "max", Math::Max, FunctionLength::TWO); - SetFunction(env, mathObject, "min", Math::Min, FunctionLength::TWO); - SetFunction(env, mathObject, "pow", Math::Pow, FunctionLength::TWO); - SetFunction(env, mathObject, "random", Math::Random, FunctionLength::ZERO); - SetFunction(env, mathObject, "round", Math::Round, FunctionLength::ONE); - SetFunction(env, mathObject, "sign", Math::Sign, FunctionLength::ONE); - SetFunction(env, mathObject, "sin", Math::Sin, FunctionLength::ONE); - SetFunction(env, mathObject, "sinh", Math::Sinh, FunctionLength::ONE); - SetFunction(env, mathObject, "sqrt", Math::Sqrt, FunctionLength::ONE); - SetFunction(env, mathObject, "tan", Math::Tan, FunctionLength::ONE); - SetFunction(env, mathObject, "tanh", Math::Tanh, FunctionLength::ONE); - SetFunction(env, mathObject, "trunc", Math::Trunc, FunctionLength::ONE); - - SetConstant(mathObject, "E", JSTaggedValue(Math::E)); - SetConstant(mathObject, "LN10", JSTaggedValue(Math::LN10)); - SetConstant(mathObject, "LN2", JSTaggedValue(Math::LN2)); - SetConstant(mathObject, "LOG10E", JSTaggedValue(Math::LOG10E)); - SetConstant(mathObject, "LOG2E", JSTaggedValue(Math::LOG2E)); - SetConstant(mathObject, "PI", JSTaggedValue(Math::PI)); - SetConstant(mathObject, "SQRT1_2", JSTaggedValue(Math::SQRT1_2)); - SetConstant(mathObject, "SQRT2", JSTaggedValue(Math::SQRT2)); - - JSHandle mathString(factory_->NewFromCanBeCompressString("Math")); - JSHandle globalObject(thread_, env->GetGlobalObject()); - PropertyDescriptor mathDesc(thread_, JSHandle::Cast(mathObject), true, false, true); - JSObject::DefineOwnProperty(thread_, globalObject, mathString, mathDesc); + 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)); + + JSHandle math_string(factory_->NewFromCanBeCompressString("Math")); + JSHandle global_object(thread_, env->GetGlobalObject()); + PropertyDescriptor math_desc(thread_, JSHandle::Cast(math_object), true, false, true); + JSObject::DefineOwnProperty(thread_, global_object, math_string, math_desc); // @@ToStringTag - SetStringTagSymbol(env, mathObject, "Math"); - env->SetMathFunction(thread_, mathObject); + SetStringTagSymbol(env, math_object, "Math"); + env->SetMathFunction(thread_, math_object); } -void Builtins::InitializeJson(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const +void Builtins::InitializeJson(const JSHandle &env, + const JSHandle &obj_func_prototype_val) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle jsonDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); - JSHandle jsonObject = factory_->NewJSObject(jsonDynclass); + JSHandle json_dynclass = factory_->CreateDynClass(JSType::JS_OBJECT, obj_func_prototype_val); + JSHandle json_object = factory_->NewJSObject(json_dynclass); - SetFunction(env, jsonObject, "parse", Json::Parse, FunctionLength::TWO); - SetFunction(env, jsonObject, "stringify", Json::Stringify, FunctionLength::THREE); + SetFunction(env, json_object, "parse", Json::Parse, FunctionLength::TWO); + SetFunction(env, json_object, "stringify", Json::Stringify, FunctionLength::THREE); - PropertyDescriptor jsonDesc(thread_, JSHandle::Cast(jsonObject), true, false, true); - JSHandle jsonString(factory_->NewFromCanBeCompressString("JSON")); - JSHandle globalObject(thread_, env->GetGlobalObject()); - JSObject::DefineOwnProperty(thread_, globalObject, jsonString, jsonDesc); + PropertyDescriptor json_desc(thread_, JSHandle::Cast(json_object), true, false, true); + JSHandle json_string(factory_->NewFromCanBeCompressString("JSON")); + JSHandle global_object(thread_, env->GetGlobalObject()); + JSObject::DefineOwnProperty(thread_, global_object, json_string, json_desc); // @@ToStringTag - SetStringTagSymbol(env, jsonObject, "JSON"); - env->SetJsonFunction(thread_, jsonObject); + SetStringTagSymbol(env, json_object, "JSON"); + env->SetJsonFunction(thread_, json_object); } -void Builtins::InitializeString(const JSHandle &env, const JSHandle &primRefObjDynclass) const +void Builtins::InitializeString(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // String.prototype - JSHandle toObject(factory_->GetEmptyString()); - JSHandle stringFuncPrototype = - JSHandle::Cast(factory_->NewJSPrimitiveRef(primRefObjDynclass, toObject)); - JSHandle stringFuncPrototypeValue(stringFuncPrototype); + JSHandle to_object(factory_->GetEmptyString()); + JSHandle string_func_prototype = + JSHandle::Cast(factory_->NewJSPrimitiveRef(prim_ref_obj_dynclass, to_object)); + JSHandle string_func_prototype_value(string_func_prototype); // String.prototype_or_dynclass - JSHandle stringFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, stringFuncPrototypeValue); + JSHandle string_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PRIMITIVE_REF, string_func_prototype_value); // String = new Function() - JSHandle stringFunction(NewBuiltinConstructor(env, stringFuncPrototype, BuiltinsString::StringConstructor, - "String", FunctionLength::ONE)); - stringFunction.GetObject()->SetFunctionPrototype(thread_, stringFuncInstanceDynclass.GetTaggedValue()); + JSHandle string_function(NewBuiltinConstructor( + env, string_func_prototype, BuiltinsString::StringConstructor, "String", FunctionLength::ONE)); + string_function.GetObject()->SetFunctionPrototype(thread_, + string_func_instance_dynclass.GetTaggedValue()); // String.prototype method - SetFunction(env, stringFuncPrototype, "charAt", BuiltinsString::CharAt, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "charCodeAt", BuiltinsString::CharCodeAt, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "codePointAt", BuiltinsString::CodePointAt, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "concat", BuiltinsString::Concat, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "endsWith", BuiltinsString::EndsWith, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "includes", BuiltinsString::Includes, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "indexOf", BuiltinsString::IndexOf, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "lastIndexOf", BuiltinsString::LastIndexOf, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "localeCompare", BuiltinsString::LocaleCompare, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "match", BuiltinsString::Match, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "matchAll", BuiltinsString::MatchAll, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "normalize", BuiltinsString::Normalize, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, "padEnd", BuiltinsString::padEnd, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "padStart", BuiltinsString::padStart, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "repeat", BuiltinsString::Repeat, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "replace", BuiltinsString::Replace, FunctionLength::TWO); - SetFunction(env, stringFuncPrototype, "replaceAll", BuiltinsString::ReplaceAll, FunctionLength::TWO); - SetFunction(env, stringFuncPrototype, "search", BuiltinsString::Search, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "slice", BuiltinsString::Slice, FunctionLength::TWO); - SetFunction(env, stringFuncPrototype, "split", BuiltinsString::Split, FunctionLength::TWO); - SetFunction(env, stringFuncPrototype, "startsWith", BuiltinsString::StartsWith, FunctionLength::ONE); - SetFunction(env, stringFuncPrototype, "substring", BuiltinsString::Substring, FunctionLength::TWO); - SetFunction(env, stringFuncPrototype, "substr", BuiltinsString::SubStr, FunctionLength::TWO); - SetFunction(env, stringFuncPrototype, "toLocaleLowerCase", BuiltinsString::ToLocaleLowerCase, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, "toLocaleUpperCase", BuiltinsString::ToLocaleUpperCase, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, "toLowerCase", BuiltinsString::ToLowerCase, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), + 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, stringFuncPrototype, "toUpperCase", BuiltinsString::ToUpperCase, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, "trim", BuiltinsString::Trim, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, "trimEnd", BuiltinsString::TrimEnd, FunctionLength::ZERO); - SetFunction(env, stringFuncPrototype, "trimStart", BuiltinsString::TrimStart, 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 trimRight(factory_->NewFromString("trimRight")); - JSHandle trimEnd(factory_->NewFromString("trimEnd")); - JSHandle trimEndFunc = - JSObject::GetMethod(thread_, JSHandle::Cast(stringFuncPrototype), trimEnd); - PropertyDescriptor trimRightDescriptor(thread_, trimEndFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, stringFuncPrototype, trimRight, trimRightDescriptor); + 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 trimLeft(factory_->NewFromString("trimLeft")); - JSHandle trimStart(factory_->NewFromString("trimStart")); - JSHandle trimStartFunc = - JSObject::GetMethod(thread_, JSHandle::Cast(stringFuncPrototype), trimStart); - PropertyDescriptor trimLeftdescriptor(thread_, trimStartFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, stringFuncPrototype, trimLeft, trimLeftdescriptor); - - SetFunction(env, stringFuncPrototype, thread_->GlobalConstants()->GetHandledValueOfString(), + 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, stringFuncPrototype, env->GetIteratorSymbol(), "[Symbol.iterator]", + SetFunctionAtSymbol(env, string_func_prototype, env->GetIteratorSymbol(), "[Symbol.iterator]", BuiltinsString::GetStringIterator, FunctionLength::ZERO); // String method - SetFunction(env, stringFunction, "fromCharCode", BuiltinsString::FromCharCode, FunctionLength::ONE); - SetFunction(env, stringFunction, "fromCodePoint", BuiltinsString::FromCodePoint, FunctionLength::ONE); - SetFunction(env, stringFunction, "raw", BuiltinsString::Raw, FunctionLength::ONE); + 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 lengthGetter = CreateGetter(env, BuiltinsString::GetLength, "length", FunctionLength::ZERO); - JSHandle lengthKey(factory_->NewFromCanBeCompressString("length")); - SetGetter(stringFuncPrototype, lengthKey, lengthGetter); + 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_, stringFunction); + env->SetStringFunction(thread_, string_function); } void Builtins::InitializeStringIterator(const JSHandle &env, - const JSHandle &iteratorFuncDynclass) const + const JSHandle &iterator_func_dynclass) const { // StringIterator.prototype - JSHandle strIterPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle str_iter_prototype(factory_->NewJSObject(iterator_func_dynclass)); // StringIterator.prototype_or_dynclass - JSHandle strIterFuncInstanceDynclass = factory_->CreateDynClass( - JSType::JS_STRING_ITERATOR, JSHandle(strIterPrototype)); + JSHandle str_iter_func_instance_dynclass = factory_->CreateDynClass( + JSType::JS_STRING_ITERATOR, JSHandle(str_iter_prototype)); - JSHandle strIterFunction( + JSHandle str_iter_function( factory_->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR)); - strIterFunction->SetFunctionPrototype(thread_, strIterFuncInstanceDynclass.GetTaggedValue()); + str_iter_function->SetFunctionPrototype(thread_, str_iter_func_instance_dynclass.GetTaggedValue()); - SetFunction(env, strIterPrototype, "next", StringIterator::Next, FunctionLength::ZERO); - SetStringTagSymbol(env, strIterPrototype, "String Iterator"); + SetFunction(env, str_iter_prototype, "next", StringIterator::Next, FunctionLength::ZERO); + SetStringTagSymbol(env, str_iter_prototype, "String Iterator"); - env->SetStringIterator(thread_, strIterFunction); - env->SetStringIteratorPrototype(thread_, strIterPrototype); + env->SetStringIterator(thread_, str_iter_function); + env->SetStringIteratorPrototype(thread_, str_iter_prototype); } -void Builtins::InitializeIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype - JSHandle iteratorPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle iterator_prototype = factory_->NewJSObject(obj_func_dynclass); // Iterator.prototype.next() - SetFunction(env, iteratorPrototype, "next", BuiltinsIterator::Next, FunctionLength::ONE); + SetFunction(env, iterator_prototype, "next", BuiltinsIterator::Next, FunctionLength::ONE); // Iterator.prototype.return() - SetFunction(env, iteratorPrototype, "return", BuiltinsIterator::Return, FunctionLength::ONE); + SetFunction(env, iterator_prototype, "return", BuiltinsIterator::Return, FunctionLength::ONE); // Iterator.prototype.throw() - SetFunction(env, iteratorPrototype, "throw", BuiltinsIterator::Throw, FunctionLength::ONE); + SetFunction(env, iterator_prototype, "throw", BuiltinsIterator::Throw, FunctionLength::ONE); // %IteratorPrototype% [ @@iterator ] - SetFunctionAtSymbol(env, iteratorPrototype, env->GetIteratorSymbol(), "[Symbol.iterator]", + SetFunctionAtSymbol(env, iterator_prototype, env->GetIteratorSymbol(), "[Symbol.iterator]", BuiltinsIterator::GetIteratorObj, FunctionLength::ZERO); - env->SetIteratorPrototype(thread_, iteratorPrototype); + env->SetIteratorPrototype(thread_, iterator_prototype); // Iterator.dynclass - JSHandle iteratorFuncDynclass = - factory_->CreateDynClass(JSType::JS_ITERATOR, JSHandle(iteratorPrototype)); + JSHandle iterator_func_dynclass = + factory_->CreateDynClass(JSType::JS_ITERATOR, JSHandle(iterator_prototype)); - InitializeForinIterator(env, iteratorFuncDynclass); - InitializeSetIterator(env, iteratorFuncDynclass); - InitializeMapIterator(env, iteratorFuncDynclass); - InitializeArrayIterator(env, iteratorFuncDynclass); - InitializeStringIterator(env, iteratorFuncDynclass); - InitializeRegexpIterator(env, iteratorFuncDynclass); + InitializeForinIterator(env, iterator_func_dynclass); + InitializeSetIterator(env, iterator_func_dynclass); + InitializeMapIterator(env, iterator_func_dynclass); + InitializeArrayIterator(env, iterator_func_dynclass); + InitializeStringIterator(env, iterator_func_dynclass); + InitializeRegexpIterator(env, iterator_func_dynclass); } -void Builtins::InitializeAsyncIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeAsyncIterator(const JSHandle &env, + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // AsyncIterator.prototype - JSHandle asyncIteratorPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle async_iterator_prototype = factory_->NewJSObject(obj_func_dynclass); // %AsyncIteratorPrototype% [ @@asyncIterator ] - SetFunctionAtSymbol(env, asyncIteratorPrototype, env->GetAsyncIteratorSymbol(), "[Symbol.asyncIterator]", + SetFunctionAtSymbol(env, async_iterator_prototype, env->GetAsyncIteratorSymbol(), "[Symbol.asyncIterator]", BuiltinsAsyncIterator::GetAsyncIteratorObj, FunctionLength::ZERO); - env->SetAsyncIteratorPrototype(thread_, asyncIteratorPrototype); + env->SetAsyncIteratorPrototype(thread_, async_iterator_prototype); } void Builtins::InitializeForinIterator(const JSHandle &env, - const JSHandle &iteratorFuncDynclass) const + const JSHandle &iterator_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Iterator.prototype - JSHandle forinIteratorPrototype = factory_->NewJSObject(iteratorFuncDynclass); + JSHandle forin_iterator_prototype = factory_->NewJSObject(iterator_func_dynclass); JSHandle dynclass = factory_->CreateDynClass( - JSType::JS_FORIN_ITERATOR, JSHandle(forinIteratorPrototype)); + JSType::JS_FORIN_ITERATOR, JSHandle(forin_iterator_prototype)); // Iterator.prototype.next() - SetFunction(env, forinIteratorPrototype, "next", JSForInIterator::Next, FunctionLength::ONE); - env->SetForinIteratorPrototype(thread_, forinIteratorPrototype); + SetFunction(env, forin_iterator_prototype, "next", JSForInIterator::Next, FunctionLength::ONE); + env->SetForinIteratorPrototype(thread_, forin_iterator_prototype); env->SetForinIteratorClass(thread_, dynclass); } void Builtins::InitializeSetIterator(const JSHandle &env, - const JSHandle &iteratorFuncDynclass) const + const JSHandle &iterator_func_dynclass) const { // SetIterator.prototype - JSHandle setIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle set_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); // Iterator.prototype.next() - SetFunction(env, setIteratorPrototype, "next", JSSetIterator::Next, FunctionLength::ZERO); - SetStringTagSymbol(env, setIteratorPrototype, "Set Iterator"); - env->SetSetIteratorPrototype(thread_, setIteratorPrototype); + SetFunction(env, set_iterator_prototype, "next", JSSetIterator::Next, FunctionLength::ZERO); + SetStringTagSymbol(env, set_iterator_prototype, "Set Iterator"); + env->SetSetIteratorPrototype(thread_, set_iterator_prototype); } void Builtins::InitializeMapIterator(const JSHandle &env, - const JSHandle &iteratorFuncDynclass) const + const JSHandle &iterator_func_dynclass) const { // MapIterator.prototype - JSHandle mapIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle map_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); // Iterator.prototype.next() - SetFunction(env, mapIteratorPrototype, "next", JSMapIterator::Next, FunctionLength::ZERO); - SetStringTagSymbol(env, mapIteratorPrototype, "Map Iterator"); - env->SetMapIteratorPrototype(thread_, mapIteratorPrototype); + SetFunction(env, map_iterator_prototype, "next", JSMapIterator::Next, FunctionLength::ZERO); + SetStringTagSymbol(env, map_iterator_prototype, "Map Iterator"); + env->SetMapIteratorPrototype(thread_, map_iterator_prototype); } void Builtins::InitializeArrayIterator(const JSHandle &env, - const JSHandle &iteratorFuncDynclass) const + const JSHandle &iterator_func_dynclass) const { // ArrayIterator.prototype - JSHandle arrayIteratorPrototype(factory_->NewJSObject(iteratorFuncDynclass)); + JSHandle array_iterator_prototype(factory_->NewJSObject(iterator_func_dynclass)); // Iterator.prototype.next() - SetFunction(env, arrayIteratorPrototype, "next", JSArrayIterator::Next, FunctionLength::ZERO); - SetStringTagSymbol(env, arrayIteratorPrototype, "Array Iterator"); - env->SetArrayIteratorPrototype(thread_, arrayIteratorPrototype); + SetFunction(env, array_iterator_prototype, "next", JSArrayIterator::Next, FunctionLength::ZERO); + SetStringTagSymbol(env, array_iterator_prototype, "Array Iterator"); + env->SetArrayIteratorPrototype(thread_, array_iterator_prototype); } void Builtins::InitializeRegexpIterator(const JSHandle &env, - const JSHandle &iteratorFuncClass) const + const JSHandle &iterator_func_class) const { // RegExpIterator.prototype - JSHandle regExpIteratorPrototype(factory_->NewJSObject(iteratorFuncClass)); + JSHandle reg_exp_iterator_prototype(factory_->NewJSObject(iterator_func_class)); // Iterator.prototype.next() - SetFunction(env, regExpIteratorPrototype, "next", JSRegExpIterator::Next, FunctionLength::ZERO); - SetStringTagSymbol(env, regExpIteratorPrototype, "RegExp String Iterator"); - env->SetRegExpIteratorPrototype(thread_, regExpIteratorPrototype); + SetFunction(env, reg_exp_iterator_prototype, "next", JSRegExpIterator::Next, FunctionLength::ZERO); + SetStringTagSymbol(env, reg_exp_iterator_prototype, "RegExp String Iterator"); + env->SetRegExpIteratorPrototype(thread_, reg_exp_iterator_prototype); } void Builtins::InitializeRegExp(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // RegExp.prototype - JSHandle objFun = env->GetObjectFunction(); - JSHandle regPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle regPrototypeValue(regPrototype); + JSHandle obj_fun = env->GetObjectFunction(); + JSHandle reg_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle reg_prototype_value(reg_prototype); // RegExp.prototype_or_dynclass - JSHandle regexpFuncInstanceDynclass = factory_->CreateJSRegExpInstanceClass(regPrototypeValue); + JSHandle regexp_func_instance_dynclass = factory_->CreateJSRegExpInstanceClass(reg_prototype_value); // RegExp = new Function() - JSHandle regexpFunction( - NewBuiltinConstructor(env, regPrototype, RegExp::RegExpConstructor, "RegExp", FunctionLength::TWO)); + JSHandle regexp_function( + NewBuiltinConstructor(env, reg_prototype, RegExp::RegExpConstructor, "RegExp", FunctionLength::TWO)); - JSHandle(regexpFunction)->SetFunctionPrototype(thread_, regexpFuncInstanceDynclass.GetTaggedValue()); + JSHandle(regexp_function) + ->SetFunctionPrototype(thread_, regexp_func_instance_dynclass.GetTaggedValue()); // RegExp.prototype method - SetFunction(env, regPrototype, "exec", RegExp::Exec, FunctionLength::ONE); - SetFunction(env, regPrototype, "test", RegExp::Test, FunctionLength::ONE); - SetFunction(env, regPrototype, thread_->GlobalConstants()->GetHandledToStringString(), RegExp::ToString, + 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 flagsGetter = CreateGetter(env, RegExp::GetFlags, "flags", FunctionLength::ZERO); - JSHandle flagsKey(factory_->NewFromCanBeCompressString("flags")); - SetGetter(regPrototype, flagsKey, flagsGetter); + JSHandle flags_getter = CreateGetter(env, RegExp::GetFlags, "flags", FunctionLength::ZERO); + JSHandle flags_key(factory_->NewFromCanBeCompressString("flags")); + SetGetter(reg_prototype, flags_key, flags_getter); - JSHandle sourceGetter = CreateGetter(env, RegExp::GetSource, "source", FunctionLength::ZERO); - JSHandle sourceKey(factory_->NewFromCanBeCompressString("source")); - SetGetter(regPrototype, sourceKey, sourceGetter); + JSHandle source_getter = CreateGetter(env, RegExp::GetSource, "source", FunctionLength::ZERO); + JSHandle source_key(factory_->NewFromCanBeCompressString("source")); + SetGetter(reg_prototype, source_key, source_getter); - JSHandle globalGetter = CreateGetter(env, RegExp::GetGlobal, "global", FunctionLength::ZERO); - JSHandle globalKey(factory_->NewFromCanBeCompressString("global")); - SetGetter(regPrototype, globalKey, globalGetter); + JSHandle global_getter = CreateGetter(env, RegExp::GetGlobal, "global", FunctionLength::ZERO); + JSHandle global_key(factory_->NewFromCanBeCompressString("global")); + SetGetter(reg_prototype, global_key, global_getter); - JSHandle ignoreCaseGetter = + JSHandle ignore_case_getter = CreateGetter(env, RegExp::GetIgnoreCase, "ignoreCase", FunctionLength::ZERO); - JSHandle ignoreCaseKey(factory_->NewFromCanBeCompressString("ignoreCase")); - SetGetter(regPrototype, ignoreCaseKey, ignoreCaseGetter); + JSHandle ignore_case_key(factory_->NewFromCanBeCompressString("ignoreCase")); + SetGetter(reg_prototype, ignore_case_key, ignore_case_getter); - JSHandle multilineGetter = + JSHandle multiline_getter = CreateGetter(env, RegExp::GetMultiline, "multiline", FunctionLength::ZERO); - JSHandle multilineKey(factory_->NewFromCanBeCompressString("multiline")); - SetGetter(regPrototype, multilineKey, multilineGetter); + JSHandle multiline_key(factory_->NewFromCanBeCompressString("multiline")); + SetGetter(reg_prototype, multiline_key, multiline_getter); - JSHandle dotAllGetter = CreateGetter(env, RegExp::GetDotAll, "dotAll", FunctionLength::ZERO); - JSHandle dotAllKey(factory_->NewFromCanBeCompressString("dotAll")); - SetGetter(regPrototype, dotAllKey, dotAllGetter); + 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 stickyGetter = CreateGetter(env, RegExp::GetSticky, "sticky", FunctionLength::ZERO); - JSHandle stickyKey(factory_->NewFromCanBeCompressString("sticky")); - SetGetter(regPrototype, stickyKey, stickyGetter); + JSHandle sticky_getter = CreateGetter(env, RegExp::GetSticky, "sticky", FunctionLength::ZERO); + JSHandle sticky_key(factory_->NewFromCanBeCompressString("sticky")); + SetGetter(reg_prototype, sticky_key, sticky_getter); - JSHandle unicodeGetter = CreateGetter(env, RegExp::GetUnicode, "unicode", FunctionLength::ZERO); - JSHandle unicodeKey(factory_->NewFromCanBeCompressString("unicode")); - SetGetter(regPrototype, unicodeKey, unicodeGetter); + 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 speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesGetter = + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_getter = CreateGetter(env, BuiltinsMap::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(regexpFunction), speciesSymbol, speciesGetter); + SetGetter(JSHandle(regexp_function), species_symbol, species_getter); // Set RegExp.prototype[@@split] - SetFunctionAtSymbol(env, regPrototype, env->GetSplitSymbol(), "[Symbol.split]", RegExp::Split, FunctionLength::TWO); + SetFunctionAtSymbol(env, reg_prototype, env->GetSplitSymbol(), "[Symbol.split]", RegExp::Split, + FunctionLength::TWO); // Set RegExp.prototype[@@search] - SetFunctionAtSymbol(env, regPrototype, env->GetSearchSymbol(), "[Symbol.search]", RegExp::Search, + SetFunctionAtSymbol(env, reg_prototype, env->GetSearchSymbol(), "[Symbol.search]", RegExp::Search, FunctionLength::ONE); // Set RegExp.prototype[@@match] - SetFunctionAtSymbol(env, regPrototype, env->GetMatchSymbol(), "[Symbol.match]", RegExp::Match, FunctionLength::ONE); + SetFunctionAtSymbol(env, reg_prototype, env->GetMatchSymbol(), "[Symbol.match]", RegExp::Match, + FunctionLength::ONE); // Set RegExp.prototype[@@matchAll] - SetFunctionAtSymbol(env, regPrototype, env->GetMatchAllSymbol(), "[Symbol.matchAll]", RegExp::MatchAll, + SetFunctionAtSymbol(env, reg_prototype, env->GetMatchAllSymbol(), "[Symbol.matchAll]", RegExp::MatchAll, FunctionLength::ONE); // Set RegExp.prototype[@@replace] - SetFunctionAtSymbol(env, regPrototype, env->GetReplaceSymbol(), "[Symbol.replace]", RegExp::Replace, + SetFunctionAtSymbol(env, reg_prototype, env->GetReplaceSymbol(), "[Symbol.replace]", RegExp::Replace, FunctionLength::TWO); - env->SetRegExpFunction(thread_, regexpFunction); - auto globalConst = const_cast(thread_->GlobalConstants()); - globalConst->SetConstant(ConstantIndex::JS_REGEXP_CLASS_INDEX, regexpFuncInstanceDynclass.GetTaggedValue()); + env->SetRegExpFunction(thread_, regexp_function); + auto global_const = const_cast(thread_->GlobalConstants()); + global_const->SetConstant(ConstantIndex::JS_REGEXP_CLASS_INDEX, regexp_func_instance_dynclass.GetTaggedValue()); } -void Builtins::InitializeArray(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const +void Builtins::InitializeArray(const JSHandle &env, + const JSHandle &obj_func_prototype_val) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Arraybase.prototype - JSHandle arrBaseFuncInstanceDynclass = factory_->CreateJSArrayInstanceClass(objFuncPrototypeVal); + JSHandle arr_base_func_instance_dynclass = factory_->CreateJSArrayInstanceClass(obj_func_prototype_val); // Array.prototype - JSHandle arrFuncPrototype = factory_->NewJSObject(arrBaseFuncInstanceDynclass); - JSHandle::Cast(arrFuncPrototype)->SetLength(thread_, JSTaggedValue(FunctionLength::ZERO)); + JSHandle arr_func_prototype = factory_->NewJSObject(arr_base_func_instance_dynclass); + JSHandle::Cast(arr_func_prototype)->SetLength(thread_, JSTaggedValue(FunctionLength::ZERO)); auto accessor = thread_->GlobalConstants()->GetArrayLengthAccessor(); - JSArray::Cast(*arrFuncPrototype)->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); - JSHandle arrFuncPrototypeValue(arrFuncPrototype); + JSArray::Cast(*arr_func_prototype) + ->SetPropertyInlinedProps(thread_, JSArray::LENGTH_INLINE_PROPERTY_INDEX, accessor); + JSHandle arr_func_prototype_value(arr_func_prototype); // Array.prototype_or_dynclass - JSHandle arrFuncInstanceDynclass = factory_->CreateJSArrayInstanceClass(arrFuncPrototypeValue); + JSHandle arr_func_instance_dynclass = factory_->CreateJSArrayInstanceClass(arr_func_prototype_value); // Array = new Function() - JSHandle arrayFunction( - NewBuiltinConstructor(env, arrFuncPrototype, BuiltinsArray::ArrayConstructor, "Array", FunctionLength::ONE)); - JSHandle arrayFuncFunction(arrayFunction); + JSHandle array_function( + NewBuiltinConstructor(env, arr_func_prototype, BuiltinsArray::ArrayConstructor, "Array", FunctionLength::ONE)); + JSHandle array_func_function(array_function); // Set the [[Realm]] internal slot of F to the running execution context's Realm - JSHandle lexicalEnv = factory_->NewLexicalEnv(0); - lexicalEnv->SetParentEnv(thread_, env.GetTaggedValue()); - arrayFuncFunction->SetLexicalEnv(thread_, lexicalEnv.GetTaggedValue()); + JSHandle lexical_env = factory_->NewLexicalEnv(0); + lexical_env->SetParentEnv(thread_, env.GetTaggedValue()); + array_func_function->SetLexicalEnv(thread_, lexical_env.GetTaggedValue()); - arrayFuncFunction->SetFunctionPrototype(thread_, arrFuncInstanceDynclass.GetTaggedValue()); + array_func_function->SetFunctionPrototype(thread_, arr_func_instance_dynclass.GetTaggedValue()); // Array.prototype method - SetFunction(env, arrFuncPrototype, "concat", BuiltinsArray::Concat, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "copyWithin", BuiltinsArray::CopyWithin, FunctionLength::TWO); - SetFunction(env, arrFuncPrototype, "entries", BuiltinsArray::Entries, FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "every", BuiltinsArray::Every, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "flat", BuiltinsArray::Flat, FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "flatMap", BuiltinsArray::FlatMap, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "fill", BuiltinsArray::Fill, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "filter", BuiltinsArray::Filter, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "find", BuiltinsArray::Find, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "findIndex", BuiltinsArray::FindIndex, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "forEach", BuiltinsArray::ForEach, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "includes", BuiltinsArray::Includes, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "indexOf", BuiltinsArray::IndexOf, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "join", BuiltinsArray::Join, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "keys", BuiltinsArray::Keys, FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "lastIndexOf", BuiltinsArray::LastIndexOf, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "map", BuiltinsArray::Map, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "pop", BuiltinsArray::Pop, FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "push", BuiltinsArray::Push, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "reduce", BuiltinsArray::Reduce, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "reduceRight", BuiltinsArray::ReduceRight, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "reverse", BuiltinsArray::Reverse, FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "shift", BuiltinsArray::Shift, FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "slice", BuiltinsArray::Slice, FunctionLength::TWO); - SetFunction(env, arrFuncPrototype, "some", BuiltinsArray::Some, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "sort", BuiltinsArray::Sort, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "splice", BuiltinsArray::Splice, FunctionLength::TWO); - SetFunction(env, arrFuncPrototype, thread_->GlobalConstants()->GetHandledToLocaleStringString(), + 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, arrFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), BuiltinsArray::ToString, - FunctionLength::ZERO); - SetFunction(env, arrFuncPrototype, "unshift", BuiltinsArray::Unshift, FunctionLength::ONE); - SetFunction(env, arrFuncPrototype, "values", BuiltinsArray::Values, 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 iteratorSymbol = env->GetIteratorSymbol(); - JSHandle valuesFunc = - JSObject::GetMethod(thread_, JSHandle::Cast(arrFuncPrototype), values); - PropertyDescriptor iteartorDesc(thread_, valuesFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, arrFuncPrototype, iteratorSymbol, iteartorDesc); + 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, arrayFunction, "from", BuiltinsArray::From, FunctionLength::ONE); - SetFunction(env, arrayFunction, "isArray", BuiltinsArray::IsArray, FunctionLength::ONE); - SetFunction(env, arrayFunction, "of", BuiltinsArray::Of, FunctionLength::ZERO); + 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 speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesGetter = + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_getter = CreateGetter(env, BuiltinsArray::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(arrayFunction), speciesSymbol, speciesGetter); + SetGetter(JSHandle(array_function), species_symbol, species_getter); - const int arrProtoLen = 0; + const int arr_proto_len = 0; JSHandle key_string = thread_->GlobalConstants()->GetHandledLengthString(); - PropertyDescriptor descriptor(thread_, JSHandle(thread_, JSTaggedValue(arrProtoLen)), true, false, + PropertyDescriptor descriptor(thread_, JSHandle(thread_, JSTaggedValue(arr_proto_len)), true, false, false); - JSObject::DefineOwnProperty(thread_, arrFuncPrototype, key_string, descriptor); + JSObject::DefineOwnProperty(thread_, arr_func_prototype, key_string, descriptor); - JSHandle valuesKey(factory_->NewFromCanBeCompressString("values")); + JSHandle values_key(factory_->NewFromCanBeCompressString("values")); PropertyDescriptor desc(thread_); - JSObject::GetOwnProperty(thread_, arrFuncPrototype, valuesKey, desc); + JSObject::GetOwnProperty(thread_, arr_func_prototype, values_key, desc); // Array.prototype [ @@unscopables ] - JSHandle unscopablesSymbol = env->GetUnscopablesSymbol(); - JSHandle unscopablesGetter = + JSHandle unscopables_symbol = env->GetUnscopablesSymbol(); + JSHandle unscopables_getter = CreateGetter(env, BuiltinsArray::Unscopables, "[Symbol.unscopables]", FunctionLength::ZERO); - SetGetter(JSHandle(arrFuncPrototype), unscopablesSymbol, unscopablesGetter); + SetGetter(JSHandle(arr_func_prototype), unscopables_symbol, unscopables_getter); env->SetArrayProtoValuesFunction(thread_, desc.GetValue()); - env->SetArrayFunction(thread_, arrayFunction); - env->SetArrayPrototype(thread_, arrFuncPrototype); + env->SetArrayFunction(thread_, array_function); + env->SetArrayPrototype(thread_, arr_func_prototype); } -void Builtins::InitializeTypedArray(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeTypedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // TypedArray.prototype - JSHandle typedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle typedArrFuncPrototypeValue(typedArrFuncPrototype); + JSHandle typed_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle typed_arr_func_prototype_value(typed_arr_func_prototype); // TypedArray.prototype_or_dynclass - JSHandle typedArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_TYPED_ARRAY, typedArrFuncPrototypeValue); + JSHandle typed_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_TYPED_ARRAY, typed_arr_func_prototype_value); // TypedArray = new Function() - JSHandle typedArrayFunction(NewBuiltinConstructor( - env, typedArrFuncPrototype, BuiltinsTypedArray::TypedArrayBaseConstructor, "TypedArray", FunctionLength::ZERO)); + JSHandle typed_array_function(NewBuiltinConstructor(env, typed_arr_func_prototype, + BuiltinsTypedArray::TypedArrayBaseConstructor, + "TypedArray", FunctionLength::ZERO)); - JSHandle(typedArrayFunction) - ->SetProtoOrDynClass(thread_, typedArrFuncInstanceDynclass.GetTaggedValue()); + JSHandle(typed_array_function) + ->SetProtoOrDynClass(thread_, typed_arr_func_instance_dynclass.GetTaggedValue()); // TypedArray.prototype method - SetFunction(env, typedArrFuncPrototype, "copyWithin", BuiltinsTypedArray::CopyWithin, FunctionLength::TWO); - SetFunction(env, typedArrFuncPrototype, "entries", BuiltinsTypedArray::Entries, FunctionLength::ZERO); - SetFunction(env, typedArrFuncPrototype, "every", BuiltinsTypedArray::Every, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "fill", BuiltinsTypedArray::Fill, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "filter", BuiltinsTypedArray::Filter, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "find", BuiltinsTypedArray::Find, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "findIndex", BuiltinsTypedArray::FindIndex, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "forEach", BuiltinsTypedArray::ForEach, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "includes", BuiltinsTypedArray::Includes, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "indexOf", BuiltinsTypedArray::IndexOf, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "join", BuiltinsTypedArray::Join, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "keys", BuiltinsTypedArray::Keys, FunctionLength::ZERO); - SetFunction(env, typedArrFuncPrototype, "lastIndexOf", BuiltinsTypedArray::LastIndexOf, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "map", BuiltinsTypedArray::Map, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "reduce", BuiltinsTypedArray::Reduce, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "reduceRight", BuiltinsTypedArray::ReduceRight, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "reverse", BuiltinsTypedArray::Reverse, FunctionLength::ZERO); - SetFunction(env, typedArrFuncPrototype, "set", BuiltinsTypedArray::Set, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "slice", BuiltinsTypedArray::Slice, FunctionLength::TWO); - SetFunction(env, typedArrFuncPrototype, "some", BuiltinsTypedArray::Some, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "sort", BuiltinsTypedArray::Sort, FunctionLength::ONE); - SetFunction(env, typedArrFuncPrototype, "subarray", BuiltinsTypedArray::Subarray, FunctionLength::TWO); - SetFunction(env, typedArrFuncPrototype, thread_->GlobalConstants()->GetHandledToLocaleStringString(), + 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, typedArrFuncPrototype, "values", BuiltinsTypedArray::Values, FunctionLength::ZERO); + SetFunction(env, typed_arr_func_prototype, "values", BuiltinsTypedArray::Values, FunctionLength::ZERO); - JSHandle bufferGetter = + JSHandle buffer_getter = CreateGetter(env, BuiltinsTypedArray::GetBuffer, "buffer", FunctionLength::ZERO); - JSHandle bufferKey(factory_->NewFromCanBeCompressString("buffer")); - SetGetter(typedArrFuncPrototype, bufferKey, bufferGetter); + JSHandle buffer_key(factory_->NewFromCanBeCompressString("buffer")); + SetGetter(typed_arr_func_prototype, buffer_key, buffer_getter); - JSHandle byteLengthGetter = + JSHandle byte_length_getter = CreateGetter(env, BuiltinsTypedArray::GetByteLength, "byteLength", FunctionLength::ZERO); - JSHandle byteLengthKey(factory_->NewFromCanBeCompressString("byteLength")); - SetGetter(typedArrFuncPrototype, byteLengthKey, byteLengthGetter); + JSHandle byte_length_key(factory_->NewFromCanBeCompressString("byteLength")); + SetGetter(typed_arr_func_prototype, byte_length_key, byte_length_getter); - JSHandle byteOffsetGetter = + JSHandle byte_offset_getter = CreateGetter(env, BuiltinsTypedArray::GetByteOffset, "byteOffset", FunctionLength::ZERO); - JSHandle byteOffsetKey(factory_->NewFromCanBeCompressString("byteOffset")); - SetGetter(typedArrFuncPrototype, byteOffsetKey, byteOffsetGetter); + JSHandle byte_offset_key(factory_->NewFromCanBeCompressString("byteOffset")); + SetGetter(typed_arr_func_prototype, byte_offset_key, byte_offset_getter); - JSHandle lengthGetter = + JSHandle length_getter = CreateGetter(env, BuiltinsTypedArray::GetLength, "length", FunctionLength::ZERO); - JSHandle lengthKey(factory_->NewFromCanBeCompressString("length")); - SetGetter(typedArrFuncPrototype, lengthKey, lengthGetter); + JSHandle length_key(factory_->NewFromCanBeCompressString("length")); + SetGetter(typed_arr_func_prototype, length_key, length_getter); // %TypedArray%.prototype.toString() - JSHandle arrFuncPrototype = env->GetArrayPrototype(); - JSHandle toStringFunc = - JSObject::GetMethod(thread_, arrFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString()); - PropertyDescriptor toStringDesc(thread_, toStringFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, typedArrFuncPrototype, thread_->GlobalConstants()->GetHandledToStringString(), - toStringDesc); + 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 iteratorSymbol = env->GetIteratorSymbol(); - JSHandle valuesFunc = - JSObject::GetMethod(thread_, JSHandle::Cast(typedArrFuncPrototype), values); - PropertyDescriptor iteartorDesc(thread_, valuesFunc, true, false, true); - JSObject::DefineOwnProperty(thread_, typedArrFuncPrototype, iteratorSymbol, iteartorDesc); + 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 toStringTagSymbol = env->GetToStringTagSymbol(); - JSHandle toStringTagGetter = + JSHandle to_string_tag_symbol = env->GetToStringTagSymbol(); + JSHandle to_string_tag_getter = CreateGetter(env, BuiltinsTypedArray::ToStringTag, "[Symbol.toStringTag]", FunctionLength::ZERO); - SetGetter(typedArrFuncPrototype, toStringTagSymbol, toStringTagGetter); + SetGetter(typed_arr_func_prototype, to_string_tag_symbol, to_string_tag_getter); // TypedArray method - SetFunction(env, typedArrayFunction, "from", BuiltinsTypedArray::From, FunctionLength::ONE); - SetFunction(env, typedArrayFunction, "of", BuiltinsTypedArray::Of, FunctionLength::ZERO); + 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 speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesGetter = + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_getter = CreateGetter(env, BuiltinsTypedArray::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(typedArrayFunction), speciesSymbol, speciesGetter); + SetGetter(JSHandle(typed_array_function), species_symbol, species_getter); - env->SetTypedArrayFunction(thread_, typedArrayFunction.GetTaggedValue()); - env->SetTypedArrayPrototype(thread_, typedArrFuncPrototype); + env->SetTypedArrayFunction(thread_, typed_array_function.GetTaggedValue()); + env->SetTypedArrayPrototype(thread_, typed_arr_func_prototype); - JSHandle specificTypedArrayFuncClass = factory_->CreateDynClass( + JSHandle specific_typed_array_func_class = factory_->CreateDynClass( JSType::JS_FUNCTION, env->GetTypedArrayFunction(), HClass::IS_CALLABLE | HClass::IS_BUILTINS_CTOR); - specificTypedArrayFuncClass->SetConstructor(true); - env->SetSpecificTypedArrayFunctionClass(thread_, specificTypedArrayFuncClass); + specific_typed_array_func_class->SetConstructor(true); + env->SetSpecificTypedArrayFunctionClass(thread_, specific_typed_array_func_class); - InitializeInt8Array(env, typedArrFuncInstanceDynclass); - InitializeUint8Array(env, typedArrFuncInstanceDynclass); - InitializeUint8ClampedArray(env, typedArrFuncInstanceDynclass); - InitializeInt16Array(env, typedArrFuncInstanceDynclass); - InitializeUint16Array(env, typedArrFuncInstanceDynclass); - InitializeInt32Array(env, typedArrFuncInstanceDynclass); - InitializeUint32Array(env, typedArrFuncInstanceDynclass); - InitializeFloat32Array(env, typedArrFuncInstanceDynclass); - InitializeFloat64Array(env, typedArrFuncInstanceDynclass); - InitializeBigInt64Array(env, typedArrFuncInstanceDynclass); - InitializeBigUint64Array(env, typedArrFuncInstanceDynclass); + InitializeInt8Array(env, typed_arr_func_instance_dynclass); + InitializeUint8Array(env, typed_arr_func_instance_dynclass); + InitializeUint8ClampedArray(env, typed_arr_func_instance_dynclass); + InitializeInt16Array(env, typed_arr_func_instance_dynclass); + InitializeUint16Array(env, typed_arr_func_instance_dynclass); + InitializeInt32Array(env, typed_arr_func_instance_dynclass); + InitializeUint32Array(env, typed_arr_func_instance_dynclass); + InitializeFloat32Array(env, typed_arr_func_instance_dynclass); + InitializeFloat64Array(env, typed_arr_func_instance_dynclass); + InitializeBigInt64Array(env, typed_arr_func_instance_dynclass); + InitializeBigUint64Array(env, typed_arr_func_instance_dynclass); } -void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int8Array.prototype - JSHandle int8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle int8ArrFuncPrototypeValue(int8ArrFuncPrototype); + JSHandle int8_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle int8_arr_func_prototype_value(int8_arr_func_prototype); // Int8Array.prototype_or_dynclass - JSHandle int8ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_INT8_ARRAY, int8ArrFuncPrototypeValue); + JSHandle int8_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_INT8_ARRAY, int8_arr_func_prototype_value); // Int8Array = new Function() - JSHandle int8ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle int8_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Int8ArrayConstructor)); - InitializeCtor(env, int8ArrFuncPrototype, int8ArrayFunction, "Int8Array", FunctionLength::THREE); + InitializeCtor(env, int8_arr_func_prototype, int8_array_function, "Int8Array", FunctionLength::THREE); - int8ArrayFunction->SetProtoOrDynClass(thread_, int8ArrFuncInstanceDynclass.GetTaggedValue()); + int8_array_function->SetProtoOrDynClass(thread_, int8_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 1; - SetConstant(int8ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(int8ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetInt8ArrayFunction(thread_, int8ArrayFunction); + const int bytes_per_element = 1; + SetConstant(int8_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(int8_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetInt8ArrayFunction(thread_, int8_array_function); } -void Builtins::InitializeUint8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeUint8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint8Array.prototype - JSHandle uint8ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle uint8ArrFuncPrototypeValue(uint8ArrFuncPrototype); + JSHandle uint8_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle uint8_arr_func_prototype_value(uint8_arr_func_prototype); // Uint8Array.prototype_or_dynclass - JSHandle uint8ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_UINT8_ARRAY, uint8ArrFuncPrototypeValue); + JSHandle uint8_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_UINT8_ARRAY, uint8_arr_func_prototype_value); // Uint8Array = new Function() - JSHandle uint8ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle uint8_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Uint8ArrayConstructor)); - InitializeCtor(env, uint8ArrFuncPrototype, uint8ArrayFunction, "Uint8Array", FunctionLength::THREE); + InitializeCtor(env, uint8_arr_func_prototype, uint8_array_function, "Uint8Array", FunctionLength::THREE); - uint8ArrayFunction->SetProtoOrDynClass(thread_, uint8ArrFuncInstanceDynclass.GetTaggedValue()); + uint8_array_function->SetProtoOrDynClass(thread_, uint8_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 1; - SetConstant(uint8ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(uint8ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetUint8ArrayFunction(thread_, uint8ArrayFunction); + const int bytes_per_element = 1; + SetConstant(uint8_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(uint8_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetUint8ArrayFunction(thread_, uint8_array_function); } void Builtins::InitializeUint8ClampedArray(const JSHandle &env, - const JSHandle &objFuncDynclass) const + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint8ClampedArray.prototype - JSHandle uint8ClampedArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle uint8ClampedArrFuncPrototypeValue(uint8ClampedArrFuncPrototype); + JSHandle uint8_clamped_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle uint8_clamped_arr_func_prototype_value(uint8_clamped_arr_func_prototype); // Uint8ClampedArray.prototype_or_dynclass - JSHandle uint8ClampedArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_UINT8_CLAMPED_ARRAY, uint8ClampedArrFuncPrototypeValue); + JSHandle uint8_clamped_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_UINT8_CLAMPED_ARRAY, uint8_clamped_arr_func_prototype_value); // Uint8ClampedArray = new Function() - JSHandle uint8ClampedArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle uint8_clamped_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Uint8ClampedArrayConstructor)); - InitializeCtor(env, uint8ClampedArrFuncPrototype, uint8ClampedArrayFunction, "Uint8ClampedArray", + InitializeCtor(env, uint8_clamped_arr_func_prototype, uint8_clamped_array_function, "Uint8ClampedArray", FunctionLength::THREE); - uint8ClampedArrayFunction->SetProtoOrDynClass(thread_, uint8ClampedArrFuncInstanceDynclass.GetTaggedValue()); + uint8_clamped_array_function->SetProtoOrDynClass(thread_, + uint8_clamped_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 1; - SetConstant(uint8ClampedArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(uint8ClampedArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetUint8ClampedArrayFunction(thread_, uint8ClampedArrayFunction); + const int bytes_per_element = 1; + SetConstant(uint8_clamped_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(uint8_clamped_array_function), "BYTES_PER_ELEMENT", + JSTaggedValue(bytes_per_element)); + env->SetUint8ClampedArrayFunction(thread_, uint8_clamped_array_function); } -void Builtins::InitializeInt16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeInt16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int16Array.prototype - JSHandle int16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle int16ArrFuncPrototypeValue(int16ArrFuncPrototype); + JSHandle int16_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle int16_arr_func_prototype_value(int16_arr_func_prototype); // Int16Array.prototype_or_dynclass - JSHandle int16ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_INT16_ARRAY, int16ArrFuncPrototypeValue); + JSHandle int16_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_INT16_ARRAY, int16_arr_func_prototype_value); // Int16Array = new Function() - JSHandle int16ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle int16_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Int16ArrayConstructor)); - InitializeCtor(env, int16ArrFuncPrototype, int16ArrayFunction, "Int16Array", FunctionLength::THREE); + InitializeCtor(env, int16_arr_func_prototype, int16_array_function, "Int16Array", FunctionLength::THREE); - int16ArrayFunction->SetProtoOrDynClass(thread_, int16ArrFuncInstanceDynclass.GetTaggedValue()); + int16_array_function->SetProtoOrDynClass(thread_, int16_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 2; - SetConstant(int16ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(int16ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetInt16ArrayFunction(thread_, int16ArrayFunction); + const int bytes_per_element = 2; + SetConstant(int16_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(int16_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetInt16ArrayFunction(thread_, int16_array_function); } -void Builtins::InitializeUint16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeUint16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint16Array.prototype - JSHandle uint16ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle uint16ArrFuncPrototypeValue(uint16ArrFuncPrototype); + JSHandle uint16_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle uint16_arr_func_prototype_value(uint16_arr_func_prototype); // Uint16Array.prototype_or_dynclass - JSHandle uint16ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_UINT16_ARRAY, uint16ArrFuncPrototypeValue); + JSHandle uint16_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_UINT16_ARRAY, uint16_arr_func_prototype_value); // Uint16Array = new Function() - JSHandle uint16ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle uint16_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Uint16ArrayConstructor)); - InitializeCtor(env, uint16ArrFuncPrototype, uint16ArrayFunction, "Uint16Array", FunctionLength::THREE); + InitializeCtor(env, uint16_arr_func_prototype, uint16_array_function, "Uint16Array", FunctionLength::THREE); - uint16ArrayFunction->SetProtoOrDynClass(thread_, uint16ArrFuncInstanceDynclass.GetTaggedValue()); + uint16_array_function->SetProtoOrDynClass(thread_, uint16_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 2; - SetConstant(uint16ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(uint16ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetUint16ArrayFunction(thread_, uint16ArrayFunction); + const int bytes_per_element = 2; + SetConstant(uint16_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(uint16_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetUint16ArrayFunction(thread_, uint16_array_function); } -void Builtins::InitializeInt32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeInt32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Int32Array.prototype - JSHandle int32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle int32ArrFuncPrototypeValue(int32ArrFuncPrototype); + JSHandle int32_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle int32_arr_func_prototype_value(int32_arr_func_prototype); // Int32Array.prototype_or_dynclass - JSHandle int32ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_INT32_ARRAY, int32ArrFuncPrototypeValue); + JSHandle int32_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_INT32_ARRAY, int32_arr_func_prototype_value); // Int32Array = new Function() - JSHandle int32ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle int32_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Int32ArrayConstructor)); - InitializeCtor(env, int32ArrFuncPrototype, int32ArrayFunction, "Int32Array", FunctionLength::THREE); + InitializeCtor(env, int32_arr_func_prototype, int32_array_function, "Int32Array", FunctionLength::THREE); - int32ArrayFunction->SetProtoOrDynClass(thread_, int32ArrFuncInstanceDynclass.GetTaggedValue()); + int32_array_function->SetProtoOrDynClass(thread_, int32_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 4; - SetConstant(int32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(int32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetInt32ArrayFunction(thread_, int32ArrayFunction); + const int bytes_per_element = 4; + SetConstant(int32_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(int32_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetInt32ArrayFunction(thread_, int32_array_function); } -void Builtins::InitializeUint32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeUint32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Uint32Array.prototype - JSHandle uint32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle uint32ArrFuncPrototypeValue(uint32ArrFuncPrototype); + JSHandle uint32_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle uint32_arr_func_prototype_value(uint32_arr_func_prototype); // Uint32Array.prototype_or_dynclass - JSHandle uint32ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_UINT32_ARRAY, uint32ArrFuncPrototypeValue); + JSHandle uint32_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_UINT32_ARRAY, uint32_arr_func_prototype_value); // Uint32Array = new Function() - JSHandle uint32ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle uint32_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Uint32ArrayConstructor)); - InitializeCtor(env, uint32ArrFuncPrototype, uint32ArrayFunction, "Uint32Array", FunctionLength::THREE); + InitializeCtor(env, uint32_arr_func_prototype, uint32_array_function, "Uint32Array", FunctionLength::THREE); - uint32ArrayFunction->SetProtoOrDynClass(thread_, uint32ArrFuncInstanceDynclass.GetTaggedValue()); + uint32_array_function->SetProtoOrDynClass(thread_, uint32_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 4; - SetConstant(uint32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(uint32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetUint32ArrayFunction(thread_, uint32ArrayFunction); + const int bytes_per_element = 4; + SetConstant(uint32_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(uint32_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetUint32ArrayFunction(thread_, uint32_array_function); } -void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Float32Array.prototype - JSHandle float32ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle float32ArrFuncPrototypeValue(float32ArrFuncPrototype); + JSHandle float32_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle float32_arr_func_prototype_value(float32_arr_func_prototype); // Float32Array.prototype_or_dynclass - JSHandle float32ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_FLOAT32_ARRAY, float32ArrFuncPrototypeValue); + JSHandle float32_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_FLOAT32_ARRAY, float32_arr_func_prototype_value); // Float32Array = new Function() - JSHandle float32ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle float32_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Float32ArrayConstructor)); - InitializeCtor(env, float32ArrFuncPrototype, float32ArrayFunction, "Float32Array", FunctionLength::THREE); + InitializeCtor(env, float32_arr_func_prototype, float32_array_function, "Float32Array", FunctionLength::THREE); - float32ArrayFunction->SetProtoOrDynClass(thread_, float32ArrFuncInstanceDynclass.GetTaggedValue()); + float32_array_function->SetProtoOrDynClass(thread_, float32_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 4; - SetConstant(float32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(float32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetFloat32ArrayFunction(thread_, float32ArrayFunction); + const int bytes_per_element = 4; + SetConstant(float32_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(float32_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetFloat32ArrayFunction(thread_, float32_array_function); } -void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // Float64Array.prototype - JSHandle float64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle float64ArrFuncPrototypeValue(float64ArrFuncPrototype); + JSHandle float64_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle float64_arr_func_prototype_value(float64_arr_func_prototype); // Float64Array.prototype_or_dynclass - JSHandle float64ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_FLOAT64_ARRAY, float64ArrFuncPrototypeValue); + JSHandle float64_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_FLOAT64_ARRAY, float64_arr_func_prototype_value); // Float64Array = new Function() - JSHandle float64ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle float64_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::Float64ArrayConstructor)); - InitializeCtor(env, float64ArrFuncPrototype, float64ArrayFunction, "Float64Array", FunctionLength::THREE); + InitializeCtor(env, float64_arr_func_prototype, float64_array_function, "Float64Array", FunctionLength::THREE); - float64ArrayFunction->SetProtoOrDynClass(thread_, float64ArrFuncInstanceDynclass.GetTaggedValue()); + float64_array_function->SetProtoOrDynClass(thread_, float64_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 8; - SetConstant(float64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(float64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetFloat64ArrayFunction(thread_, float64ArrayFunction); + const int bytes_per_element = 8; + SetConstant(float64_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(float64_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetFloat64ArrayFunction(thread_, float64_array_function); } -void Builtins::InitializeBigInt64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeBigInt64Array(const JSHandle &env, + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigInt64Array.prototype - JSHandle bigInt64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle bigInt64ArrFuncPrototypeValue(bigInt64ArrFuncPrototype); + JSHandle big_int64_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle big_int64_arr_func_prototype_value(big_int64_arr_func_prototype); // BigInt64Array.prototype_or_dynclass - JSHandle bigInt64ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_BIGINT64_ARRAY, bigInt64ArrFuncPrototypeValue); + JSHandle big_int64_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_BIGINT64_ARRAY, big_int64_arr_func_prototype_value); // BigInt64Array = new Function() - JSHandle bigInt64ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle big_int64_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::BigInt64ArrayConstructor)); - InitializeCtor(env, bigInt64ArrFuncPrototype, bigInt64ArrayFunction, "BigInt64Array", FunctionLength::THREE); + InitializeCtor(env, big_int64_arr_func_prototype, big_int64_array_function, "BigInt64Array", FunctionLength::THREE); - bigInt64ArrayFunction->SetProtoOrDynClass(thread_, bigInt64ArrFuncInstanceDynclass.GetTaggedValue()); + big_int64_array_function->SetProtoOrDynClass(thread_, big_int64_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 8; - SetConstant(bigInt64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(bigInt64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetBigInt64ArrayFunction(thread_, bigInt64ArrayFunction); + const int bytes_per_element = 8; + SetConstant(big_int64_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(big_int64_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetBigInt64ArrayFunction(thread_, big_int64_array_function); } -void Builtins::InitializeBigUint64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeBigUint64Array(const JSHandle &env, + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // BigUint64Array.prototype - JSHandle bigUint64ArrFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle bigUint64ArrFuncPrototypeValue(bigUint64ArrFuncPrototype); + JSHandle big_uint64_arr_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle big_uint64_arr_func_prototype_value(big_uint64_arr_func_prototype); // BigUint64Array.prototype_or_dynclass - JSHandle bigUint64ArrFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_BIGUINT64_ARRAY, bigUint64ArrFuncPrototypeValue); + JSHandle big_uint64_arr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_BIGUINT64_ARRAY, big_uint64_arr_func_prototype_value); // BigUint64Array = new Function() - JSHandle bigUint64ArrayFunction = factory_->NewSpecificTypedArrayFunction( + JSHandle big_uint64_array_function = factory_->NewSpecificTypedArrayFunction( env, reinterpret_cast(BuiltinsTypedArray::BigUint64ArrayConstructor)); - InitializeCtor(env, bigUint64ArrFuncPrototype, bigUint64ArrayFunction, "BigUint64Array", FunctionLength::THREE); + InitializeCtor(env, big_uint64_arr_func_prototype, big_uint64_array_function, "BigUint64Array", + FunctionLength::THREE); - bigUint64ArrayFunction->SetProtoOrDynClass(thread_, bigUint64ArrFuncInstanceDynclass.GetTaggedValue()); + big_uint64_array_function->SetProtoOrDynClass(thread_, big_uint64_arr_func_instance_dynclass.GetTaggedValue()); - const int bytesPerElement = 8; - SetConstant(bigUint64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - SetConstant(JSHandle(bigUint64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); - env->SetBigUint64ArrayFunction(thread_, bigUint64ArrayFunction); + const int bytes_per_element = 8; + SetConstant(big_uint64_arr_func_prototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + SetConstant(JSHandle(big_uint64_array_function), "BYTES_PER_ELEMENT", JSTaggedValue(bytes_per_element)); + env->SetBigUint64ArrayFunction(thread_, big_uint64_array_function); } -void Builtins::InitializeArrayBuffer(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeArrayBuffer(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // ArrayBuffer.prototype - JSHandle arrayBufferFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle arrayBufferFuncPrototypeValue(arrayBufferFuncPrototype); + JSHandle array_buffer_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle array_buffer_func_prototype_value(array_buffer_func_prototype); // ArrayBuffer.prototype_or_dynclass - JSHandle arrayBufferFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_ARRAY_BUFFER, arrayBufferFuncPrototypeValue); + JSHandle array_buffer_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_ARRAY_BUFFER, array_buffer_func_prototype_value); // ArrayBuffer = new Function() - JSHandle arrayBufferFunction(NewBuiltinConstructor( - env, arrayBufferFuncPrototype, ArrayBuffer::ArrayBufferConstructor, "ArrayBuffer", FunctionLength::ONE)); + JSHandle array_buffer_function(NewBuiltinConstructor( + env, array_buffer_func_prototype, ArrayBuffer::ArrayBufferConstructor, "ArrayBuffer", FunctionLength::ONE)); - JSHandle(arrayBufferFunction) - ->SetFunctionPrototype(thread_, arrayBufferFuncInstanceDynclass.GetTaggedValue()); + JSHandle(array_buffer_function) + ->SetFunctionPrototype(thread_, array_buffer_func_instance_dynclass.GetTaggedValue()); // ArrayBuffer prototype method - SetFunction(env, arrayBufferFuncPrototype, "slice", ArrayBuffer::Slice, FunctionLength::TWO); + SetFunction(env, array_buffer_func_prototype, "slice", ArrayBuffer::Slice, FunctionLength::TWO); // ArrayBuffer method - SetFunction(env, arrayBufferFunction, "isView", ArrayBuffer::IsView, FunctionLength::ONE); + SetFunction(env, array_buffer_function, "isView", ArrayBuffer::IsView, FunctionLength::ONE); // 24.1.3.3 get ArrayBuffer[@@species] - JSHandle speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesGetter = + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_getter = CreateGetter(env, ArrayBuffer::Species, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(JSHandle(arrayBufferFunction), speciesSymbol, speciesGetter); + SetGetter(JSHandle(array_buffer_function), species_symbol, species_getter); // 24.1.4.1 get ArrayBuffer.prototype.byteLength - JSHandle lengthGetter = + JSHandle length_getter = CreateGetter(env, ArrayBuffer::GetByteLength, "byteLength", FunctionLength::ZERO); - JSHandle lengthKey(factory_->NewFromCanBeCompressString("byteLength")); - SetGetter(arrayBufferFuncPrototype, lengthKey, lengthGetter); + JSHandle length_key(factory_->NewFromCanBeCompressString("byteLength")); + SetGetter(array_buffer_func_prototype, length_key, length_getter); // 24.1.4.4 ArrayBuffer.prototype[@@toStringTag] - SetStringTagSymbol(env, arrayBufferFuncPrototype, "ArrayBuffer"); + SetStringTagSymbol(env, array_buffer_func_prototype, "ArrayBuffer"); - env->SetArrayBufferFunction(thread_, arrayBufferFunction.GetTaggedValue()); + env->SetArrayBufferFunction(thread_, array_buffer_function.GetTaggedValue()); } void Builtins::InitializeReflect(const JSHandle &env, - const JSHandle &objFuncPrototypeVal) const + const JSHandle &obj_func_prototype_val) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle reflectDynclass = factory_->CreateDynClass(JSType::JS_OBJECT, objFuncPrototypeVal); - JSHandle reflectObject = factory_->NewJSObject(reflectDynclass); - - SetFunction(env, reflectObject, "apply", Reflect::ReflectApply, FunctionLength::THREE); - SetFunction(env, reflectObject, "construct", Reflect::ReflectConstruct, FunctionLength::TWO); - SetFunction(env, reflectObject, "defineProperty", Reflect::ReflectDefineProperty, FunctionLength::THREE); - SetFunction(env, reflectObject, "deleteProperty", Reflect::ReflectDeleteProperty, FunctionLength::TWO); - SetFunction(env, reflectObject, "get", Reflect::ReflectGet, FunctionLength::TWO); - SetFunction(env, reflectObject, "getOwnPropertyDescriptor", Reflect::ReflectGetOwnPropertyDescriptor, + 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, reflectObject, "getPrototypeOf", Reflect::ReflectGetPrototypeOf, FunctionLength::ONE); - SetFunction(env, reflectObject, "has", Reflect::ReflectHas, FunctionLength::TWO); - SetFunction(env, reflectObject, "isExtensible", Reflect::ReflectIsExtensible, FunctionLength::ONE); - SetFunction(env, reflectObject, "ownKeys", Reflect::ReflectOwnKeys, FunctionLength::ONE); - SetFunction(env, reflectObject, "preventExtensions", Reflect::ReflectPreventExtensions, FunctionLength::ONE); - SetFunction(env, reflectObject, "set", Reflect::ReflectSet, FunctionLength::THREE); - SetFunction(env, reflectObject, "setPrototypeOf", Reflect::ReflectSetPrototypeOf, FunctionLength::TWO); - - JSHandle reflectString(factory_->NewFromCanBeCompressString("Reflect")); - JSHandle globalObject(thread_, env->GetGlobalObject()); - PropertyDescriptor reflectDesc(thread_, JSHandle::Cast(reflectObject), true, false, true); - JSObject::DefineOwnProperty(thread_, globalObject, reflectString, reflectDesc); + 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); + + JSHandle reflect_string(factory_->NewFromCanBeCompressString("Reflect")); + JSHandle global_object(thread_, env->GetGlobalObject()); + PropertyDescriptor reflect_desc(thread_, JSHandle::Cast(reflect_object), true, false, true); + JSObject::DefineOwnProperty(thread_, global_object, reflect_string, reflect_desc); // @@ToStringTag - SetStringTagSymbol(env, reflectObject, "Reflect"); + SetStringTagSymbol(env, reflect_object, "Reflect"); - env->SetReflectFunction(thread_, reflectObject.GetTaggedValue()); + env->SetReflectFunction(thread_, reflect_object.GetTaggedValue()); } -void Builtins::InitializePromise(const JSHandle &env, const JSHandle &promiseFuncDynclass) +void Builtins::InitializePromise(const JSHandle &env, const JSHandle &promise_func_dynclass) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Promise.prototype - JSHandle promiseFuncPrototype = factory_->NewJSObject(promiseFuncDynclass); - JSHandle promiseFuncPrototypeValue(promiseFuncPrototype); + JSHandle promise_func_prototype = factory_->NewJSObject(promise_func_dynclass); + JSHandle promise_func_prototype_value(promise_func_prototype); // Promise.prototype_or_dynclass - JSHandle promiseFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PROMISE, promiseFuncPrototypeValue); + JSHandle promise_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PROMISE, promise_func_prototype_value); // Promise() = new Function() - JSHandle promiseFunction( - NewBuiltinConstructor(env, promiseFuncPrototype, Promise::PromiseConstructor, "Promise", FunctionLength::ONE)); - JSHandle(promiseFunction)->SetFunctionPrototype(thread_, promiseFuncInstanceDynclass.GetTaggedValue()); + JSHandle promise_function(NewBuiltinConstructor(env, promise_func_prototype, Promise::PromiseConstructor, + "Promise", FunctionLength::ONE)); + JSHandle(promise_function) + ->SetFunctionPrototype(thread_, promise_func_instance_dynclass.GetTaggedValue()); // Promise method - SetFunction(env, promiseFunction, "all", Promise::All, FunctionLength::ONE); - SetFunction(env, promiseFunction, "race", Promise::Race, FunctionLength::ONE); - SetFunction(env, promiseFunction, "resolve", Promise::Resolve, FunctionLength::ONE); - SetFunction(env, promiseFunction, "reject", Promise::Reject, FunctionLength::ONE); + 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, promiseFuncPrototype, "catch", Promise::Catch, FunctionLength::ONE); - SetFunction(env, promiseFuncPrototype, "then", Promise::Then, FunctionLength::TWO); + SetFunction(env, promise_func_prototype, "catch", Promise::Catch, FunctionLength::ONE); + SetFunction(env, promise_func_prototype, "then", Promise::Then, FunctionLength::TWO); // Promise.prototype [ @@toStringTag ] - SetStringTagSymbol(env, promiseFuncPrototype, "Promise"); + SetStringTagSymbol(env, promise_func_prototype, "Promise"); // Set Promise [@@species] - JSHandle speciesSymbol(env->GetSpeciesSymbol()); - JSHandle speciesGetter = + JSHandle species_symbol(env->GetSpeciesSymbol()); + JSHandle species_getter = CreateGetter(env, Promise::GetSpecies, "[Symbol.species]", FunctionLength::ZERO); - SetGetter(promiseFunction, speciesSymbol, speciesGetter); + SetGetter(promise_function, species_symbol, species_getter); - env->SetPromiseFunction(thread_, promiseFunction); + env->SetPromiseFunction(thread_, promise_function); } void Builtins::InitializePromiseJob(const JSHandle &env) { - JSHandle keyString(thread_->GlobalConstants()->GetHandledEmptyString()); - auto func = NewFunction(env, keyString, BuiltinsPromiseJob::PromiseReactionJob, FunctionLength::TWO); + JSHandle key_string(thread_->GlobalConstants()->GetHandledEmptyString()); + auto func = NewFunction(env, key_string, BuiltinsPromiseJob::PromiseReactionJob, FunctionLength::TWO); env->SetPromiseReactionJob(thread_, func); - func = NewFunction(env, keyString, BuiltinsPromiseJob::PromiseResolveThenableJob, FunctionLength::THREE); + func = NewFunction(env, key_string, BuiltinsPromiseJob::PromiseResolveThenableJob, FunctionLength::THREE); env->SetPromiseResolveThenableJob(thread_, func); } void Builtins::InitializeFinalizationRegistry(const JSHandle &env, - const JSHandle &objFuncDynclass) const + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); // FinalizationRegistry.prototype - JSHandle registryFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle registryFuncPrototypeValue(registryFuncPrototype); + JSHandle registry_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle registry_func_prototype_value(registry_func_prototype); // FinalizationRegistry.prototype_or_dynclass - JSHandle registryFuncInstanceDynclass = - factory_->CreateDynClass(JSType::FINALIZATION_REGISTRY, registryFuncPrototypeValue); + JSHandle registry_func_instance_dynclass = + factory_->CreateDynClass(JSType::FINALIZATION_REGISTRY, registry_func_prototype_value); // FinalizationRegistry() = new Function() - JSHandle registryFunction(NewBuiltinConstructor(env, registryFuncPrototype, - BuiltinsFinalizationRegistry::Constructor, - "FinalizationRegistry", FunctionLength::ONE)); + JSHandle registry_function(NewBuiltinConstructor(env, registry_func_prototype, + BuiltinsFinalizationRegistry::Constructor, + "FinalizationRegistry", FunctionLength::ONE)); // FinalizationRegistry().prototype = FinalizationRegistry.Prototype & // FinalizationRegistry.prototype.constructor = Finalizationregistry() - JSFunction::Cast(registryFunction->GetTaggedObject()) - ->SetProtoOrDynClass(thread_, registryFuncInstanceDynclass.GetTaggedValue()); + JSFunction::Cast(registry_function->GetTaggedObject()) + ->SetProtoOrDynClass(thread_, registry_func_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread_, JSHandle(registryFuncPrototype), constructorKey, registryFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread_, JSHandle(registry_func_prototype), constructor_key, + registry_function); // FinalizationRegistry.prototype.register() - SetFunction(env, registryFuncPrototype, "register", BuiltinsFinalizationRegistry::Register, FunctionLength::TWO); + SetFunction(env, registry_func_prototype, "register", BuiltinsFinalizationRegistry::Register, FunctionLength::TWO); // FinalizationRegistry.prototype.unregister() - SetFunction(env, registryFuncPrototype, "unregister", BuiltinsFinalizationRegistry::Unregister, + SetFunction(env, registry_func_prototype, "unregister", BuiltinsFinalizationRegistry::Unregister, FunctionLength::ONE); // @@ToStringTag - SetStringTagSymbol(env, registryFuncPrototype, "FinalizationRegistry"); + SetStringTagSymbol(env, registry_func_prototype, "FinalizationRegistry"); - const_cast(globalConst) - ->SetConstant(ConstantIndex::FINALIZATION_REGISTRY_CLASS_INDEX, registryFuncInstanceDynclass.GetTaggedValue()); + const_cast(global_const) + ->SetConstant(ConstantIndex::FINALIZATION_REGISTRY_CLASS_INDEX, + registry_func_instance_dynclass.GetTaggedValue()); } -void Builtins::InitializeDataView(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeDataView(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); // ArrayBuffer.prototype - JSHandle dataViewFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle dataViewFuncPrototypeValue(dataViewFuncPrototype); + JSHandle data_view_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle data_view_func_prototype_value(data_view_func_prototype); // ArrayBuffer.prototype_or_dynclass - JSHandle dataViewFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_DATA_VIEW, dataViewFuncPrototypeValue); + JSHandle data_view_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_DATA_VIEW, data_view_func_prototype_value); // ArrayBuffer = new Function() - JSHandle dataViewFunction(NewBuiltinConstructor(env, dataViewFuncPrototype, DataView::DataViewConstructor, - "DataView", FunctionLength::ONE)); + JSHandle data_view_function(NewBuiltinConstructor( + env, data_view_func_prototype, DataView::DataViewConstructor, "DataView", FunctionLength::ONE)); - JSHandle(dataViewFunction)->SetProtoOrDynClass(thread_, dataViewFuncInstanceDynclass.GetTaggedValue()); + JSHandle(data_view_function) + ->SetProtoOrDynClass(thread_, data_view_func_instance_dynclass.GetTaggedValue()); // DataView.prototype method - SetFunction(env, dataViewFuncPrototype, "getFloat32", DataView::GetFloat32, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getFloat64", DataView::GetFloat64, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getInt8", DataView::GetInt8, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getInt16", DataView::GetInt16, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getInt32", DataView::GetInt32, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getUint8", DataView::GetUint8, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getUint16", DataView::GetUint16, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "getUint32", DataView::GetUint32, FunctionLength::ONE); - SetFunction(env, dataViewFuncPrototype, "setFloat32", DataView::SetFloat32, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setFloat64", DataView::SetFloat64, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setInt8", DataView::SetInt8, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setInt16", DataView::SetInt16, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setInt32", DataView::SetInt32, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setUint8", DataView::SetUint8, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setUint16", DataView::SetUint16, FunctionLength::TWO); - SetFunction(env, dataViewFuncPrototype, "setUint32", DataView::SetUint32, FunctionLength::TWO); + 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 bufferGetter = CreateGetter(env, DataView::GetBuffer, "buffer", FunctionLength::ZERO); - JSHandle bufferKey(factory_->NewFromCanBeCompressString("buffer")); - SetGetter(dataViewFuncPrototype, bufferKey, bufferGetter); + 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 lengthGetter = + JSHandle length_getter = CreateGetter(env, DataView::GetByteLength, "byteLength", FunctionLength::ZERO); - JSHandle lengthKey(factory_->NewFromCanBeCompressString("byteLength")); - SetGetter(dataViewFuncPrototype, lengthKey, lengthGetter); + JSHandle length_key(factory_->NewFromCanBeCompressString("byteLength")); + SetGetter(data_view_func_prototype, length_key, length_getter); // 24.2.4.3 get DataView.prototype.byteOffset - JSHandle offsetGetter = CreateGetter(env, DataView::GetOffset, "byteOffset", FunctionLength::ZERO); - JSHandle offsetKey(factory_->NewFromCanBeCompressString("byteOffset")); - SetGetter(dataViewFuncPrototype, offsetKey, offsetGetter); + 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); // 24.2.4.21 DataView.prototype[ @@toStringTag ] - SetStringTagSymbol(env, dataViewFuncPrototype, "DataView"); - env->SetDataViewFunction(thread_, dataViewFunction.GetTaggedValue()); + SetStringTagSymbol(env, data_view_func_prototype, "DataView"); + env->SetDataViewFunction(thread_, data_view_function.GetTaggedValue()); } JSHandle Builtins::NewBuiltinConstructor(const JSHandle &env, - const JSHandle &prototype, EcmaEntrypoint ctorFunc, + const JSHandle &prototype, EcmaEntrypoint ctor_func, const char *name, int length) const { JSHandle ctor = - factory_->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_CONSTRUCTOR); + factory_->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_CONSTRUCTOR); InitializeCtor(env, prototype, ctor, name, length); return ctor; } @@ -2465,17 +2500,17 @@ JSHandle Builtins::NewFunction(const JSHandle &env, const { JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle baseFunction(function); - JSHandle handleUndefine(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, baseFunction, key, handleUndefine); + JSHandle base_function(function); + JSHandle handle_undefine(thread_, JSTaggedValue::Undefined()); + JSFunction::SetFunctionName(thread_, base_function, key, handle_undefine); return function; } void Builtins::SetFunction(const JSHandle &env, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) const { - JSHandle keyString(factory_->NewFromString(key)); - SetFunction(env, obj, keyString, func, length); + JSHandle key_string(factory_->NewFromString(key)); + SetFunction(env, obj, key_string, func, length); } void Builtins::SetFunction(const JSHandle &env, const JSHandle &obj, @@ -2489,30 +2524,30 @@ void Builtins::SetFunction(const JSHandle &env, const JSHandle &env, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) const { - JSHandle keyString(factory_->NewFromString(key)); - JSHandle function = NewFunction(env, keyString, func, length); + JSHandle key_string(factory_->NewFromString(key)); + JSHandle function = NewFunction(env, key_string, func, length); PropertyDescriptor descriptor(thread_, JSHandle(function), false, false, false); - JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); + 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 { JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle nameString(factory_->NewFromString(name)); - JSHandle baseFunction(function); - JSHandle handleUndefine(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, baseFunction, nameString, handleUndefine); + JSHandle name_string(factory_->NewFromString(name)); + JSHandle base_function(function); + JSHandle handle_undefine(thread_, JSTaggedValue::Undefined()); + JSFunction::SetFunctionName(thread_, base_function, name_string, handle_undefine); // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) - if constexpr (flag == JSSymbol::SYMBOL_TO_PRIMITIVE_TYPE) { + if constexpr (FLAG == JSSymbol::SYMBOL_TO_PRIMITIVE_TYPE) { PropertyDescriptor descriptor(thread_, JSHandle::Cast(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::SYMBOL_HAS_INSTANCE_TYPE) { // 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); @@ -2536,9 +2571,9 @@ JSHandle Builtins::CreateGetter(const JSHandle &env, E { JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle funcName(factory_->NewFromString(name)); + JSHandle func_name(factory_->NewFromString(name)); JSHandle prefix = thread_->GlobalConstants()->GetHandledGetString(); - JSFunction::SetFunctionName(thread_, JSHandle(function), funcName, prefix); + JSFunction::SetFunctionName(thread_, JSHandle(function), func_name, prefix); return JSHandle(function); } @@ -2547,61 +2582,62 @@ JSHandle Builtins::CreateSetter(const JSHandle &env, E { JSHandle function = factory_->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread_, function, JSTaggedValue(length)); - JSHandle funcName(factory_->NewFromString(name)); + JSHandle func_name(factory_->NewFromString(name)); JSHandle prefix = thread_->GlobalConstants()->GetHandledSetString(); - JSFunction::SetFunctionName(thread_, JSHandle(function), funcName, prefix); + JSFunction::SetFunctionName(thread_, JSHandle(function), func_name, prefix); return JSHandle(function); } void Builtins::SetConstant(const JSHandle &obj, const char *key, JSTaggedValue value) const { - JSHandle valueHandle(thread_, value); - JSHandle keyString(factory_->NewFromString(key)); - PropertyDescriptor descriptor(thread_, valueHandle, false, false, false); - JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); + JSHandle value_handle(thread_, value); + JSHandle key_string(factory_->NewFromString(key)); + PropertyDescriptor descriptor(thread_, value_handle, false, false, false); + JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); } void Builtins::SetConstantObject(const JSHandle &obj, const char *key, JSHandle &value) const { - JSHandle keyString(factory_->NewFromString(key)); + JSHandle key_string(factory_->NewFromString(key)); PropertyDescriptor descriptor(thread_, value, false, false, false); - JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); + JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); } -void Builtins::SetGlobalThis(const JSHandle &obj, const char *key, const JSHandle &globalValue) +void Builtins::SetGlobalThis(const JSHandle &obj, const char *key, + const JSHandle &global_value) { - JSHandle keyString(factory_->NewFromString(key)); - PropertyDescriptor descriptor(thread_, globalValue, true, false, true); - JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); + JSHandle key_string(factory_->NewFromString(key)); + PropertyDescriptor descriptor(thread_, global_value, true, false, true); + JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); } void Builtins::SetAttribute(const JSHandle &obj, const char *key, const char *value) const { - JSHandle keyString(factory_->NewFromString(key)); + JSHandle key_string(factory_->NewFromString(key)); PropertyDescriptor descriptor(thread_, JSHandle(factory_->NewFromString(value)), true, false, true); - JSObject::DefineOwnProperty(thread_, obj, keyString, descriptor); + JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); } void Builtins::SetNoneAttributeProperty(const JSHandle &obj, const char *key, const JSHandle &value) const { - JSHandle keyString(factory_->NewFromString(key)); + JSHandle key_string(factory_->NewFromString(key)); PropertyDescriptor des(thread_, value, false, false, false); - JSObject::DefineOwnProperty(thread_, obj, keyString, des); + JSObject::DefineOwnProperty(thread_, obj, key_string, des); } -void Builtins::SetFuncToObjAndGlobal(const JSHandle &env, const JSHandle &globalObject, +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 keyString(factory_->NewFromString(key)); - JSHandle baseFunction(function); - JSHandle handleUndefine(thread_, JSTaggedValue::Undefined()); - JSFunction::SetFunctionName(thread_, baseFunction, keyString, handleUndefine); + 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, keyString, descriptor); - JSObject::DefineOwnProperty(thread_, globalObject, keyString, descriptor); + JSObject::DefineOwnProperty(thread_, obj, key_string, descriptor); + JSObject::DefineOwnProperty(thread_, global_object, key_string, descriptor); } void Builtins::StrictModeForbiddenAccessCallerArguments(const JSHandle &env, @@ -2618,194 +2654,200 @@ void Builtins::StrictModeForbiddenAccessCallerArguments(const JSHandle &env, - const JSHandle &objFuncDynclass) const + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); - JSHandle generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle generatorFuncPrototypeValue(generatorFuncPrototype); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + JSHandle generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle generator_func_prototype_value(generator_func_prototype); // 26.3.3.1 GeneratorFunction.prototype.constructor // GeneratorFunction.prototype_or_dynclass - JSHandle generatorFuncInstanceDynclass = factory_->CreateDynClass( - JSType::JS_GENERATOR_FUNCTION, generatorFuncPrototypeValue, HClass::IS_CALLABLE); - generatorFuncInstanceDynclass->SetExtensible(true); + JSHandle generator_func_instance_dynclass = factory_->CreateDynClass( + JSType::JS_GENERATOR_FUNCTION, generator_func_prototype_value, HClass::IS_CALLABLE); + generator_func_instance_dynclass->SetExtensible(true); // GeneratorFunction = new GeneratorFunction() JSHandle generator_function = - NewBuiltinConstructor(env, generatorFuncPrototype, GeneratorObject::GeneratorFunctionConstructor, + NewBuiltinConstructor(env, generator_func_prototype, GeneratorObject::GeneratorFunctionConstructor, "GeneratorFunction", FunctionLength::ONE); - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - PropertyDescriptor generatorDesc(thread_, JSHandle::Cast(generator_function), false, false, true); - JSObject::DefineOwnProperty(thread_, generatorFuncPrototype, constructorKey, generatorDesc); - generator_function->SetProtoOrDynClass(thread_, generatorFuncInstanceDynclass.GetTaggedValue()); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + PropertyDescriptor generator_desc(thread_, JSHandle::Cast(generator_function), false, false, true); + JSObject::DefineOwnProperty(thread_, generator_func_prototype, constructor_key, generator_desc); + generator_function->SetProtoOrDynClass(thread_, generator_func_instance_dynclass.GetTaggedValue()); env->SetGeneratorFunctionFunction(thread_, generator_function); // 26.3.3.2 GeneratorFunction.prototype.prototype -> Generator prototype object. PropertyDescriptor descriptor(thread_, env->GetGeneratorPrototype(), false, false, true); - JSObject::DefineOwnProperty(thread_, generatorFuncPrototype, globalConst->GetHandledPrototypeString(), descriptor); + JSObject::DefineOwnProperty(thread_, generator_func_prototype, global_const->GetHandledPrototypeString(), + descriptor); // 26.3.3.3 GeneratorFunction.prototype[@@toStringTag] - SetStringTagSymbol(env, generatorFuncPrototype, "GeneratorFunction"); + SetStringTagSymbol(env, generator_func_prototype, "GeneratorFunction"); // GeneratorFunction prototype __proto__ -> Function. - JSObject::SetPrototype(thread_, generatorFuncPrototype, env->GetFunctionPrototype()); + JSObject::SetPrototype(thread_, generator_func_prototype, env->GetFunctionPrototype()); // 26.5.1.1 Generator.prototype.constructor -> %GeneratorFunction.prototype%. - PropertyDescriptor generatorObjDesc(thread_, generatorFuncPrototypeValue, false, false, true); + PropertyDescriptor generator_obj_desc(thread_, generator_func_prototype_value, false, false, true); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialGenerator()), - globalConst->GetHandledConstructorString(), generatorObjDesc); + global_const->GetHandledConstructorString(), generator_obj_desc); // Generator instances prototype -> GeneratorFunction.prototype.prototype - PropertyDescriptor generatorObjProtoDesc(thread_, generatorFuncPrototypeValue, true, false, false); + PropertyDescriptor generator_obj_proto_desc(thread_, generator_func_prototype_value, true, false, false); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialGenerator()), - globalConst->GetHandledPrototypeString(), generatorObjProtoDesc); + global_const->GetHandledPrototypeString(), generator_obj_proto_desc); - env->SetGeneratorFunctionPrototype(thread_, generatorFuncPrototype); + env->SetGeneratorFunctionPrototype(thread_, generator_func_prototype); } -void Builtins::InitializeGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeGenerator(const JSHandle &env, const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); - JSHandle generatorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + 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, generatorFuncPrototype, "next", GeneratorObject::GeneratorPrototypeNext, FunctionLength::ONE); + SetFunction(env, generator_func_prototype, "next", GeneratorObject::GeneratorPrototypeNext, FunctionLength::ONE); // 26.5.1.3 Generator.prototype.return(value) - SetFunction(env, generatorFuncPrototype, "return", GeneratorObject::GeneratorPrototypeReturn, FunctionLength::ONE); + SetFunction(env, generator_func_prototype, "return", GeneratorObject::GeneratorPrototypeReturn, + FunctionLength::ONE); // 26.5.1.4 Generator.prototype.throw(exception) - SetFunction(env, generatorFuncPrototype, "throw", GeneratorObject::GeneratorPrototypeThrow, FunctionLength::ONE); + SetFunction(env, generator_func_prototype, "throw", GeneratorObject::GeneratorPrototypeThrow, FunctionLength::ONE); // 26.5.1.5 Generator.prototype[@@toStringTag] - SetStringTagSymbol(env, generatorFuncPrototype, "Generator"); + SetStringTagSymbol(env, generator_func_prototype, "Generator"); // Generator with constructor, symbolTag, next/return/throw etc. PropertyDescriptor descriptor(thread_, env->GetIteratorPrototype(), true, false, false); - JSObject::DefineOwnProperty(thread_, generatorFuncPrototype, globalConst->GetHandledPrototypeString(), descriptor); - env->SetGeneratorPrototype(thread_, generatorFuncPrototype); - JSObject::SetPrototype(thread_, generatorFuncPrototype, env->GetIteratorPrototype()); + JSObject::DefineOwnProperty(thread_, generator_func_prototype, global_const->GetHandledPrototypeString(), + descriptor); + env->SetGeneratorPrototype(thread_, generator_func_prototype); + JSObject::SetPrototype(thread_, generator_func_prototype, env->GetIteratorPrototype()); // Generator {} - JSHandle initialGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, JSHandle(generatorFuncPrototype)); - env->SetInitialGenerator(thread_, initialGeneratorFuncPrototype); + JSHandle initial_generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSObject::SetPrototype(thread_, initial_generator_func_prototype, + JSHandle(generator_func_prototype)); + env->SetInitialGenerator(thread_, initial_generator_func_prototype); } void Builtins::InitializeAsyncGeneratorFunction(const JSHandle &env, - const JSHandle &objFuncDynclass) const + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); - JSHandle asyncGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSHandle asyncGeneratorFuncPrototypeValue(asyncGeneratorFuncPrototype); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); + JSHandle async_generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSHandle async_generator_func_prototype_value(async_generator_func_prototype); // 26.3.3.1 AsyncGeneratorFunction.prototype.constructor // AsyncGeneratorFunction.prototype_or_dynclass - JSHandle asyncGeneratorFuncInstanceDynclass = factory_->CreateDynClass( - JSType::JS_ASYNC_GENERATOR_FUNCTION, asyncGeneratorFuncPrototypeValue, HClass::IS_CALLABLE); - asyncGeneratorFuncInstanceDynclass->SetExtensible(true); + JSHandle async_generator_func_instance_dynclass = factory_->CreateDynClass( + JSType::JS_ASYNC_GENERATOR_FUNCTION, async_generator_func_prototype_value, HClass::IS_CALLABLE); + async_generator_func_instance_dynclass->SetExtensible(true); // AsyncGeneratorFunction = new AsyncGeneratorFunction() - JSHandle asyncGeneratorFunction = - NewBuiltinConstructor(env, asyncGeneratorFuncPrototype, AsyncGeneratorObject::AsyncGeneratorFunctionConstructor, - "AsyncGeneratorFunction", FunctionLength::ONE); - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - PropertyDescriptor asyncGeneratorDesc(thread_, JSHandle::Cast(asyncGeneratorFunction), false, false, - true); - JSObject::DefineOwnProperty(thread_, asyncGeneratorFuncPrototype, constructorKey, asyncGeneratorDesc); - asyncGeneratorFunction->SetProtoOrDynClass(thread_, asyncGeneratorFuncInstanceDynclass.GetTaggedValue()); - env->SetAsyncGeneratorFunctionFunction(thread_, asyncGeneratorFunction); + JSHandle async_generator_function = NewBuiltinConstructor( + env, async_generator_func_prototype, AsyncGeneratorObject::AsyncGeneratorFunctionConstructor, + "AsyncGeneratorFunction", FunctionLength::ONE); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + PropertyDescriptor async_generator_desc(thread_, JSHandle::Cast(async_generator_function), false, + false, true); + JSObject::DefineOwnProperty(thread_, async_generator_func_prototype, constructor_key, async_generator_desc); + async_generator_function->SetProtoOrDynClass(thread_, async_generator_func_instance_dynclass.GetTaggedValue()); + env->SetAsyncGeneratorFunctionFunction(thread_, async_generator_function); // 26.3.3.2 AsyncGeneratorFunction.prototype.prototype -> AsyncGenerator prototype object. PropertyDescriptor descriptor(thread_, env->GetAsyncGeneratorPrototype(), false, false, true); - JSObject::DefineOwnProperty(thread_, asyncGeneratorFuncPrototype, globalConst->GetHandledPrototypeString(), + JSObject::DefineOwnProperty(thread_, async_generator_func_prototype, global_const->GetHandledPrototypeString(), descriptor); // 26.3.3.3 AsyncGeneratorFunction.prototype[@@toStringTag] - SetStringTagSymbol(env, asyncGeneratorFuncPrototype, "AsyncGeneratorFunction"); + SetStringTagSymbol(env, async_generator_func_prototype, "AsyncGeneratorFunction"); // AsyncGeneratorFunction prototype __proto__ -> Function. - JSObject::SetPrototype(thread_, asyncGeneratorFuncPrototype, env->GetFunctionPrototype()); + JSObject::SetPrototype(thread_, async_generator_func_prototype, env->GetFunctionPrototype()); // 26.5.1.1 AsyncGenerator.prototype.constructor -> %AsyncGeneratorFunction.prototype%. - PropertyDescriptor asyncGeneratorObjDesc(thread_, asyncGeneratorFuncPrototypeValue, false, false, true); + PropertyDescriptor async_generator_obj_desc(thread_, async_generator_func_prototype_value, false, false, true); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialAsyncGenerator()), - globalConst->GetHandledConstructorString(), asyncGeneratorObjDesc); + global_const->GetHandledConstructorString(), async_generator_obj_desc); // AsyncGenerator instances prototype -> AsyncGeneratorFunction.prototype.prototype - PropertyDescriptor asyncGeneratorObjProtoDesc(thread_, asyncGeneratorFuncPrototypeValue, true, false, false); + PropertyDescriptor async_generator_obj_proto_desc(thread_, async_generator_func_prototype_value, true, false, + false); JSObject::DefineOwnProperty(thread_, JSHandle(env->GetInitialAsyncGenerator()), - globalConst->GetHandledPrototypeString(), asyncGeneratorObjProtoDesc); + global_const->GetHandledPrototypeString(), async_generator_obj_proto_desc); - env->SetAsyncGeneratorFunctionPrototype(thread_, asyncGeneratorFuncPrototype); + env->SetAsyncGeneratorFunctionPrototype(thread_, async_generator_func_prototype); } -void Builtins::InitializeAsyncGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const +void Builtins::InitializeAsyncGenerator(const JSHandle &env, + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); - JSHandle asyncGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); + 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, asyncGeneratorFuncPrototype, "next", AsyncGeneratorObject::AsyncGeneratorPrototypeNext, + SetFunction(env, async_generator_func_prototype, "next", AsyncGeneratorObject::AsyncGeneratorPrototypeNext, FunctionLength::ONE); // 27.6.1.3 AsyncGenerator.prototype.return(value) - SetFunction(env, asyncGeneratorFuncPrototype, "return", AsyncGeneratorObject::AsyncGeneratorPrototypeReturn, + SetFunction(env, async_generator_func_prototype, "return", AsyncGeneratorObject::AsyncGeneratorPrototypeReturn, FunctionLength::ONE); // 27.6.1.4 AsyncGenerator.prototype.throw(exception) - SetFunction(env, asyncGeneratorFuncPrototype, "throw", AsyncGeneratorObject::AsyncGeneratorPrototypeThrow, + SetFunction(env, async_generator_func_prototype, "throw", AsyncGeneratorObject::AsyncGeneratorPrototypeThrow, FunctionLength::ONE); // 27.6.1.5 AsyncGenerator.prototype[@@toStringTag] - SetStringTagSymbol(env, asyncGeneratorFuncPrototype, "AsyncGenerator"); + SetStringTagSymbol(env, async_generator_func_prototype, "AsyncGenerator"); PropertyDescriptor descriptor(thread_, env->GetAsyncIteratorPrototype(), true, false, false); - JSObject::DefineOwnProperty(thread_, asyncGeneratorFuncPrototype, globalConst->GetHandledPrototypeString(), + JSObject::DefineOwnProperty(thread_, async_generator_func_prototype, global_const->GetHandledPrototypeString(), descriptor); - env->SetAsyncGeneratorPrototype(thread_, asyncGeneratorFuncPrototype); - JSObject::SetPrototype(thread_, asyncGeneratorFuncPrototype, env->GetAsyncIteratorPrototype()); + env->SetAsyncGeneratorPrototype(thread_, async_generator_func_prototype); + JSObject::SetPrototype(thread_, async_generator_func_prototype, env->GetAsyncIteratorPrototype()); // AsyncGenerator {} - JSHandle initialAsyncGeneratorFuncPrototype = factory_->NewJSObject(objFuncDynclass); - JSObject::SetPrototype(thread_, initialAsyncGeneratorFuncPrototype, - JSHandle(asyncGeneratorFuncPrototype)); - env->SetInitialAsyncGenerator(thread_, initialAsyncGeneratorFuncPrototype); + JSHandle initial_async_generator_func_prototype = factory_->NewJSObject(obj_func_dynclass); + JSObject::SetPrototype(thread_, initial_async_generator_func_prototype, + JSHandle(async_generator_func_prototype)); + env->SetInitialAsyncGenerator(thread_, initial_async_generator_func_prototype); } void Builtins::InitializeAsyncFromSyncIteratorPrototypeObject(const JSHandle &env, - const JSHandle &objFuncDynclass) const + const JSHandle &obj_func_dynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle asyncFromSyncIteratorPrototype = factory_->NewJSObject(objFuncDynclass); + JSHandle async_from_sync_iterator_prototype = factory_->NewJSObject(obj_func_dynclass); // 27.1.4.2.1 %AsyncFromSyncIteratorPrototype%.next - SetFunction(env, asyncFromSyncIteratorPrototype, "next", AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext, - FunctionLength::ONE); + SetFunction(env, async_from_sync_iterator_prototype, "next", + AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext, FunctionLength::ONE); // 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return - SetFunction(env, asyncFromSyncIteratorPrototype, "return", + SetFunction(env, async_from_sync_iterator_prototype, "return", AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeReturn, FunctionLength::ONE); // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.throw - SetFunction(env, asyncFromSyncIteratorPrototype, "throw", + SetFunction(env, async_from_sync_iterator_prototype, "throw", AsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow, FunctionLength::ONE); - JSObject::SetPrototype(thread_, asyncFromSyncIteratorPrototype, env->GetAsyncIteratorPrototype()); - env->SetAsyncFromSyncIteratorPrototype(thread_, asyncFromSyncIteratorPrototype); + JSObject::SetPrototype(thread_, async_from_sync_iterator_prototype, env->GetAsyncIteratorPrototype()); + env->SetAsyncFromSyncIteratorPrototype(thread_, async_from_sync_iterator_prototype); } void Builtins::SetArgumentsSharedAccessor(const JSHandle &env) { - JSHandle throwFunction = env->GetThrowTypeError(); + JSHandle throw_function = env->GetThrowTypeError(); JSHandle accessor = factory_->NewAccessorData(); - accessor->SetGetter(thread_, throwFunction); - accessor->SetSetter(thread_, throwFunction); + accessor->SetGetter(thread_, throw_function); + accessor->SetSetter(thread_, throw_function); env->SetArgumentsCallerAccessor(thread_, accessor); accessor = factory_->NewAccessorData(); - accessor->SetGetter(thread_, throwFunction); - accessor->SetSetter(thread_, throwFunction); + accessor->SetGetter(thread_, throw_function); + accessor->SetSetter(thread_, throw_function); env->SetArgumentsCalleeAccessor(thread_, accessor); } @@ -2829,10 +2871,10 @@ void Builtins::SetGetter(const JSHandle &obj, const JSHandle Builtins::NewIntlConstructor(const JSHandle &env, const JSHandle &prototype, - EcmaEntrypoint ctorFunc, const char *name, int length) + EcmaEntrypoint ctor_func, const char *name, int length) { JSHandle ctor = - factory_->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_CONSTRUCTOR); + factory_->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_CONSTRUCTOR); InitializeIntlCtor(env, prototype, ctor, name, length); return ctor; } @@ -2840,291 +2882,293 @@ JSHandle Builtins::NewIntlConstructor(const JSHandle &env void Builtins::InitializeIntlCtor(const JSHandle &env, const JSHandle &prototype, const JSHandle &ctor, const char *name, int length) { - const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + const GlobalEnvConstants *global_const = thread_->GlobalConstants(); JSFunction::SetFunctionLength(thread_, ctor, JSTaggedValue(length)); - JSHandle nameString(factory_->NewFromString(name)); - JSFunction::SetFunctionName(thread_, JSHandle(ctor), nameString, + JSHandle name_string(factory_->NewFromString(name)); + JSFunction::SetFunctionName(thread_, JSHandle(ctor), name_string, JSHandle(thread_, JSTaggedValue::Undefined())); - JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSHandle constructor_key = global_const->GetHandledConstructorString(); PropertyDescriptor descriptor1(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, prototype, constructorKey, descriptor1); + JSObject::DefineOwnProperty(thread_, prototype, constructor_key, descriptor1); // set "prototype" in constructor. ctor->SetFunctionPrototype(thread_, prototype.GetTaggedValue()); - if (!JSTaggedValue::SameValue(nameString, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { - JSHandle intlObject(thread_, env->GetIntlFunction().GetTaggedValue()); + if (!JSTaggedValue::SameValue(name_string, thread_->GlobalConstants()->GetHandledAsyncFunctionString())) { + JSHandle intl_object(thread_, env->GetIntlFunction().GetTaggedValue()); PropertyDescriptor descriptor2(thread_, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread_, intlObject, nameString, descriptor2); + JSObject::DefineOwnProperty(thread_, intl_object, name_string, descriptor2); } } -void Builtins::InitializeIntl(const JSHandle &env, const JSHandle &objFuncPrototypeValue) +void Builtins::InitializeIntl(const JSHandle &env, const JSHandle &obj_func_prototype_value) { [[maybe_unused]] EcmaHandleScope scope(thread_); - JSHandle intlDynclass = factory_->CreateDynClass(JSType::JS_INTL, objFuncPrototypeValue); - JSHandle intlObject = factory_->NewJSObject(intlDynclass); + JSHandle intl_dynclass = factory_->CreateDynClass(JSType::JS_INTL, obj_func_prototype_value); + JSHandle intl_object = factory_->NewJSObject(intl_dynclass); - JSHandle initIntlSymbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol")); - SetNoneAttributeProperty(intlObject, "fallbackSymbol", initIntlSymbol); + JSHandle init_intl_symbol(factory_->NewPublicSymbolWithChar("Symbol.IntlLegacyConstructedSymbol")); + SetNoneAttributeProperty(intl_object, "fallbackSymbol", init_intl_symbol); - SetFunction(env, intlObject, "getCanonicalLocales", Intl::GetCanonicalLocales, FunctionLength::ONE); + SetFunction(env, intl_object, "getCanonicalLocales", Intl::GetCanonicalLocales, FunctionLength::ONE); // initial value of the "Intl" property of the global object. - JSHandle intlString(factory_->NewFromString("Intl")); - JSHandle globalObject(thread_, env->GetGlobalObject()); - PropertyDescriptor intlDesc(thread_, JSHandle::Cast(intlObject), true, false, true); - JSObject::DefineOwnProperty(thread_, globalObject, intlString, intlDesc); + JSHandle intl_string(factory_->NewFromString("Intl")); + JSHandle global_object(thread_, env->GetGlobalObject()); + PropertyDescriptor intl_desc(thread_, JSHandle::Cast(intl_object), true, false, true); + JSObject::DefineOwnProperty(thread_, global_object, intl_string, intl_desc); - SetStringTagSymbol(env, intlObject, "Intl"); + SetStringTagSymbol(env, intl_object, "Intl"); - env->SetIntlFunction(thread_, intlObject); + env->SetIntlFunction(thread_, intl_object); } void Builtins::InitializeDateTimeFormat(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // DateTimeFormat.prototype - JSHandle objFun = env->GetObjectFunction(); - JSHandle dtfPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle dtfPrototypeValue(dtfPrototype); + JSHandle obj_fun = env->GetObjectFunction(); + JSHandle dtf_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle dtf_prototype_value(dtf_prototype); // DateTimeFormat.prototype_or_dynclass - JSHandle dtfFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_DATE_TIME_FORMAT, dtfPrototypeValue); + JSHandle dtf_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_DATE_TIME_FORMAT, dtf_prototype_value); // DateTimeFormat = new Function() // 13.4.1 Intl.DateTimeFormat.prototype.constructor - JSHandle dtfFunction(NewIntlConstructor(env, dtfPrototype, DateTimeFormat::DateTimeFormatConstructor, - "DateTimeFormat", FunctionLength::ZERO)); - JSHandle(dtfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*dtfFuncInstanceDynclass)); + JSHandle dtf_function(NewIntlConstructor(env, dtf_prototype, DateTimeFormat::DateTimeFormatConstructor, + "DateTimeFormat", FunctionLength::ZERO)); + JSHandle(dtf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*dtf_func_instance_dynclass)); // 13.3.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, dtfFunction, "supportedLocalesOf", DateTimeFormat::SupportedLocalesOf, FunctionLength::ONE); + SetFunction(env, dtf_function, "supportedLocalesOf", DateTimeFormat::SupportedLocalesOf, FunctionLength::ONE); // DateTimeFormat.prototype method // 13.4.2 Intl.DateTimeFormat.prototype [ @@toStringTag ] - SetStringTagSymbol(env, dtfPrototype, "Intl.DateTimeFormat"); - env->SetDateTimeFormatFunction(thread_, dtfFunction); + SetStringTagSymbol(env, dtf_prototype, "Intl.DateTimeFormat"); + env->SetDateTimeFormatFunction(thread_, dtf_function); // 13.4.3 get Intl.DateTimeFormat.prototype.format - JSHandle formatGetter = CreateGetter(env, DateTimeFormat::Format, "format", FunctionLength::ZERO); - JSHandle formatSetter(thread_, JSTaggedValue::Undefined()); - SetAccessor(dtfPrototype, thread_->GlobalConstants()->GetHandledFormatString(), formatGetter, formatSetter); + 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, dtfPrototype, "formatToParts", DateTimeFormat::FormatToParts, FunctionLength::ONE); + SetFunction(env, dtf_prototype, "formatToParts", DateTimeFormat::FormatToParts, FunctionLength::ONE); // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () - SetFunction(env, dtfPrototype, "resolvedOptions", DateTimeFormat::ResolvedOptions, FunctionLength::ZERO); + SetFunction(env, dtf_prototype, "resolvedOptions", DateTimeFormat::ResolvedOptions, FunctionLength::ZERO); - SetFunction(env, dtfPrototype, "formatRange", DateTimeFormat::FormatRange, FunctionLength::TWO); + SetFunction(env, dtf_prototype, "formatRange", DateTimeFormat::FormatRange, FunctionLength::TWO); - SetFunction(env, dtfPrototype, "formatRangeToParts", DateTimeFormat::FormatRangeToParts, FunctionLength::TWO); + SetFunction(env, dtf_prototype, "formatRangeToParts", DateTimeFormat::FormatRangeToParts, FunctionLength::TWO); } void Builtins::InitializeRelativeTimeFormat(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // RelativeTimeFormat.prototype - JSHandle objFun = env->GetObjectFunction(); - JSHandle rtfPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle rtfPrototypeValue(rtfPrototype); + JSHandle obj_fun = env->GetObjectFunction(); + JSHandle rtf_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle rtf_prototype_value(rtf_prototype); // RelativeTimeFormat.prototype_or_dynclass - JSHandle rtfFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_RELATIVE_TIME_FORMAT, rtfPrototypeValue); + JSHandle rtf_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_RELATIVE_TIME_FORMAT, rtf_prototype_value); // RelativeTimeFormat = new Function() // 14.2.1 Intl.RelativeTimeFormat.prototype.constructor - JSHandle rtfFunction(NewIntlConstructor(env, rtfPrototype, - RelativeTimeFormat::RelativeTimeFormatConstructor, - "RelativeTimeFormat", FunctionLength::ZERO)); - JSHandle(rtfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*rtfFuncInstanceDynclass)); + JSHandle rtf_function(NewIntlConstructor(env, rtf_prototype, + RelativeTimeFormat::RelativeTimeFormatConstructor, + "RelativeTimeFormat", FunctionLength::ZERO)); + JSHandle(rtf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*rtf_func_instance_dynclass)); // 14.3.2 Intl.RelativeTimeFormat.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, rtfFunction, "supportedLocalesOf", RelativeTimeFormat::SupportedLocalesOf, FunctionLength::ONE); + SetFunction(env, rtf_function, "supportedLocalesOf", RelativeTimeFormat::SupportedLocalesOf, FunctionLength::ONE); // RelativeTimeFormat.prototype method // 14.4.2 Intl.RelativeTimeFormat.prototype [ @@toStringTag ] - SetStringTagSymbol(env, rtfPrototype, "Intl.RelativeTimeFormat"); - env->SetRelativeTimeFormatFunction(thread_, rtfFunction); + SetStringTagSymbol(env, rtf_prototype, "Intl.RelativeTimeFormat"); + env->SetRelativeTimeFormatFunction(thread_, rtf_function); // 14.4.3 get Intl.RelativeTimeFormat.prototype.format - SetFunction(env, rtfPrototype, "format", RelativeTimeFormat::Format, FunctionLength::TWO); + SetFunction(env, rtf_prototype, "format", RelativeTimeFormat::Format, FunctionLength::TWO); // 14.4.4 Intl.RelativeTimeFormat.prototype.formatToParts( value, unit ) - SetFunction(env, rtfPrototype, "formatToParts", RelativeTimeFormat::FormatToParts, FunctionLength::TWO); + SetFunction(env, rtf_prototype, "formatToParts", RelativeTimeFormat::FormatToParts, FunctionLength::TWO); // 14.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions () - SetFunction(env, rtfPrototype, "resolvedOptions", RelativeTimeFormat::ResolvedOptions, FunctionLength::ZERO); + SetFunction(env, rtf_prototype, "resolvedOptions", RelativeTimeFormat::ResolvedOptions, FunctionLength::ZERO); } void Builtins::InitializeNumberFormat(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // NumberFormat.prototype - JSHandle objFun = env->GetObjectFunction(); - JSHandle nfPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle nfPrototypeValue(nfPrototype); + JSHandle obj_fun = env->GetObjectFunction(); + JSHandle nf_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle nf_prototype_value(nf_prototype); // NumberFormat.prototype_or_dynclass - JSHandle nfFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_NUMBER_FORMAT, nfPrototypeValue); + JSHandle nf_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_NUMBER_FORMAT, nf_prototype_value); // NumberFormat = new Function() // 12.4.1 Intl.NumberFormat.prototype.constructor - JSHandle nfFunction(NewIntlConstructor(env, nfPrototype, NumberFormat::NumberFormatConstructor, - "NumberFormat", FunctionLength::ZERO)); - JSHandle(nfFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*nfFuncInstanceDynclass)); + JSHandle nf_function(NewIntlConstructor(env, nf_prototype, NumberFormat::NumberFormatConstructor, + "NumberFormat", FunctionLength::ZERO)); + JSHandle(nf_function)->SetFunctionPrototype(thread_, JSTaggedValue(*nf_func_instance_dynclass)); // 12.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, nfFunction, "supportedLocalesOf", NumberFormat::SupportedLocalesOf, FunctionLength::ONE); + SetFunction(env, nf_function, "supportedLocalesOf", NumberFormat::SupportedLocalesOf, FunctionLength::ONE); // NumberFormat.prototype method // 12.4.2 Intl.NumberFormat.prototype [ @@toStringTag ] - SetStringTagSymbol(env, nfPrototype, "Intl.NumberFormat"); - env->SetNumberFormatFunction(thread_, nfFunction); + SetStringTagSymbol(env, nf_prototype, "Intl.NumberFormat"); + env->SetNumberFormatFunction(thread_, nf_function); // 12.4.3 get Intl.NumberFormat.prototype.format - JSHandle formatGetter = CreateGetter(env, NumberFormat::Format, "format", FunctionLength::ZERO); - JSHandle formatSetter(thread_, JSTaggedValue::Undefined()); - SetAccessor(nfPrototype, thread_->GlobalConstants()->GetHandledFormatString(), formatGetter, formatSetter); + 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, nfPrototype, "formatToParts", NumberFormat::FormatToParts, FunctionLength::ONE); + SetFunction(env, nf_prototype, "formatToParts", NumberFormat::FormatToParts, FunctionLength::ONE); // 12.4.5 Intl.NumberFormat.prototype.resolvedOptions () - SetFunction(env, nfPrototype, "resolvedOptions", NumberFormat::ResolvedOptions, FunctionLength::ZERO); + SetFunction(env, nf_prototype, "resolvedOptions", NumberFormat::ResolvedOptions, FunctionLength::ZERO); } void Builtins::InitializeLocale(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Locale.prototype - JSHandle objFun = env->GetObjectFunction(); - JSHandle localePrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle localePrototypeValue(localePrototype); + JSHandle obj_fun = env->GetObjectFunction(); + JSHandle locale_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle locale_prototype_value(locale_prototype); // Locale.prototype_or_dynclass - JSHandle localeFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_LOCALE, localePrototypeValue); + JSHandle locale_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_LOCALE, locale_prototype_value); // Locale = new Function() - JSHandle localeFunction( - NewIntlConstructor(env, localePrototype, Locale::LocaleConstructor, "Locale", FunctionLength::ONE)); - JSHandle(localeFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*localeFuncInstanceDynclass)); + JSHandle locale_function( + NewIntlConstructor(env, locale_prototype, Locale::LocaleConstructor, "Locale", FunctionLength::ONE)); + JSHandle(locale_function)->SetFunctionPrototype(thread_, JSTaggedValue(*locale_func_instance_dynclass)); // Locale.prototype method - SetFunction(env, localePrototype, "maximize", Locale::Maximize, FunctionLength::ZERO); - SetFunction(env, localePrototype, "minimize", Locale::Minimize, FunctionLength::ZERO); - SetFunction(env, localePrototype, "toString", Locale::ToString, FunctionLength::ZERO); + 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 baseNameGetter = CreateGetter(env, Locale::GetBaseName, "baseName", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledBaseNameString(), baseNameGetter); + JSHandle base_name_getter = CreateGetter(env, Locale::GetBaseName, "baseName", FunctionLength::ZERO); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledBaseNameString(), base_name_getter); - JSHandle calendarGetter = CreateGetter(env, Locale::GetCalendar, "calendar", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledCalendarString(), calendarGetter); + JSHandle calendar_getter = CreateGetter(env, Locale::GetCalendar, "calendar", FunctionLength::ZERO); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledCalendarString(), calendar_getter); - JSHandle caseFirstGetter = + JSHandle case_first_getter = CreateGetter(env, Locale::GetCaseFirst, "caseFirst", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledCaseFirstString(), caseFirstGetter); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledCaseFirstString(), case_first_getter); - JSHandle collationGetter = + JSHandle collation_getter = CreateGetter(env, Locale::GetCollation, "collation", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledCollationString(), collationGetter); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledCollationString(), collation_getter); - JSHandle hourCycleGetter = + JSHandle hour_cycle_getter = CreateGetter(env, Locale::GetHourCycle, "hourCycle", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledHourCycleString(), hourCycleGetter); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledHourCycleString(), hour_cycle_getter); - JSHandle numericGetter = CreateGetter(env, Locale::GetNumeric, "numeric", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledNumericString(), numericGetter); + JSHandle numeric_getter = CreateGetter(env, Locale::GetNumeric, "numeric", FunctionLength::ZERO); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledNumericString(), numeric_getter); - JSHandle numberingSystemGetter = + JSHandle numbering_system_getter = CreateGetter(env, Locale::GetNumberingSystem, "numberingSystem", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledNumberingSystemString(), numberingSystemGetter); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledNumberingSystemString(), numbering_system_getter); - JSHandle languageGetter = CreateGetter(env, Locale::GetLanguage, "language", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledLanguageString(), languageGetter); + JSHandle language_getter = CreateGetter(env, Locale::GetLanguage, "language", FunctionLength::ZERO); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledLanguageString(), language_getter); - JSHandle scriptGetter = CreateGetter(env, Locale::GetScript, "script", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledScriptString(), scriptGetter); + JSHandle script_getter = CreateGetter(env, Locale::GetScript, "script", FunctionLength::ZERO); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledScriptString(), script_getter); - JSHandle regionGetter = CreateGetter(env, Locale::GetRegion, "region", FunctionLength::ZERO); - SetGetter(localePrototype, thread_->GlobalConstants()->GetHandledRegionString(), regionGetter); + JSHandle region_getter = CreateGetter(env, Locale::GetRegion, "region", FunctionLength::ZERO); + SetGetter(locale_prototype, thread_->GlobalConstants()->GetHandledRegionString(), region_getter); // 10.3.2 Intl.Locale.prototype[ @@toStringTag ] - SetStringTagSymbol(env, localePrototype, "Intl.Locale"); - env->SetLocaleFunction(thread_, localeFunction); + SetStringTagSymbol(env, locale_prototype, "Intl.Locale"); + env->SetLocaleFunction(thread_, locale_function); } void Builtins::InitializeCollator(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // Collator.prototype - JSHandle objFun = env->GetObjectFunction(); - JSHandle collatorPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle collatorPrototypeValue(collatorPrototype); + JSHandle obj_fun = env->GetObjectFunction(); + JSHandle collator_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle collator_prototype_value(collator_prototype); // Collator.prototype_or_dynclass - JSHandle collatorFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_COLLATOR, collatorPrototypeValue); + JSHandle collator_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_COLLATOR, collator_prototype_value); // Collator = new Function() // 11.1.2 Intl.Collator.prototype.constructor - JSHandle collatorFunction( - NewIntlConstructor(env, collatorPrototype, Collator::CollatorConstructor, "Collator", FunctionLength::ZERO)); - JSHandle(collatorFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*collatorFuncInstanceDynclass)); + JSHandle collator_function( + 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, collatorFunction, "supportedLocalesOf", Collator::SupportedLocalesOf, FunctionLength::ONE); + SetFunction(env, collator_function, "supportedLocalesOf", Collator::SupportedLocalesOf, FunctionLength::ONE); // Collator.prototype method // 11.3.2 Intl.Collator.prototype [ @@toStringTag ] - SetStringTagSymbol(env, collatorPrototype, "Intl.Collator"); - env->SetCollatorFunction(thread_, collatorFunction); + SetStringTagSymbol(env, collator_prototype, "Intl.Collator"); + env->SetCollatorFunction(thread_, collator_function); // 11.3.3 get Intl.Collator.prototype.compare - JSHandle compareGetter = CreateGetter(env, Collator::Compare, "compare", FunctionLength::ZERO); - JSHandle compareSetter(thread_, JSTaggedValue::Undefined()); - SetAccessor(collatorPrototype, thread_->GlobalConstants()->GetHandledCompareString(), compareGetter, compareSetter); + 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, collatorPrototype, "resolvedOptions", Collator::ResolvedOptions, FunctionLength::ZERO); + SetFunction(env, collator_prototype, "resolvedOptions", Collator::ResolvedOptions, FunctionLength::ZERO); } void Builtins::InitializePluralRules(const JSHandle &env) { [[maybe_unused]] EcmaHandleScope scope(thread_); // PluralRules.prototype - JSHandle objFun(env->GetObjectFunction()); - JSHandle prPrototype = factory_->NewJSObjectByConstructor(JSHandle(objFun), objFun); - JSHandle prPrototypeValue(prPrototype); + JSHandle obj_fun(env->GetObjectFunction()); + JSHandle pr_prototype = factory_->NewJSObjectByConstructor(JSHandle(obj_fun), obj_fun); + JSHandle pr_prototype_value(pr_prototype); // PluralRules.prototype_or_dynclass - JSHandle prFuncInstanceDynclass = - factory_->CreateDynClass(JSType::JS_PLURAL_RULES, prPrototypeValue); + JSHandle pr_func_instance_dynclass = + factory_->CreateDynClass(JSType::JS_PLURAL_RULES, pr_prototype_value); // PluralRules = new Function() // 15.2.1 Intl.PluralRules.prototype.constructor - JSHandle prFunction( - NewIntlConstructor(env, prPrototype, PluralRules::PluralRulesConstructor, "PluralRules", FunctionLength::ZERO)); - JSHandle(prFunction)->SetFunctionPrototype(thread_, JSTaggedValue(*prFuncInstanceDynclass)); + JSHandle pr_function(NewIntlConstructor(env, pr_prototype, PluralRules::PluralRulesConstructor, + "PluralRules", FunctionLength::ZERO)); + JSHandle(pr_function)->SetFunctionPrototype(thread_, JSTaggedValue(*pr_func_instance_dynclass)); // 15.3.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] ) - SetFunction(env, prFunction, "supportedLocalesOf", PluralRules::SupportedLocalesOf, FunctionLength::ONE); + SetFunction(env, pr_function, "supportedLocalesOf", PluralRules::SupportedLocalesOf, FunctionLength::ONE); // PluralRules.prototype method // 15.4.2 Intl.PluralRules.prototype [ @@toStringTag ] - SetStringTagSymbol(env, prPrototype, "Intl.PluralRules"); - env->SetPluralRulesFunction(thread_, prFunction); + SetStringTagSymbol(env, pr_prototype, "Intl.PluralRules"); + env->SetPluralRulesFunction(thread_, pr_function); // 15.4.3 get Intl.PluralRules.prototype.select - SetFunction(env, prPrototype, "select", PluralRules::Select, FunctionLength::ONE); + SetFunction(env, pr_prototype, "select", PluralRules::Select, FunctionLength::ONE); // 15.4.5 Intl.PluralRules.prototype.resolvedOptions () - SetFunction(env, prPrototype, "resolvedOptions", PluralRules::ResolvedOptions, FunctionLength::ZERO); + SetFunction(env, pr_prototype, "resolvedOptions", PluralRules::ResolvedOptions, FunctionLength::ZERO); } void Builtins::InitializeGcMarker(const JSHandle &env) const @@ -3143,23 +3187,25 @@ JSHandle Builtins::InitializeArkTools(const JSHandle &env) JSHandle Builtins::InitializeArkPrivate(const JSHandle &env) const { - JSHandle arkPrivate = factory_->NewEmptyJSObject(); - SetFrozenFunction(env, arkPrivate, "Load", ContainersPrivate::Load, FunctionLength::ZERO); - SetConstant(arkPrivate, "ArrayList", JSTaggedValue(static_cast(containers::ContainerTag::ArrayList))); - SetConstant(arkPrivate, "Queue", JSTaggedValue(static_cast(containers::ContainerTag::Queue))); - SetConstant(arkPrivate, "Deque", JSTaggedValue(static_cast(containers::ContainerTag::Deque))); - SetConstant(arkPrivate, "Stack", JSTaggedValue(static_cast(containers::ContainerTag::Stack))); - SetConstant(arkPrivate, "Vector", JSTaggedValue(static_cast(containers::ContainerTag::Vector))); - SetConstant(arkPrivate, "List", JSTaggedValue(static_cast(containers::ContainerTag::List))); - SetConstant(arkPrivate, "LinkedList", JSTaggedValue(static_cast(containers::ContainerTag::LinkedList))); - SetConstant(arkPrivate, "TreeMap", JSTaggedValue(static_cast(containers::ContainerTag::TreeMap))); - SetConstant(arkPrivate, "TreeSet", JSTaggedValue(static_cast(containers::ContainerTag::TreeSet))); - SetConstant(arkPrivate, "HashMap", JSTaggedValue(static_cast(containers::ContainerTag::HashMap))); - SetConstant(arkPrivate, "HashSet", JSTaggedValue(static_cast(containers::ContainerTag::HashSet))); - SetConstant(arkPrivate, "LightWightMap", JSTaggedValue(static_cast(containers::ContainerTag::LightWightMap))); - SetConstant(arkPrivate, "LightWightSet", JSTaggedValue(static_cast(containers::ContainerTag::LightWightSet))); - SetConstant(arkPrivate, "PlainArray", JSTaggedValue(static_cast(containers::ContainerTag::PlainArray))); - return arkPrivate; + JSHandle ark_private = factory_->NewEmptyJSObject(); + SetFrozenFunction(env, ark_private, "Load", ContainersPrivate::Load, FunctionLength::ZERO); + SetConstant(ark_private, "ArrayList", JSTaggedValue(static_cast(containers::ContainerTag::ARRAY_LIST))); + SetConstant(ark_private, "Queue", JSTaggedValue(static_cast(containers::ContainerTag::QUEUE))); + SetConstant(ark_private, "Deque", JSTaggedValue(static_cast(containers::ContainerTag::DEQUE))); + SetConstant(ark_private, "Stack", JSTaggedValue(static_cast(containers::ContainerTag::STACK))); + SetConstant(ark_private, "Vector", JSTaggedValue(static_cast(containers::ContainerTag::VECTOR))); + SetConstant(ark_private, "List", JSTaggedValue(static_cast(containers::ContainerTag::LIST))); + SetConstant(ark_private, "LinkedList", JSTaggedValue(static_cast(containers::ContainerTag::LINKED_LIST))); + SetConstant(ark_private, "TreeMap", JSTaggedValue(static_cast(containers::ContainerTag::TREE_MAP))); + SetConstant(ark_private, "TreeSet", JSTaggedValue(static_cast(containers::ContainerTag::TREE_SET))); + SetConstant(ark_private, "HashMap", JSTaggedValue(static_cast(containers::ContainerTag::HASH_MAP))); + SetConstant(ark_private, "HashSet", JSTaggedValue(static_cast(containers::ContainerTag::HASH_SET))); + SetConstant(ark_private, "LightWightMap", + JSTaggedValue(static_cast(containers::ContainerTag::LIGHT_WIGHT_MAP))); + SetConstant(ark_private, "LightWightSet", + JSTaggedValue(static_cast(containers::ContainerTag::LIGHT_WIGHT_SET))); + SetConstant(ark_private, "PlainArray", JSTaggedValue(static_cast(containers::ContainerTag::PLAIN_ARRAY))); + return ark_private; } #ifdef FUZZING_FUZZILLI_BUILTIN diff --git a/runtime/builtins.h b/runtime/builtins.h index c647f27db31d10ec0ca66c1b55b383d6d0c5b2ad..53a108aebae30415ac2be56622435690ba131a2d 100644 --- a/runtime/builtins.h +++ b/runtime/builtins.h @@ -26,10 +26,10 @@ namespace panda::ecmascript { struct ErrorParameter { - EcmaEntrypoint nativeConstructor {nullptr}; - EcmaEntrypoint nativeMethod {nullptr}; - const char *nativePropertyName {nullptr}; - JSType nativeJstype {JSType::INVALID}; + EcmaEntrypoint native_constructor {nullptr}; + EcmaEntrypoint native_method {nullptr}; + const char *native_property_name {nullptr}; + JSType native_jstype {JSType::INVALID}; }; enum FunctionLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR }; @@ -49,7 +49,7 @@ private: EcmaVM *vm_ {nullptr}; JSHandle NewBuiltinConstructor(const JSHandle &env, const JSHandle &prototype, - EcmaEntrypoint ctorFunc, const char *name, int length) const; + EcmaEntrypoint ctor_func, const char *name, int length) const; JSHandle NewFunction(const JSHandle &env, const JSHandle &key, EcmaEntrypoint func, int length) const; @@ -57,69 +57,70 @@ private: void InitializeCtor(const JSHandle &env, const JSHandle &prototype, const JSHandle &ctor, const char *name, int length) const; - void InitializeGlobalObject(const JSHandle &env, const JSHandle &globalObject); + void InitializeGlobalObject(const JSHandle &env, const JSHandle &global_object); - void InitializeFunction(const JSHandle &env, const JSHandle &emptyFuncDynclass) const; + void InitializeFunction(const JSHandle &env, const JSHandle &empty_func_dynclass) const; - void InitializeObject(const JSHandle &env, const JSHandle &objFuncPrototype, - const JSHandle &objFunc); + void InitializeObject(const JSHandle &env, const JSHandle &obj_func_prototype, + const JSHandle &obj_func); - void InitializeNumber(const JSHandle &env, const JSHandle &globalObject, - const JSHandle &primRefObjDynclass); + void InitializeNumber(const JSHandle &env, const JSHandle &global_object, + const JSHandle &prim_ref_obj_dynclass); - void InitializeBigInt(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeBigInt(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeDate(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeDate(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeBoolean(const JSHandle &env, const JSHandle &primRefObjDynclass) const; + void InitializeBoolean(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const; - void InitializeSymbol(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeSymbol(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeSymbolWithRealm(const JSHandle &realm, const JSHandle &objFuncInstanceDynclass); + void InitializeSymbolWithRealm(const JSHandle &realm, + const JSHandle &obj_func_instance_dynclass); - void InitializeArray(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; + void InitializeArray(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; - void InitializeTypedArray(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeTypedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeInt8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeInt8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeUint8Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeUint8Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeUint8ClampedArray(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeUint8ClampedArray(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeInt16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeInt16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeUint16Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeUint16Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeInt32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeInt32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeUint32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeUint32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeFloat32Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeFloat32Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeFloat64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeFloat64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeBigInt64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeBigInt64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeBigUint64Array(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeBigUint64Array(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeAllTypeError(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeAllTypeError(const JSHandle &env, const JSHandle &obj_func_dynclass) const; void InitializeAllTypeErrorWithRealm(const JSHandle &realm) const; - void InitializeError(const JSHandle &env, const JSHandle &objFuncDynclass, - const JSType &errorTag) const; + void InitializeError(const JSHandle &env, const JSHandle &obj_func_dynclass, + const JSType &error_tag) const; - void SetErrorWithRealm(const JSHandle &realm, const JSType &errorTag) const; + void SetErrorWithRealm(const JSHandle &realm, const JSType &error_tag) const; void InitializeRegExp(const JSHandle &env); // for Intl. JSHandle NewIntlConstructor(const JSHandle &env, const JSHandle &prototype, - EcmaEntrypoint ctorFunc, const char *name, int length); + EcmaEntrypoint ctor_func, const char *name, int length); void InitializeIntlCtor(const JSHandle &env, const JSHandle &prototype, const JSHandle &ctor, const char *name, int length); - void InitializeIntl(const JSHandle &env, const JSHandle &objFuncPrototypeValue); + void InitializeIntl(const JSHandle &env, const JSHandle &obj_func_prototype_value); void InitializeLocale(const JSHandle &env); void InitializeDateTimeFormat(const JSHandle &env); void InitializeRelativeTimeFormat(const JSHandle &env); @@ -130,69 +131,72 @@ private: void GeneralUpdateError(ErrorParameter *error, EcmaEntrypoint constructor, EcmaEntrypoint method, const char *name, JSType type) const; - void InitializeSet(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeMap(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeWeakRef(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeWeakRef(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeWeakMap(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeWeakMap(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeWeakSet(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeWeakSet(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeMath(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; + void InitializeMath(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; - void InitializeJson(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; + void InitializeJson(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; - void InitializeString(const JSHandle &env, const JSHandle &primRefObjDynclass) const; + void InitializeString(const JSHandle &env, const JSHandle &prim_ref_obj_dynclass) const; - void InitializeIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeAsyncIterator(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeAsyncIterator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeStringIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; + void InitializeStringIterator(const JSHandle &env, + const JSHandle &iterator_func_dynclass) const; - void InitializeForinIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; + void InitializeForinIterator(const JSHandle &env, + const JSHandle &iterator_func_dynclass) const; - void InitializeMapIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; + void InitializeMapIterator(const JSHandle &env, const JSHandle &iterator_func_dynclass) const; - void InitializeSetIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; + void InitializeSetIterator(const JSHandle &env, const JSHandle &iterator_func_dynclass) const; - void InitializeArrayIterator(const JSHandle &env, const JSHandle &iteratorFuncDynclass) const; + void InitializeArrayIterator(const JSHandle &env, + const JSHandle &iterator_func_dynclass) const; - void InitializeRegexpIterator(const JSHandle &env, const JSHandle &iteratorFuncClass) const; + void InitializeRegexpIterator(const JSHandle &env, const JSHandle &iterator_func_class) const; - void InitializeArrayBuffer(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeArrayBuffer(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeDataView(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeDataView(const JSHandle &env, const JSHandle &obj_func_dynclass) const; void InitializeProxy(const JSHandle &env); - void InitializeReflect(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; + void InitializeReflect(const JSHandle &env, const JSHandle &obj_func_prototype_val) const; - void InitializeAsyncFunction(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeAsyncFunction(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeGeneratorFunction(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeGeneratorFunction(const JSHandle &env, const JSHandle &obj_func_dynclass) const; - void InitializeGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeGenerator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; void InitializeAsyncGeneratorFunction(const JSHandle &env, - const JSHandle &objFuncDynclass) const; + const JSHandle &obj_func_dynclass) const; - void InitializeAsyncGenerator(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeAsyncGenerator(const JSHandle &env, const JSHandle &obj_func_dynclass) const; void InitializeAsyncFromSyncIteratorPrototypeObject(const JSHandle &env, - const JSHandle &objFuncDynclass) const; + const JSHandle &obj_func_dynclass) const; - JSHandle InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctorFunc, + JSHandle InitializeExoticConstructor(const JSHandle &env, EcmaEntrypoint ctor_func, const char *name, int length); - void InitializePromise(const JSHandle &env, const JSHandle &promiseFuncDynclass); + void InitializePromise(const JSHandle &env, const JSHandle &promise_func_dynclass); void InitializePromiseJob(const JSHandle &env); void InitializeFinalizationRegistry(const JSHandle &env, - const JSHandle &objFuncDynclass) const; + const JSHandle &obj_func_dynclass) const; void SetFunction(const JSHandle &env, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length) const; @@ -200,10 +204,10 @@ private: void SetFunction(const JSHandle &env, const JSHandle &obj, const JSHandle &key, EcmaEntrypoint func, int length) const; - void SetFuncToObjAndGlobal(const JSHandle &env, const JSHandle &globalObject, + void SetFuncToObjAndGlobal(const JSHandle &env, const JSHandle &global_object, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length); - template + template void SetFunctionAtSymbol(const JSHandle &env, const JSHandle &obj, const JSHandle &symbol, const char *name, EcmaEntrypoint func, int length) const; @@ -214,7 +218,7 @@ private: void SetConstant(const JSHandle &obj, const char *key, JSTaggedValue value) const; - void SetGlobalThis(const JSHandle &obj, const char *key, const JSHandle &globalValue); + void SetGlobalThis(const JSHandle &obj, const char *key, const JSHandle &global_value); void SetAttribute(const JSHandle &obj, const char *key, const char *value) const; diff --git a/runtime/builtins/builtins_ark_tools.cpp b/runtime/builtins/builtins_ark_tools.cpp index d0b7563fde38fcc5fedafb8f69e38728fef09d39..d9d1a365b362415669565487ea06beba0f308069 100644 --- a/runtime/builtins/builtins_ark_tools.cpp +++ b/runtime/builtins/builtins_ark_tools.cpp @@ -23,14 +23,14 @@ JSTaggedValue BuiltinsArkTools::ObjectDump(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); // The default log level of ace_engine and js_runtime is error LOG(ERROR, RUNTIME) << ": " << base::StringHelper::ToStdString(*str); - uint32_t numArgs = msg->GetArgsNumber(); - for (uint32_t i = 1; i < numArgs; i++) { + uint32_t num_args = msg->GetArgsNumber(); + for (uint32_t i = 1; i < num_args; i++) { JSHandle obj = GetCallArg(msg, i); std::ostringstream oss; obj->Dump(thread, oss); diff --git a/runtime/builtins/builtins_array.cpp b/runtime/builtins/builtins_array.cpp index 230a4abc1059d50a3fab70f062b49445db0ab3cf..5066515fec23d5ba97f7631ee5da562e4b3e97d3 100644 --- a/runtime/builtins/builtins_array.cpp +++ b/runtime/builtins/builtins_array.cpp @@ -45,7 +45,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let numberOfArgs be the number of arguments passed to this function call. @@ -71,8 +71,8 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 22.1.1.2 Array(len) if (argc == 1) { // 6. Let array be ArrayCreate(0, proto). - uint32_t newLen = 0; - JSHandle newArrayHandle(JSArray::ArrayCreate(thread, JSTaggedNumber(newLen), new_target)); + uint32_t new_len = 0; + JSHandle new_array_handle(JSArray::ArrayCreate(thread, JSTaggedNumber(new_len), new_target)); JSHandle len = GetCallArg(argv, 0); // 7. If Type(len) is not Number, then // a. Let defineStatus be CreateDataProperty(array, "0", len). @@ -85,25 +85,25 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) // 10. Assert: setStatus is not an abrupt completion. if (!len->IsNumber()) { JSHandle key0(factory->NewFromCanBeCompressString("0")); - JSObject::CreateDataProperty(thread, newArrayHandle, key0, len); - newLen = 1; + JSObject::CreateDataProperty(thread, new_array_handle, key0, len); + new_len = 1; } else { - newLen = JSTaggedValue::ToUint32(thread, len); + new_len = JSTaggedValue::ToUint32(thread, len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedNumber(len.GetTaggedValue()).GetNumber() != newLen) { + if (JSTaggedNumber(len.GetTaggedValue()).GetNumber() != new_len) { THROW_RANGE_ERROR_AND_RETURN(thread, "The length is out of range.", JSTaggedValue::Exception()); } } - JSArray::Cast(*newArrayHandle)->SetArrayLength(thread, newLen); + JSArray::Cast(*new_array_handle)->SetArrayLength(thread, new_len); // 11. Return array. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.1.3 Array(...items ) - JSTaggedValue newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(argc), new_target).GetTaggedValue(); - JSHandle newArrayHandle(thread, newArray); - if (!newArray.IsArray(thread)) { + JSTaggedValue new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(argc), new_target).GetTaggedValue(); + JSHandle new_array_handle(thread, new_array); + if (!new_array.IsArray(thread)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to create array.", JSTaggedValue::Exception()); } @@ -118,14 +118,14 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); - JSHandle itemK = GetCallArg(argv, k); - JSObject::CreateDataProperty(thread, newArrayHandle, key, itemK); + JSHandle item_k = GetCallArg(argv, k); + JSObject::CreateDataProperty(thread, new_array_handle, key, item_k); } // 11. Assert: the value of array’s length property is numberOfArgs. // 12. Return array. - JSArray::Cast(*newArrayHandle)->SetArrayLength(thread, argc); - return newArrayHandle.GetTaggedValue(); + JSArray::Cast(*new_array_handle)->SetArrayLength(thread, argc); + return new_array_handle.GetTaggedValue(); } // 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] ) @@ -135,18 +135,18 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, From); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); // 1. Let C be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = 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 thisArgHandle = GetCallArg(argv, INDEX_TWO); + JSHandle this_arg_handle = GetCallArg(argv, INDEX_TWO); JSHandle mapfn = GetCallArg(argv, 1); if (!mapfn->IsUndefined()) { if (!mapfn->IsCallable()) { @@ -160,40 +160,40 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "The items is null.", JSTaggedValue::Exception()); } JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle iteratorSymbol = env->GetIteratorSymbol(); - JSHandle usingIterator = JSObject::GetMethod(thread, items, iteratorSymbol); + JSHandle iterator_symbol = env->GetIteratorSymbol(); + JSHandle using_iterator = JSObject::GetMethod(thread, items, iterator_symbol); // 5. ReturnIfAbrupt(usingIterator). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If usingIterator is not undefined, then - if (!usingIterator->IsUndefined()) { + if (!using_iterator->IsUndefined()) { // a. If IsConstructor(C) is true, then // i. Let A be Construct(C). // b. Else, // i. Let A be ArrayCreate(0). // c. ReturnIfAbrupt(A). - JSTaggedValue newArray; - if (thisHandle->IsConstructor()) { + JSTaggedValue new_array; + if (this_handle->IsConstructor()) { auto info = - NewRuntimeCallInfo(thread, thisHandle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); - newArray = JSFunction::Construct(info.get()); + NewRuntimeCallInfo(thread, this_handle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); + new_array = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue(); + new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (!newArray.IsECMAObject()) { + if (!new_array.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the array.", JSTaggedValue::Exception()); } - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // d. Let iterator be GetIterator(items, usingIterator). - JSHandle iterator = JSIterator::GetIterator(thread, items, usingIterator); + JSHandle iterator = JSIterator::GetIterator(thread, items, using_iterator); // e. ReturnIfAbrupt(iterator). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // f. Let k be 0. int k = 0; // g. Repeat JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); while (true) { key.Update(JSTaggedValue(k)); // i. Let Pk be ToString(k). @@ -206,12 +206,13 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(setStatus). // 3. Return A. if (next->IsFalse()) { - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, key, true); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, key, + true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return JSTaggedValue(newArrayHandle.GetTaggedValue()); + return JSTaggedValue(new_array_handle.GetTaggedValue()); } // v. Let nextValue be IteratorValue(next). - JSHandle nextValue = JSIterator::IteratorValue(thread, next); + JSHandle next_value = JSIterator::IteratorValue(thread, next); // vi. ReturnIfAbrupt(nextValue). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // vii. If mapping is true, then @@ -220,33 +221,33 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // 3. Let mappedValue be mappedValue.[[value]]. // viii. Else, let mappedValue be nextValue. if (mapping) { - auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(nextValue, key); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 2: two args - mapValue.Update(callResult); - JSTaggedValue mapResult = JSIterator::IteratorClose(thread, iterator, mapValue).GetTaggedValue(); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue(mapResult)); + auto info = NewRuntimeCallInfo(thread, mapfn, this_arg_handle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(next_value, key); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 2: two args + map_value.Update(call_result); + JSTaggedValue map_result = JSIterator::IteratorClose(thread, iterator, map_value).GetTaggedValue(); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue(map_result)); } else { - mapValue.Update(nextValue.GetTaggedValue()); + map_value.Update(next_value.GetTaggedValue()); } // ix. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue). // x. If defineStatus is an abrupt completion, return IteratorClose(iterator, defineStatus). // xi. Increase k by 1. - JSHandle defineStatus( - thread, JSTaggedValue(JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, key, mapValue))); - JSTaggedValue defineResult = JSIterator::IteratorClose(thread, iterator, defineStatus).GetTaggedValue(); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue(defineResult)); + JSHandle define_status( + thread, JSTaggedValue(JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, key, map_value))); + JSTaggedValue define_result = JSIterator::IteratorClose(thread, iterator, define_status).GetTaggedValue(); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue(define_result)); k++; } } // 7. Assert: items is not an Iterable so assume it is an array-like object. // 8. Let arrayLike be ToObject(items). - JSHandle arrayLikeObj = JSTaggedValue::ToObject(thread, items); + JSHandle array_like_obj = JSTaggedValue::ToObject(thread, items); // 9. ReturnIfAbrupt(arrayLike). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle arrayLike(arrayLikeObj); + JSHandle array_like(array_like_obj); // 10. Let len be ToLength(Get(arrayLike, "length")). - double len = ArrayHelper::GetArrayLength(thread, arrayLike); + double len = ArrayHelper::GetArrayLength(thread, array_like); // 11. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 12. If IsConstructor(C) is true, then @@ -254,20 +255,20 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // 13. Else, // a. Let A be ArrayCreate(len). // 14. ReturnIfAbrupt(A). - JSTaggedValue newArray; - if (thisHandle->IsConstructor()) { - auto info = NewRuntimeCallInfo(thread, thisHandle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); + JSTaggedValue new_array; + if (this_handle->IsConstructor()) { + auto info = NewRuntimeCallInfo(thread, this_handle, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); info->SetCallArgs(JSTaggedValue(len)); - newArray = JSFunction::Construct(info.get()); + new_array = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(len)).GetTaggedValue(); + new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(len)).GetTaggedValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (!newArray.IsECMAObject()) { + if (!new_array.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the array.", JSTaggedValue::Exception()); } - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // 15. Let k be 0. // 16. Repeat, while k < len // a. Let Pk be ToString(k). @@ -277,33 +278,33 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // e. Else, let mappedValue be kValue. // f. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue). JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, arrayLike, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, array_like, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (mapping) { key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(kValue, key); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, mapfn, this_arg_handle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(k_value, key); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - mapValue.Update(callResult); + map_value.Update(call_result); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - mapValue.Update(kValue.GetTaggedValue()); + map_value.Update(k_value.GetTaggedValue()); } - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, k, mapValue); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, k, map_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 17. Let setStatus be Set(A, "length", len, true). - JSHandle lenHandle(thread, JSTaggedValue(len)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, lenHandle, true); + JSHandle len_handle(thread, JSTaggedValue(len)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, len_handle, true); // 18. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 19. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.2.2 Array.isArray ( arg ) @@ -324,37 +325,37 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Of); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle lengthKey = globalConst->GetHandledLengthString(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + JSHandle length_key = global_const->GetHandledLengthString(); // 1. Let len be the actual number of arguments passed to this function. uint32_t argc = argv->GetArgsNumber(); // 3. Let C be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 4. If IsConstructor(C) is true, then // a. Let A be Construct(C, «len»). // 5. Else, // a. Let A be ArrayCreate(len). // 6. ReturnIfAbrupt(A). - JSHandle newArray; - if (thisHandle->IsConstructor()) { - JSHandle undefined = globalConst->GetHandledUndefined(); + JSHandle new_array; + if (this_handle->IsConstructor()) { + JSHandle undefined = global_const->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, thisHandle, JSTaggedValue::Undefined(), undefined, 1); + auto info = NewRuntimeCallInfo(thread, this_handle, JSTaggedValue::Undefined(), undefined, 1); info->SetCallArgs(JSTaggedValue(argc)); - JSTaggedValue taggedArray = JSFunction::Construct(info.get()); + JSTaggedValue tagged_array = JSFunction::Construct(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - newArray = JSHandle(thread, taggedArray); + new_array = JSHandle(thread, tagged_array); } else { - newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(argc)); + new_array = JSArray::ArrayCreate(thread, JSTaggedNumber(argc)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (!newArray->IsECMAObject()) { + if (!new_array->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to create Object.", JSTaggedValue::Exception()); } - JSHandle newArrayHandle(newArray); + JSHandle new_array_handle(new_array); // 7. Let k be 0. // 8. Repeat, while k < len @@ -366,16 +367,16 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); for (uint32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); - JSHandle kValue = GetCallArg(argv, k); - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, key, kValue); + JSHandle k_value = GetCallArg(argv, k); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, key, k_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 9. Let setStatus be Set(A, "length", len, true). - JSHandle lenHandle(thread, JSTaggedValue(argc)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, lenHandle, true); + JSHandle len_handle(thread, JSTaggedValue(argc)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, len_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.2.5 get Array [ @@species ] @@ -392,45 +393,46 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Concat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let A be ArraySpeciesCreate(O, 0). - uint32_t arrayLen = 0; - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen)); + uint32_t array_len = 0; + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(array_len)); // 4. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // 5. Let n be 0. double n = 0; - JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); - bool isSpreadable = ArrayHelper::IsConcatSpreadable(thread, thisHandle); + JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); + bool is_spreadable = ArrayHelper::IsConcatSpreadable(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (isSpreadable) { - double thisLen = ArrayHelper::GetArrayLength(thread, thisObjVal); + if (is_spreadable) { + double this_len = ArrayHelper::GetArrayLength(thread, this_obj_val); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (n + thisLen > ecmascript::base::MAX_SAFE_INTEGER) { + if (n + this_len > ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } double k = 0; - while (k < thisLen) { - fromKey.Update(JSTaggedValue(k)); - toKey.Update(JSTaggedValue(n)); - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); + while (k < this_len) { + from_key.Update(JSTaggedValue(k)); + to_key.Update(JSTaggedValue(n)); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); + JSHandle from_val_handle = + JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValHandle); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_val_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } n++; @@ -440,25 +442,25 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) if (n >= ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, n, thisObjVal); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, n, this_obj_val); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); n++; } // 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 addHandle = GetCallArg(argv, i); + JSHandle add_handle = GetCallArg(argv, i); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle addObjHandle(addHandle); + JSHandle add_obj_handle(add_handle); // b. Let spreadable be IsConcatSpreadable(E). - isSpreadable = ArrayHelper::IsConcatSpreadable(thread, addHandle); + is_spreadable = ArrayHelper::IsConcatSpreadable(thread, add_handle); // c. ReturnIfAbrupt(spreadable). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. If spreadable is true, then - if (isSpreadable) { + if (is_spreadable) { // ii. Let len be ToLength(Get(E, "length")). - double len = ArrayHelper::GetArrayLength(thread, JSHandle::Cast(addObjHandle)); + double len = ArrayHelper::GetArrayLength(thread, JSHandle::Cast(add_obj_handle)); // iii. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iv. If n + len > 253-1, throw a TypeError exception. @@ -468,19 +470,21 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) double k = 0; // v. Repeat, while k < len while (k < len) { - fromKey.Update(JSTaggedValue(k)); - toKey.Update(JSTaggedValue(n)); + from_key.Update(JSTaggedValue(k)); + to_key.Update(JSTaggedValue(n)); // 1. Let P be ToString(k). // 2. Let exists be HasProperty(E, P). // 4. If exists is true, then - bool exists = JSTaggedValue::HasProperty(thread, JSHandle::Cast(addObjHandle), fromKey); + bool exists = + JSTaggedValue::HasProperty(thread, JSHandle::Cast(add_obj_handle), from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { // a. Let subElement be Get(E, P). - JSHandle fromValHandle = JSArray::FastGetPropertyByValue(thread, addHandle, fromKey); + JSHandle from_val_handle = + JSArray::FastGetPropertyByValue(thread, add_handle, from_key); // b. ReturnIfAbrupt(subElement). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValHandle); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_val_handle); // d. ReturnIfAbrupt(status). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -495,7 +499,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } // ii. Let status be CreateDataPropertyOrThrow (A, ToString(n), E). - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, n, addHandle); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, n, add_handle); // iii. ReturnIfAbrupt(status). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -504,14 +508,14 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) } } // 8. Let setStatus be Set(A, "length", n, true). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle lenHandle(thread, JSTaggedValue(n)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, lenHandle, true); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle len_handle(thread, JSTaggedValue(n)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, len_handle, true); // 9. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) @@ -520,33 +524,33 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, CopyWithin); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, GetThis(argv)); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, GetThis(argv)); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double copyTo; - double copyFrom; - double copyEnd; + double copy_to; + double copy_from; + double copy_end; // 5. Let relativeTarget be ToInteger(target). - JSTaggedNumber targetTemp = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); + JSTaggedNumber target_temp = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); // 6. ReturnIfAbrupt(relativeTarget). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double target = targetTemp.GetNumber(); + double target = target_temp.GetNumber(); // 7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to be min(relativeTarget, len). if (target < 0) { - copyTo = target + len > 0 ? target + len : 0; + copy_to = target + len > 0 ? target + len : 0; } else { - copyTo = target < len ? target : len; + copy_to = target < len ? target : len; } // 8. Let relativeStart be ToInteger(start). @@ -556,9 +560,9 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) double start = start_t.GetNumber(); // 10. If relativeStart < 0, let from be max((len + relativeStart),0); else let from be min(relativeStart, len). if (start < 0) { - copyFrom = start + len > 0 ? start + len : 0; + copy_from = start + len > 0 ? start + len : 0; } else { - copyFrom = start < len ? start : len; + copy_from = start < len ? start : len; } // 11. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). @@ -573,13 +577,13 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) // 13. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). if (end < 0) { - copyEnd = end + len > 0 ? end + len : 0; + copy_end = end + len > 0 ? end + len : 0; } else { - copyEnd = end < len ? end : len; + copy_end = end < len ? end : len; } // 14. Let count be min(final-from, len-to). - double count = (copyEnd - copyFrom < len - copyTo) ? (copyEnd - copyFrom) : (len - copyTo); + double count = (copy_end - copy_from < len - copy_to) ? (copy_end - copy_from) : (len - copy_to); // 15. If from 0 @@ -610,32 +614,32 @@ JSTaggedValue BuiltinsArray::CopyWithin(EcmaRuntimeCallInfo *argv) // g. Let from be from + direction. // h. Let to be to + direction. // i. Let count be count − 1. - JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); while (count > 0) { - fromKey.Update(JSTaggedValue(copyFrom)); - toKey.Update(JSTaggedValue(copyTo)); - bool exists = (thisObjVal->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, fromKey)); + from_key.Update(JSTaggedValue(copy_from)); + to_key.Update(JSTaggedValue(copy_to)); + bool exists = (this_obj_val->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, from_key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); + JSHandle from_val_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValHandle); + JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_val_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - if (thisObjVal->IsJSProxy()) { - toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue()); + if (this_obj_val->IsJSProxy()) { + to_key.Update(JSTaggedValue::ToString(thread, to_key).GetTaggedValue()); } - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - copyFrom = copyFrom + direction; - copyTo = copyTo + direction; + copy_from = copy_from + direction; + copy_to = copy_to + direction; count--; } // 18. Return O. - return thisObjHandle.GetTaggedValue(); + return this_obj_handle.GetTaggedValue(); } // 22.1.3.4 Array.prototype.entries ( ) @@ -644,7 +648,7 @@ JSTaggedValue BuiltinsArray::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). @@ -660,28 +664,28 @@ JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -699,18 +703,18 @@ JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool boolResult = callResult.ToBoolean(); - if (!boolResult) { + bool bool_result = call_result.ToBoolean(); + if (!bool_result) { return GetTaggedBoolean(false); } } @@ -723,24 +727,24 @@ JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) // ES2019 22.1.3.10.1 FlattenIntoArray(target, source, sourceLen, start, depth, [, mapperFunction, thisArg]) static JSTaggedValue FlattenIntoArray(JSThread *thread, const JSHandle &target, - const JSHandle &source, double sourceLen, double start, - double depth, const JSHandle &mapperFunc, - const JSHandle &thisArg) + const JSHandle &source, double source_len, double start, + double depth, const JSHandle &mapper_func, + const JSHandle &this_arg) { - JSTaggedValue targetIdx(start); + JSTaggedValue target_idx(start); // 1. - 3. - for (uint32_t srcIdx = 0; srcIdx < sourceLen; ++srcIdx) { + for (uint32_t src_idx = 0; src_idx < source_len; ++src_idx) { // a. Let P be ! ToString(sourceIndex). JSTaggedValue prop = - JSTaggedValue::ToString(thread, JSHandle(thread, JSTaggedValue(srcIdx))).GetTaggedValue(); - JSHandle propHandle(thread, prop); + JSTaggedValue::ToString(thread, JSHandle(thread, JSTaggedValue(src_idx))).GetTaggedValue(); + JSHandle prop_handle(thread, prop); // b. Let exists be ? HasProperty(source, P). // c. If exists is true, then - bool isExists = JSTaggedValue::HasProperty(thread, source, propHandle); + bool is_exists = JSTaggedValue::HasProperty(thread, source, prop_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!isExists) { + if (!is_exists) { continue; } @@ -748,14 +752,14 @@ static JSTaggedValue FlattenIntoArray(JSThread *thread, const JSHandle // ii. If mapperFunction is present, then // 1. Assert: thisArg is present. // 2. Set element to ? Call(mapperFunction, thisArg , « element, sourceIndex, source »). - JSHandle element(JSTaggedValue::GetProperty(thread, source, propHandle).GetValue()); + JSHandle element(JSTaggedValue::GetProperty(thread, source, prop_handle).GetValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!mapperFunc->IsHole()) { - ASSERT(!thisArg->IsHole()); + if (!mapper_func->IsHole()) { + ASSERT(!this_arg->IsHole()); - auto info = NewRuntimeCallInfo(thread, mapperFunc, thisArg, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(element.GetTaggedValue(), JSTaggedNumber(srcIdx), source.GetTaggedValue()); - JSTaggedValue res = JSFunction::Call(info.get()); // 3: three args + auto info = NewRuntimeCallInfo(thread, mapper_func, this_arg, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(element.GetTaggedValue(), JSTaggedNumber(src_idx), source.GetTaggedValue()); + JSTaggedValue res = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); element = JSHandle(thread, res); } @@ -772,32 +776,32 @@ static JSTaggedValue FlattenIntoArray(JSThread *thread, const JSHandle // 3. Increase targetIndex by 1. if ((depth > 0) && element->IsJSArray()) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double elementLen = ArrayHelper::GetLength(thread, element); + double element_len = ArrayHelper::GetLength(thread, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - targetIdx = FlattenIntoArray(thread, target, element, elementLen, targetIdx.GetNumber(), depth - 1, - JSHandle(thread, JSTaggedValue::Hole()), - JSHandle(thread, JSTaggedValue::Hole())); + target_idx = FlattenIntoArray(thread, target, element, element_len, target_idx.GetNumber(), depth - 1, + JSHandle(thread, JSTaggedValue::Hole()), + JSHandle(thread, JSTaggedValue::Hole())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - if (targetIdx.GetNumber() >= ecmascript::base::MAX_SAFE_INTEGER) { + if (target_idx.GetNumber() >= ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range", JSTaggedValue::Exception()); } JSTaggedValue str = // TODO(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue // (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - JSTaggedValue::ToString(thread, JSHandle(thread, targetIdx)).GetTaggedValue(); - JSHandle strHandle(thread, str); - JSObject::CreateDataPropertyOrThrow(thread, target, strHandle, element); + JSTaggedValue::ToString(thread, JSHandle(thread, target_idx)).GetTaggedValue(); + JSHandle str_handle(thread, str); + JSObject::CreateDataPropertyOrThrow(thread, target, str_handle, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - targetIdx = JSTaggedValue(targetIdx.GetNumber() + 1); + target_idx = JSTaggedValue(target_idx.GetNumber() + 1); } } // 4. Return targetIndex. // TODO(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - return targetIdx; + return target_idx; } // ES2019 22.1.3.10 Array.prototype.flat( [ depth ] ) @@ -806,39 +810,39 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Flat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ? ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let sourceLen be ? ToLength(? Get(O, "length")). - double sourceLen = ArrayHelper::GetLength(thread, thisHandle); + double source_len = ArrayHelper::GetLength(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let depthNum be 1. // 4. If depth is not undefined, then // a. Set depthNum to ? ToInteger(depth) - double depthNum = 1; + double depth_num = 1; JSHandle msg1 = GetCallArg(argv, 0); if (!msg1->IsUndefined()) { JSTaggedValue depth = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - depthNum = depth.GetNumber(); + depth_num = depth.GetNumber(); } // 5. Let A be ? ArraySpeciesCreate(O, 0) - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(0)); + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // 6. Perform FlattenIntoArray(target, source, sourceLen, start, depth) - FlattenIntoArray(thread, newArrayHandle, thisHandle, sourceLen, 0, depthNum, + FlattenIntoArray(thread, new_array_handle, this_handle, source_len, 0, depth_num, JSHandle(thread, JSTaggedValue::Hole()), JSHandle(thread, JSTaggedValue::Hole())); - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // ES2019 22.1.3.11 Array.prototype.flatMap(mapperFunction [ , thisArg ]]) @@ -847,38 +851,38 @@ JSTaggedValue BuiltinsArray::FlatMap(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, FlatMap); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ? ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. Let sourceLen be ? ToLength(? Get(O, "length")). - double sourceLen = ArrayHelper::GetLength(thread, thisHandle); + double source_len = ArrayHelper::GetLength(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If IsCallable(mapperFunction) is false, throw a TypeError exception. - JSHandle mapperFunction = GetCallArg(argv, 0); - if (!mapperFunction->IsCallable()) { + JSHandle mapper_function = 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 thisArg(thread, JSTaggedValue::Undefined()); + JSMutableHandle this_arg(thread, JSTaggedValue::Undefined()); if (argc > 1) { - thisArg.Update(GetCallArg(argv, 1).GetTaggedValue()); + this_arg.Update(GetCallArg(argv, 1).GetTaggedValue()); } // 5. Let A be ? ArraySpeciesCreate(O, 0). - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(0)); - JSHandle newArrayHandle(thread, newArray); + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(0)); + JSHandle new_array_handle(thread, new_array); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, T). - FlattenIntoArray(thread, newArrayHandle, thisHandle, sourceLen, 0, 1, mapperFunction, thisArg); + FlattenIntoArray(thread, new_array_handle, this_handle, source_len, 0, 1, mapper_function, this_arg); // 7. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) @@ -887,19 +891,19 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Fill); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); JSHandle value = GetCallArg(argv, 0); - if (thisHandle->IsTypedArray()) { - ContentType contentType = JSHandle::Cast(thisHandle)->GetContentType(); - if (contentType == ContentType::BigInt) { + if (this_handle->IsTypedArray()) { + ContentType content_type = JSHandle::Cast(this_handle)->GetContentType(); + if (content_type == ContentType::BIG_INT) { value = JSHandle(thread, JSTaggedValue::ToBigInt(thread, value)); } else { value = JSHandle(thread, JSTaggedValue::ToNumber(thread, value)); @@ -908,40 +912,40 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) } // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). double start; JSHandle msg1 = GetCallArg(argv, 1); - JSTaggedNumber argStartTemp = JSTaggedValue::ToInteger(thread, msg1); + JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg1); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double argStart = argStartTemp.GetNumber(); + double arg_start = arg_start_temp.GetNumber(); // 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be min(relativeStart, len). - if (argStart < 0) { - start = argStart + len > 0 ? argStart + len : 0; + if (arg_start < 0) { + start = arg_start + len > 0 ? arg_start + len : 0; } else { - start = argStart < len ? argStart : len; + start = arg_start < len ? arg_start : len; } // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). - double argEnd = len; + double arg_end = len; JSHandle msg2 = GetCallArg(argv, INDEX_TWO); if (!msg2->IsUndefined()) { - JSTaggedNumber argEndTemp = JSTaggedValue::ToInteger(thread, msg2); + JSTaggedNumber arg_end_temp = JSTaggedValue::ToInteger(thread, msg2); // 9. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - argEnd = argEndTemp.GetNumber(); + arg_end = arg_end_temp.GetNumber(); } // 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). double end; - if (argEnd < 0) { - end = argEnd + len > 0 ? argEnd + len : 0; + if (arg_end < 0) { + end = arg_end + len > 0 ? arg_end + len : 0; } else { - end = argEnd < len ? argEnd : len; + end = arg_end < len ? arg_end : len; } // 11. Repeat, while k < final @@ -953,13 +957,13 @@ JSTaggedValue BuiltinsArray::Fill(EcmaRuntimeCallInfo *argv) double k = start; while (k < end) { key.Update(JSTaggedValue(k)); - JSArray::FastSetPropertyByValue(thread, thisObjVal, key, value); + JSArray::FastSetPropertyByValue(thread, this_obj_val, key, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 12. Return O. - return thisObjHandle.GetTaggedValue(); + return this_obj_handle.GetTaggedValue(); } // 22.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] ) @@ -967,35 +971,35 @@ JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let A be ArraySpeciesCreate(O, 0). - int32_t arrayLen = 0; - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(arrayLen)); + int32_t array_len = 0; + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(array_len)); // 8. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // 9. Let k be 0. // 10. Let to be 0. @@ -1013,35 +1017,35 @@ JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) // 2. ReturnIfAbrupt(status). // 3. Increase to by 1. // e. Increase k by 1. - double toIndex = 0; + double to_index = 0; JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle toIndexHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle to_index_handle(thread, JSTaggedValue::Undefined()); uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args - bool boolResult = callResult.ToBoolean(); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args + bool bool_result = call_result.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (boolResult) { - toIndexHandle.Update(JSTaggedValue(toIndex)); - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toIndexHandle, kValue); + if (bool_result) { + to_index_handle.Update(JSTaggedValue(to_index)); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_index_handle, k_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - toIndex++; + to_index++; } } k++; } // 12. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.3.8 Array.prototype.find ( predicate [ , thisArg ] ) @@ -1050,28 +1054,28 @@ JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Find); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(predicate) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1086,16 +1090,16 @@ JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) uint32_t k = 0; while (k < len) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool boolResult = callResult.ToBoolean(); - if (boolResult) { - return kValue.GetTaggedValue(); + bool bool_result = call_result.ToBoolean(); + if (bool_result) { + return k_value.GetTaggedValue(); } k++; } @@ -1110,28 +1114,28 @@ JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, FindIndex); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(predicate) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1146,15 +1150,15 @@ JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) uint32_t k = 0; while (k < len) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args - bool boolResult = callResult.ToBoolean(); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args + bool bool_result = call_result.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (boolResult) { + if (bool_result) { return GetTaggedDouble(k); } k++; @@ -1169,28 +1173,28 @@ JSTaggedValue BuiltinsArray::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -1207,16 +1211,16 @@ JSTaggedValue BuiltinsArray::ForEach(EcmaRuntimeCallInfo *argv) uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue funcResult = JSFunction::Call(info.get()); // 3: three args - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue func_result = JSFunction::Call(info.Get()); // 3: three args + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func_result); } k++; } @@ -1231,17 +1235,17 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Includes); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 2. Let len be ? LengthOfArrayLike(O). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If len is 0, return false. @@ -1250,15 +1254,15 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) } ArraySizeT argc = argv->GetArgsNumber(); - double fromIndex = 0; + double from_index = 0; 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); - JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); + from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); // 6. If n is positiveInfinity, return false. if (JSTaggedValue::Equal(thread, msg1, @@ -1269,7 +1273,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) // 7. Else if n is negativeInfinity, set n to 0. if (JSTaggedValue::Equal(thread, msg1, JSHandle(thread, JSTaggedValue(-base::POSITIVE_INFINITY)))) { - fromIndex = 0; + from_index = 0; } } @@ -1278,19 +1282,19 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) // 9. Else, // a. Let k be len + n. // b. If k < 0, set k to 0. - double from = (fromIndex >= 0) ? fromIndex : ((len + fromIndex) >= 0 ? len + fromIndex : 0); + double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); // 10. - const JSHandle searchElement = GetCallArg(argv, 0); + const JSHandle search_element = GetCallArg(argv, 0); while (from < len) { // a) - JSHandle indexHandle(thread, JSTaggedValue(from)); + JSHandle index_handle(thread, JSTaggedValue(from)); JSHandle handle = - JSHandle(thread, JSTaggedValue::ToString(thread, indexHandle).GetTaggedValue()); - JSHandle element = JSTaggedValue::GetProperty(thread, thisObjVal, handle).GetValue(); + JSHandle(thread, JSTaggedValue::ToString(thread, index_handle).GetTaggedValue()); + JSHandle element = JSTaggedValue::GetProperty(thread, this_obj_val, handle).GetValue(); // b) - if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), element.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(search_element.GetTaggedValue(), element.GetTaggedValue())) { return GetTaggedBoolean(true); } @@ -1307,21 +1311,21 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, IndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); - JSHandle searchElement = GetCallArg(argv, 0); + JSHandle search_element = GetCallArg(argv, 0); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1331,17 +1335,17 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) } // 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be 0. - double fromIndex = 0; + double from_index = 0; if (argc > 1) { JSHandle msg1 = GetCallArg(argv, 1); - JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); // 7. ReturnIfAbrupt(n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); + from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); } // 8. If n ≥ len, return −1. - if (fromIndex >= len) { + if (from_index >= len) { return GetTaggedInt(-1); } @@ -1350,7 +1354,7 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) // 10. Else n<0, // a. Let k be len - abs(n). // b. If k < 0, let k be 0. - double from = (fromIndex >= 0) ? fromIndex : ((len + fromIndex) >= 0 ? len + fromIndex : 0); + double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); // 11. Repeat, while k key(thread, JSTaggedValue::Undefined()); while (from < len) { key.Update(JSTaggedValue(from)); - bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, key)); + bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); + JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::StrictEqual(thread, searchElement, kValueHandle)) { + if (JSTaggedValue::StrictEqual(thread, search_element, k_value_handle)) { return GetTaggedDouble(from); } } @@ -1386,52 +1390,52 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Join); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisHandle = GetThis(argv); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_handle = GetThis(argv); // Prevent inifinity joining of recursive arrays static std::vector visited_stack = {}; - if (std::find(visited_stack.begin(), visited_stack.end(), thisHandle->GetRawData()) != visited_stack.end()) { + if (std::find(visited_stack.begin(), visited_stack.end(), this_handle->GetRawData()) != visited_stack.end()) { return GetTaggedString(thread, ""); } - visited_stack.push_back(thisHandle->GetRawData()); + visited_stack.push_back(this_handle->GetRawData()); auto unvisit = std::unique_ptr>( reinterpret_cast(1), [&](void * /* unused */) { visited_stack.pop_back(); }); - if (thisHandle->IsStableJSArray(thread)) { - return JSStableArray::Join(JSHandle::Cast(thisHandle), argv); + if (this_handle->IsStableJSArray(thread)) { + return JSStableArray::Join(JSHandle::Cast(this_handle), argv); } auto factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If separator is undefined, let separator be the single-element String ",". // 6. Let sep be ToString(separator). - JSHandle sepHandle; + JSHandle sep_handle; if ((GetCallArg(argv, 0)->IsUndefined())) { - sepHandle = JSHandle::Cast(factory->NewFromCanBeCompressString(",")); + sep_handle = JSHandle::Cast(factory->NewFromCanBeCompressString(",")); } else { - sepHandle = GetCallArg(argv, 0); + sep_handle = GetCallArg(argv, 0); } - JSHandle sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); + JSHandle sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); // 7. ReturnIfAbrupt(sep). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t sepLen = sepStringHandle->GetLength(); - std::u16string sepStr; - if (sepStringHandle->IsUtf16()) { - sepStr = ecmascript::base::StringHelper::Utf16ToU16String(sepStringHandle->GetDataUtf16(), sepLen); + int32_t sep_len = sep_string_handle->GetLength(); + std::u16string sep_str; + if (sep_string_handle->IsUtf16()) { + sep_str = ecmascript::base::StringHelper::Utf16ToU16String(sep_string_handle->GetDataUtf16(), sep_len); } else { - sepStr = ecmascript::base::StringHelper::Utf8ToU16String(sepStringHandle->GetDataUtf8(), sepLen); + sep_str = ecmascript::base::StringHelper::Utf8ToU16String(sep_string_handle->GetDataUtf8(), sep_len); } // 8. If len is zero, return the empty String. @@ -1450,36 +1454,37 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv) // d. ReturnIfAbrupt(next). // e. Let R be a String value produced by concatenating S and next. // f. Increase k by 1. - std::u16string concatStr; - std::u16string concatStrNew; + std::u16string concat_str; + std::u16string concat_str_new; for (int32_t k = 0; k < len; k++) { - std::u16string nextStr; - JSHandle element = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + std::u16string next_str; + JSHandle element = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!element->IsUndefined() && !element->IsNull()) { - JSHandle nextStringHandle = JSTaggedValue::ToString(thread, element); + JSHandle next_string_handle = JSTaggedValue::ToString(thread, element); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t nextLen = nextStringHandle->GetLength(); - if (nextStringHandle->IsUtf16()) { - nextStr = ecmascript::base::StringHelper::Utf16ToU16String(nextStringHandle->GetDataUtf16(), nextLen); + int32_t next_len = next_string_handle->GetLength(); + if (next_string_handle->IsUtf16()) { + next_str = + ecmascript::base::StringHelper::Utf16ToU16String(next_string_handle->GetDataUtf16(), next_len); } else { - nextStr = ecmascript::base::StringHelper::Utf8ToU16String(nextStringHandle->GetDataUtf8(), nextLen); + next_str = ecmascript::base::StringHelper::Utf8ToU16String(next_string_handle->GetDataUtf8(), next_len); } } if (k > 0) { - concatStrNew = ecmascript::base::StringHelper::Append(concatStr, sepStr); - concatStr = ecmascript::base::StringHelper::Append(concatStrNew, nextStr); + concat_str_new = ecmascript::base::StringHelper::Append(concat_str, sep_str); + concat_str = ecmascript::base::StringHelper::Append(concat_str_new, next_str); continue; } - concatStr = ecmascript::base::StringHelper::Append(concatStr, nextStr); + concat_str = ecmascript::base::StringHelper::Append(concat_str, next_str); } // 14. Return R. - const char16_t *constChar16tData = concatStr.data(); - auto *char16tData = const_cast(constChar16tData); - auto *uint16tData = reinterpret_cast(char16tData); - int32_t u16strSize = concatStr.size(); - return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); + const char16_t *const_char16t_data = concat_str.data(); + auto *char16t_data = const_cast(const_char16t_data); + auto *uint16t_data = reinterpret_cast(char16t_data); + int32_t u16str_size = concat_str.size(); + return factory->NewFromUtf16Literal(uint16t_data, u16str_size).GetTaggedValue(); } // 22.1.3.13 Array.prototype.keys ( ) @@ -1488,7 +1493,7 @@ JSTaggedValue BuiltinsArray::Keys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). @@ -1505,21 +1510,21 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, LastIndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); - JSHandle searchElement = GetCallArg(argv, 0); + JSHandle search_element = GetCallArg(argv, 0); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1529,19 +1534,19 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) } // 6. If argument fromIndex was passed let n be ToInteger(fromIndex); else let n be len-1. - double fromIndex = len - 1; + double from_index = len - 1; if (argc > 1) { JSHandle msg1 = GetCallArg(argv, 1); - JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); // 7. ReturnIfAbrupt(n). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); + from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); } // 8. If n ≥ 0, let k be min(n, len – 1). // 9. Else n < 0, // a. Let k be len - abs(n). - double from = (fromIndex >= 0) ? ((len - 1) < fromIndex ? len - 1 : fromIndex) : len + fromIndex; + double from = (from_index >= 0) ? ((len - 1) < from_index ? len - 1 : from_index) : len + from_index; // 10. Repeat, while k≥ 0 // a. Let kPresent be HasProperty(O, ToString(k)). @@ -1555,12 +1560,12 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (from >= 0) { key.Update(JSTaggedValue(from)); - bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, key)); + bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); + JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (JSTaggedValue::StrictEqual(thread, searchElement, kValueHandle)) { + if (JSTaggedValue::StrictEqual(thread, search_element, k_value_handle)) { return GetTaggedDouble(from); } } @@ -1577,37 +1582,37 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Map); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let A be ArraySpeciesCreate(O, len). - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(len)); + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(len)); // 8. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!newArray.IsECMAObject()) { + if (!new_array.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to create Object.", JSTaggedValue::Exception()); } - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // 9. Let k be 0. // 10. Repeat, while k < len @@ -1623,29 +1628,29 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) // vi. ReturnIfAbrupt(status). // e. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle mapResultHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle map_result_handle(thread, JSTaggedValue::Undefined()); uint32_t k = 0; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue mapResult = JSFunction::Call(info.get()); // 3: three args + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue map_result = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - mapResultHandle.Update(mapResult); - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, k, mapResultHandle); + map_result_handle.Update(map_result); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, k, map_result_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } // 11. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.3.16 Array.prototype.pop ( ) @@ -1654,30 +1659,30 @@ JSTaggedValue BuiltinsArray::Pop(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Pop); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - if (thisHandle->IsStableJSArray(thread)) { - return JSStableArray::Pop(JSHandle::Cast(thisHandle), argv); + JSHandle this_handle = GetThis(argv); + if (this_handle->IsStableJSArray(thread)) { + return JSStableArray::Pop(JSHandle::Cast(this_handle), argv); } - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If len is zero, // a. Let setStatus be Set(O, "length", 0, true). // b. ReturnIfAbrupt(setStatus). // c. Return undefined. - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); if (len == 0) { - JSHandle lengthValue(thread, JSTaggedValue(0)); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, lengthValue, true); + JSHandle length_value(thread, JSTaggedValue(0)); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, length_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Undefined(); } @@ -1692,13 +1697,13 @@ JSTaggedValue BuiltinsArray::Pop(EcmaRuntimeCallInfo *argv) // g. Let setStatus be Set(O, "length", newLen, true). // h. ReturnIfAbrupt(setStatus). // i. Return element. - double newLen = len - 1; - JSHandle indexHandle(thread, JSTaggedValue(newLen)); - JSHandle element = JSTaggedValue::GetProperty(thread, thisObjVal, indexHandle).GetValue(); + double new_len = len - 1; + JSHandle index_handle(thread, JSTaggedValue(new_len)); + JSHandle element = JSTaggedValue::GetProperty(thread, this_obj_val, index_handle).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, indexHandle); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, index_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, indexHandle, true); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, index_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return element.GetTaggedValue(); @@ -1710,22 +1715,22 @@ JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Push); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisHandle = GetThis(argv); - if (thisHandle->IsStableJSArray(thread)) { - return JSStableArray::Push(JSHandle::Cast(thisHandle), argv); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_handle = GetThis(argv); + if (this_handle->IsStableJSArray(thread)) { + return JSStableArray::Push(JSHandle::Cast(this_handle), argv); } // 6. Let argCount be the number of elements in items. uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. If len + argCount > 253-1, throw a TypeError exception. @@ -1742,17 +1747,17 @@ JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (k < argc) { key.Update(JSTaggedValue(len)); - JSHandle kValue = GetCallArg(argv, k); - JSArray::FastSetPropertyByValue(thread, thisObjVal, key, kValue); + JSHandle k_value = GetCallArg(argv, k); + JSArray::FastSetPropertyByValue(thread, this_obj_val, key, k_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; len++; } // 9. Let setStatus be Set(O, "length", len, true). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); key.Update(JSTaggedValue(len)); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, key, true); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, key, true); // 10. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1766,25 +1771,25 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Reduce); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = GetCallArg(argv, 0); + if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } @@ -1812,17 +1817,17 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) if (argc == 2) { // 2:2 means the number of parameters accumulator.Update(GetCallArg(argv, 1).GetTaggedValue()); } else { - bool kPresent = false; - while (!kPresent && k < len) { - kPresent = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); + bool k_present = false; + while (!k_present && k < len) { + k_present = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (kPresent) { - accumulator.Update(JSArray::FastGetPropertyByValue(thread, thisObjVal, k).GetTaggedValue()); + if (k_present) { + accumulator.Update(JSArray::FastGetPropertyByValue(thread, this_obj_val, k).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } - if (!kPresent) { + if (!k_present) { THROW_TYPE_ERROR_AND_RETURN(thread, "accumulator can't be initialized.", JSTaggedValue::Exception()); } } @@ -1837,22 +1842,22 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) // iii. Let accumulator be Call(callbackfn, undefined, «accumulator, kValue, k, O»). // iv. ReturnIfAbrupt(accumulator). // e. Increase k by 1. - JSTaggedValue callResult = JSTaggedValue::Undefined(); + JSTaggedValue call_result = JSTaggedValue::Undefined(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (k < len) { - bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); + bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - JSHandle thisArgHandle = globalConst->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 4); - info->SetCallArgs(accumulator, kValue, key, thisObjVal); - callResult = JSFunction::Call(info.get()); // 4: four args + JSHandle this_arg_handle = global_const->GetHandledUndefined(); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 4); + info->SetCallArgs(accumulator, k_value, key, this_obj_val); + call_result = JSFunction::Call(info.Get()); // 4: four args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - accumulator.Update(callResult); + accumulator.Update(call_result); } k++; } @@ -1867,26 +1872,26 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ReduceRight); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = GetCallArg(argv, 0); + if (!callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); } @@ -1914,17 +1919,17 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) if (argc == 2) { // 2:2 means the number of parameters accumulator.Update(GetCallArg(argv, 1).GetTaggedValue()); } else { - bool kPresent = false; - while (!kPresent && k >= 0) { - kPresent = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); + bool k_present = false; + while (!k_present && k >= 0) { + k_present = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (kPresent) { - accumulator.Update(JSArray::FastGetPropertyByValue(thread, thisObjVal, k).GetTaggedValue()); + if (k_present) { + accumulator.Update(JSArray::FastGetPropertyByValue(thread, this_obj_val, k).GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k--; } - if (!kPresent) { + if (!k_present) { THROW_TYPE_ERROR_AND_RETURN(thread, "accumulator can't be initialized.", JSTaggedValue::Exception()); } } @@ -1940,21 +1945,21 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) // iv. ReturnIfAbrupt(accumulator). // e. Decrease k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSTaggedValue callResult = JSTaggedValue::Undefined(); + JSTaggedValue call_result = JSTaggedValue::Undefined(); while (k >= 0) { key.Update(JSTaggedValue(k)); - bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, key)); + bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, key)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisArgHandle = globalConst->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 4); - info->SetCallArgs(accumulator, kValue, key, thisObjVal); - callResult = JSFunction::Call(info.get()); // 4: four args + JSHandle this_arg_handle = global_const->GetHandledUndefined(); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 4); + info->SetCallArgs(accumulator, k_value, key, this_obj_val); + call_result = JSFunction::Call(info.Get()); // 4: four args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - accumulator.Update(callResult); + accumulator.Update(call_result); } k--; } @@ -1969,17 +1974,17 @@ JSTaggedValue BuiltinsArray::Reverse(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Reverse); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2021,40 +2026,40 @@ JSTaggedValue BuiltinsArray::Reverse(EcmaRuntimeCallInfo *argv) // m. Else both lowerExists and upperExists are false, // i. No action is required. // n. Increase lower by 1. - JSMutableHandle lowerP(thread, JSTaggedValue::Undefined()); - JSMutableHandle upperP(thread, JSTaggedValue::Undefined()); - JSHandle lowerValueHandle(thread, JSTaggedValue::Undefined()); - JSHandle upperValueHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle lower_p(thread, JSTaggedValue::Undefined()); + JSMutableHandle upper_p(thread, JSTaggedValue::Undefined()); + JSHandle lower_value_handle(thread, JSTaggedValue::Undefined()); + JSHandle upper_value_handle(thread, JSTaggedValue::Undefined()); while (lower != middle) { double upper = len - lower - 1; - lowerP.Update(JSTaggedValue(lower)); - upperP.Update(JSTaggedValue(upper)); - bool lowerExists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, lowerP)); + lower_p.Update(JSTaggedValue(lower)); + upper_p.Update(JSTaggedValue(upper)); + bool lower_exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, lower_p)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (lowerExists) { - lowerValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, lowerP); + if (lower_exists) { + lower_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, lower_p); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - bool upperExists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, upperP)); + bool upper_exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, upper_p)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (upperExists) { - upperValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, upperP); + if (upper_exists) { + upper_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, upper_p); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - if (lowerExists && upperExists) { - JSArray::FastSetPropertyByValue(thread, thisObjVal, lowerP, upperValueHandle); + if (lower_exists && upper_exists) { + JSArray::FastSetPropertyByValue(thread, this_obj_val, lower_p, upper_value_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, upperP, lowerValueHandle); + JSArray::FastSetPropertyByValue(thread, this_obj_val, upper_p, lower_value_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - } else if (upperExists) { - JSArray::FastSetPropertyByValue(thread, thisObjVal, lowerP, upperValueHandle); + } else if (upper_exists) { + JSArray::FastSetPropertyByValue(thread, this_obj_val, lower_p, upper_value_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, upperP); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, upper_p); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - } else if (lowerExists) { - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, lowerP); + } else if (lower_exists) { + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, lower_p); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, upperP, lowerValueHandle); + JSArray::FastSetPropertyByValue(thread, this_obj_val, upper_p, lower_value_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { } @@ -2062,7 +2067,7 @@ JSTaggedValue BuiltinsArray::Reverse(EcmaRuntimeCallInfo *argv) } // 8. Return O . - return thisObjHandle.GetTaggedValue(); + return this_obj_handle.GetTaggedValue(); } // 22.1.3.21 Array.prototype.shift ( ) @@ -2071,37 +2076,37 @@ JSTaggedValue BuiltinsArray::Shift(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Shift); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - if (thisHandle->IsStableJSArray(thread)) { - return JSStableArray::Shift(JSHandle::Cast(thisHandle), argv); + JSHandle this_handle = GetThis(argv); + if (this_handle->IsStableJSArray(thread)) { + return JSStableArray::Shift(JSHandle::Cast(this_handle), argv); } - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If len is zero, then // a. Let setStatus be Set(O, "length", 0, true). // b. ReturnIfAbrupt(setStatus). // c. Return undefined. - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); if (len == 0) { - JSHandle zeroLenHandle(thread, JSTaggedValue(len)); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, zeroLenHandle, true); + JSHandle zero_len_handle(thread, JSTaggedValue(len)); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, zero_len_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Undefined(); } // 6. Let first be Get(O, "0"). - JSHandle firstKey(thread, JSTaggedValue(0)); - JSHandle firstValue = JSTaggedValue::GetProperty(thread, thisObjVal, firstKey).GetValue(); + JSHandle first_key(thread, JSTaggedValue(0)); + JSHandle first_value = JSTaggedValue::GetProperty(thread, this_obj_val, first_key).GetValue(); // 7. ReturnIfAbrupt(first). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2120,37 +2125,37 @@ JSTaggedValue BuiltinsArray::Shift(EcmaRuntimeCallInfo *argv) // i. Let deleteStatus be DeletePropertyOrThrow(O, to). // ii. ReturnIfAbrupt(deleteStatus). // g. Increase k by 1. - JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); double k = 1; while (k < len) { - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, k); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, k - 1, fromValue); + JSArray::FastSetPropertyByValue(thread, this_obj_val, k - 1, from_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - toKey.Update(JSTaggedValue(k - 1)); - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); + to_key.Update(JSTaggedValue(k - 1)); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } // 10. Let deleteStatus be DeletePropertyOrThrow(O, ToString(len–1)). - JSHandle deleteKey(thread, JSTaggedValue(len - 1)); - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, deleteKey); + JSHandle delete_key(thread, JSTaggedValue(len - 1)); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, delete_key); // 11. ReturnIfAbrupt(deleteStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 12. Let setStatus be Set(O, "length", len–1, true). - JSHandle newLenHandle(thread, JSTaggedValue(len - 1)); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); + JSHandle new_len_handle(thread, JSTaggedValue(len - 1)); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, new_len_handle, true); // 13. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 14. Return first. - return firstValue.GetTaggedValue(); + return first_value.GetTaggedValue(); } // 22.1.3.22 Array.prototype.slice (start, end) @@ -2159,49 +2164,49 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Array, Slice); ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). JSHandle msg0 = GetCallArg(argv, 0); - JSTaggedNumber argStartTemp = JSTaggedValue::ToInteger(thread, msg0); + JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg0); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double argStart = argStartTemp.GetNumber(); + double arg_start = arg_start_temp.GetNumber(); double k; // 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be min(relativeStart, len). - if (argStart < 0) { - k = argStart + len > 0 ? argStart + len : 0; + if (arg_start < 0) { + k = arg_start + len > 0 ? arg_start + len : 0; } else { - k = argStart < len ? argStart : len; + k = arg_start < len ? arg_start : len; } // 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); - double argEnd = len; + double arg_end = len; if (!msg1->IsUndefined()) { - JSTaggedNumber argEndTemp = JSTaggedValue::ToInteger(thread, msg1); + JSTaggedNumber arg_end_temp = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - argEnd = argEndTemp.GetNumber(); + arg_end = arg_end_temp.GetNumber(); } double final; - if (argEnd < 0) { - final = argEnd + len > 0 ? argEnd + len : 0; + if (arg_end < 0) { + final = arg_end + len > 0 ? arg_end + len : 0; } else { - final = argEnd < len ? argEnd : len; + final = arg_end < len ? arg_end : len; } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2209,24 +2214,24 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) double count = (final - k) > 0 ? (final - k) : 0; // 12. Let A be ArraySpeciesCreate(O, count). - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(count)); + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(count)); // 13. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (count == 0) { - return newArray; + return new_array; } - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); - if (thisHandle->IsStableJSArray(thread) && newArray.IsStableJSArray(thread)) { - TaggedArray *destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, count); - TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); + if (this_handle->IsStableJSArray(thread) && new_array.IsStableJSArray(thread)) { + TaggedArray *dest_elements = *JSObject::GrowElementsCapacity(thread, new_array_handle, count); + TaggedArray *src_elements = TaggedArray::Cast(this_obj_handle->GetElements().GetTaggedObject()); for (uint32_t idx = 0; idx < count; idx++) { - destElements->Set(thread, idx, srcElements->Get(k + idx)); + dest_elements->Set(thread, idx, src_elements->Get(k + idx)); } - JSHandle::Cast(newArrayHandle)->SetArrayLength(thread, count); - return newArrayHandle.GetTaggedValue(); + JSHandle::Cast(new_array_handle)->SetArrayLength(thread, count); + return new_array_handle.GetTaggedValue(); } // 14. Let n be 0. @@ -2243,16 +2248,16 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) // f. Increase n by 1. double n = 0; JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle nKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle n_key(thread, JSTaggedValue::Undefined()); while (k < final) { key.Update(JSTaggedValue(k)); - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, key); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - nKey.Update(JSTaggedValue(n)); - JSHandle kValueHandle = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); + n_key.Update(JSTaggedValue(n)); + JSHandle k_value_handle = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, nKey, kValueHandle); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, n_key, k_value_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; @@ -2260,14 +2265,15 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) } // 16. Let setStatus be Set(A, "length", n, true). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle newLenHandle(thread, JSTaggedValue(n)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, newLenHandle, true); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle new_len_handle(thread, JSTaggedValue(n)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, new_len_handle, + true); // 17. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 18. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.3.23 Array.prototype.some ( callbackfn [ , thisArg ] ) @@ -2276,28 +2282,28 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Some); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -2315,18 +2321,18 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) double k = 0; while (k < len) { - bool exists = (thisHandle->IsTypedArray() || JSTaggedValue::HasProperty(thread, thisObjVal, k)); + bool exists = (this_handle->IsTypedArray() || JSTaggedValue::HasProperty(thread, this_obj_val, k)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { key.Update(JSTaggedValue(k)); - JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); + JSHandle k_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args - bool boolResult = callResult.ToBoolean(); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args + bool bool_result = call_result.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (boolResult) { + if (bool_result) { return GetTaggedBoolean(true); } } @@ -2343,61 +2349,62 @@ JSTaggedValue BuiltinsArray::Sort(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Sort); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsUndefined() && !callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = GetCallArg(argv, 0); + if (!callback_fn_handle->IsUndefined() && !callback_fn_handle->IsCallable()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Callable is false", JSTaggedValue::Exception()); } // 2. Let len be ToLength(Get(obj, "length")). - double len = ArrayHelper::GetArrayLength(thread, JSHandle(thisObjHandle)); + double len = ArrayHelper::GetArrayLength(thread, JSHandle(this_obj_handle)); // 3. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSMutableHandle presentValue(thread, JSTaggedValue::Undefined()); - JSMutableHandle middleValue(thread, JSTaggedValue::Undefined()); - JSMutableHandle previousValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle present_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle middle_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle previous_value(thread, JSTaggedValue::Undefined()); for (int i = 1; i < len; i++) { - int beginIndex = 0; - int endIndex = i; - presentValue.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), i)); + int begin_index = 0; + int end_index = i; + present_value.Update( + FastRuntimeStub::FastGetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - while (beginIndex < endIndex) { - int middleIndex = (beginIndex + endIndex) / 2; // 2 : half - middleValue.Update( - FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), middleIndex)); + while (begin_index < end_index) { + int middle_index = (begin_index + end_index) / 2; // 2 : half + middle_value.Update( + FastRuntimeStub::FastGetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), middle_index)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t compareResult = ArrayHelper::SortCompare(thread, callbackFnHandle, middleValue, presentValue); + int32_t compare_result = ArrayHelper::SortCompare(thread, callback_fn_handle, middle_value, present_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (compareResult > 0) { - endIndex = middleIndex; + if (compare_result > 0) { + end_index = middle_index; } else { - beginIndex = middleIndex + 1; + begin_index = middle_index + 1; } } - if (endIndex >= 0 && endIndex < i) { - for (int j = i; j > endIndex; j--) { - previousValue.Update( - FastRuntimeStub::FastGetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), j - 1)); + if (end_index >= 0 && end_index < i) { + for (int j = i; j > end_index; j--) { + previous_value.Update( + FastRuntimeStub::FastGetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), j - 1)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - FastRuntimeStub::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), j, - previousValue.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), j, + previous_value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - FastRuntimeStub::FastSetPropertyByIndex(thread, thisObjHandle.GetTaggedValue(), endIndex, - presentValue.GetTaggedValue()); + FastRuntimeStub::FastSetPropertyByIndex(thread, this_obj_handle.GetTaggedValue(), end_index, + present_value.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } - return thisObjHandle.GetTaggedValue(); + return this_obj_handle.GetTaggedValue(); } // 22.1.3.25 Array.prototype.splice (start, deleteCount , ...items ) @@ -2407,38 +2414,38 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Splice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let relativeStart be ToInteger(start). double start = 0; - double insertCount = 0; - double actualDeleteCount = 0; + double insert_count = 0; + double actual_delete_count = 0; double end = len; - double argStart = 0; + double arg_start = 0; if (argc > 0) { JSHandle msg0 = GetCallArg(argv, 0); - JSTaggedNumber argStartTemp = JSTaggedValue::ToInteger(thread, msg0); + JSTaggedNumber arg_start_temp = JSTaggedValue::ToInteger(thread, msg0); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - argStart = argStartTemp.GetNumber(); + arg_start = arg_start_temp.GetNumber(); // 7. If relativeStart < 0, let actualStart be max((len + relativeStart),0); else let actualStart be // min(relativeStart, len). - if (argStart < 0) { - start = argStart + len > 0 ? argStart + len : 0; + if (arg_start < 0) { + start = arg_start + len > 0 ? arg_start + len : 0; } else { - start = argStart < end ? argStart : end; + start = arg_start < end ? arg_start : end; } - actualDeleteCount = len - start; + actual_delete_count = len - start; } // 8. If the number of actual arguments is 0, then // a. Let insertCount be 0. @@ -2452,26 +2459,27 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) // c. ReturnIfAbrupt(dc). // d. Let actualDeleteCount be min(max(dc,0), len – actualStart). if (argc > 1) { - insertCount = argc - 2; // 2:2 means there are two arguments before the insert items. + insert_count = argc - 2; // 2:2 means there are two arguments before the insert items. JSHandle msg1 = GetCallArg(argv, 1); - JSTaggedNumber argDeleteCount = JSTaggedValue::ToInteger(thread, msg1); + JSTaggedNumber arg_delete_count = JSTaggedValue::ToInteger(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double deleteCount = argDeleteCount.GetNumber(); - deleteCount = deleteCount > 0 ? deleteCount : 0; - actualDeleteCount = deleteCount < (len - start) ? deleteCount : len - start; + double delete_count = arg_delete_count.GetNumber(); + delete_count = delete_count > 0 ? delete_count : 0; + actual_delete_count = delete_count < (len - start) ? delete_count : len - start; } // 11. If len+insertCount−actualDeleteCount > 253-1, throw a TypeError exception. - if (len + insertCount - actualDeleteCount > ecmascript::base::MAX_SAFE_INTEGER) { + if (len + insert_count - actual_delete_count > ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - if (thisHandle->IsStableJSArray(thread)) { - return JSStableArray::Splice(JSHandle::Cast(thisHandle), argv, start, insertCount, actualDeleteCount); + if (this_handle->IsStableJSArray(thread)) { + return JSStableArray::Splice(JSHandle::Cast(this_handle), argv, start, insert_count, + actual_delete_count); } // 12. Let A be ArraySpeciesCreate(O, actualDeleteCount). - JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(actualDeleteCount)); + JSTaggedValue new_array = JSArray::ArraySpeciesCreate(thread, this_obj_handle, JSTaggedNumber(actual_delete_count)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle newArrayHandle(thread, newArray); + JSHandle new_array_handle(thread, new_array); // 14. Let k be 0. // 15. Repeat, while k < actualDeleteCount // a. Let from be ToString(actualStart+k). @@ -2480,30 +2488,30 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) // i. Let fromValue be Get(O, from). // iii. Let status be CreateDataPropertyOrThrow(A, ToString(k), fromValue). // e. Increment k by 1. - JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); double k = 0; - while (k < actualDeleteCount) { + while (k < actual_delete_count) { double from = start + k; - fromKey.Update(JSTaggedValue(from)); - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); + from_key.Update(JSTaggedValue(from)); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); + JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - toKey.Update(JSTaggedValue(k)); - if (newArrayHandle->IsJSProxy()) { - toKey.Update(JSTaggedValue::ToString(thread, toKey).GetTaggedValue()); + to_key.Update(JSTaggedValue(k)); + if (new_array_handle->IsJSProxy()) { + to_key.Update(JSTaggedValue::ToString(thread, to_key).GetTaggedValue()); } - JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, toKey, fromValue); + JSObject::CreateDataPropertyOrThrow(thread, new_array_handle, to_key, from_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } // 16. Let setStatus be Set(A, "length", actualDeleteCount, true). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle deleteCountHandle(thread, JSTaggedValue(actualDeleteCount)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newArrayHandle), lengthKey, deleteCountHandle, + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle delete_count_handle(thread, JSTaggedValue(actual_delete_count)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_array_handle), length_key, delete_count_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 19. Let itemCount be the number of elements in items. @@ -2523,33 +2531,33 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) // d. Repeat, while k > (len – actualDeleteCount + itemCount) // i. Let deleteStatus be DeletePropertyOrThrow(O, ToString(k–1)). // iii. Decrease k by 1. - if (insertCount < actualDeleteCount) { + if (insert_count < actual_delete_count) { k = start; - while (k < len - actualDeleteCount) { - fromKey.Update(JSTaggedValue(k + actualDeleteCount)); - toKey.Update(JSTaggedValue(k + insertCount)); - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); + while (k < len - actual_delete_count) { + from_key.Update(JSTaggedValue(k + actual_delete_count)); + to_key.Update(JSTaggedValue(k + insert_count)); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); + JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValue); + JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k++; } k = len; - JSMutableHandle deleteKey(thread, JSTaggedValue::Undefined()); - while (k > len - actualDeleteCount + insertCount) { - deleteKey.Update(JSTaggedValue(k - 1)); - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, deleteKey); + JSMutableHandle delete_key(thread, JSTaggedValue::Undefined()); + while (k > len - actual_delete_count + insert_count) { + delete_key.Update(JSTaggedValue(k - 1)); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, delete_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k--; } - } else if (insertCount > actualDeleteCount) { + } else if (insert_count > actual_delete_count) { // 21. Else if itemCount > actualDeleteCount, then // a. Let k be (len – actualDeleteCount). // b. Repeat, while k > actualStart @@ -2566,19 +2574,19 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) // 1. Let deleteStatus be DeletePropertyOrThrow(O, to). // 2. ReturnIfAbrupt(deleteStatus). // vii. Decrease k by 1. - k = len - actualDeleteCount; + k = len - actual_delete_count; while (k > start) { - fromKey.Update(JSTaggedValue(k + actualDeleteCount - 1)); - toKey.Update(JSTaggedValue(k + insertCount - 1)); - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); + from_key.Update(JSTaggedValue(k + actual_delete_count - 1)); + to_key.Update(JSTaggedValue(k + insert_count - 1)); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); + JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValue); + JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k--; @@ -2589,20 +2597,20 @@ 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 itemValue = GetCallArg(argv, i); + JSHandle item_value = GetCallArg(argv, i); key.Update(JSTaggedValue(k)); - JSArray::FastSetPropertyByValue(thread, thisObjVal, key, itemValue); + JSArray::FastSetPropertyByValue(thread, this_obj_val, key, item_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 24. Let setStatus be Set(O, "length", len – actualDeleteCount + itemCount, true). - double newLen = len - actualDeleteCount + insertCount; - JSHandle newLenHandle(thread, JSTaggedValue(newLen)); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); + double new_len = len - actual_delete_count + insert_count; + JSHandle new_len_handle(thread, JSTaggedValue(new_len)); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, new_len_handle, true); // 25. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 26. Return A. - return newArrayHandle.GetTaggedValue(); + return new_array_handle.GetTaggedValue(); } // 22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) @@ -2611,33 +2619,33 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ToLocaleString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - auto ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + auto ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetLength(thread, thisObjVal); + double len = ArrayHelper::GetLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 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 sepHandle; + JSHandle sep_handle; if ((GetCallArg(argv, 0)->IsUndefined())) { - sepHandle = JSHandle::Cast(ecmaVm->GetFactory()->NewFromCanBeCompressString(",")); + sep_handle = JSHandle::Cast(ecma_vm->GetFactory()->NewFromCanBeCompressString(",")); } else { - sepHandle = GetCallArg(argv, 0); + sep_handle = GetCallArg(argv, 0); } - JSHandle sepStringHandle = JSTaggedValue::ToString(thread, sepHandle); + JSHandle sep_string_handle = JSTaggedValue::ToString(thread, sep_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PandaString sepString = ConvertToPandaString(*sepStringHandle); + PandaString sep_string = ConvertToPandaString(*sep_string_handle); // 6. If len is zero, return the empty String. if (len == 0) { return GetTaggedString(thread, ""); @@ -2647,7 +2655,7 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - PandaString concatStr; + PandaString concat_str; // 7. Let firstElement be Get(array, "0"). // 8. ReturnIfAbrupt(firstElement). // 9. If firstElement is undefined or null, then @@ -2667,37 +2675,37 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) // ii. ReturnIfAbrupt(R). // f. Let R be a String value produced by concatenating S and R. // g. Increase k by 1. - auto globalConst = thread->GlobalConstants(); + auto global_const = thread->GlobalConstants(); for (int32_t k = 0; k < len; k++) { - JSTaggedValue next = globalConst->GetEmptyString(); - JSHandle nextElement = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); + JSTaggedValue next = global_const->GetEmptyString(); + JSHandle next_element = JSArray::FastGetPropertyByValue(thread, this_obj_val, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!nextElement->IsUndefined() && !nextElement->IsNull()) { - JSHandle nextValueHandle = nextElement; - JSHandle key = globalConst->GetHandledToLocaleStringString(); - auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), nextValueHandle, + if (!next_element->IsUndefined() && !next_element->IsNull()) { + JSHandle next_value_handle = next_element; + JSHandle key = global_const->GetHandledToLocaleStringString(); + auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), next_value_handle, JSTaggedValue::Undefined(), 2); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArgs(locales, options); - JSTaggedValue callResult = JSFunction::Invoke(info.get(), key); + JSTaggedValue call_result = JSFunction::Invoke(info.Get(), key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - next = callResult; + next = call_result; } - JSHandle nextHandle(thread, next); - JSHandle nextStringHandle = JSTaggedValue::ToString(thread, nextHandle); + JSHandle next_handle(thread, next); + JSHandle next_string_handle = JSTaggedValue::ToString(thread, next_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PandaString nextString = ConvertToPandaString(*nextStringHandle); + PandaString next_string = ConvertToPandaString(*next_string_handle); if (k > 0) { - concatStr += sepString; - concatStr += nextString; + concat_str += sep_string; + concat_str += next_string; continue; } - concatStr += nextString; + concat_str += next_string; } // 13. Return R. - return factory->NewFromString(concatStr).GetTaggedValue(); + return factory->NewFromString(concat_str).GetTaggedValue(); } // 22.1.3.27 Array.prototype.toString ( ) @@ -2706,40 +2714,40 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - auto ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + auto ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let array be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(array). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let func be Get(array, "join"). - JSHandle joinKey(factory->NewFromCanBeCompressString("join")); - JSHandle callbackFnHandle = JSTaggedValue::GetProperty(thread, thisObjVal, joinKey).GetValue(); + JSHandle join_key(factory->NewFromCanBeCompressString("join")); + JSHandle callback_fn_handle = JSTaggedValue::GetProperty(thread, this_obj_val, join_key).GetValue(); // 4. ReturnIfAbrupt(func). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(func) is false, let func be the intrinsic function %ObjProto_toString% (19.1.3.6). - if (!callbackFnHandle->IsCallable()) { - JSHandle env = ecmaVm->GetGlobalEnv(); - JSHandle objectPrototype = env->GetObjectFunctionPrototype(); - JSHandle toStringKey = thread->GlobalConstants()->GetHandledToStringString(); - callbackFnHandle = JSTaggedValue::GetProperty(thread, objectPrototype, toStringKey).GetValue(); + if (!callback_fn_handle->IsCallable()) { + JSHandle env = ecma_vm->GetGlobalEnv(); + JSHandle object_prototype = env->GetObjectFunctionPrototype(); + JSHandle to_string_key = thread->GlobalConstants()->GetHandledToStringString(); + callback_fn_handle = JSTaggedValue::GetProperty(thread, object_prototype, to_string_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } auto info = - NewRuntimeCallInfo(thread, callbackFnHandle, thisObjVal, JSTaggedValue::Undefined(), argv->GetArgsNumber()); + NewRuntimeCallInfo(thread, callback_fn_handle, this_obj_val, JSTaggedValue::Undefined(), argv->GetArgsNumber()); if (argv->GetArgsNumber() > 0) { info->SetCallArg(argv->GetArgsNumber(), reinterpret_cast(argv->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS))); } - return JSFunction::Call(info.get()); + return JSFunction::Call(info.Get()); } // 22.1.3.28 Array.prototype.unshift ( ...items ) @@ -2748,20 +2756,20 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Unshift); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 5. Let argCount be the number of actual arguments. uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_handle = GetThis(argv); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - double len = ArrayHelper::GetArrayLength(thread, thisObjVal); + double len = ArrayHelper::GetArrayLength(thread, this_obj_val); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -2786,21 +2794,21 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) if (len + argc > ecmascript::base::MAX_SAFE_INTEGER) { THROW_TYPE_ERROR_AND_RETURN(thread, "out of range.", JSTaggedValue::Exception()); } - JSMutableHandle fromKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle toKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle from_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle to_key(thread, JSTaggedValue::Undefined()); double k = len; while (k > 0) { - fromKey.Update(JSTaggedValue(k - 1)); - toKey.Update(JSTaggedValue(k + argc - 1)); - bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, fromKey); + from_key.Update(JSTaggedValue(k - 1)); + to_key.Update(JSTaggedValue(k + argc - 1)); + bool exists = JSTaggedValue::HasProperty(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (exists) { - JSHandle fromValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, fromKey); + JSHandle from_value = JSArray::FastGetPropertyByValue(thread, this_obj_val, from_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, fromValue); + JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, from_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSTaggedValue::DeletePropertyOrThrow(thread, thisObjVal, toKey); + JSTaggedValue::DeletePropertyOrThrow(thread, this_obj_val, to_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } k--; @@ -2815,24 +2823,24 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) // iv. Increase j by 1. double j = 0; while (j < argc) { - toKey.Update(JSTaggedValue(j)); - JSHandle toValue = GetCallArg(argv, j); - JSArray::FastSetPropertyByValue(thread, thisObjVal, toKey, toValue); + to_key.Update(JSTaggedValue(j)); + JSHandle to_value = GetCallArg(argv, j); + JSArray::FastSetPropertyByValue(thread, this_obj_val, to_key, to_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); j++; } } // 7. Let setStatus be Set(O, "length", len+argCount, true). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - double newLen = len + argc; - JSHandle newLenHandle(thread, JSTaggedValue(newLen)); - JSTaggedValue::SetProperty(thread, thisObjVal, lengthKey, newLenHandle, true); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + double new_len = len + argc; + JSHandle new_len_handle(thread, JSTaggedValue(new_len)); + JSTaggedValue::SetProperty(thread, this_obj_val, length_key, new_len_handle, true); // 8. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. Return len+argCount. - return GetTaggedDouble(newLen); + return GetTaggedDouble(new_len); } // 22.1.3.29 Array.prototype.values ( ) @@ -2841,7 +2849,7 @@ JSTaggedValue BuiltinsArray::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Array, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be ToObject(this value). // 2. ReturnIfAbrupt(O). @@ -2855,43 +2863,43 @@ JSTaggedValue BuiltinsArray::Values(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsArray::Unscopables(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle nullHandle(thread, JSTaggedValue::Null()); - JSHandle unscopableList = factory->OrdinaryNewJSObjectCreate(nullHandle); + JSHandle null_handle(thread, JSTaggedValue::Null()); + JSHandle unscopable_list = factory->OrdinaryNewJSObjectCreate(null_handle); - JSHandle trueVal(thread, JSTaggedValue::True()); - JSHandle copyWithKey(factory->NewFromCanBeCompressString("copyWithin")); - JSObject::CreateDataProperty(thread, unscopableList, copyWithKey, trueVal); + JSHandle true_val(thread, JSTaggedValue::True()); + JSHandle copy_with_key(factory->NewFromCanBeCompressString("copyWithin")); + JSObject::CreateDataProperty(thread, unscopable_list, copy_with_key, true_val); - JSHandle entriesKey(factory->NewFromCanBeCompressString("entries")); - JSObject::CreateDataProperty(thread, unscopableList, entriesKey, trueVal); + JSHandle entries_key(factory->NewFromCanBeCompressString("entries")); + JSObject::CreateDataProperty(thread, unscopable_list, entries_key, true_val); - JSHandle fillKey(factory->NewFromCanBeCompressString("fill")); - JSObject::CreateDataProperty(thread, unscopableList, fillKey, trueVal); + JSHandle fill_key(factory->NewFromCanBeCompressString("fill")); + JSObject::CreateDataProperty(thread, unscopable_list, fill_key, true_val); - JSHandle findKey(factory->NewFromCanBeCompressString("find")); - JSObject::CreateDataProperty(thread, unscopableList, findKey, trueVal); + JSHandle find_key(factory->NewFromCanBeCompressString("find")); + JSObject::CreateDataProperty(thread, unscopable_list, find_key, true_val); - JSHandle findIndexKey(factory->NewFromCanBeCompressString("findIndex")); - JSObject::CreateDataProperty(thread, unscopableList, findIndexKey, trueVal); + JSHandle find_index_key(factory->NewFromCanBeCompressString("findIndex")); + JSObject::CreateDataProperty(thread, unscopable_list, find_index_key, true_val); - JSHandle flatKey(factory->NewFromCanBeCompressString("flat")); - JSObject::CreateDataProperty(thread, unscopableList, flatKey, trueVal); + JSHandle flat_key(factory->NewFromCanBeCompressString("flat")); + JSObject::CreateDataProperty(thread, unscopable_list, flat_key, true_val); - JSHandle flatMapKey(factory->NewFromCanBeCompressString("flatMap")); - JSObject::CreateDataProperty(thread, unscopableList, flatMapKey, trueVal); + JSHandle flat_map_key(factory->NewFromCanBeCompressString("flatMap")); + JSObject::CreateDataProperty(thread, unscopable_list, flat_map_key, true_val); - JSHandle includesKey(factory->NewFromCanBeCompressString("includes")); - JSObject::CreateDataProperty(thread, unscopableList, includesKey, trueVal); + JSHandle includes_key(factory->NewFromCanBeCompressString("includes")); + JSObject::CreateDataProperty(thread, unscopable_list, includes_key, true_val); - JSHandle keysKey(factory->NewFromCanBeCompressString("keys")); - JSObject::CreateDataProperty(thread, unscopableList, keysKey, trueVal); + JSHandle keys_key(factory->NewFromCanBeCompressString("keys")); + JSObject::CreateDataProperty(thread, unscopable_list, keys_key, true_val); - JSHandle valuesKey(factory->NewFromCanBeCompressString("values")); - JSObject::CreateDataProperty(thread, unscopableList, valuesKey, trueVal); + JSHandle values_key(factory->NewFromCanBeCompressString("values")); + JSObject::CreateDataProperty(thread, unscopable_list, values_key, true_val); - return unscopableList.GetTaggedValue(); + return unscopable_list.GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_arraybuffer.cpp b/runtime/builtins/builtins_arraybuffer.cpp index dc691d52d86634aff27fb0964f32a072058f1bef..4111ab24baf5ca79daba94138b7974e8eaae18fd 100644 --- a/runtime/builtins/builtins_arraybuffer.cpp +++ b/runtime/builtins/builtins_arraybuffer.cpp @@ -38,16 +38,16 @@ JSTaggedValue BuiltinsArrayBuffer::ArrayBufferConstructor(EcmaRuntimeCallInfo *a ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayBuffer, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle new_target = 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 lengthHandle = GetCallArg(argv, 0); - JSTaggedNumber lenNum = JSTaggedValue::ToIndex(thread, lengthHandle); + JSHandle length_handle = GetCallArg(argv, 0); + JSTaggedNumber len_num = JSTaggedValue::ToIndex(thread, length_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double length = lenNum.GetNumber(); + double length = len_num.GetNumber(); return AllocateArrayBuffer(thread, new_target, length); } @@ -55,7 +55,7 @@ JSTaggedValue BuiltinsArrayBuffer::ArrayBufferConstructor(EcmaRuntimeCallInfo *a JSTaggedValue BuiltinsArrayBuffer::IsView(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSHandle arg = GetCallArg(argv, 0); // 1. If Type(arg) is not Object, return false. if (!arg->IsECMAObject()) { @@ -80,25 +80,25 @@ JSTaggedValue BuiltinsArrayBuffer::Species(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsArrayBuffer::GetByteLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSThread *thread = argv->GetThread(); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an object", JSTaggedValue::Exception()); } // 3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. - if (!thisHandle->IsArrayBuffer()) { + if (!this_handle->IsArrayBuffer()) { THROW_TYPE_ERROR_AND_RETURN(thread, "don't have internal slot", JSTaggedValue::Exception()); } // 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(this_handle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "IsDetachedBuffer", JSTaggedValue::Exception()); } - JSHandle arrBuf(thisHandle); + JSHandle arr_buf(this_handle); // 5. Let length be the value of O’s [[ArrayBufferByteLength]] internal slot. - JSTaggedValue length = arrBuf->GetArrayBufferByteLength(); + JSTaggedValue length = arr_buf->GetArrayBufferByteLength(); // 6. Return length. return JSTaggedValue(length); } @@ -109,34 +109,34 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayBuffer, Slice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsObject()) { + if (!this_handle->IsObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an object", JSTaggedValue::Exception()); } - JSHandle arrBuf(thisHandle); + JSHandle arr_buf(this_handle); // 3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. - if (!thisHandle->IsArrayBuffer()) { + if (!this_handle->IsArrayBuffer()) { THROW_TYPE_ERROR_AND_RETURN(thread, "don't have internal slot", JSTaggedValue::Exception()); } // 4. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(this_handle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } // 5. Let len be the value of O’s [[ArrayBufferByteLength]] internal slot. - JSTaggedNumber lengthNum = JSTaggedNumber::FromIntOrDouble(thread, arrBuf->GetArrayBufferByteLength()); + JSTaggedNumber length_num = JSTaggedNumber::FromIntOrDouble(thread, arr_buf->GetArrayBufferByteLength()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle startHandle = GetCallArg(argv, 0); + JSHandle start_handle = GetCallArg(argv, 0); // 6. Let relativeStart be ToInteger(start). - JSTaggedNumber relativeStart = JSTaggedValue::ToInteger(thread, startHandle); + JSTaggedNumber relative_start = JSTaggedValue::ToInteger(thread, start_handle); // 7. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t len = lengthNum.ToInt32(); - int32_t start = ecmascript::base::NumberHelper::DoubleInRangeInt32(relativeStart.GetNumber()); + int32_t len = length_num.ToInt32(); + int32_t start = ecmascript::base::NumberHelper::DoubleInRangeInt32(relative_start.GetNumber()); int32_t end; int32_t first; int32_t last; @@ -147,14 +147,14 @@ 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 endHandle = GetCallArg(argv, 1); - if (endHandle->IsUndefined()) { + JSHandle end_handle = GetCallArg(argv, 1); + if (end_handle->IsUndefined()) { end = len; } else { - JSTaggedNumber relativeEnd = JSTaggedValue::ToInteger(thread, endHandle); + JSTaggedNumber relative_end = JSTaggedValue::ToInteger(thread, end_handle); // 10. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = ecmascript::base::NumberHelper::DoubleInRangeInt32(relativeEnd.GetNumber()); + end = ecmascript::base::NumberHelper::DoubleInRangeInt32(relative_end.GetNumber()); } // 11. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). if (end < 0) { @@ -163,61 +163,61 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) last = std::min(end, len); } // 12. Let newLen be max(final-first,0). - int32_t newLen = std::max((last - first), 0); + int32_t new_len = std::max((last - first), 0); // 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). - JSHandle defaultConstructor = env->GetArrayBufferFunction(); - JSHandle objHandle(thisHandle); - JSHandle constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); + JSHandle default_constructor = env->GetArrayBufferFunction(); + JSHandle obj_handle(this_handle); + JSHandle constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); // 14. ReturnIfAbrupt(ctor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 15. Let new be Construct(ctor, «newLen»). - JSHandle undefined = globalConst->GetHandledUndefined(); + JSHandle undefined = global_const->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), undefined, 1); - info->SetCallArgs(JSTaggedValue(newLen)); - JSTaggedValue taggedNewArrBuf = JSFunction::Construct(info.get()); - JSHandle newArrBuf(thread, taggedNewArrBuf); + info->SetCallArgs(JSTaggedValue(new_len)); + JSTaggedValue tagged_new_arr_buf = JSFunction::Construct(info.Get()); + JSHandle new_arr_buf(thread, tagged_new_arr_buf); // 16. ReturnIfAbrupt(new). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 17. If new does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. - if (!newArrBuf->IsArrayBuffer()) { + if (!new_arr_buf->IsArrayBuffer()) { THROW_TYPE_ERROR_AND_RETURN(thread, "don't have bufferdata internal slot", JSTaggedValue::Exception()); } // 18. If IsDetachedBuffer(new) is true, throw a TypeError exception. - if (IsDetachedBuffer(newArrBuf.GetTaggedValue())) { + if (IsDetachedBuffer(new_arr_buf.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "new arrayBuffer IsDetachedBuffer", JSTaggedValue::Exception()); } // 19. If SameValue(new, O) is true, throw a TypeError exception. - if (JSTaggedValue::SameValue(newArrBuf.GetTaggedValue(), thisHandle.GetTaggedValue())) { + if (JSTaggedValue::SameValue(new_arr_buf.GetTaggedValue(), this_handle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "value of new arraybuffer and this is same", JSTaggedValue::Exception()); } - JSHandle newJsArrBuf(newArrBuf); + JSHandle new_js_arr_buf(new_arr_buf); // 20. If the value of new’s [[ArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. - JSTaggedNumber newLengthNum = JSTaggedNumber::FromIntOrDouble(thread, newJsArrBuf->GetArrayBufferByteLength()); - int32_t newArrBufLen = newLengthNum.ToInt32(); - if (newArrBufLen < newLen) { + JSTaggedNumber new_length_num = JSTaggedNumber::FromIntOrDouble(thread, new_js_arr_buf->GetArrayBufferByteLength()); + int32_t new_arr_buf_len = new_length_num.ToInt32(); + if (new_arr_buf_len < new_len) { THROW_TYPE_ERROR_AND_RETURN(thread, "new array buffer length smaller than newlen", JSTaggedValue::Exception()); } // 21. NOTE: Side-effects of the above steps may have detached O. // 22. If IsDetachedBuffer(O) is true, throw a TypeError exception. - if (IsDetachedBuffer(thisHandle.GetTaggedValue())) { + if (IsDetachedBuffer(this_handle.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception()); } - if (newLen > 0) { + if (new_len > 0) { // 23. Let fromBuf be the value of O’s [[ArrayBufferData]] internal slot. - JSTaggedValue from = arrBuf->GetArrayBufferData(); + JSTaggedValue from = arr_buf->GetArrayBufferData(); // 24. Let toBuf be the value of new’s [[ArrayBufferData]] internal slot. - JSTaggedValue to = newJsArrBuf->GetArrayBufferData(); + JSTaggedValue to = new_js_arr_buf->GetArrayBufferData(); // 25. Perform CopyDataBlockBytes(toBuf, fromBuf, first, newLen). - JSArrayBuffer::CopyDataBlockBytes(to, from, first, newLen); + JSArrayBuffer::CopyDataBlockBytes(to, from, first, new_len); } // Return new. - return newArrBuf.GetTaggedValue(); + return new_arr_buf.GetTaggedValue(); } // 24.1.1.1 AllocateArrayBuffer(constructor, byteLength) JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const JSHandle &new_target, - double byteLength) + double byte_length) { BUILTINS_API_TRACE(thread, ArrayBuffer, AllocateArrayBuffer); /** @@ -226,135 +226,138 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J * */ ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - JSHandle arrBufFunc = env->GetArrayBufferFunction(); + JSHandle arr_buf_func = env->GetArrayBufferFunction(); JSHandle obj; if (!new_target->IsBoundFunction()) { - obj = factory->NewJSObjectByConstructor(JSHandle(arrBufFunc), new_target); + obj = factory->NewJSObjectByConstructor(JSHandle(arr_buf_func), new_target); // 2. ReturnIfAbrupt RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSHandle prototypeKey = thread->GlobalConstants()->GetHandledPrototypeString(); - JSHandle constructTag(new_target); - JSHandle constructProto = - JSTaggedValue::GetProperty(thread, constructTag, prototypeKey).GetValue(); - obj = JSObject::ObjectCreate(thread, JSHandle(constructProto)); + JSHandle prototype_key = thread->GlobalConstants()->GetHandledPrototypeString(); + JSHandle construct_tag(new_target); + JSHandle construct_proto = + JSTaggedValue::GetProperty(thread, construct_tag, prototype_key).GetValue(); + obj = JSObject::ObjectCreate(thread, JSHandle(construct_proto)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 3. Assert: byteLength is a positive integer. - ASSERT(JSTaggedValue(byteLength).IsInteger()); - ASSERT(byteLength >= 0); + ASSERT(JSTaggedValue(byte_length).IsInteger()); + ASSERT(byte_length >= 0); // 4. Let block be CreateByteDataBlock(byteLength). - if (byteLength > INT_MAX) { + if (byte_length > INT_MAX) { THROW_RANGE_ERROR_AND_RETURN(thread, "Out of range", JSTaggedValue::Exception()); } - JSHandle arrayBuffer(obj); + JSHandle array_buffer(obj); // 6. Set obj’s [[ArrayBufferData]] internal slot to block. - factory->NewJSArrayBufferData(arrayBuffer, byteLength); + factory->NewJSArrayBufferData(array_buffer, byte_length); // 7. Set obj’s [[ArrayBufferByteLength]] internal slot to byteLength. - arrayBuffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byteLength))); + array_buffer->SetArrayBufferByteLength(thread, JSTaggedValue(static_cast(byte_length))); // 8. Return obj. - return arrayBuffer.GetTaggedValue(); + return array_buffer.GetTaggedValue(); } // 24.1.1.2 IsDetachedBuffer() -bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue arrayBuffer) +bool BuiltinsArrayBuffer::IsDetachedBuffer(JSTaggedValue array_buffer) { // 1. Assert: Type(arrayBuffer) is Object and it has an [[ArrayBufferData]] internal slot. - ASSERT(arrayBuffer.IsArrayBuffer()); - JSArrayBuffer *buffer = JSArrayBuffer::Cast(arrayBuffer.GetTaggedObject()); - JSTaggedValue dataSlot = buffer->GetArrayBufferData(); + ASSERT(array_buffer.IsArrayBuffer()); + JSArrayBuffer *buffer = JSArrayBuffer::Cast(array_buffer.GetTaggedObject()); + JSTaggedValue data_slot = buffer->GetArrayBufferData(); // 2. If arrayBuffer’s [[ArrayBufferData]] internal slot is null, return true. // 3. Return false. - return dataSlot == JSTaggedValue::Null(); + return data_slot == JSTaggedValue::Null(); } // 24.1.1.4 -JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHandle &srcBuffer, - int32_t srcByteOffset, JSHandle constructor) +JSTaggedValue BuiltinsArrayBuffer::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. - ASSERT(srcBuffer->IsArrayBuffer()); + ASSERT(src_buffer->IsArrayBuffer()); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 2. If cloneConstructor is not present if (constructor->IsUndefined()) { // a. Let cloneConstructor be SpeciesConstructor(srcBuffer, %ArrayBuffer%). - JSHandle defaultConstructor = env->GetArrayBufferFunction(); - JSHandle objHandle(srcBuffer); - constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); + JSHandle default_constructor = env->GetArrayBufferFunction(); + JSHandle obj_handle(src_buffer); + constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); // b. ReturnIfAbrupt(cloneConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (IsDetachedBuffer(src_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } else { ASSERT(constructor->IsConstructor()); } } // 4. Let srcLength be the value of srcBuffer’s [[ArrayBufferByteLength]] internal slot. - JSHandle arrBuf(srcBuffer); - JSTaggedNumber lengthNumber = JSTaggedNumber::FromIntOrDouble(thread, arrBuf->GetArrayBufferByteLength()); - int32_t srcLen = lengthNumber.ToInt32(); + JSHandle arr_buf(src_buffer); + JSTaggedNumber length_number = JSTaggedNumber::FromIntOrDouble(thread, arr_buf->GetArrayBufferByteLength()); + int32_t src_len = length_number.ToInt32(); // 5. Assert: srcByteOffset ≤ srcLength. - ASSERT(srcByteOffset <= srcLen); + ASSERT(src_byte_offset <= src_len); // 6. Let cloneLength be srcLength – srcByteOffset. - int32_t cloneLen = srcLen - srcByteOffset; + int32_t clone_len = src_len - src_byte_offset; // 8. Let targetBuffer be AllocateArrayBuffer(cloneConstructor, cloneLength). - JSTaggedValue taggedBuf = AllocateArrayBuffer(thread, constructor, cloneLen); + JSTaggedValue tagged_buf = AllocateArrayBuffer(thread, constructor, clone_len); // 9. ReturnIfAbrupt(targetBuffer). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - if (IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + if (IsDetachedBuffer(src_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } // 11. Let targetBlock be the value of targetBuffer’s [[ArrayBufferData]] internal slot. - JSHandle newArrBuf(thread, taggedBuf); + JSHandle new_arr_buf(thread, tagged_buf); // Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength). // 7. Let srcBlock be the value of srcBuffer’s [[ArrayBufferData]] internal slot. - JSTaggedValue srcBlock = arrBuf->GetArrayBufferData(); - JSTaggedValue targetBlock = newArrBuf->GetArrayBufferData(); - if (cloneLen > 0) { - JSArrayBuffer::CopyDataBlockBytes(targetBlock, srcBlock, srcByteOffset, cloneLen); + JSTaggedValue src_block = arr_buf->GetArrayBufferData(); + JSTaggedValue target_block = new_arr_buf->GetArrayBufferData(); + if (clone_len > 0) { + JSArrayBuffer::CopyDataBlockBytes(target_block, src_block, src_byte_offset, clone_len); } - return taggedBuf; + return tagged_buf; } // 24.1.1.5 // NOLINTNEXTLINE(readability-function-size) -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSThread *thread, JSHandle arrBuf, - int32_t byteIndex, DataViewType type, bool littleEndian) +JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSThread *thread, JSHandle arr_buf, + int32_t byte_index, DataViewType type, bool little_endian) { - JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf->GetTaggedObject()); - JSTaggedValue data = jsArrayBuffer->GetArrayBufferData(); + 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[byteIndex]; // NOLINT + uint8_t res = block[byte_index]; // NOLINT return GetTaggedInt(res); } case DataViewType::INT8: { - uint8_t res = block[byteIndex]; // NOLINT - auto int8Res = static_cast(res); - return GetTaggedInt(int8Res); + uint8_t res = block[byte_index]; // NOLINT + auto int8_res = static_cast(res); + return GetTaggedInt(int8_res); } case DataViewType::UINT16: - return GetValueFromBufferForInteger(block, byteIndex, littleEndian); + return GetValueFromBufferForInteger(block, byte_index, little_endian); case DataViewType::INT16: - return GetValueFromBufferForInteger(block, byteIndex, littleEndian); + return GetValueFromBufferForInteger(block, byte_index, little_endian); case DataViewType::UINT32: - return GetValueFromBufferForInteger(block, byteIndex, littleEndian); + return GetValueFromBufferForInteger(block, byte_index, little_endian); case DataViewType::INT32: - return GetValueFromBufferForInteger(block, byteIndex, littleEndian); + return GetValueFromBufferForInteger(block, byte_index, little_endian); case DataViewType::FLOAT32: - return GetValueFromBufferForFloat(block, byteIndex, littleEndian); + return GetValueFromBufferForFloat(block, byte_index, + little_endian); case DataViewType::FLOAT64: - return GetValueFromBufferForFloat(block, byteIndex, littleEndian); + return GetValueFromBufferForFloat(block, byte_index, + little_endian); case DataViewType::BIGINT64: - return GetValueFromBufferForBigInt(thread, block, byteIndex, littleEndian); + return GetValueFromBufferForBigInt(thread, block, byte_index, little_endian); case DataViewType::BIGUINT64: - return GetValueFromBufferForBigInt(thread, block, byteIndex, littleEndian); + return GetValueFromBufferForBigInt(thread, block, byte_index, + little_endian); default: break; } @@ -363,23 +366,23 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBuffer(JSThread *thread, JSHandle } // 24.1.1.6 -JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSThread *thread, JSHandle arrBuf, int32_t byteIndex, - DataViewType type, const JSHandle &value, - bool littleEndian) +JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSThread *thread, JSHandle arr_buf, + int32_t byte_index, DataViewType type, + const JSHandle &value, bool little_endian) { - JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf->GetTaggedObject()); - JSTaggedValue data = jsArrayBuffer->GetArrayBufferData(); + 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, byteIndex, littleEndian); + SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; case DataViewType::BIGUINT64: - SetValueInBufferForBigInt(thread, value, block, byteIndex, littleEndian); + SetValueInBufferForBigInt(thread, value, block, byte_index, little_endian); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; default: @@ -392,31 +395,31 @@ JSTaggedValue BuiltinsArrayBuffer::SetValueInBuffer(JSThread *thread, JSHandle(val, block, byteIndex); + SetValueInBufferForByte(val, block, byte_index); break; case DataViewType::UINT8_CLAMPED: - SetValueInBufferForUint8Clamped(val, block, byteIndex); + SetValueInBufferForUint8Clamped(val, block, byte_index); break; case DataViewType::INT8: - SetValueInBufferForByte(val, block, byteIndex); + SetValueInBufferForByte(val, block, byte_index); break; case DataViewType::UINT16: - SetValueInBufferForInteger(val, block, byteIndex, littleEndian); + SetValueInBufferForInteger(val, block, byte_index, little_endian); break; case DataViewType::INT16: - SetValueInBufferForInteger(val, block, byteIndex, littleEndian); + SetValueInBufferForInteger(val, block, byte_index, little_endian); break; case DataViewType::UINT32: - SetValueInBufferForInteger(val, block, byteIndex, littleEndian); + SetValueInBufferForInteger(val, block, byte_index, little_endian); break; case DataViewType::INT32: - SetValueInBufferForInteger(val, block, byteIndex, littleEndian); + SetValueInBufferForInteger(val, block, byte_index, little_endian); break; case DataViewType::FLOAT32: - SetValueInBufferForFloat(val, block, byteIndex, littleEndian); + SetValueInBufferForFloat(val, block, byte_index, little_endian); break; case DataViewType::FLOAT64: - SetValueInBufferForFloat(val, block, byteIndex, littleEndian); + SetValueInBufferForFloat(val, block, byte_index, little_endian); break; default: UNREACHABLE(); @@ -433,27 +436,27 @@ bool BuiltinsArrayBuffer::IsBigIntElementType(DataViewType type) template void BuiltinsArrayBuffer::SetTypeData(uint8_t *block, T value, int32_t index) { - int32_t sizeCount = sizeof(T); + int32_t size_count = sizeof(T); auto *res = reinterpret_cast(&value); - for (int i = 0; i < sizeCount; i++) { + 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 byteIndex, bool littleEndian) +JSTaggedValue BuiltinsArrayBuffer::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"); + static_assert(sizeof(T) == SIZE, "Invalid number size"); static_assert(sizeof(T) >= sizeof(uint16_t), "T must have a size more than uint8"); // NOLINTNEXTLINE(misc-redundant-expression) - static_assert(size >= NumberSize::UINT16 || size <= NumberSize::FLOAT64); + static_assert(SIZE >= NumberSize::UINT16 || SIZE <= NumberSize::FLOAT64); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - T res = UnalignedLoad(reinterpret_cast(block + byteIndex)); - if (!littleEndian) { + T res = UnalignedLoad(reinterpret_cast(block + byte_index)); + if (!little_endian) { res = BSWAP(res); } @@ -468,128 +471,128 @@ JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForInteger(uint8_t *block, return GetTaggedInt(res); } -template +template // NOLINTNEXTLINE(readability-non-const-parameter) -JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForFloat(uint8_t *block, int32_t byteIndex, bool littleEndian) +JSTaggedValue BuiltinsArrayBuffer::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"); + static_assert(sizeof(T) == SIZE, "Invalid number size"); - UnionType unionValue = {0}; + UnionType union_value = {0}; // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic) - unionValue.uValue = UnalignedLoad(reinterpret_cast(block + byteIndex)); + union_value.u_value = UnalignedLoad(reinterpret_cast(block + byte_index)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - if (std::isnan(unionValue.value)) { + if (std::isnan(union_value.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(unionValue.value); + return GetTaggedDouble(union_value.value); } - if (!littleEndian) { + if (!little_endian) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(bit_cast(BSWAP(unionValue.uValue))); + return GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); } // NOLINTNEXTLINE(readability-misleading-indentation) } else if constexpr (std::is_same_v) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic) - unionValue.uValue = UnalignedLoad(reinterpret_cast(block + byteIndex)); + union_value.u_value = UnalignedLoad(reinterpret_cast(block + byte_index)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - if (std::isnan(unionValue.value) && !JSTaggedValue::IsImpureNaN(unionValue.value)) { + if (std::isnan(union_value.value) && !JSTaggedValue::IsImpureNaN(union_value.value)) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(unionValue.value); + return GetTaggedDouble(union_value.value); } - if (!littleEndian) { + if (!little_endian) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(bit_cast(BSWAP(unionValue.uValue))); + return GetTaggedDouble(bit_cast(BSWAP(union_value.u_value))); } } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access) - return GetTaggedDouble(unionValue.value); + return GetTaggedDouble(union_value.value); } -template +template JSTaggedValue BuiltinsArrayBuffer::GetValueFromBufferForBigInt(JSThread *thread, const uint8_t *block, - uint32_t byteIndex, bool littleEndian) + 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 pTmp = UnalignedLoad(reinterpret_cast(block + byteIndex)); - if (!littleEndian) { - pTmp = BSWAP(pTmp); + 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, pTmp).GetTaggedValue(); + return BigInt::Uint64ToBigInt(thread, p_tmp).GetTaggedValue(); } - return BigInt::Int64ToBigInt(thread, pTmp).GetTaggedValue(); + return BigInt::Int64ToBigInt(thread, p_tmp).GetTaggedValue(); } template -void BuiltinsArrayBuffer::SetValueInBufferForByte(double val, uint8_t *block, int32_t byteIndex) +void BuiltinsArrayBuffer::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; if (std::isnan(val) || std::isinf(val)) { res = 0; - SetTypeData(block, res, byteIndex); + SetTypeData(block, res, byte_index); return; } - auto int64Val = static_cast(val); - res = UnalignedLoad(reinterpret_cast(&int64Val)); - SetTypeData(block, res, byteIndex); + auto int64_val = static_cast(val); + res = UnalignedLoad(reinterpret_cast(&int64_val)); + SetTypeData(block, res, byte_index); } -void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byteIndex) +void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byte_index) { uint8_t res; if (std::isnan(val) || val <= 0) { res = 0; - SetTypeData(block, res, byteIndex); + SetTypeData(block, res, byte_index); return; } val = val >= UINT8_MAX ? UINT8_MAX : val; constexpr double HALF = 0.5; val = val == HALF ? 0 : std::round(val); res = static_cast(val); - SetTypeData(block, res, byteIndex); + SetTypeData(block, res, byte_index); } template -void BuiltinsArrayBuffer::SetValueInBufferForInteger(double val, uint8_t *block, int32_t byteIndex, bool littleEndian) +void BuiltinsArrayBuffer::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"); T res; if (std::isnan(val) || std::isinf(val)) { res = 0; - SetTypeData(block, res, byteIndex); + SetTypeData(block, res, byte_index); return; } - auto int64Val = static_cast(val); + auto int64_val = static_cast(val); // NOLINTNEXTLINE(readability-braces-around-statements) if constexpr (std::is_same_v) { - auto tmp = UnalignedLoad(reinterpret_cast(&int64Val)); + auto tmp = UnalignedLoad(reinterpret_cast(&int64_val)); res = static_cast(tmp); } else { // NOLINTNEXTLINE(readability-braces-around-statements) - res = UnalignedLoad(reinterpret_cast(&int64Val)); + res = UnalignedLoad(reinterpret_cast(&int64_val)); } - if (!littleEndian) { + if (!little_endian) { res = BSWAP(res); } - SetTypeData(block, res, byteIndex); + SetTypeData(block, res, byte_index); } template -void BuiltinsArrayBuffer::SetValueInBufferForFloat(double val, uint8_t *block, int32_t byteIndex, bool littleEndian) +void BuiltinsArrayBuffer::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); if (std::isnan(val)) { - SetTypeData(block, data, byteIndex); + SetTypeData(block, data, byte_index); return; } - if (!littleEndian) { + if (!little_endian) { // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (std::is_same_v) { data = bit_cast(BSWAP(bit_cast(data))); @@ -599,12 +602,12 @@ void BuiltinsArrayBuffer::SetValueInBufferForFloat(double val, uint8_t *block, i data = bit_cast(BSWAP(bit_cast(data))); } } - SetTypeData(block, data, byteIndex); + SetTypeData(block, data, byte_index); } template void BuiltinsArrayBuffer::SetValueInBufferForBigInt(JSThread *thread, const JSHandle &val, - uint8_t *block, uint32_t byteIndex, bool littleEndian) + 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; @@ -617,9 +620,9 @@ void BuiltinsArrayBuffer::SetValueInBufferForBigInt(JSThread *thread, const JSHa BigInt::BigIntToInt64(thread, val, reinterpret_cast(&value), &lossless); } RETURN_IF_ABRUPT_COMPLETION(thread); - if (!littleEndian) { + if (!little_endian) { value = BSWAP(value); } - SetTypeData(block, value, byteIndex); + SetTypeData(block, value, byte_index); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_arraybuffer.h b/runtime/builtins/builtins_arraybuffer.h index 1e63cf59f62a938699176794c50eb9277fde6d86..055431a7d9415405a72fa5d0abffa9560a57c8f1 100644 --- a/runtime/builtins/builtins_arraybuffer.h +++ b/runtime/builtins/builtins_arraybuffer.h @@ -28,11 +28,11 @@ static constexpr uint32_t BITS_FORTY = 40; static constexpr uint32_t BITS_FIFTY_SIX = 56; using DataViewType = ecmascript::DataViewType; union UnionType32 { - uint32_t uValue; + uint32_t u_value; float value; } __attribute__((packed, may_alias)); union UnionType64 { - uint64_t uValue; + uint64_t u_value; double value; } __attribute__((packed, may_alias)); class BuiltinsArrayBuffer : public ecmascript::base::BuiltinsBase { @@ -59,56 +59,56 @@ public: // 24.1.4.3 ArrayBuffer.prototype.slice() static JSTaggedValue Slice(EcmaRuntimeCallInfo *argv); // 24.1.1.2 IsDetachedBuffer(arrayBuffer) - static bool IsDetachedBuffer(JSTaggedValue arrayBuffer); + static bool IsDetachedBuffer(JSTaggedValue array_buffer); // 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type, isLittleEndian ) - static JSTaggedValue GetValueFromBuffer(JSThread *thread, JSHandle arrBuf, int32_t byteIndex, - DataViewType type, bool littleEndian); + 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 arrBuf, int32_t byteIndex, - DataViewType type, const JSHandle &value, bool littleEndian); + 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 &srcBuffer, - int32_t srcByteOffset, JSHandle constructor); + 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 byteLength); + double byte_length); // es12 25.1.2.7 IsBigIntElementType ( type ) static bool IsBigIntElementType(DataViewType type); private: template - static T LittleEndianToBigEndian(T liValue); + static T LittleEndianToBigEndian(T li_value); template - static T LittleEndianToBigEndian64Bit(T liValue); + 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 byteIndex, bool littleEndian); + template + static JSTaggedValue GetValueFromBufferForInteger(uint8_t *block, int32_t byte_index, bool little_endian); - template - static JSTaggedValue GetValueFromBufferForFloat(uint8_t *block, int32_t byteIndex, bool littleEndian); + 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 byteIndex, - bool littleEndian); + 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 byteIndex); + static void SetValueInBufferForByte(double val, uint8_t *block, int32_t byte_index); - static void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byteIndex); + static void SetValueInBufferForUint8Clamped(double val, uint8_t *block, int32_t byte_index); template - static void SetValueInBufferForInteger(double val, uint8_t *block, int32_t byteIndex, bool littleEndian); + 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 byteIndex, bool littleEndian); + 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 byteIndex, bool littleEndian); + uint32_t byte_index, bool little_endian); }; } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_async_from_sync_iterator.cpp b/runtime/builtins/builtins_async_from_sync_iterator.cpp index d12294e38fcd8c00d87a47805758e8407b878484..32c12b34ba9848029ecdffc07102365d50dcb0f9 100644 --- a/runtime/builtins/builtins_async_from_sync_iterator.cpp +++ b/runtime/builtins/builtins_async_from_sync_iterator.cpp @@ -19,20 +19,20 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeNext( JSThread *thread = argv->GetThread(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisObject = GetThis(argv); + JSHandle this_object = GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. - JSHandle asyncFromSyncIteratorObject( - thread, JSAsyncFromSyncIteratorObject::Cast(thisObject->GetHeapObject())); + JSHandle async_from_sync_iterator_object( + thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. - JSHandle iterator(thread, asyncFromSyncIteratorObject->GetIterator()); - JSHandle nextMethod(thread, asyncFromSyncIteratorObject->GetNextMethod()); + JSHandle iterator(thread, async_from_sync_iterator_object->GetIterator()); + JSHandle next_method(thread, async_from_sync_iterator_object->GetNextMethod()); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promiseCapability = + JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -41,21 +41,21 @@ 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, nextMethod, GetCallArg(argv, 0))); + result.Update(JSIterator::IteratorNext(thread, iterator, next_method, GetCallArg(argv, 0))); } else { // 6. Else, // a. Let result be IteratorNext(syncIteratorRecord). - result.Update(JSIterator::IteratorNext(thread, iterator, nextMethod)); + result.Update(JSIterator::IteratorNext(thread, iterator, next_method)); } // 7. IfAbruptRejectPromise(result, promiseCapability). if (UNLIKELY(thread->HasPendingException())) { result.Update(JSPromise::IfThrowGetThrowValue(thread)); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); // 8. Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). - return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promiseCapability); + return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promise_capability); } // 27.1.4.2.3 %AsyncFromSyncIteratorPrototype%.return(value) @@ -65,86 +65,86 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeRetur JSThread *thread = argv->GetThread(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); + const GlobalEnvConstants *global_constants = thread->GlobalConstants(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisObject = GetThis(argv); + JSHandle this_object = GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. - JSHandle asyncFromSyncIteratorObject( - thread, JSAsyncFromSyncIteratorObject::Cast(thisObject->GetHeapObject())); + JSHandle async_from_sync_iterator_object( + thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promiseCapability = + JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. - JSHandle iterator(thread, asyncFromSyncIteratorObject->GetIterator()); + JSHandle iterator(thread, async_from_sync_iterator_object->GetIterator()); // 5. Let return be GetMethod(syncIterator, "return"). - JSHandle returnKey = globalConstants->GetHandledReturnString(); - JSHandle returnMethod = JSObject::GetMethod(thread, iterator, returnKey); + JSHandle return_key = global_constants->GetHandledReturnString(); + JSHandle return_method = JSObject::GetMethod(thread, iterator, return_key); // 6. IfAbruptRejectPromise(return, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, returnMethod, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, return_method, promise_capability); // 7. If return is undefined, then - if (returnMethod->IsUndefined()) { + if (return_method->IsUndefined()) { // a. Let iterResult be ! CreateIterResultObject(value, true). - JSHandle iterResult = JSIterator::CreateIterResultObject(thread, GetCallArg(argv, 0), true); + JSHandle iter_result = JSIterator::CreateIterResultObject(thread, GetCallArg(argv, 0), true); // b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »). - JSHandle resolve(thread, promiseCapability->GetResolve()); + JSHandle resolve(thread, promise_capability->GetResolve()); auto info = NewRuntimeCallInfo(thread, resolve, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(iterResult); - [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.get()); + info->SetCallArgs(iter_result); + [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); // c. Return promiseCapability.[[Promise]]. - return promiseCapability->GetPromise(); + return promise_capability->GetPromise(); } - JSMutableHandle result(thread, globalConstants->GetHandledUndefined()); + JSMutableHandle result(thread, global_constants->GetHandledUndefined()); { ScopedCallInfo info; // 8. If value is present, then if (argv->GetArgsNumber() > 0) { // a. Let result be Call(return, syncIterator, « value »). - info = NewRuntimeCallInfo(thread, returnMethod, iterator, JSTaggedValue::Undefined(), 1); + info = NewRuntimeCallInfo(thread, return_method, iterator, JSTaggedValue::Undefined(), 1); info->SetCallArgs(GetCallArg(argv, 0)); } else { // 9. Else, // a. Let result be Call(return, syncIterator). - info = NewRuntimeCallInfo(thread, returnMethod, iterator, JSTaggedValue::Undefined(), 0); + info = NewRuntimeCallInfo(thread, return_method, iterator, JSTaggedValue::Undefined(), 0); } - result.Update(JSFunction::Call(info.get())); + result.Update(JSFunction::Call(info.Get())); } // 10. IfAbruptRejectPromise(result, promiseCapability). if (UNLIKELY(thread->HasPendingException())) { result.Update(JSPromise::IfThrowGetThrowValue(thread)); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); // 11. If Type(result) is not Object, then if (!result->IsECMAObject()) { // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "Return is not an object"); - JSHandle reject(thread, promiseCapability->GetReject()); + JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "Return is not an object"); + JSHandle reject(thread, promise_capability->GetReject()); auto info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(typeError); - [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.get()); + info->SetCallArgs(type_error); + [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info.Get()); // b. Return promiseCapability.[[Promise]]. - return promiseCapability->GetPromise(); + return promise_capability->GetPromise(); } // 12. Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). - return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promiseCapability); + return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promise_capability); } // 27.1.4.2.4 %AsyncFromSyncIteratorPrototype%.throw(exception) @@ -155,35 +155,35 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow JSThread *thread = argv->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); - const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); + const GlobalEnvConstants *global_constants = thread->GlobalConstants(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisObject = GetThis(argv); + JSHandle this_object = GetThis(argv); // 2. Assert: Type(O) is Object and O has a [[SyncIteratorRecord]] internal slot. - JSHandle asyncFromSyncIteratorObject( - thread, JSAsyncFromSyncIteratorObject::Cast(thisObject->GetHeapObject())); + JSHandle async_from_sync_iterator_object( + thread, JSAsyncFromSyncIteratorObject::Cast(this_object->GetHeapObject())); // 3. Let promiseCapability be ! NewPromiseCapability(%Promise%). - JSHandle promiseCapability = + JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, JSHandle::Cast(env->GetPromiseFunction())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let syncIteratorRecord be O.[[SyncIteratorRecord]]. - JSHandle iterator(thread, asyncFromSyncIteratorObject->GetIterator()); + JSHandle iterator(thread, async_from_sync_iterator_object->GetIterator()); // 5. Let return be GetMethod(syncIterator, "throw"). - JSHandle throwKey = globalConstants->GetHandledThrowString(); - JSHandle throwMethod = JSObject::GetMethod(thread, iterator, throwKey); + JSHandle throw_key = global_constants->GetHandledThrowString(); + JSHandle throw_method = JSObject::GetMethod(thread, iterator, throw_key); // 6. IfAbruptRejectPromise(return, promiseCapability). - RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, throwMethod, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT_THROWN_VALUE(thread, throw_method, promise_capability); // 7. If throw is undefined, then - if (throwMethod->IsUndefined()) { + if (throw_method->IsUndefined()) { // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »). - JSHandle reject(thread, promiseCapability->GetReject()); + JSHandle reject(thread, promise_capability->GetReject()); ScopedCallInfo info; if (argv->GetArgsNumber() > 0) { info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); @@ -191,48 +191,48 @@ JSTaggedValue BuiltinsAsyncFromSyncIterator::AsyncFromSyncIteratorPrototypeThrow } else { info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 0); } - [[maybe_unused]] JSTaggedValue callResult = JSFunction::Call(info.get()); + [[maybe_unused]] JSTaggedValue call_result = JSFunction::Call(info.Get()); // b. Return promiseCapability.[[Promise]]. - return promiseCapability->GetPromise(); + return promise_capability->GetPromise(); } - JSMutableHandle result(thread, globalConstants->GetHandledUndefined()); + JSMutableHandle result(thread, global_constants->GetHandledUndefined()); { ScopedCallInfo info; // 8. If value is present, then if (argv->GetArgsNumber() > 0) { // a. Let result be Call(throw, syncIterator, « value »). - info = NewRuntimeCallInfo(thread, throwMethod, iterator, JSTaggedValue::Undefined(), 1); + info = NewRuntimeCallInfo(thread, throw_method, iterator, JSTaggedValue::Undefined(), 1); info->SetCallArgs(GetCallArg(argv, 0)); } else { // 9. Else, // a. Let result be Call(throw, syncIterator). - info = NewRuntimeCallInfo(thread, throwMethod, iterator, JSTaggedValue::Undefined(), 0); + info = NewRuntimeCallInfo(thread, throw_method, iterator, JSTaggedValue::Undefined(), 0); } - result.Update(JSFunction::Call(info.get())); + result.Update(JSFunction::Call(info.Get())); } // 10. IfAbruptRejectPromise(result, promiseCapability). if (UNLIKELY(thread->HasPendingException())) { result.Update(JSPromise::IfThrowGetThrowValue(thread)); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); // 11. If Type(result) is not Object, then if (!result->IsECMAObject()) { // a. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).. - JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "Throw is not an object"); - JSHandle reject(thread, promiseCapability->GetReject()); + JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "Throw is not an object"); + JSHandle reject(thread, promise_capability->GetReject()); auto info = NewRuntimeCallInfo(thread, reject, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(typeError); - [[maybe_unused]] JSTaggedValue callResult = JSFunction::Call(info.get()); + info->SetCallArgs(type_error); + [[maybe_unused]] JSTaggedValue call_result = JSFunction::Call(info.Get()); // b. Return promiseCapability.[[Promise]]. - return promiseCapability->GetPromise(); + return promise_capability->GetPromise(); } // 12. Return ! AsyncFromSyncIteratorContinuation(result, promiseCapability). - return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promiseCapability); + return JSAsyncFromSyncIteratorObject::AsyncFromSyncIteratorContinuation(thread, result, promise_capability); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_async_generator.cpp b/runtime/builtins/builtins_async_generator.cpp index dd3d44a8d86dda499fddbb876b5f1cb7898f464e..f239ac69c6e7af113eb2fc6a8607a283de5d458a 100644 --- a/runtime/builtins/builtins_async_generator.cpp +++ b/runtime/builtins/builtins_async_generator.cpp @@ -21,16 +21,17 @@ JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeNext(EcmaRuntimeCal BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Next); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle generator = GetThis(argv); // 2. Let completion be NormalCompletion(value). JSHandle value = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::NORMAL, value); + JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::NORMAL, value); // 3. Return ! AsyncGeneratorEnqueue(generator, completion, empty). - JSHandle result = JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completionRecord); + JSHandle result = + JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completion_record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -41,16 +42,17 @@ JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeReturn(EcmaRuntimeC BUILTINS_API_TRACE(argv->GetThread(), AsyncGeneratorPrototype, Return); // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle generator = GetThis(argv); // 2. Let completion be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. JSHandle value = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::RETURN, value); + JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::RETURN, value); // 3. Return ! AsyncGeneratorEnqueue(generator, completion, empty). - JSHandle result = JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completionRecord); + JSHandle result = + JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completion_record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -62,16 +64,17 @@ JSTaggedValue BuiltinsAsyncGenerator::AsyncGeneratorPrototypeThrow(EcmaRuntimeCa // 1.Let generator be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle generator = GetThis(argv); // 2. Let completion be ThrowCompletion(exception). JSHandle value = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::THROW, value); + JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::THROW, value); // 3. Return ! AsyncGeneratorEnqueue(generator, completion, empty). - JSHandle result = JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completionRecord); + JSHandle result = + JSAsyncGeneratorObject::AsyncGeneratorEnqueue(thread, generator, completion_record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_bigint.cpp b/runtime/builtins/builtins_bigint.cpp index f2403df5f4bfdb352bb53b7cbd935ad542bcb8d0..3f8aeb7b2478f82f4d7c79c1e2a592839c84385f 100644 --- a/runtime/builtins/builtins_bigint.cpp +++ b/runtime/builtins/builtins_bigint.cpp @@ -26,18 +26,18 @@ JSTaggedValue BuiltinsBigInt::BigIntConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, Constructor); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle newTarget = GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle new_target = GetNewTarget(argv); // 1. If NewTarget is not undefined, throw a TypeError exception. JSHandle value = GetCallArg(argv, 0); - if (!newTarget->IsUndefined()) { + if (!new_target->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "BigInt is not a constructor", JSTaggedValue::Exception()); } // 2. Let prim be ? ToPrimitive(value). - JSHandle Primitive(thread, JSTaggedValue::ToPrimitive(thread, value)); + JSHandle primitive(thread, JSTaggedValue::ToPrimitive(thread, value)); // 3. If Type(prim) is Number, return ? NumberToBigInt(prim). - if (Primitive->IsNumber()) { - return BigInt::NumberToBigInt(thread, Primitive); + if (primitive->IsNumber()) { + return BigInt::NumberToBigInt(thread, primitive); } // 4. Otherwise, return ? ToBigInt(value). return JSTaggedValue::ToBigInt(thread, value); @@ -48,17 +48,17 @@ JSTaggedValue BuiltinsBigInt::AsUintN(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, AsUintN); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle bits = GetCallArg(argv, 0); JSHandle bigint = GetCallArg(argv, 1); // 1. Let bits be ? ToIndex(bits). JSTaggedNumber index = JSTaggedValue::ToIndex(thread, bits); // 2. Let bigint be ? ToBigInt(bigint). - JSTaggedValue jsBigint = JSTaggedValue::ToBigInt(thread, bigint); + JSTaggedValue js_bigint = JSTaggedValue::ToBigInt(thread, bigint); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle jsBigintVal(thread, jsBigint); + JSHandle js_bigint_val(thread, js_bigint); // 3. Return a BigInt representing bigint modulo 2bits. - return BigInt::AsUintN(thread, index, jsBigintVal); + return BigInt::AsUintN(thread, index, js_bigint_val); } JSTaggedValue BuiltinsBigInt::AsIntN(EcmaRuntimeCallInfo *argv) @@ -66,18 +66,18 @@ JSTaggedValue BuiltinsBigInt::AsIntN(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, AsIntN); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle bits = GetCallArg(argv, 0); JSHandle bigint = GetCallArg(argv, 1); // 1. Let bits be ? ToIndex(bits). JSTaggedNumber index = JSTaggedValue::ToIndex(thread, bits); // 2. Let bigint be ? ToBigInt(bigint). - JSTaggedValue jsBigint = JSTaggedValue::ToBigInt(thread, bigint); + JSTaggedValue js_bigint = JSTaggedValue::ToBigInt(thread, bigint); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle jsBigintVal(thread, jsBigint); + JSHandle js_bigint_val(thread, js_bigint); // 3. Let mod be ℝ(bigint) modulo 2bits. // 4. If mod ≥ 2bits - 1, return ℤ(mod - 2bits); otherwise, return ℤ(mod). - return BigInt::AsintN(thread, index, jsBigintVal); + return BigInt::AsintN(thread, index, js_bigint_val); } JSTaggedValue BuiltinsBigInt::ToLocaleString(EcmaRuntimeCallInfo *argv) @@ -85,24 +85,24 @@ JSTaggedValue BuiltinsBigInt::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, ToLocaleString); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? ThisBigIntValue(this value). JSTaggedValue value = ThisBigIntValue(argv); - JSHandle thisVal(thread, value); + JSHandle this_val(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let numberFormat be ? Construct(%NumberFormat%, « locales, options »). JSHandle ctor = thread->GetEcmaVM()->GetGlobalEnv()->GetNumberFormatFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); - JSHandle numberFormat = JSHandle::Cast(obj); + JSHandle number_format = JSHandle::Cast(obj); JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); + JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatNumeric(numberFormat, x). - JSHandle result = JSNumberFormat::FormatNumeric(thread, numberFormat, thisVal.GetTaggedValue()); + JSHandle result = JSNumberFormat::FormatNumeric(thread, number_format, this_val.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -112,20 +112,20 @@ JSTaggedValue BuiltinsBigInt::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, ToString); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisBigIntValue(this value). JSTaggedValue value = ThisBigIntValue(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisBigint(thread, value); + JSHandle this_bigint(thread, value); // 2. If radix is not present, let radixNumber be 10 double radix = base::DECIMAL; - JSHandle radixValue = GetCallArg(argv, 0); + JSHandle radix_value = GetCallArg(argv, 0); // 3. Else, let radixNumber be ? ToIntegerOrInfinity(radix). - if (!radixValue->IsUndefined()) { - JSTaggedNumber radixNumber = JSTaggedValue::ToInteger(thread, radixValue); + if (!radix_value->IsUndefined()) { + JSTaggedNumber radix_number = JSTaggedValue::ToInteger(thread, radix_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - radix = radixNumber.GetNumber(); + radix = radix_number.GetNumber(); } // 4. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. if (radix < base::MIN_RADIX || radix > base::MAX_RADIX) { @@ -134,10 +134,10 @@ JSTaggedValue BuiltinsBigInt::ToString(EcmaRuntimeCallInfo *argv) } // 5. If radixNumber = 10, return ToString(x). if (radix == base::DECIMAL) { - return BigInt::ToString(thread, thisBigint).GetTaggedValue(); + return BigInt::ToString(thread, this_bigint).GetTaggedValue(); } // 6. Return the String representation of this BigInt value using the radix specified by radixNumber - return BigInt::ToString(thread, thisBigint, static_cast(radix)).GetTaggedValue(); + return BigInt::ToString(thread, this_bigint, static_cast(radix)).GetTaggedValue(); } JSTaggedValue BuiltinsBigInt::ValueOf(EcmaRuntimeCallInfo *argv) @@ -145,7 +145,7 @@ JSTaggedValue BuiltinsBigInt::ValueOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, BigInt, ValueOf); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisBigIntValue(this value). return ThisBigIntValue(argv); } diff --git a/runtime/builtins/builtins_boolean.cpp b/runtime/builtins/builtins_boolean.cpp index 406ebdd23c80271283e1a62231798bf4a268e36e..b2bed8c1528c44808b5545e3b1605a36df258d52 100644 --- a/runtime/builtins/builtins_boolean.cpp +++ b/runtime/builtins/builtins_boolean.cpp @@ -27,21 +27,21 @@ JSTaggedValue BuiltinsBoolean::BooleanConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Boolean, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let b be ToBoolean(value). - bool boolValue = GetCallArg(argv, 0)->ToBoolean(); + bool bool_value = GetCallArg(argv, 0)->ToBoolean(); // 2. If NewTarget is undefined, return b. JSHandle new_target = GetNewTarget(argv); if (new_target->IsUndefined()) { - return GetTaggedBoolean(boolValue); + return 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 result = factory->NewJSObjectByConstructor(ctor, new_target); - JSTaggedValue objValue = boolValue ? JSTaggedValue::True() : JSTaggedValue::False(); - JSPrimitiveRef::Cast(*result)->SetValue(thread, objValue); + JSTaggedValue obj_value = bool_value ? JSTaggedValue::True() : JSTaggedValue::False(); + JSPrimitiveRef::Cast(*result)->SetValue(thread, obj_value); // 4. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Return O. @@ -65,7 +65,7 @@ JSTaggedValue BuiltinsBoolean::ThisBooleanValue(JSThread *thread, JSTaggedValue return primitive == JSTaggedValue::True() ? GetTaggedBoolean(true) : GetTaggedBoolean(false); } } - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 3. Throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "the type can not convert to BooleanValue", JSTaggedValue::Exception()); } @@ -75,14 +75,14 @@ JSTaggedValue BuiltinsBoolean::BooleanPrototypeToString(EcmaRuntimeCallInfo *arg { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let b be thisBooleanValue(this value). - JSTaggedValue thisValueToBoolean = BuiltinsBoolean::ThisBooleanValue(thread, GetThis(argv).GetTaggedValue()); + JSTaggedValue this_value_to_boolean = BuiltinsBoolean::ThisBooleanValue(thread, GetThis(argv).GetTaggedValue()); // 2. ReturnIfAbrupt(b) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If b is true, return "true"; else return "false". - return thisValueToBoolean.IsTrue() ? GetTaggedString(thread, "true") : GetTaggedString(thread, "false"); + return this_value_to_boolean.IsTrue() ? GetTaggedString(thread, "true") : GetTaggedString(thread, "false"); } // ecma 19.3.3.3 Boolean.prototype.valueOf () diff --git a/runtime/builtins/builtins_collator.cpp b/runtime/builtins/builtins_collator.cpp index dc8fc133021ad6eb61595e290711ab5dafe0322a..0a5f664b3976c6348d131ae3966e142ad6178d91 100644 --- a/runtime/builtins/builtins_collator.cpp +++ b/runtime/builtins/builtins_collator.cpp @@ -28,8 +28,8 @@ JSTaggedValue BuiltinsCollator::CollatorConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + 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); @@ -63,16 +63,16 @@ JSTaggedValue BuiltinsCollator::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %Collator%.[[AvailableLocales]]. - JSHandle availableLocales = JSCollator::GetAvailableLocales(thread); + JSHandle available_locales = JSCollator::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + 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 result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); + JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -83,10 +83,10 @@ JSTaggedValue BuiltinsCollator::Compare(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let collator be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]). - if (!thisValue->IsJSCollator()) { + if (!this_value->IsJSCollator()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not collator", JSTaggedValue::Exception()); } // 3. If collator.[[BoundCompare]] is undefined, then @@ -94,14 +94,14 @@ JSTaggedValue BuiltinsCollator::Compare(EcmaRuntimeCallInfo *argv) // b. Set F.[[Collator]] to collator. // c. Set collator.[[BoundCompare]] to F. // 4. Return collator.[[BoundCompare]]. - JSHandle collator = JSHandle::Cast(thisValue); - JSHandle boundCompare(thread, collator->GetBoundCompare()); - if (boundCompare->IsUndefined()) { + JSHandle collator = JSHandle::Cast(this_value); + JSHandle bound_compare(thread, collator->GetBoundCompare()); + if (bound_compare->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction( + JSHandle intl_bound_func = factory->NewJSIntlBoundFunction( reinterpret_cast(BuiltinsCollator::AnonymousCollator), FUNCTION_LENGTH_TWO); - intlBoundFunc->SetCollator(thread, collator); - collator->SetBoundCompare(thread, intlBoundFunc); + intl_bound_func->SetCollator(thread, collator); + collator->SetBoundCompare(thread, intl_bound_func); } return collator->GetBoundCompare(); } @@ -113,10 +113,10 @@ JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) // 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 intlBoundFunc = JSHandle::Cast(GetConstructor(argv)); + JSHandle intl_bound_func = JSHandle::Cast(GetConstructor(argv)); // 1. Let collator be F.[[Collator]]. - JSHandle collator(thread, intlBoundFunc->GetCollator()); + JSHandle collator(thread, intl_bound_func->GetCollator()); // 2. Assert: Type(collator) is Object and collator has an [[InitializedCollator]] internal slot. ASSERT_PRINT(collator->IsJSObject() && collator->IsJSCollator(), "collator is not object or JSCollator"); @@ -128,14 +128,14 @@ JSTaggedValue BuiltinsCollator::AnonymousCollator(EcmaRuntimeCallInfo *argv) JSHandle y = GetCallArg(argv, 1); // 5. Let X be ? ToString(x). - JSHandle xValue = JSTaggedValue::ToString(thread, x); + JSHandle x_value = JSTaggedValue::ToString(thread, x); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); // 6. Let Y be ? ToString(y). - JSHandle yValue = JSTaggedValue::ToString(thread, y); + JSHandle y_value = JSTaggedValue::ToString(thread, y); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Undefined()); // 7. Return CompareStrings(collator, X, Y). - icu::Collator *icuCollator = (JSHandle::Cast(collator))->GetIcuCollator(); - return JSCollator::CompareStrings(icuCollator, xValue, yValue); + icu::Collator *icu_collator = (JSHandle::Cast(collator))->GetIcuCollator(); + return JSCollator::CompareStrings(icu_collator, x_value, y_value); } // 11.3.4 Intl.Collator.prototype.resolvedOptions () @@ -143,11 +143,11 @@ JSTaggedValue BuiltinsCollator::ResolvedOptions(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle thisValue = GetThis(argv); - if (!thisValue->IsJSCollator()) { + JSHandle this_value = GetThis(argv); + if (!this_value->IsJSCollator()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Collator object", JSTaggedValue::Exception()); } - JSHandle options = JSCollator::ResolvedOptions(thread, JSHandle::Cast(thisValue)); + JSHandle options = JSCollator::ResolvedOptions(thread, JSHandle::Cast(this_value)); return options.GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_dataview.cpp b/runtime/builtins/builtins_dataview.cpp index 4fc8f10161a5f5aef978bb57fd998cfda8527ab3..8a4ce758f6af6213e60889f6715eac44a7125b01 100644 --- a/runtime/builtins/builtins_dataview.cpp +++ b/runtime/builtins/builtins_dataview.cpp @@ -30,57 +30,57 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle ctor = GetConstructor(argv); JSHandle new_target = 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 bufferHandle = GetCallArg(argv, 0); + JSHandle buffer_handle = GetCallArg(argv, 0); // 2. If Type(buffer) is not Object, throw a TypeError exception. - if (!bufferHandle->IsECMAObject()) { + if (!buffer_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not Object", JSTaggedValue::Exception()); } // 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. - if (!bufferHandle->IsArrayBuffer()) { + if (!buffer_handle->IsArrayBuffer()) { THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is not ArrayBuffer", JSTaggedValue::Exception()); } - JSHandle offsetHandle = GetCallArg(argv, 1); + JSHandle offset_handle = GetCallArg(argv, 1); // 4. Let numberOffset be ToNumber(byteOffset). - JSTaggedNumber offsetNumber = JSTaggedValue::ToNumber(thread, offsetHandle); + JSTaggedNumber offset_number = JSTaggedValue::ToNumber(thread, offset_handle); // 6. ReturnIfAbrupt(offset). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t offset = ecmascript::base::NumberHelper::DoubleInRangeInt32(offsetNumber.GetNumber()); + int32_t offset = ecmascript::base::NumberHelper::DoubleInRangeInt32(offset_number.GetNumber()); // 7. If numberOffset ≠ offset or offset < 0, throw a RangeError exception. if (offset < 0) { 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(bufferHandle.GetTaggedValue())) { + if (BuiltinsArrayBuffer::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. - JSHandle arrBufHandle(bufferHandle); - JSTaggedNumber bufLenNum = JSTaggedNumber::FromIntOrDouble(thread, arrBufHandle->GetArrayBufferByteLength()); - int32_t bufByteLen = bufLenNum.ToInt32(); + JSHandle arr_buf_handle(buffer_handle); + JSTaggedNumber buf_len_num = JSTaggedNumber::FromIntOrDouble(thread, arr_buf_handle->GetArrayBufferByteLength()); + int32_t buf_byte_len = buf_len_num.ToInt32(); // 10. If offset > bufferByteLength, throw a RangeError exception. - if (offset > bufByteLen) { + if (offset > buf_byte_len) { THROW_RANGE_ERROR_AND_RETURN(thread, "offset > bufferByteLength", JSTaggedValue::Exception()); } - int32_t viewByteLen; - JSHandle byteLenHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + int32_t view_byte_len; + JSHandle byte_len_handle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); // 11. If byteLength is undefined, then Let viewByteLength be bufferByteLength – offset. - if (byteLenHandle->IsUndefined()) { - viewByteLen = bufByteLen - offset; + if (byte_len_handle->IsUndefined()) { + view_byte_len = buf_byte_len - offset; } else { // Let viewByteLength be ToIndex(byteLength). - JSTaggedNumber byteLen = JSTaggedValue::ToIndex(thread, byteLenHandle); + JSTaggedNumber byte_len = JSTaggedValue::ToIndex(thread, byte_len_handle); // ReturnIfAbrupt(viewByteLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - viewByteLen = byteLen.ToInt32(); + view_byte_len = byte_len.ToInt32(); // If offset+viewByteLength > bufferByteLength, throw a RangeError exception. - if (offset + viewByteLen > bufByteLen) { + if (offset + view_byte_len > buf_byte_len) { THROW_RANGE_ERROR_AND_RETURN(thread, "offset + viewByteLen > bufByteLen", JSTaggedValue::Exception()); } } @@ -90,17 +90,17 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv) JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), new_target); // 14. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle dataView(obj); + JSHandle data_view(obj); // 15. Set O’s [[DataView]] internal slot to true. - dataView->SetDataView(thread, JSTaggedValue::True()); + data_view->SetDataView(thread, JSTaggedValue::True()); // 16. Set O’s [[ViewedArrayBuffer]] internal slot to buffer. - dataView->SetViewedArrayBuffer(thread, bufferHandle.GetTaggedValue()); + data_view->SetViewedArrayBuffer(thread, buffer_handle.GetTaggedValue()); // 17. Set O’s [[ByteLength]] internal slot to viewByteLength. - dataView->SetByteLength(thread, JSTaggedValue(viewByteLen)); + data_view->SetByteLength(thread, JSTaggedValue(view_byte_len)); // 18. Set O’s [[ByteOffset]] internal slot to offset. - dataView->SetByteOffset(thread, JSTaggedValue(offset)); + data_view->SetByteOffset(thread, JSTaggedValue(offset)); // 19. Return O. - return JSTaggedValue(dataView.GetTaggedValue()); + return JSTaggedValue(data_view.GetTaggedValue()); } // 24.2.4.1 @@ -109,20 +109,20 @@ JSTaggedValue BuiltinsDataView::GetBuffer(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, GetBuffer); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. f Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception()); } // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception. - if (!thisHandle->IsDataView()) { + if (!this_handle->IsDataView()) { THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception()); } - JSHandle dataView(thisHandle); + JSHandle data_view(this_handle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 5. Return buffer. return JSTaggedValue(buffer); } @@ -133,26 +133,26 @@ JSTaggedValue BuiltinsDataView::GetByteLength(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, GetByteLength); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception()); } // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception. - if (!thisHandle->IsDataView()) { + if (!this_handle->IsDataView()) { THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception()); } - JSHandle dataView(thisHandle); + JSHandle data_view(this_handle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (BuiltinsArrayBuffer::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. - JSTaggedValue size = dataView->GetByteLength(); + JSTaggedValue size = data_view->GetByteLength(); // 7. Return size. return JSTaggedValue(size); } @@ -163,26 +163,26 @@ JSTaggedValue BuiltinsDataView::GetOffset(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), DataView, GetOffset); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Type(O) is not Object", JSTaggedValue::Exception()); } // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception. - if (!thisHandle->IsDataView()) { + if (!this_handle->IsDataView()) { THROW_TYPE_ERROR_AND_RETURN(thread, "O does not have a [[ViewedArrayBuffer]]", JSTaggedValue::Exception()); } - JSHandle dataView(thisHandle); + JSHandle data_view(this_handle); // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (BuiltinsArrayBuffer::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. - JSTaggedValue offset = dataView->GetByteOffset(); + JSTaggedValue offset = data_view->GetByteOffset(); // 7. Return offset. return JSTaggedValue(offset); } @@ -329,7 +329,7 @@ JSTaggedValue BuiltinsDataView::SetUint32(EcmaRuntimeCallInfo *argv) // 24.2.1.1 JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &requestIndex, JSTaggedValue littleEndian, + const JSHandle &request_index, JSTaggedValue little_endian, DataViewType type) { BUILTINS_API_TRACE(thread, DataView, GetViewValue); @@ -342,58 +342,58 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle dataView(view); + JSHandle data_view(view); { // 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. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } } // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot. - JSTaggedNumber offsetNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteOffset()); - int32_t offset = offsetNum.ToInt32(); + JSTaggedNumber offset_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteOffset()); + int32_t offset = offset_num.ToInt32(); // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot. - JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength()); - int32_t size = viewNum.ToInt32(); + JSTaggedNumber view_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteLength()); + int32_t size = view_num.ToInt32(); // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. - int32_t elementSize = JSDataView::GetElementSize(type); + int32_t element_size = JSDataView::GetElementSize(type); // 13. If getIndex +elementSize > viewSize, throw a RangeError exception. - if (index + elementSize > size) { + if (index + element_size > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - int32_t bufferIndex = index + offset; + int32_t buffer_index = index + offset; // 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). { // 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, dataView->GetViewedArrayBuffer()); - return BuiltinsArrayBuffer::GetValueFromBuffer(thread, buffer, bufferIndex, type, isLittleEndian); + JSHandle buffer(thread, data_view->GetViewedArrayBuffer()); + return BuiltinsArrayBuffer::GetValueFromBuffer(thread, buffer, buffer_index, type, is_little_endian); } } // 24.2.1.2 JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &requestIndex, JSTaggedValue littleEndian, + const JSHandle &request_index, JSTaggedValue little_endian, DataViewType type, const JSHandle &value) { // 1. If Type(view) is not Object, throw a TypeError exception. @@ -406,81 +406,81 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle numVal = JSTaggedValue::ToNumeric(thread, value); + JSHandle num_val = JSTaggedValue::ToNumeric(thread, value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let isLittleEndian be ToBoolean(isLittleEndian). - bool isLittleEndian; - if (littleEndian.IsUndefined()) { - isLittleEndian = false; + bool is_little_endian; + if (little_endian.IsUndefined()) { + is_little_endian = false; } else { - isLittleEndian = littleEndian.ToBoolean(); + is_little_endian = little_endian.ToBoolean(); } // 8. Let buffer be the value of view’s [[ViewedArrayBuffer]] internal slot. - JSHandle dataView(view); + JSHandle data_view(view); { // 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. - JSTaggedValue buffer = dataView->GetViewedArrayBuffer(); + JSTaggedValue buffer = data_view->GetViewedArrayBuffer(); // 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception()); } } // 10. Let viewOffset be the value of view’s [[ByteOffset]] internal slot. - JSTaggedNumber offsetNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteOffset()); - int32_t offset = offsetNum.ToInt32(); + JSTaggedNumber offset_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteOffset()); + int32_t offset = offset_num.ToInt32(); // 11. Let viewSize be the value of view’s [[ByteLength]] internal slot. - JSTaggedNumber viewNum = JSTaggedNumber::FromIntOrDouble(thread, dataView->GetByteLength()); - int32_t size = viewNum.ToInt32(); + JSTaggedNumber view_num = JSTaggedNumber::FromIntOrDouble(thread, data_view->GetByteLength()); + int32_t size = view_num.ToInt32(); // 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type. - int32_t elementSize = JSDataView::GetElementSize(type); + int32_t element_size = JSDataView::GetElementSize(type); // 13. If getIndex +elementSize > viewSize, throw a RangeError exception. - if (index + elementSize > size) { + if (index + element_size > size) { THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception()); } // 14. Let bufferIndex be getIndex + viewOffset. - int32_t bufferIndex = index + offset; + int32_t buffer_index = index + offset; { // 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, dataView->GetViewedArrayBuffer()); + JSHandle buffer(thread, data_view->GetViewedArrayBuffer()); // 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian). - return BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, bufferIndex, type, numVal, isLittleEndian); + return BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, buffer_index, type, num_val, is_little_endian); } } JSTaggedValue BuiltinsDataView::GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisHandle = GetThis(argv); - JSHandle offsetHandle = GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_handle = GetThis(argv); + JSHandle offset_handle = GetCallArg(argv, 0); if (type == DataViewType::UINT8 || type == DataViewType::INT8) { - return GetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type); + return GetViewValue(thread, this_handle, offset_handle, JSTaggedValue::True(), type); } - JSHandle littleEndianHandle = GetCallArg(argv, 1); - return GetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type); + JSHandle little_endian_handle = GetCallArg(argv, 1); + return GetViewValue(thread, this_handle, offset_handle, little_endian_handle.GetTaggedValue(), type); } JSTaggedValue BuiltinsDataView::SetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisHandle = GetThis(argv); - JSHandle offsetHandle = GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_handle = GetThis(argv); + JSHandle offset_handle = GetCallArg(argv, 0); JSHandle value = GetCallArg(argv, 1); if (type == DataViewType::UINT8 || type == DataViewType::INT8) { - return SetViewValue(thread, thisHandle, offsetHandle, JSTaggedValue::True(), type, value); + return SetViewValue(thread, this_handle, offset_handle, JSTaggedValue::True(), type, value); } - JSHandle littleEndianHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); - return SetViewValue(thread, thisHandle, offsetHandle, littleEndianHandle.GetTaggedValue(), type, value); + JSHandle little_endian_handle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + return SetViewValue(thread, this_handle, offset_handle, little_endian_handle.GetTaggedValue(), type, value); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_dataview.h b/runtime/builtins/builtins_dataview.h index adaba56c610cde648aa427ebc9fc33e6b6dc811c..2bb89507ce03da4ce35158fe7f0d5157d981253e 100644 --- a/runtime/builtins/builtins_dataview.h +++ b/runtime/builtins/builtins_dataview.h @@ -75,10 +75,10 @@ public: private: // 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) static JSTaggedValue GetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &requestIndex, JSTaggedValue littleEndian, + const JSHandle &request_index, JSTaggedValue little_endian, DataViewType type); static JSTaggedValue SetViewValue(JSThread *thread, const JSHandle &view, - const JSHandle &requestIndex, JSTaggedValue littleEndian, + const JSHandle &request_index, JSTaggedValue little_endian, DataViewType type, const JSHandle &value); static JSTaggedValue GetTypedValue(EcmaRuntimeCallInfo *argv, DataViewType type); diff --git a/runtime/builtins/builtins_date.cpp b/runtime/builtins/builtins_date.cpp index b90ec08229192894cb122b06eda7a913b365bebb..24e3b7c7ff02272c577c3f290a13041d55de664a 100644 --- a/runtime/builtins/builtins_date.cpp +++ b/runtime/builtins/builtins_date.cpp @@ -31,7 +31,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle new_target = GetNewTarget(argv); if (new_target->IsUndefined()) { double now = JSDate::Now().GetDouble(); @@ -39,27 +39,27 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) return GetTaggedString(thread, str.c_str()); } - JSTaggedValue timeValue(0.0); + JSTaggedValue time_value(0.0); uint32_t length = argv->GetArgsNumber(); if (length == 0) { // no value - timeValue = JSDate::Now(); + time_value = JSDate::Now(); } else if (length == 1) { // one value JSHandle value = GetCallArg(argv, 0); if (value->IsDate()) { // The value is a date object. - JSHandle jsDate(thread, JSDate::Cast(value->GetTaggedObject())); - timeValue = jsDate->GetTimeValue(); + JSHandle js_date(thread, JSDate::Cast(value->GetTaggedObject())); + time_value = js_date->GetTimeValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { - JSHandle objValue(thread, JSTaggedValue::ToPrimitive(thread, value)); + JSHandle obj_value(thread, JSTaggedValue::ToPrimitive(thread, value)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (objValue->IsString()) { // The value is a string object. - timeValue = JSDate::Parse(argv); + if (obj_value->IsString()) { // The value is a string object. + time_value = JSDate::Parse(argv); } else { // The value is a number. - JSTaggedNumber val = JSTaggedValue::ToNumber(thread, objValue); + JSTaggedNumber val = JSTaggedValue::ToNumber(thread, obj_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - timeValue = JSTaggedValue(val.GetNumber()); + time_value = JSTaggedValue(val.GetNumber()); } - timeValue = JSTaggedValue(JSDate::TimeClip(timeValue.GetDouble())); + time_value = JSTaggedValue(JSDate::TimeClip(time_value.GetDouble())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } else { // two or more values @@ -81,16 +81,16 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) fields[0] += JSDate::NINETEEN_HUNDRED_YEAR; } } - timeValue = JSTaggedValue((i == length) ? JSDate::SetDateValues(&fields, true) : ecmascript::base::NAN_VALUE); + time_value = JSTaggedValue((i == length) ? JSDate::SetDateValues(&fields, true) : ecmascript::base::NAN_VALUE); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle constructor = GetConstructor(argv); - JSHandle dateObject = + JSHandle date_object = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - dateObject->SetTimeValue(thread, timeValue); - return JSTaggedValue(JSObject::Cast(static_cast(*dateObject))); + date_object->SetTimeValue(thread, time_value); + return JSTaggedValue(JSObject::Cast(static_cast(*date_object))); } // 20.4.3.1 @@ -104,7 +104,7 @@ JSTaggedValue BuiltinsDate::Now([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsDate::Parse(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, Parse); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); return JSDate::Parse(argv); } @@ -112,7 +112,7 @@ JSTaggedValue BuiltinsDate::Parse(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsDate::UTC(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Date, UTC); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); return JSDate::UTC(argv); } @@ -131,7 +131,7 @@ JSTaggedValue BuiltinsDate::GetTime(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); JSHandle msg = GetThis(argv); if (!msg->IsDate()) { - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } return JSDate::Cast(msg->GetTaggedObject())->GetTime(); @@ -142,7 +142,7 @@ JSTaggedValue BuiltinsDate::SetTime(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, SetTime); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetThis(argv); if (!msg->IsDate()) { @@ -163,7 +163,7 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, ToJSON); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). JSHandle msg = GetThis(argv); @@ -171,9 +171,9 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let tv be ToPrimitive(hint Number) - JSHandle objectHandle = JSHandle::Cast(object); - JSHandle tv(thread, - JSTaggedValue::ToPrimitive(thread, objectHandle, PreferredPrimitiveType::PREFER_NUMBER)); + JSHandle object_handle = JSHandle::Cast(object); + JSHandle tv( + thread, JSTaggedValue::ToPrimitive(thread, object_handle, PreferredPrimitiveType::PREFER_NUMBER)); // 3. If Type(tv) is Number and tv is not finite, return null if (tv->IsNumber()) { @@ -181,9 +181,9 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) return JSTaggedValue::Null(); } } - JSHandle calleeKey(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("toISOString")); - auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), objectHandle, JSTaggedValue::Undefined(), 0); - return JSFunction::Invoke(info.get(), calleeKey); + JSHandle callee_key(thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("toISOString")); + auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), object_handle, JSTaggedValue::Undefined(), 0); + return JSFunction::Invoke(info.Get(), callee_key); } // 20.4.4.44 @@ -194,7 +194,7 @@ JSTaggedValue BuiltinsDate::ValueOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); JSHandle msg = GetThis(argv); if (!msg->IsDate()) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); } return JSDate::Cast(msg->GetTaggedObject())->ValueOf(); @@ -206,7 +206,7 @@ JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Date, ToPrimitive); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle object = GetThis(argv); @@ -214,17 +214,17 @@ JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "Not a JSObject", JSTaggedValue::Exception()); } JSHandle hint = GetCallArg(argv, 0); - PreferredPrimitiveType tryFirst = PREFER_STRING; + PreferredPrimitiveType try_first = PREFER_STRING; if (hint->IsString()) { - JSHandle numberStrHandle = factory->NewFromCanBeCompressString("number"); - if (EcmaString::StringsAreEqual(hint.GetObject(), *numberStrHandle)) { - tryFirst = PREFER_NUMBER; + JSHandle number_str_handle = factory->NewFromCanBeCompressString("number"); + if (EcmaString::StringsAreEqual(hint.GetObject(), *number_str_handle)) { + try_first = PREFER_NUMBER; } else { - JSHandle stringStrHandle = factory->NewFromCanBeCompressString("string"); - JSHandle defaultStrHandle = factory->NewFromCanBeCompressString("default"); - if (EcmaString::StringsAreEqual(hint.GetObject(), *stringStrHandle) || - EcmaString::StringsAreEqual(hint.GetObject(), *defaultStrHandle)) { - tryFirst = PREFER_STRING; + JSHandle string_str_handle = factory->NewFromCanBeCompressString("string"); + JSHandle default_str_handle = factory->NewFromCanBeCompressString("default"); + if (EcmaString::StringsAreEqual(hint.GetObject(), *string_str_handle) || + EcmaString::StringsAreEqual(hint.GetObject(), *default_str_handle)) { + try_first = PREFER_STRING; } else { THROW_TYPE_ERROR_AND_RETURN(thread, "This is not a primitiveType.", JSTaggedValue::Exception()); } @@ -232,7 +232,7 @@ JSTaggedValue BuiltinsDate::ToPrimitive(EcmaRuntimeCallInfo *argv) } else { THROW_TYPE_ERROR_AND_RETURN(thread, "This is not an primitiveType.", JSTaggedValue::Exception()); } - return JSTaggedValue::OrdinaryToPrimitive(thread, object, tryFirst); + return JSTaggedValue::OrdinaryToPrimitive(thread, object, try_first); } // ecma 402 16.4.1 Date.prototype.toLocaleString ( [ locales [ , options ] ] ) @@ -240,10 +240,10 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle env = ecmaVm->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let x be ? thisTimeValue(this value). JSHandle msg = GetThis(argv); @@ -262,7 +262,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) // Let options be ? ToDateTimeOptions(options, "any", "all"). JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSHandle dateTimeOptions = + JSHandle date_time_options = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::ANY, DefaultsOption::ALL); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -270,7 +270,7 @@ JSTaggedValue BuiltinsDate::ToLocaleString(EcmaRuntimeCallInfo *argv) JSHandle ctor = env->GetDateTimeFormatFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); JSHandle dtf = JSDateTimeFormat::InitializeDateTimeFormat( - thread, JSHandle::Cast(obj), locales, JSHandle::Cast(dateTimeOptions)); + thread, JSHandle::Cast(obj), locales, JSHandle::Cast(date_time_options)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatDateTime(dateFormat, x). @@ -283,10 +283,10 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle env = ecmaVm->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let x be ? thisTimeValue(this value). JSHandle msg = GetThis(argv); @@ -305,7 +305,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) // Let options be ? ToDateTimeOptions(options, "any", "all"). JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSHandle dateTimeOptions = + JSHandle date_time_options = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::DATE, DefaultsOption::DATE); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -313,7 +313,7 @@ JSTaggedValue BuiltinsDate::ToLocaleDateString(EcmaRuntimeCallInfo *argv) JSHandle ctor = env->GetDateTimeFormatFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); JSHandle dtf = JSDateTimeFormat::InitializeDateTimeFormat( - thread, JSHandle::Cast(obj), locales, JSHandle::Cast(dateTimeOptions)); + thread, JSHandle::Cast(obj), locales, JSHandle::Cast(date_time_options)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatDateTime(dateFormat, x). @@ -326,10 +326,10 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle env = ecmaVm->GetGlobalEnv(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSHandle env = ecma_vm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let x be ? thisTimeValue(this value). JSHandle msg = GetThis(argv); @@ -348,7 +348,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) // Let options be ? ToDateTimeOptions(options, "any", "all"). JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSHandle dateTimeOptions = + JSHandle date_time_options = JSDateTimeFormat::ToDateTimeOptions(thread, options, RequiredOption::TIME, DefaultsOption::TIME); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -356,7 +356,7 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv) JSHandle ctor = env->GetDateTimeFormatFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); JSHandle dtf = JSDateTimeFormat::InitializeDateTimeFormat( - thread, JSHandle::Cast(obj), locales, JSHandle::Cast(dateTimeOptions)); + thread, JSHandle::Cast(obj), locales, JSHandle::Cast(date_time_options)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatDateTime(dateFormat, x). diff --git a/runtime/builtins/builtins_date_time_format.cpp b/runtime/builtins/builtins_date_time_format.cpp index 1d41e5ae75caf899f318e4a4f10f115f29e035ed..6c3216afaaf22ff8bd3c147fee3b7311e55e904f 100644 --- a/runtime/builtins/builtins_date_time_format.cpp +++ b/runtime/builtins/builtins_date_time_format.cpp @@ -26,9 +26,9 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + 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); @@ -41,7 +41,7 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI // [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], // [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], // [[Pattern]], [[BoundFormat]] »). - JSHandle dateTimeFormat = JSHandle::Cast( + JSHandle date_time_format = JSHandle::Cast( factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -49,24 +49,24 @@ JSTaggedValue BuiltinsDateTimeFormat::DateTimeFormatConstructor(EcmaRuntimeCallI JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); JSHandle dtf = - JSDateTimeFormat::InitializeDateTimeFormat(thread, dateTimeFormat, locales, options); + JSDateTimeFormat::InitializeDateTimeFormat(thread, date_time_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 5. If newTarget is undefined and ? OrdinaryHasInstance(%DateTimeFormat%, this) is true, then // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: // dateTimeFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }). // b. Return this. - bool isInstanceOf = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), thisValue); + bool is_instance_of = JSFunction::OrdinaryHasInstance(thread, env->GetDateTimeFormatFunction(), this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { + if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { PropertyDescriptor descriptor(thread, JSHandle::Cast(dtf), false, false, false); JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + JSTaggedValue::DefinePropertyOrThrow(thread, this_value, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return thisValue.GetTaggedValue(); + return this_value.GetTaggedValue(); } // 6. Return dateTimeFormat. @@ -79,16 +79,16 @@ JSTaggedValue BuiltinsDateTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *ar JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %DateTimeFormat%.[[AvailableLocales]]. - JSHandle availableLocales = JSDateTimeFormat::GainAvailableLocales(thread); + JSHandle available_locales = JSDateTimeFormat::GainAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + 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 result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); + JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -100,17 +100,17 @@ JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!thisValue->IsJSObject()) { + if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "dtf is not object", JSTaggedValue::Exception()); } // 3. Let dtf be ? UnwrapDateTimeFormat(dtf). - JSHandle dtfValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue); + JSHandle dtf_value = JSDateTimeFormat::UnwrapDateTimeFormat(thread, this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (dtfValue->IsUndefined()) { + if (dtf_value->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "dtfValue is not object", JSTaggedValue::Exception()); } @@ -119,14 +119,14 @@ JSTaggedValue BuiltinsDateTimeFormat::Format(EcmaRuntimeCallInfo *argv) // b. Set F.[[DateTimeFormat]] to dtf. // c. Set dtf.[[BoundFormat]] to F. // 5. Return dtf.[[BoundFormat]]. - JSHandle dtf = JSHandle::Cast(dtfValue); - JSHandle boundFormat(thread, dtf->GetBoundFormat()); - if (boundFormat->IsUndefined()) { + JSHandle dtf = JSHandle::Cast(dtf_value); + JSHandle bound_format(thread, dtf->GetBoundFormat()); + if (bound_format->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intlBoundFunc = + JSHandle intl_bound_func = factory->NewJSIntlBoundFunction(reinterpret_cast(BuiltinsDateTimeFormat::AnonymousDateTimeFormat)); - intlBoundFunc->SetDateTimeFormat(thread, dtf); - dtf->SetBoundFormat(thread, intlBoundFunc); + intl_bound_func->SetDateTimeFormat(thread, dtf); + dtf->SetBoundFormat(thread, intl_bound_func); } return dtf->GetBoundFormat(); } @@ -138,10 +138,10 @@ JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInf // 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 intlBoundFunc = JSHandle::Cast(GetConstructor(argv)); + JSHandle intl_bound_func = JSHandle::Cast(GetConstructor(argv)); // 1. Let dtf be F.[[DateTimeFormat]]. - JSHandle dtf(thread, intlBoundFunc->GetDateTimeFormat()); + JSHandle dtf(thread, intl_bound_func->GetDateTimeFormat()); // 2. Assert: Type(dtf) is Object and dtf has an [[InitializedDateTimeFormat]] internal slot. ASSERT_PRINT(dtf->IsJSObject() && dtf->IsJSDateTimeFormat(), "dtf is not object or JSDateTimeFormat"); @@ -155,9 +155,9 @@ JSTaggedValue BuiltinsDateTimeFormat::AnonymousDateTimeFormat(EcmaRuntimeCallInf if (date->IsUndefined()) { x = JSDate::Now().GetNumber(); } else { - JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date); + JSTaggedNumber x_number = JSTaggedValue::ToNumber(thread, date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - x = xNumber.GetNumber(); + x = x_number.GetNumber(); } // 5. Return ? FormatDateTime(dtf, x). @@ -187,19 +187,19 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatToParts(EcmaRuntimeCallInfo *argv) if (date->IsUndefined()) { x = JSDate::Now().GetNumber(); } else { - JSTaggedNumber xNumber = JSTaggedValue::ToNumber(thread, date); + JSTaggedNumber x_number = JSTaggedValue::ToNumber(thread, date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - x = xNumber.GetNumber(); + x = x_number.GetNumber(); } - double xValue = JSDate::TimeClip(x); - if (std::isnan(xValue)) { + double x_value = JSDate::TimeClip(x); + if (std::isnan(x_value)) { THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid time value", JSTaggedValue::Exception()); } // 5. Return ? FormatDateTimeToParts(dtf, x). JSHandle result = - JSDateTimeFormat::FormatDateTimeToParts(thread, JSHandle::Cast(dtf), xValue); + JSDateTimeFormat::FormatDateTimeToParts(thread, JSHandle::Cast(dtf), x_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -210,21 +210,21 @@ JSTaggedValue BuiltinsDateTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!thisValue->IsJSObject()) { + if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. Let dtf be ? UnwrapDateTimeFormat(dtf). - thisValue = JSDateTimeFormat::UnwrapDateTimeFormat(thread, thisValue); + this_value = JSDateTimeFormat::UnwrapDateTimeFormat(thread, this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); - JSDateTimeFormat::ResolvedOptions(thread, JSHandle::Cast(thisValue), options); + JSDateTimeFormat::ResolvedOptions(thread, JSHandle::Cast(this_value), options); // 6. Return options. return options.GetTaggedValue(); } @@ -236,40 +236,40 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRange(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!thisValue->IsJSObject()) { + if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, throw a TypeError exception. - if (!thisValue->IsJSDateTimeFormat()) { + if (!this_value->IsJSDateTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception()); } // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. - JSHandle startDate = GetCallArg(argv, 0); - JSHandle endDate = GetCallArg(argv, 1); - if (startDate->IsUndefined() || endDate->IsUndefined()) { + JSHandle start_date = GetCallArg(argv, 0); + JSHandle end_date = GetCallArg(argv, 1); + if (start_date->IsUndefined() || end_date->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception()); } // 5. Let x be ? ToNumber(startDate). - JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate); + JSTaggedNumber value_x = JSTaggedValue::ToNumber(thread, start_date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double x = valueX.GetNumber(); + double x = value_x.GetNumber(); // 6. Let y be ? ToNumber(endDate). - JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); + JSTaggedNumber value_y = JSTaggedValue::ToNumber(thread, end_date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double y = valueY.GetNumber(); + double y = value_y.GetNumber(); // 7. If x is greater than y, throw a RangeError exception. if (x > y) { THROW_RANGE_ERROR_AND_RETURN(thread, "x is greater than y", JSTaggedValue::Exception()); } // 8. Return ? FormatDateTimeRange(dtf, x, y) - JSHandle dtf = JSHandle::Cast(thisValue); + JSHandle dtf = JSHandle::Cast(this_value); JSHandle result = JSDateTimeFormat::NormDateTimeRange(thread, dtf, x, y); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); @@ -281,41 +281,41 @@ JSTaggedValue BuiltinsDateTimeFormat::FormatRangeToParts(EcmaRuntimeCallInfo *ar JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let dtf be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(dtf) is not Object, throw a TypeError exception. - if (!thisValue->IsJSObject()) { + if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. If dtf does not have an [[InitializedDateTimeFormat]] internal slot, // throw a TypeError exception. - if (!thisValue->IsJSDateTimeFormat()) { + if (!this_value->IsJSDateTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not JSDateTimeFormat", JSTaggedValue::Exception()); } // 4. If startDate is undefined or endDate is undefined, throw a TypeError exception. - JSHandle startDate = GetCallArg(argv, 0); - JSHandle endDate = GetCallArg(argv, 1); - if (startDate->IsUndefined() || endDate->IsUndefined()) { + JSHandle start_date = GetCallArg(argv, 0); + JSHandle end_date = GetCallArg(argv, 1); + if (start_date->IsUndefined() || end_date->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "startDate or endDate is undefined", JSTaggedValue::Exception()); } // 5. Let x be ? ToNumber(startDate). - JSTaggedNumber valueX = JSTaggedValue::ToNumber(thread, startDate); + JSTaggedNumber value_x = JSTaggedValue::ToNumber(thread, start_date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double x = valueX.GetNumber(); + double x = value_x.GetNumber(); // 6. Let y be ? ToNumber(endDate). - JSTaggedNumber valueY = JSTaggedValue::ToNumber(thread, endDate); + JSTaggedNumber value_y = JSTaggedValue::ToNumber(thread, end_date); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double y = valueY.GetNumber(); + double y = value_y.GetNumber(); // 7. If x is greater than y, throw a RangeError exception. if (x > y) { THROW_RANGE_ERROR_AND_RETURN(thread, "x is greater than y", JSTaggedValue::Exception()); } // 8. Return ? FormatDateTimeRangeToParts(dtf, x, y) - JSHandle dtf = JSHandle::Cast(thisValue); + JSHandle dtf = JSHandle::Cast(this_value); JSHandle result = JSDateTimeFormat::NormDateTimeRangeToParts(thread, dtf, x, y); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); diff --git a/runtime/builtins/builtins_finalization_registry.cpp b/runtime/builtins/builtins_finalization_registry.cpp index be3790c4a54e1116195e52e058aba13c1c533036..62399c12cb71d9ac4045965072418435f6829a49 100644 --- a/runtime/builtins/builtins_finalization_registry.cpp +++ b/runtime/builtins/builtins_finalization_registry.cpp @@ -26,7 +26,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Constructor(EcmaRuntimeCallInfo *arg ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -45,11 +45,11 @@ JSTaggedValue BuiltinsFinalizationRegistry::Constructor(EcmaRuntimeCallInfo *arg RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle registry = JSHandle::Cast(obj); // 4. Let fn be the active function object. - JSHandle cleanupCallback = JSHandle::Cast(constructor); + JSHandle cleanup_callback = JSHandle::Cast(constructor); // 5. Set finalizationRegistry.[[Realm]] to fn.[[Realm]]. // Skip. Don't know what is it // 6. Set finalizationRegistry.[[CleanupCallback]] to HostMakeJobCallback(cleanupCallback). - registry->SetCleanupCallback(cleanupCallback.GetTaggedValue()); + registry->SetCleanupCallback(cleanup_callback.GetTaggedValue()); // 7. Set finalizationRegistry.[[Cells]] to a new empty List. JSHandle cells = factory->EmptyArray(); registry->SetCells(cells.GetTaggedValue()); @@ -64,7 +64,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Register); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(GetThis(argv)); // 1. Let finalizationRegistry be the this value. if (!self->IsJSFinalizationRegistry()) { @@ -78,27 +78,27 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) 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 heldValue(thread, JSTaggedValue::Hole()); + JSMutableHandle held_value(thread, JSTaggedValue::Hole()); if (argv->GetArgsNumber() >= 2U) { - heldValue.Update(GetCallArg(argv, 1U)); - if (JSTaggedValue::SameValue(target.GetTaggedValue(), heldValue.GetTaggedValue())) { + held_value.Update(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()); } } // 5. If Type(unregisterToken) is not Object, then // a. If unregisterToken is not undefined, throw a TypeError exception. // b. Set unregisterToken to empty. - JSMutableHandle unregisterToken(thread, GetCallArg(argv, 2U)); - if (!unregisterToken->IsECMAObject()) { - if (!unregisterToken->IsUndefined()) { + JSMutableHandle unregister_token(thread, GetCallArg(argv, 2U)); + if (!unregister_token->IsECMAObject()) { + if (!unregister_token->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "unregisterToken must be an object.", JSTaggedValue::Exception()); } - unregisterToken.Update(JSTaggedValue::Hole()); + unregister_token.Update(JSTaggedValue::Hole()); } // 6. Let cell be the Record { [[WeakRefTarget]]: target, [[HeldValue]]: // heldValue, [[UnregisterToken]]: unregisterToken }. // 7. Append cell to finalizationRegistry.[[Cells]]. - JSFinalizationRegistry::Register(thread, registry, target, heldValue, unregisterToken); + JSFinalizationRegistry::Register(thread, registry, target, held_value, unregister_token); // 8. Return undefined. return JSTaggedValue::Undefined(); } @@ -108,7 +108,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Unregister(EcmaRuntimeCallInfo *argv ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), FinalizationRegistry, Unregister); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(GetThis(argv)); // 1. Let finalizationRegistry be the this value. if (!self->IsJSFinalizationRegistry()) { @@ -117,14 +117,14 @@ 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 unregisterToken = GetCallArg(argv, 0U); - if (!unregisterToken->IsECMAObject()) { + JSHandle unregister_token = GetCallArg(argv, 0U); + if (!unregister_token->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "unregisterToken must be an object.", JSTaggedValue::Exception()); } // 4. Let removed be false. // 5. For each Record { [[WeakRefTarget]], [[HeldValue]], [[UnregisterToken]] } cell of // finalizationRegistry.[[Cells]], do - bool removed = JSFinalizationRegistry::Unregister(thread, registry, unregisterToken); + bool removed = JSFinalizationRegistry::Unregister(thread, registry, unregister_token); // 8. Return removed. return JSTaggedValue(removed); } diff --git a/runtime/builtins/builtins_function.cpp b/runtime/builtins/builtins_function.cpp index 925ed8ebc10e86b013cd5174951bcc9cb12e03fc..e45f6a953dad567337fe24dc06d14e3548628802 100644 --- a/runtime/builtins/builtins_function.cpp +++ b/runtime/builtins/builtins_function.cpp @@ -52,19 +52,19 @@ size_t MakeArgListWithHole(JSThread *thread, TaggedArray *argv, size_t length) return length; } -std::pair BuildArgumentsListFast(JSThread *thread, const JSHandle &arrayObj) +std::pair BuildArgumentsListFast(JSThread *thread, const JSHandle &array_obj) { - if (!arrayObj->HasStableElements(thread)) { + if (!array_obj->HasStableElements(thread)) { return std::make_pair(nullptr, 0); } - if (arrayObj->IsStableJSArguments(thread)) { - JSHandle argList = JSHandle::Cast(arrayObj); - TaggedArray *elements = TaggedArray::Cast(argList->GetElements().GetTaggedObject()); + if (array_obj->IsStableJSArguments(thread)) { + JSHandle arg_list = JSHandle::Cast(array_obj); + TaggedArray *elements = TaggedArray::Cast(arg_list->GetElements().GetTaggedObject()); auto env = thread->GetEcmaVM()->GetGlobalEnv(); - if (argList->GetClass() != env->GetArgumentsClass().GetObject()) { + if (arg_list->GetClass() != env->GetArgumentsClass().GetObject()) { return std::make_pair(nullptr, 0); } - auto result = argList->GetPropertyInlinedProps(JSArguments::LENGTH_INLINE_PROPERTY_INDEX); + auto result = arg_list->GetPropertyInlinedProps(JSArguments::LENGTH_INLINE_PROPERTY_INDEX); if (!result.IsInt()) { return std::make_pair(nullptr, 0); } @@ -73,10 +73,10 @@ std::pair BuildArgumentsListFast(JSThread *thread, const return std::make_pair(elements, res); } - if (arrayObj->IsStableJSArray(thread)) { - JSHandle argList = JSHandle::Cast(arrayObj); - TaggedArray *elements = TaggedArray::Cast(argList->GetElements().GetTaggedObject()); - size_t length = argList->GetArrayLength(); + if (array_obj->IsStableJSArray(thread)) { + JSHandle arg_list = JSHandle::Cast(array_obj); + TaggedArray *elements = TaggedArray::Cast(arg_list->GetElements().GetTaggedObject()); + size_t length = arg_list->GetArrayLength(); size_t res = MakeArgListWithHole(thread, elements, length); return std::make_pair(elements, res); } @@ -90,7 +90,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeApply); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsCallable(func) is false, throw a TypeError exception. if (!GetThis(argv)->IsCallable()) { @@ -98,34 +98,34 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv } JSHandle func = GetThis(argv); - JSHandle thisArg = GetCallArg(argv, 0); + JSHandle this_arg = 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 // a. Return Call(func, thisArg). - auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, 0); - return JSFunction::Call(info.get()); + auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, 0); + return JSFunction::Call(info.Get()); } // 3. Let argList be CreateListFromArrayLike(argArray). - JSHandle arrayObj = GetCallArg(argv, 1); - auto [array, length] = BuildArgumentsListFast(thread, arrayObj); + JSHandle array_obj = GetCallArg(argv, 1); + auto [array, length] = BuildArgumentsListFast(thread, array_obj); if (array == nullptr) { - auto arg_list_res = JSObject::CreateListFromArrayLike(thread, arrayObj); + auto arg_list_res = JSObject::CreateListFromArrayLike(thread, array_obj); // 4. ReturnIfAbrupt(argList). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle arg_list = JSHandle::Cast(arg_list_res); const auto args_length = static_cast(arg_list->GetLength()); - auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, args_length); + auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, args_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(args_length, arg_list->GetData()); - return JSFunction::Call(info.get()); + return JSFunction::Call(info.Get()); } // 6. Return Call(func, thisArg, argList). const auto args_length = static_cast(length); - auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, args_length); + auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, args_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(args_length, array->GetData()); - return JSFunction::Call(info.get()); + return JSFunction::Call(info.Get()); } // ecma 19.2.3.2 Function.prototype.bind (thisArg , ...args) @@ -134,7 +134,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeBind); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let Target be the this value. @@ -144,37 +144,37 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "bind target is not callable", JSTaggedValue::Exception()); } - JSHandle thisArg = GetCallArg(argv, 0); - uint32_t argsLength = 0; + JSHandle this_arg = GetCallArg(argv, 0); + uint32_t args_length = 0; if (argv->GetArgsNumber() > 1) { - argsLength = argv->GetArgsNumber() - 1; + args_length = argv->GetArgsNumber() - 1; } // 3. Let args be a new (possibly empty) List consisting of all of the argument // values provided after thisArg in order. - JSHandle argsArray = factory->NewTaggedArray(argsLength); - for (uint32_t index = 0; index < argsLength; ++index) { - argsArray->Set(thread, index, GetCallArg(argv, index + 1)); + 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)); } // 4. Let F be BoundFunctionCreate(Target, thisArg, args). - JSHandle targetFunction = JSHandle::Cast(target); - JSHandle boundFunction = factory->NewJSBoundFunction(targetFunction, thisArg, argsArray); + JSHandle target_function = JSHandle::Cast(target); + JSHandle bound_function = factory->NewJSBoundFunction(target_function, this_arg, args_array); // 5. ReturnIfAbrupt(F) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Let targetHasLength be HasOwnProperty(Target, "length"). - auto globalConst = thread->GlobalConstants(); - JSHandle lengthKey = globalConst->GetHandledLengthString(); - bool targetHasLength = - JSTaggedValue::HasOwnProperty(thread, JSHandle::Cast(targetFunction), lengthKey); + auto global_const = thread->GlobalConstants(); + JSHandle length_key = global_const->GetHandledLengthString(); + bool target_has_length = + JSTaggedValue::HasOwnProperty(thread, JSHandle::Cast(target_function), length_key); // 7. ReturnIfAbrupt(targetHasLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double lengthValue = 0.0; + double length_value = 0.0; // 8. If targetHasLength is true, then - if (targetHasLength) { + if (target_has_length) { // a. Let targetLen be Get(Target, "length"). - JSHandle targetLen = JSObject::GetProperty(thread, target, lengthKey).GetValue(); + JSHandle target_len = JSObject::GetProperty(thread, target, length_key).GetValue(); // b. ReturnIfAbrupt(targetLen). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -182,42 +182,43 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) // d. Else, // i. Let targetLen be ToInteger(targetLen). // ii. Let L be the larger of 0 and the result of targetLen minus the number of elements of args. - if (targetLen->IsNumber()) { + if (target_len->IsNumber()) { // argv include thisArg - lengthValue = - std::max(0.0, JSTaggedValue::ToNumber(thread, targetLen).GetNumber() - static_cast(argsLength)); + length_value = std::max(0.0, JSTaggedValue::ToNumber(thread, target_len).GetNumber() - + static_cast(args_length)); } } // 9. Else let L be 0. // 10. Let status be DefinePropertyOrThrow(F, "length", PropertyDescriptor {[[Value]]: L, // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}). - PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(lengthValue)), false, false, true); + PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(length_value)), false, false, true); [[maybe_unused]] bool status = - JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(boundFunction), lengthKey, desc); + JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(bound_function), length_key, desc); // 11. Assert: status is not an abrupt completion. ASSERT_PRINT(status, "DefinePropertyOrThrow failed"); // 12. Let targetName be Get(Target, "name"). - JSHandle nameKey = globalConst->GetHandledNameString(); - JSHandle targetName = JSObject::GetProperty(thread, target, nameKey).GetValue(); + JSHandle name_key = global_const->GetHandledNameString(); + JSHandle target_name = JSObject::GetProperty(thread, target, name_key).GetValue(); // 13. ReturnIfAbrupt(targetName). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle boundName(factory->NewFromCanBeCompressString("bound")); + JSHandle bound_name(factory->NewFromCanBeCompressString("bound")); // 14. If Type(targetName) is not String, let targetName be the empty string. // 15. Perform SetFunctionName(F, targetName, "bound"). - if (!targetName->IsString()) { - JSHandle emptyString(factory->GetEmptyString()); - status = JSFunction::SetFunctionName(thread, JSHandle(boundFunction), emptyString, boundName); + if (!target_name->IsString()) { + JSHandle empty_string(factory->GetEmptyString()); + status = + JSFunction::SetFunctionName(thread, JSHandle(bound_function), empty_string, bound_name); } else { - status = JSFunction::SetFunctionName(thread, JSHandle(boundFunction), targetName, boundName); + status = JSFunction::SetFunctionName(thread, JSHandle(bound_function), target_name, bound_name); } // Assert: status is not an abrupt completion. ASSERT_PRINT(status, "SetFunctionName failed"); // 16. Return F. - return boundFunction.GetTaggedValue(); + return bound_function.GetTaggedValue(); } // ecma 19.2.3.3 Function.prototype.call (thisArg , ...args) @@ -226,7 +227,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeCall); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsCallable(func) is false, throw a TypeError exception. if (!GetThis(argv)->IsCallable()) { @@ -234,23 +235,23 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) } JSHandle func = GetThis(argv); - JSHandle thisArg = GetCallArg(argv, 0); - uint32_t argsLength = 0; + JSHandle this_arg = GetCallArg(argv, 0); + uint32_t args_length = 0; if (argv->GetArgsNumber() > 1) { - argsLength = argv->GetArgsNumber() - 1; + args_length = argv->GetArgsNumber() - 1; } // 2. Let argList be an empty List. // 3. If this method was called with more than one argument then in left to right order, // starting with the second argument, append each argument as the last element of argList. // 5. Return Call(func, thisArg, argList). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + auto info = NewRuntimeCallInfo(thread, func, this_arg, undefined, args_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (argsLength > 0) { - info->SetCallArg(argsLength, + if (args_length > 0) { + info->SetCallArg(args_length, reinterpret_cast(argv->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS + 1))); } - return JSFunction::Call(info.get()); + return JSFunction::Call(info.Get()); } // ecma 19.2.3.5 Function.prototype.toString () @@ -259,9 +260,9 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeToString(EcmaRuntimeCallInfo *a 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 handleScope(thread); - JSHandle thisValue = GetThis(argv); - if (!thisValue->IsCallable()) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_value = 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."); @@ -271,12 +272,12 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeToString(EcmaRuntimeCallInfo *a JSTaggedValue BuiltinsFunction::FunctionPrototypeHasInstance(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Function, PrototypeHasInstance); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); // 1. Let F be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Return OrdinaryHasInstance(F, V). JSHandle arg = GetCallArg(argv, 0); - return JSFunction::OrdinaryHasInstance(argv->GetThread(), thisValue, arg) ? GetTaggedBoolean(true) - : GetTaggedBoolean(false); + return JSFunction::OrdinaryHasInstance(argv->GetThread(), this_value, arg) ? GetTaggedBoolean(true) + : GetTaggedBoolean(false); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_generator.cpp b/runtime/builtins/builtins_generator.cpp index 31e60c1c8590fbbb06e9dd57015cf2dea42e615c..be16663ce393cd89068eba39017cdf37b86f6b5d 100644 --- a/runtime/builtins/builtins_generator.cpp +++ b/runtime/builtins/builtins_generator.cpp @@ -31,7 +31,7 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeNext(EcmaRuntimeCallInfo *arg BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Next); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); @@ -51,7 +51,7 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeReturn(EcmaRuntimeCallInfo *a BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Return); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); @@ -61,10 +61,10 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeReturn(EcmaRuntimeCallInfo *a // 2.Let C be Completion { [[Type]]: return, [[Value]]: value, [[Target]]: empty }. JSHandle value = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::RETURN, value); + JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::RETURN, value); // 3.Return ? GeneratorResumeAbrupt(g, C). - JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completionRecord); + JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completion_record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -75,7 +75,7 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeThrow(EcmaRuntimeCallInfo *ar BUILTINS_API_TRACE(argv->GetThread(), GeneratorPrototype, Throw); // 1.Let g be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetThis(argv); if (!msg->IsGeneratorObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Not a generator object.", JSTaggedValue::Exception()); @@ -85,10 +85,10 @@ JSTaggedValue BuiltinsGenerator::GeneratorPrototypeThrow(EcmaRuntimeCallInfo *ar // 2.Let C be ThrowCompletion(exception). JSHandle exception = GetCallArg(argv, 0); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle completionRecord = factory->NewCompletionRecord(CompletionRecord::THROW, exception); + JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::THROW, exception); // 3.Return ? GeneratorResumeAbrupt(g, C). - JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completionRecord); + JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, generator, completion_record); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_global.cpp b/runtime/builtins/builtins_global.cpp index 65c828d38245b31e082e87d78112fa2ba0b14455..0dac5cf8c21f55fb2f5f2c8f7f88054f8123e99d 100644 --- a/runtime/builtins/builtins_global.cpp +++ b/runtime/builtins/builtins_global.cpp @@ -36,7 +36,7 @@ using NumberHelper = ecmascript::base::NumberHelper; using StringHelper = ecmascript::base::StringHelper; // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) -BuiltinsGlobal::GCTaskTracker BuiltinsGlobal::g_gctask_tracker; +BuiltinsGlobal::GCTaskTracker BuiltinsGlobal::g_gctask_tracker_; void BuiltinsGlobal::GCTaskTracker::InitIfNeeded(mem::GC *gc) { @@ -80,7 +80,7 @@ void BuiltinsGlobal::GCTaskTracker::GCPhaseStarted(mem::GCPhase phase) JSHandle new_target(thread, JSTaggedValue::Undefined()); auto info = NewRuntimeCallInfo(thread, fn, global, JSTaggedValue::Undefined(), 1); info->SetCallArgs(thread->GetEcmaVM()->GetGlobalEnv()->GetGcMarker()); - JSFunction::Call(info.get()); + JSFunction::Call(info.Get()); } } @@ -116,7 +116,7 @@ void BuiltinsGlobal::GCTaskTracker::RemoveId(uint64_t id) JSTaggedValue BuiltinsGlobal::Eval(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); if (msg->GetArgsNumber() == 0) { return JSTaggedValue(JSTaggedValue::VALUE_UNDEFINED); } @@ -130,10 +130,10 @@ JSTaggedValue BuiltinsGlobal::IsFinite(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, IsFinite); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle numberInput = GetCallArg(msg, 0); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle number_input = GetCallArg(msg, 0); // 1. Let num be ToNumber(number). - JSTaggedNumber number = JSTaggedValue::ToNumber(thread, numberInput); + 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. @@ -149,10 +149,10 @@ JSTaggedValue BuiltinsGlobal::IsNaN(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, IsNaN); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle numberInput = GetCallArg(msg, 0); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle number_input = GetCallArg(msg, 0); // 1. Let num be ToNumber(number). - JSTaggedNumber number = JSTaggedValue::ToNumber(thread, numberInput); + JSTaggedNumber number = JSTaggedValue::ToNumber(thread, number_input); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If num is NaN, return true. @@ -217,7 +217,7 @@ JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) const int32_t length = sstring->GetLength(); // 3. Let R be the empty String. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string RR; + std::u16string rr; // 4. Let k be 0. // 5. Repeat, while k != length for (int32_t k = 0; k != length; ++k) { @@ -226,7 +226,7 @@ JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) // b. If c is the code unit 0x0025 (PERCENT_SIGN) then if (cc != PERCENT_SIGN) { // c. Set R to the string-concatenation of R and c. - RR.append(StringHelper::Utf16ToU16String(&cc, 1)); + rr.append(StringHelper::Utf16ToU16String(&cc, 1)); continue; } // i. Let hexEscape be the empty String. @@ -279,11 +279,11 @@ JSTaggedValue BuiltinsGlobal::Unescape(EcmaRuntimeCallInfo *msg) k += skip; } // c. Set R to the string-concatenation of R and c. - RR.append(StringHelper::Utf16ToU16String(&cc, 1)); + rr.append(StringHelper::Utf16ToU16String(&cc, 1)); } // 6. Return R. - auto *rr_data = reinterpret_cast(RR.data()); - int32_t rr_size = RR.size(); + auto *rr_data = reinterpret_cast(rr.data()); + int32_t rr_size = rr.size(); return factory->NewFromUtf16Literal(rr_data, rr_size).GetTaggedValue(); } @@ -291,7 +291,7 @@ JSTaggedValue BuiltinsGlobal::Escape(EcmaRuntimeCallInfo *msg) { ASSERT(msg); constexpr uint16_t MAX_DOUBLE_DIGIT = 256; - static const std::u16string hex_str = u"0123456789ABCDEF"; + static const std::u16string HEX_STR = u"0123456789ABCDEF"; JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, Escape); [[maybe_unused]] EcmaHandleScope handle_scope(thread); @@ -303,32 +303,32 @@ JSTaggedValue BuiltinsGlobal::Escape(EcmaRuntimeCallInfo *msg) const int32_t length = sstring->GetLength(); // 3. Let R be the empty String. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string RR; + std::u16string rr; // 4. Let k be 0. // 5. Repeat, while k < length for (int32_t k = 0; k < length; ++k) { // a. Let char be the code unit (represented as a 16-bit unsigned integer) at index k within string. uint16_t cc = sstring->At(k); - std::u16string SS; + std::u16string ss; // b. If char is one of the code units in // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./", then if (IsNotEscaped(cc)) { // i. Let S be the String value containing the single code unit char. - SS = StringHelper::Utf16ToU16String(&cc, 1); + ss = StringHelper::Utf16ToU16String(&cc, 1); } // c. Else if char ≥ 256, then else if (cc >= MAX_DOUBLE_DIGIT) { // i. Let n be the numeric value of char. // ii. Let S be the string-concatenation of: // * "%u" - SS = u"%u"; + ss = u"%u"; // * the String representation of n, formatted as a four-digit uppercase hexadecimal number, padded to // the left with zeroes if necessary constexpr uint16_t N_DIGITS = 4; for (uint16_t j = 0; j < N_DIGITS; j++) { // NOLINTNEXTLINE(hicpp-signed-bitwise,readability-magic-numbers) - uint16_t hex_c = hex_str[cc >> ((N_DIGITS - 1 - j) * 4U) & BIT_MASK]; - SS.append(StringHelper::Utf16ToU16String(&hex_c, 1)); + uint16_t hex_c = HEX_STR[cc >> ((N_DIGITS - 1 - j) * 4U) & BIT_MASK]; + ss.append(StringHelper::Utf16ToU16String(&hex_c, 1)); } } // d. Else @@ -338,23 +338,23 @@ JSTaggedValue BuiltinsGlobal::Escape(EcmaRuntimeCallInfo *msg) // ii. Let n be the numeric value of char // iii. Let S be the string-concatenation of: // * "%" - SS = u"%"; + ss = u"%"; // * the String representation of n, formatted as a two-digit uppercase hexadecimal number, padded to // the left with a zero if necessary constexpr uint16_t N_DIGITS = 2; for (uint16_t j = 0; j < N_DIGITS; j++) { // NOLINTNEXTLINE(hicpp-signed-bitwise,readability-magic-numbers) - uint16_t hex_c = hex_str[cc >> ((N_DIGITS - 1 - j) * 4U) & BIT_MASK]; - SS.append(StringHelper::Utf16ToU16String(&hex_c, 1)); + uint16_t hex_c = HEX_STR[cc >> ((N_DIGITS - 1 - j) * 4U) & BIT_MASK]; + ss.append(StringHelper::Utf16ToU16String(&hex_c, 1)); } } // e. Set R to the string-concatenation of R and S. - RR.append(SS); + rr.append(ss); // f. Set k to k + 1 } // 6. Return R. - auto *rr_data = reinterpret_cast(RR.data()); - int32_t rr_size = RR.size(); + auto *rr_data = reinterpret_cast(rr.data()); + int32_t rr_size = rr.size(); return factory->NewFromUtf16Literal(rr_data, rr_size).GetTaggedValue(); } @@ -364,15 +364,15 @@ JSTaggedValue BuiltinsGlobal::DecodeURI(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, DecodeURI); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let uriString be ToString(encodedURI). // 2. ReturnIfAbrupt(uriString). - [[maybe_unused]] JSHandle uriString = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle uri_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let reservedURISet be a String containing one instance of each code unit valid in uriReserved plus "#". // 4. Return Decode(uriString, reservedURISet). - return Decode(thread, uriString, IsInReservedURISet); + return Decode(thread, uri_string, IsInReservedURISet); } JSTaggedValue BuiltinsGlobal::EncodeURI(EcmaRuntimeCallInfo *msg) @@ -380,16 +380,16 @@ JSTaggedValue BuiltinsGlobal::EncodeURI(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, EncodeURI); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let uriString be ToString(uri). // 2. ReturnIfAbrupt(uriString). - [[maybe_unused]] JSHandle uriString = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle uri_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let unescapedURISet be a String containing one instance of // each code unit valid in uriReserved and uriUnescaped plus "#". // 4. Return Encode(uriString, unescapedURISet). - return Encode(thread, uriString, IsInUnescapedURISet); + return Encode(thread, uri_string, IsInUnescapedURISet); } JSTaggedValue BuiltinsGlobal::DecodeURIComponent(EcmaRuntimeCallInfo *msg) @@ -397,15 +397,15 @@ JSTaggedValue BuiltinsGlobal::DecodeURIComponent(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, DecodeURIComponent); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let componentString be ToString(encodedURIComponent). // 2. ReturnIfAbrupt(componentString). - [[maybe_unused]] JSHandle componentString = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle component_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let reservedURIComponentSet be the empty String. // 4. Return Decode(componentString, reservedURIComponentSet). - return Decode(thread, componentString, []([[maybe_unused]] uint16_t unused) { return false; }); + return Decode(thread, component_string, []([[maybe_unused]] uint16_t unused) { return false; }); } JSTaggedValue BuiltinsGlobal::EncodeURIComponent(EcmaRuntimeCallInfo *msg) @@ -413,35 +413,35 @@ JSTaggedValue BuiltinsGlobal::EncodeURIComponent(EcmaRuntimeCallInfo *msg) ASSERT(msg); JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, EncodeURIComponent); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let componentString be ToString(uriComponent). // 2. ReturnIfAbrupt(componentString). - [[maybe_unused]] JSHandle componentString = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + [[maybe_unused]] JSHandle component_string = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let unescapedURIComponentSet be a String containing one instance of each code unit valid in uriUnescaped. // 4. Return Encode(componentString, unescapedURIComponentSet). - return Encode(thread, componentString, IsUnescapedURI); + return Encode(thread, component_string, IsUnescapedURI); } // Runtime Semantics -JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle &str, judgURIFunc IsInURISet) +JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle &str, JudgUriFunc is_in_uri_set) { // 1. Let strLen be the number of code units in string. - uint32_t strLen = str->GetLength(); + uint32_t str_len = str->GetLength(); // 2. Let R be the empty String. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string resStr; + std::u16string res_str; // 3. Let k be 0. // 4. Repeat uint32_t k = 0; while (true) { // a. If k equals strLen, return R. - if (k == strLen) { - auto *uint16tData = reinterpret_cast(resStr.data()); - int32_t resSize = resStr.size(); - return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue(); + if (k == str_len) { + auto *uint16t_data = reinterpret_cast(res_str.data()); + int32_t res_size = res_str.size(); + return factory->NewFromUtf16Literal(uint16t_data, res_size).GetTaggedValue(); } // b. Let C be the code unit at index k within string. @@ -450,9 +450,9 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandleAt(k); - if (IsInURISet(cc)) { - std::u16string sStr = StringHelper::Utf16ToU16String(&cc, 1); - resStr.append(sStr); + if (is_in_uri_set(cc)) { + std::u16string s_str = StringHelper::Utf16ToU16String(&cc, 1); + res_str.append(s_str); } else { // i. If the code unit value of C is not less than 0xDC00 and not greater than 0xDFFF, // throw a URIError exception. @@ -474,7 +474,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandleAt(k); @@ -495,16 +495,16 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle> 4U) & BIT_MASK) // NOLINT - << hexStr.at(joct & BIT_MASK); // 4: means shift right by 4 digits + tmp_str << '%' << hex_str.at((joct >> 4U) & BIT_MASK) // NOLINT + << hex_str.at(joct & BIT_MASK); // 4: means shift right by 4 digits } - resStr.append(StringHelper::StringToU16string(tmpStr.str())); + res_str.append(StringHelper::StringToU16string(tmp_str.str())); } // e. Increase k by 1. @@ -515,32 +515,32 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle &str, judgURIFunc IsInURISet) +JSTaggedValue BuiltinsGlobal::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 strLen = str->GetLength(); + [[maybe_unused]] uint32_t str_len = str->GetLength(); // 2. Let R be the empty String. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - std::u16string resStr; + std::u16string res_str; // 3. Let k be 0. // 4. Repeat uint32_t k = 0; while (true) { // a. If k equals strLen, return R. - if (k == strLen) { - auto *uint16tData = reinterpret_cast(resStr.data()); - int32_t resSize = resStr.size(); - return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue(); + if (k == str_len) { + auto *uint16t_data = reinterpret_cast(res_str.data()); + int32_t res_size = res_str.size(); + return factory->NewFromUtf16Literal(uint16t_data, res_size).GetTaggedValue(); } // b. Let C be the code unit at index k within string. @@ -557,20 +557,20 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandleAt(k); - std::u16string sStr; + std::u16string s_str; if (cc != '%') { - if (cc == 0 && strLen == 1) { - JSHandle tmpEcmaString = factory->NewFromUtf16Literal(&cc, 1); - return tmpEcmaString.GetTaggedValue(); + if (cc == 0 && str_len == 1) { + JSHandle tmp_ecma_string = factory->NewFromUtf16Literal(&cc, 1); + return tmp_ecma_string.GetTaggedValue(); } - sStr = StringHelper::Utf16ToU16String(&cc, 1); + s_str = StringHelper::Utf16ToU16String(&cc, 1); } else { [[maybe_unused]] uint32_t start = k; // ii. If k + 2 is greater than or equal to strLen, throw a URIError exception. // iii. If the code units at index (k+1) and (k + 2) within string do not represent hexadecimal digits, // throw a URIError exception. - if ((k + 2) >= strLen) { // 2: means plus 2 + if ((k + 2) >= str_len) { // 2: means plus 2 THROW_URI_ERROR_AND_RETURN(thread, "DecodeURI: The format of the URI to be parsed is incorrect", JSTaggedValue::Exception()); } @@ -579,19 +579,19 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandleAt(k + 1); - uint16_t behindChar = str->At(k + 2); // 2: means plus 2 - uint8_t bb = GetValueFromTwoHex(frontChar, behindChar); + uint16_t front_char = str->At(k + 1); + uint16_t behind_char = str->At(k + 2); // 2: means plus 2 + uint8_t bb = GetValueFromTwoHex(front_char, behind_char); k += 2; // 2: means plus 2 if ((bb & BIT_MASK_ONE) == 0) { - if (!IsInURISet(bb)) { - sStr = StringHelper::Utf8ToU16String(&bb, 1); + if (!is_in_uri_set(bb)) { + s_str = StringHelper::Utf8ToU16String(&bb, 1); if (bb == 0) { - return factory->NewFromUtf16Literal(reinterpret_cast(sStr.data()), 1) + return factory->NewFromUtf16Literal(reinterpret_cast(s_str.data()), 1) .GetTaggedValue(); } } else { - sStr = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); + s_str = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); } } else { // vii. Else the most significant bit in B is 1, @@ -633,18 +633,18 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle oct = {bb}; // 5. If k + (3 × (n – 1)) is greater than or equal to strLen, throw a URIError exception. - if (k + (3 * (n - 1)) >= strLen) { // 3: means multiply by 3 + if (k + (3 * (n - 1)) >= str_len) { // 3: means multiply by 3 THROW_URI_ERROR_AND_RETURN(thread, "DecodeURI: The format of the URI to be parsed is incorrect", JSTaggedValue::Exception()); } uint32_t j = 1; while (j < n) { k++; - uint16_t codeUnit = str->At(k); + uint16_t code_unit = str->At(k); // b. If the code unit at index k within string is not "%", throw a URIError exception. // c. If the code units at index (k +1) and (k + 2) within string do not represent hexadecimal // digits, throw a URIError exception. - if (!(codeUnit == '%')) { + if (!(code_unit == '%')) { THROW_URI_ERROR_AND_RETURN(thread, "DecodeURI: The format of the URI to be parsed is incorrect", JSTaggedValue::Exception()); } @@ -653,9 +653,9 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandleAt(k + 1); - uint16_t behindChart = str->At(k + 2); // 2: means plus 2 - bb = GetValueFromTwoHex(frontChart, behindChart); + uint16_t front_chart = str->At(k + 1); + uint16_t behind_chart = str->At(k + 2); // 2: means plus 2 + bb = GetValueFromTwoHex(front_chart, behind_chart); // e. If the two most significant bits in B are not 10, throw a URIError exception. if (!((bb & BIT_MASK_TWO) == BIT_MASK_ONE)) { THROW_URI_ERROR_AND_RETURN(thread, "DecodeURI: The format of the URI to be parsed is incorrect", @@ -676,23 +676,23 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle(&vv), 1); + if (!is_in_uri_set(vv)) { + s_str = StringHelper::Utf16ToU16String(reinterpret_cast(&vv), 1); } else { - sStr = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); + s_str = StringHelper::StringToU16string(StringHelper::SubString(str, start, k - start + 1)); } } else { uint16_t lv = (((vv - utf::DECODE_SECOND_FACTOR) & BIT16_MASK) + utf::DECODE_TRAIL_LOW); uint16_t hv = ((((vv - utf::DECODE_SECOND_FACTOR) >> 10U) & BIT16_MASK) + // NOLINT utf::DECODE_LEAD_LOW); // 10: means shift left by 10 digits - sStr = StringHelper::Append(StringHelper::Utf16ToU16String(&hv, 1), - StringHelper::Utf16ToU16String(&lv, 1)); + s_str = StringHelper::Append(StringHelper::Utf16ToU16String(&hv, 1), + StringHelper::Utf16ToU16String(&lv, 1)); } } } // e. Let R be a new String value computed by concatenating the previous value of R and S. // f. Increase k by 1. - resStr.append(sStr); + res_str.append(s_str); k++; } } @@ -713,16 +713,16 @@ JSTaggedValue BuiltinsGlobal::PrintEntrypoint(EcmaRuntimeCallInfo *msg) return JSTaggedValue::Undefined(); } JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, PrintEntryPoint); - uint32_t numArgs = msg->GetArgsNumber(); - for (uint32_t i = 0; i < numArgs; i++) { - JSHandle stringContent = JSTaggedValue::ToString(thread, GetCallArg(msg, i)); + uint32_t num_args = msg->GetArgsNumber(); + for (uint32_t i = 0; i < num_args; i++) { + JSHandle string_content = JSTaggedValue::ToString(thread, GetCallArg(msg, i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - PrintString(thread, *stringContent); + PrintString(thread, *string_content); - if (i != numArgs - 1) { + if (i != num_args - 1) { std::cout << " "; } } @@ -734,7 +734,7 @@ JSTaggedValue BuiltinsGlobal::GCEntrypoint(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); ASSERT(thread != nullptr); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, GCEntrypoint); thread->GetEcmaVM()->GetGC()->WaitForGCInManaged(GCTask(GCTaskCause::EXPLICIT_CAUSE)); @@ -780,7 +780,7 @@ JSTaggedValue BuiltinsGlobal::SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); ASSERT(thread != nullptr); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, SpecifiedGCEntrypoint); bool run_gc_in_place = Runtime::GetOptions().IsRunGcInPlace("ecmascript"); @@ -792,7 +792,7 @@ JSTaggedValue BuiltinsGlobal::SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg) 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()) { @@ -803,7 +803,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; @@ -814,14 +814,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,7 +835,7 @@ JSTaggedValue BuiltinsGlobal::SpecifiedGCEntrypoint(EcmaRuntimeCallInfo *msg) JSTaggedValue BuiltinsGlobal::WaitForFinishGC(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, WaitForFinishGC); JSHandle arg = GetCallArg(msg, 0); if (!arg->IsNumber()) { @@ -846,9 +846,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(id)) { + while (g_gctask_tracker_.HasId(id)) { constexpr uint64_t WAIT_TIME_MS = 10; os::thread::NativeSleep(WAIT_TIME_MS); } @@ -860,7 +860,7 @@ JSTaggedValue BuiltinsGlobal::WaitForFinishGC(EcmaRuntimeCallInfo *msg) JSTaggedValue BuiltinsGlobal::ScheduleGCAfterNthAlloc(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, ScheduleGCAfterNthAlloc); JSHandle arg = GetCallArg(msg, 0); if (!arg->IsInt()) { @@ -913,45 +913,45 @@ JSTaggedValue BuiltinsGlobal::AllocateArrayObject(EcmaRuntimeCallInfo *msg) JSThread *thread = msg->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); ASSERT(thread != nullptr); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); BUILTINS_API_TRACE(thread, Global, AllocateArrayObject); - int64_t sizeInBytes = 0; + int64_t size_in_bytes = 0; if (GetCallArg(msg, 0)->IsInt()) { - sizeInBytes = GetCallArg(msg, 0)->GetInt(); + size_in_bytes = GetCallArg(msg, 0)->GetInt(); } else if (GetCallArg(msg, 0)->IsDouble()) { - sizeInBytes = GetCallArg(msg, 0)->GetDouble(); + size_in_bytes = GetCallArg(msg, 0)->GetDouble(); } else { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "The value must be an integer"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - if (sizeInBytes < 0) { + if (size_in_bytes < 0) { JSHandle err = thread->GetEcmaVM()->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "The value must be positive"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } - sizeInBytes = RoundUp(sizeInBytes, sizeof(TaggedType)) - JSArray::SIZE; + size_in_bytes = RoundUp(size_in_bytes, sizeof(TaggedType)) - JSArray::SIZE; - if (sizeInBytes < 0) { - sizeInBytes = 0; + if (size_in_bytes < 0) { + size_in_bytes = 0; } - uint32_t numElements = sizeInBytes / sizeof(TaggedType); + uint32_t num_elements = size_in_bytes / sizeof(TaggedType); JSHandle array = factory->NewJSArray(); - if (numElements > 0) { - JSHandle elements = factory->NewTaggedArray(numElements); + if (num_elements > 0) { + JSHandle elements = factory->NewTaggedArray(num_elements); if (elements.IsEmpty()) { return JSTaggedValue::Exception(); } array->SetElements(thread, elements); - array->SetArrayLength(thread, numElements); + array->SetArrayLength(thread, num_elements); } return array.GetTaggedValue(); @@ -974,7 +974,7 @@ JSTaggedValue BuiltinsGlobal::GetMarkQueue(EcmaRuntimeCallInfo *msg) JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, GetMarkQueue); EcmaVM *vm = thread->GetEcmaVM(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle array = vm->GetFactory()->NewJSArray(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); size_t index = 0; @@ -1080,7 +1080,7 @@ JSTaggedValue BuiltinsGlobal::PinObject(EcmaRuntimeCallInfo *msg) } obj_allocator->PinObject(arg->GetHeapObject()); } else { - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle err = vm->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "The value must be an object"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } @@ -1096,7 +1096,7 @@ JSTaggedValue BuiltinsGlobal::UnpinObject(EcmaRuntimeCallInfo *msg) if (arg->IsHeapObject()) { vm->GetHeapManager()->GetObjectAllocator().AsObjectAllocator()->UnpinObject(arg->GetHeapObject()); } else { - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle err = vm->GetFactory()->GetJSError(ErrorType::TYPE_ERROR, "The value must be an object"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, err.GetTaggedValue(), JSTaggedValue::Exception()); } @@ -1107,7 +1107,7 @@ JSTaggedValue BuiltinsGlobal::GetObjectAddress(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, GetObjectAddress); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); PandaStringStream addr_stream; addr_stream << GetCallArg(msg, 0)->GetHeapObject(); return thread->GetEcmaVM()->GetFactory()->NewFromString(addr_stream.str()).GetTaggedValue(); @@ -1117,12 +1117,12 @@ JSTaggedValue BuiltinsGlobal::CallJsBoundFunction(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, CallJsBoundFunction); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // msg contains jsfunc, this, arg1,... - JSHandle boundFunc(GetConstructor(msg)); - JSHandle thisObj(thread, boundFunc->GetBoundThis()); - msg->SetThis(thisObj.GetTaggedValue()); + JSHandle bound_func(GetConstructor(msg)); + JSHandle this_obj(thread, bound_func->GetBoundThis()); + msg->SetThis(this_obj.GetTaggedValue()); return SlowRuntimeHelper::CallBoundFunction(msg); } @@ -1130,7 +1130,7 @@ JSTaggedValue BuiltinsGlobal::CallJsProxy(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); BUILTINS_API_TRACE(thread, Global, CallJsProxy); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // msg contains js_proxy, this, arg1,... JSHandle proxy(GetConstructor(msg)); if (!proxy->IsCallable()) { @@ -1145,7 +1145,7 @@ JSTaggedValue BuiltinsGlobal::CallJsProxy(EcmaRuntimeCallInfo *msg) JSTaggedValue BuiltinsGlobal::StartRuntimeStat(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // start vm runtime stat statistic thread->GetEcmaVM()->SetRuntimeStatEnable(true); return JSTaggedValue::Undefined(); @@ -1154,7 +1154,7 @@ JSTaggedValue BuiltinsGlobal::StartRuntimeStat(EcmaRuntimeCallInfo *msg) JSTaggedValue BuiltinsGlobal::StopRuntimeStat(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // start vm runtime stat statistic thread->GetEcmaVM()->SetRuntimeStatEnable(false); return JSTaggedValue::Undefined(); diff --git a/runtime/builtins/builtins_global.h b/runtime/builtins/builtins_global.h index cb7edb3439d59a1e9884147ab12ea03b59532e02..0e22b45d01de49c377d59474e903dd510026fa8a 100644 --- a/runtime/builtins/builtins_global.h +++ b/runtime/builtins/builtins_global.h @@ -27,7 +27,7 @@ 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 JudgUriFunc = bool (*)(uint16_t); class BuiltinsGlobal : public ecmascript::base::BuiltinsBase { public: @@ -71,8 +71,8 @@ public: 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 IsInURISet); - static JSTaggedValue Decode(JSThread *thread, const JSHandle &str, judgURIFunc IsInURISet); + 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) { @@ -154,7 +154,7 @@ private: os::memory::Mutex lock_; }; - static GCTaskTracker g_gctask_tracker; + static GCTaskTracker g_gctask_tracker_; }; } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_iterator.cpp b/runtime/builtins/builtins_iterator.cpp index 64ca13a849e675c902bcde4951a088d658c9256c..eb6f02d65c3391e8210fe8eb9e23b8f26ff38746 100644 --- a/runtime/builtins/builtins_iterator.cpp +++ b/runtime/builtins/builtins_iterator.cpp @@ -39,10 +39,10 @@ JSTaggedValue BuiltinsIterator::Return(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Iterator, Return); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle value = GetCallArg(argv, 0); - JSHandle iterResult = JSIterator::CreateIterResultObject(thread, value, true); - return iterResult.GetTaggedValue(); + JSHandle iter_result = JSIterator::CreateIterResultObject(thread, value, true); + return iter_result.GetTaggedValue(); } JSTaggedValue BuiltinsIterator::GetIteratorObj(EcmaRuntimeCallInfo *argv) diff --git a/runtime/builtins/builtins_json.cpp b/runtime/builtins/builtins_json.cpp index 25f8be8994624f0cae0cbc8a1d22ae94cee3e0d9..597d21364b22e19253a67b89bf728dd5129c8dd0 100644 --- a/runtime/builtins/builtins_json.cpp +++ b/runtime/builtins/builtins_json.cpp @@ -31,26 +31,27 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Json, Parse); ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); uint32_t argc = argv->GetArgsNumber(); if (argc == 0) { - JSHandle syntaxError = factory->GetJSError(ecmascript::base::ErrorType::SYNTAX_ERROR, "arg is empty"); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); + JSHandle syntax_error = + factory->GetJSError(ecmascript::base::ErrorType::SYNTAX_ERROR, "arg is empty"); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), JSTaggedValue::Exception()); } JSHandle msg = GetCallArg(argv, 0); - JSHandle parseString = JSTaggedValue::ToString(thread, msg); + JSHandle parse_string = JSTaggedValue::ToString(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle result; - if (parseString->IsUtf8()) { + if (parse_string->IsUtf8()) { panda::ecmascript::base::JsonParser parser(thread); - result = parser.ParseUtf8(*parseString); + result = parser.ParseUtf8(*parse_string); } else { panda::ecmascript::base::JsonParser parser(thread); - result = parser.ParseUtf16(*parseString); + result = parser.ParseUtf16(*parse_string); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -58,17 +59,17 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) if (argc == 2) { // 2: 2 args reviver = GetCallArg(argv, 1).GetTaggedValue(); if (reviver.IsCallable()) { - JSHandle callbackfnHandle(thread, reviver); + JSHandle callbackfn_handle(thread, reviver); // Let root be ! OrdinaryObjectCreate(%Object.prototype%). JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle constructor = env->GetObjectFunction(); JSHandle root = factory->NewJSObjectByConstructor(JSHandle(constructor), constructor); // Let rootName be the empty String. - JSHandle rootName(factory->GetEmptyString()); + JSHandle root_name(factory->GetEmptyString()); // Perform ! CreateDataPropertyOrThrow(root, rootName, unfiltered). - bool success = JSObject::CreateDataProperty(thread, root, rootName, result); + bool success = JSObject::CreateDataProperty(thread, root, root_name, result); if (success) { - result = base::Internalize::InternalizeJsonProperty(thread, root, rootName, callbackfnHandle); + result = base::Internalize::InternalizeJsonProperty(thread, root, root_name, callbackfn_handle); } } } @@ -81,7 +82,7 @@ JSTaggedValue BuiltinsJson::Stringify(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Json, Parse); ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); uint32_t argc = argv->GetArgsNumber(); JSTaggedValue value = GetCallArg(argv, 0).GetTaggedValue(); @@ -95,11 +96,11 @@ JSTaggedValue BuiltinsJson::Stringify(EcmaRuntimeCallInfo *argv) gap = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD).GetTaggedValue(); } - JSHandle handleValue(thread, value); - JSHandle handleReplacer(thread, replacer); - JSHandle handleGap(thread, gap); + JSHandle handle_value(thread, value); + JSHandle handle_replacer(thread, replacer); + JSHandle handle_gap(thread, gap); panda::ecmascript::base::JsonStringifier stringifier(thread); - JSHandle result = stringifier.Stringify(handleValue, handleReplacer, handleGap); + JSHandle result = stringifier.Stringify(handle_value, handle_replacer, handle_gap); return result.GetTaggedValue(); } diff --git a/runtime/builtins/builtins_locale.cpp b/runtime/builtins/builtins_locale.cpp index fedb69ec6209e0731867e20ae89d5e6e53365c7b..564b3c73410d0a12fcf6683ae3b8e5c7be1184e4 100644 --- a/runtime/builtins/builtins_locale.cpp +++ b/runtime/builtins/builtins_locale.cpp @@ -26,8 +26,8 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. JSHandle new_target = GetNewTarget(argv); @@ -51,27 +51,27 @@ JSTaggedValue BuiltinsLocale::LocaleConstructor(EcmaRuntimeCallInfo *argv) // a.Let tag be tag.[[Locale]]. // 9. Else, // a.Let tag be ? ToString(tag). - JSHandle localeString = factory->GetEmptyString(); + JSHandle locale_string = factory->GetEmptyString(); if (!tag->IsJSLocale()) { - localeString = JSTaggedValue::ToString(thread, tag); + locale_string = JSTaggedValue::ToString(thread, tag); } else { - icu::Locale *icuLocale = (JSHandle::Cast(tag))->GetIcuLocale(); - localeString = JSLocale::ToLanguageTag(thread, *icuLocale); + icu::Locale *icu_locale = (JSHandle::Cast(tag))->GetIcuLocale(); + locale_string = JSLocale::ToLanguageTag(thread, *icu_locale); } // 10. If options is undefined, then // a.Let options be ! ObjectCreate(null). // 11. Else // a.Let options be ? ToObject(options). JSHandle options = GetCallArg(argv, 1); - JSHandle optionsObj; + JSHandle options_obj; if (options->IsUndefined()) { - optionsObj = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); + options_obj = factory->OrdinaryNewJSObjectCreate(JSHandle(thread, JSTaggedValue::Null())); } else { - optionsObj = JSTaggedValue::ToObject(thread, options); + options_obj = JSTaggedValue::ToObject(thread, options); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle result = JSLocale::InitializeLocale(thread, locale, localeString, optionsObj); + JSHandle result = JSLocale::InitializeLocale(thread, locale, locale_string, options_obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -97,9 +97,9 @@ JSTaggedValue BuiltinsLocale::Maximize(EcmaRuntimeCallInfo *argv) ASSERT(!source.isBogus()); // 4. Return ! Construct(%Locale%, maximal). - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = env->GetLocaleFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); @@ -131,9 +131,9 @@ JSTaggedValue BuiltinsLocale::Minimize(EcmaRuntimeCallInfo *argv) [[maybe_unused]] auto res = source.toLanguageTag(status); // 4. Return ! Construct(%Locale%, minimal). - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = env->GetLocaleFunction(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); @@ -169,9 +169,9 @@ JSTaggedValue BuiltinsLocale::GetBaseName(EcmaRuntimeCallInfo *argv) // 3. Let locale be loc.[[Locale]]. // 4. Return the substring of locale corresponding to the unicode_language_id production. JSHandle locale = JSHandle::Cast(loc); - icu::Locale icuLocale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName()); - JSHandle baseName = JSLocale::ToLanguageTag(thread, icuLocale); - return baseName.GetTaggedValue(); + icu::Locale icu_locale = icu::Locale::createFromName(locale->GetIcuLocale()->getBaseName()); + JSHandle base_name = JSLocale::ToLanguageTag(thread, icu_locale); + return base_name.GetTaggedValue(); } JSTaggedValue BuiltinsLocale::GetCalendar(EcmaRuntimeCallInfo *argv) @@ -203,8 +203,8 @@ JSTaggedValue BuiltinsLocale::GetCaseFirst(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[CaseFirst]]. JSHandle locale = JSHandle::Cast(loc); - JSHandle caseFirst = JSLocale::NormalizeKeywordValue(thread, locale, "kf"); - return caseFirst.GetTaggedValue(); + JSHandle case_first = JSLocale::NormalizeKeywordValue(thread, locale, "kf"); + return case_first.GetTaggedValue(); } JSTaggedValue BuiltinsLocale::GetCollation(EcmaRuntimeCallInfo *argv) @@ -235,8 +235,8 @@ JSTaggedValue BuiltinsLocale::GetHourCycle(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[HourCycle]]. JSHandle locale = JSHandle::Cast(loc); - JSHandle hourCycle = JSLocale::NormalizeKeywordValue(thread, locale, "hc"); - return hourCycle.GetTaggedValue(); + JSHandle hour_cycle = JSLocale::NormalizeKeywordValue(thread, locale, "hc"); + return hour_cycle.GetTaggedValue(); } JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv) @@ -252,9 +252,9 @@ JSTaggedValue BuiltinsLocale::GetNumeric(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[Numeric]]. JSHandle locale = JSHandle::Cast(loc); - icu::Locale *icuLocale = locale->GetIcuLocale(); + icu::Locale *icu_locale = locale->GetIcuLocale(); UErrorCode status = U_ZERO_ERROR; - auto numeric = icuLocale->getUnicodeKeywordValue("kn", status); + auto numeric = icu_locale->getUnicodeKeywordValue("kn", status); JSTaggedValue result = (numeric == "true") ? JSTaggedValue::True() : JSTaggedValue::False(); return result; } @@ -271,8 +271,8 @@ JSTaggedValue BuiltinsLocale::GetNumberingSystem(EcmaRuntimeCallInfo *argv) } // 3. Return loc.[[NumberingSystem]]. JSHandle locale = JSHandle::Cast(loc); - JSHandle numberingSystem = JSLocale::NormalizeKeywordValue(thread, locale, "nu"); - return numberingSystem.GetTaggedValue(); + JSHandle numbering_system = JSLocale::NormalizeKeywordValue(thread, locale, "nu"); + return numbering_system.GetTaggedValue(); } JSTaggedValue BuiltinsLocale::GetLanguage(EcmaRuntimeCallInfo *argv) @@ -332,9 +332,9 @@ JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let loc be the this value. JSHandle loc = GetThis(argv); // 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]). @@ -350,7 +350,7 @@ JSTaggedValue BuiltinsLocale::GetRegion(EcmaRuntimeCallInfo *argv) // unicode_language_id. PandaString region = locale->GetIcuLocale()->getCountry(); if (region.empty()) { - return globalConst->GetUndefined(); + return global_const->GetUndefined(); } return factory->NewFromString(region).GetTaggedValue(); } diff --git a/runtime/builtins/builtins_map.cpp b/runtime/builtins/builtins_map.cpp index 8f65304448f77ec4a0b0d264ef623a09f7213d81..2e31748f917b88141989ad620269ed343edd8fd8 100644 --- a/runtime/builtins/builtins_map.cpp +++ b/runtime/builtins/builtins_map.cpp @@ -29,7 +29,7 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -45,8 +45,8 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) JSHandle map = JSHandle::Cast(obj); // 4.Set map’s [[MapData]] internal slot to a new empty List. - JSHandle linkedMap = LinkedHashMap::Create(thread); - map->SetLinkedMap(thread, linkedMap); + JSHandle linked_map = LinkedHashMap::Create(thread); + map->SetLinkedMap(thread, linked_map); // 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. @@ -59,8 +59,8 @@ JSTaggedValue BuiltinsMap::MapConstructor(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is not object", JSTaggedValue::Exception()); } // Let adder be Get(map, "set"). - JSHandle adderKey(factory->NewFromCanBeCompressString("set")); - JSHandle adder = JSObject::GetProperty(thread, JSHandle(map), adderKey).GetValue(); + JSHandle adder_key(factory->NewFromCanBeCompressString("set")); + JSHandle adder = JSObject::GetProperty(thread, JSHandle(map), adder_key).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); JSTaggedValue result = @@ -73,7 +73,7 @@ JSTaggedValue BuiltinsMap::Set(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -94,7 +94,7 @@ JSTaggedValue BuiltinsMap::Clear(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Clear); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); @@ -112,7 +112,7 @@ JSTaggedValue BuiltinsMap::Delete(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = 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. @@ -130,19 +130,19 @@ JSTaggedValue BuiltinsMap::Has(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(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 jsMap(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle js_map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = GetCallArg(argv, 0); bool flag = false; if (JSMap::IsKey(key.GetTaggedValue())) { int hash = LinkedHash::Hash(key.GetTaggedValue()); - flag = jsMap->Has(key.GetTaggedValue(), hash); + flag = js_map->Has(key.GetTaggedValue(), hash); } return GetTaggedBoolean(flag); } @@ -151,19 +151,19 @@ JSTaggedValue BuiltinsMap::Get(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Get); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(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 jsMap(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle js_map(thread, JSMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = GetCallArg(argv, 0); JSTaggedValue value = JSTaggedValue::Undefined(); if (JSMap::IsKey(key.GetTaggedValue())) { int hash = LinkedHash::Hash(key.GetTaggedValue()); - value = jsMap->Get(key.GetTaggedValue(), hash); + value = js_map->Get(key.GetTaggedValue(), hash); } return value; } @@ -171,7 +171,7 @@ JSTaggedValue BuiltinsMap::Get(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -187,23 +187,23 @@ JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) 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 thisArg = GetCallArg(argv, 1); + JSHandle this_arg = GetCallArg(argv, 1); // composed arguments JSHandle iter(factory->NewJSMapIterator(map, IterationKind::KEY_AND_VALUE)); - JSHandle keyIndex(thread, JSTaggedValue(0)); - JSHandle valueIndex(thread, JSTaggedValue(1)); + JSHandle key_index(thread, JSTaggedValue(0)); + JSHandle value_index(thread, JSTaggedValue(1)); JSHandle result = JSIterator::IteratorStep(thread, iter); while (!result->IsFalse()) { RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result.GetTaggedValue()); - JSHandle iterValue(JSIterator::IteratorValue(thread, result)); - JSHandle key = JSObject::GetProperty(thread, iterValue, keyIndex).GetValue(); - JSHandle value = JSObject::GetProperty(thread, iterValue, valueIndex).GetValue(); + JSHandle iter_value(JSIterator::IteratorValue(thread, result)); + JSHandle key = JSObject::GetProperty(thread, iter_value, key_index).GetValue(); + JSHandle value = JSObject::GetProperty(thread, iter_value, value_index).GetValue(); // Let funcResult be Call(callbackfn, T, «e, e, S»). - auto info = NewRuntimeCallInfo(thread, func, thisArg, JSTaggedValue::Undefined(), 3); + auto info = NewRuntimeCallInfo(thread, func, this_arg, JSTaggedValue::Undefined(), 3); info->SetCallArgs(value, key, JSHandle(map)); - JSTaggedValue ret = JSFunction::Call(info.get()); // 3: three args + JSTaggedValue ret = JSFunction::Call(info.Get()); // 3: three args // returnIfAbrupt RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); result = JSIterator::IteratorStep(thread, iter); @@ -221,15 +221,15 @@ JSTaggedValue BuiltinsMap::GetSize(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, GetSize); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(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()); } - JSMap *jsMap = JSMap::Cast(*JSTaggedValue::ToObject(thread, self)); - int count = jsMap->GetSize(); + JSMap *js_map = JSMap::Cast(*JSTaggedValue::ToObject(thread, self)); + int count = js_map->GetSize(); return JSTaggedValue(count); } @@ -237,7 +237,7 @@ JSTaggedValue BuiltinsMap::Entries(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::KEY_AND_VALUE); return iter.GetTaggedValue(); @@ -247,7 +247,7 @@ JSTaggedValue BuiltinsMap::Keys(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::KEY); return iter.GetTaggedValue(); @@ -257,7 +257,7 @@ JSTaggedValue BuiltinsMap::Values(EcmaRuntimeCallInfo *argv) { BUILTINS_API_TRACE(argv->GetThread(), Map, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); JSHandle iter = JSMapIterator::CreateMapIterator(thread, self, IterationKind::VALUE); return iter.GetTaggedValue(); diff --git a/runtime/builtins/builtins_math.cpp b/runtime/builtins/builtins_math.cpp index 1cd3f18780bbd3681b746de7d3dbb62a521f8234..f58d08125e12de113ba884a456aee742a5e63b08 100644 --- a/runtime/builtins/builtins_math.cpp +++ b/runtime/builtins/builtins_math.cpp @@ -29,16 +29,16 @@ JSTaggedValue BuiltinsMath::Abs(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Abs); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - if (numberValue.IsDouble()) { + 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(numberValue.GetDouble())); + return GetTaggedDouble(std::fabs(number_value.GetDouble())); } // if number_value is int,boolean,null, deal in this case - return GetTaggedInt(std::abs(numberValue.GetInt())); + return GetTaggedInt(std::abs(number_value.GetInt())); } // 20.2.2.2 @@ -47,10 +47,10 @@ JSTaggedValue BuiltinsMath::Acos(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Acos); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // value == -NaN , <-1 or > 1,result is NaN if (!std::isnan(std::abs(value)) && value <= 1 && value >= -1) { @@ -65,10 +65,10 @@ JSTaggedValue BuiltinsMath::Acosh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Acosh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + 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); @@ -82,10 +82,10 @@ JSTaggedValue BuiltinsMath::Asin(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Asin); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + 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); @@ -99,10 +99,10 @@ JSTaggedValue BuiltinsMath::Asinh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Asinh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // value == -NaN, NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -117,10 +117,10 @@ JSTaggedValue BuiltinsMath::Atan(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atan); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // value == -NaN, NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -135,10 +135,10 @@ JSTaggedValue BuiltinsMath::Atanh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atanh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + 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); @@ -152,25 +152,25 @@ JSTaggedValue BuiltinsMath::Atan2(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Atan2); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle msgY = GetCallArg(argv, 0); - JSHandle msgX = GetCallArg(argv, 1); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle msg_y = GetCallArg(argv, 0); + JSHandle msg_x = GetCallArg(argv, 1); double result = ecmascript::base::NAN_VALUE; - JSTaggedNumber numberValueY = JSTaggedValue::ToNumber(thread, msgY); - JSTaggedNumber numberValueX = JSTaggedValue::ToNumber(thread, msgX); - double valueY = numberValueY.GetNumber(); - double valueX = numberValueX.GetNumber(); + JSTaggedNumber number_value_y = JSTaggedValue::ToNumber(thread, msg_y); + JSTaggedNumber number_value_x = JSTaggedValue::ToNumber(thread, msg_x); + double value_y = number_value_y.GetNumber(); + double value_x = number_value_x.GetNumber(); // y = +0 and x > +0, return +0 // y = -0 and x > +0, return -0 - if (valueY == 0 && valueX > 0) { - result = valueY; - } else if (std::isfinite(valueY) && valueX == std::numeric_limits::infinity()) { + if (value_y == 0 && value_x > 0) { + result = value_y; + } else if (std::isfinite(value_y) && value_x == std::numeric_limits::infinity()) { // y < 0 and y is finite and x is POSITIVE_INFINITY,return -0 // y >= 0 and y is finite and x is POSITIVE_INFINITY,return +0 - result = valueY >= 0 ? 0 : -0.0; - } else if (!std::isnan(std::abs(valueY)) && !std::isnan(std::abs(valueX))) { + result = value_y >= 0 ? 0 : -0.0; + } else if (!std::isnan(std::abs(value_y)) && !std::isnan(std::abs(value_x))) { // If either x or y is NaN, the result is NaN - result = std::atan2(valueY, valueX); + result = std::atan2(value_y, value_x); } return GetTaggedDouble(result); } @@ -181,10 +181,10 @@ JSTaggedValue BuiltinsMath::Cbrt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cbrt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // if value == -NaN, NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -199,10 +199,10 @@ JSTaggedValue BuiltinsMath::Ceil(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Ceil); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, +infinite, -infinite,return value if (!std::isfinite(value)) { @@ -222,16 +222,16 @@ JSTaggedValue BuiltinsMath::Clz32(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Clz32); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - constexpr int defaultValue = 32; + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + constexpr int DEFAULT_VALUE = 32; JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); - auto tmpValue = std::abs(value); - auto result = numberValue.ToUint32(); - if (!std::isfinite(tmpValue) || tmpValue == 0 || result == 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(defaultValue); + return GetTaggedInt(DEFAULT_VALUE); } return GetTaggedInt(__builtin_clz(result)); } @@ -242,10 +242,10 @@ JSTaggedValue BuiltinsMath::Cos(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cos); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, +infinite, -infinite, result is NaN if (std::isfinite(std::abs(value))) { @@ -260,10 +260,10 @@ JSTaggedValue BuiltinsMath::Cosh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Cosh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // if value is NaN or -NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -278,10 +278,10 @@ JSTaggedValue BuiltinsMath::Exp(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Exp); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // if value is NaN or -NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -296,10 +296,10 @@ JSTaggedValue BuiltinsMath::Expm1(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Expm1); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // if value is NaN or -NaN, result is NaN if (!std::isnan(std::abs(value))) { @@ -314,10 +314,10 @@ JSTaggedValue BuiltinsMath::Floor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Floor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, +infinite, -infinite, +0, -0, return value if (!std::isfinite(value) || value == 0) { @@ -340,10 +340,10 @@ JSTaggedValue BuiltinsMath::Fround(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Fround); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result; if (std::isnan(std::abs(value))) { // If result is NaN or -NaN, the result is NaN @@ -360,15 +360,15 @@ JSTaggedValue BuiltinsMath::Hypot(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Hypot); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); double result = 0; double value = 0; - int argLen = argv->GetArgsNumber(); - auto numberValue = JSTaggedNumber(0); - for (int i = 0; i < argLen; i++) { + int arg_len = argv->GetArgsNumber(); + auto number_value = JSTaggedNumber(0); + for (int i = 0; i < arg_len; i++) { JSHandle msg = GetCallArg(argv, i); - numberValue = JSTaggedValue::ToNumber(thread, msg); - value = numberValue.GetNumber(); + number_value = JSTaggedValue::ToNumber(thread, msg); + value = number_value.GetNumber(); result = std::hypot(result, value); } return GetTaggedDouble(result); @@ -380,19 +380,19 @@ JSTaggedValue BuiltinsMath::Imul(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Imul); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg1 = GetCallArg(argv, 0); JSHandle msg2 = GetCallArg(argv, 1); - JSTaggedNumber numberValue1 = JSTaggedValue::ToNumber(thread, msg1); - JSTaggedNumber numberValue2 = JSTaggedValue::ToNumber(thread, msg2); - auto value1 = numberValue1.GetNumber(); - auto value2 = numberValue2.GetNumber(); + 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); } - value1 = numberValue1.ToInt32(); - value2 = numberValue2.ToInt32(); + value1 = number_value1.ToInt32(); + value2 = number_value2.ToInt32(); // purposely ignoring overflow auto result = static_cast(static_cast(value1) * static_cast(value2)); return GetTaggedInt(result); @@ -404,10 +404,10 @@ JSTaggedValue BuiltinsMath::Log(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN , -NaN , or < 0,result is NaN if (!std::isnan(std::abs(value)) && value >= 0) { @@ -422,10 +422,10 @@ JSTaggedValue BuiltinsMath::Log1p(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log1p); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN , -NaN , or < -1,result is NaN if (!std::isnan(std::abs(value)) && value >= -1) { @@ -440,10 +440,10 @@ JSTaggedValue BuiltinsMath::Log10(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log10); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN , -NaN , or < 0,result is NaN if (!std::isnan(std::abs(value)) && value >= 0) { @@ -458,10 +458,10 @@ JSTaggedValue BuiltinsMath::Log2(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Log2); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN , -NaN , or < 0,result is NaN if (!std::isnan(std::abs(value)) && value >= 0) { @@ -482,29 +482,29 @@ JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Max); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - int argLen = argv->GetArgsNumber(); - auto numberValue = JSTaggedNumber(-ecmascript::base::POSITIVE_INFINITY); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + int arg_len = argv->GetArgsNumber(); + auto number_value = JSTaggedNumber(-ecmascript::base::POSITIVE_INFINITY); // If no arguments are given, the result is -inf auto result = JSTaggedNumber(-ecmascript::base::POSITIVE_INFINITY); - auto tmpMax = -ecmascript::base::POSITIVE_INFINITY; + auto tmp_max = -ecmascript::base::POSITIVE_INFINITY; auto value = -ecmascript::base::POSITIVE_INFINITY; - for (int i = 0; i < argLen; i++) { + for (int i = 0; i < arg_len; i++) { JSHandle msg = GetCallArg(argv, i); - numberValue = JSTaggedValue::ToNumber(thread, msg); - value = numberValue.GetNumber(); + number_value = JSTaggedValue::ToNumber(thread, msg); + value = number_value.GetNumber(); if (std::isnan(std::abs(value))) { // If any value is NaN, or -NaN, the max result is NaN - result = numberValue; + result = number_value; break; } - if (value > tmpMax) { - result = numberValue; - tmpMax = value; - } else if (value == 0 && tmpMax == 0 && IsNegZero(tmpMax) && !IsNegZero(value)) { + if (value > tmp_max) { + result = number_value; + tmp_max = value; + } else if (value == 0 && tmp_max == 0 && IsNegZero(tmp_max) && !IsNegZero(value)) { // if tmp_max is -0, value is 0, max is 0 - result = numberValue; - tmpMax = value; + result = number_value; + tmp_max = value; } } return result; @@ -516,29 +516,29 @@ JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Min); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - int argLen = argv->GetArgsNumber(); - auto numberValue = JSTaggedNumber(ecmascript::base::POSITIVE_INFINITY); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + int arg_len = argv->GetArgsNumber(); + auto number_value = JSTaggedNumber(ecmascript::base::POSITIVE_INFINITY); // If no arguments are given, the result is inf auto result = JSTaggedNumber(ecmascript::base::POSITIVE_INFINITY); - auto tmpMin = ecmascript::base::POSITIVE_INFINITY; + auto tmp_min = ecmascript::base::POSITIVE_INFINITY; auto value = ecmascript::base::POSITIVE_INFINITY; - for (int i = 0; i < argLen; i++) { + for (int i = 0; i < arg_len; i++) { JSHandle msg = GetCallArg(argv, i); - numberValue = JSTaggedValue::ToNumber(thread, msg); - value = numberValue.GetNumber(); + number_value = JSTaggedValue::ToNumber(thread, msg); + value = number_value.GetNumber(); if (std::isnan(std::abs(value))) { // If any value is NaN or -NaN, the min result is NaN - result = numberValue; + result = number_value; break; } - if (value < tmpMin) { - result = numberValue; - tmpMin = value; - } else if (value == 0 && tmpMin == 0 && !IsNegZero(tmpMin) && IsNegZero(value)) { + if (value < tmp_min) { + result = number_value; + tmp_min = value; + } else if (value == 0 && tmp_min == 0 && !IsNegZero(tmp_min) && IsNegZero(value)) { // if tmp_min is 0, value is -0, min is -0 - result = numberValue; - tmpMin = value; + result = number_value; + tmp_min = value; } } return result; @@ -550,14 +550,14 @@ JSTaggedValue BuiltinsMath::Pow(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Pow); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle msgX = GetCallArg(argv, 0); - JSHandle msgY = GetCallArg(argv, 1); - JSTaggedNumber numberValueX = JSTaggedValue::ToNumber(thread, msgX); - JSTaggedNumber numberValueY = JSTaggedValue::ToNumber(thread, msgY); - double valueX = numberValueX.GetNumber(); - double valueY = numberValueY.GetNumber(); - return base::NumberHelper::Pow(valueX, valueY); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle msg_x = GetCallArg(argv, 0); + JSHandle msg_y = 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(); + double value_y = number_value_y.GetNumber(); + return base::NumberHelper::Pow(value_x, value_y); } // 20.2.2.27 @@ -579,16 +579,16 @@ JSTaggedValue BuiltinsMath::Round(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Round); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); auto result = ecmascript::base::NAN_VALUE; const double diff = 0.5; - double absValue = std::abs(value); - if (!std::isfinite(absValue) || absValue == 0) { + double abs_value = std::abs(value); + if (!std::isfinite(abs_value) || abs_value == 0) { // If value is NaN, +infinite, or -infinite, VRegisterTag is DOUBLE - if (!std::isnan(absValue)) { + if (!std::isnan(abs_value)) { // If value is NaN or -NaN, the result is default NaN, else is value result = value; } @@ -616,10 +616,10 @@ JSTaggedValue BuiltinsMath::Sign(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sign); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); if (std::isnan(std::abs(value))) { return GetTaggedDouble(std::abs(value)); } @@ -638,10 +638,10 @@ JSTaggedValue BuiltinsMath::Sin(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sin); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, the result is NaN if (std::isfinite(std::abs(value))) { @@ -656,10 +656,10 @@ JSTaggedValue BuiltinsMath::Sinh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sinh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, the result is NaN if (!std::isnan(std::abs(value))) { @@ -674,10 +674,10 @@ JSTaggedValue BuiltinsMath::Sqrt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Sqrt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, or value < 0, the result is NaN if (!std::isnan(std::abs(value)) && value >= 0) { @@ -692,10 +692,10 @@ JSTaggedValue BuiltinsMath::Tan(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Tan); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; // If value is NaN or -NaN, +infinite, -infinite, result is NaN if (std::isfinite(value)) { @@ -710,10 +710,10 @@ JSTaggedValue BuiltinsMath::Tanh(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Tanh); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + 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); @@ -727,10 +727,10 @@ JSTaggedValue BuiltinsMath::Trunc(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Math, Trunc); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); - JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); - double value = numberValue.GetNumber(); + JSTaggedNumber number_value = JSTaggedValue::ToNumber(thread, msg); + double value = number_value.GetNumber(); double result = ecmascript::base::NAN_VALUE; if (!std::isfinite(value)) { // if value is +infinite, -infinite, NaN, -NaN, VRegisterTag is double diff --git a/runtime/builtins/builtins_number.cpp b/runtime/builtins/builtins_number.cpp index 1c0f2a9bd45d572311f11785e928922c66e50c77..0740fd72a5cd133a5b25831367655cbe0b32f865 100644 --- a/runtime/builtins/builtins_number.cpp +++ b/runtime/builtins/builtins_number.cpp @@ -35,19 +35,19 @@ JSTaggedValue BuiltinsNumber::NumberConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle new_target = GetNewTarget(argv); // 1. If no arguments were passed to this function invocation, let n be +0. - JSTaggedNumber numberValue(0); + JSTaggedNumber number_value(0); if (argv->GetArgsNumber() > 0) { // 2. Else, let n be ToNumber(value). - JSHandle numberInput = GetCallArg(argv, 0); - numberValue = JSTaggedValue::ToNumber(thread, numberInput); + JSHandle number_input = GetCallArg(argv, 0); + number_value = JSTaggedValue::ToNumber(thread, number_input); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 4. If NewTarget is undefined, return n. if (new_target->IsUndefined()) { - return numberValue; + return number_value; } // 5. Let O be OrdinaryCreateFromConstructor(NewTarget, "%NumberPrototype%", «[[NumberData]]» ). JSHandle constructor = GetConstructor(argv); @@ -56,7 +56,7 @@ JSTaggedValue BuiltinsNumber::NumberConstructor(EcmaRuntimeCallInfo *argv) // 6. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Set the value of O’s [[NumberData]] internal slot to n. - JSPrimitiveRef::Cast(*result)->SetValue(thread, numberValue); + JSPrimitiveRef::Cast(*result)->SetValue(thread, number_value); // 8. Return O. return result.GetTaggedValue(); } @@ -86,7 +86,7 @@ JSTaggedValue BuiltinsNumber::IsInteger(EcmaRuntimeCallInfo *argv) // 1. If Type(number) is not Number, return false. // 2. If number is NaN, +infinite, or -infinite, return false if (NumberHelper::IsFinite(msg.GetTaggedValue())) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber(); // 3. Let integer be ToInteger(number). JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg); @@ -123,7 +123,7 @@ JSTaggedValue BuiltinsNumber::IsSafeInteger(EcmaRuntimeCallInfo *argv) // 1. If Type(number) is not Number, return false. // 2. If number is NaN, +infinite, or -infinite, return false if (NumberHelper::IsFinite(msg.GetTaggedValue())) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber(); // 3. Let integer be ToInteger(number). JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg); @@ -156,22 +156,22 @@ JSTaggedValue BuiltinsNumber::ParseFloat(EcmaRuntimeCallInfo *argv) if (msg->IsUndefined()) { return GetTaggedDouble(ecmascript::base::NAN_VALUE); } - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let inputString be ToString(string). - JSHandle numberString = JSTaggedValue::ToString(thread, msg); + JSHandle number_string = JSTaggedValue::ToString(thread, msg); // 2. ReturnIfAbrupt(inputString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (UNLIKELY(numberString->IsUtf16())) { - size_t len = utf::Utf16ToUtf8Size(numberString->GetDataUtf16(), numberString->GetLength()) - 1; + if (UNLIKELY(number_string->IsUtf16())) { + size_t len = utf::Utf16ToUtf8Size(number_string->GetDataUtf16(), number_string->GetLength()) - 1; PandaVector buf(len); - len = - utf::ConvertRegionUtf16ToUtf8(numberString->GetDataUtf16(), buf.data(), numberString->GetLength(), len, 0); + len = utf::ConvertRegionUtf16ToUtf8(number_string->GetDataUtf16(), buf.data(), number_string->GetLength(), len, + 0); auto str = Span(buf.data(), len); return ParseFloatStr(str); } - auto str = Span(numberString->GetDataUtf8(), numberString->GetUtf8Length() - 1); + auto str = Span(number_string->GetDataUtf8(), number_string->GetUtf8Length() - 1); return ParseFloatStr(str); } @@ -187,7 +187,7 @@ JSTaggedValue BuiltinsNumber::ParseInt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ParseInt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); JSHandle arg2 = GetCallArg(argv, 1); int32_t radix = 0; @@ -198,19 +198,19 @@ JSTaggedValue BuiltinsNumber::ParseInt(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 1. Let inputString be ToString(string). - JSHandle numberString = JSTaggedValue::ToString(thread, msg); + JSHandle number_string = JSTaggedValue::ToString(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (UNLIKELY(numberString->IsUtf16())) { - size_t len = utf::Utf16ToUtf8Size(numberString->GetDataUtf16(), numberString->GetLength()) - 1; + if (UNLIKELY(number_string->IsUtf16())) { + size_t len = utf::Utf16ToUtf8Size(number_string->GetDataUtf16(), number_string->GetLength()) - 1; PandaVector buf(len); - len = - utf::ConvertRegionUtf16ToUtf8(numberString->GetDataUtf16(), buf.data(), numberString->GetLength(), len, 0); + len = utf::ConvertRegionUtf16ToUtf8(number_string->GetDataUtf16(), buf.data(), number_string->GetLength(), len, + 0); auto str = Span(buf.data(), len); return ParseIntStr(str, radix); } - auto str = Span(numberString->GetDataUtf8(), numberString->GetUtf8Length() - 1); + auto str = Span(number_string->GetDataUtf8(), number_string->GetUtf8Length() - 1); return ParseIntStr(str, radix); } @@ -221,7 +221,7 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToExponential); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber value = ThisNumberValue(argv); // 2. ReturnIfAbrupt(x). @@ -229,7 +229,7 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) // 3. Let f be ToInteger(fractionDigits). JSHandle digits = GetCallArg(argv, 0); - JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digits); + JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digits); // 5. ReturnIfAbrupt(f). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -252,7 +252,7 @@ JSTaggedValue BuiltinsNumber::ToExponential(EcmaRuntimeCallInfo *argv) // 4. Assert: f is 0, when fractionDigits is undefined. // 10. If f < 0 or f > 20, throw a RangeError exception - double fraction = digitInt.GetNumber(); + double fraction = digit_int.GetNumber(); if (digits->IsUndefined()) { fraction = -1; } else { @@ -269,38 +269,38 @@ JSTaggedValue BuiltinsNumber::ToFixed(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToFixed); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber value = ThisNumberValue(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 digitArgv = GetCallArg(argv, 0); - JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digitArgv); - if (digitArgv->IsUndefined()) { - digitInt = JSTaggedNumber(0); + JSHandle digit_argv = GetCallArg(argv, 0); + JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digit_argv); + if (digit_argv->IsUndefined()) { + digit_int = JSTaggedNumber(0); } // 4. ReturnIfAbrupt(f). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double digit = digitInt.GetNumber(); + double digit = digit_int.GetNumber(); if (digit < ecmascript::base::MIN_FRACTION || digit > ecmascript::base::MAX_FRACTION) { THROW_RANGE_ERROR_AND_RETURN(thread, "fraction must be 0 to 100", JSTaggedValue::Exception()); } // 6. If x is NaN, return the String "NaN". - double valueNumber = value.GetNumber(); - if (std::isnan(valueNumber)) { + double value_number = value.GetNumber(); + if (std::isnan(value_number)) { return GetTaggedString(thread, "NaN"); } // 9. If x  1021, then // a. Let m = ToString(x). - const double FIRST_NO_FIXED = 1e21; - if (valueNumber >= FIRST_NO_FIXED) { + const double first_no_fixed = 1e21; + if (value_number >= first_no_fixed) { return value.ToString(thread).GetTaggedValue(); } - return NumberHelper::DoubleToFixed(thread, valueNumber, static_cast(digit)); + return NumberHelper::DoubleToFixed(thread, value_number, static_cast(digit)); } // 20.1.3.4 @@ -309,7 +309,7 @@ JSTaggedValue BuiltinsNumber::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, Number, ToLocaleString); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber x = ThisNumberValue(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -317,14 +317,14 @@ JSTaggedValue BuiltinsNumber::ToLocaleString(EcmaRuntimeCallInfo *argv) JSHandle ctor = thread->GetEcmaVM()->GetGlobalEnv()->GetNumberFormatFunction(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(ctor), ctor); - JSHandle numberFormat = JSHandle::Cast(obj); + JSHandle number_format = JSHandle::Cast(obj); JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); + JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Return ? FormatNumeric(numberFormat, x). - JSHandle result = JSNumberFormat::FormatNumeric(thread, numberFormat, x); + JSHandle result = JSNumberFormat::FormatNumeric(thread, number_format, x); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -335,42 +335,42 @@ JSTaggedValue BuiltinsNumber::ToPrecision(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToPrecision); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber value = ThisNumberValue(argv); // 2. ReturnIfAbrupt(x). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If precision is undefined, return ToString(x). - JSHandle digitArgv = GetCallArg(argv, 0); - if (digitArgv->IsUndefined()) { + JSHandle digit_argv = GetCallArg(argv, 0); + if (digit_argv->IsUndefined()) { return value.ToString(thread).GetTaggedValue(); } // 4. Let p be ToInteger(precision). - JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digitArgv); + JSTaggedNumber digit_int = JSTaggedValue::ToInteger(thread, digit_argv); // 5. ReturnIfAbrupt(p). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If x is NaN, return the String "NaN". - double valueNumber = value.GetNumber(); - if (std::isnan(valueNumber)) { + double value_number = value.GetNumber(); + if (std::isnan(value_number)) { return GetTaggedString(thread, "NaN"); } // 9. If x = +infinity, then // a. Return the String that is the concatenation of s and "Infinity". - if (!std::isfinite(valueNumber)) { - if (valueNumber < 0) { + if (!std::isfinite(value_number)) { + if (value_number < 0) { return GetTaggedString(thread, "-Infinity"); } return GetTaggedString(thread, "Infinity"); } // If p < 1 or p > 21, throw a RangeError exception - double digit = digitInt.GetNumber(); + double digit = digit_int.GetNumber(); if (digit < ecmascript::base::MIN_FRACTION + 1 || digit > ecmascript::base::MAX_FRACTION) { THROW_RANGE_ERROR_AND_RETURN(thread, "fraction must be 1 to 100", JSTaggedValue::Exception()); } - return NumberHelper::DoubleToPrecision(thread, valueNumber, static_cast(digit)); + return NumberHelper::DoubleToPrecision(thread, value_number, static_cast(digit)); } // 20.1.3.6 @@ -379,7 +379,7 @@ JSTaggedValue BuiltinsNumber::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Number, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let x be ? thisNumberValue(this value). JSTaggedNumber value = ThisNumberValue(argv); // 2. ReturnIfAbrupt(x). @@ -388,13 +388,13 @@ 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 radixValue = GetCallArg(argv, 0); + JSHandle radix_value = GetCallArg(argv, 0); // 5. Else let radixNumber be ToInteger(radix). - if (!radixValue->IsUndefined()) { - JSTaggedNumber radixNumber = JSTaggedValue::ToInteger(thread, radixValue); + if (!radix_value->IsUndefined()) { + JSTaggedNumber radix_number = JSTaggedValue::ToInteger(thread, radix_value); // 6. ReturnIfAbrupt(x). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - radix = radixNumber.GetNumber(); + radix = radix_number.GetNumber(); } // 7. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception. @@ -406,20 +406,20 @@ JSTaggedValue BuiltinsNumber::ToString(EcmaRuntimeCallInfo *argv) return value.ToString(thread).GetTaggedValue(); } - double valueNumber = value.GetNumber(); + double value_number = value.GetNumber(); // If x is NaN, return the String "NaN". - if (std::isnan(valueNumber)) { + if (std::isnan(value_number)) { return GetTaggedString(thread, "NaN"); } // If x = +infinity, then // Return the String that is the concatenation of s and "Infinity". - if (!std::isfinite(valueNumber)) { - if (valueNumber < 0) { + if (!std::isfinite(value_number)) { + if (value_number < 0) { return GetTaggedString(thread, "-Infinity"); } return GetTaggedString(thread, "Infinity"); } - return NumberHelper::DoubleToString(thread, valueNumber, static_cast(radix)); + return NumberHelper::DoubleToString(thread, value_number, static_cast(radix)); } // 20.1.3.7 @@ -448,7 +448,7 @@ JSTaggedNumber BuiltinsNumber::ThisNumberValue(EcmaRuntimeCallInfo *argv) } } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); THROW_TYPE_ERROR_AND_RETURN(thread, "not number type", JSTaggedNumber::Exception()); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_number_format.cpp b/runtime/builtins/builtins_number_format.cpp index ef8cc47eddb79d43bafe2210ae3483df22d7d45c..92692ffe4c050d855dff7f123b2b451d63080f38 100644 --- a/runtime/builtins/builtins_number_format.cpp +++ b/runtime/builtins/builtins_number_format.cpp @@ -29,9 +29,9 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + 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); @@ -45,36 +45,36 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatConstructor(EcmaRuntimeCallInfo // [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], // [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], // [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »). - JSHandle numberFormat = JSHandle::Cast( + JSHandle number_format = JSHandle::Cast( factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Perform ? InitializeNumberFormat(numberFormat, locales, options). JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, options); + JSNumberFormat::InitializeNumberFormat(thread, number_format, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let this be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 5. If NewTarget is undefined and Type(this) is Object and ? InstanceofOperator(this, %NumberFormat%) is true, // then // a. Perform ? DefinePropertyOrThrow(this, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ // [[Value]]: numberFormat, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }). // b. Return this. - bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetNumberFormatFunction()); + bool is_instance_of = JSObject::InstanceOf(thread, this_value, env->GetNumberFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { - PropertyDescriptor descriptor(thread, JSHandle::Cast(numberFormat), false, false, false); + if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { + PropertyDescriptor descriptor(thread, JSHandle::Cast(number_format), false, false, false); JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + JSTaggedValue::DefinePropertyOrThrow(thread, this_value, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return thisValue.GetTaggedValue(); + return this_value.GetTaggedValue(); } // 6. Return numberFormat. - return numberFormat.GetTaggedValue(); + return number_format.GetTaggedValue(); } // 13.3.2 Intl.NumberFormat.supportedLocalesOf ( locales [ , options ] ) @@ -83,16 +83,16 @@ JSTaggedValue BuiltinsNumberFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %NumberFormat%.[[AvailableLocales]]. - JSHandle availableLocales = JSNumberFormat::GetAvailableLocales(thread); + JSHandle available_locales = JSNumberFormat::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + 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 result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); + JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -104,32 +104,32 @@ JSTaggedValue BuiltinsNumberFormat::Format(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(nf) is not Object, throw a TypeError exception. - if (!thisValue->IsJSObject()) { + if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception()); } // 3. Let nf be ? UnwrapNumberFormat(nf). - JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue); + JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (nf->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "nf is not object", JSTaggedValue::Exception()); } - JSHandle typpedNf = JSHandle::Cast(nf); - JSHandle boundFunc(thread, typpedNf->GetBoundFormat()); + JSHandle typped_nf = JSHandle::Cast(nf); + JSHandle bound_func(thread, typped_nf->GetBoundFormat()); // 4. If nf.[[BoundFormat]] is undefined, then // a. Let F be a new built-in function object as defined in Number Format Functions (12.1.4). // b. Set F.[[NumberFormat]] to nf. // c. Set nf.[[BoundFormat]] to F. - if (boundFunc->IsUndefined()) { + if (bound_func->IsUndefined()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction( + JSHandle intl_bound_func = factory->NewJSIntlBoundFunction( reinterpret_cast(BuiltinsNumberFormat::NumberFormatInternalFormatNumber)); - intlBoundFunc->SetNumberFormat(thread, typpedNf); - typpedNf->SetBoundFormat(thread, intlBoundFunc); + intl_bound_func->SetNumberFormat(thread, typped_nf); + typped_nf->SetBoundFormat(thread, intl_bound_func); } - return typpedNf->GetBoundFormat(); + return typped_nf->GetBoundFormat(); } // 13.4.4 Intl.NumberFormat.prototype.formatToParts ( date ) @@ -159,18 +159,18 @@ JSTaggedValue BuiltinsNumberFormat::ResolvedOptions(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let nf be this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(nf) is not Object, throw a TypeError exception. - if (!thisValue->IsJSObject()) { + if (!this_value->IsJSObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not object", JSTaggedValue::Exception()); } // 3. Let nf be ? UnwrapNumberFormat(nf). - JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, thisValue); + JSHandle nf = JSNumberFormat::UnwrapNumberFormat(thread, this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let options be ! ObjectCreate(%ObjectPrototype%). - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); @@ -187,10 +187,10 @@ JSTaggedValue BuiltinsNumberFormat::NumberFormatInternalFormatNumber(EcmaRuntime { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - JSHandle intlBoundFunc = JSHandle::Cast(GetConstructor(argv)); + JSHandle intl_bound_func = JSHandle::Cast(GetConstructor(argv)); // 1. Let nf be F.[[NumberFormat]]. - JSHandle nf(thread, intlBoundFunc->GetNumberFormat()); + 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. diff --git a/runtime/builtins/builtins_object.cpp b/runtime/builtins/builtins_object.cpp index fde1dcf1d42847e671d58356c9312b6f563822ad..1177bb98eeb561264b0f3d5847993e6c5b3366e3 100644 --- a/runtime/builtins/builtins_object.cpp +++ b/runtime/builtins/builtins_object.cpp @@ -34,9 +34,9 @@ JSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); // 1.If NewTarget is neither undefined nor the active function, then // a.Return OrdinaryCreateFromConstructor(NewTarget, "%ObjectPrototype%"). @@ -44,14 +44,14 @@ JSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv) JSHandle new_target = GetNewTarget(argv); if (!new_target->IsUndefined() && !(new_target.GetTaggedValue() == constructor.GetTaggedValue())) { JSHandle obj = - ecmaVm->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), new_target); + ecma_vm->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), new_target); return obj.GetTaggedValue(); } // 2.If value is null, undefined or not supplied, return ObjectCreate(%ObjectPrototype%). JSHandle value = GetCallArg(argv, 0); if (value->IsNull() || value->IsUndefined()) { - JSHandle obj = ecmaVm->GetFactory()->OrdinaryNewJSObjectCreate(env->GetObjectFunctionPrototype()); + JSHandle obj = ecma_vm->GetFactory()->OrdinaryNewJSObjectCreate(env->GetObjectFunctionPrototype()); return obj.GetTaggedValue(); } @@ -65,12 +65,12 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Assign); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); - uint32_t numArgs = argv->GetArgsNumber(); + uint32_t num_args = argv->GetArgsNumber(); // 1.Let to be ToObject(target). JSHandle target = GetCallArg(argv, 0); - JSHandle toAssign = JSTaggedValue::ToObject(thread, target); + JSHandle to_assign = JSTaggedValue::ToObject(thread, target); // 2.ReturnIfAbrupt(to). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -84,7 +84,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // iii.ReturnIfAbrupt(keys). JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 1; i < numArgs; i++) { + for (uint32_t i = 1; i < num_args; i++) { JSHandle source = GetCallArg(argv, i); if (!source->IsNull() && !source->IsUndefined()) { JSHandle from = JSTaggedValue::ToObject(thread, source); @@ -102,8 +102,8 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // 2.ReturnIfAbrupt(propValue). // 3.Let status be Set(to, nextKey, propValue, true). // 4.ReturnIfAbrupt(status). - uint32_t keysLen = keys->GetLength(); - for (uint32_t j = 0; j < keysLen; j++) { + uint32_t keys_len = keys->GetLength(); + for (uint32_t j = 0; j < keys_len; j++) { PropertyDescriptor desc(thread); key.Update(keys->Get(j)); bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(from), key, desc); @@ -115,7 +115,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // ReturnIfAbrupt(prop_value) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(toAssign), key, value); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(to_assign), key, value); // ReturnIfAbrupt(status) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -124,7 +124,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) } // 6.Return to. - return toAssign.GetTaggedValue(); + return to_assign.GetTaggedValue(); } // Runtime Semantics @@ -146,14 +146,14 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.Let keys be props.[[OwnPropertyKeys]](). - JSHandle handleKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(props)); + JSHandle handle_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(props)); // 5.ReturnIfAbrupt(keys). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6.Let descriptors be an empty List. // new an empty array and append - uint32_t length = handleKeys->GetLength(); + uint32_t length = handle_keys->GetLength(); [[maybe_unused]] JSHandle descriptors = factory->NewTaggedArray(2 * length); // 2: 2 means two element list @@ -166,23 +166,24 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH // iii.Let desc be ToPropertyDescriptor(descObj). // iv.ReturnIfAbrupt(desc). // v.Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors. - JSMutableHandle handleKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle handle_key(thread, JSTaggedValue::Undefined()); for (uint32_t i = 0; i < length; i++) { - PropertyDescriptor propDesc(thread); - handleKey.Update(handleKeys->Get(i)); + PropertyDescriptor prop_desc(thread); + handle_key.Update(handle_keys->Get(i)); - bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(props), handleKey, propDesc); + bool success = + JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(props), handle_key, prop_desc); // ReturnIfAbrupt(propDesc) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (success && propDesc.IsEnumerable()) { - JSHandle descObj = - JSTaggedValue::GetProperty(thread, JSHandle::Cast(props), handleKey).GetValue(); + if (success && prop_desc.IsEnumerable()) { + JSHandle desc_obj = + JSTaggedValue::GetProperty(thread, JSHandle::Cast(props), handle_key).GetValue(); // ReturnIfAbrupt(descObj) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PropertyDescriptor desc(thread); - JSObject::ToPropertyDescriptor(thread, descObj, desc); + JSObject::ToPropertyDescriptor(thread, desc_obj, desc); // ReturnIfAbrupt(desc) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -192,7 +193,7 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH // b.Let desc be the second element of pair. // c.Let status be DefinePropertyOrThrow(O,P, desc). // d.ReturnIfAbrupt(status). - [[maybe_unused]] bool setSuccess = JSTaggedValue::DefinePropertyOrThrow(thread, obj, handleKey, desc); + [[maybe_unused]] bool set_success = JSTaggedValue::DefinePropertyOrThrow(thread, obj, handle_key, desc); // ReturnIfAbrupt(status) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -209,7 +210,7 @@ JSTaggedValue BuiltinsObject::Create(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Create); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(O) is neither Object nor Null, throw a TypeError exception. JSHandle obj = GetCallArg(argv, 0); if (!obj->IsECMAObject() && !obj->IsNull()) { @@ -220,16 +221,16 @@ JSTaggedValue BuiltinsObject::Create(EcmaRuntimeCallInfo *argv) JSHandle properties = GetCallArg(argv, 1); // 2.Let obj be ObjectCreate(O). - JSHandle objCreate = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(obj); + JSHandle obj_create = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(obj); // 3.If the argument Properties is present and not undefined, then // a.Return ObjectDefineProperties(obj, Properties). if (!properties->IsUndefined()) { - return ObjectDefineProperties(thread, JSHandle::Cast(objCreate), properties); + return ObjectDefineProperties(thread, JSHandle::Cast(obj_create), properties); } // 4.Return obj. - return objCreate.GetTaggedValue(); + return obj_create.GetTaggedValue(); } // 19.1.2.3 Object.defineProperties ( O, Properties ) @@ -238,7 +239,7 @@ JSTaggedValue BuiltinsObject::DefineProperties(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineProperties); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Return ObjectDefineProperties(O, Properties). return ObjectDefineProperties(thread, GetCallArg(argv, 0), GetCallArg(argv, 1)); } @@ -249,7 +250,7 @@ JSTaggedValue BuiltinsObject::DefineProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(O) is not Object, throw a TypeError exception. JSHandle obj = GetCallArg(argv, 0); @@ -293,7 +294,7 @@ JSTaggedValue BuiltinsObject::Freeze(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2.Let status be SetIntegrityLevel( O, "frozen"). bool status = JSObject::SetIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::FROZEN); @@ -317,7 +318,7 @@ JSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, SetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Perform ? RequireObjectCoercible(iterable). JSHandle iterable = GetCallArg(argv, 0); @@ -333,22 +334,22 @@ JSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv) ASSERT(obj->IsExtensible()); // 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions. - EcmaEntrypoint stepsDefine = base::ObjectHelper::CreateDataPropertyOnObject; + EcmaEntrypoint steps_define = base::ObjectHelper::CreateDataPropertyOnObject; // 5. Let lengthDefine be the number of non-optional parameters of the function definition in - size_t lengthDefine = 2; + size_t length_define = 2; // CreateDataPropertyOnObject Functions. // 6. Let adder be ! CreateBuiltinFunction(stepsDefine, lengthDefine, "", « »). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle adder = factory->CreateBuiltinFunction( - stepsDefine, lengthDefine, JSHandle(factory->NewFromString("")), + steps_define, length_define, JSHandle(factory->NewFromString("")), JSHandle(thread, JSTaggedValue::Undefined()), thread->GlobalConstants()->GetHandledUndefined()); // 7. Return ? AddEntriesFromIterable(obj, iterable, adder). - JSHandle adderHandler(thread, adder.GetTaggedValue()); + JSHandle adder_handler(thread, adder.GetTaggedValue()); JSTaggedValue result = - base::ObjectHelper::AddEntriesFromIterable(thread, JSHandle(obj), iterable, adderHandler); + base::ObjectHelper::AddEntriesFromIterable(thread, JSHandle(obj), iterable, adder_handler); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); return result; } @@ -359,7 +360,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDesciptor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let obj be ToObject(O). JSHandle func = GetCallArg(argv, 0); @@ -393,7 +394,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptors(EcmaRuntimeCallInfo *argv ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyDesciptor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). JSHandle func = GetCallArg(argv, 0); @@ -401,7 +402,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptors(EcmaRuntimeCallInfo *argv RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let ownKeys be ? obj.[[OwnPropertyKeys]](). - JSHandle ownKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); + JSHandle own_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). @@ -410,9 +411,9 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyDesciptors(EcmaRuntimeCallInfo *argv thread->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(constructor), constructor)); // 4. For each element key of ownKeys, do - for (ArraySizeT i = 0; i < ownKeys->GetLength(); i++) { + for (ArraySizeT i = 0; i < own_keys->GetLength(); i++) { // a. Let desc be ? obj.[[GetOwnProperty]](key). - JSHandle key(thread, ownKeys->Get(i)); + JSHandle key(thread, own_keys->Get(i)); PropertyDescriptor desc(thread); JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(obj), key, desc); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -444,35 +445,35 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3.Let keys be obj.[[OwnPropertyKeys]](). - JSHandle handleKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); + JSHandle handle_keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle::Cast(obj)); // 4.ReturnIfAbrupt(keys). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5.Let nameList be a new empty List. // new an empty array and append - uint32_t length = handleKeys->GetLength(); - JSHandle nameList = factory->NewTaggedArray(length); + uint32_t length = handle_keys->GetLength(); + JSHandle name_list = factory->NewTaggedArray(length); // 6.Repeat for each element nextKey of keys in List order, - uint32_t copyLength = 0; + uint32_t copy_length = 0; switch (type) { case KeyType::STRING_TYPE: { for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = handleKeys->Get(i); + JSTaggedValue key = handle_keys->Get(i); if (key.IsString()) { - nameList->Set(thread, copyLength, key); - copyLength++; + name_list->Set(thread, copy_length, key); + copy_length++; } } break; } case KeyType::SYMBOL_TYPE: { for (uint32_t i = 0; i < length; i++) { - JSTaggedValue key = handleKeys->Get(i); + JSTaggedValue key = handle_keys->Get(i); if (key.IsSymbol()) { - nameList->Set(thread, copyLength, key); - copyLength++; + name_list->Set(thread, copy_length, key); + copy_length++; } } break; @@ -482,9 +483,9 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl } // 7.Return CreateArrayFromList(nameList). - JSHandle resultList = factory->CopyArray(nameList, length, copyLength); - JSHandle resultArray = JSArray::CreateArrayFromList(thread, resultList); - return resultArray.GetTaggedValue(); + JSHandle result_list = factory->CopyArray(name_list, length, copy_length); + JSHandle result_array = JSArray::CreateArrayFromList(thread, result_list); + return result_array.GetTaggedValue(); } // 19.1.2.7 Object.getOwnPropertyNames ( O ) @@ -492,7 +493,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyNames(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertyNames); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSHandle obj = GetCallArg(argv, 0); KeyType type = KeyType::STRING_TYPE; @@ -505,7 +506,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetOwnPropertySymbols); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSHandle obj = GetCallArg(argv, 0); KeyType type = KeyType::SYMBOL_TYPE; @@ -519,7 +520,7 @@ JSTaggedValue BuiltinsObject::GetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, GetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let obj be ToObject(O). JSHandle func = GetCallArg(argv, 0); @@ -554,7 +555,7 @@ JSTaggedValue BuiltinsObject::IsExtensible(EcmaRuntimeCallInfo *argv) if (!obj.IsObject()) { return GetTaggedBoolean(false); } - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2.Return IsExtensible(O). return GetTaggedBoolean(obj.IsExtensible(thread)); } @@ -570,7 +571,7 @@ JSTaggedValue BuiltinsObject::IsFrozen(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2.Return TestIntegrityLevel(O, "frozen"). bool status = JSObject::TestIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::FROZEN); @@ -589,7 +590,7 @@ JSTaggedValue BuiltinsObject::IsSealed(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2.Return TestIntegrityLevel(O, "sealed"). bool status = JSObject::TestIntegrityLevel(thread, JSHandle(obj), IntegrityLevel::SEALED); @@ -602,7 +603,7 @@ JSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). JSHandle msg = GetCallArg(argv, 0); @@ -612,11 +613,11 @@ JSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv) // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key) ArraySizeT count = 0; - JSHandle nameList = JSObject::EnumerableOwnPropertyNames(thread, obj, PropertyKind::KEY, &count); + JSHandle name_list = JSObject::EnumerableOwnPropertyNames(thread, obj, PropertyKind::KEY, &count); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayFromList(nameList). - JSHandle result = JSArray::CreateArrayFromList(thread, nameList, count); + JSHandle result = JSArray::CreateArrayFromList(thread, name_list, count); return result.GetTaggedValue(); } @@ -630,7 +631,7 @@ JSTaggedValue BuiltinsObject::PreventExtensions(EcmaRuntimeCallInfo *argv) if (!obj->IsECMAObject()) { return obj.GetTaggedValue(); } - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); // 2. Let status be O.[[PreventExtensions]](). bool status = JSTaggedValue::PreventExtensions(argv->GetThread(), obj); @@ -662,7 +663,7 @@ JSTaggedValue BuiltinsObject::Seal(EcmaRuntimeCallInfo *argv) } JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2. Let status be SetIntegrityLevel(O, "sealed"). JSHandle object = JSTaggedValue::ToObject(thread, msg); @@ -687,7 +688,7 @@ JSTaggedValue BuiltinsObject::SetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, SetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(O). JSHandle object = JSTaggedValue::RequireObjectCoercible(thread, GetCallArg(argv, 0)); @@ -731,7 +732,7 @@ JSTaggedValue BuiltinsObject::HasOwnProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, HasOwnProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let P be ToPropertyKey(V). JSHandle prop = GetCallArg(argv, 0); JSHandle property = JSTaggedValue::ToPropertyKey(thread, prop); @@ -761,7 +762,7 @@ JSTaggedValue BuiltinsObject::IsPrototypeOf(EcmaRuntimeCallInfo *argv) if (!msg->IsECMAObject()) { return GetTaggedBoolean(false); } - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 2. Let O be ToObject(this value). JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); // 3. ReturnIfAbrupt(O). @@ -771,12 +772,12 @@ JSTaggedValue BuiltinsObject::IsPrototypeOf(EcmaRuntimeCallInfo *argv) // a. Let V be V.[[GetPrototypeOf]](). // b. If V is null, return false // c. If SameValue(O, V) is true, return true. - JSTaggedValue msgValue = msg.GetTaggedValue(); - while (!msgValue.IsNull()) { - if (JSTaggedValue::SameValue(object.GetTaggedValue(), msgValue)) { + JSTaggedValue msg_value = msg.GetTaggedValue(); + while (!msg_value.IsNull()) { + if (JSTaggedValue::SameValue(object.GetTaggedValue(), msg_value)) { return GetTaggedBoolean(true); } - msgValue = JSObject::Cast(msgValue)->GetPrototype(thread); + msg_value = JSObject::Cast(msg_value)->GetPrototype(thread); } return GetTaggedBoolean(false); } @@ -787,7 +788,7 @@ JSTaggedValue BuiltinsObject::PropertyIsEnumerable(EcmaRuntimeCallInfo *argv) ASSERT(argv); // 1. Let P be ToPropertyKey(V). JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle msg = GetCallArg(argv, 0); JSHandle property = JSTaggedValue::ToPropertyKey(thread, msg); @@ -821,13 +822,13 @@ JSTaggedValue BuiltinsObject::ToLocaleString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToLocaleString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. JSHandle object = GetThis(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); // 2. Return Invoke(O, "toString"). - JSHandle calleeKey = thread->GlobalConstants()->GetHandledToStringString(); + JSHandle callee_key = thread->GlobalConstants()->GetHandledToStringString(); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), object, JSTaggedValue::Undefined(), argv->GetArgsNumber()); @@ -835,47 +836,47 @@ JSTaggedValue BuiltinsObject::ToLocaleString(EcmaRuntimeCallInfo *argv) info->SetCallArg(argv->GetArgsNumber(), reinterpret_cast(argv->GetArgAddress(js_method_args::NUM_MANDATORY_ARGS))); } - return JSFunction::Invoke(info.get(), calleeKey); + return JSFunction::Invoke(info.Get(), callee_key); } JSTaggedValue BuiltinsObject::GetBuiltinTag(JSThread *thread, const JSHandle &object) { BUILTINS_API_TRACE(thread, Object, GetBuiltinTag); // 4. Let isArray be IsArray(O). - bool isArray = object->IsJSArray(); + bool is_array = object->IsJSArray(); // 5. ReturnIfAbrupt(isArray). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle builtinTag = factory->NewFromCanBeCompressString("Object"); + JSHandle builtin_tag = factory->NewFromCanBeCompressString("Object"); // 6. If isArray is true, let builtinTag be "Array". - if (isArray) { - builtinTag = factory->NewFromCanBeCompressString("Array"); + if (is_array) { + builtin_tag = factory->NewFromCanBeCompressString("Array"); } else if (object->IsJSPrimitiveRef()) { // 7. Else, if O is an exotic String object, let builtinTag be "String". - JSPrimitiveRef *primitiveRef = JSPrimitiveRef::Cast(*object); - if (primitiveRef->IsString()) { - builtinTag = factory->NewFromCanBeCompressString("String"); - } else if (primitiveRef->IsBoolean()) { + JSPrimitiveRef *primitive_ref = JSPrimitiveRef::Cast(*object); + if (primitive_ref->IsString()) { + builtin_tag = factory->NewFromCanBeCompressString("String"); + } else if (primitive_ref->IsBoolean()) { // 11. Else, if O has a [[BooleanData]] internal slot, let builtinTag be "Boolean". - builtinTag = factory->NewFromCanBeCompressString("Boolean"); - } else if (primitiveRef->IsNumber()) { + builtin_tag = factory->NewFromCanBeCompressString("Boolean"); + } else if (primitive_ref->IsNumber()) { // 12. Else, if O has a [[NumberData]] internal slot, let builtinTag be "Number". - builtinTag = factory->NewFromCanBeCompressString("Number"); + builtin_tag = factory->NewFromCanBeCompressString("Number"); } } else if (object->IsArguments()) { - builtinTag = factory->NewFromCanBeCompressString("Arguments"); + builtin_tag = factory->NewFromCanBeCompressString("Arguments"); } else if (object->IsCallable()) { - builtinTag = factory->NewFromCanBeCompressString("Function"); + builtin_tag = factory->NewFromCanBeCompressString("Function"); } else if (object->IsJSError()) { - builtinTag = factory->NewFromCanBeCompressString("Error"); + builtin_tag = factory->NewFromCanBeCompressString("Error"); } else if (object->IsDate()) { - builtinTag = factory->NewFromCanBeCompressString("Date"); + builtin_tag = factory->NewFromCanBeCompressString("Date"); } else if (object->IsJSRegExp()) { - builtinTag = factory->NewFromCanBeCompressString("RegExp"); + builtin_tag = factory->NewFromCanBeCompressString("RegExp"); } // 15. Else, let builtinTag be "Object". - return builtinTag.GetTaggedValue(); + return builtin_tag.GetTaggedValue(); } // 19.1.3.6 Object.prototype.toString() @@ -884,7 +885,7 @@ JSTaggedValue BuiltinsObject::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If the this value is undefined, return "[object Undefined]". JSHandle msg = GetThis(argv); @@ -899,12 +900,12 @@ JSTaggedValue BuiltinsObject::ToString(EcmaRuntimeCallInfo *argv) // 3. Let O be ToObject(this value). JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle builtinTag(thread, GetBuiltinTag(thread, object)); + JSHandle builtin_tag(thread, GetBuiltinTag(thread, object)); // 16. Let tag be Get (O, @@toStringTag). - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - auto factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + auto factory = ecma_vm->GetFactory(); JSHandle tag = JSTaggedValue::GetProperty(thread, msg, env->GetToStringTagSymbol()).GetValue(); @@ -913,16 +914,16 @@ JSTaggedValue BuiltinsObject::ToString(EcmaRuntimeCallInfo *argv) // 18. If Type(tag) is not String, let tag be builtinTag. if (!tag->IsString()) { - tag = builtinTag; + tag = builtin_tag; } // 19. Return the String that is the result of concatenating "[object ", tag, and "]". - JSHandle leftString(factory->NewFromCanBeCompressString("[object ")); - JSHandle rightString(factory->NewFromCanBeCompressString("]")); + JSHandle left_string(factory->NewFromCanBeCompressString("[object ")); + JSHandle right_string(factory->NewFromCanBeCompressString("]")); - JSHandle newLeftStringHandle = - factory->ConcatFromString(leftString, JSTaggedValue::ToString(thread, tag)); - auto result = factory->ConcatFromString(newLeftStringHandle, rightString); + JSHandle new_left_string_handle = + factory->ConcatFromString(left_string, JSTaggedValue::ToString(thread, tag)); + auto result = factory->ConcatFromString(new_left_string_handle, right_string); return result.GetTaggedValue(); } @@ -932,7 +933,7 @@ JSTaggedValue BuiltinsObject::ValueOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ValueOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Return ToObject(this value). JSHandle object = JSTaggedValue::ToObject(thread, GetThis(argv)); @@ -945,7 +946,7 @@ JSTaggedValue BuiltinsObject::ProtoGetter(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ProtoGetter); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let obj be ToObject(this value). JSHandle obj = JSTaggedValue::ToObject(thread, GetThis(argv)); @@ -962,7 +963,7 @@ JSTaggedValue BuiltinsObject::ProtoSetter(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ProtoSetter); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(this value). JSHandle obj = JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)); @@ -1067,7 +1068,7 @@ JSTaggedValue BuiltinsObject::DefineSetter(EcmaRuntimeCallInfo *argv) } static JSTaggedValue LookupDesc(EcmaRuntimeCallInfo *argv, - const std::function &getDesc) + const std::function &get_desc) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, DefineGetter); @@ -1096,7 +1097,7 @@ static JSTaggedValue LookupDesc(EcmaRuntimeCallInfo *argv, RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!desc.IsEmpty()) { - return getDesc(desc); + return get_desc(desc); } objval.Update(JSObject::Cast(objval.GetTaggedValue())->GetPrototype(thread)); @@ -1133,7 +1134,7 @@ JSTaggedValue BuiltinsObject::CreateRealm(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle realm = factory->NewJSRealm(); return realm.GetTaggedValue(); @@ -1144,7 +1145,7 @@ JSTaggedValue BuiltinsObject::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). JSHandle obj = GetCallArg(argv, 0); @@ -1152,11 +1153,11 @@ JSTaggedValue BuiltinsObject::Entries(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key+value). ArraySizeT length = 0; - JSHandle nameList = + JSHandle name_list = JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::KEY_VALUE, &length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayFromList(nameList). - return JSArray::CreateArrayFromList(thread, nameList, length).GetTaggedValue(); + return JSArray::CreateArrayFromList(thread, name_list, length).GetTaggedValue(); } // ES2021 20.1.2.22 @@ -1165,7 +1166,7 @@ JSTaggedValue BuiltinsObject::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Object, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ? ToObject(O). JSHandle obj = GetCallArg(argv, 0); @@ -1173,9 +1174,10 @@ JSTaggedValue BuiltinsObject::Values(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, value). ArraySizeT length = 0; - JSHandle nameList = JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::VALUE, &length); + JSHandle name_list = + JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::VALUE, &length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return CreateArrayFromList(nameList). - return JSArray::CreateArrayFromList(thread, nameList, length).GetTaggedValue(); + return JSArray::CreateArrayFromList(thread, name_list, length).GetTaggedValue(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_plural_rules.cpp b/runtime/builtins/builtins_plural_rules.cpp index cdcb0c45fcbc3b4dad8df1265f1f44749c7afe08..b1a2f6965bd8d6c89f1fbf9aa55625a44b6f9233 100644 --- a/runtime/builtins/builtins_plural_rules.cpp +++ b/runtime/builtins/builtins_plural_rules.cpp @@ -26,8 +26,8 @@ JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *a { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. JSHandle constructor = GetConstructor(argv); @@ -39,17 +39,17 @@ JSTaggedValue BuiltinsPluralRules::PluralRulesConstructor(EcmaRuntimeCallInfo *a // 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRulesPrototype%", // « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], // [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »). - JSHandle pluralRules = + JSHandle plural_rules = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Return ? InitializePluralRules(pluralRules, locales, options). JSHandle locales = GetCallArg(argv, 0); JSHandle options = GetCallArg(argv, 1); - JSPluralRules::InitializePluralRules(thread, pluralRules, locales, options); + JSPluralRules::InitializePluralRules(thread, plural_rules, locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return pluralRules.GetTaggedValue(); + return plural_rules.GetTaggedValue(); } JSTaggedValue BuiltinsPluralRules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) @@ -58,16 +58,16 @@ JSTaggedValue BuiltinsPluralRules::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %PluralRules%.[[AvailableLocales]]. - JSHandle availableLocales = JSPluralRules::GetAvailableLocales(thread); + JSHandle available_locales = JSPluralRules::GetAvailableLocales(thread); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + 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 result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); + JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -78,10 +78,10 @@ JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let pr be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). - if (!thisValue->IsJSPluralRules()) { + if (!this_value->IsJSPluralRules()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception()); } @@ -93,8 +93,8 @@ JSTaggedValue BuiltinsPluralRules::Select(EcmaRuntimeCallInfo *argv) x = temp.GetNumber(); // 4. Return ? ResolvePlural(pr, n). - JSHandle pluralRules = JSHandle::Cast(thisValue); - JSHandle result = JSPluralRules::ResolvePlural(thread, pluralRules, x); + JSHandle plural_rules = JSHandle::Cast(this_value); + JSHandle result = JSPluralRules::ResolvePlural(thread, plural_rules, x); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -105,23 +105,23 @@ JSTaggedValue BuiltinsPluralRules::ResolvedOptions(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let thisValue be the this value; - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]). - if (!thisValue->IsJSPluralRules()) { + if (!this_value->IsJSPluralRules()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not pr object", JSTaggedValue::Exception()); } // 3. Let options be ! ObjectCreate(%ObjectPrototype%). - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); // 4. Perform resolvedOptions - JSHandle pluralRules = JSHandle::Cast(thisValue); - JSPluralRules::ResolvedOptions(thread, pluralRules, options); + JSHandle plural_rules = JSHandle::Cast(this_value); + JSPluralRules::ResolvedOptions(thread, plural_rules, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return options. diff --git a/runtime/builtins/builtins_promise.cpp b/runtime/builtins/builtins_promise.cpp index 1e8d0704ae84f6a6bd93ce391d294aa808d2bd1e..e43ae491dfec4621351587ce856de2e01186b24e 100644 --- a/runtime/builtins/builtins_promise.cpp +++ b/runtime/builtins/builtins_promise.cpp @@ -39,10 +39,10 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + 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); if (new_target->IsUndefined()) { @@ -58,7 +58,7 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa // «[[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]]» ). // 4. ReturnIfAbrupt(promise). JSHandle constructor = GetConstructor(argv); - JSHandle instancePromise = + JSHandle instance_promise = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), new_target)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -66,35 +66,36 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa // 6. Set promise's [[PromiseFulfillReactions]] internal slot to a new empty List. // 7. Set promise's [[PromiseRejectReactions]] internal slot to a new empty List. // 8. Let resolvingFunctions be CreateResolvingFunctions(promise). - JSHandle resolvingFunction = JSPromise::CreateResolvingFunctions(thread, instancePromise); + JSHandle resolving_function = + JSPromise::CreateResolvingFunctions(thread, instance_promise); // 9. Let completion be Call(executor, undefined, «resolvingFunctions.[[Resolve]], resolvingFunctions.[[reject]]) - auto resolveFunc = resolvingFunction->GetResolveFunction(); - auto rejectFunc = resolvingFunction->GetRejectFunction(); + auto resolve_func = resolving_function->GetResolveFunction(); + auto reject_func = resolving_function->GetRejectFunction(); - JSTaggedValue taggedValue; - JSHandle thisValue = globalConst->GetHandledUndefined(); + JSTaggedValue tagged_value; + JSHandle this_value = global_const->GetHandledUndefined(); { - auto info = NewRuntimeCallInfo(thread, executor, thisValue, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(resolveFunc, rejectFunc); - taggedValue = JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, executor, this_value, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(resolve_func, reject_func); + tagged_value = JSFunction::Call(info.Get()); // 2: two args } - JSHandle completionValue(thread, taggedValue); + JSHandle completion_value(thread, tagged_value); // 10. If completion is an abrupt completion, then // a. Let status be Call(resolvingFunctions.[[Reject]], undefined, «completion.[[value]]»). // b. ReturnIfAbrupt(status). if (UNLIKELY(thread->HasPendingException())) { - completionValue = JSPromise::IfThrowGetThrowValue(thread); + completion_value = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - JSHandle reject(thread, resolvingFunction->GetRejectFunction()); - auto info = NewRuntimeCallInfo(thread, reject, thisValue, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(completionValue); - JSFunction::Call(info.get()); + JSHandle reject(thread, resolving_function->GetRejectFunction()); + auto info = NewRuntimeCallInfo(thread, reject, this_value, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(completion_value); + JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 11. Return promise. - return instancePromise.GetTaggedValue(); + return instance_promise.GetTaggedValue(); } // 25.4.4.1 Promise.all ( iterable ) @@ -103,10 +104,10 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, All); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Let C be the this value. JSHandle ctor = GetThis(argv); @@ -116,8 +117,8 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) } // 3. Let S be Get(C, @@species). // 4. ReturnIfAbrupt(S). - JSHandle speciesSymbol = env->GetSpeciesSymbol(); - JSHandle sctor = JSObject::GetProperty(thread, ctor, speciesSymbol).GetValue(); + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle sctor = JSObject::GetProperty(thread, ctor, species_symbol).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, sctor.GetTaggedValue()); // 5. If S is neither undefined nor null, let C be S. @@ -138,19 +139,19 @@ JSTaggedValue BuiltinsPromise::All(EcmaRuntimeCallInfo *argv) // 10. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. JSHandle done(thread, JSTaggedValue::False()); - JSHandle itRecord = factory->NewPromiseIteratorRecord(itor, done); + JSHandle it_record = factory->NewPromiseIteratorRecord(itor, done); // 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability). - JSHandle result = PerformPromiseAll(thread, itRecord, ctor, capa); + JSHandle result = PerformPromiseAll(thread, it_record, ctor, capa); // 12. If result is an abrupt completion, if (result->IsThrow()) { thread->ClearException(); // a. If iteratorRecord.[[done]] is false, let result be IteratorClose(iterator, result). // b. IfAbruptRejectPromise(result, promiseCapability). - if (itRecord->GetDone().IsFalse()) { - JSHandle closeVal = + if (it_record->GetDone().IsFalse()) { + JSHandle close_val = JSIterator::IteratorClose(thread, itor, JSHandle::Cast(result)); - if (closeVal.GetTaggedValue().IsRecord()) { - result = JSHandle::Cast(closeVal); + if (close_val.GetTaggedValue().IsRecord()) { + result = JSHandle::Cast(close_val); RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, capa); return result->GetValue(); } @@ -168,29 +169,29 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Race); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Let C be the this value. // 2. If Type(C) is not Object, throw a TypeError exception. - JSHandle thisValue = GetThis(argv); - if (!thisValue->IsECMAObject()) { + JSHandle this_value = GetThis(argv); + if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Race: this value is not object", JSTaggedValue::Exception()); } // 3. Let S be Get(C, @@species). // 4. ReturnIfAbrupt(S). // 5. If S is neither undefined nor null, let C be S. - JSHandle speciesSymbol = env->GetSpeciesSymbol(); - JSHandle speciesConstructor = JSObject::GetProperty(thread, thisValue, speciesSymbol).GetValue(); + JSHandle species_symbol = env->GetSpeciesSymbol(); + JSHandle species_constructor = JSObject::GetProperty(thread, this_value, species_symbol).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!(speciesConstructor->IsUndefined() || speciesConstructor->IsNull())) { - thisValue = speciesConstructor; + if (!(species_constructor->IsUndefined() || species_constructor->IsNull())) { + this_value = species_constructor; } // 6. Let promiseCapability be NewPromiseCapability(C). // 7. ReturnIfAbrupt(promiseCapability). - JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, thisValue); + JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Let iterator be GetIterator(iterable). @@ -200,30 +201,30 @@ JSTaggedValue BuiltinsPromise::Race(EcmaRuntimeCallInfo *argv) if (UNLIKELY(thread->HasPendingException())) { iterator = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promise_capability); // 10. Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. JSHandle done(thread, JSTaggedValue::False()); - JSHandle iteratorRecord = factory->NewPromiseIteratorRecord(iterator, done); + JSHandle iterator_record = factory->NewPromiseIteratorRecord(iterator, done); // 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C). // 12. If result is an abrupt completion, then // a. If iteratorRecord.[[done]] is false, let result be IteratorClose(iterator,result). // b. IfAbruptRejectPromise(result, promiseCapability). // 13. Return Completion(result). - JSHandle result = PerformPromiseRace(thread, iteratorRecord, promiseCapability, thisValue); + JSHandle result = PerformPromiseRace(thread, iterator_record, promise_capability, this_value); if (result->IsThrow()) { thread->ClearException(); - if (iteratorRecord->GetDone().IsFalse()) { + if (iterator_record->GetDone().IsFalse()) { JSHandle value = JSIterator::IteratorClose(thread, iterator, JSHandle::Cast(result)); if (value.GetTaggedValue().IsCompletionRecord()) { result = JSHandle(value); - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); return result->GetValue(); } } - RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promise_capability); return result->GetValue(); } return result->GetValue(); @@ -235,17 +236,17 @@ JSTaggedValue BuiltinsPromise::Resolve(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Resolve); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let C be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If Type(C) is not Object, throw a TypeError exception. - if (!thisValue->IsECMAObject()) { + if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Resolve: this value is not object", JSTaggedValue::Exception()); } - JSHandle xValue = BuiltinsBase::GetCallArg(argv, 0); - return JSPromise::PromiseResolve(thread, thisValue, xValue); + JSHandle x_value = BuiltinsBase::GetCallArg(argv, 0); + return JSPromise::PromiseResolve(thread, this_value, x_value); } // 25.4.4.4 Promise.reject ( r ) @@ -254,34 +255,34 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Reject); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. Let C be the this value. // 2. If Type(C) is not Object, throw a TypeError exception. - JSHandle thisValue = GetThis(argv); - if (!thisValue->IsECMAObject()) { + JSHandle this_value = GetThis(argv); + if (!this_value->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Reject: this value is not object", JSTaggedValue::Exception()); } // 3. Let promiseCapability be NewPromiseCapability(C). // 4. ReturnIfAbrupt(promiseCapability). - JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, thisValue); + JSHandle promise_capability = JSPromise::NewPromiseCapability(thread, this_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let rejectResult be Call(promiseCapability.[[Reject]], undefined, «r»). // 6. ReturnIfAbrupt(rejectResult). JSHandle reason = GetCallArg(argv, 0); - JSHandle reject(thread, promiseCapability->GetReject()); - JSHandle undefined = globalConst->GetHandledUndefined(); + JSHandle reject(thread, promise_capability->GetReject()); + JSHandle undefined = global_const->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, reject, undefined, JSTaggedValue::Undefined(), 1); info->SetCallArgs(reason); - JSFunction::Call(info.get()); + JSFunction::Call(info.Get()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Return promiseCapability.[[Promise]]. - JSHandle promise(thread, promiseCapability->GetPromise()); + JSHandle promise(thread, promise_capability->GetPromise()); return promise.GetTaggedValue(); } @@ -300,15 +301,15 @@ JSTaggedValue BuiltinsPromise::Catch(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Catch); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); JSHandle promise = GetThis(argv); - JSHandle thenKey = globalConst->GetHandledPromiseThenString(); + JSHandle then_key = global_const->GetHandledPromiseThenString(); JSHandle reject = GetCallArg(argv, 0); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), promise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(JSTaggedValue::Undefined(), reject); - return JSFunction::Invoke(info.get(), thenKey); // 2: two args + return JSFunction::Invoke(info.Get(), then_key); // 2: two args } // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected ) @@ -317,84 +318,84 @@ JSTaggedValue BuiltinsPromise::Then(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Promise, Then); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Let promise be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. If IsPromise(promise) is false, throw a TypeError exception. - if (!thisValue->IsJSPromise()) { + if (!this_value->IsJSPromise()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Then: thisValue is not promise!", JSTaggedValue::Exception()); } // 3. Let C be SpeciesConstructor(promise, %Promise%). // 4. ReturnIfAbrupt(C). - JSHandle promise = JSHandle::Cast(thisValue); - JSHandle defaultFunc = JSHandle::Cast(env->GetPromiseFunction()); - JSHandle constructor = JSObject::SpeciesConstructor(thread, promise, defaultFunc); + JSHandle promise = JSHandle::Cast(this_value); + JSHandle default_func = JSHandle::Cast(env->GetPromiseFunction()); + JSHandle constructor = JSObject::SpeciesConstructor(thread, promise, default_func); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let resultCapability be NewPromiseCapability(C). // 6. ReturnIfAbrupt(resultCapability). - JSHandle resultCapability = JSPromise::NewPromiseCapability(thread, constructor); + JSHandle result_capability = JSPromise::NewPromiseCapability(thread, constructor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle onFulfilled = BuiltinsBase::GetCallArg(argv, 0); - JSHandle onRejected = BuiltinsBase::GetCallArg(argv, 1); + JSHandle on_fulfilled = BuiltinsBase::GetCallArg(argv, 0); + JSHandle on_rejected = BuiltinsBase::GetCallArg(argv, 1); // 7. Return PerformPromiseThen(promise, onFulfilled, onRejected, resultCapability). - return PerformPromiseThen(thread, JSHandle::Cast(promise), onFulfilled, onRejected, - JSHandle::Cast(resultCapability)); + return PerformPromiseThen(thread, JSHandle::Cast(promise), on_fulfilled, on_rejected, + JSHandle::Cast(result_capability)); } JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHandle &promise, - const JSHandle &onFulfilled, - const JSHandle &onRejected, + const JSHandle &on_fulfilled, + const JSHandle &on_rejected, const JSHandle &capability) { - auto ecmaVm = thread->GetEcmaVM(); - JSHandle job = ecmaVm->GetMicroJobQueue(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSMutableHandle fulfilled(thread, onFulfilled.GetTaggedValue()); - auto globalConst = thread->GlobalConstants(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle job = ecma_vm->GetMicroJobQueue(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSMutableHandle fulfilled(thread, on_fulfilled.GetTaggedValue()); + auto global_const = thread->GlobalConstants(); if (!fulfilled->IsCallable()) { - fulfilled.Update(globalConst->GetIdentityString()); + fulfilled.Update(global_const->GetIdentityString()); } - JSMutableHandle rejected(thread, onRejected.GetTaggedValue()); + JSMutableHandle rejected(thread, on_rejected.GetTaggedValue()); if (!rejected->IsCallable()) { - rejected.Update(globalConst->GetThrowerString()); + rejected.Update(global_const->GetThrowerString()); } - JSHandle fulfillReaction = factory->NewPromiseReaction(); - fulfillReaction->SetPromiseCapability(thread, capability.GetTaggedValue()); - fulfillReaction->SetHandler(thread, fulfilled.GetTaggedValue()); + JSHandle fulfill_reaction = factory->NewPromiseReaction(); + fulfill_reaction->SetPromiseCapability(thread, capability.GetTaggedValue()); + fulfill_reaction->SetHandler(thread, fulfilled.GetTaggedValue()); - JSHandle rejectReaction = factory->NewPromiseReaction(); - rejectReaction->SetPromiseCapability(thread, capability.GetTaggedValue()); - rejectReaction->SetHandler(thread, rejected.GetTaggedValue()); + JSHandle reject_reaction = factory->NewPromiseReaction(); + reject_reaction->SetPromiseCapability(thread, capability.GetTaggedValue()); + reject_reaction->SetHandler(thread, rejected.GetTaggedValue()); if (JSTaggedValue::SameValue(promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::PENDING)))) { - JSHandle fulfillReactions(thread, promise->GetPromiseFulfillReactions()); - TaggedQueue *newQueue = - TaggedQueue::Push(thread, fulfillReactions, JSHandle::Cast(fulfillReaction)); - promise->SetPromiseFulfillReactions(thread, JSTaggedValue(newQueue)); - - JSHandle rejectReactions(thread, promise->GetPromiseRejectReactions()); - newQueue = TaggedQueue::Push(thread, rejectReactions, JSHandle::Cast(rejectReaction)); - promise->SetPromiseRejectReactions(thread, JSTaggedValue(newQueue)); + JSHandle fulfill_reactions(thread, promise->GetPromiseFulfillReactions()); + TaggedQueue *new_queue = + TaggedQueue::Push(thread, fulfill_reactions, JSHandle::Cast(fulfill_reaction)); + promise->SetPromiseFulfillReactions(thread, JSTaggedValue(new_queue)); + + JSHandle reject_reactions(thread, promise->GetPromiseRejectReactions()); + new_queue = TaggedQueue::Push(thread, reject_reactions, JSHandle::Cast(reject_reaction)); + promise->SetPromiseRejectReactions(thread, JSTaggedValue(new_queue)); } else if (JSTaggedValue::SameValue(promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::FULFILLED)))) { JSHandle argv = factory->NewTaggedArray(2); // 2: 2 means two args stored in array - argv->Set(thread, 0, fulfillReaction.GetTaggedValue()); + argv->Set(thread, 0, fulfill_reaction.GetTaggedValue()); argv->Set(thread, 1, promise->GetPromiseResult()); - JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); + JSHandle promise_reactions_job(env->GetPromiseReactionJob()); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_reactions_job, argv); } else if (JSTaggedValue::SameValue(promise->GetPromiseState(), JSTaggedValue(static_cast(PromiseStatus::REJECTED)))) { JSHandle argv = factory->NewTaggedArray(2); // 2: 2 means two args stored in array - argv->Set(thread, 0, rejectReaction.GetTaggedValue()); + argv->Set(thread, 0, reject_reaction.GetTaggedValue()); argv->Set(thread, 1, promise->GetPromiseResult()); // When a handler is added to a rejected promise for the first time, it is called with its operation // argument set to "handle". @@ -402,8 +403,8 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand JSHandle reason(thread, JSTaggedValue::Null()); thread->GetEcmaVM()->PromiseRejectionTracker(promise, reason, ecmascript::PromiseRejectionEvent::HANDLE); } - JSHandle promiseReactionsJob(env->GetPromiseReactionJob()); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseReactionsJob, argv); + JSHandle promise_reactions_job(env->GetPromiseReactionJob()); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_reactions_job, argv); } promise->SetPromiseIsHandled(thread, JSTaggedValue::True()); @@ -416,34 +417,34 @@ JSTaggedValue BuiltinsPromise::PerformPromiseThen(JSThread *thread, const JSHand } JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, - const JSHandle &itRecord, + const JSHandle &it_record, const JSHandle &ctor, const JSHandle &capa) { - auto ecmaVm = thread->GetEcmaVM(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - ObjectFactory *factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. Assert: constructor is a constructor function. ASSERT_PRINT(ctor->IsConstructor(), "PerformPromiseAll is not constructor"); // 2. Assert: resultCapability is a PromiseCapability record. (not need) // 3. Let values be a new empty List. JSHandle values = factory->NewPromiseRecord(); - JSHandle emptyArray = factory->EmptyArray(); - values->SetValue(thread, emptyArray); + JSHandle empty_array = factory->EmptyArray(); + values->SetValue(thread, empty_array); // 4. Let remainingElementsCount be a new Record { [[value]]: 1 }. - JSHandle remainCnt = factory->NewPromiseRecord(); - remainCnt->SetValue(thread, JSTaggedNumber(1)); + JSHandle remain_cnt = factory->NewPromiseRecord(); + remain_cnt->SetValue(thread, JSTaggedNumber(1)); // 5. Let index be 0. uint32_t index = 0; // 6. Repeat - JSHandle itor(thread, itRecord->GetIterator()); - JSMutableHandle next(thread, globalConst->GetUndefined()); + JSHandle itor(thread, it_record->GetIterator()); + JSMutableHandle next(thread, global_const->GetUndefined()); while (true) { // a. Let next be IteratorStep(iteratorRecord.[[iterator]]). next.Update(JSIterator::IteratorStep(thread, itor).GetTaggedValue()); // b. If next is an abrupt completion, set iteratorRecord.[[done]] to true. if (UNLIKELY(thread->HasPendingException())) { - itRecord->SetDone(thread, JSTaggedValue::True()); + it_record->SetDone(thread, JSTaggedValue::True()); next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); } // c. ReturnIfAbrupt(next). @@ -451,92 +452,92 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, // d. If next is false, if (next->IsFalse()) { // i. Set iteratorRecord.[[done]] to true. - itRecord->SetDone(thread, JSTaggedValue::True()); + it_record->SetDone(thread, JSTaggedValue::True()); // ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remain_cnt->SetValue(thread, --JSTaggedNumber(remain_cnt->GetValue())); // iii. If remainingElementsCount.[[value]] is 0, - if (remainCnt->GetValue().IsZero()) { + if (remain_cnt->GetValue().IsZero()) { // 1. Let valuesArray be CreateArrayFromList(values). - JSHandle jsArrayValues = + JSHandle js_array_values = JSArray::CreateArrayFromList(thread, JSHandle(thread, values->GetValue())); // 2. Let resolveResult be Call(resultCapability.[[Resolve]], undefined, «valuesArray»). - JSHandle resCapaFunc(thread, capa->GetResolve()); + JSHandle res_capa_func(thread, capa->GetResolve()); - auto info = NewRuntimeCallInfo(thread, resCapaFunc, globalConst->GetHandledUndefined(), + auto info = NewRuntimeCallInfo(thread, res_capa_func, global_const->GetHandledUndefined(), JSTaggedValue::Undefined(), 1); - info->SetCallArgs(jsArrayValues.GetTaggedValue()); - JSTaggedValue resolveRes = JSFunction::Call(info.get()); + info->SetCallArgs(js_array_values.GetTaggedValue()); + JSTaggedValue resolve_res = JSFunction::Call(info.Get()); // 3. ReturnIfAbrupt(resolveResult) - JSHandle resolveAbrupt(thread, resolveRes); - RETURN_COMPLETION_IF_ABRUPT(thread, resolveAbrupt); + JSHandle resolve_abrupt(thread, resolve_res); + RETURN_COMPLETION_IF_ABRUPT(thread, resolve_abrupt); } // iv. Return resultCapability.[[Promise]]. - JSHandle resRecord = factory->NewCompletionRecord( + JSHandle res_record = factory->NewCompletionRecord( CompletionRecord::NORMAL, JSHandle(thread, capa->GetPromise())); - return resRecord; + return res_record; } // e. Let nextValue be IteratorValue(next). - JSHandle nextVal = JSIterator::IteratorValue(thread, next); + JSHandle next_val = JSIterator::IteratorValue(thread, next); // f. If nextValue is an abrupt completion, set iteratorRecord.[[done]] to true. if (UNLIKELY(thread->HasPendingException())) { - itRecord->SetDone(thread, JSTaggedValue::True()); + it_record->SetDone(thread, JSTaggedValue::True()); if (thread->GetException().IsObjectWrapper()) { - JSHandle wrapperVal(thread, thread->GetException()); - JSHandle throwVal(thread, wrapperVal->GetValue()); - nextVal = throwVal; + JSHandle wrapper_val(thread, thread->GetException()); + JSHandle throw_val(thread, wrapper_val->GetValue()); + next_val = throw_val; } else { - nextVal = JSHandle(thread, thread->GetException()); + next_val = JSHandle(thread, thread->GetException()); } } // g. ReturnIfAbrupt(nextValue). - RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + RETURN_COMPLETION_IF_ABRUPT(thread, next_val); // h. Append undefined to values. - JSHandle valuesArray = + JSHandle values_array = JSHandle::Cast(JSHandle(thread, values->GetValue())); - valuesArray = TaggedArray::SetCapacity(thread, valuesArray, index + 1); - valuesArray->Set(thread, index, JSTaggedValue::Undefined()); - values->SetValue(thread, valuesArray); + values_array = TaggedArray::SetCapacity(thread, values_array, index + 1); + values_array->Set(thread, index, JSTaggedValue::Undefined()); + values->SetValue(thread, values_array); // i. Let nextPromise be Invoke(constructor, "resolve", «‍nextValue»). - JSHandle resolveKey = globalConst->GetHandledPromiseResolveString(); - JSTaggedValue taggedNextPromise; + JSHandle resolve_key = global_const->GetHandledPromiseResolveString(); + JSTaggedValue tagged_next_promise; { auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), ctor, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(nextVal); - taggedNextPromise = JSFunction::Invoke(info.get(), resolveKey); + info->SetCallArgs(next_val); + tagged_next_promise = JSFunction::Invoke(info.Get(), resolve_key); } // j. ReturnIfAbrupt(nextPromise). - JSHandle nextPromise(thread, taggedNextPromise); - RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); + JSHandle next_promise(thread, tagged_next_promise); + RETURN_COMPLETION_IF_ABRUPT(thread, next_promise); // k. Let resolveElement be a new built-in function object as defined in Promise.all // Resolve Element Functions. - JSHandle resoleveElement = factory->NewJSPromiseAllResolveElementFunction( + JSHandle resoleve_element = factory->NewJSPromiseAllResolveElementFunction( reinterpret_cast(BuiltinsPromiseHandler::ResolveElementFunction)); // l. Set the [[AlreadyCalled]] internal slot of resolveElement to a new Record {[[value]]: false }. - JSHandle falseRecord = factory->NewPromiseRecord(); - falseRecord->SetValue(thread, JSTaggedValue::False()); - resoleveElement->SetAlreadyCalled(thread, falseRecord); + JSHandle false_record = factory->NewPromiseRecord(); + false_record->SetValue(thread, JSTaggedValue::False()); + resoleve_element->SetAlreadyCalled(thread, false_record); // m. Set the [[Index]] internal slot of resolveElement to index. - resoleveElement->SetIndex(thread, JSTaggedValue(index)); + resoleve_element->SetIndex(thread, JSTaggedValue(index)); // n. Set the [[Values]] internal slot of resolveElement to values. - resoleveElement->SetValues(thread, values); + resoleve_element->SetValues(thread, values); // o. Set the [[Capabilities]] internal slot of resolveElement to resultCapability. - resoleveElement->SetCapabilities(thread, capa); + resoleve_element->SetCapabilities(thread, capa); // p. Set the [[RemainingElements]] internal slot of resolveElement to remainingElementsCount. - resoleveElement->SetRemainingElements(thread, remainCnt); + resoleve_element->SetRemainingElements(thread, remain_cnt); // q. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] + 1. - remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); + remain_cnt->SetValue(thread, ++JSTaggedNumber(remain_cnt->GetValue())); // r. Let result be Invoke(nextPromise, "then", «‍resolveElement, resultCapability.[[Reject]]»). - JSTaggedValue taggedResult; + JSTaggedValue tagged_result; { - JSHandle thenKey = globalConst->GetHandledPromiseThenString(); + JSHandle then_key = global_const->GetHandledPromiseThenString(); auto info = - NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), nextPromise, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(resoleveElement, capa->GetReject()); - taggedResult = JSFunction::Invoke(info.get(), thenKey); + NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), next_promise, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(resoleve_element, capa->GetReject()); + tagged_result = JSFunction::Invoke(info.Get(), then_key); } - JSHandle result(thread, taggedResult); + JSHandle result(thread, tagged_result); // s. ReturnIfAbrupt(result). RETURN_COMPLETION_IF_ABRUPT(thread, result); // t. Set index to index + 1. @@ -545,7 +546,7 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, } JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, - const JSHandle &iteratorRecord, + const JSHandle &iterator_record, const JSHandle &capability, const JSHandle &constructor) { @@ -563,60 +564,60 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, // i. ReturnIfAbrupt(nextPromise). // j. Let result be Invoke(nextPromise, "then", «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»). // k. ReturnIfAbrupt(result). - auto ecmaVm = thread->GetEcmaVM(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle iterator(thread, iteratorRecord->GetIterator()); - JSMutableHandle next(thread, globalConst->GetUndefined()); + auto ecma_vm = thread->GetEcmaVM(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSHandle iterator(thread, iterator_record->GetIterator()); + JSMutableHandle next(thread, global_const->GetUndefined()); while (true) { next.Update(JSIterator::IteratorStep(thread, iterator).GetTaggedValue()); if (UNLIKELY(thread->HasPendingException())) { - iteratorRecord->SetDone(thread, JSTaggedValue::True()); + iterator_record->SetDone(thread, JSTaggedValue::True()); next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); } RETURN_COMPLETION_IF_ABRUPT(thread, next); if (next->IsFalse()) { - iteratorRecord->SetDone(thread, JSTaggedValue::True()); + iterator_record->SetDone(thread, JSTaggedValue::True()); JSHandle promise(thread, capability->GetPromise()); - JSHandle completionRecord = + JSHandle completion_record = factory->NewCompletionRecord(CompletionRecord::NORMAL, promise); - return completionRecord; + return completion_record; } - JSHandle nextValue = JSIterator::IteratorValue(thread, next); + JSHandle next_value = JSIterator::IteratorValue(thread, next); if (UNLIKELY(thread->HasPendingException())) { - iteratorRecord->SetDone(thread, JSTaggedValue::True()); - nextValue = JSPromise::IfThrowGetThrowValue(thread); + iterator_record->SetDone(thread, JSTaggedValue::True()); + next_value = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_COMPLETION_IF_ABRUPT(thread, nextValue); - JSHandle resolveStr = globalConst->GetHandledPromiseResolveString(); + RETURN_COMPLETION_IF_ABRUPT(thread, next_value); + JSHandle resolve_str = global_const->GetHandledPromiseResolveString(); JSTaggedValue result; { auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), constructor, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(nextValue); - result = JSFunction::Invoke(info.get(), resolveStr); + info->SetCallArgs(next_value); + result = JSFunction::Invoke(info.Get(), resolve_str); } - JSHandle nextPromise(thread, result); + JSHandle next_promise(thread, result); if (UNLIKELY(thread->HasPendingException())) { - nextPromise = JSPromise::IfThrowGetThrowValue(thread); + next_promise = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); + RETURN_COMPLETION_IF_ABRUPT(thread, next_promise); { - JSHandle thenStr = globalConst->GetHandledPromiseThenString(); + JSHandle then_str = global_const->GetHandledPromiseThenString(); auto info = - NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), nextPromise, JSTaggedValue::Undefined(), 2); + NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), next_promise, JSTaggedValue::Undefined(), 2); info->SetCallArgs(capability->GetResolve(), capability->GetReject()); - result = JSFunction::Invoke(info.get(), thenStr); // 2: two args + result = JSFunction::Invoke(info.Get(), then_str); // 2: two args } - JSHandle handleResult(thread, result); + JSHandle handle_result(thread, result); if (UNLIKELY(thread->HasPendingException())) { - handleResult = JSPromise::IfThrowGetThrowValue(thread); + handle_result = JSPromise::IfThrowGetThrowValue(thread); } - RETURN_COMPLETION_IF_ABRUPT(thread, handleResult); + RETURN_COMPLETION_IF_ABRUPT(thread, handle_result); } } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_promise.h b/runtime/builtins/builtins_promise.h index 6d2147d19b3ac75b267de91dbb12fdfaf4bbb984..21a634ae3251ead11baa81b5218d1e7ee98b0352 100644 --- a/runtime/builtins/builtins_promise.h +++ b/runtime/builtins/builtins_promise.h @@ -44,18 +44,18 @@ public: static JSTaggedValue Then(EcmaRuntimeCallInfo *argv); static JSTaggedValue PerformPromiseThen(JSThread *thread, const JSHandle &promise, - const JSHandle &onFulfilled, - const JSHandle &onRejected, + const JSHandle &on_fulfilled, + const JSHandle &on_rejected, const JSHandle &capability); private: static JSHandle PerformPromiseAll(JSThread *thread, - const JSHandle &itRecord, + const JSHandle &it_record, const JSHandle &ctor, const JSHandle &capa); static JSHandle PerformPromiseRace(JSThread *thread, - const JSHandle &iteratorRecord, + const JSHandle &iterator_record, const JSHandle &capability, const JSHandle &constructor); }; diff --git a/runtime/builtins/builtins_promise_handler.cpp b/runtime/builtins/builtins_promise_handler.cpp index 369cad69cd55f44153321cbd0d687b610d7cd9c1..29f32d37d010dd5f67c80a8ac260e04ea15accf6 100644 --- a/runtime/builtins/builtins_promise_handler.cpp +++ b/runtime/builtins/builtins_promise_handler.cpp @@ -31,10 +31,10 @@ JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Resolve); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); // 1. Assert: F has a [[Promise]] internal slot whose value is an Object. JSHandle resolve = JSHandle::Cast(GetConstructor(argv)); @@ -44,63 +44,63 @@ JSTaggedValue BuiltinsPromiseHandler::Resolve(EcmaRuntimeCallInfo *argv) // 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot. // 4. If alreadyResolved.[[value]] is true, return undefined. // 5. Set alreadyResolved.[[value]] to true. - JSHandle resolvePromise(thread, resolve->GetPromise()); - JSHandle alreadyResolved(thread, resolve->GetAlreadyResolved()); - if (alreadyResolved->GetValue().IsTrue()) { + JSHandle resolve_promise(thread, resolve->GetPromise()); + JSHandle already_resolved(thread, resolve->GetAlreadyResolved()); + if (already_resolved->GetValue().IsTrue()) { return JSTaggedValue::Undefined(); } - alreadyResolved->SetValue(thread, JSTaggedValue::True()); + already_resolved->SetValue(thread, JSTaggedValue::True()); // 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); - if (JSTaggedValue::SameValue(resolution.GetTaggedValue(), resolvePromise.GetTaggedValue())) { - JSHandle resolutionError = + 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."); - JSPromise::RejectPromise(thread, resolvePromise, JSHandle::Cast(resolutionError)); + JSPromise::RejectPromise(thread, resolve_promise, JSHandle::Cast(resolution_error)); return JSTaggedValue::Undefined(); } // 7. If Type(resolution) is not Object, then // a. Return FulfillPromise(promise, resolution). if (!resolution.GetTaggedValue().IsECMAObject()) { - JSPromise::FulfillPromise(thread, resolvePromise, resolution); + JSPromise::FulfillPromise(thread, resolve_promise, resolution); return JSTaggedValue::Undefined(); } // 8. Let then be Get(resolution, "then"). // 9. If then is an abrupt completion, then // a. Return RejectPromise(promise, then.[[value]]). - JSHandle thenKey(thread->GlobalConstants()->GetHandledPromiseThenString()); - JSHandle thenValue = JSObject::GetProperty(thread, resolution, thenKey).GetValue(); + JSHandle then_key(thread->GlobalConstants()->GetHandledPromiseThenString()); + JSHandle then_value = JSObject::GetProperty(thread, resolution, then_key).GetValue(); if (UNLIKELY(thread->HasPendingException())) { - if (!thenValue->IsJSError()) { + if (!then_value->IsJSError()) { if (thread->GetException().IsObjectWrapper()) { - JSHandle wrapperValue(thread, thread->GetException()); - JSHandle throwValue(thread, wrapperValue->GetValue()); - thenValue = throwValue; + JSHandle wrapper_value(thread, thread->GetException()); + JSHandle throw_value(thread, wrapper_value->GetValue()); + then_value = throw_value; } else { - thenValue = JSHandle(thread, thread->GetException()); + then_value = JSHandle(thread, thread->GetException()); } } thread->ClearException(); - return JSPromise::RejectPromise(thread, resolvePromise, thenValue); + return JSPromise::RejectPromise(thread, resolve_promise, then_value); } // 10. Let thenAction be then.[[value]]. // 11. If IsCallable(thenAction) is false, then // a. Return FulfillPromise(promise, resolution). - if (!thenValue->IsCallable()) { - JSPromise::FulfillPromise(thread, resolvePromise, resolution); + if (!then_value->IsCallable()) { + JSPromise::FulfillPromise(thread, resolve_promise, resolution); return JSTaggedValue::Undefined(); } // 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob, «promise, resolution, thenAction») JSHandle arguments = factory->NewTaggedArray(3); // 3: 3 means three args stored in array - arguments->Set(thread, 0, resolvePromise); + arguments->Set(thread, 0, resolve_promise); arguments->Set(thread, 1, resolution); - arguments->Set(thread, 2, thenValue); // 2: 2 means index of array is 2 + arguments->Set(thread, 2, then_value); // 2: 2 means index of array is 2 - JSHandle promiseResolveThenableJob(env->GetPromiseResolveThenableJob()); + JSHandle promise_resolve_thenable_job(env->GetPromiseResolveThenableJob()); JSHandle job = thread->GetEcmaVM()->GetMicroJobQueue(); - job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promiseResolveThenableJob, arguments); + job::MicroJobQueue::EnqueueJob(thread, job, job::QueueType::QUEUE_PROMISE, promise_resolve_thenable_job, arguments); // 13. Return undefined. return JSTaggedValue::Undefined(); @@ -112,7 +112,7 @@ JSTaggedValue BuiltinsPromiseHandler::Reject(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Reject); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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)); @@ -122,16 +122,16 @@ JSTaggedValue BuiltinsPromiseHandler::Reject(EcmaRuntimeCallInfo *argv) // 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot. // 4. If alreadyResolved.[[value]] is true, return undefined. // 5. Set alreadyResolved.[[value]] to true. - JSHandle rejectPromise(thread, reject->GetPromise()); - JSHandle alreadyResolved(thread, reject->GetAlreadyResolved()); - if (alreadyResolved->GetValue().IsTrue()) { + JSHandle reject_promise(thread, reject->GetPromise()); + JSHandle already_resolved(thread, reject->GetAlreadyResolved()); + if (already_resolved->GetValue().IsTrue()) { return JSTaggedValue::Undefined(); } - alreadyResolved->SetValue(thread, JSTaggedValue::True()); + already_resolved->SetValue(thread, JSTaggedValue::True()); // 6. Return RejectPromise(promise, reason). JSHandle reason = GetCallArg(argv, 0); - JSHandle result(thread, JSPromise::RejectPromise(thread, rejectPromise, reason)); + JSHandle result(thread, JSPromise::RejectPromise(thread, reject_promise, reason)); return result.GetTaggedValue(); } @@ -141,7 +141,7 @@ JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, Executor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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)); @@ -150,20 +150,20 @@ JSTaggedValue BuiltinsPromiseHandler::Executor(EcmaRuntimeCallInfo *argv) // 2. Let promiseCapability be the value of F's [[Capability]] internal slot. // 3. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception. - JSHandle promiseCapability(thread, executor->GetCapability()); - if (!promiseCapability->GetResolve().IsUndefined()) { + JSHandle promise_capability(thread, executor->GetCapability()); + if (!promise_capability->GetResolve().IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Executor: resolve should be undefine!", JSTaggedValue::Undefined()); } // 4. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception. - if (!promiseCapability->GetReject().IsUndefined()) { + if (!promise_capability->GetReject().IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Executor: reject should be undefine!", JSTaggedValue::Undefined()); } // 5. Set promiseCapability.[[Resolve]] to resolve. // 6. Set promiseCapability.[[Reject]] to reject. JSHandle resolve = GetCallArg(argv, 0); JSHandle reject = GetCallArg(argv, 1); - promiseCapability->SetResolve(thread, resolve); - promiseCapability->SetReject(thread, reject); + promise_capability->SetResolve(thread, resolve); + promise_capability->SetReject(thread, reject); // 7. Return undefined. return JSTaggedValue::Undefined(); } @@ -174,19 +174,19 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, ResolveElementFunction); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); JSHandle func = JSHandle::Cast(GetConstructor(argv)); // 1. Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot. - JSHandle alreadyCalled = + JSHandle already_called = JSHandle::Cast(JSHandle(thread, func->GetAlreadyCalled())); // 2. If alreadyCalled.[[value]] is true, return undefined. - if (alreadyCalled->GetValue().IsTrue()) { + if (already_called->GetValue().IsTrue()) { return JSTaggedValue::Undefined(); } // 3. Set alreadyCalled.[[value]] to true. - alreadyCalled->SetValue(thread, JSTaggedValue::True()); + already_called->SetValue(thread, JSTaggedValue::True()); // 4. Let index be the value of F's [[Index]] internal slot. JSHandle index(thread, func->GetIndex()); // 5. Let values be the value of F's [[Values]] internal slot. @@ -195,25 +195,25 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo JSHandle capa = JSHandle::Cast(JSHandle(thread, func->GetCapabilities())); // 7. Let remainingElementsCount be the value of F's [[RemainingElements]] internal slot. - JSHandle remainCnt = + JSHandle remain_cnt = JSHandle::Cast(JSHandle(thread, func->GetRemainingElements())); // 8. Set values[index] to x. - JSHandle arrayValues = + JSHandle array_values = JSHandle::Cast(JSHandle(thread, values->GetValue())); - arrayValues->Set(thread, JSTaggedValue::ToUint32(thread, index), GetCallArg(argv, 0).GetTaggedValue()); + array_values->Set(thread, JSTaggedValue::ToUint32(thread, index), GetCallArg(argv, 0).GetTaggedValue()); // 9. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] - 1. - remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + remain_cnt->SetValue(thread, --JSTaggedNumber(remain_cnt->GetValue())); // 10. If remainingElementsCount.[[value]] is 0, - if (remainCnt->GetValue().IsZero()) { + if (remain_cnt->GetValue().IsZero()) { // a. Let valuesArray be CreateArrayFromList(values). - JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, arrayValues); + JSHandle js_array_values = JSArray::CreateArrayFromList(thread, array_values); // b. Return Call(promiseCapability.[[Resolve]], undefined, «valuesArray»). - JSHandle capaResolve(thread, capa->GetResolve()); - JSHandle undefine = globalConst->GetHandledUndefined(); + JSHandle capa_resolve(thread, capa->GetResolve()); + JSHandle undefine = global_const->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, capaResolve, undefine, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(jsArrayValues); - return JSFunction::Call(info.get()); + auto info = NewRuntimeCallInfo(thread, capa_resolve, undefine, JSTaggedValue::Undefined(), 1); + info->SetCallArgs(js_array_values); + return JSFunction::Call(info.Get()); } // 11. Return undefined. return JSTaggedValue::Undefined(); @@ -223,7 +223,7 @@ JSTaggedValue BuiltinsPromiseHandler::AsyncAwaitFulfilled(EcmaRuntimeCallInfo *a { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, AsyncAwaitFulfilled); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSHandle value = GetCallArg(argv, 0); JSHandle func(GetConstructor(argv)); @@ -234,7 +234,7 @@ JSTaggedValue BuiltinsPromiseHandler::AsyncAwaitRejected(EcmaRuntimeCallInfo *ar { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseHandler, AsyncAwaitRejected); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); JSHandle reason = GetCallArg(argv, 0); JSHandle func(GetConstructor(argv)); diff --git a/runtime/builtins/builtins_promise_job.cpp b/runtime/builtins/builtins_promise_job.cpp index 88957e6bdaceac41b141f00ade033fe867d76786..7d5aec9b88b615f21b4c27eb7dbe4a9cb2efa878 100644 --- a/runtime/builtins/builtins_promise_job.cpp +++ b/runtime/builtins/builtins_promise_job.cpp @@ -29,28 +29,28 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseJob, Reaction); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Assert: reaction is a PromiseReaction Record. JSHandle value = GetCallArg(argv, 0); ASSERT(value->IsPromiseReaction()); JSHandle reaction = JSHandle::Cast(value); JSHandle argument = GetCallArg(argv, 1); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 2. Let promiseCapability be reaction.[[Capabilities]]. - JSTaggedValue capabilitiesValue = reaction->GetPromiseCapability(); + JSTaggedValue capabilities_value = reaction->GetPromiseCapability(); // 3. Let handler be reaction.[[Handler]]. JSHandle handler(thread, reaction->GetHandler()); - JSHandle thisValue = globalConst->GetHandledUndefined(); + JSHandle this_value = global_const->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, handler, thisValue, JSTaggedValue::Undefined(), 1); + auto info = NewRuntimeCallInfo(thread, handler, this_value, JSTaggedValue::Undefined(), 1); info->SetCallArgs(argument); - if (capabilitiesValue.IsUndefined()) { - [[maybe_unused]] JSTaggedValue val = JSFunction::Call(info.get()); + if (capabilities_value.IsUndefined()) { + [[maybe_unused]] JSTaggedValue val = JSFunction::Call(info.Get()); return JSTaggedValue::Undefined(); } - JSHandle capability(thread, capabilitiesValue); + JSHandle capability(thread, capabilities_value); JSMutableHandle call(thread, capability->GetResolve()); if (handler->IsString()) { @@ -59,26 +59,26 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) // [[target]]: empty}. if (EcmaString::StringsAreEqual(handler.GetObject(), - globalConst->GetHandledThrowerString().GetObject())) { + global_const->GetHandledThrowerString().GetObject())) { call.Update(capability->GetReject()); } } else { // 6. Else, let handlerResult be Call(handler, undefined, «argument»). - JSTaggedValue taggedValue = JSFunction::Call(info.get()); - info->SetCallArgs(taggedValue); + JSTaggedValue tagged_value = JSFunction::Call(info.Get()); + info->SetCallArgs(tagged_value); // 7. If handlerResult is an abrupt completion, then // a. Let status be Call(promiseCapability.[[Reject]], undefined, «handlerResult.[[value]]»). // b. NextJob Completion(status). if (UNLIKELY(thread->HasPendingException())) { - JSHandle throwValue = JSPromise::IfThrowGetThrowValue(thread); + JSHandle throw_value = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - info->SetCallArgs(throwValue); + info->SetCallArgs(throw_value); call.Update(capability->GetReject()); } } // 8. Let status be Call(promiseCapability.[[Resolve]], undefined, «handlerResult.[[value]]»). info->SetFunction(call.GetTaggedValue()); - return JSFunction::Call(info.get()); + return JSFunction::Call(info.Get()); } JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) @@ -86,12 +86,12 @@ JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), PromiseJob, ResolveThenableJob); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); JSHandle promise = GetCallArg(argv, 0); ASSERT(promise->IsJSPromise()); // 1. Let resolvingFunctions be CreateResolvingFunctions(promiseToResolve). - JSHandle resolvingFunctions = + JSHandle resolving_functions = JSPromise::CreateResolvingFunctions(thread, JSHandle::Cast(promise)); JSHandle thenable = GetCallArg(argv, 1); JSHandle then = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); @@ -101,21 +101,21 @@ JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo JSTaggedValue result; { auto info = NewRuntimeCallInfo(thread, then, thenable, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(resolvingFunctions->GetResolveFunction(), resolvingFunctions->GetRejectFunction()); - result = JSFunction::Call(info.get()); // 2: two args + info->SetCallArgs(resolving_functions->GetResolveFunction(), resolving_functions->GetRejectFunction()); + result = JSFunction::Call(info.Get()); // 2: two args } - JSHandle thenResult(thread, result); + JSHandle then_result(thread, result); // 3. If thenCallResult is an abrupt completion, // a. Let status be Call(resolvingFunctions.[[Reject]], undefined, «thenCallResult.[[value]]»). // b. NextJob Completion(status). if (UNLIKELY(thread->HasPendingException())) { - thenResult = JSPromise::IfThrowGetThrowValue(thread); + then_result = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); - JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); - JSHandle undefined = globalConst->GetHandledUndefined(); + JSHandle reject(thread, resolving_functions->GetRejectFunction()); + JSHandle undefined = global_const->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, reject, undefined, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thenResult); - return JSFunction::Call(info.get()); + info->SetCallArgs(then_result); + return JSFunction::Call(info.Get()); } // 4. NextJob Completion(thenCallResult). return result; diff --git a/runtime/builtins/builtins_proxy.cpp b/runtime/builtins/builtins_proxy.cpp index 5a0a74f23bc9cd4fd9300c00b33c902bdf1d0cf0..4b78993025ce4e805213ac8e327b025eaac7c4b6 100644 --- a/runtime/builtins/builtins_proxy.cpp +++ b/runtime/builtins/builtins_proxy.cpp @@ -26,7 +26,7 @@ JSTaggedValue BuiltinsProxy::ProxyConstructor(EcmaRuntimeCallInfo *argv) { ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, Constructor); - [[maybe_unused]] EcmaHandleScope handleScope(argv->GetThread()); + [[maybe_unused]] EcmaHandleScope handle_scope(argv->GetThread()); // 1.If NewTarget is undefined, throw a TypeError exception. JSHandle new_target = GetNewTarget(argv); @@ -47,7 +47,7 @@ JSTaggedValue BuiltinsProxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *arg ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, Revocable); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let p be ProxyCreate(target, handler). JSHandle proxy = JSProxy::ProxyCreate(thread, GetCallArg(argv, 0), GetCallArg(argv, 1)); @@ -65,13 +65,13 @@ JSTaggedValue BuiltinsProxy::Revocable([[maybe_unused]] EcmaRuntimeCallInfo *arg JSHandle result = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(proto); // 6.Perform CreateDataProperty(result, "proxy", p). - auto globalConst = thread->GlobalConstants(); - JSHandle proxyKey = globalConst->GetHandledProxyString(); - JSObject::CreateDataProperty(thread, result, proxyKey, JSHandle(proxy)); + auto global_const = thread->GlobalConstants(); + JSHandle proxy_key = global_const->GetHandledProxyString(); + JSObject::CreateDataProperty(thread, result, proxy_key, JSHandle(proxy)); // 7.Perform CreateDataProperty(result, "revoke", revoker). - JSHandle revokeKey = globalConst->GetHandledRevokeString(); - JSObject::CreateDataProperty(thread, result, revokeKey, JSHandle(revoker)); + JSHandle revoke_key = global_const->GetHandledRevokeString(); + JSObject::CreateDataProperty(thread, result, revoke_key, JSHandle(revoker)); // 8.Return result. return result.GetTaggedValue(); @@ -83,13 +83,13 @@ JSTaggedValue BuiltinsProxy::InvalidateProxyFunction(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Proxy, InvalidateProxyFunction); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle revoke_obj(GetThis(argv)); - JSHandle revokeKey = thread->GlobalConstants()->GetHandledRevokeString(); + JSHandle revoke_key = thread->GlobalConstants()->GetHandledRevokeString(); PropertyDescriptor desc(thread); - JSObject::GetOwnProperty(thread, revoke_obj, revokeKey, desc); + JSObject::GetOwnProperty(thread, revoke_obj, revoke_key, desc); JSProxyRevocFunction::ProxyRevocFunctions(thread, JSHandle(desc.GetValue())); return JSTaggedValue::Undefined(); } diff --git a/runtime/builtins/builtins_reflect.cpp b/runtime/builtins/builtins_reflect.cpp index 30972321292f3bbe61d9579a73be3c0213d7fade..a11ec2fbb4645c4a35939d74e374f80ab0310fe1 100644 --- a/runtime/builtins/builtins_reflect.cpp +++ b/runtime/builtins/builtins_reflect.cpp @@ -24,27 +24,27 @@ JSTaggedValue BuiltinsReflect::ReflectApply(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Apply); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsCallable(target) is false, throw a TypeError exception. JSHandle target = 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 thisArgument = GetCallArg(argv, 1); - JSHandle argumentsList = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); - JSHandle argOrAbrupt = JSObject::CreateListFromArrayLike(thread, argumentsList); + JSHandle this_argument = GetCallArg(argv, 1); + JSHandle arguments_list = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle arg_or_abrupt = JSObject::CreateListFromArrayLike(thread, arguments_list); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle args = JSHandle::Cast(argOrAbrupt); + JSHandle args = JSHandle::Cast(arg_or_abrupt); // 3. Perform PrepareForTailCall(). // 4. Return ? Call(target, thisArgument, args). const auto args_length = args->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - auto info = NewRuntimeCallInfo(thread, target, thisArgument, undefined, args_length); + auto info = NewRuntimeCallInfo(thread, target, this_argument, undefined, args_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(args_length, args->GetData()); - return JSFunction::Call(info.get()); + return JSFunction::Call(info.Get()); } // ecma 26.1.2 Reflect.construct (target, argumentsList [ , new_target]) @@ -53,7 +53,7 @@ JSTaggedValue BuiltinsReflect::ReflectConstruct(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If IsConstructor(target) is false, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsConstructor()) { @@ -68,16 +68,16 @@ JSTaggedValue BuiltinsReflect::ReflectConstruct(EcmaRuntimeCallInfo *argv) JSTaggedValue::Exception()); } // 4. Let args be ? CreateListFromArrayLike(argumentsList). - JSHandle argumentsList = GetCallArg(argv, 1); - JSHandle argOrAbrupt = JSObject::CreateListFromArrayLike(thread, argumentsList); + JSHandle arguments_list = GetCallArg(argv, 1); + JSHandle arg_or_abrupt = JSObject::CreateListFromArrayLike(thread, arguments_list); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle args = JSHandle::Cast(argOrAbrupt); + JSHandle args = JSHandle::Cast(arg_or_abrupt); // 5. Return ? Construct(target, args, new_target). const auto args_length = args->GetLength(); auto info = NewRuntimeCallInfo(thread, target, JSTaggedValue::Undefined(), new_target, args_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetCallArg(args_length, args->GetData()); - return JSFunction::Construct(info.get()); + return JSFunction::Construct(info.Get()); } // ecma 26.1.3 Reflect.defineProperty (target, propertyKey, attributes) @@ -86,7 +86,7 @@ JSTaggedValue BuiltinsReflect::ReflectDefineProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, DefineProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -110,7 +110,7 @@ JSTaggedValue BuiltinsReflect::ReflectDeleteProperty(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, DeleteProperty); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -129,7 +129,7 @@ JSTaggedValue BuiltinsReflect::ReflectGet(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Get); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle val = GetCallArg(argv, 0); if (!val->IsECMAObject()) { @@ -155,7 +155,7 @@ JSTaggedValue BuiltinsReflect::ReflectGetOwnPropertyDescriptor(EcmaRuntimeCallIn ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, GetOwnPropertyDescriptor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -181,7 +181,7 @@ JSTaggedValue BuiltinsReflect::ReflectGetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, GetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle val = GetCallArg(argv, 0); if (!val->IsECMAObject()) { @@ -198,7 +198,7 @@ JSTaggedValue BuiltinsReflect::ReflectHas(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -216,7 +216,7 @@ JSTaggedValue BuiltinsReflect::ReflectIsExtensible(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -232,7 +232,7 @@ JSTaggedValue BuiltinsReflect::ReflectOwnKeys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, OwnKeys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -252,7 +252,7 @@ JSTaggedValue BuiltinsReflect::ReflectPreventExtensions(EcmaRuntimeCallInfo *arg ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, PreventExtensions); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { @@ -269,10 +269,10 @@ JSTaggedValue BuiltinsReflect::ReflectSet(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. - JSHandle targetVal = GetCallArg(argv, 0); - if (!targetVal->IsECMAObject()) { + JSHandle target_val = 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). @@ -283,10 +283,10 @@ JSTaggedValue BuiltinsReflect::ReflectSet(EcmaRuntimeCallInfo *argv) // 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, targetVal, key, value)); + return GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value)); } JSHandle receiver = GetCallArg(argv, 3); // 3: 3 means the third arg - return GetTaggedBoolean(JSTaggedValue::SetProperty(thread, targetVal, key, value, receiver)); + return GetTaggedBoolean(JSTaggedValue::SetProperty(thread, target_val, key, value, receiver)); } // ecma 26.1.13 Reflect.setPrototypeOf (target, proto) @@ -295,7 +295,7 @@ JSTaggedValue BuiltinsReflect::ReflectSetPrototypeOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Reflect, SetPrototypeOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. If Type(target) is not Object, throw a TypeError exception. JSHandle target = GetCallArg(argv, 0); if (!target->IsECMAObject()) { diff --git a/runtime/builtins/builtins_regexp.cpp b/runtime/builtins/builtins_regexp.cpp index 53738fb3481523a61402f0785d40753e4fbb5bd9..781d91fbbefee7ce459d402545c702c5068e3f9a 100644 --- a/runtime/builtins/builtins_regexp.cpp +++ b/runtime/builtins/builtins_regexp.cpp @@ -39,87 +39,87 @@ JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle newTargetTemp = GetNewTarget(argv); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle new_target_temp = GetNewTarget(argv); JSHandle pattern = GetCallArg(argv, 0); JSHandle flags = GetCallArg(argv, 1); // 1. Let patternIsRegExp be IsRegExp(pattern). - bool patternIsRegExp = JSObject::IsRegExp(thread, pattern); + bool pattern_is_reg_exp = JSObject::IsRegExp(thread, pattern); // 2. ReturnIfAbrupt(patternIsRegExp). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If NewTarget is not undefined, let new_target be NewTarget. JSHandle new_target; - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - if (!newTargetTemp->IsUndefined()) { - new_target = newTargetTemp; + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + if (!new_target_temp->IsUndefined()) { + new_target = new_target_temp; } else { - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); // disable gc [[maybe_unused]] DisallowGarbageCollection no_gc; // 4.a Let new_target be the active function object. new_target = env->GetRegExpFunction(); - JSHandle constructorString = globalConst->GetHandledConstructorString(); + JSHandle constructor_string = global_const->GetHandledConstructorString(); // 4.b If patternIsRegExp is true and flags is undefined - if (patternIsRegExp && flags->IsUndefined()) { + if (pattern_is_reg_exp && flags->IsUndefined()) { // 4.b.i Let patternConstructor be Get(pattern, "constructor"). - JSTaggedValue patternConstructor = - FastRuntimeStub::FastGetPropertyByValue(thread, pattern, constructorString); + JSTaggedValue pattern_constructor = + FastRuntimeStub::FastGetPropertyByValue(thread, pattern, constructor_string); // 4.b.ii ReturnIfAbrupt(patternConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4.b.iii If SameValue(new_target, patternConstructor) is true, return pattern. - if (JSTaggedValue::SameValue(new_target.GetTaggedValue(), patternConstructor)) { + if (JSTaggedValue::SameValue(new_target.GetTaggedValue(), pattern_constructor)) { return pattern.GetTaggedValue(); } } } // 5. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal slot - bool isJsReg = false; + bool is_js_reg = false; if (pattern->IsECMAObject()) { - JSHandle patternObj = JSHandle::Cast(pattern); - isJsReg = patternObj->IsJSRegExp(); + JSHandle pattern_obj = JSHandle::Cast(pattern); + is_js_reg = pattern_obj->IsJSRegExp(); } - JSHandle patternTemp; - JSHandle flagsTemp; - if (isJsReg) { - JSHandle patternReg(thread, JSRegExp::Cast(pattern->GetTaggedObject())); + JSHandle pattern_temp; + JSHandle flags_temp; + if (is_js_reg) { + JSHandle pattern_reg(thread, JSRegExp::Cast(pattern->GetTaggedObject())); // 5.a Let P be the value of pattern’s [[OriginalSource]] internal slot. - patternTemp = JSHandle(thread, patternReg->GetOriginalSource()); + pattern_temp = JSHandle(thread, pattern_reg->GetOriginalSource()); if (flags->IsUndefined()) { // 5.b If flags is undefined, let F be the value of pattern’s [[OriginalFlags]] internal slot. - flagsTemp = JSHandle(thread, patternReg->GetOriginalFlags()); + flags_temp = JSHandle(thread, pattern_reg->GetOriginalFlags()); } else { // 5.c Else, let F be flags. - flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); + flags_temp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); } // 6. Else if patternIsRegExp is true - } else if (patternIsRegExp) { - JSHandle sourceString(globalConst->GetHandledSourceString()); - JSHandle flagsString(globalConst->GetHandledFlagsString()); + } else if (pattern_is_reg_exp) { + JSHandle source_string(global_const->GetHandledSourceString()); + JSHandle flags_string(global_const->GetHandledFlagsString()); // disable gc - [[maybe_unused]] DisallowGarbageCollection noGc; + [[maybe_unused]] DisallowGarbageCollection no_gc; // 6.a Let P be Get(pattern, "source"). - patternTemp = JSObject::GetProperty(thread, pattern, sourceString).GetValue(); + pattern_temp = JSObject::GetProperty(thread, pattern, source_string).GetValue(); // 6.b ReturnIfAbrupt(P). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6.c If flags is undefined if (flags->IsUndefined()) { // 6.c.i Let F be Get(pattern, "flags"). - flagsTemp = JSObject::GetProperty(thread, pattern, flagsString).GetValue(); + flags_temp = JSObject::GetProperty(thread, pattern, flags_string).GetValue(); // 6.c.ii ReturnIfAbrupt(F). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { // 6.d Else, let F be flags. - flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); + flags_temp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); } } else { // 7.a Let P be pattern. - patternTemp = pattern; + pattern_temp = pattern; // 7.b Let F be flags. if (flags->IsUndefined()) { - flagsTemp = flags; + flags_temp = flags; } else { - flagsTemp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); + flags_temp = JSHandle(thread, *JSTaggedValue::ToString(thread, flags)); } } // 8. Let O be RegExpAlloc(new_target). @@ -127,28 +127,28 @@ JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) // 9. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 10. Return RegExpInitialize(O, P, F). - JSTaggedValue result = RegExpInitialize(thread, object, patternTemp, flagsTemp); + JSTaggedValue result = RegExpInitialize(thread, object, pattern_temp, flags_temp); return JSTaggedValue(result); } -static bool ExecCachingAllowed(JSThread *thread, JSHandle &thisVal) +static bool ExecCachingAllowed(JSThread *thread, JSHandle &this_val) { - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); - if (!thisVal->IsJSObject()) { + if (!this_val->IsJSObject()) { return false; } - JSObject *thisObj = JSObject::Cast(thisVal->GetTaggedObject()); - JSHClass *thisClass = thisObj->GetJSHClass(); + JSObject *this_obj = JSObject::Cast(this_val->GetTaggedObject()); + JSHClass *this_class = this_obj->GetJSHClass(); - JSHandle regexFn(thread->GetEcmaVM()->GetGlobalEnv()->GetRegExpFunction()); - if (JSTaggedValue(thisClass) != regexFn->GetProtoOrDynClass()) { + JSHandle regex_fn(thread->GetEcmaVM()->GetGlobalEnv()->GetRegExpFunction()); + if (JSTaggedValue(this_class) != regex_fn->GetProtoOrDynClass()) { return false; } - JSTaggedValue regexProto = - JSHClass::Cast(globalConst->GetHandledJSRegExpClass()->GetTaggedObject())->GetPrototype(); - return thisClass->GetPrototype() == regexProto; + JSTaggedValue regex_proto = + JSHClass::Cast(global_const->GetHandledJSRegExpClass()->GetTaggedObject())->GetPrototype(); + return this_class->GetPrototype() == regex_proto; } // prototype @@ -158,34 +158,34 @@ JSTaggedValue BuiltinsRegExp::Exec(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Exec); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle thisObj = GetThis(argv); + JSHandle this_obj = GetThis(argv); // 4. Let S be ToString(string). - JSHandle inputStr = GetCallArg(argv, 0); - JSHandle stringHandle = JSTaggedValue::ToString(thread, inputStr); + JSHandle input_str = GetCallArg(argv, 0); + JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); // 5. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(stringHandle); + JSHandle string = JSHandle::Cast(string_handle); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!thisObj->IsECMAObject()) { + if (!this_obj->IsECMAObject()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } // 3. If R does not have a [[RegExpMatcher]] internal slot, throw a TypeError exception. - if (!thisObj->IsJSRegExp()) { + if (!this_obj->IsJSRegExp()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this does not have [[RegExpMatcher]]", JSTaggedValue::Exception()); } - bool useCache = ExecCachingAllowed(thread, thisObj); - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - if (cacheTable->GetLargeStrCount() == 0 || cacheTable->GetConflictCount() == 0) { - useCache = false; + bool use_cache = ExecCachingAllowed(thread, this_obj); + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + if (cache_table->GetLargeStrCount() == 0 || cache_table->GetConflictCount() == 0) { + use_cache = false; } // 6. Return RegExpBuiltinExec(R, S). - JSTaggedValue result = RegExpBuiltinExec(thread, thisObj, string, useCache); + JSTaggedValue result = RegExpBuiltinExec(thread, this_obj, string, use_cache); return JSTaggedValue(result); } @@ -195,27 +195,27 @@ JSTaggedValue BuiltinsRegExp::Test(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Test); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle thisObj = GetThis(argv); - JSHandle inputStr = GetCallArg(argv, 0); + JSHandle this_obj = GetThis(argv); + JSHandle input_str = GetCallArg(argv, 0); // 3. Let string be ToString(S). // 4. ReturnIfAbrupt(string). - JSHandle stringHandle = JSTaggedValue::ToString(thread, inputStr); + JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(stringHandle); + JSHandle string = JSHandle::Cast(string_handle); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!thisObj->IsECMAObject()) { + if (!this_obj->IsECMAObject()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } // 5. Let match be RegExpExec(R, string). - JSTaggedValue matchResult = RegExpExec(thread, thisObj, string, false); + JSTaggedValue match_result = 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(!matchResult.IsNull()); + return GetTaggedBoolean(!match_result.IsNull()); } // 20.2.5.14 @@ -224,33 +224,33 @@ JSTaggedValue BuiltinsRegExp::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle thisObj = GetThis(argv); - auto ecmaVm = thread->GetEcmaVM(); + JSHandle this_obj = GetThis(argv); + auto ecma_vm = thread->GetEcmaVM(); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!thisObj->IsECMAObject()) { + if (!this_obj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } - ObjectFactory *factory = ecmaVm->GetFactory(); - const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); - JSHandle sourceString(globalConstants->GetHandledSourceString()); - JSHandle flagsString(globalConstants->GetHandledFlagsString()); + ObjectFactory *factory = ecma_vm->GetFactory(); + const GlobalEnvConstants *global_constants = thread->GlobalConstants(); + JSHandle source_string(global_constants->GetHandledSourceString()); + JSHandle flags_string(global_constants->GetHandledFlagsString()); // 3. Let pattern be ToString(Get(R, "source")). - JSHandle getSource(JSObject::GetProperty(thread, thisObj, sourceString).GetValue()); - JSHandle getFlags(JSObject::GetProperty(thread, thisObj, flagsString).GetValue()); - JSHandle sourceStrHandle = JSTaggedValue::ToString(thread, getSource); + JSHandle get_source(JSObject::GetProperty(thread, this_obj, source_string).GetValue()); + JSHandle get_flags(JSObject::GetProperty(thread, this_obj, flags_string).GetValue()); + JSHandle source_str_handle = JSTaggedValue::ToString(thread, get_source); // 4. ReturnIfAbrupt(pattern). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let flags be ToString(Get(R, "flags")). - JSHandle flagsStrHandle = JSTaggedValue::ToString(thread, getFlags); + JSHandle flags_str_handle = JSTaggedValue::ToString(thread, get_flags); // 4. ReturnIfAbrupt(flags). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle slashStr = JSHandle::Cast(globalConstants->GetHandledBackslashString()); + JSHandle slash_str = JSHandle::Cast(global_constants->GetHandledBackslashString()); // 7. Let result be the String value formed by concatenating "/", pattern, and "/", and flags. - JSHandle tempStr = factory->ConcatFromString(slashStr, sourceStrHandle); - JSHandle resultTemp = factory->ConcatFromString(tempStr, slashStr); - return factory->ConcatFromString(resultTemp, flagsStrHandle).GetTaggedValue(); + JSHandle temp_str = factory->ConcatFromString(slash_str, source_str_handle); + JSHandle result_temp = factory->ConcatFromString(temp_str, slash_str); + return factory->ConcatFromString(result_temp, flags_str_handle).GetTaggedValue(); } // 20.2.5.3 @@ -259,48 +259,48 @@ JSTaggedValue BuiltinsRegExp::GetFlags(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, GetFlags); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle thisObj = GetThis(argv); + JSHandle this_obj = GetThis(argv); // 2. If Type(R) is not Object, throw a TypeError exception. - if (!thisObj->IsECMAObject()) { + if (!this_obj->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } // 3. Let result be the empty String. // 4. ~ 19. - if (JSHandle::Cast(thisObj)->IsJSRegExp()) { - uint8_t flagsBits = - static_cast(JSRegExp::Cast(thisObj->GetTaggedObject())->GetOriginalFlags().GetInt()); - return FlagsBitsToString(thread, flagsBits); + if (JSHandle::Cast(this_obj)->IsJSRegExp()) { + uint8_t flags_bits = + static_cast(JSRegExp::Cast(this_obj->GetTaggedObject())->GetOriginalFlags().GetInt()); + return FlagsBitsToString(thread, flags_bits); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) - std::array flagsStr; // six flags + \0 + std::array flags_str; // six flags + \0 { - char *flagsCur = flagsStr.data(); + char *flags_cur = flags_str.data(); - auto addFlagVal = [&](char const *propStr, char const flagChar) { - JSHandle prop(factory->NewFromString(propStr)); - JSHandle getResult(JSObject::GetProperty(thread, thisObj, prop).GetValue()); - if (getResult->ToBoolean()) { + auto add_flag_val = [&](char const *prop_str, char const flag_char) { + JSHandle prop(factory->NewFromString(prop_str)); + JSHandle get_result(JSObject::GetProperty(thread, this_obj, prop).GetValue()); + if (get_result->ToBoolean()) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *flagsCur++ = flagChar; + *flags_cur++ = flag_char; } }; - addFlagVal("global", 'g'); - addFlagVal("ignoreCase", 'i'); - addFlagVal("multiline", 'm'); - addFlagVal("dotAll", 's'); - addFlagVal("unicode", 'u'); - addFlagVal("sticky", 'y'); + add_flag_val("global", 'g'); + add_flag_val("ignoreCase", 'i'); + add_flag_val("multiline", 'm'); + add_flag_val("dotAll", 's'); + add_flag_val("unicode", 'u'); + add_flag_val("sticky", 'y'); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *flagsCur = '\0'; + *flags_cur = '\0'; } - return factory->NewFromString(flagsStr.data()).GetTaggedValue(); + return factory->NewFromString(flags_str.data()).GetTaggedValue(); } // 20.2.5.4 @@ -308,9 +308,9 @@ JSTaggedValue BuiltinsRegExp::GetGlobal(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisObj = GetThis(argv); - bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_GLOBAL); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_obj = GetThis(argv); + bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_GLOBAL); return GetTaggedBoolean(result); } @@ -319,9 +319,9 @@ JSTaggedValue BuiltinsRegExp::GetIgnoreCase(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisObj = GetThis(argv); - bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_IGNORECASE); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_obj = GetThis(argv); + bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_IGNORECASE); return GetTaggedBoolean(result); } @@ -330,9 +330,9 @@ JSTaggedValue BuiltinsRegExp::GetMultiline(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisObj = GetThis(argv); - bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_MULTILINE); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_obj = GetThis(argv); + bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_MULTILINE); return GetTaggedBoolean(result); } @@ -340,9 +340,9 @@ JSTaggedValue BuiltinsRegExp::GetDotAll(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisObj = GetThis(argv); - bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_DOTALL); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_obj = GetThis(argv); + bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_DOTALL); return GetTaggedBoolean(result); } @@ -351,26 +351,26 @@ JSTaggedValue BuiltinsRegExp::GetSource(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. - JSHandle thisObj = GetThis(argv); + JSHandle this_obj = 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. - if (!thisObj->IsECMAObject()) { + if (!this_obj->IsECMAObject()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this is not Object", JSTaggedValue::Exception()); } - if (!thisObj->IsJSRegExp()) { + if (!this_obj->IsJSRegExp()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this does not have [[OriginalSource]]", JSTaggedValue::Exception()); } // 5. Let src be the value of R’s [[OriginalSource]] internal slot. - JSHandle regexpObj(thread, JSRegExp::Cast(thisObj->GetTaggedObject())); - JSHandle source(thread, regexpObj->GetOriginalSource()); + JSHandle regexp_obj(thread, JSRegExp::Cast(this_obj->GetTaggedObject())); + JSHandle source(thread, regexp_obj->GetOriginalSource()); // 6. Let flags be the value of R’s [[OriginalFlags]] internal slot. - uint8_t flagsBits = static_cast(regexpObj->GetOriginalFlags().GetInt()); - JSHandle flags(thread, FlagsBitsToString(thread, flagsBits)); + uint8_t flags_bits = static_cast(regexp_obj->GetOriginalFlags().GetInt()); + JSHandle flags(thread, FlagsBitsToString(thread, flags_bits)); // 7. Return EscapeRegExpPattern(src, flags). return JSTaggedValue(EscapeRegExpPattern(thread, source, flags)); } @@ -380,9 +380,9 @@ JSTaggedValue BuiltinsRegExp::GetSticky(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisObj = GetThis(argv); - bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_STICKY); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_obj = GetThis(argv); + bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_STICKY); return GetTaggedBoolean(result); } @@ -391,9 +391,9 @@ JSTaggedValue BuiltinsRegExp::GetUnicode(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisObj = GetThis(argv); - bool result = GetFlagsInternal(thread, thisObj, RegExpParser::FLAG_UTF16); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_obj = GetThis(argv); + bool result = GetFlagsInternal(thread, this_obj, RegExpParser::FLAG_UTF16); return GetTaggedBoolean(result); } @@ -410,98 +410,98 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Match); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let rx be the this value. - JSHandle thisObj = GetThis(argv); + JSHandle this_obj = GetThis(argv); // 3. Let S be ToString(string) - JSHandle inputString = GetCallArg(argv, 0); - JSHandle stringHandle = JSTaggedValue::ToString(thread, inputString); - bool useCache = true; - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - if (cacheTable->GetLargeStrCount() == 0 || cacheTable->GetConflictCount() == 0) { - useCache = false; + JSHandle input_string = GetCallArg(argv, 0); + JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); + bool use_cache = true; + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + if (cache_table->GetLargeStrCount() == 0 || cache_table->GetConflictCount() == 0) { + use_cache = false; } // 4. ReturnIfAbrupt(string). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(stringHandle); - if (!thisObj->IsECMAObject()) { + JSHandle string = JSHandle::Cast(string_handle); + 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()); } - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); - useCache &= ExecCachingAllowed(thread, thisObj); + use_cache &= ExecCachingAllowed(thread, this_obj); // 5. Let global be ToBoolean(Get(rx, "global")). - JSHandle global = globalConst->GetHandledGlobalString(); - JSTaggedValue globalValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, global); + JSHandle global = global_const->GetHandledGlobalString(); + JSTaggedValue global_value = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, global); // 6. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle regexpObj(thisObj); + JSHandle regexp_obj(this_obj); JSMutableHandle pattern(thread, JSTaggedValue::Undefined()); JSMutableHandle flags(thread, JSTaggedValue::Undefined()); - if (thisObj->IsJSRegExp()) { - pattern.Update(regexpObj->GetOriginalSource()); - flags.Update(regexpObj->GetOriginalFlags()); + if (this_obj->IsJSRegExp()) { + pattern.Update(regexp_obj->GetOriginalSource()); + flags.Update(regexp_obj->GetOriginalFlags()); } - bool isGlobal = globalValue.ToBoolean(); + bool is_global = global_value.ToBoolean(); // 7. If global is false, then - if (!isGlobal) { + if (!is_global) { // a. Return RegExpExec(rx, S). - if (useCache) { - JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flags, inputString, - RegExpExecResultCache::EXEC_TYPE, thisObj); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + if (use_cache) { + JSTaggedValue cache_result = cache_table->FindCachedResult(thread, pattern, flags, input_string, + RegExpExecResultCache::EXEC_TYPE, this_obj); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } - JSTaggedValue result = RegExpExec(thread, thisObj, string, useCache); + JSTaggedValue result = RegExpExec(thread, this_obj, string, use_cache); return JSTaggedValue(result); } - if (useCache) { - JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flags, inputString, - RegExpExecResultCache::MATCH_TYPE, thisObj); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + if (use_cache) { + JSTaggedValue cache_result = cache_table->FindCachedResult(thread, pattern, flags, input_string, + RegExpExecResultCache::MATCH_TYPE, this_obj); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } // 8. Else global is true // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). - JSHandle unicode = globalConst->GetHandledUnicodeString(); - JSTaggedValue uincodeValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, unicode); + JSHandle unicode = global_const->GetHandledUnicodeString(); + JSTaggedValue uincode_value = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, unicode); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool fullUnicode = uincodeValue.ToBoolean(); + bool full_unicode = uincode_value.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). - JSHandle lastIndexString(globalConst->GetHandledLastIndexString()); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(thisObj), lastIndexString, + JSHandle last_index_string(global_const->GetHandledLastIndexString()); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(this_obj), last_index_string, thread->GlobalConstants()->GetHandledZero()); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // e. Let A be ArrayCreate(0). JSHandle array(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); // f. Let n be 0. - int resultNum = 0; + int result_num = 0; JSMutableHandle result(thread, JSTaggedValue(0)); // g. Repeat, while (true) { // i. Let result be RegExpExec(rx, S). - result.Update(RegExpExec(thread, thisObj, string, useCache)); + result.Update(RegExpExec(thread, this_obj, string, use_cache)); // ii. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iii. If result is null, then if (result->IsNull()) { // 1. If n=0, return null. - if (resultNum == 0) { + if (result_num == 0) { return JSTaggedValue::Null(); } - if (useCache) { - RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flags, inputString, + if (use_cache) { + RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags, input_string, JSHandle(array), RegExpExecResultCache::MATCH_TYPE, 0); } @@ -510,33 +510,33 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) } // iv. Else result is not null, // 1. Let matchStr be ToString(Get(result, "0")). - JSHandle zeroString = globalConst->GetHandledZeroString(); - JSTaggedValue matchVal = FastRuntimeStub::FastGetPropertyByValue(thread, result, zeroString); - JSHandle matchStr(thread, matchVal); - JSHandle matchString = JSTaggedValue::ToString(thread, matchStr); + JSHandle zero_string = global_const->GetHandledZeroString(); + JSTaggedValue match_val = FastRuntimeStub::FastGetPropertyByValue(thread, result, zero_string); + JSHandle match_str(thread, match_val); + JSHandle match_string = JSTaggedValue::ToString(thread, match_str); // 2. ReturnIfAbrupt(matchStr). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle matchValue = JSHandle::Cast(matchString); + JSHandle match_value = JSHandle::Cast(match_string); // 3. Let status be CreateDataProperty(A, ToString(n), matchStr). - JSObject::CreateDataProperty(thread, array, resultNum, matchValue); + JSObject::CreateDataProperty(thread, array, result_num, match_value); // 5. If matchStr is the empty String, then - if (JSTaggedValue::ToString(thread, matchValue)->GetLength() == 0) { + if (JSTaggedValue::ToString(thread, match_value)->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - JSTaggedValue lastIndex = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, lastIndexString); - JSHandle lastIndexHandle(thread, lastIndex); - JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, lastIndexHandle); + JSTaggedValue last_index = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, last_index_string); + JSHandle last_index_handle(thread, last_index); + JSTaggedNumber this_index = JSTaggedValue::ToLength(thread, last_index_handle); // b. ReturnIfAbrupt(thisIndex). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). - auto nextIndex = JSTaggedValue(AdvanceStringIndex(string, thisIndex.GetNumber(), fullUnicode)); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(thisObj), lastIndexString, - HandleFromLocal(&nextIndex)); + auto next_index = JSTaggedValue(AdvanceStringIndex(string, this_index.GetNumber(), full_unicode)); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(this_obj), last_index_string, + HandleFromLocal(&next_index)); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 6. Increase n. - resultNum++; + result_num++; } } @@ -545,194 +545,196 @@ JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, RegExp, MatchAll); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let R be the this value. // 2. If Type(R) is not Object, throw a TypeError exception. - JSHandle thisObj = GetThis(argv); - auto ecmaVm = thread->GetEcmaVM(); - if (!thisObj->IsECMAObject()) { + JSHandle this_obj = 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 inputString = GetCallArg(argv, 0); - JSHandle stringHandle = JSTaggedValue::ToString(thread, inputString); + JSHandle input_string = GetCallArg(argv, 0); + JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let C be ? SpeciesConstructor(R, %RegExp%). - JSHandle defaultConstructor = ecmaVm->GetGlobalEnv()->GetRegExpFunction(); - JSHandle objHandle(thisObj); - JSHandle constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); + JSHandle default_constructor = ecma_vm->GetGlobalEnv()->GetRegExpFunction(); + JSHandle obj_handle(this_obj); + JSHandle constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); + const GlobalEnvConstants *global_constants = thread->GlobalConstants(); // 5. Let flags be ? ToString(? Get(R, "flags")). - JSHandle flagsString(globalConstants->GetHandledFlagsString()); - JSHandle getFlags(JSObject::GetProperty(thread, thisObj, flagsString).GetValue()); - JSHandle flagsStrHandle = JSTaggedValue::ToString(thread, getFlags); + JSHandle flags_string(global_constants->GetHandledFlagsString()); + JSHandle get_flags(JSObject::GetProperty(thread, this_obj, flags_string).GetValue()); + JSHandle flags_str_handle = JSTaggedValue::ToString(thread, get_flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. Let matcher be ? Construct(C, « R, flags »). - JSHandle undefined = globalConstants->GetHandledUndefined(); + JSHandle undefined = global_constants->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), undefined, 2); - info->SetCallArgs(thisObj.GetTaggedValue(), flagsStrHandle.GetTaggedValue()); - JSTaggedValue taggedMatcher = JSFunction::Construct(info.get()); - JSHandle matcherHandle(thread, taggedMatcher); + info->SetCallArgs(this_obj.GetTaggedValue(), flags_str_handle.GetTaggedValue()); + JSTaggedValue tagged_matcher = JSFunction::Construct(info.Get()); + JSHandle matcher_handle(thread, tagged_matcher); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let lastIndex be ? ToLength(? Get(R, "lastIndex")). - JSHandle lastIndexString(globalConstants->GetHandledLastIndexString()); - JSHandle getLastIndex(JSObject::GetProperty(thread, thisObj, lastIndexString).GetValue()); - JSTaggedNumber thisLastIndex = JSTaggedValue::ToLength(thread, getLastIndex); + JSHandle last_index_string(global_constants->GetHandledLastIndexString()); + JSHandle get_last_index(JSObject::GetProperty(thread, this_obj, last_index_string).GetValue()); + JSTaggedNumber this_last_index = JSTaggedValue::ToLength(thread, get_last_index); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Perform ? Set(matcher, "lastIndex", lastIndex, true). - FastRuntimeStub::FastSetPropertyByValue(thread, matcherHandle, lastIndexString, HandleFromLocal(&thisLastIndex)); + FastRuntimeStub::FastSetPropertyByValue(thread, matcher_handle, last_index_string, + HandleFromLocal(&this_last_index)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If flags contains "g", let global be true. // 10. Else, let global be false. - JSHandle gString(globalConstants->GetHandledGString()); + JSHandle g_string(global_constants->GetHandledGString()); bool global = false; - if (base::StringHelper::Contains(*flagsStrHandle, *gString)) { + if (base::StringHelper::Contains(*flags_str_handle, *g_string)) { global = true; } // 11. If flags contains "u", let fullUnicode be true. // 12. Else, let fullUnicode be false. - JSHandle uString(globalConstants->GetHandledUString()); - bool fullUnicode = false; - if (base::StringHelper::Contains(*flagsStrHandle, *uString)) { - fullUnicode = true; + JSHandle u_string(global_constants->GetHandledUString()); + bool full_unicode = false; + if (base::StringHelper::Contains(*flags_str_handle, *u_string)) { + full_unicode = true; } // 13. Return ! CreateRegExpStringIterator(matcher, S, global, fullUnicode). - return JSRegExpIterator::CreateRegExpStringIterator(thread, matcherHandle, stringHandle, global, fullUnicode) + return JSRegExpIterator::CreateRegExpStringIterator(thread, matcher_handle, string_handle, global, full_unicode) .GetTaggedValue(); } JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle ®exp, - JSHandle inputString, uint32_t inputLength) + JSHandle input_string, uint32_t input_length) { ASSERT(regexp->IsJSRegExp()); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // get bytecode - JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); - void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); + JSTaggedValue buffer_data = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + void *dyn_buf = JSNativePointer::Cast(buffer_data.GetTaggedObject())->GetExternalPointer(); // get flags - auto bytecodeBuffer = reinterpret_cast(dynBuf); + auto bytecode_buffer = reinterpret_cast(dyn_buf); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - uint32_t flags = *reinterpret_cast(bytecodeBuffer + RegExpParser::FLAGS_OFFSET); - JSHandle lastIndexHandle(thread->GlobalConstants()->GetHandledLastIndexString()); - uint32_t lastIndex; - JSHandle regexpHandle(regexp); - bool useCache = false; + uint32_t flags = *reinterpret_cast(bytecode_buffer + RegExpParser::FLAGS_OFFSET); + JSHandle last_index_handle(thread->GlobalConstants()->GetHandledLastIndexString()); + uint32_t last_index; + JSHandle regexp_handle(regexp); + bool use_cache = false; if ((flags & (RegExpParser::FLAG_STICKY | RegExpParser::FLAG_GLOBAL)) == 0) { - lastIndex = 0; + last_index = 0; } else { - JSTaggedValue thisIndex = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, lastIndexHandle); - if (thisIndex.IsInt()) { - lastIndex = static_cast(thisIndex.GetInt()); + JSTaggedValue this_index = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, last_index_handle); + if (this_index.IsInt()) { + last_index = static_cast(this_index.GetInt()); } else { - JSHandle thisIndexHandle(thread, thisIndex); - lastIndex = JSTaggedValue::ToLength(thread, thisIndexHandle).GetNumber(); + JSHandle this_index_handle(thread, this_index); + last_index = JSTaggedValue::ToLength(thread, this_index_handle).GetNumber(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } - auto globalConst = thread->GlobalConstants(); - JSHandle tagInputString = JSHandle::Cast(inputString); - JSHandle pattern(thread, regexpHandle->GetOriginalSource()); - JSHandle flagsBits(thread, regexpHandle->GetOriginalFlags()); + auto global_const = thread->GlobalConstants(); + JSHandle tag_input_string = JSHandle::Cast(input_string); + JSHandle pattern(thread, regexp_handle->GetOriginalSource()); + JSHandle flags_bits(thread, regexp_handle->GetOriginalFlags()); - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - uint32_t length = inputString->GetLength(); - uint32_t largeStrCount = cacheTable->GetLargeStrCount(); - if (largeStrCount != 0) { + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + uint32_t length = input_string->GetLength(); + uint32_t large_str_count = cache_table->GetLargeStrCount(); + if (large_str_count != 0) { if (length > MIN_REPLACE_STRING_LENGTH) { - cacheTable->SetLargeStrCount(thread, --largeStrCount); + cache_table->SetLargeStrCount(thread, --large_str_count); } } else { - cacheTable->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); + cache_table->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); } - if (length > cacheTable->GetStrLenThreshold()) { - useCache = ExecCachingAllowed(thread, regexp); + if (length > cache_table->GetStrLenThreshold()) { + use_cache = ExecCachingAllowed(thread, regexp); } - if (useCache) { - JSTaggedValue cacheResult = - cacheTable->FindCachedResult(thread, pattern, flagsBits, tagInputString, - RegExpExecResultCache::REPLACE_TYPE, regexp, globalConst->GetEmptyString()); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + if (use_cache) { + JSTaggedValue cache_result = + cache_table->FindCachedResult(thread, pattern, flags_bits, tag_input_string, + RegExpExecResultCache::REPLACE_TYPE, regexp, global_const->GetEmptyString()); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } - std::string resultString; - uint32_t nextPosition = 0; + std::string result_string; + uint32_t next_position = 0; // 12. Let done be false. // 13. Repeat, while done is false for (;;) { - if (lastIndex > inputLength) { + if (last_index > input_length) { break; } - bool isUtf16 = inputString->IsUtf16(); - const uint8_t *strBuffer; - PandaVector u8Buffer; - PandaVector u16Buffer; - if (isUtf16) { - u16Buffer = PandaVector(inputLength); - inputString->CopyDataUtf16(u16Buffer.data(), inputLength); - strBuffer = reinterpret_cast(u16Buffer.data()); + bool is_utf16 = input_string->IsUtf16(); + const uint8_t *str_buffer; + PandaVector u8_buffer; + PandaVector u16_buffer; + if (is_utf16) { + u16_buffer = PandaVector(input_length); + input_string->CopyDataUtf16(u16_buffer.data(), input_length); + str_buffer = reinterpret_cast(u16_buffer.data()); } else { - u8Buffer = PandaVector(inputLength + 1); - inputString->CopyDataUtf8(u8Buffer.data(), inputLength + 1); - strBuffer = u8Buffer.data(); + u8_buffer = PandaVector(input_length + 1); + input_string->CopyDataUtf8(u8_buffer.data(), input_length + 1); + str_buffer = u8_buffer.data(); } - RegExpExecutor::MatchResult matchResult = Matcher(thread, regexp, strBuffer, inputLength, lastIndex, isUtf16); - if (!matchResult.isSuccess_) { + RegExpExecutor::MatchResult match_result = + Matcher(thread, regexp, str_buffer, input_length, last_index, is_utf16); + if (!match_result.is_success) { if ((flags & (RegExpParser::FLAG_STICKY | RegExpParser::FLAG_GLOBAL)) != 0) { - lastIndex = 0; - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), lastIndexHandle, + last_index = 0; + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), last_index_handle, thread->GlobalConstants()->GetHandledZero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } break; } - uint32_t startIndex = matchResult.index_; - uint32_t endIndex = matchResult.endIndex_; - lastIndex = endIndex; - if (nextPosition < startIndex) { - resultString += base::StringHelper::SubString(inputString, nextPosition, startIndex - nextPosition); + uint32_t start_index = match_result.index; + uint32_t end_index = match_result.end_index; + last_index = end_index; + if (next_position < start_index) { + result_string += base::StringHelper::SubString(input_string, next_position, start_index - next_position); } - nextPosition = endIndex; + next_position = end_index; if ((flags & RegExpParser::FLAG_GLOBAL) == 0) { // a. Let setStatus be Set(R, "lastIndex", e, true). - JSTaggedValue lastIndexValue(lastIndex); - FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), lastIndexHandle, - HandleFromLocal(&lastIndexValue)); + JSTaggedValue last_index_value(last_index); + FastRuntimeStub::FastSetPropertyByValue(thread, JSHandle(regexp), last_index_handle, + HandleFromLocal(&last_index_value)); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); break; } - if (endIndex == startIndex) { - bool unicode = inputString->IsUtf16() && ((flags & RegExpParser::FLAG_UTF16) != 0); - endIndex = AdvanceStringIndex(tagInputString, endIndex, unicode); + if (end_index == start_index) { + bool unicode = input_string->IsUtf16() && ((flags & RegExpParser::FLAG_UTF16) != 0); + end_index = AdvanceStringIndex(tag_input_string, end_index, unicode); } - lastIndex = endIndex; + last_index = end_index; } - resultString += base::StringHelper::SubString(inputString, nextPosition, inputLength - nextPosition); - auto resultValue = factory->NewFromStdString(resultString); - if (useCache) { + result_string += base::StringHelper::SubString(input_string, next_position, input_length - next_position); + auto result_value = factory->NewFromStdString(result_string); + if (use_cache) { RegExpExecResultCache::AddResultInCache( - thread, cacheTable, pattern, flagsBits, tagInputString, JSHandle(resultValue), - RegExpExecResultCache::REPLACE_TYPE, lastIndex, globalConst->GetEmptyString()); + thread, cache_table, pattern, flags_bits, tag_input_string, JSHandle(result_value), + RegExpExecResultCache::REPLACE_TYPE, last_index, global_const->GetEmptyString()); } - return resultValue.GetTaggedValue(); + return result_value.GetTaggedValue(); } // 21.2.5.8 @@ -742,184 +744,184 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Replace); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let rx be the this value. - JSHandle thisObj = GetThis(argv); - if (!thisObj->IsECMAObject()) { + JSHandle this_obj = 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 inputReplaceValue = GetCallArg(argv, 1); - JSHandle srPandaString = JSTaggedValue::ToString(thread, string); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle input_replace_value = GetCallArg(argv, 1); + JSHandle sr_panda_string = JSTaggedValue::ToString(thread, string); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 4. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle inputStr = JSHandle::Cast(srPandaString); + JSHandle input_str = JSHandle::Cast(sr_panda_string); // 5. Let lengthS be the number of code unit elements in S. - uint32_t length = srPandaString->GetLength(); + uint32_t length = sr_panda_string->GetLength(); // 6. Let functionalReplace be IsCallable(replaceValue). - bool functionalReplace = inputReplaceValue->IsCallable(); - JSHandle replaceValueHandle; - if (!functionalReplace) { - replaceValueHandle = JSTaggedValue::ToString(thread, inputReplaceValue); + bool functional_replace = input_replace_value->IsCallable(); + JSHandle replace_value_handle; + if (!functional_replace) { + replace_value_handle = JSTaggedValue::ToString(thread, input_replace_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - JSHandle lastIndex = globalConst->GetHandledLastIndexString(); + JSHandle last_index = global_const->GetHandledLastIndexString(); // 8. Let global be ToBoolean(Get(rx, "global")). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle global = globalConst->GetHandledGlobalString(); - JSTaggedValue globalValue = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, global); + JSHandle global = global_const->GetHandledGlobalString(); + JSTaggedValue global_value = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, global); // 9. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool isGlobal = globalValue.ToBoolean(); + bool is_global = global_value.ToBoolean(); // 10. If global is true, then - bool fullUnicode = false; - if (isGlobal) { + bool full_unicode = false; + if (is_global) { // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). - JSHandle unicode = globalConst->GetHandledUnicodeString(); - JSTaggedValue fullUnicodeTag = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, unicode); + JSHandle unicode = global_const->GetHandledUnicodeString(); + JSTaggedValue full_unicode_tag = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, unicode); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - fullUnicode = fullUnicodeTag.ToBoolean(); + full_unicode = full_unicode_tag.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). - FastRuntimeStub::FastSetPropertyByValue(thread, thisObj, lastIndex, + FastRuntimeStub::FastSetPropertyByValue(thread, this_obj, last_index, thread->GlobalConstants()->GetHandledZero()); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // Add cache for regexp replace - bool useCache = false; + bool use_cache = false; JSMutableHandle pattern(thread, JSTaggedValue::Undefined()); - JSMutableHandle flagsBits(thread, JSTaggedValue::Undefined()); - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - if (isGlobal && !functionalReplace && thisObj->IsJSRegExp()) { - JSHClass *hclass = JSHandle::Cast(thisObj)->GetJSHClass(); - JSHClass *originHClass = JSHClass::Cast(globalConst->GetJSRegExpClass().GetTaggedObject()); - if (hclass == originHClass) { - if (replaceValueHandle->GetLength() == 0) { - return RegExpReplaceFast(thread, thisObj, srPandaString, length); + JSMutableHandle flags_bits(thread, JSTaggedValue::Undefined()); + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + if (is_global && !functional_replace && this_obj->IsJSRegExp()) { + JSHClass *hclass = JSHandle::Cast(this_obj)->GetJSHClass(); + JSHClass *origin_h_class = JSHClass::Cast(global_const->GetJSRegExpClass().GetTaggedObject()); + if (hclass == origin_h_class) { + if (replace_value_handle->GetLength() == 0) { + return RegExpReplaceFast(thread, this_obj, sr_panda_string, length); } - JSHandle regexpHandle(thisObj); - if (regexpHandle->IsJSRegExp()) { - pattern.Update(regexpHandle->GetOriginalSource()); - flagsBits.Update(regexpHandle->GetOriginalFlags()); + JSHandle regexp_handle(this_obj); + if (regexp_handle->IsJSRegExp()) { + pattern.Update(regexp_handle->GetOriginalSource()); + flags_bits.Update(regexp_handle->GetOriginalFlags()); } - uint32_t strLength = replaceValueHandle->GetLength(); - uint32_t largeStrCount = cacheTable->GetLargeStrCount(); - if (largeStrCount != 0) { - if (strLength > MIN_REPLACE_STRING_LENGTH) { - cacheTable->SetLargeStrCount(thread, --largeStrCount); + uint32_t str_length = replace_value_handle->GetLength(); + uint32_t large_str_count = cache_table->GetLargeStrCount(); + if (large_str_count != 0) { + if (str_length > MIN_REPLACE_STRING_LENGTH) { + cache_table->SetLargeStrCount(thread, --large_str_count); } } else { - cacheTable->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); + cache_table->SetStrLenThreshold(thread, MIN_REPLACE_STRING_LENGTH); } - if (strLength > cacheTable->GetStrLenThreshold()) { - useCache = ExecCachingAllowed(thread, thisObj); - JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flagsBits, string, - RegExpExecResultCache::REPLACE_TYPE, thisObj, - inputReplaceValue.GetTaggedValue()); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + if (str_length > cache_table->GetStrLenThreshold()) { + use_cache = ExecCachingAllowed(thread, this_obj); + JSTaggedValue cache_result = cache_table->FindCachedResult( + thread, pattern, flags_bits, string, RegExpExecResultCache::REPLACE_TYPE, this_obj, + input_replace_value.GetTaggedValue()); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } } } - JSHandle matchedStr = globalConst->GetHandledZeroString(); + JSHandle matched_str = global_const->GetHandledZeroString(); // 11. Let results be a new empty List. - JSHandle resultsList(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); - int resultsIndex = 0; + JSHandle results_list(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); + int results_index = 0; // 12. Let done be false. // 13. Repeat, while done is false - JSMutableHandle nextIndexHandle(thread, JSTaggedValue(0)); - JSMutableHandle execResult(thread, JSTaggedValue(0)); + JSMutableHandle next_index_handle(thread, JSTaggedValue(0)); + JSMutableHandle exec_result(thread, JSTaggedValue(0)); for (;;) { // a. Let result be RegExpExec(rx, S). - execResult.Update(RegExpExec(thread, thisObj, inputStr, useCache)); + exec_result.Update(RegExpExec(thread, this_obj, input_str, use_cache)); // b. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If result is null, set done to true. - if (execResult->IsNull()) { + if (exec_result->IsNull()) { break; } // d. Else result is not null, i. Append result to the end of results. - JSObject::CreateDataProperty(thread, resultsList, resultsIndex, execResult); - resultsIndex++; + JSObject::CreateDataProperty(thread, results_list, results_index, exec_result); + results_index++; // ii. If global is false, set done to true. - if (!isGlobal) { + if (!is_global) { break; } // iii. Else, 1. Let matchStr be ToString(Get(result, "0")). - JSTaggedValue getMatchVal = FastRuntimeStub::FastGetPropertyByValue(thread, execResult, matchedStr); - JSHandle getMatch(thread, getMatchVal); - JSHandle matchString = JSTaggedValue::ToString(thread, getMatch); + JSTaggedValue get_match_val = FastRuntimeStub::FastGetPropertyByValue(thread, exec_result, matched_str); + JSHandle get_match(thread, get_match_val); + JSHandle match_string = JSTaggedValue::ToString(thread, get_match); // 2. ReturnIfAbrupt(matchStr). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If matchStr is the empty String, then - if (matchString->GetLength() == 0) { + if (match_string->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - JSTaggedValue thisIndexVal = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj, lastIndex); - JSHandle thisIndexHandle(thread, thisIndexVal); - uint32_t thisIndex = 0; - if (thisIndexHandle->IsInt()) { - thisIndex = static_cast(thisIndexHandle->GetInt()); + JSTaggedValue this_index_val = FastRuntimeStub::FastGetPropertyByValue(thread, this_obj, last_index); + JSHandle this_index_handle(thread, this_index_val); + uint32_t this_index = 0; + if (this_index_handle->IsInt()) { + this_index = static_cast(this_index_handle->GetInt()); } else { - thisIndexVal = JSTaggedValue::ToLength(thread, thisIndexHandle); + this_index_val = JSTaggedValue::ToLength(thread, this_index_handle); // b. ReturnIfAbrupt(thisIndex). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - thisIndex = thisIndexVal.GetNumber(); + this_index = this_index_val.GetNumber(); } // c. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). - uint32_t nextIndex = AdvanceStringIndex(inputStr, thisIndex, fullUnicode); - nextIndexHandle.Update(JSTaggedValue(nextIndex)); + uint32_t next_index = AdvanceStringIndex(input_str, this_index, full_unicode); + next_index_handle.Update(JSTaggedValue(next_index)); // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). - FastRuntimeStub::FastSetPropertyByValue(thread, thisObj, lastIndex, nextIndexHandle); + FastRuntimeStub::FastSetPropertyByValue(thread, this_obj, last_index, next_index_handle); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } } // 14. Let accumulatedResult be the empty String value. - std::string accumulatedResult; + std::string accumulated_result; // 15. Let nextSourcePosition be 0. - uint32_t nextSourcePosition = 0; - JSHandle getMatchString; - JSMutableHandle resultValues(thread, JSTaggedValue(0)); - JSMutableHandle ncapturesHandle(thread, JSTaggedValue(0)); - JSMutableHandle capN(thread, JSTaggedValue(0)); + uint32_t next_source_position = 0; + JSHandle get_match_string; + JSMutableHandle result_values(thread, JSTaggedValue(0)); + JSMutableHandle ncaptures_handle(thread, JSTaggedValue(0)); + JSMutableHandle cap_n(thread, JSTaggedValue(0)); // 16. Repeat, for each result in results, - for (int i = 0; i < resultsIndex; i++) { - resultValues.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultsList.GetTaggedValue(), i)); + for (int i = 0; i < results_index; i++) { + result_values.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, results_list.GetTaggedValue(), i)); // a. Let nCaptures be ToLength(Get(result, "length")). - JSHandle lengthHandle = globalConst->GetHandledLengthString(); - ncapturesHandle.Update(FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, lengthHandle)); - uint32_t ncaptures = JSTaggedValue::ToUint32(thread, ncapturesHandle); + JSHandle length_handle = global_const->GetHandledLengthString(); + ncaptures_handle.Update(FastRuntimeStub::FastGetPropertyByValue(thread, result_values, length_handle)); + uint32_t ncaptures = JSTaggedValue::ToUint32(thread, ncaptures_handle); // b. ReturnIfAbrupt(nCaptures). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let nCaptures be max(nCaptures − 1, 0). ncaptures = std::max((ncaptures - 1), 0); // d. Let matched be ToString(Get(result, "0")). - JSTaggedValue value = FastRuntimeStub::GetPropertyByIndex(thread, resultValues.GetTaggedValue(), 0); - getMatchString = JSHandle(thread, value); - JSHandle matchString = JSTaggedValue::ToString(thread, getMatchString); + JSTaggedValue value = FastRuntimeStub::GetPropertyByIndex(thread, result_values.GetTaggedValue(), 0); + get_match_string = JSHandle(thread, value); + JSHandle match_string = JSTaggedValue::ToString(thread, get_match_string); // e. ReturnIfAbrupt(matched). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // f. Let matchLength be the number of code units in matched. - uint32_t matchLength = matchString->GetLength(); + uint32_t match_length = match_string->GetLength(); // g. Let position be ToInteger(Get(result, "index")). - JSHandle resultIndex = globalConst->GetHandledIndexString(); - JSTaggedValue positionTag = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, resultIndex); - JSHandle positionHandle(thread, positionTag); + JSHandle result_index = global_const->GetHandledIndexString(); + JSTaggedValue position_tag = FastRuntimeStub::FastGetPropertyByValue(thread, result_values, result_index); + JSHandle position_handle(thread, position_tag); uint32_t position = 0; - if (positionHandle->IsInt()) { - position = static_cast(positionHandle->GetInt()); + if (position_handle->IsInt()) { + position = static_cast(position_handle->GetInt()); } else { - position = JSTaggedValue::ToUint32(thread, positionHandle); + position = JSTaggedValue::ToUint32(thread, position_handle); // h. ReturnIfAbrupt(position). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -928,117 +930,117 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // j. Let n be 1. uint32_t index = 1; // k. Let captures be an empty List. - JSHandle capturesList = factory->NewTaggedArray(ncaptures); + JSHandle captures_list = factory->NewTaggedArray(ncaptures); // l. Repeat while n ≤ nCaptures while (index <= ncaptures) { // i. Let capN be Get(result, ToString(n)). - capN.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultValues.GetTaggedValue(), index)); + cap_n.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, result_values.GetTaggedValue(), index)); // ii. ReturnIfAbrupt(capN). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iii. If capN is not undefined, then - if (!capN->IsUndefined()) { + if (!cap_n->IsUndefined()) { // 1. Let capN be ToString(capN). - JSHandle capNStr = JSTaggedValue::ToString(thread, capN); + JSHandle cap_n_str = JSTaggedValue::ToString(thread, cap_n); // 2. ReturnIfAbrupt(capN). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle capnStr = JSHandle::Cast(capNStr); - capturesList->Set(thread, index - 1, capnStr); + JSHandle capn_str = JSHandle::Cast(cap_n_str); + captures_list->Set(thread, index - 1, capn_str); } else { // iv. Append capN as the last element of captures. - capturesList->Set(thread, index - 1, capN); + captures_list->Set(thread, index - 1, cap_n); } // v. Let n be n+1 ++index; } // j. Let namedCaptures be ? Get(result, "groups"). - JSHandle groupsKey = globalConst->GetHandledGroupsString(); - JSTaggedValue named = FastRuntimeStub::FastGetPropertyByValue(thread, resultValues, groupsKey); - JSHandle namedCaptures(thread, named); + JSHandle groups_key = global_const->GetHandledGroupsString(); + JSTaggedValue named = FastRuntimeStub::FastGetPropertyByValue(thread, result_values, groups_key); + JSHandle named_captures(thread, named); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // m. If functionalReplace is true, then PandaString replacement; - int emptyArrLength = 0; - if (namedCaptures->IsUndefined()) { - emptyArrLength = 3; // 3: «matched, pos, and string» + int empty_arr_length = 0; + if (named_captures->IsUndefined()) { + empty_arr_length = 3; // 3: «matched, pos, and string» } else { - emptyArrLength = 4; // 4: «matched, pos, string, and groups» + empty_arr_length = 4; // 4: «matched, pos, string, and groups» } - JSHandle replacerArgs = factory->NewTaggedArray(emptyArrLength + capturesList->GetLength()); - if (functionalReplace) { + JSHandle replacer_args = factory->NewTaggedArray(empty_arr_length + captures_list->GetLength()); + if (functional_replace) { // i. Let replacerArgs be «matched». - replacerArgs->Set(thread, 0, getMatchString.GetTaggedValue()); + replacer_args->Set(thread, 0, get_match_string.GetTaggedValue()); // ii. Append in list order the elements of captures to the end of the List replacerArgs. // iii. Append position and S as the last two elements of replacerArgs. index = 0; - while (index < capturesList->GetLength()) { - replacerArgs->Set(thread, index + 1, capturesList->Get(index)); + while (index < captures_list->GetLength()) { + replacer_args->Set(thread, index + 1, captures_list->Get(index)); ++index; } - replacerArgs->Set(thread, index + 1, JSTaggedValue(position)); - replacerArgs->Set(thread, index + 2, inputStr.GetTaggedValue()); // 2: position of string - if (!namedCaptures->IsUndefined()) { - replacerArgs->Set(thread, index + 3, namedCaptures.GetTaggedValue()); // 3: position of groups + replacer_args->Set(thread, index + 1, JSTaggedValue(position)); + replacer_args->Set(thread, index + 2, input_str.GetTaggedValue()); // 2: position of string + if (!named_captures->IsUndefined()) { + replacer_args->Set(thread, index + 3, named_captures.GetTaggedValue()); // 3: position of groups } // iv. Let replValue be Call(replaceValue, undefined, replacerArgs). - const int32_t argsLength = replacerArgs->GetLength(); - auto info = NewRuntimeCallInfo(thread, inputReplaceValue, JSTaggedValue::Undefined(), - JSTaggedValue::Undefined(), argsLength); + const int32_t args_length = replacer_args->GetLength(); + auto info = NewRuntimeCallInfo(thread, input_replace_value, JSTaggedValue::Undefined(), + JSTaggedValue::Undefined(), args_length); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info->SetCallArg(argsLength, replacerArgs->GetData()); - JSTaggedValue replaceResult = JSFunction::Call(info.get()); - JSHandle replValue(thread, replaceResult); + info->SetCallArg(args_length, replacer_args->GetData()); + JSTaggedValue replace_result = JSFunction::Call(info.Get()); + JSHandle repl_value(thread, replace_result); // v. Let replacement be ToString(replValue). - JSHandle replacementString = JSTaggedValue::ToString(thread, replValue); + JSHandle replacement_string = JSTaggedValue::ToString(thread, repl_value); // o. ReturnIfAbrupt(replacement). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - replacement = ConvertToPandaString(*replacementString, StringConvertedUsage::LOGICOPERATION); + replacement = ConvertToPandaString(*replacement_string, StringConvertedUsage::LOGICOPERATION); } else { // n. Else, - if (!namedCaptures->IsUndefined()) { - JSHandle namedCapturesObj = JSTaggedValue::ToObject(thread, namedCaptures); + if (!named_captures->IsUndefined()) { + JSHandle named_captures_obj = JSTaggedValue::ToObject(thread, named_captures); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - namedCaptures = JSHandle::Cast(namedCapturesObj); + named_captures = JSHandle::Cast(named_captures_obj); } - JSHandle replacementHandle( - thread, BuiltinsString::GetSubstitution(thread, matchString, srPandaString, position, capturesList, - namedCaptures, replaceValueHandle)); - replacement = ConvertToPandaString(EcmaString::Cast(replacementHandle->GetTaggedObject()), + JSHandle replacement_handle( + thread, BuiltinsString::GetSubstitution(thread, match_string, sr_panda_string, position, captures_list, + named_captures, replace_value_handle)); + replacement = ConvertToPandaString(EcmaString::Cast(replacement_handle->GetTaggedObject()), StringConvertedUsage::LOGICOPERATION); } // p. If position ≥ nextSourcePosition, then - if (position >= nextSourcePosition) { + if (position >= next_source_position) { // ii. Let accumulatedResult be the String formed by concatenating the code units of the current value // of accumulatedResult with the substring of S consisting of the code units from nextSourcePosition // (inclusive) up to position (exclusive) and with the code units of replacement. - accumulatedResult += base::StringHelper::SubString(JSHandle::Cast(inputStr), nextSourcePosition, - (position - nextSourcePosition)); - accumulatedResult += replacement; + accumulated_result += base::StringHelper::SubString( + JSHandle::Cast(input_str), next_source_position, (position - next_source_position)); + accumulated_result += replacement; // iii. Let nextSourcePosition be position + matchLength. - nextSourcePosition = position + matchLength; + next_source_position = position + match_length; } } // 17. If nextSourcePosition ≥ lengthS, return accumulatedResult. - if (nextSourcePosition >= length) { - JSHandle resultValue = factory->NewFromStdString(accumulatedResult); - if (useCache) { + if (next_source_position >= length) { + JSHandle result_value = factory->NewFromStdString(accumulated_result); + if (use_cache) { RegExpExecResultCache::AddResultInCache( - thread, cacheTable, pattern, flagsBits, string, JSHandle(resultValue), - RegExpExecResultCache::REPLACE_TYPE, nextIndexHandle->GetInt(), inputReplaceValue.GetTaggedValue()); + thread, cache_table, pattern, flags_bits, string, JSHandle(result_value), + RegExpExecResultCache::REPLACE_TYPE, next_index_handle->GetInt(), input_replace_value.GetTaggedValue()); } - return resultValue.GetTaggedValue(); + return result_value.GetTaggedValue(); } // 18. Return the String formed by concatenating the code units of accumulatedResult with the substring of S // consisting of the code units from nextSourcePosition (inclusive) up through the final code unit of S(inclusive). - accumulatedResult += base::StringHelper::SubString(JSHandle::Cast(inputStr), nextSourcePosition, - (length - nextSourcePosition)); - JSHandle resultValue = factory->NewFromStdString(accumulatedResult); - if (useCache) { + accumulated_result += base::StringHelper::SubString(JSHandle::Cast(input_str), next_source_position, + (length - next_source_position)); + JSHandle result_value = factory->NewFromStdString(accumulated_result); + if (use_cache) { RegExpExecResultCache::AddResultInCache( - thread, cacheTable, pattern, flagsBits, string, JSHandle(resultValue), - RegExpExecResultCache::REPLACE_TYPE, nextIndexHandle->GetInt(), inputReplaceValue.GetTaggedValue()); + thread, cache_table, pattern, flags_bits, string, JSHandle(result_value), + RegExpExecResultCache::REPLACE_TYPE, next_index_handle->GetInt(), input_replace_value.GetTaggedValue()); } - return resultValue.GetTaggedValue(); + return result_value.GetTaggedValue(); } // 21.2.5.9 @@ -1047,40 +1049,40 @@ JSTaggedValue BuiltinsRegExp::Search(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Search); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let rx be the this value. - JSHandle thisObj = GetThis(argv); + JSHandle this_obj = GetThis(argv); // 3. Let S be ToString(string). - JSHandle inputStr = GetCallArg(argv, 0); - JSHandle stringHandle = JSTaggedValue::ToString(thread, inputStr); + JSHandle input_str = GetCallArg(argv, 0); + JSHandle string_handle = JSTaggedValue::ToString(thread, input_str); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle string = JSHandle::Cast(stringHandle); - if (!thisObj->IsECMAObject()) { + JSHandle string = JSHandle::Cast(string_handle); + 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()); } // 4. Let previousLastIndex be ? Get(rx, "lastIndex"). - JSHandle lastIndexString(thread->GlobalConstants()->GetHandledLastIndexString()); - JSHandle previousLastIndex = JSObject::GetProperty(thread, thisObj, lastIndexString).GetValue(); + JSHandle last_index_string(thread->GlobalConstants()->GetHandledLastIndexString()); + JSHandle previous_last_index = JSObject::GetProperty(thread, this_obj, last_index_string).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If SameValue(previousLastIndex, 0) is false, then // Perform ? Set(rx, "lastIndex", 0, true). - if (!JSTaggedValue::SameValue(previousLastIndex.GetTaggedValue(), JSTaggedValue(0))) { + if (!JSTaggedValue::SameValue(previous_last_index.GetTaggedValue(), JSTaggedValue(0))) { JSHandle value(thread, JSTaggedValue(0)); - JSObject::SetProperty(thread, thisObj, lastIndexString, value, true); + JSObject::SetProperty(thread, this_obj, last_index_string, value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 6. Let result be ? RegExpExec(rx, S). - JSHandle result(thread, RegExpExec(thread, thisObj, string, false)); + JSHandle result(thread, RegExpExec(thread, this_obj, string, false)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let currentLastIndex be ? Get(rx, "lastIndex"). - JSHandle currentLastIndex = JSObject::GetProperty(thread, thisObj, lastIndexString).GetValue(); + JSHandle current_last_index = JSObject::GetProperty(thread, this_obj, last_index_string).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. If SameValue(currentLastIndex, previousLastIndex) is false, then // Perform ? Set(rx, "lastIndex", previousLastIndex, true). - if (!JSTaggedValue::SameValue(previousLastIndex.GetTaggedValue(), currentLastIndex.GetTaggedValue())) { - JSObject::SetProperty(thread, thisObj, lastIndexString, previousLastIndex, true); + if (!JSTaggedValue::SameValue(previous_last_index.GetTaggedValue(), current_last_index.GetTaggedValue())) { + JSObject::SetProperty(thread, this_obj, last_index_string, previous_last_index, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 9. If result is null, return -1. @@ -1099,56 +1101,56 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), RegExp, Split); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - bool useCache = false; + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + bool use_cache = false; // 1. Let rx be the this value. - JSHandle thisObj = GetThis(argv); - auto ecmaVm = thread->GetEcmaVM(); + JSHandle this_obj = GetThis(argv); + auto ecma_vm = thread->GetEcmaVM(); // 3. Let S be ToString(string). - JSHandle inputString = GetCallArg(argv, 0); + JSHandle input_string = GetCallArg(argv, 0); JSHandle limit = GetCallArg(argv, 1); - JSHandle stringHandle = JSTaggedValue::ToString(thread, inputString); + JSHandle string_handle = JSTaggedValue::ToString(thread, input_string); // 4. ReturnIfAbrupt(string). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle jsString = JSHandle::Cast(stringHandle); - if (!thisObj->IsECMAObject()) { + JSHandle js_string = JSHandle::Cast(string_handle); + 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()); } // 5. Let C be SpeciesConstructor(rx, %RegExp%). - JSHandle defaultConstructor = ecmaVm->GetGlobalEnv()->GetRegExpFunction(); - JSHandle objHandle(thisObj); - JSHandle constructor = JSObject::SpeciesConstructor(thread, objHandle, defaultConstructor); + JSHandle default_constructor = ecma_vm->GetGlobalEnv()->GetRegExpFunction(); + JSHandle obj_handle(this_obj); + JSHandle constructor = JSObject::SpeciesConstructor(thread, obj_handle, default_constructor); // 6. ReturnIfAbrupt(C). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let flags be ToString(Get(rx, "flags")). - ObjectFactory *factory = ecmaVm->GetFactory(); - const GlobalEnvConstants *globalConstants = thread->GlobalConstants(); - JSHandle flagsString(globalConstants->GetHandledFlagsString()); - JSHandle taggedFlags = JSObject::GetProperty(thread, thisObj, flagsString).GetValue(); + ObjectFactory *factory = ecma_vm->GetFactory(); + const GlobalEnvConstants *global_constants = thread->GlobalConstants(); + JSHandle flags_string(global_constants->GetHandledFlagsString()); + JSHandle tagged_flags = JSObject::GetProperty(thread, this_obj, flags_string).GetValue(); JSHandle flags; - if (taggedFlags->IsUndefined()) { + if (tagged_flags->IsUndefined()) { flags = factory->GetEmptyString(); } else { - flags = JSTaggedValue::ToString(thread, taggedFlags); + flags = JSTaggedValue::ToString(thread, tagged_flags); } // 8. ReturnIfAbrupt(flags). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If flags contains "u", let unicodeMatching be true. // 10. Else, let unicodeMatching be false. - JSHandle uStringHandle(globalConstants->GetHandledUString()); - bool unicodeMatching = base::StringHelper::Contains(*flags, *uStringHandle); + JSHandle u_string_handle(global_constants->GetHandledUString()); + bool unicode_matching = base::StringHelper::Contains(*flags, *u_string_handle); // 11. If flags contains "y", let newFlags be flags. - JSHandle newFlagsHandle; - JSHandle yStringHandle = JSHandle::Cast(globalConstants->GetHandledYString()); - if (base::StringHelper::Contains(*flags, *yStringHandle)) { - newFlagsHandle = flags; + JSHandle new_flags_handle; + JSHandle y_string_handle = JSHandle::Cast(global_constants->GetHandledYString()); + if (base::StringHelper::Contains(*flags, *y_string_handle)) { + new_flags_handle = flags; } else { // 12. Else, let newFlags be the string that is the concatenation of flags and "y". - JSHandle yStr = JSHandle::Cast(globalConstants->GetHandledYString()); - newFlagsHandle = factory->ConcatFromString(flags, yStr); + JSHandle y_str = JSHandle::Cast(global_constants->GetHandledYString()); + new_flags_handle = factory->ConcatFromString(flags, y_str); } // 17. If limit is undefined, let lim be 2^32–1; else let lim be ToUint32(limit). @@ -1162,45 +1164,45 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) } if (lim == MAX_SPLIT_LIMIT) { - useCache = ExecCachingAllowed(thread, thisObj); + use_cache = ExecCachingAllowed(thread, this_obj); } - JSHandle regexpHandle(thisObj); + JSHandle regexp_handle(this_obj); JSMutableHandle pattern(thread, JSTaggedValue::Undefined()); - JSMutableHandle flagsBits(thread, JSTaggedValue::Undefined()); - if (thisObj->IsJSRegExp()) { - pattern.Update(regexpHandle->GetOriginalSource()); - flagsBits.Update(regexpHandle->GetOriginalFlags()); - } - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - if (useCache) { - JSTaggedValue cacheResult = cacheTable->FindCachedResult(thread, pattern, flagsBits, inputString, - RegExpExecResultCache::SPLIT_TYPE, thisObj); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + JSMutableHandle flags_bits(thread, JSTaggedValue::Undefined()); + if (this_obj->IsJSRegExp()) { + pattern.Update(regexp_handle->GetOriginalSource()); + flags_bits.Update(regexp_handle->GetOriginalFlags()); + } + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + if (use_cache) { + JSTaggedValue cache_result = cache_table->FindCachedResult(thread, pattern, flags_bits, input_string, + RegExpExecResultCache::SPLIT_TYPE, this_obj); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } // 13. Let splitter be Construct(C, «rx, newFlags»). - JSHandle globalObject(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); - JSHandle undefined = globalConstants->GetHandledUndefined(); + JSHandle global_object(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); + JSHandle undefined = global_constants->GetHandledUndefined(); auto info = NewRuntimeCallInfo(thread, constructor, JSTaggedValue::Undefined(), undefined, 2); - info->SetCallArgs(thisObj.GetTaggedValue(), newFlagsHandle.GetTaggedValue()); - JSTaggedValue taggedSplitter = JSFunction::Construct(info.get()); + info->SetCallArgs(this_obj.GetTaggedValue(), new_flags_handle.GetTaggedValue()); + JSTaggedValue tagged_splitter = JSFunction::Construct(info.Get()); // 14. ReturnIfAbrupt(splitter). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle splitter(thread, taggedSplitter); + JSHandle splitter(thread, tagged_splitter); // 15. Let A be ArrayCreate(0). JSHandle array(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); // 16. Let lengthA be 0. - uint32_t aLength = 0; + uint32_t a_length = 0; // 19. Let size be the number of elements in S. - uint32_t size = static_cast(jsString->GetTaggedObject())->GetLength(); + uint32_t size = static_cast(js_string->GetTaggedObject())->GetLength(); // 20. Let p be 0. - uint32_t startIndex = 0; + uint32_t start_index = 0; // 21. If lim = 0, return A. if (lim == 0) { return JSTaggedValue(static_cast(array.GetTaggedValue().GetTaggedObject())); @@ -1208,122 +1210,122 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) // 22. If size = 0, then if (size == 0) { // a. Let z be RegExpExec(splitter, S). - JSHandle execResult(thread, RegExpExec(thread, splitter, jsString, useCache)); + JSHandle exec_result(thread, RegExpExec(thread, splitter, js_string, use_cache)); // b. ReturnIfAbrupt(z). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. If z is not null, return A. - if (!execResult->IsNull()) { + if (!exec_result->IsNull()) { return JSTaggedValue(static_cast(array.GetTaggedValue().GetTaggedObject())); } // d. Assert: The following call will never result in an abrupt completion. // e. Perform CreateDataProperty(A, "0", S). - JSObject::CreateDataProperty(thread, array, 0, jsString); + JSObject::CreateDataProperty(thread, array, 0, js_string); // f. Return A. return JSTaggedValue(static_cast(array.GetTaggedValue().GetTaggedObject())); } // 23. Let q be p. - uint32_t endIndex = startIndex; - JSMutableHandle lastIndexvalue(thread, JSTaggedValue(endIndex)); + uint32_t end_index = start_index; + JSMutableHandle last_indexvalue(thread, JSTaggedValue(end_index)); // 24. Repeat, while q < size - JSHandle lastIndexString = globalConstants->GetHandledLastIndexString(); - while (endIndex < size) { + JSHandle last_index_string = global_constants->GetHandledLastIndexString(); + while (end_index < size) { // a. Let setStatus be Set(splitter, "lastIndex", q, true). - lastIndexvalue.Update(JSTaggedValue(endIndex)); - JSObject::SetProperty(thread, splitter, lastIndexString, lastIndexvalue, true); + last_indexvalue.Update(JSTaggedValue(end_index)); + JSObject::SetProperty(thread, splitter, last_index_string, last_indexvalue, true); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle execResult(thread, RegExpExec(thread, splitter, jsString, useCache)); + JSHandle exec_result(thread, RegExpExec(thread, splitter, js_string, use_cache)); // d. ReturnIfAbrupt(z). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // e. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). - if (execResult->IsNull()) { - endIndex = AdvanceStringIndex(jsString, endIndex, unicodeMatching); + if (exec_result->IsNull()) { + end_index = AdvanceStringIndex(js_string, end_index, unicode_matching); } else { // f. Else z is not null, // i. Let e be ToLength(Get(splitter, "lastIndex")). - JSHandle lastIndexHandle = - JSObject::GetProperty(thread, splitter, lastIndexString).GetValue(); - JSTaggedNumber lastIndexNumber = JSTaggedValue::ToLength(thread, lastIndexHandle); + JSHandle last_index_handle = + JSObject::GetProperty(thread, splitter, last_index_string).GetValue(); + JSTaggedNumber last_index_number = JSTaggedValue::ToLength(thread, last_index_handle); // ii. ReturnIfAbrupt(e). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t lastIndex = lastIndexNumber.GetNumber(); + uint32_t last_index = last_index_number.GetNumber(); // iii. If e = p, let q be AdvanceStringIndex(S, q, unicodeMatching). - if (lastIndex == startIndex) { - endIndex = AdvanceStringIndex(jsString, endIndex, unicodeMatching); + if (last_index == start_index) { + end_index = AdvanceStringIndex(js_string, end_index, unicode_matching); } else { // iv. Else e != p, // 1. Let T be a String value equal to the substring of S consisting of the elements at indices p // (inclusive) through q (exclusive). - std::string stdStrT = base::StringHelper::SubString(JSHandle::Cast(jsString), startIndex, - (endIndex - startIndex)); + std::string std_str_t = base::StringHelper::SubString(JSHandle::Cast(js_string), + start_index, (end_index - start_index)); // 2. Assert: The following call will never result in an abrupt completion. // 3. Perform CreateDataProperty(A, ToString(lengthA), T). - JSHandle tValue(factory->NewFromStdString(stdStrT)); - JSObject::CreateDataProperty(thread, array, aLength, tValue); + JSHandle t_value(factory->NewFromStdString(std_str_t)); + JSObject::CreateDataProperty(thread, array, a_length, t_value); // 4. Let lengthA be lengthA +1. - ++aLength; + ++a_length; // 5. If lengthA = lim, return A. - if (aLength == lim) { - if (useCache) { - RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flagsBits, inputString, + if (a_length == lim) { + if (use_cache) { + RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags_bits, input_string, JSHandle(array), - RegExpExecResultCache::SPLIT_TYPE, lastIndex); + RegExpExecResultCache::SPLIT_TYPE, last_index); } return array.GetTaggedValue(); } // 6. Let p be e. - startIndex = lastIndex; + start_index = last_index; // 7. Let numberOfCaptures be ToLength(Get(z, "length")). - JSHandle lengthString(thread->GlobalConstants()->GetHandledLengthString()); - JSHandle capturesHandle = - JSObject::GetProperty(thread, execResult, lengthString).GetValue(); - JSTaggedNumber numberOfCapturesNumber = JSTaggedValue::ToLength(thread, capturesHandle); + JSHandle length_string(thread->GlobalConstants()->GetHandledLengthString()); + JSHandle captures_handle = + JSObject::GetProperty(thread, exec_result, length_string).GetValue(); + JSTaggedNumber number_of_captures_number = JSTaggedValue::ToLength(thread, captures_handle); // 8. ReturnIfAbrupt(numberOfCaptures). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t numberOfCaptures = numberOfCapturesNumber.GetNumber(); + uint32_t number_of_captures = number_of_captures_number.GetNumber(); // 9. Let numberOfCaptures be max(numberOfCaptures-1, 0). - numberOfCaptures = (numberOfCaptures == 0) ? 0 : numberOfCaptures - 1; + number_of_captures = (number_of_captures == 0) ? 0 : number_of_captures - 1; // 10. Let i be 1. uint32_t i = 1; // 11. Repeat, while i ≤ numberOfCaptures. - while (i <= numberOfCaptures) { + while (i <= number_of_captures) { // a. Let nextCapture be Get(z, ToString(i)). - JSHandle nextCapture = JSObject::GetProperty(thread, execResult, i).GetValue(); + JSHandle next_capture = JSObject::GetProperty(thread, exec_result, i).GetValue(); // b. ReturnIfAbrupt(nextCapture). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Perform CreateDataProperty(A, ToString(lengthA), nextCapture). - JSObject::CreateDataProperty(thread, array, aLength, nextCapture); + JSObject::CreateDataProperty(thread, array, a_length, next_capture); // d. Let i be i + 1. ++i; // e. Let lengthA be lengthA +1. - ++aLength; + ++a_length; // f. If lengthA = lim, return A. - if (aLength == lim) { - if (useCache) { - RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flagsBits, inputString, - JSHandle(array), - RegExpExecResultCache::SPLIT_TYPE, lastIndex); + if (a_length == lim) { + if (use_cache) { + RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags_bits, + input_string, JSHandle(array), + RegExpExecResultCache::SPLIT_TYPE, last_index); } return array.GetTaggedValue(); } } // 12. Let q be p. - endIndex = startIndex; + end_index = start_index; } } } // 25. Let T be a String value equal to the substring of S consisting of the elements at indices p (inclusive) // through size (exclusive). - std::string stdStrT = - base::StringHelper::SubString(JSHandle::Cast(jsString), startIndex, (size - startIndex)); + std::string std_str_t = + base::StringHelper::SubString(JSHandle::Cast(js_string), start_index, (size - start_index)); // 26. Assert: The following call will never result in an abrupt completion. // 27. Perform CreateDataProperty(A, ToString(lengthA), t). - JSHandle tValue(factory->NewFromStdString(stdStrT)); - JSObject::CreateDataProperty(thread, array, aLength, tValue); + JSHandle t_value(factory->NewFromStdString(std_str_t)); + JSObject::CreateDataProperty(thread, array, a_length, t_value); if (lim == MAX_SPLIT_LIMIT) { - RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flagsBits, inputString, + RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags_bits, input_string, JSHandle(array), RegExpExecResultCache::SPLIT_TYPE, - endIndex); + end_index); } // 28. Return A. return array.GetTaggedValue(); @@ -1331,27 +1333,27 @@ 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 lastIndex, - bool isUtf16) + const uint8_t *buffer, size_t length, int32_t last_index, + bool is_utf16) { // get bytecode - JSTaggedValue bufferData = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); - void *dynBuf = JSNativePointer::Cast(bufferData.GetTaggedObject())->GetExternalPointer(); - auto bytecodeBuffer = reinterpret_cast(dynBuf); + JSTaggedValue buffer_data = JSRegExp::Cast(regexp->GetTaggedObject())->GetByteCodeBuffer(); + void *dyn_buf = JSNativePointer::Cast(buffer_data.GetTaggedObject())->GetExternalPointer(); + auto bytecode_buffer = reinterpret_cast(dyn_buf); // execute RegExpExecutor executor {}; - if (lastIndex < 0) { - lastIndex = 0; + if (last_index < 0) { + last_index = 0; } - bool ret = executor.Execute(buffer, lastIndex, static_cast(length), bytecodeBuffer, isUtf16); + bool ret = executor.Execute(buffer, last_index, static_cast(length), bytecode_buffer, is_utf16); RegExpExecutor::MatchResult result = executor.GetResult(thread, ret); return result; } -uint32_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &inputStr, uint32_t index, bool unicode) +uint32_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &input_str, uint32_t index, bool unicode) { // 1. Assert: Type(S) is String. - ASSERT(inputStr->IsString()); + ASSERT(input_str->IsString()); // 2. Assert: index is an integer such that 0≤index≤2^53 - 1 ASSERT(index <= pow(2, 53) - 1); // 3. Assert: Type(unicode) is Boolean. @@ -1360,19 +1362,19 @@ uint32_t BuiltinsRegExp::AdvanceStringIndex(const JSHandle &input return index + 1; } // 5. Let length be the number of code units in S. - uint32_t length = static_cast(inputStr->GetTaggedObject())->GetLength(); + uint32_t length = static_cast(input_str->GetTaggedObject())->GetLength(); // 6. If index+1 ≥ length, return index+1. if (index + 1 >= length) { return index + 1; } // 7. Let first be the code unit value at index index in S. - uint16_t first = static_cast(inputStr->GetTaggedObject())->At(index); + uint16_t first = static_cast(input_str->GetTaggedObject())->At(index); // 8. If first < 0xD800 or first > 0xDFFF, return index+1. if (first < 0xD800 || first > 0xDFFF) { // NOLINT(readability-magic-numbers) return index + 1; } // 9. Let second be the code unit value at index index+1 in S. - uint16_t second = static_cast(inputStr->GetTaggedObject())->At(index + 1); + uint16_t second = static_cast(input_str->GetTaggedObject())->At(index + 1); // 10. If second < 0xDC00 or second > 0xDFFF, return index+1. if (second < 0xDC00 || second > 0xDFFF) { // NOLINT(readability-magic-numbers) return index + 1; @@ -1390,144 +1392,144 @@ bool BuiltinsRegExp::GetFlagsInternal(JSThread *thread, const JSHandle patternObj = JSHandle::Cast(obj); - if (!patternObj->IsJSRegExp()) { + JSHandle pattern_obj = JSHandle::Cast(obj); + if (!pattern_obj->IsJSRegExp()) { // throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "this does not have [[OriginalFlags]]", false); } // 4. Let flags be the value of R’s [[OriginalFlags]] internal slot. - JSHandle regexpObj(thread, JSRegExp::Cast(obj->GetTaggedObject())); + JSHandle regexp_obj(thread, JSRegExp::Cast(obj->GetTaggedObject())); // 5. If flags contains the code unit "[flag]", return true. // 6. Return false. - uint8_t flags = static_cast(regexpObj->GetOriginalFlags().GetInt()); + uint8_t flags = static_cast(regexp_obj->GetOriginalFlags().GetInt()); return (flags & mask) != 0; } // 21.2.5.2.2 JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &inputStr, bool useCache) + const JSHandle &input_str, bool use_cache) { ASSERT(JSObject::IsRegExp(thread, regexp)); - ASSERT(inputStr->IsString()); + ASSERT(input_str->IsString()); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle lastIndexHandle = globalConst->GetHandledLastIndexString(); - JSTaggedValue result = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, lastIndexHandle); - int32_t lastIndex = 0; + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + JSHandle last_index_handle = global_const->GetHandledLastIndexString(); + JSTaggedValue result = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, last_index_handle); + int32_t last_index = 0; if (result.IsInt()) { - lastIndex = result.GetInt(); + last_index = result.GetInt(); } else { - JSHandle lastIndexResult(thread, result); - JSTaggedNumber lastIndexNumber = JSTaggedValue::ToLength(thread, lastIndexResult); + JSHandle last_index_result(thread, result); + JSTaggedNumber last_index_number = JSTaggedValue::ToLength(thread, last_index_result); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - lastIndex = lastIndexNumber.GetNumber(); + last_index = last_index_number.GetNumber(); } - JSHandle globalHandle = globalConst->GetHandledGlobalString(); - bool global = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, globalHandle).ToBoolean(); + JSHandle global_handle = global_const->GetHandledGlobalString(); + bool global = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, global_handle).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle stickyHandle = globalConst->GetHandledStickyString(); - bool sticky = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, stickyHandle).ToBoolean(); + JSHandle sticky_handle = global_const->GetHandledStickyString(); + bool sticky = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, sticky_handle).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!global && !sticky) { - lastIndex = 0; + last_index = 0; } - JSHandle regexpObj(regexp); - JSMutableHandle pattern(thread, regexpObj->GetOriginalSource()); - JSMutableHandle flags(thread, regexpObj->GetOriginalFlags()); + JSHandle regexp_obj(regexp); + JSMutableHandle pattern(thread, regexp_obj->GetOriginalSource()); + JSMutableHandle flags(thread, regexp_obj->GetOriginalFlags()); - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - uint32_t length = static_cast(inputStr->GetTaggedObject())->GetLength(); - if (lastIndex > static_cast(length)) { - FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + uint32_t length = static_cast(input_str->GetTaggedObject())->GetLength(); + if (last_index > static_cast(length)) { + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, last_index_handle, thread->GlobalConstants()->GetHandledZero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return JSTaggedValue::Null(); } - JSHandle inputString = JSTaggedValue::ToString(thread, inputStr); - bool isUtf16 = inputString->IsUtf16(); - const uint8_t *strBuffer; - size_t stringLength = inputString->GetLength(); - PandaVector u8Buffer; - PandaVector u16Buffer; - if (isUtf16) { - u16Buffer = PandaVector(stringLength); - inputString->CopyDataUtf16(u16Buffer.data(), stringLength); - strBuffer = reinterpret_cast(u16Buffer.data()); + JSHandle input_string = JSTaggedValue::ToString(thread, input_str); + bool is_utf16 = input_string->IsUtf16(); + const uint8_t *str_buffer; + size_t string_length = input_string->GetLength(); + PandaVector u8_buffer; + PandaVector u16_buffer; + if (is_utf16) { + u16_buffer = PandaVector(string_length); + input_string->CopyDataUtf16(u16_buffer.data(), string_length); + str_buffer = reinterpret_cast(u16_buffer.data()); } else { - u8Buffer = PandaVector(stringLength + 1); - inputString->CopyDataUtf8(u8Buffer.data(), stringLength + 1); - strBuffer = u8Buffer.data(); + u8_buffer = PandaVector(string_length + 1); + input_string->CopyDataUtf8(u8_buffer.data(), string_length + 1); + str_buffer = u8_buffer.data(); } - RegExpExecutor::MatchResult matchResult = Matcher(thread, regexp, strBuffer, stringLength, lastIndex, isUtf16); - if (!matchResult.isSuccess_) { + RegExpExecutor::MatchResult match_result = Matcher(thread, regexp, str_buffer, string_length, last_index, is_utf16); + if (!match_result.is_success) { if (global || sticky) { - JSHandle lastIndexValue(thread, JSTaggedValue(0)); - FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, + JSHandle last_index_value(thread, JSTaggedValue(0)); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, last_index_handle, thread->GlobalConstants()->GetHandledZero()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } return JSTaggedValue::Null(); } - uint32_t endIndex = matchResult.endIndex_; + uint32_t end_index = match_result.end_index; if (global || sticky) { // a. Let setStatus be Set(R, "lastIndex", e, true). - JSTaggedValue endIndexVal(endIndex); - FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, HandleFromLocal(&endIndexVal)); + JSTaggedValue end_index_val(end_index); + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, last_index_handle, HandleFromLocal(&end_index_val)); // b. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - uint32_t capturesSize = matchResult.captures_.size(); - JSHandle results(JSArray::ArrayCreate(thread, JSTaggedNumber(capturesSize))); - uint32_t matchIndex = matchResult.index_; + uint32_t captures_size = match_result.captures.size(); + JSHandle results(JSArray::ArrayCreate(thread, JSTaggedNumber(captures_size))); + uint32_t match_index = match_result.index; // 24. Perform CreateDataProperty(A, "index", matchIndex). - JSHandle indexKey = globalConst->GetHandledIndexString(); - JSHandle indexValue(thread, JSTaggedValue(matchIndex)); - JSObject::CreateDataProperty(thread, results, indexKey, indexValue); + JSHandle index_key = global_const->GetHandledIndexString(); + JSHandle index_value(thread, JSTaggedValue(match_index)); + JSObject::CreateDataProperty(thread, results, index_key, index_value); // 25. Perform CreateDataProperty(A, "input", S). - JSHandle inputKey = globalConst->GetHandledInputString(); + JSHandle input_key = global_const->GetHandledInputString(); - JSHandle inputValue(thread, static_cast(inputStr->GetTaggedObject())); - JSObject::CreateDataProperty(thread, results, inputKey, inputValue); + JSHandle input_value(thread, static_cast(input_str->GetTaggedObject())); + JSObject::CreateDataProperty(thread, results, input_key, input_value); // 27. Perform CreateDataProperty(A, "0", matched_substr). - JSHandle zeroValue(matchResult.captures_[0].second); - JSObject::CreateDataProperty(thread, results, 0, zeroValue); + JSHandle zero_value(match_result.captures[0].second); + JSObject::CreateDataProperty(thread, results, 0, zero_value); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle groupName(thread, regexpObj->GetGroupName()); + JSHandle group_name(thread, regexp_obj->GetGroupName()); JSMutableHandle groups(thread, JSTaggedValue::Undefined()); - if (!groupName->IsUndefined()) { - JSHandle nullHandle(thread, JSTaggedValue::Null()); - JSHandle nullObj = factory->OrdinaryNewJSObjectCreate(nullHandle); - groups.Update(nullObj.GetTaggedValue()); + if (!group_name->IsUndefined()) { + JSHandle null_handle(thread, JSTaggedValue::Null()); + JSHandle null_obj = factory->OrdinaryNewJSObjectCreate(null_handle); + groups.Update(null_obj.GetTaggedValue()); } - JSHandle groupsKey = globalConst->GetHandledGroupsString(); - JSObject::CreateDataProperty(thread, results, groupsKey, groups); + JSHandle groups_key = global_const->GetHandledGroupsString(); + JSObject::CreateDataProperty(thread, results, groups_key, groups); // 28. For each integer i such that i > 0 and i <= n - for (uint32_t i = 1; i < capturesSize; i++) { + for (uint32_t i = 1; i < captures_size; i++) { // a. Let capture_i be ith element of r's captures List - JSTaggedValue capturedValue; - if (matchResult.captures_[i].first) { - capturedValue = JSTaggedValue::Undefined(); + JSTaggedValue captured_value; + if (match_result.captures[i].first) { + captured_value = JSTaggedValue::Undefined(); } else { - capturedValue = matchResult.captures_[i].second.GetTaggedValue(); + captured_value = match_result.captures[i].second.GetTaggedValue(); } - JSHandle iValue(thread, capturedValue); - JSObject::CreateDataProperty(thread, results, i, iValue); - if (!groupName->IsUndefined()) { - JSHandle groupObject = JSHandle::Cast(groups); - TaggedArray *groupArray = TaggedArray::Cast(regexpObj->GetGroupName().GetTaggedObject()); - if (groupArray->GetLength() > i - 1) { - JSHandle skey(thread, groupArray->Get(i - 1)); - JSObject::CreateDataProperty(thread, groupObject, skey, iValue); + JSHandle i_value(thread, captured_value); + JSObject::CreateDataProperty(thread, results, i, i_value); + if (!group_name->IsUndefined()) { + JSHandle group_object = JSHandle::Cast(groups); + TaggedArray *group_array = TaggedArray::Cast(regexp_obj->GetGroupName().GetTaggedObject()); + if (group_array->GetLength() > i - 1) { + JSHandle skey(thread, group_array->Get(i - 1)); + JSObject::CreateDataProperty(thread, group_object, skey, i_value); } } } - if (lastIndex == 0 && useCache) { - RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flags, inputStr, + if (last_index == 0 && use_cache) { + RegExpExecResultCache::AddResultInCache(thread, cache_table, pattern, flags, input_str, JSHandle(results), RegExpExecResultCache::EXEC_TYPE, - endIndex); + end_index); } // 29. Return A. return results.GetTaggedValue(); @@ -1535,26 +1537,26 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle // 21.2.5.2.1 JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandle ®exp, - const JSHandle &inputString, bool useCache) + const JSHandle &input_string, bool use_cache) { // 1. Assert: Type(R) is Object. ASSERT(regexp->IsECMAObject()); // 2. Assert: Type(S) is String. - ASSERT(inputString->IsString()); + ASSERT(input_string->IsString()); // 3. Let exec be Get(R, "exec"). - JSHandle inputStr = JSTaggedValue::ToString(thread, inputString); + JSHandle input_str = JSTaggedValue::ToString(thread, input_string); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle execHandle = globalConst->GetHandledExecString(); - JSTaggedValue execVal = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, execHandle); - JSHandle exec(thread, execVal); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); + JSHandle exec_handle = global_const->GetHandledExecString(); + JSTaggedValue exec_val = FastRuntimeStub::FastGetPropertyByValue(thread, regexp, exec_handle); + JSHandle exec(thread, exec_val); // 4. ReturnIfAbrupt(exec). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(exec) is true, then if (exec->IsCallable()) { auto info = NewRuntimeCallInfo(thread, exec, regexp, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(inputStr.GetTaggedValue()); - JSTaggedValue result = JSFunction::Call(info.get()); + info->SetCallArgs(input_str.GetTaggedValue()); + JSTaggedValue result = JSFunction::Call(info.Get()); // b. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!result.IsECMAObject() && !result.IsNull()) { @@ -1569,7 +1571,7 @@ JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); - JSHandle syntaxError = + JSHandle syntax_error = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, "invalid regular expression flags"); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), 0); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), 0); } } - if ((flagsBits & flagsBitsTemp) != 0) { + if ((flags_bits & flags_bits_temp) != 0) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle syntaxError = + JSHandle syntax_error = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, "invalid regular expression flags"); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), 0); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), 0); } - flagsBits |= flagsBitsTemp; + flags_bits |= flags_bits_temp; } - return flagsBits; + return flags_bits; } JSTaggedValue BuiltinsRegExp::FlagsBitsToString(JSThread *thread, uint8_t flags) @@ -1636,36 +1638,36 @@ JSTaggedValue BuiltinsRegExp::FlagsBitsToString(JSThread *thread, uint8_t flags) ASSERT((flags & static_cast(0xC0)) == 0); // 0xC0: first 2 bits of flags must be 0 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) - std::array flagsStr; // 7: maximum 6 flags + '\0' - size_t flagsLen = 0; + std::array flags_str; // 7: maximum 6 flags + '\0' + size_t flags_len = 0; if ((flags & RegExpParser::FLAG_GLOBAL) != 0) { - flagsStr[flagsLen] = 'g'; - flagsLen++; + flags_str[flags_len] = 'g'; + flags_len++; } if ((flags & RegExpParser::FLAG_IGNORECASE) != 0) { - flagsStr[flagsLen] = 'i'; - flagsLen++; + flags_str[flags_len] = 'i'; + flags_len++; } if ((flags & RegExpParser::FLAG_MULTILINE) != 0) { - flagsStr[flagsLen] = 'm'; - flagsLen++; + flags_str[flags_len] = 'm'; + flags_len++; } if ((flags & RegExpParser::FLAG_DOTALL) != 0) { - flagsStr[flagsLen] = 's'; - flagsLen++; + flags_str[flags_len] = 's'; + flags_len++; } if ((flags & RegExpParser::FLAG_UTF16) != 0) { - flagsStr[flagsLen] = 'u'; - flagsLen++; + flags_str[flags_len] = 'u'; + flags_len++; } if ((flags & RegExpParser::FLAG_STICKY) != 0) { - flagsStr[flagsLen] = 'y'; - flagsLen++; + flags_str[flags_len] = 'y'; + flags_len++; } - flagsStr[flagsLen] = '\0'; - JSHandle flagsString = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(flagsStr.data(), flagsLen); + flags_str[flags_len] = '\0'; + JSHandle flags_string = thread->GetEcmaVM()->GetFactory()->NewFromUtf8(flags_str.data(), flags_len); - return flagsString.GetTaggedValue(); + return flags_string.GetTaggedValue(); } // 21.2.3.2.2 @@ -1674,80 +1676,81 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< const JSHandle &flags) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle patternStrHandle; - uint8_t flagsBits = 0; + JSHandle pattern_str_handle; + uint8_t flags_bits = 0; // 1. If pattern is undefined, let P be the empty String. if (pattern->IsUndefined()) { - patternStrHandle = factory->GetEmptyString(); + pattern_str_handle = factory->GetEmptyString(); } else { // 2. Else, let P be ToString(pattern). - patternStrHandle = JSTaggedValue::ToString(thread, pattern); + pattern_str_handle = JSTaggedValue::ToString(thread, pattern); // 3. ReturnIfAbrupt(P). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 4. If flags is undefined, let F be the empty String. if (flags->IsUndefined()) { - flagsBits = 0; + flags_bits = 0; } else if (flags->IsInt()) { - flagsBits = static_cast(flags->GetInt()); + flags_bits = static_cast(flags->GetInt()); } else { // 5. Else, let F be ToString(flags). - JSHandle flagsStrHandle = JSTaggedValue::ToString(thread, flags); + JSHandle flags_str_handle = JSTaggedValue::ToString(thread, flags); // 6. ReturnIfAbrupt(F). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); /** * 7. If F contains any code unit other than "g", "i", "m", "u", or "y" or if it contains the same code * unit more than once, throw a SyntaxError exception. **/ - PandaString checkStr = ConvertToPandaString(*flagsStrHandle, StringConvertedUsage::LOGICOPERATION); - flagsBits = static_cast(UpdateExpressionFlags(thread, checkStr)); + PandaString check_str = ConvertToPandaString(*flags_str_handle, StringConvertedUsage::LOGICOPERATION); + flags_bits = static_cast(UpdateExpressionFlags(thread, check_str)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // String -> PandaString - PandaString patternStdStr = ConvertToPandaString(*patternStrHandle, StringConvertedUsage::LOGICOPERATION); + PandaString pattern_std_str = ConvertToPandaString(*pattern_str_handle, StringConvertedUsage::LOGICOPERATION); // 9. 10. RegExpParser parser = RegExpParser(); - RegExpParserCache *regExpParserCache = thread->GetEcmaVM()->GetRegExpParserCache(); - PandaVector groupName; - auto getCache = regExpParserCache->GetCache(*patternStrHandle, flagsBits, groupName); - if (getCache.first == JSTaggedValue::Hole()) { - parser.Init(const_cast(reinterpret_cast(patternStdStr.c_str())), patternStdStr.size(), - flagsBits); + RegExpParserCache *reg_exp_parser_cache = thread->GetEcmaVM()->GetRegExpParserCache(); + PandaVector group_name; + auto get_cache = reg_exp_parser_cache->GetCache(*pattern_str_handle, flags_bits, group_name); + if (get_cache.first == JSTaggedValue::Hole()) { + parser.Init(const_cast(reinterpret_cast(pattern_std_str.c_str())), pattern_std_str.size(), + flags_bits); parser.Parse(); if (parser.IsError()) { - JSHandle syntaxError = + JSHandle syntax_error = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, parser.GetErrorMsg().c_str()); - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntax_error.GetTaggedValue(), JSTaggedValue::Exception()); } - groupName = parser.GetGroupNames(); + group_name = parser.GetGroupNames(); } JSHandle regexp(thread, JSRegExp::Cast(obj->GetTaggedObject())); // 11. Set the value of obj’s [[OriginalSource]] internal slot to P. - regexp->SetOriginalSource(thread, patternStrHandle.GetTaggedValue()); + regexp->SetOriginalSource(thread, pattern_str_handle.GetTaggedValue()); // 12. Set the value of obj’s [[OriginalFlags]] internal slot to F. - regexp->SetOriginalFlags(thread, JSTaggedValue(flagsBits)); - if (!groupName.empty()) { - JSHandle taggedArray = factory->NewTaggedArray(groupName.size()); - for (size_t i = 0; i < groupName.size(); ++i) { - JSHandle flagsKey(factory->NewFromString(groupName[i])); - taggedArray->Set(thread, i, flagsKey); + regexp->SetOriginalFlags(thread, JSTaggedValue(flags_bits)); + if (!group_name.empty()) { + JSHandle tagged_array = factory->NewTaggedArray(group_name.size()); + for (size_t i = 0; i < group_name.size(); ++i) { + JSHandle flags_key(factory->NewFromString(group_name[i])); + tagged_array->Set(thread, i, flags_key); } - regexp->SetGroupName(thread, taggedArray); + regexp->SetGroupName(thread, tagged_array); } // 13. Set obj’s [[RegExpMatcher]] internal slot. - if (getCache.first == JSTaggedValue::Hole()) { - auto bufferSize = parser.GetOriginBufferSize(); + if (get_cache.first == JSTaggedValue::Hole()) { + auto buffer_size = parser.GetOriginBufferSize(); auto buffer = parser.GetOriginBuffer(); - factory->NewJSRegExpByteCodeData(regexp, buffer, bufferSize); - regExpParserCache->SetCache(*patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(), bufferSize, - std::move(groupName)); + factory->NewJSRegExpByteCodeData(regexp, buffer, buffer_size); + reg_exp_parser_cache->SetCache(*pattern_str_handle, flags_bits, regexp->GetByteCodeBuffer(), buffer_size, + std::move(group_name)); } else { - regexp->SetByteCodeBuffer(thread, getCache.first); - regexp->SetLength(thread, JSTaggedValue(static_cast(getCache.second))); + regexp->SetByteCodeBuffer(thread, get_cache.first); + regexp->SetLength(thread, JSTaggedValue(static_cast(get_cache.second))); } // 14. Let setStatus be Set(obj, "lastIndex", 0, true). - JSHandle lastIndexString = thread->GlobalConstants()->GetHandledLastIndexString(); - FastRuntimeStub::FastSetPropertyByValue(thread, obj, lastIndexString, thread->GlobalConstants()->GetHandledZero()); + JSHandle last_index_string = thread->GlobalConstants()->GetHandledLastIndexString(); + FastRuntimeStub::FastSetPropertyByValue(thread, obj, last_index_string, + thread->GlobalConstants()->GetHandledZero()); // 15. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. Return obj. @@ -1758,8 +1761,8 @@ JSTaggedValue BuiltinsRegExp::RegExpCreate(JSThread *thread, const JSHandle &flags) { BUILTINS_API_TRACE(thread, RegExp, Create); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); JSHandle new_target = env->GetRegExpFunction(); // 1. Let obj be RegExpAlloc(%RegExp%). JSHandle object(thread, RegExpAlloc(thread, new_target)); @@ -1774,20 +1777,20 @@ EcmaString *BuiltinsRegExp::EscapeRegExpPattern(JSThread *thread, const JSHandle const JSHandle &flags) { // String -> PandaString - JSHandle srcStr(thread, static_cast(src->GetTaggedObject())); - JSHandle flagsStr(thread, static_cast(flags->GetTaggedObject())); - PandaString srcStdStr = ConvertToPandaString(*srcStr, StringConvertedUsage::LOGICOPERATION); + JSHandle src_str(thread, static_cast(src->GetTaggedObject())); + JSHandle flags_str(thread, static_cast(flags->GetTaggedObject())); + PandaString src_std_str = ConvertToPandaString(*src_str, StringConvertedUsage::LOGICOPERATION); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // "" -> (?:) - if (srcStdStr.empty()) { - srcStdStr = "(?:)"; + if (src_std_str.empty()) { + src_std_str = "(?:)"; } // "/" -> "\/" - srcStdStr = base::StringHelper::RepalceAll(srcStdStr, "/", "\\/"); + src_std_str = base::StringHelper::RepalceAll(src_std_str, "/", "\\/"); // "\\" -> "\" - srcStdStr = base::StringHelper::RepalceAll(srcStdStr, "\\", "\\"); + src_std_str = base::StringHelper::RepalceAll(src_std_str, "\\", "\\"); - return *factory->NewFromString(srcStdStr); + return *factory->NewFromString(src_std_str); } JSTaggedValue RegExpExecResultCache::CreateCacheTable(JSThread *thread) @@ -1810,9 +1813,9 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, const JS const JSHandle &input, CacheType type, const JSHandle ®exp, JSTaggedValue extend) { - JSTaggedValue patternValue = pattern.GetTaggedValue(); - JSTaggedValue flagsValue = flags.GetTaggedValue(); - JSTaggedValue inputValue = input.GetTaggedValue(); + JSTaggedValue pattern_value = pattern.GetTaggedValue(); + JSTaggedValue flags_value = flags.GetTaggedValue(); + JSTaggedValue input_value = input.GetTaggedValue(); if (!pattern->IsString() || !flags->IsInt() || !input->IsString()) { return JSTaggedValue::Undefined(); @@ -1820,9 +1823,9 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, const JS uint32_t hash = pattern->GetKeyHashCode() + static_cast(flags->GetInt()) + input->GetKeyHashCode(); uint32_t entry = hash & static_cast(GetCacheLength() - 1); - if (!Match(entry, patternValue, flagsValue, inputValue, extend)) { + if (!Match(entry, pattern_value, flags_value, input_value, extend)) { uint32_t entry2 = (entry + 1) & static_cast(GetCacheLength() - 1); - if (!Match(entry2, patternValue, flagsValue, inputValue, extend)) { + if (!Match(entry2, pattern_value, flags_value, input_value, extend)) { return JSTaggedValue::Undefined(); } entry = entry2; @@ -1847,65 +1850,65 @@ JSTaggedValue RegExpExecResultCache::FindCachedResult(JSThread *thread, const JS break; } SetHitCount(thread, GetHitCount() + 1); - JSHandle lastIndexHandle = thread->GlobalConstants()->GetHandledLastIndexString(); - JSTaggedValue lastIndex = Get(index + LAST_INDEX_INDEX); // must be primitive - FastRuntimeStub::FastSetPropertyByValue(thread, regexp, lastIndexHandle, HandleFromLocal(&lastIndex)); + JSHandle last_index_handle = thread->GlobalConstants()->GetHandledLastIndexString(); + JSTaggedValue last_index = Get(index + LAST_INDEX_INDEX); // must be primitive + FastRuntimeStub::FastSetPropertyByValue(thread, regexp, last_index_handle, HandleFromLocal(&last_index)); return result; } void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle cache, const JSHandle &pattern, const JSHandle &flags, const JSHandle &input, - const JSHandle &resultArray, CacheType type, - uint32_t lastIndex, JSTaggedValue extend) + const JSHandle &result_array, CacheType type, + uint32_t last_index, JSTaggedValue extend) { if (!pattern->IsString() || !flags->IsInt() || !input->IsString()) { return; } - JSTaggedValue patternValue = pattern.GetTaggedValue(); - JSTaggedValue flagsValue = flags.GetTaggedValue(); - JSTaggedValue inputValue = input.GetTaggedValue(); - JSTaggedValue lastIndexValue(lastIndex); + JSTaggedValue pattern_value = pattern.GetTaggedValue(); + JSTaggedValue flags_value = flags.GetTaggedValue(); + JSTaggedValue input_value = input.GetTaggedValue(); + JSTaggedValue last_index_value(last_index); uint32_t hash = - patternValue.GetKeyHashCode() + static_cast(flagsValue.GetInt()) + inputValue.GetKeyHashCode(); + pattern_value.GetKeyHashCode() + static_cast(flags_value.GetInt()) + input_value.GetKeyHashCode(); uint32_t entry = hash & static_cast(cache->GetCacheLength() - 1); uint32_t index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; if (cache->Get(index) == JSTaggedValue::Undefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); - cache->SetEntry(thread, entry, patternValue, flagsValue, inputValue, lastIndexValue, extend); - cache->UpdateResultArray(thread, entry, resultArray.GetTaggedValue(), type); - } else if (cache->Match(entry, patternValue, flagsValue, inputValue, extend)) { - cache->UpdateResultArray(thread, entry, resultArray.GetTaggedValue(), type); + cache->SetEntry(thread, entry, pattern_value, flags_value, input_value, last_index_value, extend); + cache->UpdateResultArray(thread, entry, result_array.GetTaggedValue(), type); + } else if (cache->Match(entry, pattern_value, flags_value, input_value, extend)) { + cache->UpdateResultArray(thread, entry, result_array.GetTaggedValue(), type); } else { uint32_t entry2 = (entry + 1) & static_cast(cache->GetCacheLength() - 1); uint32_t index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE; - JSHandle extendHandle(thread, extend); + JSHandle extend_handle(thread, extend); if (cache->GetCacheLength() < DEFAULT_CACHE_NUMBER) { GrowRegexpCache(thread, cache); // update value after gc. - patternValue = pattern.GetTaggedValue(); - flagsValue = flags.GetTaggedValue(); - inputValue = input.GetTaggedValue(); + pattern_value = pattern.GetTaggedValue(); + flags_value = flags.GetTaggedValue(); + input_value = input.GetTaggedValue(); cache->SetCacheLength(thread, DEFAULT_CACHE_NUMBER); entry2 = hash & static_cast(cache->GetCacheLength() - 1); index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE; } - JSTaggedValue extendValue = extendHandle.GetTaggedValue(); + JSTaggedValue extend_value = extend_handle.GetTaggedValue(); if (cache->Get(index2) == JSTaggedValue::Undefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); - cache->SetEntry(thread, entry2, patternValue, flagsValue, inputValue, lastIndexValue, extendValue); - cache->UpdateResultArray(thread, entry2, resultArray.GetTaggedValue(), type); - } else if (cache->Match(entry2, patternValue, flagsValue, inputValue, extendValue)) { - cache->UpdateResultArray(thread, entry2, resultArray.GetTaggedValue(), type); + cache->SetEntry(thread, entry2, pattern_value, flags_value, input_value, last_index_value, extend_value); + cache->UpdateResultArray(thread, entry2, result_array.GetTaggedValue(), type); + } else if (cache->Match(entry2, pattern_value, flags_value, input_value, extend_value)) { + cache->UpdateResultArray(thread, entry2, result_array.GetTaggedValue(), type); } else { cache->SetConflictCount(thread, cache->GetConflictCount() > 1 ? (cache->GetConflictCount() - 1) : 0); cache->SetCacheCount(thread, cache->GetCacheCount() - 1); cache->ClearEntry(thread, entry2); - cache->SetEntry(thread, entry, patternValue, flagsValue, inputValue, lastIndexValue, extendValue); - cache->UpdateResultArray(thread, entry, resultArray.GetTaggedValue(), type); + cache->SetEntry(thread, entry, pattern_value, flags_value, input_value, last_index_value, extend_value); + cache->UpdateResultArray(thread, entry, result_array.GetTaggedValue(), type); } } } @@ -1914,37 +1917,37 @@ void RegExpExecResultCache::GrowRegexpCache(JSThread *thread, JSHandleGetEcmaVM()->GetFactory(); - auto newCache = factory->ExtendArray(JSHandle(cache), length, JSTaggedValue::Undefined()); - thread->GetEcmaVM()->SetRegExpCache(newCache.GetTaggedValue()); + auto new_cache = factory->ExtendArray(JSHandle(cache), length, JSTaggedValue::Undefined()); + thread->GetEcmaVM()->SetRegExpCache(new_cache.GetTaggedValue()); } void RegExpExecResultCache::SetEntry(JSThread *thread, int entry, JSTaggedValue &pattern, JSTaggedValue &flags, - JSTaggedValue &input, JSTaggedValue &lastIndexValue, JSTaggedValue &extendValue) + JSTaggedValue &input, JSTaggedValue &last_index_value, JSTaggedValue &extend_value) { int index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; Set(thread, index + PATTERN_INDEX, pattern); Set(thread, index + FLAG_INDEX, flags); Set(thread, index + INPUT_STRING_INDEX, input); - Set(thread, index + LAST_INDEX_INDEX, lastIndexValue); - Set(thread, index + EXTEND_INDEX, extendValue); + Set(thread, index + LAST_INDEX_INDEX, last_index_value); + Set(thread, index + EXTEND_INDEX, extend_value); } -void RegExpExecResultCache::UpdateResultArray(JSThread *thread, int entry, JSTaggedValue resultArray, CacheType type) +void RegExpExecResultCache::UpdateResultArray(JSThread *thread, int entry, JSTaggedValue result_array, CacheType type) { int index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; switch (type) { break; case REPLACE_TYPE: - Set(thread, index + RESULT_REPLACE_INDEX, resultArray); + Set(thread, index + RESULT_REPLACE_INDEX, result_array); break; case SPLIT_TYPE: - Set(thread, index + RESULT_SPLIT_INDEX, resultArray); + Set(thread, index + RESULT_SPLIT_INDEX, result_array); break; case MATCH_TYPE: - Set(thread, index + RESULT_MATCH_INDEX, resultArray); + Set(thread, index + RESULT_MATCH_INDEX, result_array); break; case EXEC_TYPE: - Set(thread, index + RESULT_EXEC_INDEX, resultArray); + Set(thread, index + RESULT_EXEC_INDEX, result_array); break; default: UNREACHABLE(); @@ -1964,32 +1967,32 @@ bool RegExpExecResultCache::Match(int entry, JSTaggedValue &pattern, JSTaggedVal JSTaggedValue &extend) { int index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; - JSTaggedValue keyPattern = Get(index + PATTERN_INDEX); - JSTaggedValue keyFlags = Get(index + FLAG_INDEX); - JSTaggedValue keyInput = Get(index + INPUT_STRING_INDEX); - JSTaggedValue keyExtend = Get(index + EXTEND_INDEX); + JSTaggedValue key_pattern = Get(index + PATTERN_INDEX); + JSTaggedValue key_flags = Get(index + FLAG_INDEX); + JSTaggedValue key_input = Get(index + INPUT_STRING_INDEX); + JSTaggedValue key_extend = Get(index + EXTEND_INDEX); - if (keyPattern == JSTaggedValue::Undefined()) { + if (key_pattern == JSTaggedValue::Undefined()) { return false; } - EcmaString *patternStr = EcmaString::Cast(pattern.GetTaggedObject()); - uint8_t flagsBits = flags.GetInt(); - EcmaString *inputStr = EcmaString::Cast(input.GetTaggedObject()); - EcmaString *keyPatternStr = EcmaString::Cast(keyPattern.GetTaggedObject()); - uint8_t keyFlagsBits = keyFlags.GetInt(); - EcmaString *keyInputStr = EcmaString::Cast(keyInput.GetTaggedObject()); - bool extendEqual = false; - if (extend.IsString() && keyExtend.IsString()) { - EcmaString *extendStr = EcmaString::Cast(extend.GetTaggedObject()); - EcmaString *keyExtendStr = EcmaString::Cast(keyExtend.GetTaggedObject()); - extendEqual = EcmaString::StringsAreEqual(extendStr, keyExtendStr); - } else if (extend.IsUndefined() && keyExtend.IsUndefined()) { - extendEqual = true; + EcmaString *pattern_str = EcmaString::Cast(pattern.GetTaggedObject()); + uint8_t flags_bits = flags.GetInt(); + EcmaString *input_str = EcmaString::Cast(input.GetTaggedObject()); + EcmaString *key_pattern_str = EcmaString::Cast(key_pattern.GetTaggedObject()); + uint8_t key_flags_bits = key_flags.GetInt(); + EcmaString *key_input_str = EcmaString::Cast(key_input.GetTaggedObject()); + bool extend_equal = false; + if (extend.IsString() && key_extend.IsString()) { + EcmaString *extend_str = EcmaString::Cast(extend.GetTaggedObject()); + EcmaString *key_extend_str = EcmaString::Cast(key_extend.GetTaggedObject()); + extend_equal = EcmaString::StringsAreEqual(extend_str, key_extend_str); + } else if (extend.IsUndefined() && key_extend.IsUndefined()) { + extend_equal = true; } else { return false; } - return EcmaString::StringsAreEqual(patternStr, keyPatternStr) && flagsBits == keyFlagsBits && - EcmaString::StringsAreEqual(inputStr, keyInputStr) && extendEqual; + return EcmaString::StringsAreEqual(pattern_str, key_pattern_str) && flags_bits == key_flags_bits && + EcmaString::StringsAreEqual(input_str, key_input_str) && extend_equal; } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_regexp.h b/runtime/builtins/builtins_regexp.h index 5d7f28602dfc8c9e100e8537aaa0ef5cc8574fd3..64f043a02f5b4354d8b86d5fb81db0ff3bcc0990 100644 --- a/runtime/builtins/builtins_regexp.h +++ b/runtime/builtins/builtins_regexp.h @@ -69,26 +69,26 @@ public: 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 &inputString, bool useCache); + const JSHandle &input_string, bool use_cache); // 21.2.5.2.3 AdvanceStringIndex ( S, index, unicode ) - static uint32_t AdvanceStringIndex(const JSHandle &inputStr, uint32_t index, bool 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 lastindex, bool isUtf16); + 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 &inputStr, bool useCache); + 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 &checkStr); + 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, @@ -97,7 +97,7 @@ private: static EcmaString *EscapeRegExpPattern(JSThread *thread, const JSHandle &src, const JSHandle &flags); static JSTaggedValue RegExpReplaceFast(JSThread *thread, JSHandle ®exp, - JSHandle inputString, uint32_t inputLength); + JSHandle input_string, uint32_t input_length); }; class RegExpExecResultCache : public TaggedArray { @@ -116,20 +116,21 @@ public: // extend as an additional parameter to judge cached static void AddResultInCache(JSThread *thread, JSHandle cache, const JSHandle &pattern, const JSHandle &flags, - const JSHandle &input, const JSHandle &resultArray, - CacheType type, uint32_t lastIndex, JSTaggedValue extend = JSTaggedValue::Undefined()); + const JSHandle &input, const JSHandle &result_array, + CacheType type, uint32_t last_index, + JSTaggedValue extend = JSTaggedValue::Undefined()); static void GrowRegexpCache(JSThread *thread, JSHandle cache); void ClearEntry(JSThread *thread, int entry); void SetEntry(JSThread *thread, int entry, JSTaggedValue &pattern, JSTaggedValue &flags, JSTaggedValue &input, - JSTaggedValue &lastIndexValue, JSTaggedValue &extendValue); - void UpdateResultArray(JSThread *thread, int entry, JSTaggedValue resultArray, CacheType type); - bool Match(int entry, JSTaggedValue &patternStr, JSTaggedValue &flagsStr, JSTaggedValue &inputStr, + JSTaggedValue &last_index_value, JSTaggedValue &extend_value); + void UpdateResultArray(JSThread *thread, int entry, JSTaggedValue result_array, CacheType type); + bool Match(int entry, JSTaggedValue &pattern_str, JSTaggedValue &flags_str, JSTaggedValue &input_str, JSTaggedValue &extend); - inline void SetHitCount(JSThread *thread, int hitCount) + inline void SetHitCount(JSThread *thread, int hit_count) { - Set(thread, CACHE_HIT_COUNT_INDEX, JSTaggedValue(hitCount)); + Set(thread, CACHE_HIT_COUNT_INDEX, JSTaggedValue(hit_count)); } inline int GetHitCount() @@ -137,9 +138,9 @@ public: return Get(CACHE_HIT_COUNT_INDEX).GetInt(); } - inline void SetCacheCount(JSThread *thread, int hitCount) + inline void SetCacheCount(JSThread *thread, int hit_count) { - Set(thread, CACHE_COUNT_INDEX, JSTaggedValue(hitCount)); + Set(thread, CACHE_COUNT_INDEX, JSTaggedValue(hit_count)); } inline int GetCacheCount() @@ -153,19 +154,19 @@ public: std::cout << "cache hit count: " << GetHitCount() << std::endl; } - inline void SetLargeStrCount(JSThread *thread, uint32_t newCount) + inline void SetLargeStrCount(JSThread *thread, uint32_t new_count) { - Set(thread, LARGE_STRING_COUNT_INDEX, JSTaggedValue(newCount)); + Set(thread, LARGE_STRING_COUNT_INDEX, JSTaggedValue(new_count)); } - inline void SetConflictCount(JSThread *thread, uint32_t newCount) + inline void SetConflictCount(JSThread *thread, uint32_t new_count) { - Set(thread, CONFLICT_COUNT_INDEX, JSTaggedValue(newCount)); + Set(thread, CONFLICT_COUNT_INDEX, JSTaggedValue(new_count)); } - inline void SetStrLenThreshold(JSThread *thread, uint32_t newThreshold) + inline void SetStrLenThreshold(JSThread *thread, uint32_t new_threshold) { - Set(thread, STRING_LENGTH_THRESHOLD_INDEX, JSTaggedValue(newThreshold)); + Set(thread, STRING_LENGTH_THRESHOLD_INDEX, JSTaggedValue(new_threshold)); } inline uint32_t GetLargeStrCount() diff --git a/runtime/builtins/builtins_relative_time_format.cpp b/runtime/builtins/builtins_relative_time_format.cpp index d5202b1e227a3ed7f2ad2ebd9474ba7ebc7d50fb..ee8e8cefa57fb7d9e41c819db85f238b398bebb4 100644 --- a/runtime/builtins/builtins_relative_time_format.cpp +++ b/runtime/builtins/builtins_relative_time_format.cpp @@ -20,9 +20,9 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt { JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope scope(thread); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); // 1. If NewTarget is undefined, throw a TypeError exception. JSHandle new_target = GetNewTarget(argv); @@ -34,30 +34,30 @@ JSTaggedValue BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(EcmaRunt // (NewTarget, "%RelativeTimeFormatPrototype%", « [[InitializedRelativeTimeFormat]], // [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »). JSHandle constructor = GetConstructor(argv); - JSHandle relativeTimeFormat = JSHandle::Cast( + 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); - JSRelativeTimeFormat::InitializeRelativeTimeFormat(thread, relativeTimeFormat, locales, options); + 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 thisValue = GetThis(argv); - bool isInstanceOf = JSObject::InstanceOf(thread, thisValue, env->GetRelativeTimeFormatFunction()); + JSHandle this_value = GetThis(argv); + bool is_instance_of = JSObject::InstanceOf(thread, this_value, env->GetRelativeTimeFormatFunction()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (new_target->IsUndefined() && thisValue->IsJSObject() && isInstanceOf) { - PropertyDescriptor descriptor(thread, JSHandle::Cast(relativeTimeFormat), false, false, true); + if (new_target->IsUndefined() && this_value->IsJSObject() && is_instance_of) { + PropertyDescriptor descriptor(thread, JSHandle::Cast(relative_time_format), false, false, true); JSHandle key(thread, JSHandle::Cast(env->GetIntlFunction())->GetFallbackSymbol()); - JSTaggedValue::DefinePropertyOrThrow(thread, thisValue, key, descriptor); + JSTaggedValue::DefinePropertyOrThrow(thread, this_value, key, descriptor); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return thisValue.GetTaggedValue(); + return this_value.GetTaggedValue(); } - return relativeTimeFormat.GetTaggedValue(); + return relative_time_format.GetTaggedValue(); } JSTaggedValue BuiltinsRelativeTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo *argv) @@ -66,16 +66,16 @@ JSTaggedValue BuiltinsRelativeTimeFormat::SupportedLocalesOf(EcmaRuntimeCallInfo [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let availableLocales be %RelativeTimeFormat%.[[AvailableLocales]]. - JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); + JSHandle available_locales = JSLocale::GetAvailableLocales(thread, "calendar", nullptr); // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + 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 result = JSLocale::SupportedLocales(thread, availableLocales, requestedLocales, options); + JSHandle result = JSLocale::SupportedLocales(thread, available_locales, requested_locales, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -86,10 +86,10 @@ JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - if (!thisValue->IsJSRelativeTimeFormat()) { + if (!this_value->IsJSRelativeTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception()); } @@ -101,13 +101,13 @@ JSTaggedValue BuiltinsRelativeTimeFormat::Format(EcmaRuntimeCallInfo *argv) x = temp.GetNumber(); // 4. Let unit be ? ToString(unit). - JSHandle unitValue = GetCallArg(argv, 1); - JSHandle unit = JSTaggedValue::ToString(thread, unitValue); + JSHandle unit_value = GetCallArg(argv, 1); + JSHandle unit = JSTaggedValue::ToString(thread, unit_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit). - JSHandle relativeTimeFormat = JSHandle::Cast(thisValue); - JSHandle result = JSRelativeTimeFormat::Format(thread, x, unit, relativeTimeFormat); + JSHandle relative_time_format = JSHandle::Cast(this_value); + JSHandle result = JSRelativeTimeFormat::Format(thread, x, unit, relative_time_format); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -118,10 +118,10 @@ JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *arg [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - if (!thisValue->IsJSRelativeTimeFormat()) { + if (!this_value->IsJSRelativeTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception()); } @@ -133,13 +133,13 @@ JSTaggedValue BuiltinsRelativeTimeFormat::FormatToParts(EcmaRuntimeCallInfo *arg x = temp.GetNumber(); // 4. Let unit be ? ToString(unit). - JSHandle unitValue = GetCallArg(argv, 1); - JSHandle unit = JSTaggedValue::ToString(thread, unitValue); + JSHandle unit_value = GetCallArg(argv, 1); + JSHandle unit = JSTaggedValue::ToString(thread, unit_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit). - JSHandle relativeTimeFormat = JSHandle::Cast(thisValue); - JSHandle result = JSRelativeTimeFormat::FormatToParts(thread, x, unit, relativeTimeFormat); + JSHandle relative_time_format = JSHandle::Cast(this_value); + JSHandle result = JSRelativeTimeFormat::FormatToParts(thread, x, unit, relative_time_format); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result.GetTaggedValue(); } @@ -150,23 +150,23 @@ JSTaggedValue BuiltinsRelativeTimeFormat::ResolvedOptions(EcmaRuntimeCallInfo *a [[maybe_unused]] EcmaHandleScope scope(thread); // 1. Let relativeTimeFormat be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = GetThis(argv); // 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]). - if (!thisValue->IsJSRelativeTimeFormat()) { + if (!this_value->IsJSRelativeTimeFormat()) { THROW_TYPE_ERROR_AND_RETURN(thread, "this is not rtf object", JSTaggedValue::Exception()); } // 3. Let options be ! ObjectCreate(%ObjectPrototype%). - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - ObjectFactory *factory = ecmaVm->GetFactory(); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); + ObjectFactory *factory = ecma_vm->GetFactory(); JSHandle ctor = env->GetObjectFunction(); JSHandle options(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); // 4. perform resolvedOptions - JSHandle relativeTimeFormat = JSHandle::Cast(thisValue); - JSRelativeTimeFormat::ResolvedOptions(thread, relativeTimeFormat, options); + JSHandle relative_time_format = JSHandle::Cast(this_value); + JSRelativeTimeFormat::ResolvedOptions(thread, relative_time_format, options); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Return options. return options.GetTaggedValue(); diff --git a/runtime/builtins/builtins_set.cpp b/runtime/builtins/builtins_set.cpp index 60240f01c52003c34a6946b5fbca8e5075e4dee7..ea8cc8255e3e92c4f3a835dcb65c45d88bb5f577 100644 --- a/runtime/builtins/builtins_set.cpp +++ b/runtime/builtins/builtins_set.cpp @@ -30,7 +30,7 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -46,8 +46,8 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) JSHandle set = JSHandle::Cast(obj); // 3.ReturnIfAbrupt(set). // 4.Set set’s [[SetData]] internal slot to a new empty List. - JSHandle linkedSet = LinkedHashSet::Create(thread); - set->SetLinkedSet(thread, linkedSet); + JSHandle linked_set = LinkedHashSet::Create(thread); + set->SetLinkedSet(thread, linked_set); // add data into set from iterable // 5.If iterable is not present, let iterable be undefined. @@ -58,9 +58,9 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) return set.GetTaggedValue(); } // Let adder be Get(set, "add"). - JSHandle adderKey(factory->NewFromCanBeCompressString("add")); - JSHandle setHandle(set); - JSHandle adder = JSObject::GetProperty(thread, setHandle, adderKey).GetValue(); + JSHandle adder_key(factory->NewFromCanBeCompressString("add")); + JSHandle set_handle(set); + JSHandle adder = JSObject::GetProperty(thread, set_handle, adder_key).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); // If IsCallable(adder) is false, throw a TypeError exception @@ -73,24 +73,24 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter.GetTaggedValue()); // values in iterator_result may be a JSArray, values[0] = key values[1]=value, used valueIndex to get value from // jsarray - JSHandle valueIndex(thread, JSTaggedValue(1)); + JSHandle value_index(thread, JSTaggedValue(1)); JSHandle next = JSIterator::IteratorStep(thread, iter); while (!next->IsFalse()) { // ReturnIfAbrupt(next). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // Let nextValue be IteratorValue(next). - JSHandle nextValue(JSIterator::IteratorValue(thread, next)); + JSHandle next_value(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next_value.GetTaggedValue()); auto info = NewRuntimeCallInfo(thread, adder, set, JSTaggedValue::Undefined(), 1); - if (nextValue->IsArray(thread)) { - auto prop = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); + if (next_value->IsArray(thread)) { + auto prop = JSObject::GetProperty(thread, next_value, value_index).GetValue(); info->SetCallArgs(prop); } else { - info->SetCallArgs(nextValue); + info->SetCallArgs(next_value); } - JSTaggedValue ret = JSFunction::Call(info.get()); + JSTaggedValue ret = JSFunction::Call(info.Get()); // Let status be Call(adder, set, «nextValue.[[value]]»). JSHandle status(thread, ret); @@ -108,7 +108,7 @@ JSTaggedValue BuiltinsSet::Add(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Add); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -129,7 +129,7 @@ JSTaggedValue BuiltinsSet::Clear(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Clear); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -147,7 +147,7 @@ JSTaggedValue BuiltinsSet::Delete(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = 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. @@ -166,19 +166,19 @@ JSTaggedValue BuiltinsSet::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = 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 jsSet(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle js_set(thread, JSSet::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle value = GetCallArg(argv, 0); bool flag = false; if (JSSet::IsKey(value.GetTaggedValue())) { int hash = LinkedHash::Hash(value.GetTaggedValue()); - flag = jsSet->Has(value.GetTaggedValue(), hash); + flag = js_set->Has(value.GetTaggedValue(), hash); } return GetTaggedBoolean(flag); } @@ -186,7 +186,7 @@ JSTaggedValue BuiltinsSet::Has(EcmaRuntimeCallInfo *argv) JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -203,7 +203,7 @@ JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) } // 5.If thisArg was supplied, let T be thisArg; else let T be undefined. - JSHandle thisArg = GetCallArg(argv, 1); + JSHandle this_arg = GetCallArg(argv, 1); // composed arguments JSHandle iter(factory->NewJSSetIterator(set, IterationKind::KEY)); @@ -213,9 +213,9 @@ JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result.GetTaggedValue()); JSHandle value = JSIterator::IteratorValue(thread, result); // Let funcResult be Call(callbackfn, T, «e, e, S»). - auto info = NewRuntimeCallInfo(thread, func, thisArg, JSTaggedValue::Undefined(), 3); + auto info = NewRuntimeCallInfo(thread, func, this_arg, JSTaggedValue::Undefined(), 3); info->SetCallArgs(value, value, JSHandle(set)); - JSTaggedValue ret = JSFunction::Call(info.get()); // 3: three args + JSTaggedValue ret = JSFunction::Call(info.Get()); // 3: three args // returnIfAbrupt RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); result = JSIterator::IteratorStep(thread, iter); @@ -233,15 +233,15 @@ JSTaggedValue BuiltinsSet::GetSize(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, GetSize); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(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()); } - JSSet *jsSet = JSSet::Cast(*JSTaggedValue::ToObject(thread, self)); - int count = jsSet->GetSize(); + JSSet *js_set = JSSet::Cast(*JSTaggedValue::ToObject(thread, self)); + int count = js_set->GetSize(); return JSTaggedValue(count); } @@ -250,7 +250,7 @@ JSTaggedValue BuiltinsSet::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); JSHandle iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::KEY_AND_VALUE); return iter.GetTaggedValue(); @@ -261,7 +261,7 @@ JSTaggedValue BuiltinsSet::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Set, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); JSHandle iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::VALUE); return iter.GetTaggedValue(); diff --git a/runtime/builtins/builtins_string.cpp b/runtime/builtins/builtins_string.cpp index cf8d4efec66a7f840301bb2d326b7ee6f946c1e1..1e296b0d5128f66e439a2aaac0bb74f5b010ee2f 100644 --- a/runtime/builtins/builtins_string.cpp +++ b/runtime/builtins/builtins_string.cpp @@ -54,28 +54,28 @@ JSTaggedValue BuiltinsString::StringConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle new_target = GetNewTarget(argv); if (argv->GetArgsNumber() > 0) { - JSHandle valTagNew = GetCallArg(argv, 0); - if (new_target->IsUndefined() && valTagNew->IsSymbol()) { - return BuiltinsSymbol::SymbolDescriptiveString(thread, valTagNew.GetTaggedValue()); + JSHandle val_tag_new = GetCallArg(argv, 0); + if (new_target->IsUndefined() && val_tag_new->IsSymbol()) { + return BuiltinsSymbol::SymbolDescriptiveString(thread, val_tag_new.GetTaggedValue()); } - JSHandle str = JSTaggedValue::ToString(thread, valTagNew); + JSHandle str = JSTaggedValue::ToString(thread, val_tag_new); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (new_target->IsUndefined()) { return str.GetTaggedValue(); } - JSHandle strTag(str); - return JSPrimitiveRef::StringCreate(thread, strTag).GetTaggedValue(); + JSHandle str_tag(str); + return JSPrimitiveRef::StringCreate(thread, str_tag).GetTaggedValue(); } JSHandle val = factory->GetEmptyString(); - JSHandle valTag(val); + JSHandle val_tag(val); if (new_target->IsUndefined()) { return factory->GetEmptyString().GetTaggedValue(); } - return JSPrimitiveRef::StringCreate(thread, valTag).GetTaggedValue(); + return JSPrimitiveRef::StringCreate(thread, val_tag).GetTaggedValue(); } // 21.1.2.1 @@ -84,35 +84,35 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, FromCharCode); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t argLength = argv->GetArgsNumber(); - if (argLength == 0) { + int32_t arg_length = argv->GetArgsNumber(); + if (arg_length == 0) { return factory->GetEmptyString().GetTaggedValue(); } - JSHandle codePointTag = BuiltinsString::GetCallArg(argv, 0); - uint16_t codePointValue = JSTaggedValue::ToUint16(thread, codePointTag); + JSHandle code_point_tag = BuiltinsString::GetCallArg(argv, 0); + uint16_t code_point_value = JSTaggedValue::ToUint16(thread, code_point_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle strHandle = factory->NewFromUtf16Literal(&codePointValue, 1); - if (argLength == 1) { - return strHandle.GetTaggedValue(); - } - std::u16string u16str = ecmascript::base::StringHelper::Utf16ToU16String(&codePointValue, 1); - PandaVector valueTable; - valueTable.reserve(argLength - 1); - for (int32_t i = 1; i < argLength; i++) { - JSHandle nextCp = BuiltinsString::GetCallArg(argv, i); - uint16_t nextCv = JSTaggedValue::ToUint16(thread, nextCp); - valueTable.emplace_back(nextCv); + JSHandle str_handle = factory->NewFromUtf16Literal(&code_point_value, 1); + if (arg_length == 1) { + return str_handle.GetTaggedValue(); + } + std::u16string u16str = ecmascript::base::StringHelper::Utf16ToU16String(&code_point_value, 1); + 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); + uint16_t next_cv = JSTaggedValue::ToUint16(thread, next_cp); + value_table.emplace_back(next_cv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - std::u16string nextU16str = base::StringHelper::Utf16ToU16String(valueTable.data(), argLength - 1); - u16str = base::StringHelper::Append(u16str, nextU16str); - const char16_t *constChar16tData = u16str.data(); - auto *char16tData = const_cast(constChar16tData); - auto *uint16tData = reinterpret_cast(char16tData); - int32_t u16strSize = u16str.size(); - return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); + std::u16string next_u16str = base::StringHelper::Utf16ToU16String(value_table.data(), arg_length - 1); + u16str = base::StringHelper::Append(u16str, next_u16str); + const char16_t *const_char16t_data = u16str.data(); + auto *char16t_data = const_cast(const_char16t_data); + auto *uint16t_data = reinterpret_cast(char16t_data); + int32_t u16str_size = u16str.size(); + return factory->NewFromUtf16Literal(uint16t_data, u16str_size).GetTaggedValue(); } // 21.1.2.2 @@ -121,22 +121,22 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, FromCodePoint); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - int32_t argLength = argv->GetArgsNumber(); - if (argLength == 0) { + int32_t arg_length = argv->GetArgsNumber(); + if (arg_length == 0) { return factory->GetEmptyString().GetTaggedValue(); } std::u16string u16str; - int32_t u16strSize = argLength; - for (int i = 0; i < argLength; i++) { - JSHandle nextCpTag = BuiltinsString::GetCallArg(argv, i); - JSTaggedNumber nextCpVal = JSTaggedValue::ToNumber(thread, nextCpTag); + int32_t u16str_size = arg_length; + for (int i = 0; i < arg_length; i++) { + JSHandle next_cp_tag = BuiltinsString::GetCallArg(argv, i); + JSTaggedNumber next_cp_val = JSTaggedValue::ToNumber(thread, next_cp_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (!nextCpVal.IsInteger()) { + if (!next_cp_val.IsInteger()) { THROW_RANGE_ERROR_AND_RETURN(thread, "is not integer", JSTaggedValue::Exception()); } - int32_t cp = nextCpVal.ToInt32(); + int32_t cp = next_cp_val.ToInt32(); if (cp < 0 || cp > ENCODE_MAX_UTF16) { THROW_RANGE_ERROR_AND_RETURN(thread, "CodePoint < 0 or CodePoint > 0x10FFFF", JSTaggedValue::Exception()); } @@ -147,21 +147,21 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) if (cp > UINT16_MAX) { uint16_t cu1 = std::floor((cp - ENCODE_SECOND_FACTOR) / ENCODE_FIRST_FACTOR) + ENCODE_LEAD_LOW; uint16_t cu2 = ((cp - ENCODE_SECOND_FACTOR) % ENCODE_FIRST_FACTOR) + ENCODE_TRAIL_LOW; - std::u16string nextU16str1 = ecmascript::base::StringHelper::Utf16ToU16String(&cu1, 1); - std::u16string nextU16str2 = ecmascript::base::StringHelper::Utf16ToU16String(&cu2, 1); - u16str = ecmascript::base::StringHelper::Append(u16str, nextU16str1); - u16str = ecmascript::base::StringHelper::Append(u16str, nextU16str2); - u16strSize++; + std::u16string next_u16str1 = ecmascript::base::StringHelper::Utf16ToU16String(&cu1, 1); + std::u16string next_u16str2 = ecmascript::base::StringHelper::Utf16ToU16String(&cu2, 1); + u16str = ecmascript::base::StringHelper::Append(u16str, next_u16str1); + u16str = ecmascript::base::StringHelper::Append(u16str, next_u16str2); + u16str_size++; } else { - auto u16tCp = static_cast(cp); - std::u16string nextU16str = ecmascript::base::StringHelper::Utf16ToU16String(&u16tCp, 1); - u16str = ecmascript::base::StringHelper::Append(u16str, nextU16str); + auto u16t_cp = static_cast(cp); + std::u16string next_u16str = ecmascript::base::StringHelper::Utf16ToU16String(&u16t_cp, 1); + u16str = ecmascript::base::StringHelper::Append(u16str, next_u16str); } } - const char16_t *constChar16tData = u16str.data(); - auto *char16tData = const_cast(constChar16tData); - auto *uint16tData = reinterpret_cast(char16tData); - return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); + const char16_t *const_char16t_data = u16str.data(); + auto *char16t_data = const_cast(const_char16t_data); + auto *uint16t_data = reinterpret_cast(char16t_data); + return factory->NewFromUtf16Literal(uint16t_data, u16str_size).GetTaggedValue(); } // 21.1.2.4 @@ -170,27 +170,27 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Raw); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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)); // ReturnIfAbrupt(cooked). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let raw be ToObject(Get(cooked, "raw")). - JSHandle rawKey(factory->NewFromCanBeCompressString("raw")); - JSHandle rawTag = - JSObject::GetProperty(thread, JSHandle::Cast(cooked), rawKey).GetValue(); - JSHandle rawObj = JSTaggedValue::ToObject(thread, rawTag); + JSHandle raw_key(factory->NewFromCanBeCompressString("raw")); + JSHandle raw_tag = + JSObject::GetProperty(thread, JSHandle::Cast(cooked), raw_key).GetValue(); + JSHandle raw_obj = JSTaggedValue::ToObject(thread, raw_tag); // ReturnIfAbrupt(rawObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle rawLen = - JSObject::GetProperty(thread, JSHandle::Cast(rawObj), lengthKey).GetValue(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle raw_len = + JSObject::GetProperty(thread, JSHandle::Cast(raw_obj), length_key).GetValue(); // ReturnIfAbrupt(rawLen). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedNumber lengthNumber = JSTaggedValue::ToLength(thread, rawLen); + JSTaggedNumber length_number = JSTaggedValue::ToLength(thread, raw_len); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int length = lengthNumber.ToUint32(); + int length = length_number.ToUint32(); if (length <= 0) { return factory->GetEmptyString().GetTaggedValue(); } @@ -198,37 +198,38 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) std::u16string u16str; int argc = static_cast(argv->GetArgsNumber()) - 1; bool can_be_compress = true; - for (int i = 0, argsI = 1; i < length; ++i, ++argsI) { + for (int i = 0, args_i = 1; i < length; ++i, ++args_i) { // Let nextSeg be ToString(Get(raw, nextKey)). - JSHandle elementString = - JSObject::GetProperty(thread, JSHandle::Cast(rawObj), i).GetValue(); + JSHandle element_string = + JSObject::GetProperty(thread, JSHandle::Cast(raw_obj), i).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *nextSeg = *JSTaggedValue::ToString(thread, elementString); + EcmaString *next_seg = *JSTaggedValue::ToString(thread, element_string); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (nextSeg->IsUtf16()) { - u16str += ecmascript::base::StringHelper::Utf16ToU16String(nextSeg->GetDataUtf16(), nextSeg->GetLength()); + if (next_seg->IsUtf16()) { + u16str += ecmascript::base::StringHelper::Utf16ToU16String(next_seg->GetDataUtf16(), next_seg->GetLength()); can_be_compress = false; } else { - u16str += ecmascript::base::StringHelper::Utf8ToU16String(nextSeg->GetDataUtf8(), nextSeg->GetLength()); + u16str += ecmascript::base::StringHelper::Utf8ToU16String(next_seg->GetDataUtf8(), next_seg->GetLength()); } if (i + 1 == length) { break; } - if (argsI <= argc) { - EcmaString *nextSub = *JSTaggedValue::ToString(thread, GetCallArg(argv, argsI)); + if (args_i <= argc) { + EcmaString *next_sub = *JSTaggedValue::ToString(thread, GetCallArg(argv, args_i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (nextSub->IsUtf16()) { + if (next_sub->IsUtf16()) { u16str += - ecmascript::base::StringHelper::Utf16ToU16String(nextSub->GetDataUtf16(), nextSub->GetLength()); + ecmascript::base::StringHelper::Utf16ToU16String(next_sub->GetDataUtf16(), next_sub->GetLength()); can_be_compress = false; } else { - u16str += ecmascript::base::StringHelper::Utf8ToU16String(nextSub->GetDataUtf8(), nextSub->GetLength()); + u16str += + ecmascript::base::StringHelper::Utf8ToU16String(next_sub->GetDataUtf8(), next_sub->GetLength()); } } } // return the result string - auto *uint16tData = reinterpret_cast(const_cast(u16str.data())); - return factory->NewFromUtf16LiteralUnCheck(uint16tData, u16str.size(), can_be_compress).GetTaggedValue(); + auto *uint16t_data = reinterpret_cast(const_cast(u16str.data())); + return factory->NewFromUtf16LiteralUnCheck(uint16t_data, u16str.size(), can_be_compress).GetTaggedValue(); } // 21.1.3.1 @@ -237,25 +238,25 @@ JSTaggedValue BuiltinsString::CharAt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, CharAt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - JSHandle posTag = BuiltinsString::GetCallArg(argv, 0); + int32_t this_len = this_handle->GetLength(); + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 0); int32_t pos; - if (posTag->IsUndefined()) { + if (pos_tag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = posVal.ToInt32(); + pos = pos_val.ToInt32(); } - if (pos < 0 || pos >= thisLen) { + if (pos < 0 || pos >= this_len) { return factory->GetEmptyString().GetTaggedValue(); } - uint16_t res = thisHandle->At(pos); + uint16_t res = this_handle->At(pos); return factory->NewFromUtf16Literal(&res, 1).GetTaggedValue(); } @@ -265,24 +266,24 @@ JSTaggedValue BuiltinsString::CharCodeAt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, CharCodeAt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - JSHandle posTag = BuiltinsString::GetCallArg(argv, 0); + int32_t this_len = this_handle->GetLength(); + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 0); int32_t pos; - if (posTag->IsUndefined()) { + if (pos_tag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = posVal.ToInt32(); + pos = pos_val.ToInt32(); } - if (pos < 0 || pos >= thisLen) { + if (pos < 0 || pos >= this_len) { return GetTaggedDouble(ecmascript::base::NAN_VALUE); } - uint16_t ret = thisHandle->At(pos); + uint16_t ret = this_handle->At(pos); return GetTaggedInt(ret); } @@ -292,24 +293,24 @@ JSTaggedValue BuiltinsString::CodePointAt(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, CodePointAt); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle posTag = BuiltinsString::GetCallArg(argv, 0); + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 0); - JSTaggedNumber posVal = JSTaggedValue::ToNumber(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToNumber(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber()); - int32_t thisLen = thisHandle->GetLength(); - if (pos < 0 || pos >= thisLen) { + int32_t pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(pos_val.GetNumber()); + int32_t this_len = this_handle->GetLength(); + if (pos < 0 || pos >= this_len) { return JSTaggedValue::Undefined(); } - uint16_t first = thisHandle->At(pos); - if (first < utf::DECODE_LEAD_LOW || first > utf::DECODE_LEAD_HIGH || pos + 1 == thisLen) { + 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); } - uint16_t second = thisHandle->At(pos + 1); + uint16_t second = this_handle->At(pos + 1); if (second < utf::DECODE_TRAIL_LOW || second > utf::DECODE_TRAIL_HIGH) { return GetTaggedInt(first); } @@ -323,42 +324,42 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Concat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t argLength = argv->GetArgsNumber(); - if (argLength == 0) { - return thisHandle.GetTaggedValue(); + int32_t this_len = this_handle->GetLength(); + int32_t arg_length = argv->GetArgsNumber(); + if (arg_length == 0) { + return this_handle.GetTaggedValue(); } - std::u16string u16strThis; - std::u16string u16strNext; + std::u16string u16str_this; + std::u16string u16str_next; bool can_be_compress = true; - if (thisHandle->IsUtf16()) { - u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + if (this_handle->IsUtf16()) { + u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); can_be_compress = false; } else { - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(thisHandle->GetDataUtf8(), thisLen); - } - for (int i = 0; i < argLength; i++) { - JSHandle nextTag = BuiltinsString::GetCallArg(argv, i); - JSHandle nextHandle = JSTaggedValue::ToString(thread, nextTag); - int32_t nextLen = nextHandle->GetLength(); - if (nextHandle->IsUtf16()) { - u16strNext = ecmascript::base::StringHelper::Utf16ToU16String(nextHandle->GetDataUtf16(), nextLen); + 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_handle = JSTaggedValue::ToString(thread, next_tag); + int32_t next_len = next_handle->GetLength(); + if (next_handle->IsUtf16()) { + u16str_next = ecmascript::base::StringHelper::Utf16ToU16String(next_handle->GetDataUtf16(), next_len); can_be_compress = false; } else { - u16strNext = ecmascript::base::StringHelper::Utf8ToU16String(nextHandle->GetDataUtf8(), nextLen); + u16str_next = ecmascript::base::StringHelper::Utf8ToU16String(next_handle->GetDataUtf8(), next_len); } - u16strThis = ecmascript::base::StringHelper::Append(u16strThis, u16strNext); + u16str_this = ecmascript::base::StringHelper::Append(u16str_this, u16str_next); } - const char16_t *constChar16tData = u16strThis.data(); - auto *char16tData = const_cast(constChar16tData); - auto *uint16tData = reinterpret_cast(char16tData); - int32_t u16strSize = u16strThis.size(); - return factory->NewFromUtf16LiteralUnCheck(uint16tData, u16strSize, can_be_compress).GetTaggedValue(); + const char16_t *const_char16t_data = u16str_this.data(); + auto *char16t_data = const_cast(const_char16t_data); + auto *uint16t_data = reinterpret_cast(char16t_data); + int32_t u16str_size = u16str_this.size(); + return factory->NewFromUtf16LiteralUnCheck(uint16t_data, u16str_size, can_be_compress).GetTaggedValue(); } // 21.1.3.5 String.prototype.constructor @@ -368,48 +369,48 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, EndsWith); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool isRegexp = JSObject::IsRegExp(thread, searchTag); - if (isRegexp) { + bool is_regexp = JSObject::IsRegExp(thread, search_tag); + if (is_regexp) { THROW_TYPE_ERROR_AND_RETURN(thread, "is regexp", JSTaggedValue::Exception()); } - JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); + JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t searchLen = searchHandle->GetLength(); + int32_t this_len = this_handle->GetLength(); + int32_t search_len = search_handle->GetLength(); int32_t pos; - JSHandle posTag = BuiltinsString::GetCallArg(argv, 1); - if (posTag->IsUndefined()) { - pos = thisLen; + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + if (pos_tag->IsUndefined()) { + pos = this_len; } else { - JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = posVal.ToInt32(); + pos = pos_val.ToInt32(); } - int32_t end = std::min(std::max(pos, 0), thisLen); - int32_t start = end - searchLen; + int32_t end = std::min(std::max(pos, 0), this_len); + int32_t start = end - search_len; if (start < 0) { return BuiltinsString::GetTaggedBoolean(false); } - std::u16string u16strThis; - std::u16string u16strSearch; - if (thisHandle->IsUtf16()) { - u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + std::u16string u16str_this; + std::u16string u16str_search; + if (this_handle->IsUtf16()) { + u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); } else { - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); } - if (searchHandle->IsUtf16()) { - u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); + if (search_handle->IsUtf16()) { + u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); } else { - const uint8_t *uint8Search = searchHandle->GetDataUtf8(); - u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); + const uint8_t *uint8_search = search_handle->GetDataUtf8(); + u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); } - int32_t idx = ecmascript::base::StringHelper::Find(u16strThis, u16strSearch, start); + int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, start); if (idx == start) { return BuiltinsString::GetTaggedBoolean(true); } @@ -422,45 +423,45 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Includes); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool isRegexp = JSObject::IsRegExp(thread, searchTag); - if (isRegexp) { + bool is_regexp = JSObject::IsRegExp(thread, search_tag); + if (is_regexp) { THROW_TYPE_ERROR_AND_RETURN(thread, "is regexp", JSTaggedValue::Exception()); } - JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); + JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t searchLen = searchHandle->GetLength(); + int32_t this_len = this_handle->GetLength(); + int32_t search_len = search_handle->GetLength(); int32_t pos = 0; - JSHandle posTag = BuiltinsBase::GetCallArg(argv, 1); + JSHandle pos_tag = BuiltinsBase::GetCallArg(argv, 1); if (argv->GetArgsNumber() == 1) { pos = 0; } else { - JSTaggedNumber posVal = JSTaggedValue::ToNumber(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToNumber(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber()); + pos = ecmascript::base::NumberHelper::DoubleInRangeInt32(pos_val.GetNumber()); } - int32_t start = std::min(std::max(pos, 0), thisLen); - std::u16string u16strThis; - std::u16string u16strSearch; - if (thisHandle->IsUtf16()) { - u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + int32_t start = std::min(std::max(pos, 0), this_len); + std::u16string u16str_this; + std::u16string u16str_search; + if (this_handle->IsUtf16()) { + u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); } else { - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); } - if (searchHandle->IsUtf16()) { - u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); + if (search_handle->IsUtf16()) { + u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); } else { - const uint8_t *uint8Search = searchHandle->GetDataUtf8(); - u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); + const uint8_t *uint8_search = search_handle->GetDataUtf8(); + u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); } - int32_t idx = ecmascript::base::StringHelper::Find(u16strThis, u16strSearch, start); - if (idx < 0 || idx > thisLen) { + int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, start); + if (idx < 0 || idx > this_len) { return BuiltinsString::GetTaggedBoolean(false); } return BuiltinsString::GetTaggedBoolean(true); @@ -472,28 +473,28 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, IndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - uint32_t thisLen = thisHandle->GetLength(); - JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); + uint32_t this_len = this_handle->GetLength(); + JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle posTag = BuiltinsString::GetCallArg(argv, 1); + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); int32_t pos; - if (posTag->IsInt()) { - pos = posTag->GetInt(); - } else if (posTag->IsUndefined()) { + if (pos_tag->IsInt()) { + pos = pos_tag->GetInt(); + } else if (pos_tag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = posVal.ToInt32(); + pos = pos_val.ToInt32(); } - pos = std::min(std::max(pos, 0), static_cast(thisLen)); - int32_t res = thisHandle->IndexOf(*searchHandle, pos); - if (res >= 0 && res < static_cast(thisLen)) { + 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 GetTaggedInt(-1); @@ -505,45 +506,45 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, LastIndexOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); + int32_t this_len = this_handle->GetLength(); + JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t searchLen = searchHandle->GetLength(); + int32_t search_len = search_handle->GetLength(); int32_t pos; if (argv->GetArgsNumber() == 1) { - pos = thisLen; + pos = this_len; } else { - JSHandle posTag = BuiltinsString::GetCallArg(argv, 1); - JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (std::isnan(JSTaggedValue::ToNumber(thread, posTag).GetNumber())) { - pos = thisLen; + if (std::isnan(JSTaggedValue::ToNumber(thread, pos_tag).GetNumber())) { + pos = this_len; } else { - pos = posVal.ToInt32(); + pos = pos_val.ToInt32(); } } - pos = std::min(std::max(pos, 0), thisLen); - std::u16string u16strThis; - std::u16string u16strSearch; - if (thisHandle->IsUtf16()) { - u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + pos = std::min(std::max(pos, 0), this_len); + std::u16string u16str_this; + std::u16string u16str_search; + if (this_handle->IsUtf16()) { + u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); } else { - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); } - if (searchHandle->IsUtf16()) { - u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); + if (search_handle->IsUtf16()) { + u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); } else { - const uint8_t *uint8Search = searchHandle->GetDataUtf8(); - u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); + const uint8_t *uint8_search = search_handle->GetDataUtf8(); + u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); } - int32_t res = ecmascript::base::StringHelper::RFind(u16strThis, u16strSearch, pos); - if (res >= 0 && res < thisLen) { + int32_t res = ecmascript::base::StringHelper::RFind(u16str_this, u16str_search, pos); + if (res >= 0 && res < this_len) { return GetTaggedInt(res); } res = -1; @@ -556,14 +557,14 @@ JSTaggedValue BuiltinsString::LocaleCompare(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, LocaleCompare); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle that_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thatHandle = JSTaggedValue::ToString(thread, that_tag); + JSHandle that_handle = JSTaggedValue::ToString(thread, that_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t res = thisHandle->Compare(*thatHandle); + int32_t res = this_handle->Compare(*that_handle); return GetTaggedInt(res); } @@ -573,44 +574,44 @@ JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Match); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + [[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 matchTag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); + JSHandle match_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchSymbol(); if (regexp->IsJSRegExp()) { - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); JSHandle re(regexp); JSHandle pattern(thread, re->GetOriginalSource()); JSHandle flags(thread, re->GetOriginalFlags()); - JSTaggedValue cacheResult = - cacheTable->FindCachedResult(thread, pattern, flags, thisTag, RegExpExecResultCache::MATCH_TYPE, regexp); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + JSTaggedValue cache_result = + cache_table->FindCachedResult(thread, pattern, flags, this_tag, RegExpExecResultCache::MATCH_TYPE, regexp); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } if (!regexp->IsUndefined() && !regexp->IsNull()) { if (regexp->IsECMAObject()) { - JSHandle matcher = JSObject::GetMethod(thread, regexp, matchTag); + JSHandle matcher = JSObject::GetMethod(thread, regexp, match_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!matcher->IsUndefined()) { ASSERT(matcher->IsJSFunction()); auto info = NewRuntimeCallInfo(thread, matcher, regexp, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thisTag); - return JSFunction::Call(info.get()); + info->SetCallArgs(this_tag); + return JSFunction::Call(info.Get()); } } } - JSHandle thisVal = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle undifinedHandle = globalConst->GetHandledUndefined(); - JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifinedHandle)); + JSHandle undifined_handle = global_const->GetHandledUndefined(); + JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifined_handle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thisVal.GetTaggedValue()); - return JSFunction::Invoke(info.get(), matchTag); + info->SetCallArgs(this_val.GetTaggedValue()); + return JSFunction::Invoke(info.Get(), match_tag); } JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) @@ -618,32 +619,32 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, MatchAll); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); // 1. Let O be ? RequireObjectCoercible(this value). - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); JSHandle regexp = BuiltinsString::GetCallArg(argv, 0); - JSHandle matchAllTag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchAllSymbol(); - JSHandle gvalue(globalConst->GetHandledGString()); + JSHandle match_all_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetMatchAllSymbol(); + JSHandle gvalue(global_const->GetHandledGString()); // 2. If regexp is neither undefined nor null, then if (!regexp->IsUndefined() && !regexp->IsNull()) { // a. Let isRegExp be ? IsRegExp(searchValue). - bool isJSRegExp = JSObject::IsRegExp(thread, regexp); + bool is_js_reg_exp = JSObject::IsRegExp(thread, regexp); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If isRegExp is true, then - if (isJSRegExp) { + if (is_js_reg_exp) { // i. Let flags be ? Get(searchValue, "flags"). - JSHandle flagsString(globalConst->GetHandledFlagsString()); - JSHandle flags = JSObject::GetProperty(thread, regexp, flagsString).GetValue(); + JSHandle flags_string(global_const->GetHandledFlagsString()); + JSHandle flags = JSObject::GetProperty(thread, regexp, flags_string).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // ii. Perform ? RequireObjectCoercible(flags). JSTaggedValue::RequireObjectCoercible(thread, flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iii. If ? ToString(flags) does not contain "g", throw a TypeError exception. - JSHandle flagString = JSTaggedValue::ToString(thread, flags); + JSHandle flag_string = JSTaggedValue::ToString(thread, flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t pos = flagString->IndexOf(static_cast(gvalue->GetTaggedObject())); + int32_t pos = flag_string->IndexOf(static_cast(gvalue->GetTaggedObject())); if (pos == -1) { THROW_TYPE_ERROR_AND_RETURN(thread, "matchAll called with a non-global RegExp argument", JSTaggedValue::Exception()); @@ -653,27 +654,27 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) if (regexp->IsECMAObject()) { // c. c. Let matcher be ? GetMethod(regexp, @@matchAll). // d. d. If matcher is not undefined, then - JSHandle matcher = JSObject::GetMethod(thread, regexp, matchAllTag); + JSHandle matcher = JSObject::GetMethod(thread, regexp, match_all_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!matcher->IsUndefined()) { ASSERT(matcher->IsJSFunction()); // i. i. Return ? Call(matcher, regexp, « O »). auto info = NewRuntimeCallInfo(thread, matcher, regexp, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thisTag.GetTaggedValue()); - return JSFunction::Call(info.get()); + info->SetCallArgs(this_tag.GetTaggedValue()); + return JSFunction::Call(info.Get()); } } } // 3. Let S be ? ToString(O). - JSHandle thisVal = JSTaggedValue::ToString(thread, thisTag); + 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)); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thisVal.GetTaggedValue()); - return JSFunction::Invoke(info.get(), matchAllTag); + info->SetCallArgs(this_val.GetTaggedValue()); + return JSFunction::Invoke(info.Get(), match_all_tag); } // 21.1.3.12 @@ -682,20 +683,20 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Normalize); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - JSHandle formValue; + JSHandle form_value; if (argv->GetArgsNumber() == 0) { - formValue = factory->NewFromString("NFC"); + form_value = factory->NewFromString("NFC"); } else { - JSHandle formTag = BuiltinsString::GetCallArg(argv, 0); - if (formTag->IsUndefined()) { - formValue = factory->NewFromString("NFC"); + JSHandle form_tag = BuiltinsString::GetCallArg(argv, 0); + if (form_tag->IsUndefined()) { + form_value = factory->NewFromString("NFC"); } else { - formValue = JSTaggedValue::ToString(thread, formTag); + form_value = JSTaggedValue::ToString(thread, form_tag); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); } } @@ -703,64 +704,64 @@ JSTaggedValue BuiltinsString::Normalize(EcmaRuntimeCallInfo *argv) JSHandle nfd = factory->NewFromString("NFD"); JSHandle nfkc = factory->NewFromString("NFKC"); JSHandle nfkd = factory->NewFromString("NFKD"); - if (formValue->Compare(*nfc) != 0 && formValue->Compare(*nfd) != 0 && formValue->Compare(*nfkc) != 0 && - formValue->Compare(*nfkd) != 0) { + if (form_value->Compare(*nfc) != 0 && form_value->Compare(*nfd) != 0 && form_value->Compare(*nfkc) != 0 && + form_value->Compare(*nfkd) != 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "compare not equal", JSTaggedValue::Exception()); } - std::u16string u16strThis; - if (thisHandle->IsUtf16()) { - u16strThis = - ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisHandle->GetLength()); + std::u16string u16str_this; + if (this_handle->IsUtf16()) { + u16str_this = + ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_handle->GetLength()); } else { - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisHandle->GetLength()); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_handle->GetLength()); } - const char16_t *constChar16tData = u16strThis.data(); - icu::UnicodeString src(constChar16tData); + const char16_t *const_char16t_data = u16str_this.data(); + icu::UnicodeString src(const_char16t_data); icu::UnicodeString res; - UErrorCode errorCode = U_ZERO_ERROR; - UNormalizationMode uForm; + UErrorCode error_code = U_ZERO_ERROR; + UNormalizationMode u_form; int32_t option = 0; - if (formValue->Compare(*nfc) == 0) { - uForm = UNORM_NFC; - } else if (formValue->Compare(*nfd) == 0) { - uForm = UNORM_NFD; - } else if (formValue->Compare(*nfkc) == 0) { - uForm = UNORM_NFKC; - } else if (formValue->Compare(*nfkd) == 0) { - uForm = UNORM_NFKD; + if (form_value->Compare(*nfc) == 0) { + u_form = UNORM_NFC; + } else if (form_value->Compare(*nfd) == 0) { + u_form = UNORM_NFD; + } else if (form_value->Compare(*nfkc) == 0) { + u_form = UNORM_NFKC; + } else if (form_value->Compare(*nfkd) == 0) { + u_form = UNORM_NFKD; } else { UNREACHABLE(); } - icu::Normalizer::normalize(src, uForm, option, res, errorCode); + icu::Normalizer::normalize(src, u_form, option, res, error_code); JSHandle str = JSLocale::IcuToString(thread, res); return JSTaggedValue(*str); } // ES2021 22.1.3.14 -JSTaggedValue BuiltinsString::padEnd(EcmaRuntimeCallInfo *argv) +JSTaggedValue BuiltinsString::PadEnd(EcmaRuntimeCallInfo *argv) { // 1. Let O be ? RequireObjectCoercible(this value). JSThread *thread = argv->GetThread(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return ? StringPad(O, maxLength, fillString, start). - return base::StringHelper::StringPad(thread, thisTag, BuiltinsString::GetCallArg(argv, 0), + return base::StringHelper::StringPad(thread, this_tag, BuiltinsString::GetCallArg(argv, 0), BuiltinsString::GetCallArg(argv, 1), base::PadPlacement::END); } // ES2021 22.1.3.15 -JSTaggedValue BuiltinsString::padStart(EcmaRuntimeCallInfo *argv) +JSTaggedValue BuiltinsString::PadStart(EcmaRuntimeCallInfo *argv) { // 1. Let O be ? RequireObjectCoercible(this value). JSThread *thread = argv->GetThread(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return ? StringPad(O, maxLength, fillString, start). - return base::StringHelper::StringPad(thread, thisTag, BuiltinsString::GetCallArg(argv, 0), + return base::StringHelper::StringPad(thread, this_tag, BuiltinsString::GetCallArg(argv, 0), BuiltinsString::GetCallArg(argv, 1), base::PadPlacement::START); } @@ -770,13 +771,13 @@ JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Repeat); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - JSHandle countTag = BuiltinsString::GetCallArg(argv, 0); - JSTaggedNumber num = JSTaggedValue::ToInteger(thread, countTag); + int32_t this_len = this_handle->GetLength(); + JSHandle count_tag = BuiltinsString::GetCallArg(argv, 0); + JSTaggedNumber num = JSTaggedValue::ToInteger(thread, count_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); double d = num.GetNumber(); if (d < 0) { @@ -786,20 +787,20 @@ JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv) THROW_RANGE_ERROR_AND_RETURN(thread, "is infinity", JSTaggedValue::Exception()); } int32_t count = ecmascript::base::NumberHelper::DoubleInRangeInt32(d); - std::u16string u16strThis; + std::u16string u16str_this; bool can_be_compress = true; - if (thisHandle->IsUtf16()) { - u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + if (this_handle->IsUtf16()) { + u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); can_be_compress = false; } else { - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); } - if (thisLen == 0) { - return thisHandle.GetTaggedValue(); + if (this_len == 0) { + return this_handle.GetTaggedValue(); } - EcmaString *res = ecmascript::base::StringHelper::Repeat(thread, u16strThis, count, can_be_compress); + EcmaString *res = ecmascript::base::StringHelper::Repeat(thread, u16str_this, count, can_be_compress); return JSTaggedValue(res); } @@ -809,101 +810,102 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Replace); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle replaceTag = BuiltinsString::GetCallArg(argv, 1); + 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); - ObjectFactory *factory = ecmaVm->GetFactory(); + ObjectFactory *factory = ecma_vm->GetFactory(); - if (searchTag->IsJSRegExp() && replaceTag->IsString()) { - JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - JSHandle re(searchTag); + if (search_tag->IsJSRegExp() && replace_tag->IsString()) { + JSHandle cache_table(thread->GetEcmaVM()->GetRegExpCache()); + JSHandle re(search_tag); JSHandle pattern(thread, re->GetOriginalSource()); JSHandle flags(thread, re->GetOriginalFlags()); - JSTaggedValue cacheResult = - cacheTable->FindCachedResult(thread, pattern, flags, thisTag, RegExpExecResultCache::REPLACE_TYPE, - searchTag, replaceTag.GetTaggedValue()); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; + JSTaggedValue cache_result = + cache_table->FindCachedResult(thread, pattern, flags, this_tag, RegExpExecResultCache::REPLACE_TYPE, + search_tag, replace_tag.GetTaggedValue()); + if (cache_result != JSTaggedValue::Undefined()) { + return cache_result; } } // If searchValue is neither undefined nor null, then - if (searchTag->IsECMAObject()) { - JSHandle replaceKey = env->GetReplaceSymbol(); + if (search_tag->IsECMAObject()) { + JSHandle replace_key = env->GetReplaceSymbol(); // Let replacer be GetMethod(searchValue, @@replace). - JSHandle replaceMethod = JSObject::GetMethod(thread, searchTag, replaceKey); + JSHandle replace_method = JSObject::GetMethod(thread, search_tag, replace_key); // ReturnIfAbrupt(replacer). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If replacer is not undefined, then - if (!replaceMethod->IsUndefined()) { + if (!replace_method->IsUndefined()) { // Return Call(replacer, searchValue, «O, replaceValue»). - auto info = NewRuntimeCallInfo(thread, replaceMethod, searchTag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(thisTag, replaceTag); - return JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, replace_method, search_tag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(this_tag, replace_tag); + return JSFunction::Call(info.Get()); // 2: two args } } // Let string be ToString(O). - JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); // ReturnIfAbrupt(string). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let searchString be ToString(searchValue). - JSHandle searchString = JSTaggedValue::ToString(thread, searchTag); + JSHandle search_string = JSTaggedValue::ToString(thread, search_tag); // ReturnIfAbrupt(searchString). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let functionalReplace be IsCallable(replaceValue). - if (!replaceTag->IsCallable()) { + if (!replace_tag->IsCallable()) { // If functionalReplace is false, then // Let replaceValue be ToString(replaceValue). // ReturnIfAbrupt(replaceValue) - replaceTag = JSHandle(JSTaggedValue::ToString(thread, replaceTag)); + replace_tag = JSHandle(JSTaggedValue::ToString(thread, replace_tag)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // Search string for the first occurrence of searchString and let pos be the index within string of the first code // unit of the matched substring and let matched be searchString. If no occurrences of searchString were found, // return string. - int32_t pos = thisString->IndexOf(*searchString); + int32_t pos = this_string->IndexOf(*search_string); if (pos == -1) { - return thisString.GetTaggedValue(); + return this_string.GetTaggedValue(); } - JSMutableHandle replHandle(thread, factory->GetEmptyString().GetTaggedValue()); + JSMutableHandle repl_handle(thread, factory->GetEmptyString().GetTaggedValue()); // If functionalReplace is true, then - if (replaceTag->IsCallable()) { + if (replace_tag->IsCallable()) { // Let replValue be Call(replaceValue, undefined,«matched, pos, and string»). - auto info = NewRuntimeCallInfo(thread, replaceTag, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 3); - info->SetCallArgs(searchString, JSTaggedValue(pos), thisString); - JSTaggedValue replStrDeocodeValue = JSFunction::Call(info.get()); // 3: «matched, pos, and string» - replHandle.Update(replStrDeocodeValue); + auto info = NewRuntimeCallInfo(thread, replace_tag, JSTaggedValue::Undefined(), JSTaggedValue::Undefined(), 3); + info->SetCallArgs(search_string, JSTaggedValue(pos), this_string); + JSTaggedValue repl_str_deocode_value = JSFunction::Call(info.Get()); // 3: «matched, pos, and string» + repl_handle.Update(repl_str_deocode_value); } else { - JSHandle undefined = globalConst->GetHandledUndefined(); + JSHandle undefined = global_const->GetHandledUndefined(); // Let captures be an empty List. - JSHandle capturesList = factory->EmptyArray(); - ASSERT_PRINT(replaceTag->IsString(), "replace must be string"); - JSHandle replacement(thread, replaceTag->GetTaggedObject()); + JSHandle captures_list = factory->EmptyArray(); + ASSERT_PRINT(replace_tag->IsString(), "replace must be string"); + JSHandle replacement(thread, replace_tag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) - replHandle.Update(GetSubstitution(thread, searchString, thisString, pos, capturesList, undefined, replacement)); + repl_handle.Update( + GetSubstitution(thread, search_string, this_string, pos, captures_list, undefined, replacement)); } - JSHandle realReplaceStr = JSTaggedValue::ToString(thread, replHandle); + JSHandle real_replace_str = JSTaggedValue::ToString(thread, repl_handle); // Let tailPos be pos + the number of code units in matched. - int32_t tailPos = pos + searchString->GetLength(); + int32_t tail_pos = pos + search_string->GetLength(); // Let newString be the String formed by concatenating the first pos code units of string, replStr, and the trailing // substring of string starting at index tailPos. If pos is 0, the first element of the concatenation will be the // empty String. // Return newString. - JSHandle prefixString(thread, EcmaString::FastSubString(thisString, 0, pos, ecmaVm)); - JSHandle suffixString( - thread, EcmaString::FastSubString(thisString, tailPos, thisString->GetLength() - tailPos, ecmaVm)); - JSHandle tempString(thread, EcmaString::Concat(prefixString, realReplaceStr, ecmaVm)); - return JSTaggedValue(EcmaString::Concat(tempString, suffixString, ecmaVm)); + JSHandle prefix_string(thread, EcmaString::FastSubString(this_string, 0, pos, ecma_vm)); + JSHandle suffix_string( + thread, EcmaString::FastSubString(this_string, tail_pos, this_string->GetLength() - tail_pos, ecma_vm)); + JSHandle temp_string(thread, EcmaString::Concat(prefix_string, real_replace_str, ecma_vm)); + return JSTaggedValue(EcmaString::Concat(temp_string, suffix_string, ecma_vm)); } // ES2021 22.1.3.18 @@ -913,36 +915,36 @@ JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) ASSERT(argv); JSThread *thread = argv->GetThread(); BUILTINS_API_TRACE(thread, String, ReplaceAll); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle replaceTag = BuiltinsString::GetCallArg(argv, 1); + 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); - ObjectFactory *factory = ecmaVm->GetFactory(); + ObjectFactory *factory = ecma_vm->GetFactory(); - if (!searchTag->IsUndefined() && !searchTag->IsNull()) { + if (!search_tag->IsUndefined() && !search_tag->IsNull()) { // a. Let isRegExp be ? IsRegExp(searchValue). - bool isJSRegExp = JSObject::IsRegExp(thread, searchTag); + bool is_js_reg_exp = JSObject::IsRegExp(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // b. If isRegExp is true, then - if (isJSRegExp) { + if (is_js_reg_exp) { // i. Let flags be ? Get(searchValue, "flags"). - JSHandle flagsString(globalConst->GetHandledFlagsString()); - JSHandle flags = JSObject::GetProperty(thread, searchTag, flagsString).GetValue(); + JSHandle flags_string(global_const->GetHandledFlagsString()); + JSHandle flags = JSObject::GetProperty(thread, search_tag, flags_string).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // ii. Perform ? RequireObjectCoercible(flags). JSTaggedValue::RequireObjectCoercible(thread, flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // iii. If ? ToString(flags) does not contain "g", throw a TypeError exception. - JSHandle flagString = JSTaggedValue::ToString(thread, flags); + JSHandle flag_string = JSTaggedValue::ToString(thread, flags); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle gString(globalConst->GetHandledGString()); - int32_t pos = flagString->IndexOf(*gString); + JSHandle g_string(global_const->GetHandledGString()); + int32_t pos = flag_string->IndexOf(*g_string); if (pos == -1) { THROW_TYPE_ERROR_AND_RETURN(thread, "string.prototype.replaceAll called with a non-global RegExp argument", @@ -950,204 +952,206 @@ JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) } } // c. Let replacer be ? GetMethod(searchValue, @@replace). - JSHandle replaceKey = env->GetReplaceSymbol(); - JSHandle replaceMethod = JSObject::GetMethod(thread, searchTag, replaceKey); + JSHandle replace_key = env->GetReplaceSymbol(); + JSHandle replace_method = JSObject::GetMethod(thread, search_tag, replace_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. If replacer is not undefined, then - if (!replaceMethod->IsUndefined()) { + if (!replace_method->IsUndefined()) { // i. Return ? Call(replacer, searchValue, «O, replaceValue»). - auto info = NewRuntimeCallInfo(thread, replaceMethod, searchTag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(thisTag.GetTaggedValue(), replaceTag.GetTaggedValue()); - return JSFunction::Call(info.get()); + auto info = NewRuntimeCallInfo(thread, replace_method, search_tag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(this_tag.GetTaggedValue(), replace_tag.GetTaggedValue()); + return JSFunction::Call(info.Get()); } } // 3. Let string be ? ToString(O). - JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 4. Let searchString be ? ToString(searchValue). - JSHandle searchString = JSTaggedValue::ToString(thread, searchTag); + JSHandle search_string = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. Let functionalReplace be IsCallable(replaceValue). // 6. If functionalReplace is false, then - if (!replaceTag->IsCallable()) { + if (!replace_tag->IsCallable()) { // a. Set replaceValue to ? ToString(replaceValue). - replaceTag = JSHandle(JSTaggedValue::ToString(thread, replaceTag)); + replace_tag = JSHandle(JSTaggedValue::ToString(thread, replace_tag)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 7. Let searchLength be the length of searchString. // 8. Let advanceBy be max(1, searchLength). - int32_t searchLength = searchString->GetLength(); - int32_t advanceBy = std::max(1, searchLength); + int32_t search_length = search_string->GetLength(); + int32_t advance_by = std::max(1, search_length); // 9. Let matchPositions be a new empty List. - std::u16string stringBuilder; - std::u16string stringPrefixString; - std::u16string stringRealReplaceStr; - std::u16string stringSuffixString; + std::u16string string_builder; + std::u16string string_prefix_string; + std::u16string string_real_replace_str; + std::u16string string_suffix_string; // 10. Let position be ! StringIndexOf(string, searchString, 0). - int32_t pos = thisString->IndexOf(*searchString); - int32_t endOfLastMatch = 0; + int32_t pos = this_string->IndexOf(*search_string); + int32_t end_of_last_match = 0; bool can_be_compress = true; - JSHandle undefined = globalConst->GetHandledUndefined(); - JSMutableHandle replHandle(thread, factory->GetEmptyString().GetTaggedValue()); + JSHandle undefined = global_const->GetHandledUndefined(); + JSMutableHandle repl_handle(thread, factory->GetEmptyString().GetTaggedValue()); while (pos != -1) { // If functionalReplace is true, then - if (replaceTag->IsCallable()) { + if (replace_tag->IsCallable()) { // Let replValue be Call(replaceValue, undefined, «matched, pos, and string»). - auto info = NewRuntimeCallInfo(thread, replaceTag, undefined, JSTaggedValue::Undefined(), 3U); - info->SetCallArgs(searchString.GetTaggedValue(), JSTaggedValue(pos), thisString.GetTaggedValue()); - JSTaggedValue replStrDeocodeValue = JSFunction::Call(info.get()); - replHandle.Update(replStrDeocodeValue); + auto info = NewRuntimeCallInfo(thread, replace_tag, undefined, JSTaggedValue::Undefined(), 3U); + info->SetCallArgs(search_string.GetTaggedValue(), JSTaggedValue(pos), this_string.GetTaggedValue()); + JSTaggedValue repl_str_deocode_value = JSFunction::Call(info.Get()); + repl_handle.Update(repl_str_deocode_value); } else { // Let captures be an empty List. - JSHandle capturesList = factory->NewTaggedArray(0); - ASSERT_PRINT(replaceTag->IsString(), "replace must be string"); - JSHandle replacement(thread, replaceTag->GetTaggedObject()); + JSHandle captures_list = factory->NewTaggedArray(0); + ASSERT_PRINT(replace_tag->IsString(), "replace must be string"); + JSHandle replacement(thread, replace_tag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) - replHandle.Update( - GetSubstitution(thread, searchString, thisString, pos, capturesList, undefined, replacement)); + repl_handle.Update( + GetSubstitution(thread, search_string, this_string, pos, captures_list, undefined, replacement)); } - JSHandle realReplaceStr = JSTaggedValue::ToString(thread, replHandle); + JSHandle real_replace_str = JSTaggedValue::ToString(thread, repl_handle); // Let tailPos be pos + the number of code units in matched. // Let newString be the String formed by concatenating the first pos code units of string, // replStr, and the trailing substring of string starting at index tailPos. // If pos is 0, the first element of the concatenation will be the // empty String. // Return newString. - JSHandle prefixString( - thread, EcmaString::FastSubString(thisString, endOfLastMatch, pos - endOfLastMatch, ecmaVm)); - if (prefixString->IsUtf16()) { - const uint16_t *data = prefixString->GetDataUtf16(); - stringPrefixString = base::StringHelper::Utf16ToU16String(data, prefixString->GetLength()); + JSHandle prefix_string( + thread, EcmaString::FastSubString(this_string, end_of_last_match, pos - end_of_last_match, ecma_vm)); + if (prefix_string->IsUtf16()) { + const uint16_t *data = prefix_string->GetDataUtf16(); + string_prefix_string = base::StringHelper::Utf16ToU16String(data, prefix_string->GetLength()); can_be_compress = false; } else { - const uint8_t *data = prefixString->GetDataUtf8(); - stringPrefixString = base::StringHelper::Utf8ToU16String(data, prefixString->GetLength()); + const uint8_t *data = prefix_string->GetDataUtf8(); + string_prefix_string = base::StringHelper::Utf8ToU16String(data, prefix_string->GetLength()); } - if (realReplaceStr->IsUtf16()) { - const uint16_t *data = realReplaceStr->GetDataUtf16(); - stringRealReplaceStr = base::StringHelper::Utf16ToU16String(data, realReplaceStr->GetLength()); + if (real_replace_str->IsUtf16()) { + const uint16_t *data = real_replace_str->GetDataUtf16(); + string_real_replace_str = base::StringHelper::Utf16ToU16String(data, real_replace_str->GetLength()); can_be_compress = false; } else { - const uint8_t *data = realReplaceStr->GetDataUtf8(); - stringRealReplaceStr = base::StringHelper::Utf8ToU16String(data, realReplaceStr->GetLength()); + const uint8_t *data = real_replace_str->GetDataUtf8(); + string_real_replace_str = base::StringHelper::Utf8ToU16String(data, real_replace_str->GetLength()); } - stringBuilder.append(stringPrefixString); - stringBuilder.append(stringRealReplaceStr); - endOfLastMatch = pos + searchLength; - pos = thisString->IndexOf(*searchString, pos + advanceBy); - } - - if (endOfLastMatch < static_cast(thisString->GetLength())) { - JSHandle suffixString( - thread, - EcmaString::FastSubString(thisString, endOfLastMatch, thisString->GetLength() - endOfLastMatch, ecmaVm)); - if (suffixString->IsUtf16()) { - const uint16_t *data = suffixString->GetDataUtf16(); - stringSuffixString = base::StringHelper::Utf16ToU16String(data, suffixString->GetLength()); + string_builder.append(string_prefix_string); + string_builder.append(string_real_replace_str); + end_of_last_match = pos + search_length; + pos = this_string->IndexOf(*search_string, pos + advance_by); + } + + if (end_of_last_match < static_cast(this_string->GetLength())) { + JSHandle suffix_string( + thread, EcmaString::FastSubString(this_string, end_of_last_match, + this_string->GetLength() - end_of_last_match, ecma_vm)); + if (suffix_string->IsUtf16()) { + const uint16_t *data = suffix_string->GetDataUtf16(); + string_suffix_string = base::StringHelper::Utf16ToU16String(data, suffix_string->GetLength()); can_be_compress = false; } else { - const uint8_t *data = suffixString->GetDataUtf8(); - stringSuffixString = base::StringHelper::Utf8ToU16String(data, suffixString->GetLength()); + const uint8_t *data = suffix_string->GetDataUtf8(); + string_suffix_string = base::StringHelper::Utf8ToU16String(data, suffix_string->GetLength()); } - stringBuilder = stringBuilder + stringSuffixString; + string_builder = string_builder + string_suffix_string; } - auto *char16tData = const_cast(stringBuilder.c_str()); - auto *uint16tData = reinterpret_cast(char16tData); - return factory->NewFromUtf16LiteralUnCheck(uint16tData, stringBuilder.length(), can_be_compress).GetTaggedValue(); + auto *char16t_data = const_cast(string_builder.c_str()); + auto *uint16t_data = reinterpret_cast(char16t_data); + return factory->NewFromUtf16LiteralUnCheck(uint16t_data, string_builder.length(), can_be_compress).GetTaggedValue(); } // NOLINTNEXTLINE(readability-function-size) JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle &matched, - const JSHandle &srcString, int position, - const JSHandle &captureList, - const JSHandle &namedCaptures, + const JSHandle &src_string, int position, + const JSHandle &capture_list, + const JSHandle &named_captures, const JSHandle &replacement) { BUILTINS_API_TRACE(thread, String, GetSubstitution); - auto ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - JSHandle dollarString = JSHandle::Cast(thread->GlobalConstants()->GetHandledDollarString()); - int32_t replaceLength = replacement->GetLength(); - int32_t tailPos = position + static_cast(matched->GetLength()); - - int32_t nextDollarIndex = replacement->IndexOf(*dollarString, 0); - if (nextDollarIndex < 0) { + auto ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + JSHandle dollar_string = + JSHandle::Cast(thread->GlobalConstants()->GetHandledDollarString()); + int32_t replace_length = replacement->GetLength(); + int32_t tail_pos = position + static_cast(matched->GetLength()); + + int32_t next_dollar_index = replacement->IndexOf(*dollar_string, 0); + if (next_dollar_index < 0) { return replacement.GetTaggedValue(); } - std::u16string stringBuilder; + std::u16string string_builder; bool can_be_compress = true; - if (nextDollarIndex > 0) { + if (next_dollar_index > 0) { if (replacement->IsUtf16()) { const uint16_t *data = replacement->GetDataUtf16(); - stringBuilder += base::StringHelper::Utf16ToU16String(data, nextDollarIndex); + string_builder += base::StringHelper::Utf16ToU16String(data, next_dollar_index); can_be_compress = false; } else { const uint8_t *data = replacement->GetDataUtf8(); - stringBuilder += base::StringHelper::Utf8ToU16String(data, nextDollarIndex); + string_builder += base::StringHelper::Utf8ToU16String(data, next_dollar_index); } } while (true) { - int peekIndex = nextDollarIndex + 1; - if (peekIndex >= replaceLength) { - stringBuilder += '$'; - auto *char16tData = const_cast(stringBuilder.c_str()); - auto *uint16tData = reinterpret_cast(char16tData); - return factory->NewFromUtf16LiteralUnCheck(uint16tData, stringBuilder.length(), can_be_compress) + int peek_index = next_dollar_index + 1; + if (peek_index >= replace_length) { + string_builder += '$'; + auto *char16t_data = const_cast(string_builder.c_str()); + auto *uint16t_data = reinterpret_cast(char16t_data); + return factory->NewFromUtf16LiteralUnCheck(uint16t_data, string_builder.length(), can_be_compress) .GetTaggedValue(); } - int continueFromIndex = -1; - uint16_t peek = replacement->At(peekIndex); + int continue_from_index = -1; + uint16_t peek = replacement->At(peek_index); switch (peek) { case '$': // $$ - stringBuilder += '$'; - continueFromIndex = peekIndex + 1; + string_builder += '$'; + continue_from_index = peek_index + 1; break; case '&': // $& - match if (matched->IsUtf16()) { const uint16_t *data = matched->GetDataUtf16(); - stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, matched->GetLength()); + string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, matched->GetLength()); can_be_compress = false; } else { const uint8_t *data = matched->GetDataUtf8(); - stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, matched->GetLength()); + string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, matched->GetLength()); } - continueFromIndex = peekIndex + 1; + continue_from_index = peek_index + 1; break; case '`': // $` - prefix if (position > 0) { - EcmaString *prefix = EcmaString::FastSubString(srcString, 0, position, ecmaVm); + EcmaString *prefix = EcmaString::FastSubString(src_string, 0, position, ecma_vm); if (prefix->IsUtf16()) { const uint16_t *data = prefix->GetDataUtf16(); - stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, prefix->GetLength()); + string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, prefix->GetLength()); can_be_compress = false; } else { const uint8_t *data = prefix->GetDataUtf8(); - stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, prefix->GetLength()); + string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, prefix->GetLength()); } } - continueFromIndex = peekIndex + 1; + continue_from_index = peek_index + 1; break; case '\'': { // $' - suffix - int32_t srcLength = srcString->GetLength(); - if (tailPos < srcLength) { - EcmaString *sufffix = EcmaString::FastSubString(srcString, tailPos, srcLength - tailPos, ecmaVm); + int32_t src_length = src_string->GetLength(); + if (tail_pos < src_length) { + EcmaString *sufffix = + EcmaString::FastSubString(src_string, tail_pos, src_length - tail_pos, ecma_vm); if (sufffix->IsUtf16()) { const uint16_t *data = sufffix->GetDataUtf16(); - stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, sufffix->GetLength()); + string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, sufffix->GetLength()); can_be_compress = false; } else { const uint8_t *data = sufffix->GetDataUtf8(); - stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, sufffix->GetLength()); + string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, sufffix->GetLength()); } } - continueFromIndex = peekIndex + 1; + continue_from_index = peek_index + 1; break; } case '0': @@ -1160,114 +1164,114 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleGetLength(); + int captures_length = capture_list->GetLength(); // Valid indices are $1 .. $9, $01 .. $09 and $10 .. $99 - int32_t scaledIndex = (peek - '0'); + int32_t scaled_index = (peek - '0'); int32_t advance = 1; - if (peekIndex + 1 < replaceLength) { - uint16_t nextPeek = replacement->At(peekIndex + 1); - if (nextPeek >= '0' && nextPeek <= '9') { + if (peek_index + 1 < replace_length) { + uint16_t next_peek = replacement->At(peek_index + 1); + if (next_peek >= '0' && next_peek <= '9') { constexpr int32_t TEN_BASE = 10; - int32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0'); - if (newScaledIndex <= capturesLength) { - scaledIndex = newScaledIndex; + int32_t new_scaled_index = scaled_index * TEN_BASE + (next_peek - '0'); + if (new_scaled_index <= captures_length) { + scaled_index = new_scaled_index; advance = 2; // 2: 2 means from index needs to add two. } } } - if (scaledIndex == 0 || scaledIndex > capturesLength) { - stringBuilder += '$'; - continueFromIndex = peekIndex; + if (scaled_index == 0 || scaled_index > captures_length) { + string_builder += '$'; + continue_from_index = peek_index; break; } - JSTaggedValue capturesVal(captureList->Get(scaledIndex - 1)); - if (!capturesVal.IsUndefined()) { - EcmaString *captureString = EcmaString::Cast(capturesVal.GetTaggedObject()); - if (captureString->IsUtf16()) { - const uint16_t *data = captureString->GetDataUtf16(); - stringBuilder += - ecmascript::base::StringHelper::Utf16ToU16String(data, captureString->GetLength()); + JSTaggedValue captures_val(capture_list->Get(scaled_index - 1)); + if (!captures_val.IsUndefined()) { + EcmaString *capture_string = EcmaString::Cast(captures_val.GetTaggedObject()); + if (capture_string->IsUtf16()) { + const uint16_t *data = capture_string->GetDataUtf16(); + string_builder += + ecmascript::base::StringHelper::Utf16ToU16String(data, capture_string->GetLength()); can_be_compress = false; } else { - const uint8_t *data = captureString->GetDataUtf8(); - stringBuilder += - ecmascript::base::StringHelper::Utf8ToU16String(data, captureString->GetLength()); + const uint8_t *data = capture_string->GetDataUtf8(); + string_builder += + ecmascript::base::StringHelper::Utf8ToU16String(data, capture_string->GetLength()); } } - continueFromIndex = peekIndex + advance; + continue_from_index = peek_index + advance; break; } case '<': { - if (namedCaptures->IsUndefined()) { - stringBuilder += '$'; - continueFromIndex = peekIndex; + if (named_captures->IsUndefined()) { + string_builder += '$'; + continue_from_index = peek_index; break; } - JSHandle greaterSymString = factory->NewFromStdString(">"); - int pos = replacement->IndexOf(*greaterSymString, peekIndex); + JSHandle greater_sym_string = factory->NewFromStdString(">"); + int pos = replacement->IndexOf(*greater_sym_string, peek_index); if (pos == -1) { - stringBuilder += '$'; - continueFromIndex = peekIndex; + string_builder += '$'; + continue_from_index = peek_index; break; } - JSHandle groupName( - thread, EcmaString::FastSubString(replacement, peekIndex + 1, pos - peekIndex - 1, ecmaVm)); - JSHandle names(groupName); - JSHandle capture = JSObject::GetProperty(thread, namedCaptures, names).GetValue(); + JSHandle group_name( + thread, EcmaString::FastSubString(replacement, peek_index + 1, pos - peek_index - 1, ecma_vm)); + JSHandle names(group_name); + JSHandle capture = JSObject::GetProperty(thread, named_captures, names).GetValue(); if (capture->IsUndefined()) { - continueFromIndex = pos + 1; + continue_from_index = pos + 1; break; } - JSHandle captureName(capture); - if (captureName->IsUtf16()) { - const uint16_t *data = captureName->GetDataUtf16(); - stringBuilder += base::StringHelper::Utf16ToU16String(data, captureName->GetLength()); + JSHandle capture_name(capture); + if (capture_name->IsUtf16()) { + const uint16_t *data = capture_name->GetDataUtf16(); + string_builder += base::StringHelper::Utf16ToU16String(data, capture_name->GetLength()); can_be_compress = false; } else { - const uint8_t *data = captureName->GetDataUtf8(); - stringBuilder += base::StringHelper::Utf8ToU16String(data, captureName->GetLength()); + const uint8_t *data = capture_name->GetDataUtf8(); + string_builder += base::StringHelper::Utf8ToU16String(data, capture_name->GetLength()); } - continueFromIndex = pos + 1; + continue_from_index = pos + 1; break; } default: - stringBuilder += '$'; - continueFromIndex = peekIndex; + string_builder += '$'; + continue_from_index = peek_index; break; } // Go the the next $ in the replacement. - nextDollarIndex = replacement->IndexOf(*dollarString, continueFromIndex); - if (nextDollarIndex < 0) { - if (continueFromIndex < replaceLength) { - EcmaString *nextAppend = EcmaString::FastSubString(replacement, continueFromIndex, - replaceLength - continueFromIndex, ecmaVm); - if (nextAppend->IsUtf16()) { - const uint16_t *data = nextAppend->GetDataUtf16(); - stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, nextAppend->GetLength()); + next_dollar_index = replacement->IndexOf(*dollar_string, continue_from_index); + if (next_dollar_index < 0) { + if (continue_from_index < replace_length) { + EcmaString *next_append = EcmaString::FastSubString(replacement, continue_from_index, + replace_length - continue_from_index, ecma_vm); + if (next_append->IsUtf16()) { + const uint16_t *data = next_append->GetDataUtf16(); + string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, next_append->GetLength()); can_be_compress = false; } else { - const uint8_t *data = nextAppend->GetDataUtf8(); - stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, nextAppend->GetLength()); + const uint8_t *data = next_append->GetDataUtf8(); + string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, next_append->GetLength()); } } - auto *char16tData = const_cast(stringBuilder.c_str()); - auto *uint16tData = reinterpret_cast(char16tData); - return factory->NewFromUtf16LiteralUnCheck(uint16tData, stringBuilder.length(), can_be_compress) + auto *char16t_data = const_cast(string_builder.c_str()); + auto *uint16t_data = reinterpret_cast(char16t_data); + return factory->NewFromUtf16LiteralUnCheck(uint16t_data, string_builder.length(), can_be_compress) .GetTaggedValue(); } // Append substring between the previous and the next $ character. - if (nextDollarIndex > continueFromIndex) { - EcmaString *nextAppend = - EcmaString::FastSubString(replacement, continueFromIndex, nextDollarIndex - continueFromIndex, ecmaVm); - if (nextAppend->IsUtf16()) { - const uint16_t *data = nextAppend->GetDataUtf16(); - stringBuilder += ecmascript::base::StringHelper::Utf16ToU16String(data, nextAppend->GetLength()); + if (next_dollar_index > continue_from_index) { + EcmaString *next_append = EcmaString::FastSubString(replacement, continue_from_index, + next_dollar_index - continue_from_index, ecma_vm); + if (next_append->IsUtf16()) { + const uint16_t *data = next_append->GetDataUtf16(); + string_builder += ecmascript::base::StringHelper::Utf16ToU16String(data, next_append->GetLength()); can_be_compress = false; } else { - const uint8_t *data = nextAppend->GetDataUtf8(); - stringBuilder += ecmascript::base::StringHelper::Utf8ToU16String(data, nextAppend->GetLength()); + const uint8_t *data = next_append->GetDataUtf8(); + string_builder += ecmascript::base::StringHelper::Utf8ToU16String(data, next_append->GetLength()); } } } @@ -1280,33 +1284,33 @@ JSTaggedValue BuiltinsString::Search(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Search); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + [[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 searchTag = thread->GetEcmaVM()->GetGlobalEnv()->GetSearchSymbol(); + JSHandle search_tag = thread->GetEcmaVM()->GetGlobalEnv()->GetSearchSymbol(); if (!regexp->IsUndefined() && !regexp->IsNull()) { if (regexp->IsECMAObject()) { - JSHandle searcher = JSObject::GetMethod(thread, regexp, searchTag); + JSHandle searcher = JSObject::GetMethod(thread, regexp, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!searcher->IsUndefined()) { ASSERT(searcher->IsJSFunction()); auto info = NewRuntimeCallInfo(thread, searcher, regexp, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thisTag); - return JSFunction::Call(info.get()); + info->SetCallArgs(this_tag); + return JSFunction::Call(info.Get()); } } } - JSHandle thisVal = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_val = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle undifinedHandle = globalConst->GetHandledUndefined(); - JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifinedHandle)); + JSHandle undifined_handle = global_const->GetHandledUndefined(); + JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifined_handle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); auto info = NewRuntimeCallInfo(thread, JSTaggedValue::Undefined(), rx, JSTaggedValue::Undefined(), 1); - info->SetCallArgs(thisVal.GetTaggedValue()); - return JSFunction::Invoke(info.get(), searchTag); + info->SetCallArgs(this_val.GetTaggedValue()); + return JSFunction::Invoke(info.Get(), search_tag); } // 21.1.3.16 @@ -1315,39 +1319,39 @@ JSTaggedValue BuiltinsString::Slice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Slice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - JSHandle startTag = BuiltinsString::GetCallArg(argv, 0); - JSTaggedNumber startVal = JSTaggedValue::ToInteger(thread, startTag); + int32_t this_len = this_handle->GetLength(); + JSHandle start_tag = BuiltinsString::GetCallArg(argv, 0); + JSTaggedNumber start_val = JSTaggedValue::ToInteger(thread, start_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t start = ConvertDoubleToInt(startVal.GetNumber()); + int32_t start = ConvertDoubleToInt(start_val.GetNumber()); int32_t end; - JSHandle endTag = BuiltinsString::GetCallArg(argv, 1); - if (endTag->IsUndefined()) { - end = thisLen; + JSHandle end_tag = BuiltinsString::GetCallArg(argv, 1); + if (end_tag->IsUndefined()) { + end = this_len; } else { - JSTaggedNumber endVal = JSTaggedValue::ToInteger(thread, endTag); + JSTaggedNumber end_val = JSTaggedValue::ToInteger(thread, end_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = ConvertDoubleToInt(endVal.GetNumber()); + end = ConvertDoubleToInt(end_val.GetNumber()); } int32_t from; int32_t to; if (start < 0) { - from = std::max(start + thisLen, 0); + from = std::max(start + this_len, 0); } else { - from = std::min(start, thisLen); + from = std::min(start, this_len); } if (end < 0) { - to = std::max(end + thisLen, 0); + to = std::max(end + this_len, 0); } else { - to = std::min(end, thisLen); + to = std::min(end, this_len); } int32_t len = std::max(to - from, 0); - return JSTaggedValue(EcmaString::FastSubString(thisHandle, from, len, thread->GetEcmaVM())); + return JSTaggedValue(EcmaString::FastSubString(this_handle, from, len, thread->GetEcmaVM())); } // 21.1.3.17 @@ -1356,104 +1360,104 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Split); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - auto ecmaVm = thread->GetEcmaVM(); - JSHandle env = ecmaVm->GetGlobalEnv(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + auto ecma_vm = thread->GetEcmaVM(); + JSHandle env = ecma_vm->GetGlobalEnv(); // Let O be RequireObjectCoercible(this value). - JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)); - JSHandle thisObj(thisTag); + JSHandle this_tag = JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)); + JSHandle this_obj(this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle seperatorTag = BuiltinsString::GetCallArg(argv, 0); - JSHandle limitTag = BuiltinsString::GetCallArg(argv, 1); + JSHandle seperator_tag = BuiltinsString::GetCallArg(argv, 0); + JSHandle limit_tag = BuiltinsString::GetCallArg(argv, 1); // If separator is neither undefined nor null, then - if (seperatorTag->IsECMAObject()) { - JSHandle splitKey = env->GetSplitSymbol(); + if (seperator_tag->IsECMAObject()) { + JSHandle split_key = env->GetSplitSymbol(); // Let splitter be GetMethod(separator, @@split). - JSHandle splitter = JSObject::GetMethod(thread, seperatorTag, splitKey); + JSHandle splitter = JSObject::GetMethod(thread, seperator_tag, split_key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!splitter->IsUndefined()) { // Return Call(splitter, separator, «‍O, limit»). - auto info = NewRuntimeCallInfo(thread, splitter, seperatorTag, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(thisTag, limitTag); - return JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, splitter, seperator_tag, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(this_tag, limit_tag); + return JSFunction::Call(info.Get()); // 2: two args } } // Let S be ToString(O). - JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let A be ArrayCreate(0). - JSHandle resultArray(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); - uint32_t arrayLength = 0; + JSHandle result_array(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); + uint32_t array_length = 0; // If limit is undefined, let lim = 2^53–1; else let lim = ToLength(limit). uint32_t lim; - if (limitTag->IsUndefined()) { + if (limit_tag->IsUndefined()) { lim = UINT32_MAX - 1; } else { - JSTaggedNumber limVal = JSTaggedValue::ToInteger(thread, limitTag); + JSTaggedNumber lim_val = JSTaggedValue::ToInteger(thread, limit_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - lim = limVal.ToUint32(); + lim = lim_val.ToUint32(); } // ReturnIfAbrupt(lim). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If lim = 0, return A. if (lim == 0) { - return resultArray.GetTaggedValue(); + return result_array.GetTaggedValue(); } // Let s be the number of elements in S. - int32_t thisLength = thisString->GetLength(); - JSHandle seperatorString = JSTaggedValue::ToString(thread, seperatorTag); + int32_t this_length = this_string->GetLength(); + JSHandle seperator_string = JSTaggedValue::ToString(thread, seperator_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (seperatorTag->IsUndefined()) { + if (seperator_tag->IsUndefined()) { // Perform CreateDataProperty(A, "0", S). - JSObject::CreateDataProperty(thread, resultArray, 0, JSHandle(thisString)); + JSObject::CreateDataProperty(thread, result_array, 0, JSHandle(this_string)); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty(A, \"0\", S) can't throw exception"); - return resultArray.GetTaggedValue(); + return result_array.GetTaggedValue(); } // If S.length = 0, then - if (thisLength == 0) { - if (thisString->IndexOf(*seperatorString, 0) != -1) { - return resultArray.GetTaggedValue(); + if (this_length == 0) { + if (this_string->IndexOf(*seperator_string, 0) != -1) { + return result_array.GetTaggedValue(); } - JSObject::CreateDataProperty(thread, resultArray, 0, JSHandle(thisString)); + JSObject::CreateDataProperty(thread, result_array, 0, JSHandle(this_string)); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty(A, \"0\", S) can't throw exception"); - return resultArray.GetTaggedValue(); + return result_array.GetTaggedValue(); } - int32_t seperatorLength = seperatorString->GetLength(); - if (seperatorLength == 0) { - for (int32_t i = 0; i < thisLength; ++i) { - EcmaString *elementString = EcmaString::FastSubString(thisString, i, 1, ecmaVm); - JSHandle elementTag(thread, elementString); - JSObject::CreateDataProperty(thread, resultArray, arrayLength, elementTag); + int32_t seperator_length = seperator_string->GetLength(); + if (seperator_length == 0) { + for (int32_t i = 0; i < this_length; ++i) { + EcmaString *element_string = EcmaString::FastSubString(this_string, i, 1, ecma_vm); + JSHandle element_tag(thread, element_string); + JSObject::CreateDataProperty(thread, result_array, array_length, element_tag); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty can't throw exception"); - ++arrayLength; - if (arrayLength == lim) { - return resultArray.GetTaggedValue(); + ++array_length; + if (array_length == lim) { + return result_array.GetTaggedValue(); } } - return resultArray.GetTaggedValue(); + return result_array.GetTaggedValue(); } int32_t index = 0; - int32_t pos = thisString->IndexOf(*seperatorString); + int32_t pos = this_string->IndexOf(*seperator_string); while (pos != -1) { - EcmaString *elementString = EcmaString::FastSubString(thisString, index, pos - index, ecmaVm); - JSHandle elementTag(thread, elementString); - JSObject::CreateDataProperty(thread, resultArray, arrayLength, elementTag); + EcmaString *element_string = EcmaString::FastSubString(this_string, index, pos - index, ecma_vm); + JSHandle element_tag(thread, element_string); + JSObject::CreateDataProperty(thread, result_array, array_length, element_tag); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty can't throw exception"); - ++arrayLength; - if (arrayLength == lim) { - return resultArray.GetTaggedValue(); + ++array_length; + if (array_length == lim) { + return result_array.GetTaggedValue(); } - index = pos + seperatorLength; - pos = thisString->IndexOf(*seperatorString, index); + index = pos + seperator_length; + pos = this_string->IndexOf(*seperator_string, index); } - EcmaString *elementString = EcmaString::FastSubString(thisString, index, thisLength - index, ecmaVm); - JSHandle elementTag(thread, elementString); - JSObject::CreateDataProperty(thread, resultArray, arrayLength, elementTag); + EcmaString *element_string = EcmaString::FastSubString(this_string, index, this_length - index, ecma_vm); + JSHandle element_tag(thread, element_string); + JSObject::CreateDataProperty(thread, result_array, array_length, element_tag); ASSERT_PRINT(!thread->HasPendingException(), "CreateDataProperty can't throw exception"); - return resultArray.GetTaggedValue(); + return result_array.GetTaggedValue(); } int32_t BuiltinsString::SplitMatch(const JSHandle &str, int32_t q, const JSHandle ®) @@ -1478,49 +1482,49 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, StartsWith); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle search_tag = BuiltinsString::GetCallArg(argv, 0); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool isRegexp = JSObject::IsRegExp(thread, searchTag); - if (isRegexp) { + bool is_regexp = JSObject::IsRegExp(thread, search_tag); + if (is_regexp) { THROW_TYPE_ERROR_AND_RETURN(thread, "is regexp", JSTaggedValue::Exception()); } - JSHandle searchHandle = JSTaggedValue::ToString(thread, searchTag); + JSHandle search_handle = JSTaggedValue::ToString(thread, search_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - int32_t searchLen = searchHandle->GetLength(); + int32_t this_len = this_handle->GetLength(); + int32_t search_len = search_handle->GetLength(); int32_t pos; - JSHandle posTag = BuiltinsString::GetCallArg(argv, 1); - if (posTag->IsUndefined()) { + JSHandle pos_tag = BuiltinsString::GetCallArg(argv, 1); + if (pos_tag->IsUndefined()) { pos = 0; } else { - JSTaggedNumber posVal = JSTaggedValue::ToInteger(thread, posTag); + JSTaggedNumber pos_val = JSTaggedValue::ToInteger(thread, pos_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - pos = posVal.ToInt32(); + pos = pos_val.ToInt32(); } - pos = std::min(std::max(pos, 0), thisLen); - if (pos + searchLen > thisLen) { + pos = std::min(std::max(pos, 0), this_len); + if (pos + search_len > this_len) { return BuiltinsString::GetTaggedBoolean(false); } - std::u16string u16strThis; - std::u16string u16strSearch; - if (thisHandle->IsUtf16()) { - u16strThis = ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + std::u16string u16str_this; + std::u16string u16str_search; + if (this_handle->IsUtf16()) { + u16str_this = ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); } else { - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - u16strThis = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + u16str_this = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); } - if (searchHandle->IsUtf16()) { - u16strSearch = ecmascript::base::StringHelper::Utf16ToU16String(searchHandle->GetDataUtf16(), searchLen); + if (search_handle->IsUtf16()) { + u16str_search = ecmascript::base::StringHelper::Utf16ToU16String(search_handle->GetDataUtf16(), search_len); } else { - const uint8_t *uint8Search = searchHandle->GetDataUtf8(); - u16strSearch = ecmascript::base::StringHelper::Utf8ToU16String(uint8Search, searchLen); + const uint8_t *uint8_search = search_handle->GetDataUtf8(); + u16str_search = ecmascript::base::StringHelper::Utf8ToU16String(uint8_search, search_len); } - int32_t idx = ecmascript::base::StringHelper::Find(u16strThis, u16strSearch, pos); + int32_t idx = ecmascript::base::StringHelper::Find(u16str_this, u16str_search, pos); if (idx == pos) { return BuiltinsString::GetTaggedBoolean(true); } @@ -1533,31 +1537,31 @@ JSTaggedValue BuiltinsString::Substring(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Substring); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t thisLen = thisHandle->GetLength(); - JSHandle startTag = BuiltinsString::GetCallArg(argv, 0); - JSTaggedNumber startVal = JSTaggedValue::ToInteger(thread, startTag); + int32_t this_len = this_handle->GetLength(); + JSHandle start_tag = BuiltinsString::GetCallArg(argv, 0); + JSTaggedNumber start_val = JSTaggedValue::ToInteger(thread, start_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t start = ConvertDoubleToInt(startVal.GetNumber()); + int32_t start = ConvertDoubleToInt(start_val.GetNumber()); int32_t end; - JSHandle endTag = BuiltinsString::GetCallArg(argv, 1); - if (endTag->IsUndefined()) { - end = thisLen; + JSHandle end_tag = BuiltinsString::GetCallArg(argv, 1); + if (end_tag->IsUndefined()) { + end = this_len; } else { - JSTaggedNumber endVal = JSTaggedValue::ToInteger(thread, endTag); + JSTaggedNumber end_val = JSTaggedValue::ToInteger(thread, end_tag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = ConvertDoubleToInt(endVal.GetNumber()); + end = ConvertDoubleToInt(end_val.GetNumber()); } - start = std::min(std::max(start, 0), thisLen); - end = std::min(std::max(end, 0), thisLen); + start = std::min(std::max(start, 0), this_len); + end = std::min(std::max(end, 0), this_len); int32_t from = std::min(start, end); int32_t to = std::max(start, end); int32_t len = to - from; - return JSTaggedValue(EcmaString::FastSubString(thisHandle, from, len, thread->GetEcmaVM())); + return JSTaggedValue(EcmaString::FastSubString(this_handle, from, len, thread->GetEcmaVM())); } // 21.1.3.20 @@ -1566,9 +1570,9 @@ JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToLocaleLowerCase); JSThread *thread = argv->GetThread(); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let O be RequireObjectCoercible(this value). JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); @@ -1579,29 +1583,29 @@ JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) // Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If requestedLocales is not an empty List, then Let requestedLocale be requestedLocales[0]. // Else, Let requestedLocale be DefaultLocale(). - JSHandle requestedLocale = JSLocale::DefaultLocale(thread); - if (requestedLocales->GetLength() != 0) { - requestedLocale = JSHandle(thread, requestedLocales->Get(0)); + JSHandle requested_locale = JSLocale::DefaultLocale(thread); + if (requested_locales->GetLength() != 0) { + requested_locale = JSHandle(thread, requested_locales->Get(0)); } // Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences // removed. - JSLocale::ParsedLocale noExtensionsLocale = JSLocale::HandleLocale(requestedLocale); + JSLocale::ParsedLocale no_extensions_locale = JSLocale::HandleLocale(requested_locale); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let availableLocales be a List with language tags that includes the languages for which the Unicode Character // Database contains language sensitive case mappings. Implementations may add additional language tags // if they support case mapping for additional locales. - JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); + JSHandle available_locales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let locale be BestAvailableLocale(availableLocales, noExtensionsLocale). - std::string locale = JSLocale::BestAvailableLocale(thread, availableLocales, noExtensionsLocale.base); + std::string locale = JSLocale::BestAvailableLocale(thread, available_locales, no_extensions_locale.base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If locale is undefined, let locale be "und". @@ -1612,20 +1616,20 @@ JSTaggedValue BuiltinsString::ToLocaleLowerCase(EcmaRuntimeCallInfo *argv) // Let uString be a List containing in order the code points of S as defined in ES2020, 6.1.4, // starting at the first element of S. // Transform those elements in uString to the to the Unicode Default Case Conversion algorithm - icu::Locale icuLocale = icu::Locale::createFromName(locale.c_str()); - std::u16string utf16String; + icu::Locale icu_locale = icu::Locale::createFromName(locale.c_str()); + std::u16string utf16_string; if (string->IsUtf16()) { - utf16String = + utf16_string = ecmascript::base::StringHelper::Utf16ToU16String(string->GetDataUtf16(), string->GetUtf16Length()); } else { - const uint8_t *uint8This = string->GetDataUtf8(); - utf16String = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, string->GetLength()); - } - icu::UnicodeString uString(utf16String.data()); - icu::UnicodeString res = uString.toLower(icuLocale); - std::string CSLower; - res.toUTF8String(CSLower); - JSHandle result = factory->NewFromStdString(CSLower); + const uint8_t *uint8_this = string->GetDataUtf8(); + utf16_string = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, string->GetLength()); + } + icu::UnicodeString u_string(utf16_string.data()); + icu::UnicodeString res = u_string.toLower(icu_locale); + std::string cs_lower; + res.toUTF8String(cs_lower); + JSHandle result = factory->NewFromStdString(cs_lower); return result.GetTaggedValue(); } @@ -1635,9 +1639,9 @@ JSTaggedValue BuiltinsString::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToLocaleLowerCase); JSThread *thread = argv->GetThread(); - EcmaVM *ecmaVm = thread->GetEcmaVM(); - ObjectFactory *factory = ecmaVm->GetFactory(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + EcmaVM *ecma_vm = thread->GetEcmaVM(); + ObjectFactory *factory = ecma_vm->GetFactory(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let O be RequireObjectCoercible(this value). JSHandle obj(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); @@ -1648,29 +1652,29 @@ JSTaggedValue BuiltinsString::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) // Let requestedLocales be ? CanonicalizeLocaleList(locales). JSHandle locales = GetCallArg(argv, 0); - JSHandle requestedLocales = JSLocale::CanonicalizeLocaleList(thread, locales); + JSHandle requested_locales = JSLocale::CanonicalizeLocaleList(thread, locales); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If requestedLocales is not an empty List, then Let requestedLocale be requestedLocales[0]. // Else, Let requestedLocale be DefaultLocale(). - JSHandle requestedLocale = JSLocale::DefaultLocale(thread); - if (requestedLocales->GetLength() != 0) { - requestedLocale = JSHandle(thread, requestedLocales->Get(0)); + JSHandle requested_locale = JSLocale::DefaultLocale(thread); + if (requested_locales->GetLength() != 0) { + requested_locale = JSHandle(thread, requested_locales->Get(0)); } // Let noExtensionsLocale be the String value that is requestedLocale with all Unicode locale extension sequences // removed. - JSLocale::ParsedLocale noExtensionsLocale = JSLocale::HandleLocale(requestedLocale); + JSLocale::ParsedLocale no_extensions_locale = JSLocale::HandleLocale(requested_locale); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let availableLocales be a List with language tags that includes the languages for which the Unicode Character // Database contains language sensitive case mappings. Implementations may add additional language tags // if they support case mapping for additional locales. - JSHandle availableLocales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); + JSHandle available_locales = JSLocale::GetAvailableLocales(thread, nullptr, nullptr); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // Let locale be BestAvailableLocale(availableLocales, noExtensionsLocale). - std::string locale = JSLocale::BestAvailableLocale(thread, availableLocales, noExtensionsLocale.base); + std::string locale = JSLocale::BestAvailableLocale(thread, available_locales, no_extensions_locale.base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // If locale is undefined, let locale be "und". @@ -1681,41 +1685,41 @@ JSTaggedValue BuiltinsString::ToLocaleUpperCase(EcmaRuntimeCallInfo *argv) // Let uString be a List containing in order the code points of S as defined in ES2020, 6.1.4, // starting at the first element of S. // Transform those elements in uString to the to the Unicode Default Case Conversion algorithm - icu::Locale icuLocale = icu::Locale::createFromName(locale.c_str()); - std::u16string utf16String; + icu::Locale icu_locale = icu::Locale::createFromName(locale.c_str()); + std::u16string utf16_string; if (string->IsUtf16()) { - utf16String = + utf16_string = ecmascript::base::StringHelper::Utf16ToU16String(string->GetDataUtf16(), string->GetUtf16Length()); } else { - const uint8_t *uint8This = string->GetDataUtf8(); - utf16String = ecmascript::base::StringHelper::Utf8ToU16String(uint8This, string->GetLength()); - } - icu::UnicodeString uString(utf16String.data()); - icu::UnicodeString res = uString.toUpper(icuLocale); - std::string CSUpper; - res.toUTF8String(CSUpper); - JSHandle result = factory->NewFromStdString(CSUpper); + const uint8_t *uint8_this = string->GetDataUtf8(); + utf16_string = ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, string->GetLength()); + } + icu::UnicodeString u_string(utf16_string.data()); + icu::UnicodeString res = u_string.toUpper(icu_locale); + std::string cs_upper; + res.toUTF8String(cs_upper); + JSHandle result = factory->NewFromStdString(cs_upper); return result.GetTaggedValue(); } static std::u16string ToU16String(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisTag( + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_tag( JSTaggedValue::RequireObjectCoercible(thread, ecmascript::base::BuiltinsBase::GetThis(argv))); - JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_handle = JSTaggedValue::ToString(thread, this_tag); if (UNLIKELY(thread->HasPendingException())) { return std::u16string(); } - int32_t thisLen = thisHandle->GetLength(); - if (thisHandle->IsUtf16()) { - return ecmascript::base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen); + int32_t this_len = this_handle->GetLength(); + if (this_handle->IsUtf16()) { + return ecmascript::base::StringHelper::Utf16ToU16String(this_handle->GetDataUtf16(), this_len); } - const uint8_t *uint8This = thisHandle->GetDataUtf8(); - return ecmascript::base::StringHelper::Utf8ToU16String(uint8This, thisLen); + const uint8_t *uint8_this = this_handle->GetDataUtf8(); + return ecmascript::base::StringHelper::Utf8ToU16String(uint8_this, this_len); } // 21.1.3.22 @@ -1724,9 +1728,9 @@ JSTaggedValue BuiltinsString::ToLowerCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToLowerCase); JSThread *thread = argv->GetThread(); - std::u16string u16strThis = ToU16String(argv); + std::u16string u16str_this = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return JSTaggedValue(ecmascript::base::StringHelper::ToLower(thread, u16strThis)); + return JSTaggedValue(ecmascript::base::StringHelper::ToLower(thread, u16str_this)); } // 21.1.3.23 @@ -1742,9 +1746,9 @@ JSTaggedValue BuiltinsString::ToUpperCase(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, ToUpperCase); JSThread *thread = argv->GetThread(); - std::u16string u16strThis = ToU16String(argv); + std::u16string u16str_this = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return JSTaggedValue(ecmascript::base::StringHelper::ToUpper(thread, u16strThis)); + return JSTaggedValue(ecmascript::base::StringHelper::ToUpper(thread, u16str_this)); } // 21.1.3.25 @@ -1753,9 +1757,9 @@ JSTaggedValue BuiltinsString::Trim(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Trim); JSThread *thread = argv->GetThread(); - std::u16string u16strThis = ToU16String(argv); + std::u16string u16str_this = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16strThis, base::TrimKind::TRIM_START_END); + EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16str_this, base::TrimKind::TRIM_START_END); return JSTaggedValue(str); } @@ -1765,9 +1769,9 @@ JSTaggedValue BuiltinsString::TrimEnd(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Trim); JSThread *thread = argv->GetThread(); - std::u16string u16strThis = ToU16String(argv); + std::u16string u16str_this = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16strThis, base::TrimKind::TRIM_END); + EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16str_this, base::TrimKind::TRIM_END); return JSTaggedValue(str); } @@ -1777,9 +1781,9 @@ JSTaggedValue BuiltinsString::TrimStart(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, Trim); JSThread *thread = argv->GetThread(); - std::u16string u16strThis = ToU16String(argv); + std::u16string u16str_this = ToU16String(argv); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16strThis, base::TrimKind::TRIM_START); + EcmaString *str = ecmascript::base::StringHelper::Trim(thread, u16str_this, base::TrimKind::TRIM_START); return JSTaggedValue(str); } @@ -1796,7 +1800,7 @@ JSTaggedValue BuiltinsString::GetStringIterator(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), String, GetStringIterator); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(this value). JSHandle current(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); // Let S be ToString(O). @@ -1814,58 +1818,58 @@ JSTaggedValue BuiltinsString::SubStr(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), String, SubStr); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be RequireObjectCoercible(this value). // 2. Let S be ToString(O). - JSHandle thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); - JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); + JSHandle this_tag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv))); + JSHandle this_string = JSTaggedValue::ToString(thread, this_tag); // 3. ReturnIfAbrupt(S). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle intStart = GetCallArg(argv, 0); + JSHandle int_start = GetCallArg(argv, 0); // 4. Let intStart be ToInteger(start). - JSTaggedNumber numStart = JSTaggedValue::ToInteger(thread, intStart); + JSTaggedNumber num_start = JSTaggedValue::ToInteger(thread, int_start); // 5. ReturnIfAbrupt(intStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t start = numStart.ToInt32(); - JSHandle lengthTag = GetCallArg(argv, 1); + int32_t start = num_start.ToInt32(); + JSHandle length_tag = GetCallArg(argv, 1); // 6. If length is undefined, let end be +; otherwise let end be ToInteger(length). int32_t end; - if (lengthTag->IsUndefined()) { + if (length_tag->IsUndefined()) { end = INT_MAX; } else { - JSTaggedNumber lengthNumber = JSTaggedValue::ToInteger(thread, lengthTag); + JSTaggedNumber length_number = JSTaggedValue::ToInteger(thread, length_tag); // 7. ReturnIfAbrupt(end). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - end = lengthNumber.ToInt32(); + end = length_number.ToInt32(); } // 8. Let size be the number of code units in S. - int32_t size = thisString->GetLength(); + int32_t size = this_string->GetLength(); // 9. If intStart < 0, let intStart be max(size + intStart,0). if (start < 0) { start = std::max(size + start, 0); } // 10. Let resultLength be min(max(end,0), size – intStart). - int32_t resultLength = std::min(std::max(end, 0), size - start); + int32_t result_length = std::min(std::max(end, 0), size - start); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 11. If resultLength  0, return the empty String "". - if (resultLength <= 0) { + if (result_length <= 0) { return factory->GetEmptyString().GetTaggedValue(); } - return JSTaggedValue(EcmaString::FastSubString(thisString, start, resultLength, thread->GetEcmaVM())); + return JSTaggedValue(EcmaString::FastSubString(this_string, start, result_length, thread->GetEcmaVM())); } JSTaggedValue BuiltinsString::GetLength(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle thisHandle = GetThis(argv); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + JSHandle this_handle = GetThis(argv); - JSHandle thisString = JSTaggedValue::ToString(thread, thisHandle); - return GetTaggedInt(thisString->GetLength()); + JSHandle this_string = JSTaggedValue::ToString(thread, this_handle); + return GetTaggedInt(this_string->GetLength()); } // 21.1.3 @@ -1875,8 +1879,8 @@ JSTaggedValue BuiltinsString::ThisStringValue(JSThread *thread, JSTaggedValue va return value; } if (value.IsECMAObject()) { - auto jshClass = value.GetTaggedObject()->GetClass(); - if (jshClass->GetObjectType() == JSType::JS_PRIMITIVE_REF) { + auto jsh_class = value.GetTaggedObject()->GetClass(); + if (jsh_class->GetObjectType() == JSType::JS_PRIMITIVE_REF) { JSTaggedValue primitive = JSPrimitiveRef::Cast(value.GetTaggedObject())->GetValue(); if (primitive.IsString()) { return primitive; diff --git a/runtime/builtins/builtins_string.h b/runtime/builtins/builtins_string.h index bb507165ca3e296efb0f0e0cf684a8432c3b8a85..88eb2f99f7b21e7a762104fc278193c69f97d4eb 100644 --- a/runtime/builtins/builtins_string.h +++ b/runtime/builtins/builtins_string.h @@ -41,9 +41,9 @@ public: static JSTaggedValue Raw(EcmaRuntimeCallInfo *argv); // 21.1.3.14.1 Runtime Semantics: GetSubstitution() static JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle &matched, - const JSHandle &srcString, int position, - const JSHandle &captureList, - const JSHandle &namedCaptures, + 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); @@ -71,9 +71,9 @@ public: // 21.1.3.12 static JSTaggedValue Normalize(EcmaRuntimeCallInfo *argv); // ES2021 22.1.3.14 - static JSTaggedValue padEnd(EcmaRuntimeCallInfo *argv); + static JSTaggedValue PadEnd(EcmaRuntimeCallInfo *argv); // ES2021 22.1.3.15 - static JSTaggedValue padStart(EcmaRuntimeCallInfo *argv); + static JSTaggedValue PadStart(EcmaRuntimeCallInfo *argv); // 21.1.3.13 static JSTaggedValue Repeat(EcmaRuntimeCallInfo *argv); // 21.1.3.14 diff --git a/runtime/builtins/builtins_string_iterator.cpp b/runtime/builtins/builtins_string_iterator.cpp index 6b0d73281c52d99a07e5b737fe80444c48bdcd63..2adc17e154cbc676585ec7c047a860cc56939f36 100644 --- a/runtime/builtins/builtins_string_iterator.cpp +++ b/runtime/builtins/builtins_string_iterator.cpp @@ -28,23 +28,24 @@ JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), StringIterator, Next); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisValue = GetThis(argv); + JSHandle this_value = 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. - if (!thisValue->IsStringIterator()) { + if (!this_value->IsStringIterator()) { THROW_TYPE_ERROR_AND_RETURN(thread, "is not StringIterator", JSTaggedValue::Exception()); } // 4. Let s be the value of the [[IteratedString]] internal slot of O. - JSHandle string(thread, thisValue.GetObject()->GetIteratedString()); + JSHandle string(thread, this_value.GetObject()->GetIteratedString()); // 5. If s is undefined, return CreateIterResultObject(undefined, true). if (string->IsUndefined()) { return JSIterator::CreateIterResultObject(thread, string, true).GetTaggedValue(); } // 6. Let position be the value of the [[StringIteratorNextIndex]] internal slot of O. - double position = JSTaggedNumber(thisValue.GetObject()->GetStringIteratorNextIndex()).GetNumber(); + double position = + JSTaggedNumber(this_value.GetObject()->GetStringIteratorNextIndex()).GetNumber(); // 7. Let len be the number of elements in s. uint32_t len = string.GetObject()->GetLength(); @@ -52,7 +53,7 @@ JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) // a. Set the value of the [[IteratedString]] internal slot of O to // b. Return CreateIterResultObject(undefined, true). if (position >= len) { - thisValue.GetObject()->SetIteratedString(thread, JSTaggedValue::Undefined()); + this_value.GetObject()->SetIteratedString(thread, JSTaggedValue::Undefined()); JSHandle result(thread, JSTaggedValue::Undefined()); return JSIterator::CreateIterResultObject(thread, result, true).GetTaggedValue(); } @@ -60,13 +61,13 @@ JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) // 9. Let first be the code unit value at index position in s. uint16_t first = string.GetObject()->At(position); JSMutableHandle result(thread, JSTaggedValue::Undefined()); - uint32_t resultSize = 1; + uint32_t result_size = 1; // 10. If first < 0xD800 or first > 0xDBFF or position+1 = len, let resultString be the string consisting of the // single code unit first. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (position + 1 == len || first < utf::DECODE_LEAD_LOW || first > utf::DECODE_LEAD_HIGH) { - std::vector resultString {first, 0x0}; - result.Update(factory->NewFromUtf16UnCheck(resultString.data(), 1, true).GetTaggedValue()); + std::vector result_string {first, 0x0}; + result.Update(factory->NewFromUtf16UnCheck(result_string.data(), 1, true).GetTaggedValue()); } else { // 11. Else, // a. Let second be the code unit value at index position+1 in the String S. @@ -75,18 +76,18 @@ JSTaggedValue BuiltinsStringIterator::Next(EcmaRuntimeCallInfo *argv) // c. Else, let resultString be the string consisting of the code unit first followed by the code unit second. uint16_t second = string.GetObject()->At(position + 1); if (second < utf::DECODE_TRAIL_LOW || second > utf::DECODE_TRAIL_HIGH) { - std::vector resultString {first, 0x0}; - result.Update(factory->NewFromUtf16UnCheck(resultString.data(), 1, false).GetTaggedValue()); + std::vector result_string {first, 0x0}; + result.Update(factory->NewFromUtf16UnCheck(result_string.data(), 1, false).GetTaggedValue()); } else { - std::vector resultString {first, second, 0x0}; + std::vector result_string {first, second, 0x0}; result.Update( - factory->NewFromUtf16UnCheck(resultString.data(), 2, false).GetTaggedValue()); // 2: two bytes - resultSize = 2; // 2: 2 means that two bytes represent a character string + factory->NewFromUtf16UnCheck(result_string.data(), 2, false).GetTaggedValue()); // 2: two bytes + result_size = 2; // 2: 2 means that two bytes represent a character string } } // 12. Let resultSize be the number of code units in resultString. // 13. Set the value of the [[StringIteratorNextIndex]] internal slot of O to position+ resultSize. - thisValue.GetObject()->SetStringIteratorNextIndex(thread, JSTaggedValue(position + resultSize)); + this_value.GetObject()->SetStringIteratorNextIndex(thread, JSTaggedValue(position + result_size)); // 14. Return CreateIterResultObject(resultString, false). return JSIterator::CreateIterResultObject(thread, result, false).GetTaggedValue(); diff --git a/runtime/builtins/builtins_symbol.cpp b/runtime/builtins/builtins_symbol.cpp index aca8767f4927edd7a07adec7c65959c935664d79..8fb82483938fb325d0f7cd7bfca4214251aee44a 100644 --- a/runtime/builtins/builtins_symbol.cpp +++ b/runtime/builtins/builtins_symbol.cpp @@ -33,7 +33,7 @@ JSTaggedValue BuiltinsSymbol::SymbolConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -44,16 +44,16 @@ JSTaggedValue BuiltinsSymbol::SymbolConstructor(EcmaRuntimeCallInfo *argv) // 2.If description is undefined, let descString be undefined. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (key->IsUndefined()) { - JSHandle jsSymbol = factory->NewJSSymbol(); - return jsSymbol.GetTaggedValue(); + JSHandle js_symbol = factory->NewJSSymbol(); + return js_symbol.GetTaggedValue(); } // 3.Else, let descString be ToString(description). - JSHandle descHandle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); + JSHandle desc_handle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); // 4.ReturnIfAbrupt(descString). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); // 5.Return a new unique Symbol value whose [[Description]] value is descString. - JSHandle jsSymbol = factory->NewPublicSymbol(descHandle); - return jsSymbol.GetTaggedValue(); + JSHandle js_symbol = factory->NewPublicSymbol(desc_handle); + return js_symbol.GetTaggedValue(); } // 19.4.3.2 Symbol.prototype.toString() @@ -62,20 +62,20 @@ JSTaggedValue BuiltinsSymbol::ToString(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, ToString); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let s be the this value. - JSHandle valueHandle = GetThis(argv); + JSHandle value_handle = GetThis(argv); // 2.If Type(s) is Symbol, let sym be s. - JSTaggedValue sym = valueHandle.GetTaggedValue(); + JSTaggedValue sym = value_handle.GetTaggedValue(); // 3.Else - if (!valueHandle->IsSymbol()) { - if (valueHandle->IsObject()) { - if (!valueHandle->IsJSPrimitiveRef()) { + if (!value_handle->IsSymbol()) { + if (value_handle->IsObject()) { + if (!value_handle->IsJSPrimitiveRef()) { // If s does not have a [[SymbolData]] internal slot, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "ToString: no [[SymbolData]]", JSTaggedValue::Exception()); } // Let sym be the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value_handle->GetTaggedObject())->GetValue(); ASSERT(primitive.IsSymbol()); sym = primitive; } else { @@ -95,25 +95,25 @@ JSTaggedValue BuiltinsSymbol::SymbolDescriptiveString(JSThread *thread, JSTagged ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Let desc be sym’s [[Description]] value. - auto symbolObject = reinterpret_cast(sym.GetTaggedObject()); - JSHandle descHandle(thread, symbolObject->GetDescription()); + auto symbol_object = reinterpret_cast(sym.GetTaggedObject()); + JSHandle desc_handle(thread, symbol_object->GetDescription()); // If desc is undefined, let desc be the empty string. - if (descHandle->IsUndefined()) { - JSHandle leftHandle(factory->NewFromCanBeCompressString("Symbol(")); - JSHandle rightHandle(factory->NewFromCanBeCompressString(")")); - JSHandle str = factory->ConcatFromString(leftHandle, rightHandle); + if (desc_handle->IsUndefined()) { + JSHandle left_handle(factory->NewFromCanBeCompressString("Symbol(")); + JSHandle right_handle(factory->NewFromCanBeCompressString(")")); + JSHandle str = factory->ConcatFromString(left_handle, right_handle); return str.GetTaggedValue(); } // Assert: Type(desc) is String. - ASSERT(descHandle->IsString()); + ASSERT(desc_handle->IsString()); // Return the result of concatenating the strings "Symbol(", desc, and ")". - JSHandle leftHandle(factory->NewFromCanBeCompressString("Symbol(")); - JSHandle rightHandle(factory->NewFromCanBeCompressString(")")); - JSHandle stringLeft = - factory->ConcatFromString(leftHandle, JSTaggedValue::ToString(thread, descHandle)); - JSHandle str = factory->ConcatFromString(stringLeft, rightHandle); + JSHandle left_handle(factory->NewFromCanBeCompressString("Symbol(")); + JSHandle right_handle(factory->NewFromCanBeCompressString(")")); + JSHandle string_left = + factory->ConcatFromString(left_handle, JSTaggedValue::ToString(thread, desc_handle)); + JSHandle str = factory->ConcatFromString(string_left, right_handle); return str.GetTaggedValue(); } @@ -123,24 +123,24 @@ JSTaggedValue BuiltinsSymbol::ValueOf(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, ValueOf); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // Let s be the this value. - JSHandle valueHandle = GetThis(argv); + JSHandle value_handle = GetThis(argv); // If Type(s) is Symbol, return s. - if (valueHandle->IsSymbol()) { - return valueHandle.GetTaggedValue(); + if (value_handle->IsSymbol()) { + return value_handle.GetTaggedValue(); } // If Type(s) is not Object, throw a TypeError exception. - if (!valueHandle->IsObject()) { + if (!value_handle->IsObject()) { // return TypeError THROW_TYPE_ERROR_AND_RETURN(thread, "ValueOf: s is not Object", JSTaggedValue::Exception()); } // If s does not have a [[SymbolData]] internal slot, throw a TypeError exception. - if (!valueHandle->IsJSPrimitiveRef()) { + if (!value_handle->IsJSPrimitiveRef()) { // If s does not have a [[SymbolData]] internal slot, throw a TypeError exception. THROW_TYPE_ERROR_AND_RETURN(thread, "ValueOf: no [[SymbolData]]", JSTaggedValue::Exception()); } - JSTaggedValue primitive = JSPrimitiveRef::Cast(valueHandle->GetTaggedObject())->GetValue(); + JSTaggedValue primitive = JSPrimitiveRef::Cast(value_handle->GetTaggedObject())->GetValue(); ASSERT(primitive.IsSymbol()); // Return the value of s's [[SymbolData]] internal slot. return primitive; @@ -152,10 +152,10 @@ JSTaggedValue BuiltinsSymbol::For(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, For); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let stringKey be ToString(key). JSHandle key = BuiltinsSymbol::GetCallArg(argv, 0); - JSHandle stringHandle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); + JSHandle string_handle = JSHandle::Cast(JSTaggedValue::ToString(thread, key)); // 2.ReturnIfAbrupt RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); @@ -166,7 +166,7 @@ JSTaggedValue BuiltinsSymbol::For(EcmaRuntimeCallInfo *argv) // 6.Append the record { [[key]]: stringKey, [[symbol]]: newSymbol } to the GlobalSymbolRegistry List. // 7.Return newSymbol. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle symbol = factory->NewSymbolWithTable(stringHandle); + JSHandle symbol = factory->NewSymbolWithTable(string_handle); return symbol.GetTaggedValue(); } @@ -176,7 +176,7 @@ JSTaggedValue BuiltinsSymbol::KeyFor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, KeyFor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.If Type(sym) is not Symbol, throw a TypeError exception. JSHandle sym = BuiltinsSymbol::GetCallArg(argv, 0); if (!sym->IsSymbol()) { @@ -203,7 +203,7 @@ JSTaggedValue BuiltinsSymbol::ToPrimitive(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), Symbol, ToPrimitive); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1.Let s be the this value. JSHandle sym = GetThis(argv); // 2.If Type(s) is Symbol, return s. @@ -234,7 +234,7 @@ JSTaggedValue BuiltinsSymbol::DescriptionGetter(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Symbol, DescriptionGetter); // 1.Let s be the this value. JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle s = GetThis(argv); // 2.Let sym be ? thisSymbolValue(s). // 3.Return sym.[[Description]]. @@ -245,8 +245,8 @@ JSTaggedValue BuiltinsSymbol::ThisSymbolValue(JSThread *thread, const JSHandleIsSymbol()) { - JSTaggedValue desValue = JSSymbol::Cast(value->GetTaggedObject())->GetDescription(); - return desValue; + JSTaggedValue des_value = JSSymbol::Cast(value->GetTaggedObject())->GetDescription(); + return des_value; } // If s does not have a [[SymbolData]] internal slot, throw a TypeError exception. @@ -256,7 +256,7 @@ JSTaggedValue BuiltinsSymbol::ThisSymbolValue(JSThread *thread, const JSHandleGetTaggedObject())->GetValue(); ASSERT(primitive.IsSymbol()); // Return the value of s's [[SymbolData]] internal slot. - JSTaggedValue primitiveDesValue = JSSymbol::Cast(primitive.GetTaggedObject())->GetDescription(); - return primitiveDesValue; + JSTaggedValue primitive_des_value = JSSymbol::Cast(primitive.GetTaggedObject())->GetDescription(); + return primitive_des_value; } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_typedarray.cpp b/runtime/builtins/builtins_typedarray.cpp index 9f4582da987dd49e68a1b93d6bcd5afba133ca4d..39208833a6d9a02402d5b85d92eda02c3f46fc29 100644 --- a/runtime/builtins/builtins_typedarray.cpp +++ b/runtime/builtins/builtins_typedarray.cpp @@ -131,16 +131,16 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, From); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 1. Let C be the this value. // 2. If IsConstructor(C) is false, throw a TypeError exception. - JSHandle thisHandle = GetThis(argv); - if (!thisHandle->IsConstructor()) { + JSHandle this_handle = GetThis(argv); + if (!this_handle->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the this value is not a Constructor.", JSTaggedValue::Exception()); } - JSHandle thisArgHandle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); + JSHandle this_arg_handle = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); // 3. If mapfn is undefined, let mapping be false. // 4. Else, // a. If IsCallable(mapfn) is false, throw a TypeError exception. @@ -158,33 +158,34 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) if (!source->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the source is not an object.", JSTaggedValue::Exception()); } - JSHandle sourceObj(source); - JSHandle iteratorSymbol = env->GetIteratorSymbol(); - JSHandle usingIterator = - JSObject::GetMethod(thread, JSHandle::Cast(sourceObj), iteratorSymbol); + JSHandle source_obj(source); + JSHandle iterator_symbol = env->GetIteratorSymbol(); + JSHandle using_iterator = + JSObject::GetMethod(thread, JSHandle::Cast(source_obj), iterator_symbol); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 6. If usingIterator is not undefined, then // a. Let values be ? IterableToList(source, usingIterator). // b. Let len be the number of elements in values. // c. Let targetObj be ? TypedArrayCreate(C, « len »). - if (!usingIterator->IsUndefined()) { + if (!using_iterator->IsUndefined()) { PandaVector> vec; - JSHandle iterator = JSIterator::GetIterator(thread, source, usingIterator); + JSHandle iterator = JSIterator::GetIterator(thread, source, using_iterator); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle next(thread, JSTaggedValue::True()); while (!next->IsFalse()) { next = JSIterator::IteratorStep(thread, iterator); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!next->IsFalse()) { - JSHandle nextValue = JSIterator::IteratorValue(thread, next); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); - vec.push_back(nextValue); + JSHandle next_value = JSIterator::IteratorValue(thread, next); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next_value.GetTaggedValue()); + vec.push_back(next_value); } } uint32_t len = vec.size(); std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle targetObj = TypedArrayHelper::TypedArrayCreate(thread, thisHandle, args.size(), args.data()); + JSHandle target_obj = + TypedArrayHelper::TypedArrayCreate(thread, this_handle, args.size(), args.data()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // d. Let k be 0. // e. Repeat, while k < len @@ -195,49 +196,49 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) // iv. Else, let mappedValue be kValue. // v. Perform ? Set(targetObj, Pk, mappedValue, true). // vi. Set k to k + 1. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - tKey.Update(JSTaggedValue(k)); - JSHandle kValue = vec[k]; + t_key.Update(JSTaggedValue(k)); + JSHandle k_value = vec[k]; if (mapping) { - auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(kValue, tKey); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, mapfn, this_arg_handle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(k_value, t_key); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - mapValue.Update(callResult); + map_value.Update(call_result); } else { - mapValue.Update(kValue.GetTaggedValue()); + map_value.Update(k_value.GetTaggedValue()); } - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(targetObj), kKey, mapValue, true); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(target_obj), k_key, map_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // f. Assert: values is now an empty List. // g. Return targetObj. - return targetObj.GetTaggedValue(); + return target_obj.GetTaggedValue(); } // 7. NOTE: source is not an Iterable so assume it is already an array-like object. // 8. Let arrayLike be ! ToObject(source). - JSHandle arrayLikeObj = JSTaggedValue::ToObject(thread, source); + JSHandle array_like_obj = JSTaggedValue::ToObject(thread, source); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle arrayLike(arrayLikeObj); + JSHandle array_like(array_like_obj); // 9. Let len be ? LengthOfArrayLike(arrayLike). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle lenResult = JSTaggedValue::GetProperty(thread, arrayLike, lengthKey).GetValue(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle len_result = JSTaggedValue::GetProperty(thread, array_like, length_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedNumber tLen = JSTaggedValue::ToLength(thread, lenResult); + JSTaggedNumber t_len = JSTaggedValue::ToLength(thread, len_result); // 6. ReturnIfAbrupt(relativeTarget). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double len = tLen.GetNumber(); + double len = t_len.GetNumber(); // 10. Let targetObj be ? TypedArrayCreate(C, « len »). std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle targetObj = TypedArrayHelper::TypedArrayCreate(thread, thisHandle, args.size(), args.data()); + JSHandle target_obj = TypedArrayHelper::TypedArrayCreate(thread, this_handle, args.size(), args.data()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11. Let k be 0. // 12. Repeat, while k < len @@ -248,29 +249,29 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) // d. Else, let mappedValue be kValue. // e. Perform ? Set(targetObj, Pk, mappedValue, true). // f. Set k to k + 1. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSHandle kValue = JSTaggedValue::GetProperty(thread, arrayLike, kKey).GetValue(); + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSHandle k_value = JSTaggedValue::GetProperty(thread, array_like, k_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle mapValue; + JSHandle map_value; if (mapping) { - auto info = NewRuntimeCallInfo(thread, mapfn, thisArgHandle, JSTaggedValue::Undefined(), 2); - info->SetCallArgs(kValue, tKey); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 2: two args + auto info = NewRuntimeCallInfo(thread, mapfn, this_arg_handle, JSTaggedValue::Undefined(), 2); + info->SetCallArgs(k_value, t_key); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 2: two args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - mapValue = JSHandle(thread, callResult); + map_value = JSHandle(thread, call_result); } else { - mapValue = kValue; + map_value = k_value; } - JSTaggedValue::SetProperty(thread, JSHandle::Cast(targetObj), kKey, mapValue, true); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(target_obj), k_key, map_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 13. Return targetObj. - return targetObj.GetTaggedValue(); + return target_obj.GetTaggedValue(); } // 22.2.2.2 %TypedArray%.of ( ...items ) @@ -279,20 +280,20 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Of); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let len be the actual number of arguments passed to this function. 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 thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 4. If IsConstructor(C) is false, throw a TypeError exception. - if (!thisHandle->IsConstructor()) { + if (!this_handle->IsConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "the this value is not a Constructor.", JSTaggedValue::Exception()); } // 5. Let newObj be TypedArrayCreate(C, « len »). std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle newObj = TypedArrayHelper::TypedArrayCreate(thread, thisHandle, args.size(), args.data()); + JSHandle new_obj = TypedArrayHelper::TypedArrayCreate(thread, this_handle, args.size(), args.data()); // 6. ReturnIfAbrupt(newObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Let k be 0. @@ -302,18 +303,18 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) // c. Perform ? Set(newObj, Pk, kValue, true). // d. ReturnIfAbrupt(status). // e. Set k to k + 1. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); double k = 0; while (k < len) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSHandle kValue = GetCallArg(argv, k); - JSTaggedValue::SetProperty(thread, JSHandle::Cast(newObj), kKey, kValue, true); + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSHandle k_value = GetCallArg(argv, k); + JSTaggedValue::SetProperty(thread, JSHandle::Cast(new_obj), k_key, k_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; } // 9. Return newObj. - return newObj.GetTaggedValue(); + return new_obj.GetTaggedValue(); } // 22.2.2.4 @@ -331,20 +332,20 @@ JSTaggedValue BuiltinsTypedArray::GetBuffer(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetBuffer); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception. - if (!thisHandle->IsTypedArray()) { + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value does not have a [[ViewedArrayBuffer]] internal slot.", JSTaggedValue::Exception()); } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 5. Return buffer. return buffer; } @@ -355,27 +356,27 @@ JSTaggedValue BuiltinsTypedArray::GetByteLength(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetByteLength); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception. - if (!thisHandle->IsTypedArray()) { + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value does not have a [[ViewedArrayBuffer]] internal slot.", JSTaggedValue::Exception()); } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, return 0. if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 6. Let size be the value of O’s [[ByteLength]] internal slot. // 7. Return size. - return JSHandle(thisHandle)->GetByteLength(); + return JSHandle(this_handle)->GetByteLength(); } // 22.2.3.3 @@ -384,26 +385,26 @@ JSTaggedValue BuiltinsTypedArray::GetByteOffset(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetByteOffset); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } // 3. If O does not have a [[ViewedArrayBuffer]] internal slot, throw a TypeError exception. - if (!thisHandle->IsTypedArray()) { + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value does not have a [[ViewedArrayBuffer]] internal slot.", JSTaggedValue::Exception()); } // 4. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 5. If IsDetachedBuffer(buffer) is true, return 0. if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 6. Let offset be the value of O’s [[ByteOffset]] internal slot. - int32_t offset = TypedArrayHelper::GetByteOffset(thread, JSHandle(thisHandle)); + int32_t offset = TypedArrayHelper::GetByteOffset(thread, JSHandle(this_handle)); // 7. Return offset. return JSTaggedValue(offset); } @@ -425,14 +426,14 @@ JSTaggedValue BuiltinsTypedArray::Entries(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Entries); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); - JSHandle self(thisHandle); + JSHandle self(this_handle); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 4. Return CreateArrayIterator(O, "key+value"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::KEY_AND_VALUE)); @@ -445,31 +446,31 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Every); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - if (!thisHandle->IsTypedArray()) { + JSHandle this_handle = GetThis(argv); + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObjHandle); + int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -488,15 +489,15 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) int32_t k = 0; while (k < len) { RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle kValue = JSTaggedValue::GetProperty(thread, thisObjVal, k).GetValue(); + JSHandle k_value = JSTaggedValue::GetProperty(thread, this_obj_val, k).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - bool boolResult = callResult.ToBoolean(); - if (!boolResult) { + bool bool_result = call_result.ToBoolean(); + if (!bool_result) { return GetTaggedBoolean(false); } k++; @@ -522,25 +523,25 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Filter); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObj(thisHandle); + JSHandle this_obj(this_handle); // 4. Let len be the value of O’s [[ArrayLength]] internal slot. - int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); + int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 10. Let kept be a new empty List. JSHandle kept(factory->NewTaggedArray(len)); @@ -558,26 +559,27 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) // ii. Increase captured by 1. // g. Increase k by 1. int32_t captured = 0; - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); for (int32_t k = 0; k < len; k++) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSHandle kValue = JSTaggedValue::GetProperty(thread, thisHandle, kKey).GetValue(); + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSHandle k_value = JSTaggedValue::GetProperty(thread, this_handle, k_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, tKey, thisHandle); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args - bool testResult = callResult.ToBoolean(); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, t_key, this_handle); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args + bool test_result = call_result.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (testResult) { - kept->Set(thread, captured, kValue); + if (test_result) { + kept->Set(thread, captured, k_value); captured++; } } // es11 9. Let A be ? TypedArraySpeciesCreate(O, « captured »). std::array args = {JSTaggedValue(captured).GetRawData()}; - JSHandle newArrObj = TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); + JSHandle new_arr_obj = + TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); // 15. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. Let n be 0. @@ -585,17 +587,17 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) // a. Let status be Set(A, ToString(n), e, true ). // b. ReturnIfAbrupt(status). // c. Increment n by 1. - JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); - JSMutableHandle ntKey(thread, JSTaggedValue::Undefined()); + JSMutableHandle value_handle(thread, JSTaggedValue::Undefined()); + JSMutableHandle nt_key(thread, JSTaggedValue::Undefined()); for (int32_t n = 0; n < captured; n++) { - valueHandle.Update(kept->Get(n)); - ntKey.Update(JSTaggedValue(n)); - JSHandle nKey(JSTaggedValue::ToString(thread, ntKey)); - JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), nKey, valueHandle, true); + value_handle.Update(kept->Get(n)); + nt_key.Update(JSTaggedValue(n)); + JSHandle n_key(JSTaggedValue::ToString(thread, nt_key)); + JSTaggedValue::SetProperty(thread, JSHandle(new_arr_obj), n_key, value_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 18. Return A. - return newArrObj.GetTaggedValue(); + return new_arr_obj.GetTaggedValue(); } // 22.2.3.10 @@ -624,31 +626,31 @@ JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, ForEach); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - if (!thisHandle->IsTypedArray()) { + JSHandle this_handle = GetThis(argv); + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); // 2. ReturnIfAbrupt(O). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); // 3. Let len be ToLength(Get(O, "length")). - int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObjHandle); + int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); // 4. ReturnIfAbrupt(len). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackFnHandle = GetCallArg(argv, 0); - if (!callbackFnHandle->IsCallable()) { + JSHandle callback_fn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // 7. Let k be 0. // 8. Repeat, while k < len @@ -665,13 +667,13 @@ JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) int32_t k = 0; while (k < len) { - JSHandle kValue = JSTaggedValue::GetProperty(thread, thisObjVal, k).GetValue(); + JSHandle k_value = JSTaggedValue::GetProperty(thread, this_obj_val, k).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - auto info = NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisObjVal); - JSTaggedValue funcResult = JSFunction::Call(info.get()); // 3: three args - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); + auto info = NewRuntimeCallInfo(thread, callback_fn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_obj_val); + JSTaggedValue func_result = JSFunction::Call(info.Get()); // 3: three args + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, func_result); k++; } @@ -685,18 +687,18 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Includes); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Perform ? ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Let len be ToLength(Get(O, "length")). - JSHandle thisObj(thisHandle); - int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); + JSHandle this_obj(this_handle); + int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If len is 0, return false. @@ -705,15 +707,15 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) } ArraySizeT argc = argv->GetArgsNumber(); - double fromIndex = 0; + double from_index = 0; 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); - JSTaggedNumber fromIndexTemp = JSTaggedValue::ToNumber(thread, msg1); + JSTaggedNumber from_index_temp = JSTaggedValue::ToNumber(thread, msg1); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - fromIndex = ecmascript::base::NumberHelper::TruncateDouble(fromIndexTemp.GetNumber()); + from_index = ecmascript::base::NumberHelper::TruncateDouble(from_index_temp.GetNumber()); // 6. If n is positiveInfinity, return false. if (JSTaggedValue::Equal(thread, msg1, @@ -724,7 +726,7 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) // 7. Else if n is negativeInfinity, set n to 0. if (JSTaggedValue::Equal(thread, msg1, JSHandle(thread, JSTaggedValue(-base::POSITIVE_INFINITY)))) { - fromIndex = 0; + from_index = 0; } } @@ -733,19 +735,19 @@ JSTaggedValue BuiltinsTypedArray::Includes(EcmaRuntimeCallInfo *argv) // 9. Else, // a. Let k be len + n. // b. If k < 0, set k to 0. - double from = (fromIndex >= 0) ? fromIndex : ((len + fromIndex) >= 0 ? len + fromIndex : 0); + double from = (from_index >= 0) ? from_index : ((len + from_index) >= 0 ? len + from_index : 0); // 10. - const JSHandle searchElement = GetCallArg(argv, 0); + const JSHandle search_element = GetCallArg(argv, 0); while (from < len) { // a) - JSHandle indexHandle(thread, JSTaggedValue(from)); + JSHandle index_handle(thread, JSTaggedValue(from)); JSHandle handle = - JSHandle(thread, JSTaggedValue::ToString(thread, indexHandle).GetTaggedValue()); - JSHandle element = JSTaggedValue::GetProperty(thread, thisHandle, handle).GetValue(); + JSHandle(thread, JSTaggedValue::ToString(thread, index_handle).GetTaggedValue()); + JSHandle element = JSTaggedValue::GetProperty(thread, this_handle, handle).GetValue(); // b) - if (JSTaggedValue::SameValueZero(searchElement.GetTaggedValue(), element.GetTaggedValue())) { + if (JSTaggedValue::SameValueZero(search_element.GetTaggedValue(), element.GetTaggedValue())) { return GetTaggedBoolean(true); } @@ -781,14 +783,14 @@ JSTaggedValue BuiltinsTypedArray::Keys(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Keys); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); - JSHandle self(thisHandle); + JSHandle self(this_handle); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 4. Return CreateArrayIterator(O, "key"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::KEY)); @@ -811,27 +813,27 @@ JSTaggedValue BuiltinsTypedArray::GetLength(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, GetLength); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } // 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception. - if (!thisHandle->IsTypedArray()) { + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value does not have a [[TypedArrayName]] internal slot.", JSTaggedValue::Exception()); } // 4. Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots. // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSHandle::Cast(thisHandle)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSHandle::Cast(this_handle)->GetViewedArrayBuffer(); // 6. If IsDetachedBuffer(buffer) is true, return 0. if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) { return JSTaggedValue(0); } // 7. Let length be the value of O’s [[ArrayLength]] internal slot. - int32_t length = TypedArrayHelper::GetArrayLength(thread, JSHandle(thisHandle)); + int32_t length = TypedArrayHelper::GetArrayLength(thread, JSHandle(this_handle)); // 8. Return length. return JSTaggedValue(length); } @@ -842,28 +844,29 @@ JSTaggedValue BuiltinsTypedArray::Map(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Map); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObj(thisHandle); + JSHandle this_obj(this_handle); // 4. Let len be the value of O’s [[ArrayLength]] internal slot. - int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); + int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); // 5. If IsCallable(callbackfn) is false, throw a TypeError exception. - JSHandle callbackfnHandle = GetCallArg(argv, 0); - if (!callbackfnHandle->IsCallable()) { + JSHandle callbackfn_handle = 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 thisArgHandle = GetCallArg(argv, 1); + JSHandle this_arg_handle = GetCallArg(argv, 1); // es11 5. Let A be ? TypedArraySpeciesCreate(O, « len »). std::array args = {JSTaggedValue(len).GetRawData()}; - JSHandle newArrObj = TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); + JSHandle new_arr_obj = + TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); // 11. ReturnIfAbrupt(A). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -878,22 +881,22 @@ JSTaggedValue BuiltinsTypedArray::Map(EcmaRuntimeCallInfo *argv) // g. ReturnIfAbrupt(status). // h. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle map_value(thread, JSTaggedValue::Undefined()); for (int32_t k = 0; k < len; k++) { key.Update(JSTaggedValue(k)); - JSHandle kValue = JSTaggedValue::GetProperty(thread, thisHandle, key).GetValue(); + JSHandle k_value = JSTaggedValue::GetProperty(thread, this_handle, key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - auto info = NewRuntimeCallInfo(thread, callbackfnHandle, thisArgHandle, JSTaggedValue::Undefined(), 3); - info->SetCallArgs(kValue, key, thisHandle); - JSTaggedValue callResult = JSFunction::Call(info.get()); // 3: three args - mapValue.Update(callResult); + auto info = NewRuntimeCallInfo(thread, callbackfn_handle, this_arg_handle, JSTaggedValue::Undefined(), 3); + info->SetCallArgs(k_value, key, this_handle); + JSTaggedValue call_result = JSFunction::Call(info.Get()); // 3: three args + map_value.Update(call_result); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), key, mapValue, true); + JSTaggedValue::SetProperty(thread, JSHandle(new_arr_obj), key, map_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } // 14. Return A. - return newArrObj.GetTaggedValue(); + return new_arr_obj.GetTaggedValue(); } // 22.2.3.19 @@ -933,7 +936,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); // 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. @@ -943,7 +946,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) if (!target->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } - JSHandle targetObj(target); + JSHandle target_obj(target); // 4. If target does not have a [[TypedArrayName]] internal slot, throw a TypeError exception. if (!target->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value does not have a [[TypedArrayName]] internal slot.", @@ -952,19 +955,19 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 5. Assert: target has a [[ViewedArrayBuffer]] internal slot. // 6. Let targetOffset be ToInteger (offset). - JSTaggedNumber tTargetOffset = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 1)); + JSTaggedNumber t_target_offset = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 1)); // 7. ReturnIfAbrupt(targetOffset). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double targetOffset = tTargetOffset.GetNumber(); + double target_offset = t_target_offset.GetNumber(); // 8. If targetOffset < 0, throw a RangeError exception. - if (targetOffset < 0) { + if (target_offset < 0) { THROW_RANGE_ERROR_AND_RETURN(thread, "The targetOffset of This value is less than 0.", JSTaggedValue::Exception()); } // 9. Let targetBuffer be the value of target’s [[ViewedArrayBuffer]] internal slot. - JSHandle targetBuffer(thread, JSTypedArray::Cast(*targetObj)->GetViewedArrayBuffer()); + JSHandle target_buffer(thread, JSTypedArray::Cast(*target_obj)->GetViewedArrayBuffer()); // 10. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. - if (BuiltinsArrayBuffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } @@ -973,40 +976,40 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 13. Let targetElementSize be the Number value of the Element Size value specified in Table 49 for targetName. // 14. Let targetType be the String value of the Element Type value in Table 49 for targetName. // 15. Let targetByteOffset be the value of target’s [[ByteOffset]] internal slot. - int32_t targetLength = TypedArrayHelper::GetArrayLength(thread, targetObj); - JSHandle targetName(thread, JSTypedArray::Cast(*targetObj)->GetTypedArrayName()); - int32_t targetElementSize = TypedArrayHelper::GetSizeFromName(thread, targetName); - DataViewType targetType = TypedArrayHelper::GetTypeFromName(thread, targetName); - int32_t targetByteOffset = TypedArrayHelper::GetByteOffset(thread, targetObj); + int32_t target_length = TypedArrayHelper::GetArrayLength(thread, target_obj); + JSHandle target_name(thread, JSTypedArray::Cast(*target_obj)->GetTypedArrayName()); + int32_t target_element_size = TypedArrayHelper::GetSizeFromName(thread, target_name); + DataViewType target_type = TypedArrayHelper::GetTypeFromName(thread, target_name); + int32_t target_byte_offset = TypedArrayHelper::GetByteOffset(thread, target_obj); - JSHandle argArray = GetCallArg(argv, 0); + JSHandle arg_array = GetCallArg(argv, 0); // 22.2.3.22.1 %TypedArray%.prototype.set (array [ , offset ] ) - if (!argArray->IsTypedArray()) { + if (!arg_array->IsTypedArray()) { // 16. Let src be ToObject(array). - JSHandle src = JSTaggedValue::ToObject(thread, argArray); + JSHandle src = JSTaggedValue::ToObject(thread, arg_array); // 17. ReturnIfAbrupt(src). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 18. Let srcLength be ToLength(Get(src, "length")). - JSHandle lengthKey = thread->GlobalConstants()->GetHandledLengthString(); - JSHandle lenResult = - JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), lengthKey).GetValue(); + JSHandle length_key = thread->GlobalConstants()->GetHandledLengthString(); + JSHandle len_result = + JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), length_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedNumber tSrcLen = JSTaggedValue::ToLength(thread, lenResult); + JSTaggedNumber t_src_len = JSTaggedValue::ToLength(thread, len_result); // 19. ReturnIfAbrupt(srcLength). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double srcLen = tSrcLen.GetNumber(); + double src_len = t_src_len.GetNumber(); // 20. If srcLength + targetOffset > targetLength, throw a RangeError exception. - if (srcLen + targetOffset > targetLength) { + if (src_len + target_offset > target_length) { THROW_RANGE_ERROR_AND_RETURN(thread, "The sum of srcLength and targetOffset is greater than targetLength.", JSTaggedValue::Exception()); } // 21. Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset. - int32_t targetByteIndex = targetOffset * targetElementSize + targetByteOffset; + int32_t target_byte_index = target_offset * target_element_size + target_byte_offset; // 22. Let k be 0. // 23. Let limit be targetByteIndex + targetElementSize × srcLength. int32_t k = 0; - int32_t limit = targetByteIndex + targetElementSize * srcLen; + int32_t limit = target_byte_index + target_element_size * src_len; // 24. Repeat, while targetByteIndex < limit // a. Let Pk be ToString(k). // b. Let kNumber be ToNumber(Get(src, Pk)). @@ -1015,42 +1018,42 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // e. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber). // f. Set k to k + 1. // g. Set targetByteIndex to targetByteIndex + targetElementSize. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle kNumberHandle(thread, JSTaggedValue::Undefined()); - while (targetByteIndex < limit) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - JSHandle kValue = - JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), kKey).GetValue(); + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle k_number_handle(thread, JSTaggedValue::Undefined()); + while (target_byte_index < limit) { + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + JSHandle k_value = + JSTaggedValue::GetProperty(thread, JSHandle::Cast(src), k_key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (BuiltinsArrayBuffer::IsDetachedBuffer(targetBuffer.GetTaggedValue())) { + if (BuiltinsArrayBuffer::IsDetachedBuffer(target_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The targetBuffer of This value is detached buffer.", JSTaggedValue::Exception()); } - ContentType contentType = JSHandle::Cast(target)->GetContentType(); - if (contentType == ContentType::BigInt) { - kNumberHandle.Update(JSTaggedValue::ToBigInt(thread, kValue)); + ContentType content_type = JSHandle::Cast(target)->GetContentType(); + if (content_type == ContentType::BIG_INT) { + k_number_handle.Update(JSTaggedValue::ToBigInt(thread, k_value)); } else { - kNumberHandle.Update(JSTaggedValue::ToNumber(thread, kValue)); + k_number_handle.Update(JSTaggedValue::ToNumber(thread, k_value)); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - BuiltinsArrayBuffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, targetType, kNumberHandle, - true); + BuiltinsArrayBuffer::SetValueInBuffer(thread, target_buffer, target_byte_index, target_type, + k_number_handle, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); k++; - targetByteIndex = targetByteIndex + targetElementSize; + target_byte_index = target_byte_index + target_element_size; } // 25. Return undefined. return JSTaggedValue::Undefined(); } // 22.2.3.22.2 %TypedArray%.prototype.set(typedArray [, offset ] ) - JSHandle typedArray(argArray); + JSHandle typed_array(arg_array); // 12. Let srcBuffer be the value of typedArray’s [[ViewedArrayBuffer]] internal slot. // 13. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSMutableHandle srcBuffer(thread, JSTypedArray::Cast(*typedArray)->GetViewedArrayBuffer()); - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + JSMutableHandle src_buffer(thread, JSTypedArray::Cast(*typed_array)->GetViewedArrayBuffer()); + if (BuiltinsArrayBuffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of typedArray is detached buffer.", JSTaggedValue::Exception()); } @@ -1059,13 +1062,13 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 20. Let srcElementSize be the Number value of the Element Size value specified in Table 49 for srcName. // 21. Let srcLength be the value of typedArray’s [[ArrayLength]] internal slot. // 22. Let srcByteOffset be the value of typedArray’s [[ByteOffset]] internal slot. - JSHandle srcName(thread, JSTypedArray::Cast(*typedArray)->GetTypedArrayName()); - DataViewType srcType = TypedArrayHelper::GetTypeFromName(thread, srcName); - int32_t srcElementSize = TypedArrayHelper::GetSizeFromName(thread, srcName); - int32_t srcLength = TypedArrayHelper::GetArrayLength(thread, typedArray); - int32_t srcByteOffset = TypedArrayHelper::GetByteOffset(thread, typedArray); + JSHandle src_name(thread, JSTypedArray::Cast(*typed_array)->GetTypedArrayName()); + DataViewType src_type = TypedArrayHelper::GetTypeFromName(thread, src_name); + int32_t src_element_size = TypedArrayHelper::GetSizeFromName(thread, src_name); + int32_t src_length = TypedArrayHelper::GetArrayLength(thread, typed_array); + int32_t src_byte_offset = TypedArrayHelper::GetByteOffset(thread, typed_array); // 23. If srcLength + targetOffset > targetLength, throw a RangeError exception. - if (srcLength + targetOffset > targetLength) { + if (src_length + target_offset > target_length) { THROW_RANGE_ERROR_AND_RETURN(thread, "The sum of srcLength and targetOffset is greater than targetLength.", JSTaggedValue::Exception()); } @@ -1076,19 +1079,19 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // c. ReturnIfAbrupt(srcBuffer). // d. Let srcByteIndex be 0. // 25. Else, let srcByteIndex be srcByteOffset. - int32_t srcByteIndex; - if (JSTaggedValue::SameValue(srcBuffer.GetTaggedValue(), targetBuffer.GetTaggedValue())) { - srcBuffer.Update( - BuiltinsArrayBuffer::CloneArrayBuffer(thread, targetBuffer, srcByteOffset, env->GetArrayBufferFunction())); + 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())); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - srcByteIndex = 0; + src_byte_index = 0; } else { - srcByteIndex = srcByteOffset; + src_byte_index = src_byte_offset; } // 26. Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset. - int32_t targetByteIndex = targetOffset * targetElementSize + targetByteOffset; + int32_t target_byte_index = target_offset * target_element_size + target_byte_offset; // 27. Let limit be targetByteIndex + targetElementSize × srcLength. - int32_t limit = targetByteIndex + targetElementSize * srcLength; + int32_t limit = target_byte_index + target_element_size * src_length; // 28. If SameValue(srcType, targetType) is false, then // a. Repeat, while targetByteIndex < limit // i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). @@ -1096,15 +1099,15 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // iii. Set srcByteIndex to srcByteIndex + srcElementSize. // iv. Set targetByteIndex to targetByteIndex + targetElementSize. JSMutableHandle value(thread, JSTaggedValue::Undefined()); - if (srcType != targetType) { - while (targetByteIndex < limit) { - JSTaggedValue taggedData = - BuiltinsArrayBuffer::GetValueFromBuffer(thread, srcBuffer, srcByteIndex, srcType, true); - value.Update(taggedData); - BuiltinsArrayBuffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, targetType, value, true); + if (src_type != target_type) { + while (target_byte_index < limit) { + JSTaggedValue tagged_data = + BuiltinsArrayBuffer::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); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - srcByteIndex = srcByteIndex + srcElementSize; - targetByteIndex = targetByteIndex + targetElementSize; + src_byte_index = src_byte_index + src_element_size; + target_byte_index = target_byte_index + target_element_size; } } else { // 29. Else, @@ -1115,18 +1118,18 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // ii. Perform SetValueInBuffer (targetBuffer, targetByteIndex, "Uint8", value). // iii. Set srcByteIndex to srcByteIndex + 1. // iv. Set targetByteIndex to targetByteIndex + 1. - while (targetByteIndex < limit) { - JSTaggedValue taggedData = + while (target_byte_index < limit) { + JSTaggedValue tagged_data = // TODO(audovichenko): Remove this suppression when CSA gets recognize primitive TaggedValue // (issue #I5QOJX) // SUPPRESS_CSA_NEXTLINE(alpha.core.WasteObjHeader) - BuiltinsArrayBuffer::GetValueFromBuffer(thread, srcBuffer, srcByteIndex, DataViewType::UINT8, true); - value.Update(taggedData); - BuiltinsArrayBuffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, DataViewType::UINT8, value, + BuiltinsArrayBuffer::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); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - srcByteIndex = srcByteIndex + 1; - targetByteIndex = targetByteIndex + 1; + src_byte_index = src_byte_index + 1; + target_byte_index = target_byte_index + 1; } } // 30. Return undefined. @@ -1139,62 +1142,63 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Slice); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObj(thisHandle); + JSHandle this_obj(this_handle); // 4. Let len be the value of O’s [[ArrayLength]] internal slot. - int32_t len = TypedArrayHelper::GetArrayLength(thread, thisObj); + int32_t len = TypedArrayHelper::GetArrayLength(thread, this_obj); double k; // 5. Let relativeStart be ToInteger(start). - JSTaggedNumber tRelativeStart = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); + JSTaggedNumber t_relative_start = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); // 6. ReturnIfAbrupt(relativeStart). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double relativeStart = tRelativeStart.GetNumber(); + double relative_start = t_relative_start.GetNumber(); // 7. If relativeStart < 0, let k be max((len + relativeStart),0); else let k be min(relativeStart, len). - if (relativeStart < 0) { - k = relativeStart + len > 0 ? relativeStart + len : 0; + if (relative_start < 0) { + k = relative_start + len > 0 ? relative_start + len : 0; } else { - k = relativeStart < len ? relativeStart : len; + k = relative_start < len ? relative_start : len; } // 8. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). - double relativeEnd = len; + double relative_end = len; JSHandle end = GetCallArg(argv, 1); if (!end->IsUndefined()) { - JSTaggedNumber tRelativeEnd = JSTaggedValue::ToInteger(thread, end); + JSTaggedNumber t_relative_end = JSTaggedValue::ToInteger(thread, end); // 9. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - relativeEnd = tRelativeEnd.GetNumber(); + relative_end = t_relative_end.GetNumber(); } // 10. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). double final = 0; - if (relativeEnd < 0) { - final = relativeEnd + len > 0 ? relativeEnd + len : 0; + if (relative_end < 0) { + final = relative_end + len > 0 ? relative_end + len : 0; } else { - final = relativeEnd < len ? relativeEnd : len; + final = relative_end < len ? relative_end : len; } // 11. Let count be max(final – k, 0). double count = (final - k) > 0 ? (final - k) : 0; // es11 9. Let A be ? TypedArraySpeciesCreate(O, « count »). std::array args = {JSTaggedValue(count).GetRawData()}; - JSHandle newArrObj = TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); + JSHandle new_arr_obj = + TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 17. Let srcName be the String value of O’s [[TypedArrayName]] internal slot. // 18. Let srcType be the String value of the Element Type value in Table 49 for srcName. - JSHandle srcName(thread, JSTypedArray::Cast(*thisObj)->GetTypedArrayName()); - DataViewType srcType = TypedArrayHelper::GetTypeFromName(thread, srcName); + JSHandle src_name(thread, JSTypedArray::Cast(*this_obj)->GetTypedArrayName()); + DataViewType src_type = TypedArrayHelper::GetTypeFromName(thread, src_name); // 19. Let targetName be the String value of A’s [[TypedArrayName]] internal slot. // 20. Let targetType be the String value of the Element Type value in Table 49 for targetName. - JSHandle targetName(thread, JSTypedArray::Cast(*newArrObj)->GetTypedArrayName()); - DataViewType targetType = TypedArrayHelper::GetTypeFromName(thread, targetName); + JSHandle target_name(thread, JSTypedArray::Cast(*new_arr_obj)->GetTypedArrayName()); + DataViewType target_type = TypedArrayHelper::GetTypeFromName(thread, target_name); // 21. If SameValue(srcType, targetType) is false, then // a. Let n be 0. // b. Repeat, while k < final @@ -1205,19 +1209,19 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) // v. ReturnIfAbrupt(status). // vi. Increase k by 1. // vii. Increase n by 1. - JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); - JSMutableHandle ntKey(thread, JSTaggedValue::Undefined()); - if (srcType != targetType) { + JSMutableHandle t_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle k_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle nt_key(thread, JSTaggedValue::Undefined()); + if (src_type != target_type) { double n = 0; while (k < final) { - tKey.Update(JSTaggedValue(k)); - JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); - kValue.Update(JSTaggedValue::GetProperty(thread, thisHandle, kKey).GetValue().GetTaggedValue()); + t_key.Update(JSTaggedValue(k)); + JSHandle k_key(JSTaggedValue::ToString(thread, t_key)); + k_value.Update(JSTaggedValue::GetProperty(thread, this_handle, k_key).GetValue().GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - ntKey.Update(JSTaggedValue(n)); - JSHandle nKey(JSTaggedValue::ToString(thread, ntKey)); - JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), nKey, kValue, true); + nt_key.Update(JSTaggedValue(n)); + JSHandle n_key(JSTaggedValue::ToString(thread, nt_key)); + JSTaggedValue::SetProperty(thread, JSHandle(new_arr_obj), n_key, k_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); n++; k++; @@ -1226,39 +1230,40 @@ JSTaggedValue BuiltinsTypedArray::Slice(EcmaRuntimeCallInfo *argv) // 22. Else if count > 0, // a. Let srcBuffer be the value of O’s [[ViewedArrayBuffer]] internal slot. // b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. - JSHandle srcBuffer(thread, JSTypedArray::Cast(*thisObj)->GetViewedArrayBuffer()); - if (BuiltinsArrayBuffer::IsDetachedBuffer(srcBuffer.GetTaggedValue())) { + JSHandle src_buffer(thread, JSTypedArray::Cast(*this_obj)->GetViewedArrayBuffer()); + if (BuiltinsArrayBuffer::IsDetachedBuffer(src_buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of this value is detached buffer.", JSTaggedValue::Exception()); } // c. Let targetBuffer be the value of A’s [[ViewedArrayBuffer]] internal slot. - JSHandle targetBuffer(thread, JSTypedArray::Cast(*newArrObj)->GetViewedArrayBuffer()); + JSHandle target_buffer(thread, JSTypedArray::Cast(*new_arr_obj)->GetViewedArrayBuffer()); // d. Let elementSize be the Number value of the Element Size value specified in Table 49 for srcType. - int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, srcName); + int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, src_name); // e. NOTE: If srcType and targetType are the same the transfer must be performed in a manner that // preserves the bit-level encoding of the source data. f. Let srcByteOffset be the value of O’s // [[ByteOffset]] internal slot. - int32_t srcByteOffset = TypedArrayHelper::GetByteOffset(thread, thisObj); + int32_t src_byte_offset = TypedArrayHelper::GetByteOffset(thread, this_obj); // g. Let targetByteIndex be 0. // h. Let srcByteIndex be (k × elementSize) + srcByteOffset. - int32_t srcByteIndex = k * elementSize + srcByteOffset; + int32_t src_byte_index = k * element_size + src_byte_offset; // i. Repeat, while targetByteIndex < count × elementSize // i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). // ii. Perform SetValueInBuffer (targetBuffer, targetByteIndex, "Uint8", value). // iii. Increase srcByteIndex by 1. // iv. Increase targetByteIndex by 1. JSMutableHandle value(thread, JSTaggedValue::Undefined()); - for (int32_t targetByteIndex = 0; targetByteIndex < count * elementSize; srcByteIndex++, targetByteIndex++) { - JSTaggedValue taggedData = - BuiltinsArrayBuffer::GetValueFromBuffer(thread, srcBuffer, srcByteIndex, DataViewType::UINT8, true); - value.Update(taggedData); - BuiltinsArrayBuffer::SetValueInBuffer(thread, targetBuffer, targetByteIndex, DataViewType::UINT8, value, + 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); + value.Update(tagged_data); + BuiltinsArrayBuffer::SetValueInBuffer(thread, target_buffer, target_byte_index, DataViewType::UINT8, value, true); } } // 23. Return A. - return newArrObj.GetTaggedValue(); + return new_arr_obj.GetTaggedValue(); } // 22.2.3.24 @@ -1277,47 +1282,47 @@ JSTaggedValue BuiltinsTypedArray::Sort(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Sort); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let obj be ToObject(this value). - JSHandle thisHandle = GetThis(argv); - if (!thisHandle->IsTypedArray()) { + JSHandle this_handle = GetThis(argv); + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception()); } - JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); + JSHandle this_obj_handle = JSTaggedValue::ToObject(thread, this_handle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle thisObjVal(thisObjHandle); + JSHandle this_obj_val(this_obj_handle); JSHandle buffer; - buffer = JSHandle(thread, TypedArrayHelper::ValidateTypedArray(thread, thisHandle)); + buffer = JSHandle(thread, TypedArrayHelper::ValidateTypedArray(thread, this_handle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double len = TypedArrayHelper::GetArrayLength(thread, thisObjHandle); + double len = TypedArrayHelper::GetArrayLength(thread, this_obj_handle); - JSHandle callbackFnHandle = GetCallArg(argv, 0); + JSHandle callback_fn_handle = GetCallArg(argv, 0); uint32_t i = 0; while (i < len - 1) { uint32_t j = len - 1; while (j > i) { - JSHandle xValue = JSTaggedValue::GetProperty(thread, thisObjVal, j - 1).GetValue(); + JSHandle x_value = JSTaggedValue::GetProperty(thread, this_obj_val, j - 1).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle yValue = JSTaggedValue::GetProperty(thread, thisObjVal, j).GetValue(); + JSHandle y_value = JSTaggedValue::GetProperty(thread, this_obj_val, j).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - int32_t compareResult; - compareResult = TypedArrayHelper::SortCompare(thread, callbackFnHandle, buffer, xValue, yValue); + int32_t compare_result; + compare_result = TypedArrayHelper::SortCompare(thread, callback_fn_handle, buffer, x_value, y_value); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - if (compareResult > 0) { - JSTaggedValue::SetProperty(thread, thisObjVal, j - 1, yValue, true); + if (compare_result > 0) { + JSTaggedValue::SetProperty(thread, this_obj_val, j - 1, y_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSTaggedValue::SetProperty(thread, thisObjVal, j, xValue, true); + JSTaggedValue::SetProperty(thread, this_obj_val, j, x_value, true); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } j--; } i++; } - return JSTaggedValue::ToObject(thread, thisHandle).GetTaggedValue(); + return JSTaggedValue::ToObject(thread, this_handle).GetTaggedValue(); } // 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) @@ -1326,75 +1331,75 @@ JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Subarray); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, throw a TypeError exception. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value is not an object.", JSTaggedValue::Exception()); } - JSHandle thisObj(thisHandle); + JSHandle this_obj(this_handle); // 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception. - if (!thisHandle->IsTypedArray()) { + if (!this_handle->IsTypedArray()) { THROW_TYPE_ERROR_AND_RETURN(thread, "This value does not have a [[TypedArrayName]] internal slot.", JSTaggedValue::Exception()); } // 4. Assert: O has a [[ViewedArrayBuffer]] internal slot. // 6. Let srcLength be the value of O’s [[ArrayLength]] internal slot. - int32_t srcLength = TypedArrayHelper::GetArrayLength(thread, thisObj); + int32_t src_length = TypedArrayHelper::GetArrayLength(thread, this_obj); // 7. Let relativeBegin be ToInteger(begin). - JSTaggedNumber tRelativeBegin = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); + JSTaggedNumber t_relative_begin = JSTaggedValue::ToInteger(thread, GetCallArg(argv, 0)); // 8. ReturnIfAbrupt(relativeBegin). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - double relativeBegin = tRelativeBegin.GetNumber(); + double relative_begin = t_relative_begin.GetNumber(); - double beginIndex; + double begin_index; // 9. If relativeBegin < 0, let beginIndex be max((srcLength + relativeBegin), 0); else let beginIndex be // min(relativeBegin, srcLength). - if (relativeBegin < 0) { - beginIndex = relativeBegin + srcLength > 0 ? relativeBegin + srcLength : 0; + if (relative_begin < 0) { + begin_index = relative_begin + src_length > 0 ? relative_begin + src_length : 0; } else { - beginIndex = relativeBegin < srcLength ? relativeBegin : srcLength; + begin_index = relative_begin < src_length ? relative_begin : src_length; } // 10. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be ToInteger(end). - double relativeEnd = srcLength; + double relative_end = src_length; JSHandle end = GetCallArg(argv, 1); if (!end->IsUndefined()) { - JSTaggedNumber tRelativeEnd = JSTaggedValue::ToInteger(thread, end); + JSTaggedNumber t_relative_end = JSTaggedValue::ToInteger(thread, end); // 11. ReturnIfAbrupt(relativeEnd). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - relativeEnd = tRelativeEnd.GetNumber(); + relative_end = t_relative_end.GetNumber(); } // 12. If relativeEnd < 0, let endIndex be max((srcLength + relativeEnd), 0); else let endIndex be // min(relativeEnd, srcLength). - double endIndex; - if (relativeEnd < 0) { - endIndex = relativeEnd + srcLength > 0 ? relativeEnd + srcLength : 0; + double end_index; + if (relative_end < 0) { + end_index = relative_end + src_length > 0 ? relative_end + src_length : 0; } else { - endIndex = relativeEnd < srcLength ? relativeEnd : srcLength; + end_index = relative_end < src_length ? relative_end : src_length; } // 13. Let new_length be max(endIndex – beginIndex, 0). - double new_length = (endIndex - beginIndex) > 0 ? (endIndex - beginIndex) : 0; + double new_length = (end_index - begin_index) > 0 ? (end_index - begin_index) : 0; // 14. Let constructorName be the String value of O’s [[TypedArrayName]] internal slot. // 15. Let elementSize be the Number value of the Element Size value specified in Table 49 for constructorName. // 16. Let srcByteOffset be the value of O’s [[ByteOffset]] internal slot. // 17. Let beginByteOffset be srcByteOffset + beginIndex × elementSize. - JSHandle constructorName(thread, JSTypedArray::Cast(*thisObj)->GetTypedArrayName()); - int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName); - int32_t srcByteOffset = TypedArrayHelper::GetByteOffset(thread, thisObj); - int32_t beginByteOffset = srcByteOffset + beginIndex * elementSize; + JSHandle constructor_name(thread, JSTypedArray::Cast(*this_obj)->GetTypedArrayName()); + int32_t element_size = TypedArrayHelper::GetSizeFromName(thread, constructor_name); + int32_t src_byte_offset = TypedArrayHelper::GetByteOffset(thread, this_obj); + int32_t begin_byte_offset = src_byte_offset + begin_index * element_size; // 21. Let argumentsList be «buffer, beginByteOffset, new_length». // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. - JSTaggedValue buffer = JSTypedArray::Cast(*thisObj)->GetViewedArrayBuffer(); + JSTaggedValue buffer = JSTypedArray::Cast(*this_obj)->GetViewedArrayBuffer(); // 22. Return Construct(constructor, argumentsList). - std::array args = {buffer.GetRawData(), JSTaggedValue(beginByteOffset).GetRawData(), + std::array args = {buffer.GetRawData(), JSTaggedValue(begin_byte_offset).GetRawData(), JSTaggedValue(new_length).GetRawData()}; - JSHandle newArr = - TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, args.size(), args.data()); // 3: three args + JSHandle new_arr = + TypedArrayHelper::TypedArraySpeciesCreate(thread, this_obj, args.size(), args.data()); // 3: three args RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return newArr.GetTaggedValue(); + return new_arr.GetTaggedValue(); } // 22.2.3.27 @@ -1423,14 +1428,14 @@ JSTaggedValue BuiltinsTypedArray::Values(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, Values); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. Let valid be ValidateTypedArray(O). - TypedArrayHelper::ValidateTypedArray(thread, thisHandle); + TypedArrayHelper::ValidateTypedArray(thread, this_handle); // 3. ReturnIfAbrupt(valid). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); - JSHandle self(thisHandle); + JSHandle self(this_handle); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 4. Return CreateArrayIterator(O, "value"). JSHandle iter(factory->NewJSArrayIterator(self, IterationKind::VALUE)); @@ -1443,19 +1448,19 @@ JSTaggedValue BuiltinsTypedArray::ToStringTag(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), TypedArray, ToStringTag); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); // 1. Let O be the this value. - JSHandle thisHandle = GetThis(argv); + JSHandle this_handle = GetThis(argv); // 2. If Type(O) is not Object, return undefined. - if (!thisHandle->IsECMAObject()) { + if (!this_handle->IsECMAObject()) { return JSTaggedValue::Undefined(); } // 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. - if (!thisHandle->IsTypedArray()) { + if (!this_handle->IsTypedArray()) { return JSTaggedValue::Undefined(); } // 4. Let name be the value of O’s [[TypedArrayName]] internal slot. - JSTaggedValue name = JSHandle::Cast(thisHandle)->GetTypedArrayName(); + JSTaggedValue name = JSHandle::Cast(this_handle)->GetTypedArrayName(); // 5. Assert: name is a String value. ASSERT(name.IsString()); // 6. Return name. diff --git a/runtime/builtins/builtins_weak_map.cpp b/runtime/builtins/builtins_weak_map.cpp index ea8e41ecef2fd950c963ee7dc476c9847e9757a5..9aad53c94bf7f9f4f34d22aa04015519de6756e6 100644 --- a/runtime/builtins/builtins_weak_map.cpp +++ b/runtime/builtins/builtins_weak_map.cpp @@ -29,7 +29,7 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -42,26 +42,26 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle weakMap = JSHandle::Cast(obj); + JSHandle weak_map = JSHandle::Cast(obj); // 4.Set weakmap’s [[WeakMapData]] internal slot to a new empty List. - JSHandle linkedMap = LinkedHashMap::Create(thread, true); - weakMap->SetLinkedMap(thread, linkedMap); + JSHandle linked_map = LinkedHashMap::Create(thread, true); + weak_map->SetLinkedMap(thread, linked_map); // 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); // 8.If iter is undefined, return set if (iterable->IsUndefined() || iterable->IsNull()) { - return weakMap.GetTaggedValue(); + return weak_map.GetTaggedValue(); } if (!iterable->IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is not object", JSTaggedValue::Exception()); } // Let adder be Get(weakMap, "set"). - JSHandle adderKey(factory->NewFromCanBeCompressString("set")); + JSHandle adder_key(factory->NewFromCanBeCompressString("set")); JSHandle adder = - JSObject::GetProperty(thread, JSHandle(weakMap), adderKey).GetValue(); + JSObject::GetProperty(thread, JSHandle(weak_map), adder_key).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); // If IsCallable(adder) is false, throw a TypeError exception @@ -72,8 +72,8 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) JSHandle iter(JSIterator::GetIterator(thread, iterable)); // ReturnIfAbrupt(iter). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter.GetTaggedValue()); - JSHandle keyIndex(thread, JSTaggedValue(0)); - JSHandle valueIndex(thread, JSTaggedValue(1)); + JSHandle key_index(thread, JSTaggedValue(0)); + JSHandle value_index(thread, JSTaggedValue(1)); JSHandle next = JSIterator::IteratorStep(thread, iter); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); JSMutableHandle status(thread, JSTaggedValue::Undefined()); @@ -81,29 +81,29 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // ReturnIfAbrupt(next). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // Let nextValue be IteratorValue(next). - JSHandle nextValue(JSIterator::IteratorValue(thread, next)); + JSHandle next_value(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // If Type(nextItem) is not Object - if (!nextValue->IsECMAObject()) { - JSHandle typeError = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); + if (!next_value->IsECMAObject()) { + JSHandle type_error = factory->GetJSError(ErrorType::TYPE_ERROR, "nextItem is not Object"); JSHandle record( - factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(typeError))); + factory->NewCompletionRecord(CompletionRecord::THROW, JSHandle(type_error))); JSTaggedValue ret = JSIterator::IteratorClose(thread, iter, record).GetTaggedValue(); if (LIKELY(!thread->HasPendingException())) { - THROW_NEW_ERROR_AND_RETURN_VALUE(thread, typeError.GetTaggedValue(), ret); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, type_error.GetTaggedValue(), ret); }; return ret; } // Let k be Get(nextItem, "0"). - JSHandle key = JSObject::GetProperty(thread, nextValue, keyIndex).GetValue(); + JSHandle key = JSObject::GetProperty(thread, next_value, key_index).GetValue(); // If k is an abrupt completion, return IteratorClose(iter, k). if (UNLIKELY(thread->HasPendingException())) { return JSIterator::IteratorCloseAndReturn(thread, iter, key); } // Let v be Get(nextItem, "1"). - JSHandle value = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); + JSHandle value = JSObject::GetProperty(thread, next_value, value_index).GetValue(); // If v is an abrupt completion, return IteratorClose(iter, v). if (UNLIKELY(thread->HasPendingException())) { return JSIterator::IteratorCloseAndReturn(thread, iter, value); @@ -111,9 +111,9 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // Let status be Call(adder, weakMap, «nextValue.[[value]]»). - auto info = NewRuntimeCallInfo(thread, adder, JSHandle(weakMap), JSTaggedValue::Undefined(), 2); + auto info = NewRuntimeCallInfo(thread, adder, JSHandle(weak_map), JSTaggedValue::Undefined(), 2); info->SetCallArgs(key, value); - JSTaggedValue ret = JSFunction::Call(info.get()); // 2: key and value pair + JSTaggedValue ret = JSFunction::Call(info.Get()); // 2: key and value pair status.Update(ret); // If status is an abrupt completion, return IteratorClose(iter, status). @@ -123,7 +123,7 @@ JSTaggedValue BuiltinsWeakMap::WeakMapConstructor(EcmaRuntimeCallInfo *argv) // Let next be IteratorStep(iter). next = JSIterator::IteratorStep(thread, iter); } - return weakMap.GetTaggedValue(); + return weak_map.GetTaggedValue(); } JSTaggedValue BuiltinsWeakMap::Delete(EcmaRuntimeCallInfo *argv) @@ -131,7 +131,7 @@ JSTaggedValue BuiltinsWeakMap::Delete(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = 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. @@ -139,13 +139,13 @@ JSTaggedValue BuiltinsWeakMap::Delete(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakMap.", JSTaggedValue::Exception()); } - JSHandle weakMap(self); + JSHandle weak_map(self); JSHandle key = GetCallArg(argv, 0); // 5.if Type(key) is not Object, return false. if (!key->IsHeapObject()) { return GetTaggedBoolean(false); } - return GetTaggedBoolean(JSWeakMap::Delete(thread, weakMap, key)); + return GetTaggedBoolean(JSWeakMap::Delete(thread, weak_map, key)); } JSTaggedValue BuiltinsWeakMap::Has(EcmaRuntimeCallInfo *argv) @@ -153,21 +153,21 @@ JSTaggedValue BuiltinsWeakMap::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(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 jsWeakMap(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle js_weak_map(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = GetCallArg(argv, 0); // 5.if Type(key) is not Object, return false. if (!key->IsHeapObject()) { return GetTaggedBoolean(false); } int hash = LinkedHash::Hash(key.GetTaggedValue()); - return GetTaggedBoolean(jsWeakMap->Has(key.GetTaggedValue(), hash)); + return GetTaggedBoolean(js_weak_map->Has(key.GetTaggedValue(), hash)); } JSTaggedValue BuiltinsWeakMap::Get(EcmaRuntimeCallInfo *argv) @@ -175,20 +175,20 @@ JSTaggedValue BuiltinsWeakMap::Get(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Get); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self(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 jsWeakMap(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle js_weak_map(thread, JSWeakMap::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle key = GetCallArg(argv, 0); if (!key->IsHeapObject()) { return JSTaggedValue::Undefined(); } int hash = LinkedHash::Hash(key.GetTaggedValue()); - return jsWeakMap->Get(key.GetTaggedValue(), hash); + return js_weak_map->Get(key.GetTaggedValue(), hash); } JSTaggedValue BuiltinsWeakMap::Set(EcmaRuntimeCallInfo *argv) @@ -196,7 +196,7 @@ JSTaggedValue BuiltinsWeakMap::Set(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakMap, Set); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. diff --git a/runtime/builtins/builtins_weak_ref.cpp b/runtime/builtins/builtins_weak_ref.cpp index 4dd00cde643022e823768c6c6fe819471cbe2447..14d4dfd1595084753d6802d1b30bab748d734984 100644 --- a/runtime/builtins/builtins_weak_ref.cpp +++ b/runtime/builtins/builtins_weak_ref.cpp @@ -26,7 +26,7 @@ JSTaggedValue BuiltinsWeakRef::Constructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakRef, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -42,13 +42,13 @@ JSTaggedValue BuiltinsWeakRef::Constructor(EcmaRuntimeCallInfo *argv) JSHandle constructor = GetConstructor(argv); JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle weakRef = JSHandle::Cast(obj); + JSHandle weak_ref = JSHandle::Cast(obj); // 4. Perform AddToKeptObjects(target). // 5. Set weakRef.[[WeakRefTarget]] to target. - weakRef->SetReferent(thread, target.GetTaggedValue()); + weak_ref->SetReferent(thread, target.GetTaggedValue()); // Return weakRef. - return weakRef.GetTaggedValue(); + return weak_ref.GetTaggedValue(); } JSTaggedValue BuiltinsWeakRef::Deref(EcmaRuntimeCallInfo *argv) @@ -56,15 +56,15 @@ JSTaggedValue BuiltinsWeakRef::Deref(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakRef, Deref); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); // 1. Let weakRef be the this value. // 2. Perform ? RequireInternalSlot(weakRef, [[WeakRefTarget]]). if (!self->IsJSWeakRef()) { THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakRef.", JSTaggedValue::Exception()); } - JSHandle weakRef(self); + JSHandle weak_ref(self); // 3. Return WeakRefDeref(weakRef). - return weakRef->GetReferent(); + return weak_ref->GetReferent(); } } // namespace panda::ecmascript::builtins diff --git a/runtime/builtins/builtins_weak_set.cpp b/runtime/builtins/builtins_weak_set.cpp index 33d44e886a603ec27cc6f3a4d70e2f9f5b1ff745..625bf451989284b9987b80e7032adf33dbca98f0 100644 --- a/runtime/builtins/builtins_weak_set.cpp +++ b/runtime/builtins/builtins_weak_set.cpp @@ -29,7 +29,7 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[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); @@ -42,11 +42,11 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), new_target); // 3.returnIfAbrupt() RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - JSHandle weakSet = JSHandle::Cast(obj); + JSHandle weak_set = JSHandle::Cast(obj); // 3.ReturnIfAbrupt(weakSet). // 4.WeakSet set’s [[WeakSetData]] internal slot to a new empty List. - JSHandle linkedSet = LinkedHashSet::Create(thread, true); - weakSet->SetLinkedSet(thread, linkedSet); + JSHandle linked_set = LinkedHashSet::Create(thread, true); + weak_set->SetLinkedSet(thread, linked_set); // add data into weakset from iterable // 5.If iterable is not present, let iterable be undefined. @@ -54,12 +54,12 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) JSHandle iterable(GetCallArg(argv, 0)); // 8.If iter is undefined, return weakset if (iterable->IsUndefined() || iterable->IsNull()) { - return weakSet.GetTaggedValue(); + return weak_set.GetTaggedValue(); } // Let adder be Get(weakset, "add"). - JSHandle adderKey(factory->NewFromCanBeCompressString("add")); - JSHandle weakSetHandle(weakSet); - JSHandle adder = JSObject::GetProperty(thread, weakSetHandle, adderKey).GetValue(); + JSHandle adder_key(factory->NewFromCanBeCompressString("add")); + JSHandle weak_set_handle(weak_set); + JSHandle adder = JSObject::GetProperty(thread, weak_set_handle, adder_key).GetValue(); // ReturnIfAbrupt(adder). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue()); // If IsCallable(adder) is false, throw a TypeError exception @@ -73,25 +73,25 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter.GetTaggedValue()); // values in iterator_result may be a JSArray, values[0] = key values[1]=value, used valueIndex to get value from // jsarray - JSHandle valueIndex(thread, JSTaggedValue(1)); + JSHandle value_index(thread, JSTaggedValue(1)); JSHandle next = JSIterator::IteratorStep(thread, iter); JSMutableHandle status(thread, JSTaggedValue::Undefined()); while (!next->IsFalse()) { // ReturnIfAbrupt(next). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); // Let nextValue be IteratorValue(next). - JSHandle nextValue(JSIterator::IteratorValue(thread, next)); + JSHandle next_value(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next_value.GetTaggedValue()); - auto info = NewRuntimeCallInfo(thread, adder, weakSet, JSTaggedValue::Undefined(), 1); - if (nextValue->IsArray(thread)) { - auto prop = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); + auto info = NewRuntimeCallInfo(thread, adder, weak_set, JSTaggedValue::Undefined(), 1); + if (next_value->IsArray(thread)) { + auto prop = JSObject::GetProperty(thread, next_value, value_index).GetValue(); info->SetCallArgs(prop); } else { - info->SetCallArgs(nextValue); + info->SetCallArgs(next_value); } - JSTaggedValue ret = JSFunction::Call(info.get()); + JSTaggedValue ret = JSFunction::Call(info.Get()); // Let status be Call(adder, weakset, «nextValue.[[value]]»). status.Update(ret); @@ -102,7 +102,7 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) // Let next be IteratorStep(iter). next = JSIterator::IteratorStep(thread, iter); } - return weakSet.GetTaggedValue(); + return weak_set.GetTaggedValue(); } JSTaggedValue BuiltinsWeakSet::Add(EcmaRuntimeCallInfo *argv) @@ -110,7 +110,7 @@ JSTaggedValue BuiltinsWeakSet::Add(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Add); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); // 2.If Type(S) is not Object, throw a TypeError exception. @@ -127,10 +127,10 @@ JSTaggedValue BuiltinsWeakSet::Add(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "value is Symblol or String", JSTaggedValue::Exception()); } - JSHandle weakSet(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); - JSWeakSet::Add(thread, weakSet, value); - return weakSet.GetTaggedValue(); + JSWeakSet::Add(thread, weak_set, value); + return weak_set.GetTaggedValue(); } JSTaggedValue BuiltinsWeakSet::Delete(EcmaRuntimeCallInfo *argv) @@ -138,7 +138,7 @@ JSTaggedValue BuiltinsWeakSet::Delete(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Delete); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = 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. @@ -146,12 +146,12 @@ JSTaggedValue BuiltinsWeakSet::Delete(EcmaRuntimeCallInfo *argv) THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSWeakSet", JSTaggedValue::Exception()); } - JSHandle weakSet(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle value = GetCallArg(argv, 0); if (!value->IsHeapObject()) { GetTaggedBoolean(false); } - return GetTaggedBoolean(JSWeakSet::Delete(thread, weakSet, value)); + return GetTaggedBoolean(JSWeakSet::Delete(thread, weak_set, value)); } JSTaggedValue BuiltinsWeakSet::Has(EcmaRuntimeCallInfo *argv) @@ -159,19 +159,19 @@ JSTaggedValue BuiltinsWeakSet::Has(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), WeakSet, Has); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = 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 jsWeakSet(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); + JSHandle js_weak_set(thread, JSWeakSet::Cast(*JSTaggedValue::ToObject(thread, self))); JSHandle value = GetCallArg(argv, 0); if (!value->IsHeapObject()) { GetTaggedBoolean(false); } int hash = LinkedHash::Hash(value.GetTaggedValue()); - return GetTaggedBoolean(jsWeakSet->Has(value.GetTaggedValue(), hash)); + return GetTaggedBoolean(js_weak_set->Has(value.GetTaggedValue(), hash)); } } // namespace panda::ecmascript::builtins diff --git a/runtime/class_info_extractor.cpp b/runtime/class_info_extractor.cpp index 45b1942c7a301975fb23ef109ee67ff29501447a..00f10d1b4a9eae363a6ce3cf7267920614283167 100644 --- a/runtime/class_info_extractor.cpp +++ b/runtime/class_info_extractor.cpp @@ -23,75 +23,75 @@ namespace panda::ecmascript { void ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(JSThread *thread, JSHandle &extractor, const JSHandle &literal) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t literalBufferLength = literal->GetLength(); + uint32_t literal_buffer_length = literal->GetLength(); // non static properties number is hidden in the last index of Literal buffer - uint32_t nonStaticNum = literal->Get(thread, literalBufferLength - 1).GetInt(); + uint32_t non_static_num = literal->Get(thread, literal_buffer_length - 1).GetInt(); // Reserve sufficient length to prevent frequent creation. - JSHandle nonStaticKeys = factory->NewTaggedArray(nonStaticNum + NON_STATIC_RESERVED_LENGTH); - JSHandle nonStaticProperties = factory->NewTaggedArray(nonStaticNum + NON_STATIC_RESERVED_LENGTH); + JSHandle non_static_keys = factory->NewTaggedArray(non_static_num + NON_STATIC_RESERVED_LENGTH); + JSHandle non_static_properties = factory->NewTaggedArray(non_static_num + NON_STATIC_RESERVED_LENGTH); - nonStaticKeys->Set(thread, CONSTRUCTOR_INDEX, globalConst->GetConstructorString()); + non_static_keys->Set(thread, CONSTRUCTOR_INDEX, global_const->GetConstructorString()); - JSHandle nonStaticElements = factory->EmptyArray(); + JSHandle non_static_elements = factory->EmptyArray(); - if (nonStaticNum != 0U) { - ExtractContentsDetail nonStaticDetail {0, nonStaticNum * 2, NON_STATIC_RESERVED_LENGTH, nullptr}; + if (non_static_num != 0U) { + ExtractContentsDetail non_static_detail {0, non_static_num * 2, NON_STATIC_RESERVED_LENGTH, nullptr}; - if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, nonStaticDetail, nonStaticKeys, - nonStaticProperties, nonStaticElements))) { + if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, non_static_detail, non_static_keys, + non_static_properties, non_static_elements))) { extractor->SetNonStaticWithElements(); - extractor->SetNonStaticElements(thread, nonStaticElements); + extractor->SetNonStaticElements(thread, non_static_elements); } } - extractor->SetNonStaticKeys(thread, nonStaticKeys); - extractor->SetNonStaticProperties(thread, nonStaticProperties); + extractor->SetNonStaticKeys(thread, non_static_keys); + extractor->SetNonStaticProperties(thread, non_static_properties); - JSHandle prototypeHClass = CreatePrototypeHClass(thread, nonStaticKeys, nonStaticProperties); - extractor->SetPrototypeHClass(thread, prototypeHClass); + JSHandle prototype_h_class = CreatePrototypeHClass(thread, non_static_keys, non_static_properties); + extractor->SetPrototypeHClass(thread, prototype_h_class); - uint32_t staticNum = (literalBufferLength - 1) / 2 - nonStaticNum; + uint32_t static_num = (literal_buffer_length - 1) / 2 - non_static_num; // Reserve sufficient length to prevent frequent creation. - JSHandle staticKeys = factory->NewTaggedArray(staticNum + STATIC_RESERVED_LENGTH); - JSHandle staticProperties = factory->NewTaggedArray(staticNum + STATIC_RESERVED_LENGTH); + JSHandle static_keys = factory->NewTaggedArray(static_num + STATIC_RESERVED_LENGTH); + JSHandle static_properties = factory->NewTaggedArray(static_num + STATIC_RESERVED_LENGTH); - staticKeys->Set(thread, LENGTH_INDEX, globalConst->GetLengthString()); - staticKeys->Set(thread, NAME_INDEX, globalConst->GetNameString()); - staticKeys->Set(thread, PROTOTYPE_INDEX, globalConst->GetPrototypeString()); + static_keys->Set(thread, LENGTH_INDEX, global_const->GetLengthString()); + static_keys->Set(thread, NAME_INDEX, global_const->GetNameString()); + static_keys->Set(thread, PROTOTYPE_INDEX, global_const->GetPrototypeString()); - JSHandle staticElements = factory->EmptyArray(); + JSHandle static_elements = factory->EmptyArray(); - if (staticNum != 0U) { - ExtractContentsDetail staticDetail {nonStaticNum * 2, literalBufferLength - 1, STATIC_RESERVED_LENGTH, - extractor->GetConstructorMethod()}; + if (static_num != 0U) { + ExtractContentsDetail static_detail {non_static_num * 2, literal_buffer_length - 1, STATIC_RESERVED_LENGTH, + extractor->GetConstructorMethod()}; - if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, staticDetail, staticKeys, staticProperties, - staticElements))) { + if (UNLIKELY(ExtractAndReturnWhetherWithElements(thread, literal, static_detail, static_keys, static_properties, + static_elements))) { extractor->SetStaticWithElements(); - extractor->SetStaticElements(thread, staticElements); + extractor->SetStaticElements(thread, static_elements); } } else { // without static properties, set class name - PandaString clsName = extractor->GetConstructorMethod()->ParseFunctionName(); - JSHandle clsNameHandle = factory->NewFromString(clsName); - staticProperties->Set(thread, NAME_INDEX, clsNameHandle); + PandaString cls_name = extractor->GetConstructorMethod()->ParseFunctionName(); + JSHandle cls_name_handle = factory->NewFromString(cls_name); + static_properties->Set(thread, NAME_INDEX, cls_name_handle); } // set prototype internal accessor - JSHandle prototypeAccessor = globalConst->GetHandledFunctionPrototypeAccessor(); - staticProperties->Set(thread, PROTOTYPE_INDEX, prototypeAccessor); + JSHandle prototype_accessor = global_const->GetHandledFunctionPrototypeAccessor(); + static_properties->Set(thread, PROTOTYPE_INDEX, prototype_accessor); - extractor->SetStaticKeys(thread, staticKeys); - extractor->SetStaticProperties(thread, staticProperties); + extractor->SetStaticKeys(thread, static_keys); + extractor->SetStaticProperties(thread, static_properties); - JSHandle ctorHClass = CreateConstructorHClass(thread, staticKeys, staticProperties); - extractor->SetConstructorHClass(thread, ctorHClass); + JSHandle ctor_h_class = CreateConstructorHClass(thread, static_keys, static_properties); + extractor->SetConstructorHClass(thread, ctor_h_class); } bool ClassInfoExtractor::ExtractAndReturnWhetherWithElements(JSThread *thread, const JSHandle &literal, @@ -100,70 +100,70 @@ bool ClassInfoExtractor::ExtractAndReturnWhetherWithElements(JSThread *thread, c JSHandle &properties, JSHandle &elements) { - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); ASSERT(keys->GetLength() == properties->GetLength() && elements->GetLength() == 0); - uint32_t pos = detail.fillStartLoc; - bool withElemenstFlag = false; - bool isStaticFlag = detail.ctor_method != nullptr; - bool keysHasNameFlag = false; - - JSHandle nameString = globalConst->GetHandledNameString(); - JSMutableHandle firstValue(thread, JSTaggedValue::Undefined()); - JSMutableHandle secondValue(thread, JSTaggedValue::Undefined()); - for (uint32_t index = detail.extractBegin; index < detail.extractEnd; index += 2) { // 2: key-value pair - firstValue.Update(literal->Get(index)); - secondValue.Update(literal->Get(index + 1)); - ASSERT_PRINT(JSTaggedValue::IsPropertyKey(firstValue), "Key is not a property key"); - - if (LIKELY(firstValue->IsString())) { - if (isStaticFlag && !keysHasNameFlag && JSTaggedValue::SameValue(firstValue, nameString)) { - properties->Set(thread, NAME_INDEX, secondValue); - keysHasNameFlag = true; + uint32_t pos = detail.fill_start_loc; + bool with_elemenst_flag = false; + bool is_static_flag = detail.ctor_method != nullptr; + bool keys_has_name_flag = false; + + JSHandle name_string = global_const->GetHandledNameString(); + JSMutableHandle first_value(thread, JSTaggedValue::Undefined()); + JSMutableHandle second_value(thread, JSTaggedValue::Undefined()); + for (uint32_t index = detail.extract_begin; index < detail.extract_end; index += 2) { // 2: key-value pair + first_value.Update(literal->Get(index)); + second_value.Update(literal->Get(index + 1)); + ASSERT_PRINT(JSTaggedValue::IsPropertyKey(first_value), "Key is not a property key"); + + if (LIKELY(first_value->IsString())) { + if (is_static_flag && !keys_has_name_flag && JSTaggedValue::SameValue(first_value, name_string)) { + properties->Set(thread, NAME_INDEX, second_value); + keys_has_name_flag = true; continue; } // front-end can do better: write index in class literal directly. - uint32_t elementIndex = 0; - if (JSTaggedValue::StringToElementIndex(firstValue.GetTaggedValue(), &elementIndex)) { - ASSERT(elementIndex < JSObject::MAX_ELEMENT_INDEX); - uint32_t elementsLength = elements->GetLength(); - elements = TaggedArray::SetCapacity(thread, elements, elementsLength + 2); // 2: key-value pair - elements->Set(thread, elementsLength, firstValue); - elements->Set(thread, elementsLength + 1, secondValue); - withElemenstFlag = true; + uint32_t element_index = 0; + if (JSTaggedValue::StringToElementIndex(first_value.GetTaggedValue(), &element_index)) { + ASSERT(element_index < JSObject::MAX_ELEMENT_INDEX); + uint32_t elements_length = elements->GetLength(); + elements = TaggedArray::SetCapacity(thread, elements, elements_length + 2); // 2: key-value pair + elements->Set(thread, elements_length, first_value); + elements->Set(thread, elements_length + 1, second_value); + with_elemenst_flag = true; continue; } } - keys->Set(thread, pos, firstValue); - properties->Set(thread, pos, secondValue); + keys->Set(thread, pos, first_value); + properties->Set(thread, pos, second_value); pos++; } - if (isStaticFlag) { - if (LIKELY(!keysHasNameFlag)) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); + if (is_static_flag) { + if (LIKELY(!keys_has_name_flag)) { + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - PandaString clsName = detail.ctor_method->ParseFunctionName(); - JSHandle clsNameHandle = factory->NewFromString(clsName); - properties->Set(thread, NAME_INDEX, clsNameHandle); + PandaString cls_name = detail.ctor_method->ParseFunctionName(); + JSHandle cls_name_handle = factory->NewFromString(cls_name); + properties->Set(thread, NAME_INDEX, cls_name_handle); } else { // class has static name property, reserved length bigger 1 than actual, need trim - uint32_t trimOneLength = keys->GetLength() - 1; - keys->Trim(thread, trimOneLength); - properties->Trim(thread, trimOneLength); + uint32_t trim_one_length = keys->GetLength() - 1; + keys->Trim(thread, trim_one_length); + properties->Trim(thread, trim_one_length); } } - if (UNLIKELY(withElemenstFlag)) { + if (UNLIKELY(with_elemenst_flag)) { ASSERT(pos + elements->GetLength() / 2 == properties->GetLength()); // 2: half keys->Trim(thread, pos); properties->Trim(thread, pos); } - return withElemenstFlag; + return with_elemenst_flag; } JSHandle ClassInfoExtractor::CreatePrototypeHClass(JSThread *thread, JSHandle &keys, @@ -274,69 +274,69 @@ JSHandle ClassHelper::DefineClassTemplate(JSThread *thread, JSHandle { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle prototypeHClass(thread, extractor->GetPrototypeHClass()); - JSHandle prototype = factory->NewJSObject(prototypeHClass); + JSHandle prototype_h_class(thread, extractor->GetPrototypeHClass()); + JSHandle prototype = factory->NewJSObject(prototype_h_class); - JSHandle constructorHClass(thread, extractor->GetConstructorHClass()); + JSHandle constructor_h_class(thread, extractor->GetConstructorHClass()); JSHandle constructor = factory->NewJSFunctionByDynClass( - extractor->GetConstructorMethod(), constructorHClass, FunctionKind::CLASS_CONSTRUCTOR); + extractor->GetConstructorMethod(), constructor_h_class, FunctionKind::CLASS_CONSTRUCTOR); // non-static - JSHandle nonStaticProperties(thread, extractor->GetNonStaticProperties()); - nonStaticProperties->Set(thread, 0, constructor); - - uint32_t nonStaticLength = nonStaticProperties->GetLength(); - JSMutableHandle propValue(thread, JSTaggedValue::Undefined()); - - if (LIKELY(!prototypeHClass->IsDictionaryMode())) { - for (uint32_t index = 0; index < nonStaticLength; ++index) { - propValue.Update(nonStaticProperties->Get(index)); - if (propValue->IsJSFunction()) { - JSHandle propFunc = JSHandle::Cast(propValue); - propFunc->SetHomeObject(thread, prototype); - propFunc->SetConstantPool(thread, constantpool); + JSHandle non_static_properties(thread, extractor->GetNonStaticProperties()); + non_static_properties->Set(thread, 0, constructor); + + uint32_t non_static_length = non_static_properties->GetLength(); + JSMutableHandle prop_value(thread, JSTaggedValue::Undefined()); + + if (LIKELY(!prototype_h_class->IsDictionaryMode())) { + for (uint32_t index = 0; index < non_static_length; ++index) { + prop_value.Update(non_static_properties->Get(index)); + if (prop_value->IsJSFunction()) { + JSHandle prop_func = JSHandle::Cast(prop_value); + prop_func->SetHomeObject(thread, prototype); + prop_func->SetConstantPool(thread, constantpool); } - prototype->SetPropertyInlinedProps(thread, index, propValue.GetTaggedValue()); + prototype->SetPropertyInlinedProps(thread, index, prop_value.GetTaggedValue()); } } else { - JSHandle nonStaticKeys(thread, extractor->GetNonStaticKeys()); - JSHandle dict = BuildDictionaryPropeties(thread, prototype, nonStaticKeys, nonStaticProperties, - ClassPropertyType::NON_STATIC, constantpool); + JSHandle non_static_keys(thread, extractor->GetNonStaticKeys()); + JSHandle dict = BuildDictionaryPropeties( + thread, prototype, non_static_keys, non_static_properties, ClassPropertyType::NON_STATIC, constantpool); prototype->SetProperties(thread, dict); } // non-static elements if (UNLIKELY(extractor->IsNonStaticWithElements())) { - JSHandle nonStaticElements(thread, extractor->GetNonStaticElements()); - ClassHelper::HandleElementsProperties(thread, prototype, nonStaticElements, constantpool); + JSHandle non_static_elements(thread, extractor->GetNonStaticElements()); + ClassHelper::HandleElementsProperties(thread, prototype, non_static_elements, constantpool); } // static - JSHandle staticProperties(thread, extractor->GetStaticProperties()); - uint32_t staticLength = staticProperties->GetLength(); - - if (LIKELY(!constructorHClass->IsDictionaryMode())) { - for (uint32_t index = 0; index < staticLength; ++index) { - propValue.Update(staticProperties->Get(index)); - if (propValue->IsJSFunction()) { - JSHandle propFunc = JSHandle::Cast(propValue); - propFunc->SetHomeObject(thread, constructor); - propFunc->SetConstantPool(thread, constantpool); + JSHandle static_properties(thread, extractor->GetStaticProperties()); + uint32_t static_length = static_properties->GetLength(); + + if (LIKELY(!constructor_h_class->IsDictionaryMode())) { + for (uint32_t index = 0; index < static_length; ++index) { + prop_value.Update(static_properties->Get(index)); + if (prop_value->IsJSFunction()) { + JSHandle prop_func = JSHandle::Cast(prop_value); + prop_func->SetHomeObject(thread, constructor); + prop_func->SetConstantPool(thread, constantpool); } - JSHandle::Cast(constructor)->SetPropertyInlinedProps(thread, index, propValue.GetTaggedValue()); + JSHandle::Cast(constructor)->SetPropertyInlinedProps(thread, index, prop_value.GetTaggedValue()); } } else { - JSHandle staticKeys(thread, extractor->GetStaticKeys()); + JSHandle static_keys(thread, extractor->GetStaticKeys()); JSHandle dict = - BuildDictionaryPropeties(thread, JSHandle(constructor), staticKeys, staticProperties, + BuildDictionaryPropeties(thread, JSHandle(constructor), static_keys, static_properties, ClassPropertyType::STATIC, constantpool); constructor->SetProperties(thread, dict); } // static elements if (UNLIKELY(extractor->IsStaticWithElements())) { - JSHandle staticElements(thread, extractor->GetStaticElements()); - ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), staticElements, constantpool); + JSHandle static_elements(thread, extractor->GetStaticElements()); + ClassHelper::HandleElementsProperties(thread, JSHandle(constructor), static_elements, constantpool); } constructor->SetProtoOrDynClass(thread, prototype); @@ -356,8 +356,8 @@ JSHandle ClassHelper::BuildDictionaryPropeties(JSThread *thread, JSMutableHandle dict(thread, NameDictionary::Create(thread, NameDictionary::ComputeHashTableSize(length))); - JSMutableHandle propKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle propValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle prop_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle prop_value(thread, JSTaggedValue::Undefined()); for (uint32_t index = 0; index < length; index++) { PropertyAttributes attributes; if (type == ClassPropertyType::STATIC) { @@ -383,15 +383,15 @@ JSHandle ClassHelper::BuildDictionaryPropeties(JSThread *thread, } else { attributes = PropertyAttributes::Default(true, false, true); // non-enumerable } - propKey.Update(keys->Get(index)); - propValue.Update(properties->Get(index)); - if (propValue->IsJSFunction()) { - JSHandle propFunc = JSHandle::Cast(propValue); - propFunc->SetHomeObject(thread, object); - propFunc->SetConstantPool(thread, constantpool); + prop_key.Update(keys->Get(index)); + prop_value.Update(properties->Get(index)); + if (prop_value->IsJSFunction()) { + JSHandle prop_func = JSHandle::Cast(prop_value); + prop_func->SetHomeObject(thread, object); + prop_func->SetConstantPool(thread, constantpool); } - JSHandle newDict = NameDictionary::PutIfAbsent(thread, dict, propKey, propValue, attributes); - dict.Update(newDict); + JSHandle new_dict = NameDictionary::PutIfAbsent(thread, dict, prop_key, prop_value, attributes); + dict.Update(new_dict); } return dict; @@ -400,18 +400,18 @@ JSHandle ClassHelper::BuildDictionaryPropeties(JSThread *thread, void ClassHelper::HandleElementsProperties(JSThread *thread, const JSHandle &object, JSHandle &elements, const JSHandle &constantpool) { - JSMutableHandle elementsKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle elementsValue(thread, JSTaggedValue::Undefined()); + JSMutableHandle elements_key(thread, JSTaggedValue::Undefined()); + JSMutableHandle elements_value(thread, JSTaggedValue::Undefined()); for (uint32_t index = 0; index < elements->GetLength(); index += 2) { // 2: key-value pair - elementsKey.Update(elements->Get(index)); - elementsValue.Update(elements->Get(index + 1)); + elements_key.Update(elements->Get(index)); + elements_value.Update(elements->Get(index + 1)); // class property attribute is not default, will transition to dictionary directly. - JSObject::DefinePropertyByLiteral(thread, object, elementsKey, elementsValue, true); + JSObject::DefinePropertyByLiteral(thread, object, elements_key, elements_value, true); - if (elementsValue->IsJSFunction()) { - JSHandle elementsFunc = JSHandle::Cast(elementsValue); - elementsFunc->SetHomeObject(thread, object); - elementsFunc->SetConstantPool(thread, constantpool); + if (elements_value->IsJSFunction()) { + JSHandle elements_func = JSHandle::Cast(elements_value); + elements_func->SetHomeObject(thread, object); + elements_func->SetConstantPool(thread, constantpool); } } } diff --git a/runtime/class_info_extractor.h b/runtime/class_info_extractor.h index 8937f518786be2b89568deb6b9e87b351353b58d..7a992a28641159b54f082c7a1a1113b3eeda406c 100644 --- a/runtime/class_info_extractor.h +++ b/runtime/class_info_extractor.h @@ -34,9 +34,9 @@ public: static constexpr uint8_t PROTOTYPE_INDEX = 2; struct ExtractContentsDetail { - uint32_t extractBegin; - uint32_t extractEnd; - uint8_t fillStartLoc; + uint32_t extract_begin; + uint32_t extract_end; + uint8_t fill_start_loc; JSMethod *ctor_method; }; @@ -56,15 +56,15 @@ public: inline void SetNonStaticWithElements() { uint8_t bits = GetBitField(); - uint8_t newVal = NonStaticWithElementsBit::Update(bits, true); - SetBitField(newVal); + uint8_t new_val = NonStaticWithElementsBit::Update(bits, true); + SetBitField(new_val); } inline void SetStaticWithElements() { uint8_t bits = GetBitField(); - uint8_t newVal = StaticWithElementsBit::Update(bits, true); - SetBitField(newVal); + uint8_t new_val = StaticWithElementsBit::Update(bits, true); + SetBitField(new_val); } inline bool IsNonStaticWithElements() const diff --git a/runtime/class_linker/panda_file_translator.cpp b/runtime/class_linker/panda_file_translator.cpp index 497ae35e364d4d2f19f445a8fbafdfe676782f01..549adbc91f0c935e36dbb64bb06318ed2ab1e277 100644 --- a/runtime/class_linker/panda_file_translator.cpp +++ b/runtime/class_linker/panda_file_translator.cpp @@ -78,7 +78,7 @@ const JSMethod *PandaFileTranslator::FindMethods(uint32_t offset) const void PandaFileTranslator::TranslateClasses(const panda_file::File &pf, const PandaString &method_name) { - Span classIndexes = pf.GetClasses(); + Span class_indexes = pf.GetClasses(); methods_ = MakePandaUnique>(); panda_file::File::StringData sd = {static_cast(method_name.size()), @@ -88,16 +88,16 @@ void PandaFileTranslator::TranslateClasses(const panda_file::File &pf, const Pan auto filename = os::GetAbsolutePath(pf.GetFilename()); auto aot_pfile = aot_manager->FindPandaFile(filename); - for (const uint32_t index : classIndexes) { - panda_file::File::EntityId classId(index); - if (pf.IsExternal(classId)) { + for (const uint32_t index : class_indexes) { + panda_file::File::EntityId class_id(index); + if (pf.IsExternal(class_id)) { continue; } - panda_file::ClassDataAccessor cda(pf, classId); + panda_file::ClassDataAccessor cda(pf, class_id); auto descriptor = cda.GetDescriptor(); compiler::AotClass aot_class = - (aot_pfile != nullptr) ? aot_pfile->GetClass(classId.GetOffset()) : compiler::AotClass::Invalid(); + (aot_pfile != nullptr) ? aot_pfile->GetClass(class_id.GetOffset()) : compiler::AotClass::Invalid(); cda.EnumerateMethods([this, &aot_class, &sd, &pf, &descriptor](panda_file::MethodDataAccessor &mda) { TranslateMethod(aot_class, sd, pf, descriptor, mda); @@ -109,11 +109,11 @@ void PandaFileTranslator::TranslateMethod(const compiler::AotClass &aot_class, c const panda_file::File &pf, const uint8_t *descriptor, panda_file::MethodDataAccessor &mda) { - auto codeId = mda.GetCodeId(); - ASSERT(codeId.has_value()); + auto code_id = mda.GetCodeId(); + ASSERT(code_id.has_value()); - panda_file::CodeDataAccessor codeDataAccessor(pf, codeId.value()); - uint32_t codeSize = codeDataAccessor.GetCodeSize(); + panda_file::CodeDataAccessor code_data_accessor(pf, code_id.value()); + uint32_t code_size = code_data_accessor.GetCodeSize(); if (main_method_index_ == 0 && pf.GetStringData(mda.GetNameId()) == sd) { main_method_index_ = mda.GetMethodId().GetOffset(); @@ -131,8 +131,8 @@ void PandaFileTranslator::TranslateMethod(const compiler::AotClass &aot_class, c ASSERT(klass != nullptr); // Very important assert. - methods_->emplace_back(klass, &pf, mda.GetMethodId(), codeDataAccessor.GetCodeId(), mda.GetAccessFlags(), - codeDataAccessor.GetNumArgs(), reinterpret_cast(pda.GetShorty().Data())); + methods_->emplace_back(klass, &pf, mda.GetMethodId(), code_data_accessor.GetCodeId(), mda.GetAccessFlags(), + code_data_accessor.GetNumArgs(), reinterpret_cast(pda.GetShorty().Data())); JSMethod *method = &methods_->back(); if (aot_class.IsValid()) { @@ -148,20 +148,20 @@ void PandaFileTranslator::TranslateMethod(const compiler::AotClass &aot_class, c method->SetCallTypeFromAnnotation(); method->InitProfileVector(); - const uint8_t *insns = codeDataAccessor.GetInstructions(); + const uint8_t *insns = code_data_accessor.GetInstructions(); if (translated_code_.find(insns) == translated_code_.end()) { translated_code_.insert(insns); if (pf.GetHeader()->quickened_flag != 0U) { - TranslateBytecode(codeSize, insns, pf, method); + TranslateBytecode(code_size, insns, pf, method); } else { - TranslateBytecode(codeSize, insns, pf, method); + TranslateBytecode(code_size, insns, pf, method); } } } Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) { - EcmaHandleScope handleScope(thread_); + EcmaHandleScope handle_scope(thread_); JSHandle program = factory_->NewProgram(); JSHandle location = @@ -174,18 +174,19 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) JSHandle env = ecma_vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetFunctionClassWithProto()); - JSHandle normalDynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); - JSHandle asyncDynclass = JSHandle::Cast(env->GetAsyncFunctionClass()); - JSHandle generatorDynclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); - JSHandle asyncgeneratorDynclass = JSHandle::Cast(env->GetAsyncGeneratorFunctionClass()); + JSHandle normal_dynclass = JSHandle::Cast(env->GetFunctionClassWithoutProto()); + JSHandle async_dynclass = JSHandle::Cast(env->GetAsyncFunctionClass()); + JSHandle generator_dynclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); + JSHandle asyncgenerator_dynclass = JSHandle::Cast(env->GetAsyncGeneratorFunctionClass()); for (const auto &it : constpool_map_) { ConstPoolValue value(it.second); if (value.GetConstpoolType() == ConstPoolType::STRING) { panda_file::File::EntityId id(it.first); - auto foundStr = pf.GetStringData(id); - auto string = factory_->GetRawStringFromStringTable(foundStr.data, foundStr.utf16_length, foundStr.is_ascii, - panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + auto found_str = pf.GetStringData(id); + auto string = + factory_->GetRawStringFromStringTable(found_str.data, found_str.utf16_length, found_str.is_ascii, + panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); if (string == nullptr) { LOG(FATAL, ECMASCRIPT) << "Not enough memory"; } @@ -206,8 +207,9 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) auto method = const_cast(FindMethods(it.first)); ASSERT(method != nullptr); - JSHandle js_func = factory_->NewJSFunctionByDynClass( - method, normalDynclass, FunctionKind::NORMAL_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + JSHandle js_func = + factory_->NewJSFunctionByDynClass(method, normal_dynclass, FunctionKind::NORMAL_FUNCTION, + panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); constpool->Set(thread_, value.GetConstpoolIndex(), js_func.GetTaggedValue()); js_func->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::GENERATOR_FUNCTION) { @@ -217,7 +219,7 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) ASSERT(method != nullptr); JSHandle js_func = - factory_->NewJSFunctionByDynClass(method, generatorDynclass, FunctionKind::GENERATOR_FUNCTION, + factory_->NewJSFunctionByDynClass(method, generator_dynclass, FunctionKind::GENERATOR_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); // 26.3.4.3 prototype // Whenever a GeneratorFunction instance is created another ordinary object is also created and @@ -237,7 +239,7 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) ASSERT(method != nullptr); JSHandle js_func = factory_->NewJSFunctionByDynClass( - method, asyncDynclass, FunctionKind::ASYNC_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + method, async_dynclass, FunctionKind::ASYNC_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); constpool->Set(thread_, value.GetConstpoolIndex(), js_func.GetTaggedValue()); js_func->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::ASYNC_GENERATOR_FUNCTION) { @@ -247,7 +249,7 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) ASSERT(method != nullptr); JSHandle js_func = factory_->NewJSFunctionByDynClass( - method, asyncgeneratorDynclass, FunctionKind::ASYNC_GENERATOR_FUNCTION, + method, asyncgenerator_dynclass, FunctionKind::ASYNC_GENERATOR_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); constpool->Set(thread_, value.GetConstpoolIndex(), js_func.GetTaggedValue()); js_func->SetConstantPool(thread_, constpool.GetTaggedValue()); @@ -256,16 +258,17 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) panda_file::File::EntityId id(it.first); auto method = const_cast(FindMethods(it.first)); ASSERT(method != nullptr); - JSHandle classInfoExtractor = factory_->NewClassInfoExtractor(method); - constpool->Set(thread_, value.GetConstpoolIndex(), classInfoExtractor.GetTaggedValue()); + JSHandle class_info_extractor = factory_->NewClassInfoExtractor(method); + constpool->Set(thread_, value.GetConstpoolIndex(), class_info_extractor.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::METHOD) { ASSERT(main_method_index_ != it.first); panda_file::File::EntityId id(it.first); auto method = const_cast(FindMethods(it.first)); ASSERT(method != nullptr); - JSHandle js_func = factory_->NewJSFunctionByDynClass( - method, normalDynclass, FunctionKind::NORMAL_FUNCTION, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); + JSHandle js_func = + factory_->NewJSFunctionByDynClass(method, normal_dynclass, FunctionKind::NORMAL_FUNCTION, + panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); constpool->Set(thread_, value.GetConstpoolIndex(), js_func.GetTaggedValue()); js_func->SetConstantPool(thread_, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::OBJECT_LITERAL) { @@ -277,15 +280,15 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) thread_, properties, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); JSMutableHandle key(thread_, JSTaggedValue::Undefined()); - JSMutableHandle valueHandle(thread_, JSTaggedValue::Undefined()); - size_t elementsLen = elements->GetLength(); - for (size_t i = 0; i < elementsLen; i += 2) { // 2: Each literal buffer contains a pair of key-value. + JSMutableHandle value_handle(thread_, JSTaggedValue::Undefined()); + size_t elements_len = elements->GetLength(); + for (size_t i = 0; i < elements_len; i += 2) { // 2: Each literal buffer contains a pair of key-value. key.Update(elements->Get(i)); if (key->IsHole()) { break; } - valueHandle.Update(elements->Get(i + 1)); - JSObject::DefinePropertyByLiteral(thread_, obj, key, valueHandle); + value_handle.Update(elements->Get(i + 1)); + JSObject::DefinePropertyByLiteral(thread_, obj, key, value_handle); } constpool->Set(thread_, value.GetConstpoolIndex(), obj.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::ARRAY_LITERAL) { @@ -308,10 +311,10 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) { auto method = const_cast(FindMethods(main_method_index_)); ASSERT(method != nullptr); - JSHandle mainFunc = factory_->NewJSFunctionByDynClass( + JSHandle main_func = factory_->NewJSFunctionByDynClass( method, dynclass, FunctionKind::BASE_CONSTRUCTOR, panda::SpaceType::SPACE_TYPE_NON_MOVABLE_OBJECT); - mainFunc->SetConstantPool(thread_, constpool.GetTaggedValue()); - program->SetMainFunction(thread_, mainFunc.GetTaggedValue()); + main_func->SetConstantPool(thread_, constpool.GetTaggedValue()); + program->SetMainFunction(thread_, main_func.GetTaggedValue()); program->SetMethodsData(methods_.release()); // link program constpool->Set(thread_, constpool_index_, program.GetTaggedValue()); @@ -327,7 +330,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ { using EnumT = std::conditional_t; using R = BytecodeInstructionResolver; - constexpr int payload_offset = IS_QUICKENED ? 1 : 2; + constexpr int PAYLOAD_OFFSET = IS_QUICKENED ? 1 : 2; // NOLINTNEXTLINE(hicpp-use-auto) auto pc = const_cast(inst.GetAddress()); @@ -354,7 +357,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ case R::template Get(): { uint8_t size = sizeof(uint16_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(pc + payload_offset, size, &index, size) != EOK) { + if (memcpy_s(pc + PAYLOAD_OFFSET, size, &index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -371,7 +374,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ case R::template Get(): { uint8_t size = sizeof(uint32_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(pc + payload_offset, size, &index, size) != EOK) { + if (memcpy_s(pc + PAYLOAD_OFFSET, size, &index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -383,7 +386,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ uint16_t u16_index = index; uint8_t size = sizeof(uint16_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(pc + payload_offset, size, &u16_index, size) != EOK) { + if (memcpy_s(pc + PAYLOAD_OFFSET, size, &u16_index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -396,7 +399,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ uint8_t size = sizeof(uint16_t); ASSERT(static_cast(index) == index); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(pc + payload_offset, size, &index, size) != EOK) { + if (memcpy_s(pc + PAYLOAD_OFFSET, size, &index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -407,7 +410,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, [[ uint16_t u16_index = index; uint8_t size = sizeof(uint16_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - if (memcpy_s(pc + payload_offset + 2, size, &u16_index, size) != EOK) { + if (memcpy_s(pc + PAYLOAD_OFFSET + 2, size, &u16_index, size) != EOK) { LOG_ECMA(FATAL) << "memcpy_s failed"; UNREACHABLE(); } diff --git a/runtime/compiler/ecmascript_runtime_interface.cpp b/runtime/compiler/ecmascript_runtime_interface.cpp index 3daa2ad0a2bb599e3b40a811d113eb0dbfbb9396..37bd3d6010ab44dcb41b8ca17d3a44b0be714886 100644 --- a/runtime/compiler/ecmascript_runtime_interface.cpp +++ b/runtime/compiler/ecmascript_runtime_interface.cpp @@ -239,16 +239,16 @@ compiler::AnyBaseType EcmaRuntimeInterface::GetProfilingAnyType(RuntimeInterface RuntimeInterface::NewObjDynInfo EcmaRuntimeInterface::GetNewObjDynInfo(uintptr_t ctor) const { - static constexpr NewObjDynInfo slow_path = {NewObjDynInfo::AllocatorType::SLOW_PATH, + static constexpr NewObjDynInfo SLOW_PATH = {NewObjDynInfo::AllocatorType::SLOW_PATH, NewObjDynInfo::ResolverType::RESOLVE}; [[maybe_unused]] ScopedMutatorLock lock; JSObject *ctor_ptr = *reinterpret_cast(ctor); if (ctor_ptr == nullptr || !ctor_ptr->IsJSFunction()) { - return slow_path; + return SLOW_PATH; } auto js_fun = static_cast(ctor_ptr); if (!js_fun->IsConstructor()) { - return slow_path; + return SLOW_PATH; } auto method = js_fun->GetMethod(); @@ -257,13 +257,13 @@ RuntimeInterface::NewObjDynInfo EcmaRuntimeInterface::GetNewObjDynInfo(uintptr_t if (js_fun->IsBuiltinConstructor()) { return {NewObjDynInfo::AllocatorType::UNDEFINED, NewObjDynInfo::ResolverType::USE_CTOR_RESULT}; } - return slow_path; + return SLOW_PATH; } if (!js_fun->IsBase()) { if (js_fun->IsDerivedConstructor()) { return {NewObjDynInfo::AllocatorType::UNDEFINED, NewObjDynInfo::ResolverType::RESOLVE}; } - return slow_path; + return SLOW_PATH; } return {NewObjDynInfo::AllocatorType::ALLOC_OBJ, NewObjDynInfo::ResolverType::RESOLVE}; } diff --git a/runtime/containers/containers_arraylist.cpp b/runtime/containers/containers_arraylist.cpp index 90a74f16546417168a20ed15322de48dc68e6bda..41e1366945697bdd05edfd8750a727713e8256cc 100644 --- a/runtime/containers/containers_arraylist.cpp +++ b/runtime/containers/containers_arraylist.cpp @@ -25,7 +25,7 @@ JSTaggedValue ContainersArrayList::ArrayListConstructor(EcmaRuntimeCallInfo *arg ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayList, Constructor); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle new_target = GetNewTarget(argv); if (new_target->IsUndefined()) { @@ -44,7 +44,7 @@ JSTaggedValue ContainersArrayList::Add(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayList, Add); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle self = GetThis(argv); if (!self->IsJSArrayList()) { @@ -63,7 +63,7 @@ JSTaggedValue ContainersArrayList::Iterator(EcmaRuntimeCallInfo *argv) ASSERT(argv); BUILTINS_API_TRACE(argv->GetThread(), ArrayList, Iterator); JSThread *thread = argv->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); return JSTaggedValue::Undefined(); } } // namespace panda::ecmascript::containers diff --git a/runtime/containers/containers_private.cpp b/runtime/containers/containers_private.cpp index fe3ab2b0b42809c6444101ba2a87155fc0897265..1f4850f80d78ff1121d3b9948daf4deeb3ed967e 100644 --- a/runtime/containers/containers_private.cpp +++ b/runtime/containers/containers_private.cpp @@ -26,9 +26,9 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) { ASSERT(msg); JSThread *thread = msg->GetThread(); - [[maybe_unused]] EcmaHandleScope handleScope(thread); + [[maybe_unused]] EcmaHandleScope handle_scope(thread); JSHandle argv = GetCallArg(msg, 0); - JSHandle thisValue(GetThis(msg)); + JSHandle this_value(GetThis(msg)); uint32_t tag = 0; if (!JSTaggedValue::ToElementIndex(argv.GetTaggedValue(), &tag) || tag >= ContainerTag::END) { @@ -38,20 +38,20 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSTaggedValue res = JSTaggedValue::Undefined(); switch (tag) { - case ContainerTag::ArrayList: { + case ContainerTag::ARRAY_LIST: { JSHandle key(factory->NewFromCanBeCompressString("ArrayListConstructor")); JSTaggedValue value = - FastRuntimeStub::GetPropertyByName(thread, thisValue.GetTaggedValue(), key.GetTaggedValue()); + FastRuntimeStub::GetPropertyByName(thread, this_value.GetTaggedValue(), key.GetTaggedValue()); if (value != JSTaggedValue::Undefined()) { res = value; } else { - JSHandle arrayList = InitializeArrayList(thread); - SetFrozenConstructor(thread, thisValue, "ArrayListConstructor", arrayList); - res = arrayList.GetTaggedValue(); + JSHandle array_list = InitializeArrayList(thread); + SetFrozenConstructor(thread, this_value, "ArrayListConstructor", array_list); + res = array_list.GetTaggedValue(); } break; } - case ContainerTag::Queue: + case ContainerTag::QUEUE: case ContainerTag::END: break; default: @@ -62,21 +62,21 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) } JSHandle ContainersPrivate::NewContainerConstructor(JSThread *thread, const JSHandle &prototype, - EcmaEntrypoint ctorFunc, const char *name, int length) + EcmaEntrypoint ctor_func, const char *name, int length) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle ctor = - factory->NewJSFunction(env, reinterpret_cast(ctorFunc), FunctionKind::BUILTIN_CONSTRUCTOR); + factory->NewJSFunction(env, reinterpret_cast(ctor_func), FunctionKind::BUILTIN_CONSTRUCTOR); - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); JSFunction::SetFunctionLength(thread, ctor, JSTaggedValue(length)); - JSHandle nameString(factory->NewFromCanBeCompressString(name)); - JSFunction::SetFunctionName(thread, JSHandle(ctor), nameString, + JSHandle name_string(factory->NewFromCanBeCompressString(name)); + JSFunction::SetFunctionName(thread, JSHandle(ctor), name_string, JSHandle(thread, JSTaggedValue::Undefined())); - JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSHandle constructor_key = global_const->GetHandledConstructorString(); PropertyDescriptor descriptor1(thread, JSHandle::Cast(ctor), true, false, true); - JSObject::DefineOwnProperty(thread, prototype, constructorKey, descriptor1); + JSObject::DefineOwnProperty(thread, prototype, constructor_key, descriptor1); /* set "prototype" in constructor */ ctor->SetFunctionPrototype(thread, prototype.GetTaggedValue()); @@ -88,18 +88,18 @@ void ContainersPrivate::SetFrozenFunction(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); - JSHandle keyString(factory->NewFromCanBeCompressString(key)); - JSHandle function = NewFunction(thread, keyString, func, length); + JSHandle key_string(factory->NewFromCanBeCompressString(key)); + JSHandle function = NewFunction(thread, key_string, func, length); PropertyDescriptor descriptor(thread, JSHandle(function), false, false, false); - JSObject::DefineOwnProperty(thread, obj, keyString, descriptor); + JSObject::DefineOwnProperty(thread, obj, key_string, descriptor); } -void ContainersPrivate::SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *keyChar, +void ContainersPrivate::SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *key_char, JSHandle &value) { JSObject::PreventExtensions(thread, obj); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle key(factory->NewFromCanBeCompressString(keyChar)); + JSHandle key(factory->NewFromCanBeCompressString(key_char)); PropertyDescriptor descriptor(thread, value, false, false, false); JSObject::DefineOwnProperty(thread, obj, key, descriptor); } @@ -111,8 +111,8 @@ JSHandle ContainersPrivate::NewFunction(JSThread *thread, const JSHa JSHandle function = factory->NewJSFunction(thread->GetEcmaVM()->GetGlobalEnv(), reinterpret_cast(func)); JSFunction::SetFunctionLength(thread, function, JSTaggedValue(length)); - JSHandle baseFunction(function); - JSFunction::SetFunctionName(thread, baseFunction, key, thread->GlobalConstants()->GetHandledUndefined()); + JSHandle base_function(function); + JSFunction::SetFunctionName(thread, base_function, key, thread->GlobalConstants()->GetHandledUndefined()); return function; } @@ -123,9 +123,9 @@ JSHandle ContainersPrivate::CreateGetter(JSThread *thread, EcmaEn ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle function = factory->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread, function, JSTaggedValue(length)); - JSHandle funcName(factory->NewFromString(name)); + JSHandle func_name(factory->NewFromString(name)); JSHandle prefix = thread->GlobalConstants()->GetHandledGetString(); - JSFunction::SetFunctionName(thread, JSHandle(function), funcName, prefix); + JSFunction::SetFunctionName(thread, JSHandle(function), func_name, prefix); return JSHandle(function); } @@ -146,9 +146,9 @@ void ContainersPrivate::SetFunctionAtSymbol(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); JSHandle function = factory->NewJSFunction(env, reinterpret_cast(func)); JSFunction::SetFunctionLength(thread, function, JSTaggedValue(length)); - JSHandle nameString(factory->NewFromString(name)); - JSHandle baseFunction(function); - JSFunction::SetFunctionName(thread, baseFunction, nameString, thread->GlobalConstants()->GetHandledUndefined()); + JSHandle name_string(factory->NewFromString(name)); + JSHandle base_function(function); + JSFunction::SetFunctionName(thread, base_function, name_string, thread->GlobalConstants()->GetHandledUndefined()); PropertyDescriptor descriptor(thread, JSHandle::Cast(function), false, false, false); JSObject::DefineOwnProperty(thread, obj, symbol, descriptor); @@ -166,26 +166,28 @@ void ContainersPrivate::SetStringTagSymbol(JSThread *thread, const JSHandle ContainersPrivate::InitializeArrayList(JSThread *thread) { - const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + const GlobalEnvConstants *global_const = thread->GlobalConstants(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // ArrayList.prototype - JSHandle arrayListFuncPrototype = factory->NewEmptyJSObject(); - JSHandle arrayListFuncPrototypeValue(arrayListFuncPrototype); + JSHandle array_list_func_prototype = factory->NewEmptyJSObject(); + JSHandle array_list_func_prototype_value(array_list_func_prototype); // ArrayList.prototype_or_dynclass - JSHandle arrayListInstanceDynclass = - factory->CreateDynClass(JSType::JS_ARRAY_LIST, arrayListFuncPrototypeValue); + JSHandle array_list_instance_dynclass = + factory->CreateDynClass(JSType::JS_ARRAY_LIST, array_list_func_prototype_value); // ArrayList() = new Function() - JSHandle arrayListFunction(NewContainerConstructor( - thread, arrayListFuncPrototype, ContainersArrayList::ArrayListConstructor, "ArrayList", FuncLength::ZERO)); - JSHandle(arrayListFunction)->SetFunctionPrototype(thread, arrayListInstanceDynclass.GetTaggedValue()); + JSHandle array_list_function(NewContainerConstructor( + thread, array_list_func_prototype, ContainersArrayList::ArrayListConstructor, "ArrayList", FuncLength::ZERO)); + JSHandle(array_list_function) + ->SetFunctionPrototype(thread, array_list_instance_dynclass.GetTaggedValue()); // "constructor" property on the prototype - JSHandle constructorKey = globalConst->GetHandledConstructorString(); - JSObject::SetProperty(thread, JSHandle(arrayListFuncPrototype), constructorKey, arrayListFunction); + JSHandle constructor_key = global_const->GetHandledConstructorString(); + JSObject::SetProperty(thread, JSHandle(array_list_func_prototype), constructor_key, + array_list_function); // ArrayList.prototype.add() - SetFrozenFunction(thread, arrayListFuncPrototype, "add", ContainersArrayList::Add, FuncLength::ONE); + SetFrozenFunction(thread, array_list_func_prototype, "add", ContainersArrayList::Add, FuncLength::ONE); - return arrayListFunction; + return array_list_function; } } // namespace panda::ecmascript::containers diff --git a/runtime/containers/containers_private.h b/runtime/containers/containers_private.h index 705dc53e5a91ffe230fa0a91f8b7c7cdf018a076..83a7a686338891dc987d4f03966a17e2ff94edcd 100644 --- a/runtime/containers/containers_private.h +++ b/runtime/containers/containers_private.h @@ -21,20 +21,20 @@ namespace panda::ecmascript::containers { enum FuncLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR }; enum ContainerTag : uint8_t { - ArrayList = 0, - Queue, - Deque, - Stack, - Vector, - List, - LinkedList, - TreeMap, - TreeSet, - HashMap, - HashSet, - LightWightMap, - LightWightSet, - PlainArray, + ARRAY_LIST = 0, + QUEUE, + DEQUE, + STACK, + VECTOR, + LIST, + LINKED_LIST, + TREE_MAP, + TREE_SET, + HASH_MAP, + HASH_SET, + LIGHT_WIGHT_MAP, + LIGHT_WIGHT_SET, + PLAIN_ARRAY, END }; // Using Lazy-loading container, including ArrayList, Queue, Stack, Vector, List, LinkedList, Deque, @@ -46,12 +46,12 @@ public: private: static JSHandle NewContainerConstructor(JSThread *thread, const JSHandle &prototype, - EcmaEntrypoint ctorFunc, const char *name, int length); + EcmaEntrypoint ctor_func, const char *name, int length); static JSHandle NewFunction(JSThread *thread, const JSHandle &key, EcmaEntrypoint func, int length); static void SetFrozenFunction(JSThread *thread, const JSHandle &obj, const char *key, EcmaEntrypoint func, int length); - static void SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *keyChar, + static void SetFrozenConstructor(JSThread *thread, const JSHandle &obj, const char *key_char, JSHandle &value); static JSHandle CreateGetter(JSThread *thread, EcmaEntrypoint func, const char *name, int length); static void SetGetter(JSThread *thread, const JSHandle &obj, const JSHandle &key, diff --git a/runtime/dump.cpp b/runtime/dump.cpp index 581bbb548df48b1aa10736198718e0f005f5a94a..2a807e9e26bad75e92cf9ee2e7effb93da022c1d 100644 --- a/runtime/dump.cpp +++ b/runtime/dump.cpp @@ -314,7 +314,7 @@ static void DumpPropertyKey(JSTaggedValue key, std::ostream &os) } } -static void DumpHClass(JSThread *thread, const JSHClass *jshclass, std::ostream &os, bool withDetail) +static void DumpHClass(JSThread *thread, const JSHClass *jshclass, std::ostream &os, bool with_detail) { os << "JSHClass :" << std::setw(DUMP_TYPE_OFFSET); os << "Type :" << JSHClass::DumpJSType(jshclass->GetObjectType()) << "\n"; @@ -326,15 +326,15 @@ static void DumpHClass(JSThread *thread, const JSHClass *jshclass, std::ostream JSTaggedValue attrs = jshclass->GetLayout(); attrs.DumpTaggedValue(thread, os); os << "\n"; - if (withDetail && !attrs.IsNull()) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); - layoutInfo->Dump(thread, os); + if (with_detail && !attrs.IsNull()) { + LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetTaggedObject()); + layout_info->Dump(thread, os); } os << " - Transitions :" << std::setw(DUMP_TYPE_OFFSET); JSTaggedValue transtions = jshclass->GetTransitions(); transtions.DumpTaggedValue(thread, os); os << "\n"; - if (withDetail && !transtions.IsNull()) { + if (with_detail && !transtions.IsNull()) { transtions.Dump(thread, os); } os << " - Parent :" << std::setw(DUMP_TYPE_OFFSET); @@ -358,7 +358,7 @@ static void DumpDynClass(JSThread *thread, TaggedObject *obj, std::ostream &os) DumpHClass(thread, hclass, os, true); } -static void DumpAttr(const PropertyAttributes &attr, bool fastMode, std::ostream &os) +static void DumpAttr(const PropertyAttributes &attr, bool fast_mode, std::ostream &os) { if (attr.IsAccessor()) { os << "(Accessor) "; @@ -381,7 +381,7 @@ static void DumpAttr(const PropertyAttributes &attr, bool fastMode, std::ostream os << " InlinedProps: " << attr.IsInlinedProps(); - if (fastMode) { + if (fast_mode) { os << " Order: " << std::dec << attr.GetOffset(); os << " SortedIndex: " << std::dec << attr.GetSortedIndex(); } else { @@ -392,8 +392,8 @@ static void DumpAttr(const PropertyAttributes &attr, bool fastMode, std::ostream // NOLINTNEXTLINE(readability-function-size) static void DumpObject(JSThread *thread, TaggedObject *obj, std::ostream &os) { - auto jsHclass = obj->GetClass(); - JSType type = jsHclass->GetObjectType(); + auto js_hclass = obj->GetClass(); + JSType type = js_hclass->GetObjectType(); switch (type) { case JSType::HCLASS: @@ -646,7 +646,7 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, std::ostream &os) break; } - DumpHClass(thread, jsHclass, os, false); + DumpHClass(thread, js_hclass, os, false); } void JSTaggedValue::DumpSpecialValue([[maybe_unused]] JSThread *thread, std::ostream &os) const @@ -695,9 +695,9 @@ void JSTaggedValue::DumpHeapObjectType([[maybe_unused]] JSThread *thread, std::o } else { std::ostringstream address; address << obj; - PandaString addrStr = PandaString(address.str()); + PandaString addr_str = PandaString(address.str()); - os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[" + JSHClass::DumpJSType(type) + "(" + addrStr + ")]"; + os << std::left << std::setw(DUMP_TYPE_OFFSET) << "[" + JSHClass::DumpJSType(type) + "(" + addr_str + ")]"; } } @@ -747,15 +747,15 @@ void JSThread::DumpStack() void NumberDictionary::Dump(JSThread *thread, std::ostream &os) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(hash_index)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << static_cast(JSTaggedNumber(key).GetNumber()) << ": "; val.DumpTaggedValue(thread, os); os << " "; - DumpAttr(GetAttributes(hashIndex), false, os); + DumpAttr(GetAttributes(hash_index), false, os); os << "\n"; } } @@ -764,16 +764,16 @@ void NumberDictionary::Dump(JSThread *thread, std::ostream &os) const void NameDictionary::Dump(JSThread *thread, std::ostream &os) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(hash_index)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); os << ": "; val.DumpTaggedValue(thread, os); os << " "; - DumpAttr(GetAttributes(hashIndex), false, os); + DumpAttr(GetAttributes(hash_index), false, os); os << "\n"; } } @@ -782,16 +782,16 @@ void NameDictionary::Dump(JSThread *thread, std::ostream &os) const void GlobalDictionary::Dump(JSThread *thread, std::ostream &os) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(hash_index)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); os << " : "; val.DumpTaggedValue(thread, os); os << " "; - DumpAttr(GetAttributes(hashIndex), false, os); + DumpAttr(GetAttributes(hash_index), false, os); os << "\n"; } } @@ -815,15 +815,15 @@ void LayoutInfo::Dump([[maybe_unused]] JSThread *thread, std::ostream &os) const void TransitionsDictionary::Dump(JSThread *thread, std::ostream &os) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); os << " : "; - GetValue(hashIndex).DumpTaggedValue(thread, os); + GetValue(hash_index).DumpTaggedValue(thread, os); os << " : "; - GetAttributes(hashIndex).DumpTaggedValue(thread, os); + GetAttributes(hash_index).DumpTaggedValue(thread, os); os << "\n"; } } @@ -832,8 +832,8 @@ void TransitionsDictionary::Dump(JSThread *thread, std::ostream &os) const void LinkedHashSet::Dump(JSThread *thread, std::ostream &os) const { int capacity = NumberOfElements() + NumberOfDeletedElements(); - for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < capacity; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET); key.DumpTaggedValue(thread, os); @@ -845,10 +845,10 @@ void LinkedHashSet::Dump(JSThread *thread, std::ostream &os) const void LinkedHashMap::Dump(JSThread *thread, std::ostream &os) const { int capacity = NumberOfElements() + NumberOfDeletedElements(); - for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < capacity; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(hash_index)); os << std::right << std::setw(DUMP_PROPERTY_OFFSET); key.DumpTaggedValue(thread, os); os << ": "; @@ -893,12 +893,12 @@ void JSObject::Dump(JSThread *thread, std::ostream &os) const return; } - LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject()); - int propNumber = jshclass->NumberOfProps(); - os << " \n"; - for (int i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); - PropertyAttributes attr = layoutInfo->GetAttr(i); + LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetTaggedObject()); + int prop_number = jshclass->NumberOfProps(); + os << " \n"; + for (int i = 0; i < prop_number; i++) { + JSTaggedValue key = layout_info->GetKey(i); + PropertyAttributes attr = layout_info->GetAttr(i); ASSERT(i == static_cast(attr.GetOffset())); os << " " << std::right << std::setw(DUMP_PROPERTY_OFFSET); DumpPropertyKey(key, os); @@ -1235,8 +1235,8 @@ void JSProxy::Dump(JSThread *thread, std::ostream &os) const void JSSymbol::Dump([[maybe_unused]] JSThread *thread, std::ostream &os) const { os << " - hash-field: "; - JSTaggedValue hashField = GetHashField(); - hashField.D(); + JSTaggedValue hash_field = GetHashField(); + hash_field.D(); os << " - flags: "; JSTaggedValue flags = GetFlags(); flags.D(); @@ -1253,7 +1253,7 @@ void LexicalEnv::Dump(JSThread *thread, std::ostream &os) const // NOLINTNEXTLINE(readability-function-size) void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const { - auto globalConst = thread->GlobalConstants(); + auto global_const = thread->GlobalConstants(); os << " - ObjectFunction: "; GetObjectFunction().GetTaggedValue().Dump(thread, os); os << " - FunctionFunction: "; @@ -1325,11 +1325,11 @@ void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const os << " - EmptyArray: "; GetEmptyArray().GetTaggedValue().Dump(thread, os); os << " - EmptyString "; - globalConst->GetEmptyString().Dump(thread, os); + global_const->GetEmptyString().Dump(thread, os); os << " - EmptyTaggedQueue: "; GetEmptyTaggedQueue().GetTaggedValue().Dump(thread, os); os << " - PrototypeString: "; - globalConst->GetPrototypeString().Dump(thread, os); + global_const->GetPrototypeString().Dump(thread, os); os << " - HasInstanceSymbol: "; GetHasInstanceSymbol().GetTaggedValue().Dump(thread, os); os << " - IsConcatSpreadableSymbol: "; @@ -1355,7 +1355,7 @@ void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const os << " - HoleySymbol: "; GetHoleySymbol().GetTaggedValue().Dump(thread, os); os << " - ConstructorString: "; - globalConst->GetConstructorString().Dump(thread, os); + global_const->GetConstructorString().Dump(thread, os); os << " - IteratorPrototype: "; GetIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - ForinIteratorPrototype: "; @@ -1373,77 +1373,77 @@ void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const os << " - StringIteratorPrototype: "; GetStringIteratorPrototype().GetTaggedValue().Dump(thread, os); os << " - LengthString: "; - globalConst->GetLengthString().Dump(thread, os); + global_const->GetLengthString().Dump(thread, os); os << " - ValueString: "; - globalConst->GetValueString().Dump(thread, os); + global_const->GetValueString().Dump(thread, os); os << " - WritableString: "; - globalConst->GetWritableString().Dump(thread, os); + global_const->GetWritableString().Dump(thread, os); os << " - GetString: "; - globalConst->GetGetString().Dump(thread, os); + global_const->GetGetString().Dump(thread, os); os << " - SetString: "; - globalConst->GetSetString().Dump(thread, os); + global_const->GetSetString().Dump(thread, os); os << " - EnumerableString: "; - globalConst->GetEnumerableString().Dump(thread, os); + global_const->GetEnumerableString().Dump(thread, os); os << " - ConfigurableString: "; - globalConst->GetConfigurableString().Dump(thread, os); + global_const->GetConfigurableString().Dump(thread, os); os << " - NameString: "; - globalConst->GetNameString().Dump(thread, os); + global_const->GetNameString().Dump(thread, os); os << " - ValueOfString: "; - globalConst->GetValueOfString().Dump(thread, os); + global_const->GetValueOfString().Dump(thread, os); os << " - ToStringString: "; - globalConst->GetToStringString().Dump(thread, os); + global_const->GetToStringString().Dump(thread, os); os << " - ToLocaleStringString: "; - globalConst->GetToLocaleStringString().Dump(thread, os); + global_const->GetToLocaleStringString().Dump(thread, os); os << " - UndefinedString: "; - globalConst->GetUndefinedString().Dump(thread, os); + global_const->GetUndefinedString().Dump(thread, os); os << " - NullString: "; - globalConst->GetNullString().Dump(thread, os); + global_const->GetNullString().Dump(thread, os); os << " - TrueString: "; - globalConst->GetTrueString().Dump(thread, os); + global_const->GetTrueString().Dump(thread, os); os << " - FalseString: "; - globalConst->GetFalseString().Dump(thread, os); + global_const->GetFalseString().Dump(thread, os); os << " - RegisterSymbols: "; GetRegisterSymbols().GetTaggedValue().Dump(thread, os); os << " - ThrowTypeError: "; GetThrowTypeError().GetTaggedValue().Dump(thread, os); os << " - GetPrototypeOfString: "; - globalConst->GetGetPrototypeOfString().Dump(thread, os); + global_const->GetGetPrototypeOfString().Dump(thread, os); os << " - SetPrototypeOfString: "; - globalConst->GetSetPrototypeOfString().Dump(thread, os); + global_const->GetSetPrototypeOfString().Dump(thread, os); os << " - IsExtensibleString: "; - globalConst->GetIsExtensibleString().Dump(thread, os); + global_const->GetIsExtensibleString().Dump(thread, os); os << " - PreventExtensionsString: "; - globalConst->GetPreventExtensionsString().Dump(thread, os); + global_const->GetPreventExtensionsString().Dump(thread, os); os << " - GetOwnPropertyDescriptorString: "; - globalConst->GetGetOwnPropertyDescriptorString().Dump(thread, os); + global_const->GetGetOwnPropertyDescriptorString().Dump(thread, os); os << " - DefinePropertyString: "; - globalConst->GetDefinePropertyString().Dump(thread, os); + global_const->GetDefinePropertyString().Dump(thread, os); os << " - HasString: "; - globalConst->GetHasString().Dump(thread, os); + global_const->GetHasString().Dump(thread, os); os << " - DeletePropertyString: "; - globalConst->GetDeletePropertyString().Dump(thread, os); + global_const->GetDeletePropertyString().Dump(thread, os); os << " - EnumerateString: "; - globalConst->GetEnumerateString().Dump(thread, os); + global_const->GetEnumerateString().Dump(thread, os); os << " - OwnKeysString: "; - globalConst->GetOwnKeysString().Dump(thread, os); + global_const->GetOwnKeysString().Dump(thread, os); os << " - ApplyString: "; - globalConst->GetApplyString().Dump(thread, os); + global_const->GetApplyString().Dump(thread, os); os << " - ProxyString: "; - globalConst->GetProxyString().Dump(thread, os); + global_const->GetProxyString().Dump(thread, os); os << " - RevokeString: "; - globalConst->GetRevokeString().Dump(thread, os); + global_const->GetRevokeString().Dump(thread, os); os << " - ProxyConstructString: "; - globalConst->GetProxyConstructString().Dump(thread, os); + global_const->GetProxyConstructString().Dump(thread, os); os << " - ProxyCallString: "; - globalConst->GetProxyCallString().Dump(thread, os); + global_const->GetProxyCallString().Dump(thread, os); os << " - DoneString: "; - globalConst->GetDoneString().Dump(thread, os); + global_const->GetDoneString().Dump(thread, os); os << " - NegativeZeroString: "; - globalConst->GetNegativeZeroString().Dump(thread, os); + global_const->GetNegativeZeroString().Dump(thread, os); os << " - NextString: "; - globalConst->GetNextString().Dump(thread, os); + global_const->GetNextString().Dump(thread, os); os << " - PromiseThenString: "; - globalConst->GetPromiseThenString().Dump(thread, os); + global_const->GetPromiseThenString().Dump(thread, os); os << " - PromiseFunction: "; GetPromiseFunction().GetTaggedValue().Dump(thread, os); os << " - PromiseReactionJob: "; @@ -1451,17 +1451,17 @@ void GlobalEnv::Dump(JSThread *thread, std::ostream &os) const os << " - PromiseResolveThenableJob: "; GetPromiseResolveThenableJob().GetTaggedValue().Dump(thread, os); os << " - ScriptJobString: "; - globalConst->GetScriptJobString().Dump(thread, os); + global_const->GetScriptJobString().Dump(thread, os); os << " - PromiseString: "; - globalConst->GetPromiseString().Dump(thread, os); + global_const->GetPromiseString().Dump(thread, os); os << " - IdentityString: "; - globalConst->GetIdentityString().Dump(thread, os); + global_const->GetIdentityString().Dump(thread, os); os << " - AsyncFunctionString: "; - globalConst->GetAsyncFunctionString().Dump(thread, os); + global_const->GetAsyncFunctionString().Dump(thread, os); os << " - ThrowerString: "; - globalConst->GetThrowerString().Dump(thread, os); + global_const->GetThrowerString().Dump(thread, os); os << " - Undefined: "; - globalConst->GetUndefined().Dump(thread, os); + global_const->GetUndefined().Dump(thread, os); } void JSDataView::Dump([[maybe_unused]] JSThread *thread, std::ostream &os) const @@ -2074,8 +2074,8 @@ static void DumpDynClass([[maybe_unused]] JSThread *thread, TaggedObject *obj, static void DumpObject(JSThread *thread, TaggedObject *obj, std::vector> &vec, bool is_vm_mode) { - auto jsHclass = obj->GetClass(); - JSType type = jsHclass->GetObjectType(); + auto js_hclass = obj->GetClass(); + JSType type = js_hclass->GetObjectType(); switch (type) { case JSType::HCLASS: @@ -2361,10 +2361,10 @@ void NumberDictionary::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(hash_index)); PandaString str = ToPandaString(static_cast(JSTaggedNumber(key).GetNumber())); vec.emplace_back(std::make_pair(str, val)); } @@ -2375,10 +2375,10 @@ void NameDictionary::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val(GetValue(hashIndex)); + JSTaggedValue val(GetValue(hash_index)); PandaString str; KeyToStd(str, key); vec.emplace_back(std::make_pair(str, val)); @@ -2390,12 +2390,12 @@ void GlobalDictionary::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { int size = Size(); - for (int hashIndex = 0; hashIndex < size; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < size; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { PandaString str; KeyToStd(str, key); - JSTaggedValue val = GetValue(hashIndex); + JSTaggedValue val = GetValue(hash_index); vec.emplace_back(std::make_pair(str, val)); } } @@ -2405,8 +2405,8 @@ void LinkedHashSet::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { int capacity = NumberOfElements() + NumberOfDeletedElements(); - for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < capacity; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { PandaString str; KeyToStd(str, key); @@ -2419,10 +2419,10 @@ void LinkedHashMap::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { int capacity = NumberOfElements() + NumberOfDeletedElements(); - for (int hashIndex = 0; hashIndex < capacity; hashIndex++) { - JSTaggedValue key(GetKey(hashIndex)); + for (int hash_index = 0; hash_index < capacity; hash_index++) { + JSTaggedValue key(GetKey(hash_index)); if (!key.IsUndefined() && !key.IsHole() && !key.IsNull()) { - JSTaggedValue val = GetValue(hashIndex); + JSTaggedValue val = GetValue(hash_index); PandaString str; KeyToStd(str, key); vec.emplace_back(std::make_pair(str, val)); @@ -2457,11 +2457,11 @@ void JSObject::DumpForSnapshot(JSThread *thread, std::vectorNumberOfProps(); - for (int i = 0; i < propNumber; i++) { - JSTaggedValue key = layoutInfo->GetKey(i); - PropertyAttributes attr = layoutInfo->GetAttr(i); + LayoutInfo *layout_info = LayoutInfo::Cast(attrs.GetTaggedObject()); + int prop_number = jshclass->NumberOfProps(); + for (int i = 0; i < prop_number; i++) { + JSTaggedValue key = layout_info->GetKey(i); + PropertyAttributes attr = layout_info->GetAttr(i); ASSERT(i == static_cast(attr.GetOffset())); JSTaggedValue val; if (attr.IsInlinedProps()) { @@ -2701,7 +2701,7 @@ void LexicalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, void GlobalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::vector> &vec) const { - auto globalConst = thread->GlobalConstants(); + auto global_const = thread->GlobalConstants(); vec.emplace_back(std::make_pair(PandaString("ObjectFunction"), GetObjectFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("FunctionFunction"), GetFunctionFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("NumberFunction"), GetNumberFunction().GetTaggedValue())); @@ -2747,9 +2747,9 @@ void GlobalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::make_pair(PandaString("AsyncFunctionPrototype"), GetAsyncFunctionPrototype().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("JSGlobalObject"), GetJSGlobalObject().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("EmptyArray"), GetEmptyArray().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("EmptyString"), globalConst->GetEmptyString())); + vec.emplace_back(std::make_pair(PandaString("EmptyString"), global_const->GetEmptyString())); vec.emplace_back(std::make_pair(PandaString("EmptyTaggedQueue"), GetEmptyTaggedQueue().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("PrototypeString"), globalConst->GetPrototypeString())); + vec.emplace_back(std::make_pair(PandaString("PrototypeString"), global_const->GetPrototypeString())); vec.emplace_back(std::make_pair(PandaString("HasInstanceSymbol"), GetHasInstanceSymbol().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("IsConcatSpreadableSymbol"), GetIsConcatSpreadableSymbol().GetTaggedValue())); @@ -2763,7 +2763,7 @@ void GlobalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, vec.emplace_back(std::make_pair(PandaString("ToPrimitiveSymbol"), GetToPrimitiveSymbol().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("UnscopablesSymbol"), GetUnscopablesSymbol().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("HoleySymbol"), GetHoleySymbol().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("ConstructorString"), globalConst->GetConstructorString())); + vec.emplace_back(std::make_pair(PandaString("ConstructorString"), global_const->GetConstructorString())); vec.emplace_back(std::make_pair(PandaString("IteratorPrototype"), GetIteratorPrototype().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("ForinIteratorPrototype"), GetForinIteratorPrototype().GetTaggedValue())); @@ -2776,53 +2776,54 @@ void GlobalEnv::DumpForSnapshot([[maybe_unused]] JSThread *thread, std::make_pair(PandaString("ArrayIteratorPrototype"), GetArrayIteratorPrototype().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("StringIteratorPrototype"), GetStringIteratorPrototype().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("LengthString"), globalConst->GetLengthString())); - vec.emplace_back(std::make_pair(PandaString("ValueString"), globalConst->GetValueString())); - vec.emplace_back(std::make_pair(PandaString("WritableString"), globalConst->GetWritableString())); - vec.emplace_back(std::make_pair(PandaString("GetString"), globalConst->GetGetString())); - vec.emplace_back(std::make_pair(PandaString("SetString"), globalConst->GetSetString())); - vec.emplace_back(std::make_pair(PandaString("EnumerableString"), globalConst->GetEnumerableString())); - vec.emplace_back(std::make_pair(PandaString("ConfigurableString"), globalConst->GetConfigurableString())); - vec.emplace_back(std::make_pair(PandaString("NameString"), globalConst->GetNameString())); - vec.emplace_back(std::make_pair(PandaString("ValueOfString"), globalConst->GetValueOfString())); - vec.emplace_back(std::make_pair(PandaString("ToStringString"), globalConst->GetToStringString())); - vec.emplace_back(std::make_pair(PandaString("ToLocaleStringString"), globalConst->GetToLocaleStringString())); - vec.emplace_back(std::make_pair(PandaString("UndefinedString"), globalConst->GetUndefinedString())); - vec.emplace_back(std::make_pair(PandaString("NullString"), globalConst->GetNullString())); - vec.emplace_back(std::make_pair(PandaString("TrueString"), globalConst->GetTrueString())); - vec.emplace_back(std::make_pair(PandaString("FalseString"), globalConst->GetFalseString())); + vec.emplace_back(std::make_pair(PandaString("LengthString"), global_const->GetLengthString())); + vec.emplace_back(std::make_pair(PandaString("ValueString"), global_const->GetValueString())); + vec.emplace_back(std::make_pair(PandaString("WritableString"), global_const->GetWritableString())); + vec.emplace_back(std::make_pair(PandaString("GetString"), global_const->GetGetString())); + vec.emplace_back(std::make_pair(PandaString("SetString"), global_const->GetSetString())); + vec.emplace_back(std::make_pair(PandaString("EnumerableString"), global_const->GetEnumerableString())); + vec.emplace_back(std::make_pair(PandaString("ConfigurableString"), global_const->GetConfigurableString())); + vec.emplace_back(std::make_pair(PandaString("NameString"), global_const->GetNameString())); + vec.emplace_back(std::make_pair(PandaString("ValueOfString"), global_const->GetValueOfString())); + vec.emplace_back(std::make_pair(PandaString("ToStringString"), global_const->GetToStringString())); + vec.emplace_back(std::make_pair(PandaString("ToLocaleStringString"), global_const->GetToLocaleStringString())); + vec.emplace_back(std::make_pair(PandaString("UndefinedString"), global_const->GetUndefinedString())); + vec.emplace_back(std::make_pair(PandaString("NullString"), global_const->GetNullString())); + vec.emplace_back(std::make_pair(PandaString("TrueString"), global_const->GetTrueString())); + vec.emplace_back(std::make_pair(PandaString("FalseString"), global_const->GetFalseString())); vec.emplace_back(std::make_pair(PandaString("RegisterSymbols"), GetRegisterSymbols().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("ThrowTypeError"), GetThrowTypeError().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("GetPrototypeOfString"), globalConst->GetGetPrototypeOfString())); - vec.emplace_back(std::make_pair(PandaString("SetPrototypeOfString"), globalConst->GetSetPrototypeOfString())); - vec.emplace_back(std::make_pair(PandaString("IsExtensibleString"), globalConst->GetIsExtensibleString())); - vec.emplace_back(std::make_pair(PandaString("PreventExtensionsString"), globalConst->GetPreventExtensionsString())); + vec.emplace_back(std::make_pair(PandaString("GetPrototypeOfString"), global_const->GetGetPrototypeOfString())); + vec.emplace_back(std::make_pair(PandaString("SetPrototypeOfString"), global_const->GetSetPrototypeOfString())); + vec.emplace_back(std::make_pair(PandaString("IsExtensibleString"), global_const->GetIsExtensibleString())); + vec.emplace_back( + std::make_pair(PandaString("PreventExtensionsString"), global_const->GetPreventExtensionsString())); vec.emplace_back(std::make_pair(PandaString("GetOwnPropertyDescriptorString"), - globalConst->GetGetOwnPropertyDescriptorString())); - vec.emplace_back(std::make_pair(PandaString("DefinePropertyString"), globalConst->GetDefinePropertyString())); - vec.emplace_back(std::make_pair(PandaString("HasString"), globalConst->GetHasString())); - vec.emplace_back(std::make_pair(PandaString("DeletePropertyString"), globalConst->GetDeletePropertyString())); - vec.emplace_back(std::make_pair(PandaString("EnumerateString"), globalConst->GetEnumerateString())); - vec.emplace_back(std::make_pair(PandaString("OwnKeysString"), globalConst->GetOwnKeysString())); - vec.emplace_back(std::make_pair(PandaString("ApplyString"), globalConst->GetApplyString())); - vec.emplace_back(std::make_pair(PandaString("ProxyString"), globalConst->GetProxyString())); - vec.emplace_back(std::make_pair(PandaString("RevokeString"), globalConst->GetRevokeString())); - vec.emplace_back(std::make_pair(PandaString("ProxyConstructString"), globalConst->GetProxyConstructString())); - vec.emplace_back(std::make_pair(PandaString("ProxyCallString"), globalConst->GetProxyCallString())); - vec.emplace_back(std::make_pair(PandaString("DoneString"), globalConst->GetDoneString())); - vec.emplace_back(std::make_pair(PandaString("NegativeZeroString"), globalConst->GetNegativeZeroString())); - vec.emplace_back(std::make_pair(PandaString("NextString"), globalConst->GetNextString())); - vec.emplace_back(std::make_pair(PandaString("PromiseThenString"), globalConst->GetPromiseThenString())); + global_const->GetGetOwnPropertyDescriptorString())); + vec.emplace_back(std::make_pair(PandaString("DefinePropertyString"), global_const->GetDefinePropertyString())); + vec.emplace_back(std::make_pair(PandaString("HasString"), global_const->GetHasString())); + vec.emplace_back(std::make_pair(PandaString("DeletePropertyString"), global_const->GetDeletePropertyString())); + vec.emplace_back(std::make_pair(PandaString("EnumerateString"), global_const->GetEnumerateString())); + vec.emplace_back(std::make_pair(PandaString("OwnKeysString"), global_const->GetOwnKeysString())); + vec.emplace_back(std::make_pair(PandaString("ApplyString"), global_const->GetApplyString())); + vec.emplace_back(std::make_pair(PandaString("ProxyString"), global_const->GetProxyString())); + vec.emplace_back(std::make_pair(PandaString("RevokeString"), global_const->GetRevokeString())); + vec.emplace_back(std::make_pair(PandaString("ProxyConstructString"), global_const->GetProxyConstructString())); + vec.emplace_back(std::make_pair(PandaString("ProxyCallString"), global_const->GetProxyCallString())); + vec.emplace_back(std::make_pair(PandaString("DoneString"), global_const->GetDoneString())); + vec.emplace_back(std::make_pair(PandaString("NegativeZeroString"), global_const->GetNegativeZeroString())); + vec.emplace_back(std::make_pair(PandaString("NextString"), global_const->GetNextString())); + vec.emplace_back(std::make_pair(PandaString("PromiseThenString"), global_const->GetPromiseThenString())); vec.emplace_back(std::make_pair(PandaString("PromiseFunction"), GetPromiseFunction().GetTaggedValue())); vec.emplace_back(std::make_pair(PandaString("PromiseReactionJob"), GetPromiseReactionJob().GetTaggedValue())); vec.emplace_back( std::make_pair(PandaString("PromiseResolveThenableJob"), GetPromiseResolveThenableJob().GetTaggedValue())); - vec.emplace_back(std::make_pair(PandaString("ScriptJobString"), globalConst->GetScriptJobString())); - vec.emplace_back(std::make_pair(PandaString("PromiseString"), globalConst->GetPromiseString())); - vec.emplace_back(std::make_pair(PandaString("IdentityString"), globalConst->GetIdentityString())); - vec.emplace_back(std::make_pair(PandaString("AsyncFunctionString"), globalConst->GetAsyncFunctionString())); - vec.emplace_back(std::make_pair(PandaString("ThrowerString"), globalConst->GetThrowerString())); - vec.emplace_back(std::make_pair(PandaString("Undefined"), globalConst->GetUndefined())); + vec.emplace_back(std::make_pair(PandaString("ScriptJobString"), global_const->GetScriptJobString())); + vec.emplace_back(std::make_pair(PandaString("PromiseString"), global_const->GetPromiseString())); + vec.emplace_back(std::make_pair(PandaString("IdentityString"), global_const->GetIdentityString())); + vec.emplace_back(std::make_pair(PandaString("AsyncFunctionString"), global_const->GetAsyncFunctionString())); + vec.emplace_back(std::make_pair(PandaString("ThrowerString"), global_const->GetThrowerString())); + vec.emplace_back(std::make_pair(PandaString("Undefined"), global_const->GetUndefined())); } void JSDataView::DumpForSnapshot([[maybe_unused]] JSThread *thread, diff --git a/runtime/ecma_class_linker_extension.cpp b/runtime/ecma_class_linker_extension.cpp index 9bba23ed39d4056558cf02d56df9fa2e8e9f8f93..6dceabae2e5080c17bdfc9a3249a701ed7ed6289 100644 --- a/runtime/ecma_class_linker_extension.cpp +++ b/runtime/ecma_class_linker_extension.cpp @@ -24,7 +24,7 @@ namespace panda::ecmascript { using SourceLang = panda_file::SourceLang; -bool EcmaClassLinkerExtension::InitializeImpl([[maybe_unused]] bool cmpStrEnabled) +bool EcmaClassLinkerExtension::InitializeImpl([[maybe_unused]] bool cmp_str_enabled) { return true; } @@ -44,21 +44,21 @@ void EcmaClassLinkerExtension::InitClasses(EcmaVM *vm) LanguageContext ctx = Runtime::GetCurrent()->GetLanguageContext(GetLanguage()); [[maybe_unused]] EcmaHandleScope scope(vm->GetJSThread()); - auto *classClass = NewClass(ctx.GetClassClassDescriptor(), 0, 0, GetClassSize(ClassRoot::CLASS)); - if (classClass == nullptr) { + auto *class_class = NewClass(ctx.GetClassClassDescriptor(), 0, 0, GetClassSize(ClassRoot::CLASS)); + if (class_class == nullptr) { return; } - classClass->SetObjectSize(ObjectHeader::ObjectHeaderSize()); - classClass->SetState(Class::State::LOADED); - Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::CLASS, classClass); + class_class->SetObjectSize(ObjectHeader::ObjectHeaderSize()); + class_class->SetState(Class::State::LOADED); + Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::CLASS, class_class); - auto *objClass = NewClass(ctx.GetObjectClassDescriptor(), 0, 0, GetClassSize(ClassRoot::OBJECT)); - if (objClass == nullptr) { + auto *obj_class = NewClass(ctx.GetObjectClassDescriptor(), 0, 0, GetClassSize(ClassRoot::OBJECT)); + if (obj_class == nullptr) { return; } - objClass->SetObjectSize(TaggedObject::TaggedObjectSize()); - objClass->SetState(Class::State::LOADED); - Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::OBJECT, objClass); + obj_class->SetObjectSize(TaggedObject::TaggedObjectSize()); + obj_class->SetState(Class::State::LOADED); + Runtime::GetCurrent()->GetClassLinker()->AddClassRoot(ClassRoot::OBJECT, obj_class); } ClassLinkerContext *EcmaClassLinkerExtension::CreateApplicationClassLinkerContext(const PandaVector &path) @@ -75,7 +75,7 @@ ClassLinkerContext *EcmaClassLinkerExtension::CreateApplicationClassLinkerContex return ClassLinkerExtension::CreateApplicationClassLinkerContext(std::move(app_files)); } -Class *EcmaClassLinkerExtension::NewClass(const uint8_t *descriptor, size_t vtableSize, size_t imtSize, +Class *EcmaClassLinkerExtension::NewClass(const uint8_t *descriptor, size_t vtable_size, size_t imt_size, size_t class_size) { ASSERT(IsInitialized()); @@ -117,7 +117,7 @@ Class *EcmaClassLinkerExtension::NewClass(const uint8_t *descriptor, size_t vtab JSHandle klass_obj(vm_->GetJSThread(), factory->NewNonMovableDynObject(hclass)); auto *klass = reinterpret_cast(ToUintPtr(klass_obj.GetObject()) + ObjectHeader::ObjectHeaderSize()); - new (klass) Class(descriptor, panda_file::SourceLang::ECMASCRIPT, vtableSize, imtSize, class_size); + new (klass) Class(descriptor, panda_file::SourceLang::ECMASCRIPT, vtable_size, imt_size, class_size); klass->SetManagedObject(klass_obj.GetObject()); AddCreatedClass(klass); return klass; diff --git a/runtime/ecma_class_linker_extension.h b/runtime/ecma_class_linker_extension.h index 9e6a64cde78dcd53a0ab0f71b240417389120d4b..647ca268caf51bb32ac254624bcb6295ba0e9c74 100644 --- a/runtime/ecma_class_linker_extension.h +++ b/runtime/ecma_class_linker_extension.h @@ -49,12 +49,12 @@ public: return true; } - bool InitializeArrayClass([[maybe_unused]] Class *array_class, [[maybe_unused]] Class *componentClass) override + bool InitializeArrayClass([[maybe_unused]] Class *array_class, [[maybe_unused]] Class *component_class) override { return true; } - void InitializePrimitiveClass([[maybe_unused]] Class *primitiveClass) override {} + void InitializePrimitiveClass([[maybe_unused]] Class *primitive_class) override {} size_t GetClassVTableSize([[maybe_unused]] ClassRoot root) override { @@ -79,10 +79,10 @@ public: } size_t GetArrayClassSize() override; - Class *CreateClass([[maybe_unused]] const uint8_t *descriptor, [[maybe_unused]] size_t vtableSize, size_t imtSize, + Class *CreateClass([[maybe_unused]] const uint8_t *descriptor, [[maybe_unused]] size_t vtable_size, size_t imt_size, [[maybe_unused]] size_t size) override { - return NewClass(descriptor, vtableSize, imtSize, size); + return NewClass(descriptor, vtable_size, imt_size, size); } bool InitializeClass([[maybe_unused]] Class *klass) override @@ -103,8 +103,8 @@ public: void FreeClass(Class *klass) override; private: - bool InitializeImpl(bool cmpStrEnabled) override; - Class *NewClass(const uint8_t *descriptor, size_t vtableSize, size_t imtSize, size_t size); + bool InitializeImpl(bool cmp_str_enabled) override; + Class *NewClass(const uint8_t *descriptor, size_t vtable_size, size_t imt_size, size_t size); EcmaVM *vm_ {nullptr}; }; diff --git a/runtime/ecma_exceptions.cpp b/runtime/ecma_exceptions.cpp index c8196733167fd7d9d9a9a63e9be4767f159874ab..c9e13b841f969f74e09a3a2d9d23e968990d91cd 100644 --- a/runtime/ecma_exceptions.cpp +++ b/runtime/ecma_exceptions.cpp @@ -31,20 +31,20 @@ void SetException(JSThread *thread, JSObject *error) void ThrowException(JSThread *thread, const char *name, const char *msg) { - auto jsThread = static_cast(thread); - ObjectFactory *factory = jsThread->GetEcmaVM()->GetFactory(); + auto js_thread = static_cast(thread); + ObjectFactory *factory = js_thread->GetEcmaVM()->GetFactory(); if (std::strcmp(name, REFERENCE_ERROR_STRING) == 0) { - SetException(jsThread, *factory->GetJSError(base::ErrorType::REFERENCE_ERROR, msg)); + SetException(js_thread, *factory->GetJSError(base::ErrorType::REFERENCE_ERROR, msg)); return; } if (std::strcmp(name, TYPE_ERROR_STRING) == 0) { - SetException(jsThread, *factory->GetJSError(base::ErrorType::TYPE_ERROR, msg)); + SetException(js_thread, *factory->GetJSError(base::ErrorType::TYPE_ERROR, msg)); return; } if (std::strcmp(name, RANGE_ERROR_STRING) == 0) { - SetException(jsThread, *factory->GetJSError(base::ErrorType::RANGE_ERROR, msg)); + SetException(js_thread, *factory->GetJSError(base::ErrorType::RANGE_ERROR, msg)); return; } UNREACHABLE(); diff --git a/runtime/ecma_global_storage-inl.h b/runtime/ecma_global_storage-inl.h index 07ece9706faa46856f99447fdb333939c8511d9e..59c1422656a9cf8e032baafaf64377c975c32897 100644 --- a/runtime/ecma_global_storage-inl.h +++ b/runtime/ecma_global_storage-inl.h @@ -148,10 +148,10 @@ inline uintptr_t EcmaGlobalStorage::NewGlobalHandle(JSTaggedType value) return NewGlobalHandleImplement(&last_global_nodes_, &free_list_nodes_, false, value); } -inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t nodeAddr) +inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t node_addr) { auto allocator = Runtime::GetCurrent()->GetInternalAllocator(); - Node *node = reinterpret_cast(nodeAddr); + Node *node = reinterpret_cast(node_addr); if (node->IsFree()) { return; } @@ -195,10 +195,10 @@ inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t nodeAddr) } } -inline uintptr_t EcmaGlobalStorage::SetWeak(uintptr_t nodeAddr) +inline uintptr_t EcmaGlobalStorage::SetWeak(uintptr_t node_addr) { - auto value = reinterpret_cast(nodeAddr)->GetObject(); - DisposeGlobalHandle(nodeAddr); + auto value = reinterpret_cast(node_addr)->GetObject(); + DisposeGlobalHandle(node_addr); return NewGlobalHandleImplement(&last_weak_global_nodes_, &weak_free_list_nodes_, true, value); } diff --git a/runtime/ecma_language_context.cpp b/runtime/ecma_language_context.cpp index 6d879bb1b4b4352ca972a934d8d289db64ca9846..6c2db5b400b5bc94bf3060cd9a0e10cebeb409cb 100644 --- a/runtime/ecma_language_context.cpp +++ b/runtime/ecma_language_context.cpp @@ -35,22 +35,22 @@ using ecmascript::JSThread; std::pair EcmaLanguageContext::GetCatchMethodAndOffset(Method *method, ManagedThread *thread) const { - Method *catchMethod = method; - uint32_t catchOffset = 0; - auto jsThread = static_cast(thread); + Method *catch_method = method; + uint32_t catch_offset = 0; + auto js_thread = static_cast(thread); for (auto stack = StackWalker::Create(thread); stack.HasFrame(); stack.NextFrame()) { - catchMethod = stack.GetMethod(); - if (catchMethod->IsNative()) { + catch_method = stack.GetMethod(); + if (catch_method->IsNative()) { continue; } - catchOffset = catchMethod->FindCatchBlock(jsThread->GetException().GetTaggedObject()->ClassAddr(), - stack.GetBytecodePc()); - if (catchOffset != panda_file::INVALID_OFFSET) { + catch_offset = catch_method->FindCatchBlock(js_thread->GetException().GetTaggedObject()->ClassAddr(), + stack.GetBytecodePc()); + if (catch_offset != panda_file::INVALID_OFFSET) { break; } } - return std::make_pair(catchMethod, catchOffset); + return std::make_pair(catch_method, catch_offset); } PandaVM *EcmaLanguageContext::CreateVM(Runtime *runtime, const RuntimeOptions &options) const diff --git a/runtime/ecma_macro_accessors.h b/runtime/ecma_macro_accessors.h index add45a97f8cb3d78f148efabc936e4679efc054d..b012a44c47bc44dc7835a1a2627c841590371903 100644 --- a/runtime/ecma_macro_accessors.h +++ b/runtime/ecma_macro_accessors.h @@ -12,28 +12,28 @@ namespace panda::ecmascript { using JSAccessorsMaskType = uint32_t; -template +template struct JSAccessorsOffs { - static constexpr size_t END = OFFS_; + static constexpr size_t END = OFFS; }; -template